Commit Graph

1070 Commits

Author SHA1 Message Date
Henri Verbeet
cfe9cd3794 Release 1.18. 2025-11-20 11:36:06 +01:00
Giovanni Mascellani
7f377879fc vkd3d-shader/spirv: Clamp push constant CBV sizes to those of the push constant ranges backing them.
Otherwise invalid SPIR-V may be generated, because the CBV field in
"push_cb_struct" may end up overlapping with a subsequent one.
2025-11-12 15:24:30 +01:00
Henri Verbeet
fce89133e7 vkd3d-shader/ir: Remove VSIR_OP_DCL_IMMEDIATE_CONSTANT_BUFFER instructions. 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
6654b88407 vkd3d-shader/ir: Check that no modifier is added to a vsir program after lowering. 2025-10-27 18:48:33 +01:00
Elizabeth Figura
24d84e2ee2 vkd3d-shader/spirv: Allow swizzling parameters.
This was previously not a concern, since all of our parameter usage involved
trivial swizzles and write masks, but bump parameters will not.
2025-10-27 17:35:14 +01:00
Giovanni Mascellani
86b8f2de35 vkd3d-shader/ir: Error out on unsupported source modifiers. 2025-10-16 15:15:05 +02:00
Giovanni Mascellani
c99c729513 vkd3d-shader/ir: Error out on unsupported destination modifiers. 2025-10-16 15:10:39 +02:00
Giovanni Mascellani
8a100fa06d vkd3d-shader/ir: Ignore and drop PARTIALPRECISION modifiers. 2025-10-16 14:57:56 +02:00
Giovanni Mascellani
737158e7b8 vkd3d-shader/ir: Remove SATURATE modifiers after lowering them. 2025-10-16 14:55:51 +02:00
Henri Verbeet
346b62bc70 vkd3d-shader/spirv: Free the output on failure in spirv_compiler_generate_spirv(). 2025-10-16 14:31:18 +02:00
Conor McCarthy
3943f9aca6 vkd3d-shader/spirv: Handle VSIR_DATA_SNORM and VSIR_DATA_UNORM in image_format_for_image_read().
Typed UAVs can be declared snorm or unorm.
2025-10-15 12:41:49 +02:00
Conor McCarthy
1586c2294a vkd3d-shader/spirv: Handle VSIR_DATA_SNORM and VSIR_DATA_UNORM in spirv_get_type_id(). 2025-10-15 12:41:49 +02:00
Henri Verbeet
808191eb8e vkd3d-shader/spirv: Emit an error for unhandled types in spirv_get_type_id(). 2025-10-15 12:41:49 +02: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
11e5b83e79 vkd3d-shader/spirv: Handle VSIR_DATA_MIXED in spirv_get_type_id().
For example, a HLSL shader like this:

    tbuffer t0
    {
        float4 data;
    };

    float4 main() : sv_target
    {
        return data;
    }

would be compiled to the following:

    ps_4_0
    dcl_resource_buffer (mixed,mixed,mixed,mixed) t0
    dcl_output o0.xyzw
    dcl_temps 1
    ld r0.xyzw, l(0, 0, 0, 0), t0.xyzw
    mov o0.xyzw, r0.xyzw
    ret

VSIR_DATA_MIXED used to be mapped to VKD3D_SHADER_COMPONENT_UINT by
vkd3d_component_type_from_data_type(), but we no longer use that.
Found by Giovanni Mascellani.
2025-10-14 15:48:36 +02:00
Giovanni Mascellani
b5b5c67b34 vkd3d-shader/ir: Lower ABSNEG modifiers to instructions. 2025-10-13 19:25:51 +02:00
Giovanni Mascellani
968eb7467c vkd3d-shader/ir: Use VSIR_OP_NEG in insert_fragment_fog_before_ret(), in the common part.
The NEG source modifier is not generated any more during vsir
transformation, so it can be dropped in backends.
2025-10-13 19:13:05 +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
Henri Verbeet
9de229925d vkd3d-shader/ir: Handle integer division by zero in vsir_program_lower_udiv().
This achieves two things:
  - The GLSL backend no longer needs to handle this by itself. Likwise, the
    MSL backend won't have to either.
  - We no longer handle division by zero for DXIL UDiv and URem instructions,
    which leave this undefined.
2025-10-13 19:00:05 +02:00
Henri Verbeet
90cbe25d1e vkd3d-shader/spirv: Do not handle division by zero for VSIR_OP_IDIV or VSIR_OP_IREM.
These correspond to the DXIL SDiv and SRem instructions, for which division by
zero is undefined. Division by zero is also undefined for DXIL UDiv and URem;
addressing those is slightly more involved.
2025-10-13 19:00:05 +02:00
Henri Verbeet
32a6967778 vkd3d-shader/dxil: Ignore ORDERING_SEQCST.
More recent versions of the Vulkan/SPIR-V validation layers have started
to complain about our usage of "SequentiallyConsistent" in our SPIR-V
output. Specifically, VUID-StandaloneSpirv-MemorySemantics-10866 "Memory
Semantics with SequentiallyConsistent memory order must not be used in
the Vulkan API".

The SPIR-V specification says: "If the declared memory model is Vulkan,
SequentiallyConsistent must not be used." However, we're using the
GLSL450 memory model with SPIR-V 1.3, and "Vulkan" is not available
before SPIR-V 1.5.

The Vulkan specification says "Sequentially consistent atomics and
barriers are not supported and SequentiallyConsistent is treated as
AcquireRelease. SequentiallyConsistent should not be used." in the
"Shader Memory Access Ordering" section.

Those don't quite add up to the "... must not be used in the Vulkan
API", from the validation layers, but it does seem clear that
SequentiallyConsistent isn't actually supported. On the DXIL side, when
targetting SPIR-V with dxc, the generated SPIR-V uses the
"None"/"Relaxed" memory semantics. I wasn't immediately able to find a
reference for what seq_cst is supposed to mean in the context of DXIL,
but "None"/"Relaxed" does seem consistent with how the HLSL
atomic/interlocked intrinsics are expected to behave, as well as with
our behaviour for tpf shaders.
2025-10-09 15:39:41 +02:00
Henri Verbeet
d50503f116 vkd3d-shader/spirv: Pass a vsir_data_type to spirv_compiler_emit_interpolation_decorations(). 2025-10-08 13:32:42 +02:00
Henri Verbeet
8bf97a27bf vkd3d-shader/spirv: Pass a vsir_data_type to spirv_compiler_emit_store_dst_swizzled(). 2025-10-08 13:32:42 +02:00
Henri Verbeet
408eb145a6 vkd3d-shader/spirv: Pass a vsir_data_type to spirv_compiler_emit_load_src_with_type(). 2025-10-08 13:32:42 +02:00