Welcome, Guest.
Username: Password: Remember me

TOPIC: for loop issue when int type condition in D3D9

for loop issue when int type condition in D3D9 6 months 1 day ago #1

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: 6 months 1 day ago by seri14.
The administrator has disabled public write access.

for loop issue when int type condition in D3D9 6 months 1 day ago #2

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)
The administrator has disabled public write access.

for loop issue when int type condition in D3D9 6 months 21 hours ago #3

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).
Cheers, crosire =)
The administrator has disabled public write access.
The following user(s) said Thank You: seri14