Commit Graph

274 Commits

Author SHA1 Message Date
Nikolay Sivov
88caf87789 vkd3d-shader/hlsl: Add a helper to check for a numeric type. 2023-11-15 21:48:49 +01:00
Zebediah Figura
ade8899456 vkd3d-shader/hlsl: Use hlsl_types_are_equal() in func_decl_matches().
Besides reusing code, this now handles UAV types correctly.
2023-11-09 21:15:21 +01:00
Zebediah Figura
8f041fbe6f vkd3d-shader/hlsl: Return bool from compare_function_decl(). 2023-11-09 21:15:19 +01:00
Zebediah Figura
514d179b70 vkd3d-shader/hlsl: Do not consider scalars and 1-dimensional vectors to be equivalent in function parameters. 2023-11-09 21:15:14 +01:00
Zebediah Figura
b1c2852cd7 vkd3d-shader/hlsl: Store function overloads in a list.
The choice to store them in an rbtree was made early on. It does not seem likely
that HLSL programs would define many overloads for any of their functions, but I
suspect the idea was rather that intrinsics would be defined as plain
hlsl_ir_function_decl structures [cf. 447463e590]
and that some intrinsics that could operate on any type would therefore need
many overrides.

This is not how we deal with intrinsics, however. When the first intrinsics were
implemented I made the choice disregard this intended design, and instead match
and convert their types manually, in C. Nothing that has happened in the time
since has led me to question that choice, and in fact, the flexibility with
which we must accommodate functions has led me to believe that matching in this
way was definitely the right choice. The main other designs I see would have
been:

* define each intrinsic variant separately using existing HLSL types. Besides
  efficiency concerns (i.e. this would take more space in memory, and would take
  longer to generate each variant), the normal type-matching rules don't really
  apply to intrinsics.

  [For example: elementwise intrinsics like abs() return the same type as the
  input, including preserving the distinction between float and float1. It is
  legal to define separate HLSL overloads taking float and float1, but trying to
  invoke these functions yields an "ambiguous function call" error.]

* introduce new (semi-)generic types. This is far more code and ends up acting
  like our current scheme (with helpers) in a slightly more complex form.

So I think we can go ahead and rip out this vestige of the original design for
intrinsics.

As for why to change it: rbtrees are simply more complex to deal with, and it
seems unlikely to me that the difference is going to matter. I do not expect any
program to define large quantities of intrinsics; linked list search should be
good enough.
2023-11-09 21:15:11 +01:00
Zebediah Figura
2b59a759d5 vkd3d-shader/hlsl: Rename hlsl_get_func_decl() to hlsl_get_first_func_decl(). 2023-11-09 21:15:09 +01:00
Nikolay Sivov
634ec96b52 vkd3d-shader: Add a missing entry to instruction debug print helper.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:40 +01:00
Nikolay Sivov
4284b7c522 vkd3d-shader/hlsl: Parse ceil() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:37 +01:00
Nikolay Sivov
76e42fbd21 vkd3d-shader/hlsl: Implement ternary operator for SM1.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:31 +01:00
Zebediah Figura
a9f33e8657 vkd3d-shader/hlsl: Consistently use HLSL allocation functions. 2023-11-06 23:09:22 +01:00
Giovanni Mascellani
dd96fe50e2 vkd3d-shader: Dump shaders as soon as possible.
So that they are dumped even if parsing fails, which is a circumstance
in which one likely wants to see the problematic shader.

The downside of that is that for shader types other than HLSL
the profile is not written any more in the filename. This should
not be a big problem, because in those cases the shader describes
its own type.

When dumping an HLSL shader, the id is brought in front of the profile
in the file name, in order to make it more tab-friendly: when dealing
with a directory full of shaders it's likely that the id determines
the profile, but the other way around.
2023-11-02 18:22:26 +01:00
Giovanni Mascellani
ab09c0b45b vkd3d-shader: Expose the whole profile when dumping an HLSL shader.
The profile cannot be reliably devised by analyzing the HLSL code,
so it's useful to have it included in the file name.
2023-11-02 18:22:24 +01:00
Francisco Casas
313df300ad vkd3d-shader/hlsl: Rename hlsl_deref.offset to hlsl_deref.rel_offset.
This field is now analogous to vkd3d_shader_register_index.rel_addr.

