447 Commits

Author SHA1 Message Date
Francisco Casas
7b23cd4d3c vkd3d-shader: Avoid passing NULL to qsort(). (ubsan)
Otherwise ubsan reports runtime errors such as:

    libs/vkd3d-shader/ir.c:4731:5: runtime error: null pointer passed as argument 1, which is declared to never be null
2025-01-10 19:51:55 +01:00
Francisco Casas
eaf4d0bfbf vkd3d-shader: Avoid passing NULL to memcpy(). (ubsan)
Otherwise when passing "-fsanitize=undefined" to the compiler, ubsan
reports such as:

   libs/vkd3d-shader/ir.c:3794:5: runtime error: null pointer passed as argument 1, which is declared to never be null
2025-01-10 19:51:43 +01:00
Giovanni Mascellani
4f7eb890ef vkd3d-shader/ir: Validate OUTCONTROLPOINT source parameters. 2024-12-19 21:06:13 +01:00
Giovanni Mascellani
495e10e93b vkd3d-shader/ir: Validate INCONTROLPOINT source parameters. 2024-12-19 21:06:13 +01:00
Giovanni Mascellani
513609ef0e vkd3d-shader/ir: Validate INPUT source parameters. 2024-12-19 21:06:13 +01:00
Giovanni Mascellani
23d4bd1dae vkd3d-shader/ir: Validate PATCHCONST source parameters using a uniform helper. 2024-12-19 21:06:13 +01:00
Giovanni Mascellani
67420aa8b6 vkd3d-shader/ir: Validate OUTPUT source parameters using a uniform helper. 2024-12-19 21:06:13 +01:00
Giovanni Mascellani
7de7025750 vkd3d-shader/ir: Disallow array signature elements for normalisation levels < SM6. 2024-12-19 21:06:13 +01:00
Elizabeth Figura
3c53293028 vkd3d-shader/ir: Separate VKD3DSPR_OUTPUT and VKD3DSPR_TEXCRDOUT.
This simplifies the IR.
2024-12-18 17:30:16 +01:00
Elizabeth Figura
8132239ed2 vkd3d-shader/ir: Separate VKD3DSPR_ADDR and VKD3DSPR_TEXTURE.
This simplifies the IR.
2024-12-18 17:30:16 +01:00
Elizabeth Figura
65f3f56f63 vkd3d-shader/d3dbc: Normalize to a single VKD3DSPR_CONST register set when reading.
We don't need VKD3DSPR_CONST2 et al in the IR, even for disassembly.
2024-12-18 17:30:16 +01:00
Francisco Casas
825784322d vkd3d-shader/ir: Properly lower texldp. 2024-12-18 17:30:15 +01:00
Francisco Casas
7cc802afd7 vkd3d-shader/ir: Properly lower texldb. 2024-12-18 17:27:43 +01:00
Giovanni Mascellani
a68fd1b0de vkd3d-shader/ir: Simplify shader_register_normalise_arrayed_addressing().
The two branches do essentially the same thing, but in different
ways and each one omitting different details. In particular there
is no need to discriminate on whether the register is a relative
address, we can just copy the NULL pointer.
2024-12-17 16:44:00 +01:00
Giovanni Mascellani
3db458697e vkd3d-shader/ir: Remove a redundant assignment.
The hull shader control point normalisation pass already ensures
that output registers in the control point phase have two
indices (the control point index and the register index).
2024-12-17 16:44:00 +01:00
Giovanni Mascellani
00538c377e vkd3d-shader/ir: Validate OUTCONTROLPOINT destination parameters. 2024-12-17 16:39:32 +01:00
Giovanni Mascellani
3dc7f322cc vkd3d-shader/ir: Validate INCONTROLPOINT destination parameters. 2024-12-17 16:39:32 +01:00
Giovanni Mascellani
7d87b4e869 vkd3d-shader/ir: Validate OUTPUT destination parameters. 2024-12-17 16:39:32 +01:00
Giovanni Mascellani
b194e5dc4e vkd3d-shader/ir: Validate PATCHCONST destination parameters using a uniform helper. 2024-12-17 16:39:32 +01:00
Giovanni Mascellani
38a5c905db vkd3d-shader/ir: Validate INPUT destination parameters using a uniform helper. 2024-12-17 16:39:32 +01:00
Giovanni Mascellani
8d4b790eb2 vkd3d-shader/ir: Represent information about I/O registers with a table.
It makes the code quite longer, but also easier to read and extend
with further properties.

A (desirable) side effect of this commit is that it is checked
whether I/O register types are legal depending on the shader type
and phase, while before that was assumed.

This commit introduces enum vsir_io_reg_type and enum vsir_phase
which shadow enum vkd3d_shader_register_type and enum
vkd3d_shader_opcode, with the goal of making the data tables
smaller.
2024-12-17 16:39:32 +01:00
Giovanni Mascellani
dd0ed989a1 vkd3d-shader/d3dbc: Normalise I/O register write masks when not disassembling.
Sometimes SM1-3 shaders contain write masks that exceed the
signature element masks. That happens because SM1-3 shaders do not
have a concept of signature and signature masks, and OTOH aren't
always able to express any given write mask.

In VSIR we don't want to deal with I/O register masks exceeding the
corresponding signature element mask or usage mask, because, for
instance, for higher shader models it can complicate dealing with
DCL_INDEX_RANGE. In order to have uniform rules for all shader
models we normalise masks coming from SM1-3 shaders.

