Commit Graph

429 Commits

Author SHA1 Message Date
Francisco Casas
cfac67ccc2 vkd3d-shader/hlsl: Cast slt before multiplying on ternary operator.
Otherwise we may get a failing
    "hlsl_types_are_equal(arg1->data_type, arg2->data_type)"
assertion on hlsl_new_binary_expr() when creating the MUL.

This happens in the test introducing in the following patch:

    int a, b, c;

    void main(out float4 res : COLOR1, in float4 pos : position, out float4 out_pos : sv_position)
    {
        out_pos = pos;

        res = a ? b/1000.0 : c/1000.0;
    }
2024-03-11 22:09:42 +01:00
Francisco Casas
747511131d vkd3d-shader/hlsl: Lower non-float operators for SM1. 2024-03-06 23:04:05 +01:00
Francisco Casas
a3319339e4 vkd3d-shader/hlsl: Lower casts to int using REINTERPRET instead.
I realized that it is better to lower casts to int to FLOOR+REINTERPET
instead of appending a FLOOR to all casts to int and assuming that this
is the case for all of them in d3dbc.c.

This in case we introduce new passes in the future that add casts that
we forget to lower, after the lower_casts_to_bool pass.
2024-03-06 23:04:04 +01:00
Nikolay Sivov
937d76507d vkd3d-shader/hlsl: Implement ternary operator for older vertex profiles.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56333
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-03-06 23:03:59 +01:00
Henri Verbeet
49d14613a5 vkd3d-shader/hlsl: Introduce hlsl_type.e.resource. 2024-02-21 23:23:06 +01:00
Nikolay Sivov
c107ec03b8 vkd3d-shader/fx: Add initial support for writing buffers descriptions.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-02-19 21:12:08 +01:00
Francisco Casas
e3ed5ac77e vkd3d-shader/hlsl: Lower casts to int for SM1. 2024-02-15 23:29:39 +01:00
Francisco Casas
13f713f74b vkd3d-shader/hlsl: Turn register(cX) reservations into buffer offset for SM4. 2024-01-29 22:33:27 +01:00
Francisco Casas
c7f7636534 vkd3d-shader/hlsl: Make register(cX) reservations work for SM1. 2024-01-29 22:33:25 +01:00
Zebediah Figura
a5549bae38 vkd3d-shader/hlsl: Do not try to lower ternaries of types other than scalar or vector. 2024-01-17 22:28:49 +01:00
Francisco Casas
43ff28b00b vkd3d-shader/hlsl: Emit fixmes on non-constant vector addressing.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56162

Storing to a vector component using a non-constant index is not allowed
on profiles lower than 6.0. Unless this happens inside a loop that can be
unrolled, which we are not doing yet.

For this reason, a validate_nonconstant_vector_store_derefs pass is
added to detect these cases.

Ideally we would want to emit an hlsl_error on this pass, but before
implementing loop unrolling, we could reach this point on valid HLSL.

Also, as pointed out by Nikolay in the mentioned bug, currently
new_offset_from_path_index() fails an assertion when this happens,
because it expects an hlsl_ir_constant, so a check is added.
It also felt correct to emit an hlsl_fixme there, despite the
redundancy.
2024-01-15 19:57:12 +01:00
Henri Verbeet
3344c4e93d vkd3d-shader/hlsl: Store modifier flags as a uint32_t. 2024-01-08 21:45:26 +01:00
Henri Verbeet
fafe2a1dba vkd3d-shader/hlsl: Store swizzles as a uint32_t. 2024-01-08 21:45:24 +01:00
Zebediah Figura
dfea1abbd8 vkd3d-shader/hlsl: Avoid shadowing "jump" in normalize_switch_cases(). 2023-12-07 21:57:33 +01:00
Zebediah Figura
46e135f6a7 vkd3d-shader/hlsl: Avoid shadowing "load" in lower_index_loads().
Found with -Wshadow.
2023-12-07 21:57:16 +01:00
Francisco Casas
736f3ae2df vkd3d-shader/hlsl: Use values at the time of the swizzle's load in copy-propagation.
This preempts us from replacing a swizzle incorrectly, as in the
following example:

    1: A.x = 1.0
    2: A
    3: A.x = 2.0
    4: @2.x

