Commit Graph

2103 Commits

Author SHA1 Message Date
Zebediah Figura
372ddd1f29 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_load_component(). 2023-08-08 21:15:05 +09:00
Zebediah Figura
f649db23a5 vkd3d-shader: Introduce a function to build a varying map between sm1 stages. 2023-08-03 21:20:44 +09:00
Zebediah Figura
d932fba7c3 vkd3d-shader/spirv: Make output varyings not consumed by the next stage private variables. 2023-08-03 21:20:42 +09:00
Zebediah Figura
11475ef62a vkd3d-shader: Implement remapping shader output registers to match the next shader's semantics. 2023-08-03 21:20:42 +09:00
Zebediah Figura
cb96482500 vkd3d-shader: Add a separate field for the target location of a signature element.
We want to be able to remap input signatures based on the signature index, but
signature normalization both reorders the signature, and requires the old
register index, so add a new field for this.
2023-08-03 21:20:39 +09:00
Zebediah Figura
bad72d1874 vkd3d-shader/d3dbc: Make sure all inter-stage varyings have a unique register index.
spirv will need this.
2023-08-03 21:20:22 +09:00
Zebediah Figura
b4bb3931c5 vkd3d-shader/preproc: Append spaces between tokens in macro invocations. 2023-08-02 20:19:21 +09:00
Zebediah Figura
250a24bd3f vkd3d-shader/preproc: Strip whitespace when stringifying. 2023-08-02 20:19:20 +09:00
Zebediah Figura
6fc3ae2b5c vkd3d-shader/preproc: Stringify text immediately in macro invocations. 2023-08-02 20:19:19 +09:00
Zebediah Figura
cbb1d84069 vkd3d-shader/preproc: Separate a preproc_stringify() helper. 2023-08-02 20:19:18 +09:00
Zebediah Figura
3a235b57f6 vkd3d-shader/preproc: Expand macro arguments in macro invocations.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55361
2023-08-02 20:19:17 +09:00
Zebediah Figura
9b98489155 vkd3d-shader/preproc: Parse hash marks as two separate tokens when not in stringification contexts. 2023-08-02 20:19:15 +09:00
Zebediah Figura
9a80ff28e4 vkd3d-shader/tpf: Check buffer->status in add_section(). 2023-08-02 20:19:00 +09:00
Zebediah Figura
71afb78126 vkd3d-shader/d3dbc: Return ctx->result from hlsl_sm1_write(). 2023-08-02 20:18:59 +09:00
Zebediah Figura
6e370777b4 vkd3d-shader/d3dbc: Free vkd3d_bytecode_buffer data on failure. 2023-08-02 20:18:58 +09:00
Zebediah Figura
1bd873fb2b vkd3d-shader/d3dbc: Skip generic sampler declarations.
Instead of asserting.
2023-08-02 20:18:56 +09:00
Nikolay Sivov
bfdd5c142d vkd3d-shader/tpf: Add support for writing 'resinfo' instruction.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-31 21:07:50 +09:00
Nikolay Sivov
78719dc814 vkd3d-shader/tpf: Add support for writing 'sampleinfo' instruction.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-31 21:07:49 +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
819c5f1943 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_expr(). 2023-07-27 17:17:48 +09:00
Zebediah Figura
9d94506313 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_cast(). 2023-07-27 17:17:47 +09:00
Zebediah Figura
fe70ee2158 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_implicit_conversion(). 2023-07-27 17:17:46 +09:00
Zebediah Figura
21d5ee4df2 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_array_access(). 2023-07-27 17:17:41 +09:00
Zebediah Figura
c861a937e8 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_method_call(). 2023-07-27 17:17:37 +09:00
Zebediah Figura
f95ab2a5e8 vkd3d-shader/hlsl: Pass an hlsl_block pointer to add_assignment(). 2023-07-24 22:41:16 +02: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
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
d52eb8595f vkd3d-shader/hlsl: Use a hlsl_block to build replacement instructions in lower_int_division(). 2023-07-20 22:33:01 +02:00
Zebediah Figura
cdabe172cb vkd3d-shader/hlsl: Return a hlsl_block from the "declaration" and "struct_declaration" rules. 2023-07-20 22:33:00 +02:00
Zebediah Figura
54bd6f7b4b vkd3d-shader/hlsl: Return a hlsl_block from the "declaration_statement" rule. 2023-07-20 22:32:59 +02:00
Zebediah Figura
77e1c5893e vkd3d-shader/hlsl: Return a hlsl_block from the "primary_expr" rule. 2023-07-20 22:32:57 +02:00
Conor McCarthy
c0a2bb1095 vkd3d-shader/dxil: Emit undefined constants. 2023-07-20 22:32:53 +02:00
Conor McCarthy
402c93fa68 vkd3d-shader/spirv: Introduce an undefined register type. 2023-07-20 22:32:52 +02:00
Conor McCarthy
3e553aaaa7 vkd3d-shader/dxil: Emit the shader instructions.
Sufficient for compiling a no-op pixel shader.
2023-07-20 22:32:51 +02:00
Conor McCarthy
f26d47585f vkd3d-shader/spirv: Do not normalise Shader Model 6 shaders. 2023-07-20 22:32:50 +02:00
Conor McCarthy
8fe6d2eeac vkd3d-shader/dxil: Return an error from sm6_parser_globals_init() on invalid operand count. 2023-07-20 22:32:48 +02:00
Zebediah Figura
e0e261eac3 vkd3d-shader/spirv: Emit variables for flat constant buffers. 2023-07-17 22:56:47 +02:00
Zebediah Figura
25cf6a720b vkd3d-shader/ir: Normalise sm1-style constants. 2023-07-17 22:56:45 +02:00
Zebediah Figura
e9fb067d4c vkd3d-shader/ir: Move normalization code from spirv.c to ir.c.
It is not spirv-specific and will (presumably) be used for GLSL as well.
2023-07-17 22:56:43 +02:00
Zebediah Figura
d077562f79 vkd3d-shader/d3dbc: Scan descriptors for constant register sets. 2023-07-17 22:56:39 +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
Nikolay Sivov
63631a8fd4 vkd3d-shader/tpf: Support some of the UAV types when writing RDEF records.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-17 22:56:05 +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
c4f074d25d vkd3d-shader/hlsl: Introduce hlsl_new_synthetic_var_named(). 2023-07-17 22:55:46 +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
c58d666d1b vkd3d-shader/hlsl: Handle resource components individually for SM 5.0. 2023-07-17 22:55:40 +02:00
Francisco Casas
8f8c7a02ee vkd3d-shader/tpf: Introduce struct extern_resource.
This struct is required for handling both whole-variable resources for
SM < 5 and single-component resources for SM 5 in the same way, when
writting the RDEF block and resource declarations within the shader.
2023-07-17 22:55:39 +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
aec9ea085e vkd3d-shader/hlsl: Return a hlsl_block from the "postfix_expr" rule. 2023-07-11 22:44:15 +02:00
Zebediah Figura
e222a786a1 vkd3d-shader/hlsl: Return a hlsl_block from binary and ternary expression rules. 2023-07-11 22:44:12 +02:00
Zebediah Figura
3079c874e3 vkd3d-shader/hlsl: Return a hlsl_block from the "unary_expr" rule. 2023-07-11 22:44:10 +02:00
Zebediah Figura
28dff58fb5 vkd3d-shader/hlsl: Return a hlsl_block from the "initializer_expr" rule. 2023-07-11 22:44:09 +02:00
Zebediah Figura
53d5ea639c vkd3d-shader/hlsl: Return a hlsl_block from the "assignment_expr" rule. 2023-07-11 22:44:06 +02:00
Conor McCarthy
1ec112e3d7 vkd3d-shader/dxil: Read function bodies. 2023-07-11 22:43:58 +02:00
Conor McCarthy
5d33fb4633 vkd3d-shader/dxil: Read numeric constants. 2023-07-11 22:43:57 +02:00
Conor McCarthy
c96143abdc vkd3d-shader/dxil: Read global function declarations. 2023-07-11 22:43:55 +02:00
Conor McCarthy
22157c3da3 vkd3d-shader/dxil: Validate the module format version. 2023-07-11 22:43:53 +02:00
Conor McCarthy
eca4b62c7e vkd3d-shader/dxil: Read the value symbol table. 2023-07-11 22:43:49 +02:00
Conor McCarthy
571d807dd8 vkd3d-shader/dxil: Read the type table. 2023-07-11 22:43:48 +02:00
Conor McCarthy
41a5d37935 vkd3d-shader/dxil: Use size_t where applicable. 2023-07-11 22:43:46 +02:00
Andrey Gusev
d4d960cb8b vkd3d-shader/spirv: Add support for VKD3DSIM_LINEAR_NOPERSPECTIVE_SAMPLE interpolation qualifier.
Used by F1 2018.
2023-07-10 23:17:59 +02:00
Zebediah Figura
6e303af519 vkd3d-shader/hlsl: Free the "iter" block pointer on success in create_loop().
Spotted by Giovanni Mascellani.
2023-07-05 22:32:48 +02:00
Zebediah Figura
b0ac77b44d vkd3d-shader/hlsl: Return a hlsl_block from the "expr_statement" and "expr" rules. 2023-07-05 22:32:47 +02:00
Zebediah Figura
07ce711583 vkd3d-shader/hlsl: Return a hlsl_block from the "jump_statement" rule. 2023-07-05 22:32:46 +02:00
Zebediah Figura
e4bf5933b9 vkd3d-shader/hlsl: Return a hlsl_block from the "selection_statement" rule. 2023-07-05 22:32:45 +02:00
Zebediah Figura
79dd9544b7 vkd3d-shader/hlsl: Return a hlsl_block from the "loop_statement" rule. 2023-07-05 22:32:43 +02:00
Zebediah Figura
23ff83e8a0 vkd3d-shader/hlsl: Return a hlsl_block from the "statement" rule.
As well as from the "statement_list" and "compound_statement" rules, which
trivially pass through from "statement".
2023-07-05 22:32:41 +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
Zebediah Figura
717cd3f5bb vkd3d-shader/hlsl: Consistently use the destination width in constant folding instructions (Valgrind). 2023-07-04 22:40:06 +02:00
Zebediah Figura
e390bc35e2 vkd3d-shader/d3dbc: Set the source count for DEF instructions to 1 (Valgrind).
We emit one source with multiple components.
2023-07-04 22:40:04 +02:00
Nikolay Sivov
06040d2a30 vkd3d-shader/hlsl: Disallow certain instruction types from constant expressions.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-04 22:39:57 +02:00
Nikolay Sivov
a65c0b0e22 vkd3d-shader/hlsl: Support evaluated expressions for sample count in multisampled textures declarations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-07-04 22:39:55 +02:00
Zebediah Figura
73d422a0e0 vkd3d-shader/d3dbc: Scan for the maximum temporary register index. 2023-07-04 22:39:48 +02:00
Zebediah Figura
e489098878 vkd3d-shader: Record a global temporary count per sm4 shader.
Store it in the shader_desc, and declare temps from that when compiling SPIR-V,
instead of parsing dcl_instructions.