We don't do that normalisation when disassembling, in order to
preserve the expected output.
2024-12-12 17:21:49 +01:00
Giovanni Mascellani
64126a00c3 vkd3d-shader/ir: Give more meaningful names to I/O normalisation levels.
The previous names "not normalised" and "fully normalised" have meanings
which are likely to change with time. OTOH including a description of the
normalisation level in the enumerant seems excessive. Relating
normalisation levels to shader model versions might be a reasonable
compromise.
2024-12-12 17:21:49 +01:00
Elizabeth Figura
77843aa837 vkd3d-shader/ir: Always initialise "*control_point_count" in vsir_signature_from_register_type().
Avoid a spurious -Wmaybe-uninitialized warning.
2024-12-11 15:33:06 +01:00
Giovanni Mascellani
c1df64b3a6 vkd3d-shader/ir: Check that signature elements do not conflict with each other. 2024-12-09 16:11:34 +01:00
Giovanni Mascellani
b6a00579a2 vkd3d-shader/ir: Validate the signature element register index, for some sysvals. 2024-12-09 16:11:34 +01:00
Giovanni Mascellani
59a3a8e2d6 vkd3d-shader/ir: Validate the signature element stream index. 2024-12-09 16:11:34 +01:00
Giovanni Mascellani
db5a3197b7 vkd3d-shader/ir: Validate the register index and count for signature elements. 2024-12-09 16:11:34 +01:00
Giovanni Mascellani
267c70fa55 vkd3d-shader/ir: Check that signature element masks are left-aligned with in a DCL_INDEX_RANGE. 2024-12-09 16:10:47 +01:00
Giovanni Mascellani
703da18955 vkd3d-shader/ir: Check that the DCL_INDEX_RANGE effective mask stabilizes after one iteration. 2024-12-09 16:10:47 +01:00
Giovanni Mascellani
74fa51d57c vkd3d-shader/ir: Check that DCL_INDEX_RANGE ranges do not overlap with unrelated signature elements. 2024-12-05 21:06:31 +01:00
Giovanni Mascellani
aae0a74d60 vkd3d-shader/ir: Validate the DCL_INDEX_RANGE instruction. 2024-12-05 21:06:31 +01:00
Giovanni Mascellani
38c53dca08 vkd3d-shader/ir: Introduce a helper function to determine the signature for a register type. 2024-12-05 21:05:50 +01:00
Giovanni Mascellani
b5e1c45827 vkd3d-shader/ir: Validate the register type for registers used as relative addresses. 2024-12-05 21:00:43 +01:00
Giovanni Mascellani
abf7a91834 vkd3d-shader/ir: Validate the array index when it is statically known. 2024-12-05 21:00:43 +01:00
Giovanni Mascellani
82963035e9 vkd3d-shader/ir: Validate the control point index when it is statically known. 2024-12-04 14:36:36 +01:00
Giovanni Mascellani
1c93d706d7 vkd3d-shader/ir: Merge removing I/O declarations in the general instruction lowering pass. 2024-12-03 14:36:13 +01:00
Giovanni Mascellani
4717775abb vkd3d-shader/ir: Remove I/O declarations before flattening hull shader phases. 2024-12-03 14:19:50 +01:00
Giovanni Mascellani
4ef946287c vkd3d-shader/ir: Remove I/O declarations before normalising hull shader control point I/O. 2024-12-03 14:19:50 +01:00
Giovanni Mascellani
66382f0d68 vkd3d-shader/ir: Remove I/O declarations before I/O normalisation. 2024-12-03 14:19:50 +01:00
Giovanni Mascellani
18e422dfe4 vkd3d-shader/ir: Encode I/O declarations in vsir_program.
Most I/O registers are already described by the shader signatures.
The registers that are not do not have any property other then
being used by the program or not, so they can be collectively
described with a bitmap.
2024-12-03 14:19:24 +01:00
Elizabeth Figura
d56601c8d0 vkd3d-shader/ir: Implement exponential fog. 2024-12-02 17:12:20 +01:00
Elizabeth Figura
1fbbc82f3a vkd3d-shader/ir: Allow controlling the fog source through a parameter. 2024-12-02 17:12:16 +01:00
Elizabeth Figura
fc98cb482f vkd3d-shader/ir: Add a couple of traces for signature remapping. 2024-12-02 17:12:13 +01:00
Elizabeth Figura
f86d1e72a4 vkd3d-shader/ir: Allow controlling fog through parameters.
Fog requires several parameters to even implement the most basic of
functionality correctly, so this commit is relatively large.
2024-12-02 17:12:06 +01:00
Giovanni Mascellani
9e0c02a0ea vkd3d-shader/ir: Evaluate OUTCONTROLPOINT usage in the patch constant phase directly.
Instead of using DCL_INPUT.

The main goal here is to eventually get rid of the I/O
declaration instructions. A positive side effect is that we don't
add a useless barrier to shaders which have a DCL_INPUT instruction
in the patch constant phase but don't actually read OUTCONTROLPOINT
registers.
2024-11-27 13:59:39 +01:00
Giovanni Mascellani
1cfe23569c vkd3d-shader/ir: Synthesize the default control point phase in the HS control point I/O normaliser.
This makes it available to all backends, without requiring an
ad-hoc solution for each of them. It also gets rid of an
undocumented flag we're currently passing to
DCL_CONTROL_POINT_PHASE.
2024-11-27 13:57:09 +01:00
Giovanni Mascellani
2c3a7b0dd9 vkd3d-shader/ir: Validate the register type for DCL_OUTPUT_SIV instructions. 2024-11-25 20:51:29 +01:00
Giovanni Mascellani
3832e38ce0 vkd3d-shader/ir: Validate the register type for DCL_OUTPUT instructions. 2024-11-25 20:51:25 +01:00
Giovanni Mascellani
e7770eaaf6 vkd3d-shader/ir: Validate the register type for DCL_INPUT_PS_SGV instructions. 2024-11-25 20:48:39 +01:00