Also, it makes sense to rename it now because all the constant part of
the offset is now handled to hlsl_deref.const_offset. Consequently, it
may also be NULL now.
2023-10-31 21:59:19 +01:00
Francisco Casas
1520f327e5 vkd3d-shader/hlsl: Express deref->offset in whole registers.
This is required to use SM4 relative addressing, because it is limited
to whole-register granularity.
2023-10-31 21:59:16 +01:00
Francisco Casas
61a17643a2 vkd3d-shader/hlsl: Split deref-offset into a node and a constant uint.
This uint will be used for the following:

- Since SM4's relative addressing (the capability of passing a register
  as an index to another register) only has whole-register granularity,
  we will need to make the offset node express the offset in
  whole-registers and specify the register component in this uint,
  otherwise we would have to add additional / and % operations in the
  output binary.

- If, after we apply constant folding and copy propagation, we determine
  that the offset is a single constant node, we can store all the offset
  in this uint constant, and remove the offset src.

  This allows DCE to remove a good bunch of the nodes previously required
  only for the offset constants, which makes the output more liteweight
  and readable, and simplifies the implementation of relative addressing
  when writing tpf in the following patches.

In dump_deref(), we use "c" to indicate components instead of whole
registers. Since now both the offset node and the offset uint are in
components a lowered deref would look like:

    var[@42c + 2c]

But, once we express the offset node in whole registers we will remove
the "c" from the node part:

    var[@22 + 3c]
2023-10-31 21:59:14 +01:00
Francisco Casas
81be47c00b vkd3d-shader/hlsl: Introduce hlsl_deref_is_lowered() helper.
Some functions work with dereferences and need to know if they are
lowered yet.

