Commit Graph

1786 Commits

Author SHA1 Message Date
Zebediah Figura
1c1f1094a5 vkd3d-shader/hlsl: Handle reserved vars specially in get_allocated_object(). 2023-06-22 22:00:16 +02:00
Francisco Casas
c1ca0dafe8 vkd3d-shader/d3dbc: Avoid hlsl_type_get_regset() in d3dbc.c.
In SM1 we can expect all variables to always belong to a single regset.
structs in particular, should always be allocated to HLSL_REGSET_NUM,
since they are only allowed if all their components are numeric.

We are not covering the structs case because of the use of
hlsl_type_get_regset(), which is currently not defined for structs.

So the current shader

    struct
    {
        float4 a;
        float4 b;
    } apple;

    float4 main() : sv_target
    {
        return apple.a + apple.b;
    }

fails with

    vkd3d/libs/vkd3d-shader/hlsl.c:224: Aborting, reached unreachable code.

The solution is to iterate over all regsets to find the one where the
variable is allocated (if any), and ignore all others.
2023-06-22 22:00:14 +02:00
Conor McCarthy
bce2a898b3 vkd3d-shader/spirv: Take ownership of the shader signatures in spirv_compiler_create().
Fixes leakage of the replacement elements in shader_signature_merge().
2023-06-19 22:44:07 +02:00
Zebediah Figura
df0a031ad8 vkd3d-shader/spirv: Retrieve input sysvals from the signature for geometry shaders as well.
This only affects clip and cull distances. The HLSL compiler emits these using
dcl_input, but the previous shader (vertex or TES) will write them as a SPIRV
builtin, and hence we want to read this as a SPIRV builtin as well.

This fixes validation errors in Wine's test_clip_distance().
2023-06-12 22:50:19 +02:00
Nikolay Sivov
d856be0519 vkd3d-shader/hlsl: Handle static constants in array size expressions. 2023-06-12 22:50:12 +02:00
Nikolay Sivov
99314b6340 vkd3d-shader/hlsl: Store static initialization instructions in a block. 2023-06-12 22:50:11 +02:00
Francisco Casas
5dee6561c2 vkd3d-shader/hlsl: Fold redundant casts again after lower narrowing casts.
lower_narrowing_casts() currently creates a new cast calling
hlsl_new_cast(). This cast may be redundant, but it is not folded, which
is making SM1 emit an unnecessary fixme in some shaders:

    Aborting due to not yet implemented feature: SM1 "cast" expression.

Other passes that call hlsl_new_cast() are lower_int_division() and
lower_int_modulus(), so the new fold_redundant_casts() pass is called
after these as well.
2023-06-08 23:21:40 +02:00
Zebediah Figura
f34b107faf vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_constant(). 2023-06-08 18:50:35 +02:00
Zebediah Figura
740b0ad807 vkd3d-shader/hlsl: Pass a hlsl_constant_value pointer to hlsl_new_constant(). 2023-06-08 18:50:34 +02:00
Zebediah Figura
79f443d131 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_or(). 2023-06-08 18:50:32 +02:00
Zebediah Figura
1049f489bb vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_and(). 2023-06-08 18:50:31 +02:00
Zebediah Figura
a7a09ac5ef vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_bit_xor(). 2023-06-08 18:50:30 +02:00
Zebediah Figura
974528cbe3 vkd3d-shader/hlsl: Only read used coordinates in encode_texel_offset_as_aoffimmi().
The V and W offsets may be uninitialized, which may spuriously trigger "out of range" errors.
2023-06-08 18:50:28 +02:00
Zebediah Figura
7b476573ff vkd3d-shader/hlsl: Use the writemask to map the coords swizzle for load instructions.
Instead of modifying the swizzle after calling sm4_src_from_node().

This fixes the case where sm4_src_from_node() returns an immediate constant.

