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
This commit is contained in:
Francisco Casas
2025-01-15 10:45:39 -03:00
committed by Henri Verbeet
parent 4f7c117296
commit 2d91bd9200
Notes: Henri Verbeet 2025-01-16 19:29:44 +01:00
Approved-by: Elizabeth Figura (@zfigura)
Approved-by: Henri Verbeet (@hverbeet)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1339
2 changed files with 52 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ float4 main() : sv_target
[test]
uniform 0 float4 10.3 -11.6 12.8 13.1
draw quad
todo(sm<4) probe (0, 0) rgba(10, -11, 12, 0)
probe (0, 0) rgba(10, -11, 12, 0)
[vertex shader]
@@ -32,7 +32,7 @@ float4 main(float4 t1 : TEXCOORD1) : sv_target
[test]
uniform 0 float4 -0.4 -0.7 -12.8 14.8
draw quad
todo(sm<4) probe (0, 0) rgba(0, 0, -12, 14)
probe (0, 0) rgba(0, 0, -12, 14)
[pixel shader todo(sm<4)]