Commit Graph

433 Commits

Author SHA1 Message Date
Giovanni Mascellani
9457dc9c75 vkd3d-shader/dxil: Take the record from the function emission state in sm6_parser_emit_atomicrmw(). 2025-12-02 13:39:44 +01:00
Giovanni Mascellani
26f9644fb6 vkd3d-shader/dxil: Allocate instructions directly in sm6_parser_emit_alloca().
I think the main argument for preallocating instructions and
passing them to helpers is that this simplifies error handling.
However it seems that the simplification is close to negligible,
while the current solution makes it harder to use the iterator
abstraction layer for the instruction array, and it also makes
the code harder to read and check.
2025-12-02 13:39:44 +01:00
Giovanni Mascellani
3b9fbe3e4a vkd3d-shader/dxil: Pass function emission state to sm6_parser_emit_alloca(). 2025-12-02 13:39:44 +01:00
Giovanni Mascellani
6a3f360a2b vkd3d-shader/dxil: Move the function emission state outside the opcode switch. 2025-12-02 13:39:44 +01:00
Giovanni Mascellani
e9d08df010 vkd3d-shader/dxil: Check the fields of well-known structure types.
The main reason is to avoid making false assumptions in the code.
I don't know how that could be used, say, to introduce a security
bug, but I think validating untrusted input should be done by
default.

Conveniently this also acts as documentation for who needs to know
what fields we indeed expect to find in a well-known structure.
2025-11-24 19:03:29 +01:00
Giovanni Mascellani
44c80c60b8 vkd3d-shader/dxil: Parse string attributes with string value in parameter attribute groups. 2025-11-20 17:47:47 +01:00
Giovanni Mascellani
64738f5d9f vkd3d-shader/dxil: Parse string attributes in parameter attribute groups. 2025-11-20 17:43:07 +01:00
Giovanni Mascellani
e8db25750c vkd3d-shader/dxil: Parse well-known attributes with numeric value in parameter attribute groups. 2025-11-20 17:42:23 +01:00
Giovanni Mascellani
090490576a vkd3d-shader/dxil: Parse well-known attributes in parameter attribute groups. 2025-11-20 17:41:00 +01:00
Giovanni Mascellani
b174c64308 vkd3d-shader/dxil: Parse the parameter attribute group records.
Except that individual attributes are not parsed yet.
2025-11-20 17:30:22 +01:00
Conor McCarthy
25719f93fa vkd3d-shader/dxil: Get rid of struct sm6_block.
Emission of code into individual block instruction arrays was done to
enable construction of a control flow graph. A graph is constructed from
the flat instruction array in a later pass, so blocks are not needed.

It is possible to emit instructions directly into the array in struct
vsir_program instead of from sm6_function_emit_instructions(), but since
the patch constant function occurs first in DXIL hull shaders, this would
reverse the current order of functions in the flat array. That may be
acceptable, but it is left for a later patch in case any issues arise.
2025-11-20 17:21:16 +01:00
Conor McCarthy
6643c848fd vkd3d-shader/dxil: Emit phi instructions during parsing. 2025-11-20 17:21:16 +01:00
Conor McCarthy
28e58e0c85 vkd3d-shader/dxil: Move relative index validation outside sm6_parser_get_value_index().
This allows sm6_parser_get_value_index() to be called with relative indices
requiring different validation.
2025-11-20 17:21:16 +01:00
Conor McCarthy
7d3a520060 vkd3d-shader/dxil: Initialise or validate forward-referenced values in a helper function.
A future patch needs to call this function from another location.
2025-11-20 17:21:16 +01:00
Conor McCarthy
8a6c5cb401 vkd3d-shader/dxil: Emit an error if a return instruction has operands. 2025-11-20 17:21:16 +01:00
Conor McCarthy
32d0613bcb vkd3d-shader/dxil: Emit return instructions during parsing. 2025-11-20 17:21:15 +01:00
Conor McCarthy
c9f660ec55 vkd3d-shader/dxil: Emit switch instructions during parsing. 2025-11-20 17:21:15 +01:00
Conor McCarthy
8fdc156adb vkd3d-shader/dxil: Emit branch instructions during parsing. 2025-11-20 17:21:15 +01:00
Giovanni Mascellani
065430547c vkd3d-shader/dxil: Parse the gather offset as an int2.
Instead of an int3.