Fixes: a471c5567a
2023-06-08 18:50:26 +02:00
Francisco Casas
ebf7573571 vkd3d-shader/hlsl: Support non-constant vector indexing.
Non-constant vector indexing is not solved with relative addressing
in the register indexes because this indexation cannot be at the level
of register-components.

Mathematical operations must be used instead.
2023-06-07 20:48:59 +02:00
Francisco Casas
6cfa8cf859 vkd3d-shader/hlsl: Lower dot for non-float types. 2023-06-07 20:48:58 +02:00
Francisco Casas
441902bb85 vkd3d-shader/hlsl: Introduce transform_derefs(). 2023-06-07 20:48:57 +02:00
Nikolay Sivov
82ddc6b417 vkd3d-shader/hlsl: Fix sampler type used for samplerCUBE. 2023-06-05 22:27:36 +02:00
Nikolay Sivov
ccad49d486 vkd3d-shader/d3d-asm: Fix 3D sampler declaration instruction name. 2023-06-05 22:27:33 +02:00
Giovanni Mascellani
7c360330d7 vkd3d-shader/tpf: Do not emit HLSL_IR_CONSTANT instructions.
Since constants are now inlined.
2023-05-29 20:21:29 +02:00
Giovanni Mascellani
a471c5567a vkd3d-shader/tpf: Emit constant values inline. 2023-05-29 20:21:27 +02:00
Giovanni Mascellani
a7de09d418 vkd3d-shader/tpf: Move sm4_src_from_constant_value() above.
So that it can be used by sm4_src_from_node() in later commits.
2023-05-29 20:21:25 +02:00
Giovanni Mascellani
4ecd3af2af vkd3d-shader/tpf: Use a semicolon to separate statements. 2023-05-29 20:21:23 +02:00
Nikolay Sivov
a2e85a8a76 vkd3d-shader/hlsl: Parse SampleCmpLevelZero() method. 2023-05-29 20:21:17 +02:00
Nikolay Sivov
c33219c97b vkd3d-shader/tpf: Write out comparison mode sampler declarations and corresponding sampling instruction. 2023-05-29 20:21:16 +02:00
Nikolay Sivov
2fd3550ba6 vkd3d-shader/hlsl: Parse SampleCmp() method. 2023-05-29 20:21:14 +02:00
Nikolay Sivov
7c94705c54 vkd3d-shader/hlsl: Parse SamplerComparisonState objects. 2023-05-29 20:21:11 +02:00
Nikolay Sivov
efe107d231 vkd3d-shader/hlsl: Use a function table for object methods handlers. 2023-05-29 20:21:10 +02:00
Nikolay Sivov
87cd3f872b vkd3d-shader/hlsl: Move object type checks to methods handlers. 2023-05-29 20:21:07 +02:00
Jan Sikorski
bb680e73de vkd3d-shader/spirv: Ensure that the OpLabel emitted vkd3d_spirv_builder_begin_main_function() gets terminated. 2023-05-26 19:11:55 +02:00
Zebediah Figura
b453a0acd6 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_abs(). 2023-05-26 19:11:46 +02:00
Zebediah Figura
c805eb1191 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_min(). 2023-05-26 19:11:44 +02:00
Zebediah Figura
aa82f61ef3 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_max(). 2023-05-26 19:11:42 +02:00
Zebediah Figura
ad0ab664d2 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_mod(). 2023-05-26 19:11:39 +02:00
Zebediah Figura
c8b7dbebe4 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_div(). 2023-05-26 19:11:36 +02:00
Conor McCarthy
f4778b727d vkd3d-shader/spirv: Use the register index count in shader_register_clone_relative_addresses(). 2023-05-26 19:11:15 +02:00
Conor McCarthy
4a64cf74c3 vkd3d-shader/spirv: Use the register index count in I/O relative address assertions. 2023-05-26 19:11:07 +02:00
Conor McCarthy
06dd0ccd4c vkd3d-shader/spirv: Use the register index count in I/O register assertions. 2023-05-26 19:11:03 +02:00
Conor McCarthy
178a7677e2 vkd3d-shader/spirv: Use the register index count in shader_register_get_io_indices(). 2023-05-26 19:11:02 +02:00
Conor McCarthy
d46250a59b vkd3d-shader/spirv: Use the register index count in default register dereferences. 2023-05-26 19:11:00 +02:00
Conor McCarthy
a2b3f70d8e vkd3d-shader/spirv: Use the register index count in aggregate register dereferences. 2023-05-26 19:10:58 +02:00
Conor McCarthy
ad08864134 vkd3d-shader/spirv: Use the register index count in spirv_compiler_get_register_name(). 2023-05-26 19:10:56 +02:00
Conor McCarthy
b3927726cc vkd3d-shader/spirv: Use the register index count in non-I/O variable registers in vkd3d_symbol_make_register(). 2023-05-26 19:10:54 +02:00
Conor McCarthy
ec5f195b6b vkd3d-shader/spirv: Use the register index count in I/O registers in vkd3d_symbol_make_register(). 2023-05-26 19:10:52 +02:00
Conor McCarthy
532fe01818 vkd3d-shader/spirv: Set the register index count in spirv_compiler_emit_default_control_point_phase(). 2023-05-26 19:10:49 +02:00
Conor McCarthy
9c6040df02 vkd3d-shader/spirv: Set the register index count in spirv_compiler_emit_dcl_indexable_temp(). 2023-05-26 19:10:47 +02:00
Conor McCarthy
bf1ecc0f60 vkd3d-shader/spirv: Set the register index count in spirv_compiler_emit_hull_shader_builtins(). 2023-05-26 19:10:33 +02:00
Conor McCarthy
7e58511b76 vkd3d-shader/spirv: Set the register index count in spirv_compiler_get_invocation_id(). 2023-05-26 19:10:30 +02:00
Ethan Lee
ea7d8c65bd vkd3d-shader/tpf: Add support for emitting sample_l instructions.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-05-24 22:00:41 +02:00
Conor McCarthy
6835e8176f vkd3d-shader/ir: Normalise signatures and input/output registers to the Shader Model 6 pattern.
In Shader Model 6 each signature element can span a range of register
indices, or 'rows', and system values do not share a register index with
non-system values. Inputs and outputs are referenced by element index
instead of register index. This patch merges multiple signature elements
into a single element under the following conditions:

- The register index in a load or store is specified dynamically by
  including a relative address parameter with a base register index. The
  dcl_index_range instruction is used to identify these.
- A register declaration is split across multiple elements which declare
  different components of the register.
- A patch constant function writes tessellation factors. These are an
  array in SPIR-V, but in SM 5.x each factor is declared as a separate
  register, and these are dynamically indexed by the fork/join instance
  id. Elimination of multiple fork/join phases converts the indices to
  constants, but merging the signature elements into a single arrayed
  element matches the SPIR-V output.

All references to input/output register indices are converted to element
indices. If a relative address is present, the element index is moved up
a slot so it cannot be confused with a constant offset. Existing code
only handles register index relative addressing for tessellation factors.
This patch adds generic support for it.
2023-05-24 22:00:29 +02:00
Conor McCarthy
110e48e54d vkd3d-shader/ir: Eliminate struct vkd3d_shader_normaliser. 2023-05-24 22:00:28 +02:00
Conor McCarthy
31682c52c7 vkd3d-shader/spirv: Support emitting multi-dimensional array variables. 2023-05-24 22:00:27 +02:00
Francisco Casas
e060773c19 vkd3d-shader/hlsl: Extend the liveness of nodes produced outside loops.
Otherwise, it is possible that the register used by the temp is
overridden by a subsequent instruction within the same loop.
2023-05-24 22:00:21 +02:00
Zebediah Figura
855bb71f6d vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_nequal(). 2023-05-23 21:08:22 +02:00
Zebediah Figura
d565caafb5 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_mul(). 2023-05-23 21:08:21 +02:00
Zebediah Figura
623cd94997 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_add(). 2023-05-23 21:08:20 +02:00
Zebediah Figura
7d9b24fe11 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_neg(). 2023-05-23 21:08:19 +02:00
Zebediah Figura
eb04829e66 vkd3d-shader/hlsl: Pass hlsl_constant_value and hlsl_type pointers to fold_cast(). 2023-05-23 21:08:17 +02:00
Ethan Lee
24d4ab7fb3 vkd3d-shader/hlsl: Add support for SampleGrad() method.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-05-23 21:07:49 +02:00
Nikolay Sivov
cf8cacd336 vkd3d-shader/hlsl: Improve UAV format type checking for buffer types.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-05-22 22:03:27 +02:00
Nikolay Sivov
cff22ecde8 vkd3d-shader/hlsl: Add support for writing RWStructuredBuffer declarations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-05-22 22:03:26 +02:00
Nikolay Sivov
3de824bfd8 vkd3d-shader/hlsl: Add support for RWBuffer object.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-05-22 22:03:24 +02:00
Nikolay Sivov
44a90f5d41 vkd3d-shader: Fix dcl_uav_typed_* formatting.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-05-22 22:03:24 +02:00
Ethan Lee
fb9328d030 vkd3d-shader/hlsl: Fold constant integral abs().
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-05-22 22:03:18 +02:00
Nikolay Sivov
dfa0076473 vkd3d-shader/hlsl: Add support for sample index argument in Load(). 2023-05-22 22:03:12 +02:00
Nikolay Sivov
dc41444941 vkd3d-shader/hlsl: Convert ternary operator true/false values to a common type. 2023-05-09 21:51:46 +02:00
Conor McCarthy
be4a71da7d vkd3d-shader/tpf: Validate input and output index ranges for default control point phases. 2023-05-09 21:51:33 +02:00
Conor McCarthy
3e50c4d13b vkd3d-shader/tpf: Remove an unnecessary carriage return from a parser error message. 2023-05-09 21:51:32 +02:00
Conor McCarthy
6dd1b01284 vkd3d-shader/tpf: Validate index range declarations. 2023-05-09 21:51:31 +02:00
Conor McCarthy
d565fbdcd6 vkd3d-shader/tpf: Validate input/output registers. 2023-05-09 21:51:29 +02:00
Conor McCarthy
2166088b0b vkd3d-shader/tpf: Validate signature element masks. 2023-05-09 21:51:28 +02:00
Conor McCarthy
b8e6482365 vkd3d-shader/tpf: Validate signature element register indices. 2023-05-09 21:51:19 +02:00
Conor McCarthy
adf7db021c vkd3d-shader/tpf: Validate input/output register index counts. 2023-05-09 21:51:17 +02:00
Zebediah Figura
b1bc4044ae vkd3d-shader/hlsl: Use %option nodefault in the lexer. 2023-05-09 21:51:09 +02:00
Zebediah Figura
600fdcd112 vkd3d-shader/hlsl: Lex invalid characters in #line directives.
Avoid letting them fall through to the default rule.
2023-05-09 21:51:08 +02:00
Zebediah Figura
7b8845474d vkd3d-shader/preproc: Use %option nodefault in the lexer. 2023-05-09 21:51:06 +02:00
Zebediah Figura
871cf0b4b5 vkd3d-shader/preproc: Ignore newlines in C comments.
Avoid letting them fall through to the default rule.
2023-05-09 21:51:05 +02:00
Zebediah Figura
ddbfd88e74 vkd3d-shader/preproc: Lex whitespace and invalid characters in #include and #line directives.
Avoid letting them fall through to the default rule.