were @4 ends up being 2.0 instead of 1.0, because that's the value stored in
A.x at time 4, and we should be querying it at time 2.

This also helps us to avoid replacing a swizzle with itself in copy-prop
which can result in infinite loops, as with the included tests this commit.

Consider the following sequence of instructions:

    1 : A
    2 : B = @1
    3 : B
    4 : A = @3
    5 : @1.x

Current copy-prop would replace 5 so it points to @3 now:

    1 : A
    2 : B = @1
    3 : B
    4 : A = @3
    5 : @3.x

But in the next iteration it would make it point back to @1, keeping it
spinning infinitively.

The solution is to index the instructions and don't replace the swizzle
if the new load happens after the current load.
2023-11-29 22:53:24 +01:00
Francisco Casas
d877b877b3 vkd3d-shader/hlsl: Record trace of stored values in copy-propagation.
Instead of only storing the value that each variable's component has at
the moment of the instruction currently handled by copy-prop, we store
the trace of all the historic values with their timestamps, i.e. the
instruction index on which the value was stored.

This would allow us to query the value that the variable had at the time
of execution of previous instructions.
2023-11-29 22:53:21 +01:00
Francisco Casas
539294daea vkd3d-shader/hlsl: Move index_instructions() up. 2023-11-29 22:53:19 +01:00
Zebediah Figura
2d1825bb89 vkd3d-shader/hlsl: Remove an unnecessary local variable in copy_propagation_get_value().
Found with -Wshadow.
2023-11-28 00:09:53 +01:00
Jacek Caban
85f21f197c vkd3d-shader: Avoid implicit enum pointer casts in allocate_semantic_register. 2023-11-28 00:09:29 +01:00
Nikolay Sivov
88caf87789 vkd3d-shader/hlsl: Add a helper to check for a numeric type. 2023-11-15 21:48:49 +01:00
Nikolay Sivov
dd6a9135f4 vkd3d-shader/hlsl: Implement tex2Dproj().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-10 20:23:41 +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
Nikolay Sivov
9a70ae5b6a vkd3d-shader: Add support for floor() on SM1-3.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:40 +01:00
Nikolay Sivov
aaef82e680 vkd3d-shader: Add support for ceil() on SM1-3.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-11-08 22:49:40 +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
f0a6c7de1d vkd3d-shader/hlsl: Record partial allocations in allocate_range(). 2023-11-07 22:26:11 +01:00
Zebediah Figura
c683fc9402 vkd3d-shader/hlsl: Check that a partial register's mask is also available in is_range_available(). 2023-11-07 22:26:10 +01:00
Nikolay Sivov
31346e2cba vkd3d-shader/tpf: Fix used temp registers accounting for dcl_temps.
Otherwise we always output "dcl_temps 1" even when no temp registers were used.
2023-11-06 23:08:10 +01:00
Francisco Casas
eef2163375 vkd3d-shader/tpf: Declare indexable temps.
If var->indexable, then the variable is given a unique register number,
regardless of its lifetime.
2023-10-31 21:59:22 +01:00
Francisco Casas
83c313ecc6 vkd3d-shader/hlsl: Mark vars that require non-constant dereferences. 2023-10-31 21:59:21 +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
74767beaf6 vkd3d-shader/hlsl: Absorb hlsl_ir_constant deref offsets into const_offset. 2023-10-31 21:59:18 +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
Francisco Casas
e93568f290 vkd3d-shader/hlsl: Clean-up instruction block for offset node creation. 2023-10-31 21:59:11 +01:00
Nikolay Sivov
68c14079a6 vkd3d-shader/hlsl: Add a pass to normalize switch cases blocks.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:59:04 +01:00
Nikolay Sivov
c84d4e3571 vkd3d-shader/hlsl: Add a pass to remove unreachable code.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:59:03 +01:00
Nikolay Sivov
a4fa323e6c vkd3d-shader/hlsl: Add copy propagation logic for switches.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-31 21:59:02 +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
Francisco Casas
7960836551 vkd3d-shader/hlsl: Remove enum hlsl_error_level (clangd).
It is only used once for calling hlsl_note(), and it expects an enum
vkd3d_shader_log_level values instead.
2023-10-12 23:27:22 +02:00
Nikolay Sivov
8479ceedfc vkd3d-shader/hlsl: Propagate structure fields modifiers when copying shader inputs.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-09 21:58:29 +02:00
Nikolay Sivov
7c378cc6f9 vkd3d-shader/hlsl: Remove conditional branching when condition is a compile time constant.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-10-05 16:16:09 +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
a214b7374b vkd3d-shader/hlsl: Avoid hlsl_type_get_regset() in allocate_register_reservations(). 2023-10-05 16:15:34 +02:00
Francisco Casas
13f62e60e1 vkd3d-shader/tpf: Remove sm4_src_register.swizzle_type. 2023-10-03 21:27:47 +02:00
Zebediah Figura
fcda20a8c3 vkd3d-shader/hlsl: Use lower_ir() for lower_sqrt(). 2023-09-25 22:07:23 +02:00
Zebediah Figura
496a3a2093 vkd3d-shader/hlsl: Use lower_ir() for lower_division(). 2023-09-25 22:07:22 +02:00
Zebediah Figura
ecd781e809 vkd3d-shader/hlsl: Use lower_ir() for lower_int_abs(). 2023-09-25 22:07:21 +02:00
Zebediah Figura
7944ee9bed vkd3d-shader/hlsl: Use lower_ir() for lower_casts_to_bool(). 2023-09-25 22:07:20 +02:00
Zebediah Figura
65bf6e997c vkd3d-shader/hlsl: Use lower_ir() for more passes. 2023-09-25 22:07:18 +02:00
Nikolay Sivov
6d1ba83856 vkd3d-shader/hlsl: Use conditional moves for arithmetic operators instead of branching.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-09-22 11:06:22 +02:00
Francisco Casas
39563aa5b3 vkd3d-shader/hlsl: Lower matrix swizzles. 2023-09-13 23:10:38 +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
63e056512d vkd3d-shader/hlsl: Introduce an hlsl_sprintf_alloc() helper. 2023-08-30 22:48:55 +02:00
Zebediah Figura
926575a6f3 vkd3d-shader/hlsl: Force sm1 inputs to be 4-component only for vertex shaders.
Pixel shaders still have an appropriate writemask.
2023-08-24 21:43:44 +02:00
Zebediah Figura
240b9424fb vkd3d-shader/hlsl: Pass an hlsl_block pointer to append_output_copy(). 2023-08-15 21:51:47 +02:00
Zebediah Figura
a04e3a51dd vkd3d-shader/hlsl: Pass an hlsl_block pointer to prepend_input_copy(). 2023-08-15 21:51:39 +02:00
Zebediah Figura
7a4ac1afb1 vkd3d-shader/hlsl: Pass an hlsl_block pointer to prepend_uniform_copy(). 2023-08-15 21:51:37 +02:00
Francisco Casas
d4a49d788a vkd3d-shader/hlsl: Simplify computation of allocation size. 2023-08-15 21:51:32 +02:00
Francisco Casas
37cfbe47d7 vkd3d-shader/hlsl: Sort synthetic separated samplers first for SM4. 2023-08-15 21:51:31 +02:00
Francisco Casas
81afe43569 vkd3d-shader/tpf: Put the actual bind count in the RDEF table. 2023-08-15 21:51:29 +02:00
Francisco Casas
7eba063136 vkd3d-shader/hlsl: Rename hlsl_reg.bind_count to hlsl_reg.allocation_size.
We have to distinguish between the "bind count" and the "allocation size"
of variables.