As part of this change, we declare a single, global temps array (with Private
scope instead of Function) which is as large as the maximum of all dcl_temps
instructions. It is not clear to me whether this will improve, hurt, or have no
significant effect on the lower-level compiler. An alternative is to still
redeclare a new temps array every time (although still with a smaller size).
2023-07-04 22:39:45 +02:00
Zebediah Figura
dfb2a316e6 vkd3d-shader/dxbc: Remove redundant zero-initialization of the vkd3d_shader_desc structure. 2023-07-04 22:39:43 +02:00
Nikolay Sivov
300f3462a4 vkd3d-shader/hlsl: Add constant folding for 'rcp'. 2023-07-04 22:39:36 +02:00
Francisco Casas
01800942a9 vkd3d-shader/hlsl: Declare vars individually when parsing struct declarations.
A struct declaration with variables is now absorbed into the 'declaration'
rule, like any other variable declaration.

A struct declaration without variables is now reduced to the
'struct_declaration_without_vars' rule.

They both are reduced to a 'declaration_statement' in the end.
2023-07-04 22:39:24 +02:00
Francisco Casas
62c891b796 vkd3d-shader/hlsl: Declare vars individually when parsing regular declarations.
In a declaration with multiple variables, the variables must be created
before the initializer of the next variable is parsed. This is required
for initializers such as:

    float a = 1, b = a, c = b + 1;

