vkd3d-shader/hlsl: Only use the temp copy for variables that are written.

This can save a significant amount of temp registers because it allows to
avoid referencing the temp (and having to store it) when not needed.

For instance, this patch lowers the number of required temps for the
following ps_2_0 shader from 24 to 19:

    int i;
    float3x3 mats[4];

    float4 main() : sv_target
    {
        return mul(mats[i], float3(1, 2, 3)).xyzz;
    }

Also, it is needed for SM1 vertex shader relative addressing since
non-constant loads are required to be directly on the uniform ('c'
registers) instead of the temp, and non-constant loads cannot be
transformed by copy propagation.
This commit is contained in:
Francisco Casas
2025-02-03 19:28:25 -03:00
committed by Henri Verbeet
parent 8e6ddb0c1a
commit 321fda9c26
Notes: Henri Verbeet 2025-02-20 16:06:52 +01:00
Approved-by: Henri Verbeet (@hverbeet)
Approved-by: Elizabeth Figura (@zfigura)
Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/1367
2 changed files with 44 additions and 26 deletions

View File

@@ -482,6 +482,9 @@ struct hlsl_ir_var
union hlsl_constant_value_component number;
} *default_values;
/* Pointer to the temp copy of the variable, in case it is uniform. */
struct hlsl_ir_var *temp_copy;
/* A dynamic array containing the state block on the variable's declaration, if any.
* An array variable may contain multiple state blocks.
* A technique pass will always contain one.