The "allocation size" affects the starting register id for the resource to
be allocated next, while the "bind count" is determined by the last field
actually used. The former may be larger than the latter.

What we are currently calling hlsl_reg.bind_count is actually the
"allocation size", so a rename is in order.

The real "bind count", which will be introduced in following patches,
is important because it is what should be shown in the RDEF table and
some resource allocation rules depend on it.

For instance, for this shader:

    texture2D texs[3];
    texture2D tex;

    float4 main() : sv_target
    {
        return texs[0].Load(int3(0, 0, 0)) + tex.Load(int3(0, 0, 0));
    }

the variable "texs" has a "bind count" of 1, but an "allocation size" of
3:

    // Resource Bindings:
    //
    // Name                                 Type  Format         Dim      HLSL Bind  Count
    // ------------------------------ ---------- ------- ----------- -------------- ------
    // texs                              texture  float4          2d             t0      1
    // tex                               texture  float4          2d             t3      1
2023-08-15 21:51:27 +02:00
Zebediah Figura
372ddd1f29 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_load_component(). 2023-08-08 21:15:05 +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
Zebediah Figura
7e7a6d3691 vkd3d-shader/hlsl: Pass a hlsl_block pointer to hlsl_add_conditional(). 2023-07-24 22:41:15 +02:00
Zebediah Figura
80b9f52010 vkd3d-shader/hlsl: Use a hlsl_block to build replacement instructions in lower_discard_neg(). 2023-07-24 22:41:14 +02:00
Zebediah Figura
3a07df8476 vkd3d-shader/hlsl: Use a hlsl_block to build replacement instructions in lower_float_modulus(). 2023-07-24 22:41:13 +02:00
Zebediah Figura
0dee96ead6 vkd3d-shader/hlsl: Use a hlsl_block to build replacement instructions in lower_int_modulus(). 2023-07-24 22:41:12 +02:00
Zebediah Figura
d52eb8595f vkd3d-shader/hlsl: Use a hlsl_block to build replacement instructions in lower_int_division(). 2023-07-20 22:33:01 +02:00
Francisco Casas
3bafd036bb vkd3d-shader/hlsl: Don't allocate all texture registers for synthetic separated samplers. 2023-07-17 22:55:53 +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
15ea5ff9db vkd3d-shader/hlsl: Separate tracking of sampler_dim and usage for object components. 2023-07-17 22:55:48 +02:00
Francisco Casas
866c5d9531 vkd3d-shader/hlsl: Check is_uniform instead of HLSL_STORAGE_UNIFORM when validating object refs.
We are using the hlsl_ir_var.is_uniform flag to indicate when an object
is a uniform copy created from a variable with the HLSL_STORAGE_UNIFORM
modifier.