A syntax error will be emitted by the parser.
2023-05-09 21:51:01 +02:00
Zebediah Figura
da7670f7c8 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from add_conditional(). 2023-05-09 21:50:37 +02:00
Zebediah Figura
39bbac3cca vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_uint_constant(). 2023-05-09 21:50:36 +02:00
Zebediah Figura
b991f98e2f vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_swizzle(). 2023-05-09 21:50:35 +02:00
Zebediah Figura
306ae40696 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_store_index(). 2023-05-09 21:50:34 +02:00
Zebediah Figura
29a2b87f54 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_simple_store(). 2023-05-09 21:50:33 +02:00
Zebediah Figura
145a2dfd2d vkd3d-shader/hlsl: Return bool from hlsl_new_store_component(). 2023-05-09 21:50:31 +02:00
Francisco Casas
fd38c58112 vkd3d-shader/hlsl: Introduce hlsl_calloc().
This is just a wrapper of vkd3d_calloc(), that has the advantage of
checking for multiplication overflow.
2023-05-08 20:24:15 +02:00
Francisco Casas
ef7cf9b1ad vkd3d-shader/hlsl: Support resource arrays when writting SM4.
The new fixmes can be triggered in presence of object components within
structs (for SM5).

In shaders such as this one:

    struct apple
    {
        Texture2D tex : TEX;
        float4 color : COLOR;
    };

    float4 main(struct apple input) : sv_target
    {
        return input.tex.Load(int3(1, 2, 3));
    }

