Welcome, Guest.
Username: Password: Remember me

TOPIC: [SOLVED] Compiling error only on DX10/11

Compiling error only on DX10/11 10 months 5 days ago #1

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
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).
Loves to test stuff for no reason.
Last Edit: 10 months 4 days ago by matsilagi.
The administrator has disabled public write access.

Compiling error only on DX10/11 10 months 4 days ago #2

use tex2Dlod instead of tex2D in the loop if you don't want to unroll.
The administrator has disabled public write access.

Compiling error only on DX10/11 10 months 4 days ago #3

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
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);
Loves to test stuff for no reason.
Last Edit: 10 months 4 days ago by matsilagi.
The administrator has disabled public write access.

Compiling error only on DX10/11 10 months 4 days ago #4

This dummy code also shows the error, change the tex2d to tex2dlod fix the issue.
also if the error message start with , 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 administrator has disabled public write access.
The following user(s) said Thank You: matsilagi

Compiling error only on DX10/11 10 months 4 days ago #5

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
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)
Loves to test stuff for no reason.
Last Edit: 10 months 4 days ago by matsilagi.
The administrator has disabled public write access.

Compiling error only on DX10/11 10 months 4 days ago #6

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: 10 months 4 days ago by kingeric1992. Reason: typo
The administrator has disabled public write access.
The following user(s) said Thank You: matsilagi

Compiling error only on DX10/11 10 months 4 days ago #7

  • matsilagi
  • matsilagi's Avatar
  • Online
  • Posts: 199
  • Thank you received: 54
Now it worked, thanks a lot for the time and patience!
Loves to test stuff for no reason.
The administrator has disabled public write access.
The following user(s) said Thank You: kingeric1992