We should be checking for this instead of the HLSL_STORAGE_UNIFORM flag
which is also set to 1 for the original variables, and there should be
no reason to use this flag instead of "is_uniform" after the uniform
copies and combined/separated samplers are created.
2023-07-17 22:55:43 +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
Zebediah Figura
d4b5e79c8b vkd3d-shader/hlsl: Skip unallocated variables when looking for reservation conflicts. 2023-07-13 23:00:03 +02:00
Zebediah Figura
53e9ad3e4c vkd3d-shader/hlsl: Do not emit DEF instructions for uniform constants. 2023-07-04 22:40:20 +02:00
Zebediah Figura
e5afbda34a vkd3d-shader/hlsl: Simplify allocate_const_registers_recurse() to stop accounting for constants larger than a vector.
That cannot happen with the current code.
2023-07-04 22:40:16 +02:00
Zebediah Figura
8a2b357855 vkd3d-shader/hlsl: Allocate anonymous constants after uniforms. 2023-07-04 22:40:13 +02:00
Nikolay Sivov
4ed60cda13 vkd3d-shader: Remove extra newlines from compiler messages. 2023-06-27 22:34:19 +02:00
Nikolay Sivov
861078d63a vkd3d-shader/hlsl: Handle 'texkill' discard type for sm4+.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-06-27 22:33:50 +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
Nikolay Sivov
c8ffe8e1a8 vkd3d-shader/hlsl: Don't report a register type mismatch for unused reserved variables. 2023-06-22 22:00:19 +02:00
Zebediah Figura
d6ac823dd6 vkd3d-shader/hlsl: Don't set "allocated" for unused reserved variables. 2023-06-22 22:00:17 +02:00
Zebediah Figura
1c1f1094a5 vkd3d-shader/hlsl: Handle reserved vars specially in get_allocated_object(). 2023-06-22 22:00:16 +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
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
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
Nikolay Sivov
2fd3550ba6 vkd3d-shader/hlsl: Parse SampleCmp() method. 2023-05-29 20:21:14 +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
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
dfa0076473 vkd3d-shader/hlsl: Add support for sample index argument in Load(). 2023-05-22 22:03:12 +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
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
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
Francisco Casas
34ddc13390 vkd3d-shader/hlsl: Don't keep the implicit mipmap level on hlsl_ir_index. 2023-05-03 21:11:59 +02:00
Francisco Casas
4aaf6b8895 vkd3d-shader/hlsl: Use hlsl_ir_index for resource access.
This patch makes index expressions on resources hlsl_ir_index nodes
instead of hlsl_ir_resource_load nodes, because it is not known if they
will be used later as the lhs of an hlsl_ir_resource_store.

