for loop issue when int type condition in D3D9

  • Posts: 154
1 year 5 months ago - 1 year 5 months ago #1 by seri14
This effect outputs black only in D3D9 configuration mode.
When used in D3D9 performance mode, it works. (gradation of black to white, from left top to other edge)
uniform int iUniform = 1;

#include "ReShade.fxh"

void PS_Test(float4 pos : SV_Position, float2 texcoord : TEXCOORD, out float3 color : SV_Target)
	color = float3(0.0, 0.0, 0.0);

	for (int _ = 0; _ < iUniform; _++)
		color += max(texcoord.x, texcoord.y);

technique Test { pass { VertexShader = PostProcessVS; PixelShader = PS_Test; } }
If change the loop condition to iUniform * 1.0, it works in each cases.

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

  • Posts: 154
1 year 5 months ago #2 by seri14
Some users say you need to switch to performance mode to use the DoF (DOF.fx) effect, I think It is caused by this. (D3D9 only)

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

  • Posts: 3750
1 year 5 months ago #3 by crosire
This is an interesting one.

Shader model 3 types of constant registers: Boolean, Float and Integer. The "Float" registers are the most interesting ones, because there are the most of these available: 224 (See ). So ReShade uses them for all uniforms, because the current D3D9 runtime seems to just reinterpret the data as whatever variable type is bound to them. So storing an 32-bit integer in the 32 float bits works nicely. Unfortunately, the "rep" instruction which is used for loops (See instruction) requires the repeat counter to be an Integer register. The HLSL compiler silently ignores the fact that ReShade decorated the uniform variable with ": register(cXXX)" and just uses the first available Integer register instead (Yay! Yet another thing to add to the list of things where D3DCompiler messes up). But since ReShade never binds any data to those, it will always hold the value zero and as such the loop is never executed.

Quite honestly I don't know how to fix that. ReShade would have to detect if a uniform variable was used as a loop counter somehow and also allocate an Integer register in that case. Just pushing all uniform variables into integer registers as well doesn't work (there are only 16 of those).
The following user(s) said Thank You: seri14

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