Fxc.exe没有longers会产生错误X4014(发散梯度操作) [英] Fxc.exe no longers make error X4014 (divergent gradient operations)

查看:167
本文介绍了Fxc.exe没有longers会产生错误X4014(发散梯度操作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我很惊讶地发现最近(windows 10的10.0.17134.0)fxc.exe接受了分支内的Texture.Sample()。 />
这是正常的吗?

是否仍然建议避免这种情况(在分支之前计算渐变或使用SampleLevel)?

是GPU驱动程序知道这个变化吗?



 struct PS_INPUT {
float2 TexCoord:TEXCOORD0;
};
struct PS_OUTPUT {
float4 Color0:SV_Target0;
};
Texture2D TMapColor;
SamplerState SGbxWrap_Bilinear;

PS_OUTPUT psMain(const PS_INPUT v)// ps_2_0 ps_3_0
{
PS_OUTPUT输出;
Output.Color0 = 0;
[branch]
if(v.TexCoord.x> 0){
float4 m = TMapColor.Sample(SGbxWrap_Bilinear,v.TexCoord);
[branch]
if(m.x> 0.5){
Output.Color0 = TMapColor.Sample(SGbxWrap_Bilinear,v.TexCoord * 4);
}
}
返回输出;
};




使用旧编译器我得到了
Microsoft(R)Direct3D着色编译器9.30.9200.16384(C :\ Program Files(x86)\ Windows Wits \8.0\bin\x64)

Microsoft(R)Direct3D着色器编译器6.3.9600.16384(使用C:\Program Files(x86) )\ Windows Kits \\\\\ x64 \D3DCOMPILER_47.dll)

c:\ Nadeo \ GameBox \Projects\Test\Media \Text \ PHLSL \ _GradientInBranch_p.hlsl(19,3):错误X4014:流控制内部不能有发散梯度操作

编译失败;没有代码生成



现在编译成功,在分支内部调用'sample_indexable'

Microsoft(R)Direct3D着色器编译器10.1(使用C: \Program Files(x86)\ Windows Kits \10\bin\10.0.17134.0\x64 \D3DCOMPILER_47.dll)

ps_5_0
$
dcl_globalFlags refactoringAllowed

dcl_sampler s0,mode_default

dcl_resource_texture2d(float,float,float,float)t0

dcl_input_ps linear v0.xy

dcl_output o0.xyzw

dcl_temps 1

lt r0.x,l(0.000000),v0.x

if_nz r0.x

  sample_indexable(texture2d)(float,float,float,float)r0.x,v0.xyxx,t0.xyzw,s0

  lt r0.x,l(0.500000),r0.x

  if_nz r0.x

    mul r0.xy,v0.xyxx,l(4.000000,4000000,0.000000,0.000000)

    sample_indexable(texture2d)(float,float,float,float)o0.xyzw,r0.xyxx,t0.xyzw,s0

 否则为
    mov o0.xyzw,l(0,0,0,0)

 结束日
其他

  mov o0.xyzw,l(0,0,0,0)

endif

ret



谢谢

JSeb


解决方案

这是一次故意改变。 HLSL团队已得到反馈,原始错误过于保守,使得着色器开发人员很难在大多数情况下实际上并没有分歧。因此,最新版本将不再生成
此错误。


您仍然可以获得将在运行时显示的正确性问题,因此您作为开发人员在执行此操作时应该小心。此外,优化器可能会对指令进行重新排序,结果可能会产生性能影响,具体取决于着色器代码尝试执行的


YMMV。


Hello,

I was quite surprised to see that recent (windows 10's 10.0.17134.0) fxc.exe accept Texture.Sample() inside branches.
Is that normal ?
Is it still advised to avoid theses case (to compute gradients before the branch or to use SampleLevel) ?
Are GPU drivers aware of that change ?

struct PS_INPUT {
	float2 TexCoord	: TEXCOORD0;
};
struct PS_OUTPUT {
	float4 Color0 	: SV_Target0;
};
Texture2D 		TMapColor;
SamplerState	SGbxWrap_Bilinear;

PS_OUTPUT psMain(const PS_INPUT v) // ps_2_0 ps_3_0
{
	PS_OUTPUT Output;
	Output.Color0 = 0;
	[branch]
	if (v.TexCoord.x > 0) {
		float4	m = TMapColor.Sample(SGbxWrap_Bilinear, v.TexCoord);
		[branch]
		if (m.x > 0.5) {
			Output.Color0 = TMapColor.Sample(SGbxWrap_Bilinear, v.TexCoord*4);
		}
	}
	return Output;
};


With old compilers I got
Microsoft (R) Direct3D Shader Compiler 9.30.9200.16384 (C:\Program Files (x86)\Windows Kits\8.0\bin\x64)
Microsoft (R) Direct3D Shader Compiler 6.3.9600.16384 (using C:\Program Files (x86)\Windows Kits\8.1\bin\x64\D3DCOMPILER_47.dll)
c:\Nadeo\GameBox\Projects\Test\Media\Text\PHLSL\GradientInBranch_p.hlsl(19,3): error X4014: cannot have divergent gradient operations inside flow control
compilation failed; no code produced

Now compilation succeed with 'sample_indexable' being called inside branches
Microsoft (R) Direct3D Shader Compiler 10.1 (using C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64\D3DCOMPILER_47.dll)
ps_5_0
dcl_globalFlags refactoringAllowed
dcl_sampler s0, mode_default
dcl_resource_texture2d (float,float,float,float) t0
dcl_input_ps linear v0.xy
dcl_output o0.xyzw
dcl_temps 1
lt r0.x, l(0.000000), v0.x
if_nz r0.x
  sample_indexable(texture2d)(float,float,float,float) r0.x, v0.xyxx, t0.xyzw, s0
  lt r0.x, l(0.500000), r0.x
  if_nz r0.x
    mul r0.xy, v0.xyxx, l(4.000000, 4.000000, 0.000000, 0.000000)
    sample_indexable(texture2d)(float,float,float,float) o0.xyzw, r0.xyxx, t0.xyzw, s0
  else
    mov o0.xyzw, l(0,0,0,0)
  endif
else
  mov o0.xyzw, l(0,0,0,0)
endif
ret

Thanks
JSeb

解决方案

This was an intentional change. The HLSL team had gotten feedback that the original error was too conservative and making it difficult for shader developers where in most cases it wasn't actually divergent. Therefore the latest version will no longer generate this error.

You can still get correctness issues which will show up at runtime, so you as the developer should be careful when doing this. Furthermore, the optimizer can potentially reorder instructions and the result could have a performance impact depending on exactly what the shader code is trying to do.

YMMV.


这篇关于Fxc.exe没有longers会产生错误X4014(发散梯度操作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