[SOLVED] Compiling error only on DX10/11

  • matsilagi
  • Topic Author
More
8 years 2 months ago - 8 years 2 months ago #1 by matsilagi Compiling error only on DX10/11 was created by matsilagi
So, i have a shader that works on all renderers but DX10/11, it gives the following error: error X4014: cannot have gradient operations inside loops with divergent flow control

The function that gives that error in DX10/11 is the following:
for(int i = 0; i < tailLength % 1023; i++){

							float2 d = float2(pn.x-ONEXN*i,pn.y);
							tn = tex2Dlod(SamplerTape, float4(d,0.0,0.0) ).x;
							// tn = tex2D(_TapeTex, d).x;
							// tn = tapeNoise(float2(pn.x-ONEXN*i,pn.y), t*tapeNoiseSpeed)*tapeNoiseAmount;

							//for tails length difference
							float fadediff = tex2D(SamplerTape, d).a; //hash12(d); 

							if( tn > 0.8 ){								
								float nsx =  0.0; //new signal x
								float newlength = float(tailLength)*(1.0-fadediff); //tail lenght diff
								if( float(i) <= newlength ) nsx = 1.0-( float(i)/ newlength ); //tail
								signal.x = bms(signal.x, nsx*tapeNoiseAmount).x;									
							}
							
						}

						//tape noise color shift
						if(distShift>0.4){
							// float tnl = tapeNoiseLines(float2(0.0,pn.y), t*tapeNoiseSpeed)*tapeNoiseAmount;
							float tnl = tex2D(SamplerTape, pn).y;//tapeNoiseLines(float2(0.0,pn.y), t*tapeNoiseSpeed)*tapeNoiseAmount;
						   signal.y *= 1.0/distShift;//tnl*0.1;//*distShift;//*signal.x;
						   signal.z *= 1.0/distShift;//*distShift;//*signal.x;

						}

It could be soemthing on the code, but im pretty sure it isn't (since its after the compiling phase, when ReShade converts the shader to the DX11 format, hence why i posted here).
Last edit: 8 years 2 months ago by matsilagi.

Please Log in or Create an account to join the conversation.

  • kingeric1992
More
8 years 2 months ago #2 by kingeric1992 Replied by kingeric1992 on topic Compiling error only on DX10/11
use tex2Dlod instead of tex2D in the loop if you don't want to unroll.

Please Log in or Create an account to join the conversation.

  • matsilagi
  • Topic Author
More
8 years 2 months ago - 8 years 2 months ago #3 by matsilagi Replied by matsilagi on topic Compiling error only on DX10/11
Sorry but, that didn't fix the issue.

Im still not sure why it happens only on DX10/11, the line that gives the problem is this one: float2 d = float2(pn.x-ONEXN*i,pn.y);
Last edit: 8 years 2 months ago by matsilagi.

Please Log in or Create an account to join the conversation.

  • kingeric1992
More
8 years 2 months ago #4 by kingeric1992 Replied by kingeric1992 on topic Compiling error only on DX10/11
This dummy code also shows the error, change the tex2d to tex2dlod fix the issue.
also if the error message start with Shader@0x0xxxx...etc, there will be a bias on error line.

and you need to check bms() function if there is sampler in it.
#define ONEXN 1

float4  PS_Test(in float4 position : SV_Position, in float2 texcoord : TEXCOORD0) : SV_Target0
{
float tailLength = texcoord.x * 1024;
float2 pn = float2(1, 1);
float tn = 0;
[loop]
for(int i = 0; i < tailLength % 1023; i++){

							float2 d = float2(pn.x-ONEXN*i,pn.y);
							tn = tex2Dlod(RFX_depthColor, float4(d,0.0,0.0) ).x;
							// tn = tex2D(_TapeTex, d).x;
							// tn = tapeNoise(float2(pn.x-ONEXN*i,pn.y), t*tapeNoiseSpeed)*tapeNoiseAmount;

							//for tails length difference
							float fadediff = tex2D(RFX_depthColor, d).a; //hash12(d); 
                            tn += fadediff;
						}
                        
    return tn;
}
The following user(s) said Thank You: matsilagi

Please Log in or Create an account to join the conversation.

  • matsilagi
  • Topic Author
More
8 years 2 months ago - 8 years 2 months ago #5 by matsilagi Replied by matsilagi on topic Compiling error only on DX10/11
I thank you for the effort, but i still think that isn't the problem, it says it cant implicitly convert float2 to float4

The BMS function has no samplers in it i guess, hence why i posted on ReShade troubleshooting in the first place, because i think that is a ReShade mistake, not mine.

And yes, it starts with Shader@0x0xxxx, hence why i have put Compiling error. (should have put post-compiling i guess)
Last edit: 8 years 2 months ago by matsilagi.

Please Log in or Create an account to join the conversation.

  • kingeric1992
More
8 years 2 months ago - 8 years 2 months ago #6 by kingeric1992 Replied by kingeric1992 on topic Compiling error only on DX10/11
sorry I didn't make it clear....tex2dlod takes float4 in, that's why it says cannot convert from f2 to f4.
so you need to do the same as the line "tn" does. float4(d, 0, 0).

from
float fadediff = tex2D(RFX_depthColor, d).a; //hash12(d);
to
float fadediff = tex2Dlod(RFX_depthColor, float4(d, 0, 0)).a; //hash12(d);

I think the error message that start with Shader@.... is from api after reshade convert the code into their standard?

Normally, dx9 or dx10/11, sampling in loop (without unroll) requires tex2dlod or samplerlevel to be able to compile, to bypass gradient ops.
Don't know why it works in your case on dx9.

Can't imagine if it actually force unrolled by the compiler(which actually is what happening on the dummy code without [loop] prefix). it took a huge amount of time doing that on those 1023 iterations.
Last edit: 8 years 2 months ago by kingeric1992. Reason: typo
The following user(s) said Thank You: matsilagi

Please Log in or Create an account to join the conversation.

  • matsilagi
  • Topic Author
More
8 years 2 months ago #7 by matsilagi Replied by matsilagi on topic Compiling error only on DX10/11
Now it worked, thanks a lot for the time and patience!
The following user(s) said Thank You: kingeric1992

Please Log in or Create an account to join the conversation.

We use cookies
We use cookies on our website. Some of them are essential for the operation of the forum. You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.