for loop issue when int type condition in D3D9

  • seri14
  • Topic Author
More
5 years 2 months ago - 5 years 2 months ago #1 by seri14 for loop issue when int type condition in D3D9 was created 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.
Last edit: 5 years 2 months ago by seri14.

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

  • seri14
  • Topic Author
More
5 years 2 months ago #2 by seri14 Replied by seri14 on topic for loop issue when int type condition in D3D9
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.

  • crosire
More
5 years 2 months ago #3 by crosire Replied by crosire on topic for loop issue when int type condition in D3D9
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 docs.microsoft.com/en-us/windows/desktop...-ps-registers-ps-3-0 ). 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 docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/rep---ps 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.

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.