Or this one:

    struct
    {
        Texture2D tex;
        float4 color;
    } s;

    float4 main() : sv_target
    {
        return s.tex.Load(int3(1, 2, 3));
    }
2023-05-08 20:24:15 +02:00
Francisco Casas
a91e6d4563 vkd3d-shader/hlsl: Write resource loads in SM1. 2023-05-08 20:24:15 +02:00
Francisco Casas
96c844ffb8 vkd3d-shader/hlsl: Write sampler declarations in SM1. 2023-05-08 20:24:15 +02:00
Francisco Casas
3e9a9c5051 vkd3d-shader/hlsl: Track objects sampling dimension. 2023-05-08 20:24:15 +02:00
Francisco Casas
4dba38e6c8 vkd3d-shader/hlsl: Track object components usage and allocate registers accordingly. 2023-05-08 20:24:14 +02:00
Francisco Casas
6f71077e3e vkd3d-shader/hlsl: Skip object components when creating input/output copies. 2023-05-08 20:22:19 +02:00
Francisco Casas
4413f6b64b vkd3d-shader/hlsl: Add fixme for uniform copies for objects within structs. 2023-05-08 20:22:17 +02:00
Francisco Casas
69ff249ef4 vkd3d-shader/hlsl: Support multiple-register variables in object regsets.
Variables that contain more than one object (arrays or structs) require
the allocation of contiguous registers in the respective object
register spaces.
2023-05-08 20:22:14 +02:00
Nikolay Sivov
7516adeeae vkd3d-shader/hlsl: Add support for fmod() intrinsic. 2023-05-08 20:21:52 +02:00
Zebediah Figura
8b57a612d7 vkd3d-shader/hlsl: Map the colour output for ps_1_* to r0. 2023-05-03 21:12:39 +02:00
Zebediah Figura
b2959739ed vkd3d-shader/hlsl: Rewrite the register allocator to allow allocating in multiple passes.
We will need this in order to allocate some "special" registers: ps_1_* output, sincos output, etc.
2023-05-03 21:12:38 +02:00
Zebediah Figura
71d8ff85c6 vkd3d-shader/hlsl: Avoid leaking the allocator register map in allocate_const_registers(). 2023-05-03 21:12:37 +02:00
Zebediah Figura
c57ac0b207 vkd3d-shader/hlsl: Rename struct liveness to struct register_allocator. 2023-05-03 21:12:34 +02:00
Conor McCarthy
a0a18b1620 vkd3d-shader: Introduce an internal shader signature structure.
A register count is required for Shader Model 6 signatures, including
those normalised from earlier models.
2023-05-03 21:12:07 +02:00
Conor McCarthy
5ae068168c vkd3d-shader/tpf: Return an error from vkd3d_shader_sm4_parser_create() if the parser failed. 2023-05-03 21:12:06 +02:00