Gather operations expect an offset with only two components.
Currently the following field (which is the gather channel) is
parsed as a third component, which leads to wrong and invalid
results.

This fixes a crash on a shader from WRC Generations.
2025-11-12 15:08:42 +01:00
Henri Verbeet
9c6f8c8bd5 vkd3d-shader/dxil: Only add declared ICBs to the vsir program.
The input DXIL can sometimes contain constant arrays not referenced by the
resulting vsir program. It doesn't hurt much to generate ICBs for those
anyway, but it's a little pointless.
2025-10-29 13:27:33 +01:00
Francisco Casas
32b622d7a5 vkd3d-shader/dxil: Also map destination write masks for system values.
Currently, on what we consider normalized vsir, destination write masks
are not relative to the signature element's mask, even though source
swizzles are. Also for most instructions, the source swizzles are masked
by the destination write mask, as given by vsir_src_is_masked().

The DXIL parser however, is not derelativizing the destination write
masks for system value signature elements, so we fix that to make it
consistent with how other front-ends are handled.

For instance, when the test introduced in commit
ca5bc63e5e is compiled to DXIL using DXC,
and then parsed using vkd3d-compiler, we get the following store
instructions:

    vs_6_0
    .input
    .param POSITION.xyzw, v0.xyzw, float
    .output
    .param SV_Position.xyzw, o0.xyzw, float, POS
    .param SV_CullDistance.x, o1.x, float, CULLDST
    .param SV_ClipDistance.y, o1.y, float, CLIPDST
    .descriptors
    .text
    label l1
        ...
        mov o1.x <v4:f32>, sr1 <s:f32>
        mov o2.x <v4:f32>, sr2 <s:f32> // Note the .x write mask!
        ret

whereas, when compiling using FXC and parsing the TPF using
vkd3d-compiler we get:

    vs_4_0
    .input
    .param POSITION.xyzw, v0.xyzw, float
    .output
    .param SV_POSITION.xyzw, o0.xyzw, float, POS
    .param SV_CULLDISTANCE.x, o1.x, float, CULLDST
    .param SV_CLIPDISTANCE.y, o1.y, float, CLIPDST
    .descriptors
    .text
    label l1
        mov o0.xyzw <v4:f32>, v0.xyzw <v4:f32>
        mov o1.x <v4:f32>, v0.x <v4:f32>
        mov o2.y <v4:f32>, v0.y <v4:f32> // Note the .y write mask.
        ret

This only really matters for cases where we have a system value semantic
whose mask doesn't start at .x, which is very rare. For instance, it
requires the clip/cull distance combo, which share registers, so one of
them pushes the other to start on another component.

According to the tests, the only thing relying on this behaviour is the
handling of private variables for system value semantics on the SPIR-V
backend, which expects destination write masks as if the element started
at .x even though it might not. This is modified then.
2025-10-29 13:14:54 +01:00
Giovanni Mascellani
835044dd8e vkd3d-shader/ir: Introduce VSIR_OP_SATURATE to represent floating-point clamping to [0, 1]. 2025-10-14 15:53:26 +02:00
Henri Verbeet
c89fd93859 vkd3d-shader/ir: Require signed operands for IREM instructions. 2025-10-14 15:49:18 +02:00
Henri Verbeet
320bdd6759 vkd3d-shader/ir: Validate IDIV instructions. 2025-10-14 15:49:18 +02:00
Giovanni Mascellani
79736ae6ff vkd3d-shader/ir: Introduce VSIR_OP_NEG to represent floating-point negation. 2025-10-13 19:06:34 +02:00