For now, the only benefit is consistency.
2023-05-03 21:11:56 +02:00
Nikolay Sivov
7d41cf4440 vkd3d-shader/hlsl: Partially implement static expressions evaluation. 2023-05-02 20:46:08 +02:00
Zebediah Figura
0a44e6043e vkd3d-shader/hlsl: Put the hlsl_ir_constant value in a structure. 2023-05-01 22:18:33 +02:00
Francisco Casas
dcd991deda vkd3d-shader/hlsl: Consider duplicated input semantic types equivalent in SM1. 2023-05-01 22:18:27 +02:00
Francisco Casas
34431239a5 vkd3d-shader/hlsl: Handle possibly different types in input semantic var load.
Since in SM1 all vector types use 4 register components, and since SM1
doesn't consider vectors of different dimx incompatible, it is necessary
to ensure that the semantic var is created with dimx=4, and to add a
cast node.
2023-05-01 22:18:26 +02:00
Francisco Casas
537d7c27a2 vkd3d-shader/hlsl: Error out when a semantic is used with incompatible types.
Considering row vectors from row_major matrices as having a different
layout as regular vectors, and error out in that case, is left as todo.
2023-05-01 22:18:24 +02:00
Francisco Casas
d96e9665b1 vkd3d-shader/hlsl: Error out when an output semantic is used more than once.
The use of the hlsl_semantic.reported_duplicated_output_next_index field
allows reporting multiple overlapping indexes, such as in the following
vertex shader:

    void main(out float1x3 x : OVERLAP0, out float1x3 y : OVERLAP1)
    {
        x = float3(1.0, 2.0, 3.2);
        y = float3(5.0, 6.0, 5.0);
    }

    apple.hlsl:1:41: E5013: Output semantic "OVERLAP1" is used multiple times.
    apple.hlsl:1:13: First use of "OVERLAP1" is here.
    apple.hlsl:1:41: E5013: Output semantic "OVERLAP2" is used multiple times.
    apple.hlsl:1:13: First use of "OVERLAP2" is here.

While at the same time avoiding reporting overlaps more than once for
large arrays:

    struct apple
    {
        float2 p : sv_position;
    };

    void main(out apple aps[4])
    {
    }

    apple.hlsl:3:8: E5013: Output semantic "sv_position0" is used multiple times.
    apple.hlsl:3:8: First use of "sv_position0" is here.
2023-05-01 22:18:22 +02:00
Francisco Casas
edc72fdefc vkd3d-shader/hlsl: Support semantics for array types. 2023-05-01 22:18:21 +02:00
Francisco Casas
a488889494 vkd3d-shader/hlsl: Don't create semantic vars more than once. 2023-05-01 22:18:20 +02:00
Francisco Casas
61c72a4fd1 vkd3d-shader/hlsl: Avoid invalid input/output copies for non-numeric types. 2023-05-01 22:18:17 +02:00
Zebediah Figura
e5ec431784 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_jump(). 2023-04-20 22:54:10 +02:00
Nikolay Sivov
dfe923ea1d vkd3d-shader: Consistently pass location structure by pointer. 2023-04-19 20:45:31 +02:00
Zebediah Figura
7ee66351c8 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_if(). 2023-04-18 21:59:49 +02:00
Zebediah Figura
50f0ae1b21 vkd3d-shader/hlsl: Pass hlsl_block pointers to hlsl_new_if(). 2023-04-18 21:59:45 +02:00
Zebediah Figura
5a3fe1609b vkd3d-shader/hlsl: Initialize the block in clone_block(). 2023-04-18 21:59:44 +02:00
Zebediah Figura
dc7514afc9 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_float_constant(). 2023-04-18 21:59:39 +02:00
Zebediah Figura
b23ef3ca3b vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_cast() and hlsl_new_copy(). 2023-04-18 21:59:37 +02:00
Zebediah Figura
1bf3aa9275 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_bool_constant(). 2023-04-18 21:59:34 +02:00
Zebediah Figura
0654d88edd vkd3d-shader/hlsl: Allow VPOS and VFACE to be specified in sm3 pixel shaders.
We were previously (accidentally) rejecting them because they didn't have a
usage.
2023-04-18 21:59:22 +02:00
Francisco Casas
5c285adc6b vkd3d-shader/hlsl: Use hlsl_ir_index for array and record access.
From this point on, it is no longer true that only hlsl_ir_loads can
return objects, because an object can also come from chain of
hlsl_ir_indexes that ends in an hlsl_ir_load.