A requisite for this is that the type information is parsed in the same
rule as the first variable (as a variable_def_typed) so it is
immediately available to declare the first variable. Then, the next
untyped variable declaration is parsed, and the type from the first
variable can be used to declare the second, before the third is parsed,
and so on.
2023-07-04 22:39:21 +02:00
Francisco Casas
a34cf2e64e vkd3d-shader/hlsl: Split declare_vars().
Basically, declare_vars() is separated in three functions:

1. check_invalid_in_out_modifiers(), which is to be called once per
   declaration and emits an error when in or out modifiers are used for
   these non-parameter variables.

2. declare_var(), which now handles one variable at the time and doesn't
   free any memory.

3. initialize_vars(), which takes care of preparing the initialization
   instructions of several variables and frees their struct
   parse_variable_def, using exclusively free_parse_variable_def().

This allows to declare variables individually before the initializer of
the next variable in the same declaration is parsed, which is used in
the following patches.

Also, simplifies memory management.
2023-07-04 22:39:18 +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
Conor McCarthy
de25e88901 vkd3d-shader/dxil: Read and validate global abbreviated operands. 2023-06-28 21:40:37 +02:00
Conor McCarthy
e9a8bfb2c4 vkd3d-shader/dxil: Read and validate local abbreviated operands. 2023-06-28 21:40:36 +02:00
Conor McCarthy
6775f7ba66 vkd3d-shader/dxil: Read and validate DXIL bitcode unabbreviated blocks. 2023-06-28 21:40:34 +02:00
Nikolay Sivov
69f32796b0 vkd3d-shader: Unify static string arrays initialization pattern. 2023-06-28 21:40:21 +02:00
Zebediah Figura
9ccba35dde vkd3d-shader/hlsl: Store the fields of struct parse_if_body as hlsl_block pointers. 2023-06-28 21:40:18 +02:00
Zebediah Figura
8fa1750206 vkd3d-shader/hlsl: Store the "instrs" field of struct parse_initializer as a hlsl_block pointer. 2023-06-28 21:40:16 +02:00
Zebediah Figura
7d521db3db vkd3d-shader/hlsl: Merge the "discard_statement" rule into "jump_statement". 2023-06-28 21:40:15 +02:00
Zebediah Figura
588784e4dc vkd3d-shader/hlsl: Use add_unary_arithmetic_expr() in the subtraction rule. 2023-06-28 21:40:14 +02:00
Zebediah Figura
b4bf5af475 vkd3d-shader/hlsl: Factor out add_binary_expr_merge(). 2023-06-28 21:40:12 +02:00
Giovanni Mascellani
bdfec4886d vkd3d-shader/hlsl: Fold logical expressions. 2023-06-27 22:34:33 +02:00
Giovanni Mascellani
5a05fabe62 vkd3d-shader/hlsl: Fold floating point minimum expressions. 2023-06-27 22:34:30 +02:00
Giovanni Mascellani
2a2943c2cf vkd3d-shader/hlsl: Fold floating point maximum expressions. 2023-06-27 22:34:29 +02:00
Giovanni Mascellani
358d656262 vkd3d-shader/hlsl: Fold greater-than-or-equal comparisons. 2023-06-27 22:34:28 +02:00
Giovanni Mascellani
bf452b5907 vkd3d-shader/hlsl: Fold less-than comparisons. 2023-06-27 22:34:27 +02:00
Giovanni Mascellani
488af14144 vkd3d-shader/hlsl: Fold equality comparisons. 2023-06-27 22:34:25 +02:00
Giovanni Mascellani
6c9f6d0fcf vkd3d-shader/hlsl: Sort constant folding helpers alphabetically. 2023-06-27 22:34:24 +02:00
Nikolay Sivov
4ed60cda13 vkd3d-shader: Remove extra newlines from compiler messages. 2023-06-27 22:34:19 +02:00
Nikolay Sivov
9ccf291971 vkd3d-shader/hlsl: Use profile version testing helpers in more places. 2023-06-27 22:34:05 +02:00
Nikolay Sivov
5c02e12187 vkd3d-shader/hlsl: Make sample count optional for SM4.1+.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-06-27 22:34:03 +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
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
Zebediah Figura
7e1fcdca89 vkd3d-shader: Synthesize signatures for d3dbc shaders. 2023-06-27 22:33:41 +02:00
Zebediah Figura
20190a1388 vkd3d-shader: Introduce an API to retrieve all signatures from DXBC shaders. 2023-06-27 22:33:41 +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
Henri Verbeet
771e442af1 Release 1.8. 2023-06-22 22:00:20 +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
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
Conor McCarthy
85eb231492 vkd3d-shader/d3dbc: Return an error from vkd3d_shader_sm1_parser_create() if the parser failed. 2023-05-03 21:12:03 +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
87037d3748 vkd3d-shader/hlsl: Implement asfloat().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-05-02 20:46:16 +02:00
Nikolay Sivov
7d41cf4440 vkd3d-shader/hlsl: Partially implement static expressions evaluation. 2023-05-02 20:46:08 +02:00
Zebediah Figura
6de904b448 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_resource_store(). 2023-05-02 20:46:03 +02:00
Zebediah Figura
3cc18f1e9f vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_resource_load(). 2023-05-02 20:46:02 +02:00
Zebediah Figura
8485b2ee95 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_loop(). 2023-05-02 20:46:00 +02:00
Zebediah Figura
3ca9656e84 vkd3d-shader/hlsl: Pass an hlsl_block pointer to hlsl_new_loop(). 2023-05-02 20:45:59 +02:00
Zebediah Figura
e848c57b46 vkd3d-shader/hlsl: Reuse the "init" instruction list if possible in create_loop(). 2023-05-02 20:45:57 +02:00
Henri Verbeet
3f8aa0e272 vkd3d-shader/d3d-asm: Rename trace.c to d3d_asm.c. 2023-05-02 20:45:33 +02:00
Henri Verbeet
73dc62aebf vkd3d-shader: Get rid of the unused vkd3d_shader_src_param_entry structure. 2023-05-02 20:45:27 +02:00
Francisco Casas
abb207fab0 vkd3d-shader/hlsl: Always specify resource on intrinsic_tex().
Otherwise, in the added test, we get:

vkd3d-compiler: vkd3d-shader/hlsl.c:452: hlsl_init_deref_from_index_chain: Assertion `chain' failed.

because on the path that triggers the following error:

E5002: Wrong type for argument 1 of 'tex3D': expected 'sampler' or 'sampler3D', but got 'sampler2D'.

a NULL params.resource is passed to hlsl_new_resource_load() and
then to hlsl_init_deref_from_index_chain().
2023-05-01 22:18:46 +02:00
Ethan Lee
5d735f3b0e vkd3d-shader/hlsl: Add support for sign() intrinsic.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-05-01 22:18:41 +02:00
Zebediah Figura
6e677def71 vkd3d-shader/hlsl: Normalize bools when loading from uniforms or vertex input. 2023-05-01 22:18:36 +02:00
Zebediah Figura
834497d5ac vkd3d-shader/hlsl: Introduce an sm4_src_from_constant_value() helper. 2023-05-01 22:18:35 +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
b589c2b32d vkd3d-shader/hlsl: Move get_array_size() and get_array_type() to hlsl.c. 2023-05-01 22:18:19 +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
Nikolay Sivov
7ba373946b vkd3d-shader/hlsl: Implement D3DCOLORtoUBYTE4() function. 2023-04-28 21:04:13 +02:00
Nikolay Sivov
4b3707aeb4 vkd3d-shader/hlsl: Partially implement trunc().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-28 21:04:11 +02:00
Ethan Lee
138c32ce88 vkd3d-shader/hlsl: Add support for ddx(), ddy() intrinsics.
SPIR-V already handled DSX/DSY, so only D3DBC/TPF needed new case blocks.

Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-04-28 21:03:40 +02:00
Nikolay Sivov
af4bb03795 vkd3d-shader/hlsl: Implement SampleBias() method.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-26 22:46:55 +02:00
Nikolay Sivov
c166ab9727 vkd3d-shader/hlsl: Add separate helpers to generate object methods.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-26 22:46:53 +02:00
Nikolay Sivov
59c63ec584 vkd3d-shader/hlsl: Handle discard statement.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-26 22:46:50 +02:00
Nikolay Sivov
6da7d16d4c vkd3d-shader/trace: Add separate id for discard.
Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-04-26 22:46:49 +02:00
Zebediah Figura
b46df551eb vkd3d-shader/tpf: Return unsigned int from hlsl_sm4_register_from_semantic().
Fix a compile warning:

../vkd3d/libs/vkd3d-shader/hlsl_codegen.c: In function 'allocate_semantic_register':
../vkd3d/libs/vkd3d-shader/hlsl_codegen.c:2947:85: error: passing argument 4 of 'hlsl_sm4_register_from_semantic' from incompatible pointer type [-Werror=incompatible-pointer-types]
 2947 |         if ((builtin = hlsl_sm4_register_from_semantic(ctx, &var->semantic, output, &type, NULL, &has_idx)))
      |                                                                                     ^~~~~
      |                                                                                     |
      |                                                                                     unsigned int *
In file included from ../vkd3d/libs/vkd3d-shader/hlsl_codegen.c:21:
../vkd3d/libs/vkd3d-shader/hlsl.h:1171:52: note: expected 'enum vkd3d_sm4_register_type *' but argument is of type 'unsigned int *'
 1171 |         bool output, enum vkd3d_sm4_register_type *type, enum vkd3d_sm4_swizzle_type *swizzle_type, bool *has_idx);
      |                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
2023-04-21 20:55:56 +02:00
Nikolay Sivov
317b8aa039 vkd3d-shader/hlsl: Ignore "unroll" attribute for loops. 2023-04-21 20:55:48 +02:00
Henri Verbeet
8e0df3f720 vkd3d-shader/sm1: Merge hlsl_sm1.c into d3dbc.c. 2023-04-20 22:54:32 +02:00
Henri Verbeet
99bc07ccf5 vkd3d-shader/sm4: Merge sm4.h into tpf.c. 2023-04-20 22:54:31 +02:00
Henri Verbeet
7800c7b40f vkd3d-shader/sm4: Rename hlsl_sm4.c to tpf.c. 2023-04-20 22:54:30 +02:00
Henri Verbeet
804e315b68 vkd3d-shader/sm4: Move the TPF parser from dxbc.c to hlsl_sm4.c. 2023-04-20 22:54:28 +02:00
Zebediah Figura
0959c6663f vkd3d-shader/hlsl: Remove an unused local variable from create_loop(). 2023-04-20 22:54:13 +02:00
Zebediah Figura
39a03cfd22 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_load_component(). 2023-04-20 22:54:12 +02:00
Zebediah Figura
a98686ed78 vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from add_load_component(). 2023-04-20 22:54:11 +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
Zebediah Figura
dfe056596a vkd3d-shader/hlsl: Return an hlsl_ir_node pointer from hlsl_new_int_constant(). 2023-04-20 22:54:09 +02:00
Ethan Lee
0668d32631 vkd3d-shader/hlsl: Add support for any() intrinsic.
For now, this is limited to float and bool, scalar and vector. All other types are unsupported.

Signed-off-by: Ethan Lee <flibitijibibo@gmail.com>
2023-04-19 20:46:53 +02:00
Francisco Casas
3f9cd58f5b vkd3d-shader/hlsl: Fix missing extern resource names. 2023-04-19 20:46:53 +02:00
Nikolay Sivov
827a359b45 vkd3d-shader/hlsl: Handle uppercase regset names in packoffset().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-19 20:45:50 +02:00
Nikolay Sivov
0cea4d352e vkd3d-shader/hlsl: Handle uppercase regset names in register(). 2023-04-19 20:45:48 +02:00
Zebediah Figura
d8ef0c69a8 vkd3d-shader/spirv: Do not declare resources as multisampled if the sample count is 1.
It is illegal to match a SPIR-V multisampled resource to a Vulkan resource which
is not multisampled. Vulkan considers a resource to be multisampled if its
sample count is greater than 1 (and SPIR-V does not care about the sample count).

This fixes validation errors in the case where the sample count does actually
match the resource. In order to provide correct behaviour when there is a
mismatch, or when the sample count is missing, we will need yet another
additional interface. In the absence of that it seems best to provide a best
guess.

This fixes a validation error with the not-yet-committed merge request 135, when
the d3d11 runner is run through Wine with the Vulkan backend.
2023-04-19 20:45:39 +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
733141720a vkd3d-shader/hlsl: Introduce a hlsl_block_cleanup() helper. 2023-04-18 21:59:42 +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
Zebediah Figura
b19105eaeb vkd3d-shader/hlsl: Do not write DCL instructions for ps_1_* shaders. 2023-04-18 21:59:17 +02:00
Zebediah Figura
99d413206b vkd3d-shader/hlsl: Map ps_1_* color and texcoord semantics to registers. 2023-04-18 21:59:15 +02:00
Zebediah Figura
98e2461392 vkd3d-shader/hlsl: Sort only uniforms by name in the sm1 backend. 2023-04-18 21:59:13 +02:00
Zebediah Figura
8ed7437708 vkd3d-shader/hlsl: Evaluate index before array.
Co-authored-by: Francisco Casas <fcasas@codeweavers.com>
2023-04-13 23:05:43 +02:00
Francisco Casas
af1aa63ace vkd3d-shader/hlsl: Support column-major matrix indexing in the lhs. 2023-04-13 23:05:41 +02:00
Francisco Casas
dc2a34824d vkd3d-shader/hlsl: Always load from a synthetic copy in add_load_component(). 2023-04-13 23:05:39 +02:00
Francisco Casas
82ff408451 vkd3d-shader/hlsl: Remove add_load_index(). 2023-04-13 23:05:34 +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
Francisco Casas
0ceecd1225 vkd3d-shader/hlsl: Fix numeric offset of object fields. 2023-04-13 23:05:07 +02:00
Nikolay Sivov
ca59a3c35b vkd3d-shader/hlsl: Handle SV_IsFrontFace semantic. 2023-04-13 23:04:58 +02:00
Nikolay Sivov
a1bd4e080e vkd3d-shader/hlsl: Support log() intrinsic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-13 23:04:44 +02:00
Nikolay Sivov
210caa931d vkd3d-shader/hlsl: Support log10() intrinsic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-04-13 23:04:42 +02:00
Nikolay Sivov
49b63fbeba vkd3d-shader/hlsl: Support log2() intrinsic. 2023-04-13 23:04:40 +02:00
Nikolay Sivov
c93dac3620 vkd3d-shader/hlsl: Write 'log' instruction for SM1. 2023-04-13 23:04:37 +02:00
Henri Verbeet
0c05f2409c vkd3d-shader/sm4: Get rid of shader_sm4_is_end(). 2023-04-12 21:54:57 +02:00
Henri Verbeet
1e448b0b71 vkd3d-shader/sm4: Pass a vkd3d_shader_sm4_parser structure to shader_sm4_read_instruction(). 2023-04-12 21:54:56 +02:00
Henri Verbeet
1b7b694190 vkd3d-shader/sm1: Pass a vkd3d_shader_sm1_parser structure to shader_sm1_is_end(). 2023-04-12 21:54:55 +02:00
Henri Verbeet
df6a34e1bd vkd3d-shader/sm1: Pass a vkd3d_shader_sm1_parser structure to shader_sm1_read_instruction(). 2023-04-12 21:54:54 +02:00
Henri Verbeet
09566e2c25 vkd3d-shader: Get rid of the "ptr" field from struct vkd3d_shader_parser.
This is an implementation detail.
2023-04-12 21:54:53 +02:00
Henri Verbeet
c4d307a08d vkd3d-shader: Get rid of the "instruction_idx" field from struct vkd3d_shader_parser.
This is unused now.
2023-04-12 21:54:51 +02:00
Conor McCarthy
98b5e2c6e0 vkd3d-shader/ir: Insert hull shader control point input declarations if no control point phase is defined.
The SPIR-V backend will emit a default control point phase. Inserting
inputs into the IR allows handling of declarations via the usual path
instead of an ad hoc implementation which may not match later changes
to input handling.
2023-04-12 21:54:28 +02:00
Conor McCarthy
14295a224d vkd3d-shader/ir: Normalise control point phase output registers to include the control point id.
In SPIR-V the address must include the invocation id, but in TPF it
is implicit. Move the register index up one slot and insert an
OUTPOINTID relative address.
2023-04-12 21:54:27 +02:00
Zebediah Figura
616c4bf51f vkd3d-shader/hlsl: Always align section sizes.
This fixes disassembly using native D3DDisassemble() of shaders generated with vkd3d-shader.

Fixes: d6d9aab31c
2023-04-06 17:52:16 +02:00
Zebediah Figura
a60c47ff39 vkd3d-shader: Explicitly align the size in bytecode_get_next_offset() and rename it accordingly. 2023-04-06 17:52:16 +02:00
Zebediah Figura
1514755043 vkd3d-shader/hlsl: Make a string array const. 2023-04-06 17:52:07 +02:00