-
4f7c1172
by Francisco Casas at 2025-01-16T18:43:12+01:00
tests: Test casting negative floats to int.
Turns out we are not doing this correctly in SM1, because the rounding
should be to the number that is closer to zero and lower_casts_to_int()
doesn't do that.
A vertex shader test is added since in SM1 they must rely on the SLT
operation instead of the CMP operation.
-
2d91bd92
by Francisco Casas at 2025-01-16T18:46:49+01:00
vkd3d-shader/hlsl: Properly lower casts to int for negative numbers.
While it looks complicated, it is what fxc/d3dcompiler does.
A shader as simple as:
float4 f;
float4 main() : sv_target
{
return (int4)f;
}
results in the following instructions:
ps_2_0
def c1, 0, 1, 0, 0
frc r0, c0
cmp r1, -r0, c1.x, c1.y
add r0, -r0, c0
mov r2, c0
cmp r1, r2, c1.x, r1
add r0, r0, r1
mov oC0, r0
-
cf19b4da
by Francisco Casas at 2025-01-16T18:48:35+01:00
vkd3d-shader/hlsl: Specialize lowering SM1 casts to int for vertex shaders.
Vertex shaders do not have CMP, so we use SLT and MAD.
For example, this vertex shader:
uniform float4 f;
void main(inout float4 pos : position, out float4 t1 : TEXCOORD1)
{
t1 = (int4)f;
}
results in:
vs_2_0
dcl_position v0
slt r0, c0, -c0
frc r1, c0
add r2, -r1, c0
slt r1, -r1, r1
mad oT1, r0, r1, r2
mov oPos, v0
while we have the lower_cmp() pass, each time it is applied many
instructions are generated, so this patch introduces a specialized
version of the cast-to-int lowering for efficiency.