The lower_index_loads pass takes care of lowering all hlsl_ir_indexes
into hlsl_ir_loads.

For this reason, hlsl_resource_load_params now expects both the resource
as the sampler to be just an hlsl_ir_node pointer instead of a pointer
to a more specific hlsl_ir_load.
2023-04-13 23:05:32 +02:00
Francisco Casas
741c9e5893 vkd3d-shader/hlsl: Introduce hlsl_ir_index.
This node type is intended for use during parse-time.

While we parse an indexing expression such as "a[3]", we don't know if
it will end up as part of an expression (in which case it must be folded
into a load) or it is for the lhs of a store (in which case it must be
folded into the store's deref).
2023-04-13 23:05:25 +02:00
Zebediah Figura
1514755043 vkd3d-shader/hlsl: Make a string array const. 2023-04-06 17:52:07 +02:00
Zebediah Figura
725d408974 vkd3d-shader/hlsl: Introduce an hlsl_block_init() helper. 2023-04-06 17:51:40 +02:00
Zebediah Figura
1da5a9a490 vkd3d-shader/hlsl: Introduce an hlsl_block_add_block() helper. 2023-04-06 17:51:38 +02:00
Zebediah Figura
ceac81b816 vkd3d-shader/hlsl: Introduce an hlsl_block_add_instr() helper. 2023-04-06 17:51:36 +02:00
Francisco Casas
f3e81327dc vkd3d-shader/hlsl: Consider register() as manual packing for resource fields. 2023-04-04 21:59:49 +02:00
Francisco Casas
60237cb773 vkd3d-shader/hlsl: Don't allow manual and automatic cbuffer offset packing. 2023-04-04 21:59:45 +02:00
Francisco Casas
4448d114ad vkd3d-shader/hlsl: Detect overlaps in cbuffer offsets. 2023-04-04 21:59:43 +02:00
Francisco Casas
7777c32cac vkd3d-shader/hlsl: Support packoffset(). 2023-04-04 21:59:42 +02:00
Francisco Casas
9b70971696 vkd3d-shader/hlsl: Rename struct hlsl_reg_reservation fields. 2023-04-04 21:59:39 +02:00
Nikolay Sivov
eb71c5f20d vkd3d-shader/hlsl: Handle round() for SM1. 2023-04-03 18:00:03 +02:00
Zebediah Figura
7a9e393ea0 vkd3d-shader/hlsl: Rename the "type" field of struct hlsl_type to "class".
To be consistent with enum hlsl_type_class and HLSL_CLASS_*.
2023-04-03 17:59:24 +02:00
Nikolay Sivov
4110f1e547 vkd3d-shader: Fix a few typos in the comments. 2023-03-15 20:13:27 +01:00
Francisco Casas
f8338ef089 vkd3d-shader/hlsl: Allocate register reservations in a separate pass.
This refactoring is required for improving the allocation strategy so it
works with multiple-register variables.
2023-02-22 18:28:19 +01:00
Francisco Casas
75359e6dbd vkd3d-shader/hlsl: Respect object reservations even if the object is unused. 2023-02-22 18:28:19 +01:00
Francisco Casas
c5384b38ee vkd3d-shader/hlsl: Allocate objects according to register set. 2023-02-22 18:28:19 +01:00