This can be known checking if deref->offset.node is NULL or
deref->data_type is NULL. I am using the latter since it keeps working
even after the following patches that split deref->offset into
constant and variable parts.
2023-10-31 21:59:12 +01:00
Nikolay Sivov
ec8dfa467f vkd3d-shader/hlsl: Add initial support for parsing 'switch' statements.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:58:57 +01:00
Nikolay Sivov
e242b46922 vkd3d-shader/tpf: Convert some of the semantic names to system values names when in compatibility mode.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-19 23:03:23 +02:00
Nikolay Sivov
de860c3cbf vkd3d-shader/hlsl: Parse 'centroid' and 'noperspective' modifiers.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:24 +02:00
Nikolay Sivov
e4b423d6b5 vkd3d-shader/hlsl: Handle 'continue' statements.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:14 +02:00
Francisco Casas
4ab6572be7 vkd3d-shader/hlsl: Replace hlsl_type_get_regset() uses with hlsl_deref_get_regset(). 2023-10-05 16:15:37 +02:00
Francisco Casas
dfce1e7f4a vkd3d-shader/hlsl: Make regset an output argument in hlsl_type_get_component_offset().
Components only span across a single regset, so instead of expecting the
regset as input for the offset, hlsl_type_get_component_offset() can
actually retrieve it.
2023-10-05 16:15:26 +02:00
Giovanni Mascellani
f251da574c vkd3d-shader/hlsl: Remove HLSL_OP3_LERP.
It is unused, and it's not clear whether it would be of any help to
have it.
2023-09-14 20:28:54 +02:00
Nikolay Sivov
1002a6b357 vkd3d-shader/tpf: Use 'movc' to implement ternary operator.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-07 19:15:25 +02:00
Zebediah Figura
9ab77658f2 vkd3d-shader/hlsl: Define smoothstep() in HLSL. 2023-08-30 22:49:01 +02:00
Zebediah Figura
d396c4ce27 vkd3d-shader/hlsl: Store the internal name counter in struct hlsl_ctx.
This is minutely more efficient than using a global variable and atomic instructions.
2023-08-30 22:48:59 +02:00
Zebediah Figura
63e056512d vkd3d-shader/hlsl: Introduce an hlsl_sprintf_alloc() helper. 2023-08-30 22:48:55 +02:00
Zebediah Figura
cf6bc95a3d vkd3d-shader/hlsl: Use hlsl_block_add_instr() in clone_block(). 2023-08-08 21:15:16 +09:00
Zebediah Figura
4ae00cea43 vkd3d-shader/hlsl: Clean up the static_initializers block when the context is destroyed (Valgrind).
This is currently leaked if we fail parsing before reaching codegen.
2023-08-08 21:15:13 +09:00
Zebediah Figura
b22e2113a6 vkd3d-shader/hlsl: Pass a hlsl_block pointer to dump_instr_list(). 2023-08-08 21:15:10 +09:00
Zebediah Figura
0652bb1950 vkd3d-shader/hlsl: Store the "instrs" field of struct hlsl_attribute as a hlsl_block. 2023-08-08 21:15:08 +09:00
Nikolay Sivov
d50b5fe767 vkd3d-shader/hlsl: Parse GetDimensions() method.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-31 21:07:48 +09:00
Nikolay Sivov
bd3d4a6c06 vkd3d-shader: Add compiler option to specify matrix majority.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-24 22:41:09 +02:00
Zebediah Figura
44bf5556ae vkd3d-shader/hlsl: Free the constant defs array in hlsl_ctx_cleanup().
Spotted by Francisco Casas.
2023-07-17 22:56:19 +02:00
Zebediah Figura
a55973d695 vkd3d-shader/hlsl: Lower combined samplers to separate sampler and texture objects for SM4.
Co-authored-by: Francisco Casas <fcasas@codeweavers.com>
2023-07-17 22:55:51 +02:00
Francisco Casas
c4f074d25d vkd3d-shader/hlsl: Introduce hlsl_new_synthetic_var_named(). 2023-07-17 22:55:46 +02:00
Francisco Casas
c58d666d1b vkd3d-shader/hlsl: Handle resource components individually for SM 5.0. 2023-07-17 22:55:40 +02:00
Francisco Casas
ae6bc398d6 vkd3d-shader/hlsl: Allow derefs to provide the data_type.
After lowering the derefs path to a single offset node, there was no way
of knowing the type of the referenced part of the variable. This little
modification allows to avoid having to pass the data type everywhere and
it is required for supporting instructions that reference objects
components within struct types.

Since deref->data_type allows us to retrieve the type of the deref,
deref->offset_regset is no longer necessary.
2023-07-17 22:55:36 +02:00
Francisco Casas
e4d94d955c vkd3d-shader/hlsl: Support fine derivates. 2023-07-04 22:39:12 +02:00
Francisco Casas
ff31284f8d vkd3d-shader/hlsl: Support coarse derivates. 2023-07-04 22:39:10 +02:00
Nikolay Sivov
69f32796b0 vkd3d-shader: Unify static string arrays initialization pattern. 2023-06-28 21:40:21 +02:00
Nikolay Sivov
8d84e206ab vkd3d-shader/hlsl: Parse clip() function.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-06-27 22:33:48 +02:00
Nikolay Sivov
b40179da3a vkd3d-shader/hlsl: Add a parameter for jump nodes and use it for 'discard'. 2023-06-27 22:33:47 +02:00
Stefan Dösinger
5e88ab22aa vkd3d-shader/hlsl: Make sure variants is initialized in declare_predefined_types().
MSVC is too stupid to see it is unused when n_variants=0.
2023-06-27 22:33:31 +02:00
Nikolay Sivov
99314b6340 vkd3d-shader/hlsl: Store static initialization instructions in a block. 2023-06-12 22:50:11 +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
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
Nikolay Sivov
a2e85a8a76 vkd3d-shader/hlsl: Parse SampleCmpLevelZero() method. 2023-05-29 20:21:17 +02:00
Nikolay Sivov
2fd3550ba6 vkd3d-shader/hlsl: Parse SampleCmp() method. 2023-05-29 20:21:14 +02:00