Commit Graph

3162 Commits

Author SHA1 Message Date
Nikolay Sivov
75299c04fd vkd3d-shader: Handle the SV_SampleIndex semantic.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-10 21:39:03 +02:00
Giovanni Mascellani
bfd1fc9cd6 vkd3d-shader/ir: Assume that Hull Shaders have a control point phase in vsir_program_normalise_io_registers().
The control point phase is always introduced, when missing, by the
earlier instruction_array_normalise_hull_shader_control_point_io()
pass.
2024-09-05 16:33:05 +02:00
Giovanni Mascellani
7b9a1bf6df vkd3d-shader/ir: Run validation after materializing undominated SSAs to TEMPs. 2024-09-05 16:29:47 +02:00
Giovanni Mascellani
08c1f4d45e vkd3d-shader/ir: Run validation after flattening control flow constructs. 2024-09-05 16:29:17 +02:00
Giovanni Mascellani
455c826a6a vkd3d-shader/ir: Run validation after structurization. 2024-09-05 16:29:11 +02:00
Giovanni Mascellani
e935dcb88d vkd3d-shader/ir: Run validation after lowering switches to selection ladders. 2024-09-05 16:29:02 +02:00
Giovanni Mascellani
4a28433ef5 vkd3d-shader/ir: Run validation after materializing PHI SSAs to TEMPs. 2024-09-05 16:26:52 +02:00
Giovanni Mascellani
fade5dd54c vkd3d-shader/ir: Run validation after lowering instructions. 2024-09-05 16:25:33 +02:00
Giovanni Mascellani
ffb7284fb6 vkd3d-shader/ir: Do not decide the control flow type on NOPs. 2024-09-05 16:20:39 +02:00
Giovanni Mascellani
829e6f5cd0 vkd3d-shader/ir: Emit a warning instead of an error on validation failures. 2024-09-05 16:20:39 +02:00
Henri Verbeet
03d76f653b vkd3d-shader/d3dbc: Use VKD3D_SM1_INSTRUCTION_LENGTH_SHIFT instead of D3DSI_INSTLENGTH_SHIFT. 2024-09-05 12:47:43 +02:00
Henri Verbeet
b9693393fd vkd3d-shader/d3dbc: Store a enum vkd3d_sm1_opcode in struct sm1_instruction. 2024-09-05 12:45:43 +02:00
Nikolay Sivov
0a6bcf5da7 vkd3d-shader/tpf: Fix a typo when adding the SFI0 section.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-04 18:43:41 +02:00
Henri Verbeet
a214e96cf8 vkd3d-shader/tpf: Use enum vkd3d_sm4_data_type in sm4_resource_format(). 2024-09-04 18:42:26 +02:00
Henri Verbeet
b61675d0f3 vkd3d-shader/tpf: Use enum vkd3d_shader_component_type in write_sm4_signature(). 2024-09-04 18:40:56 +02:00
Shaun Ren
c1babbc8aa vkd3d-shader/hlsl: Validate hull shader attributes. 2024-09-04 18:30:04 +02:00
Shaun Ren
6c1dc53d15 vkd3d-shader/hlsl: Parse the patchconstantfunc attribute. 2024-09-04 18:30:04 +02:00
Shaun Ren
41cb29c4c8 vkd3d-shader/hlsl: Parse the partitioning attribute. 2024-09-04 18:28:59 +02:00
Shaun Ren
615ffb823b vkd3d-shader/hlsl: Parse the outputtopology attribute. 2024-09-04 18:28:57 +02:00
Shaun Ren
dae88bab52 vkd3d-shader/hlsl: Parse the outputcontrolpoints attribute. 2024-09-04 18:28:46 +02:00
Shaun Ren
4dfd682446 vkd3d-shader/hlsl: Parse the domain attribute. 2024-09-04 18:21:15 +02:00
Shaun Ren
51e9b05fe5 vkd3d-shader/hlsl: Introduce parse_entry_function_attributes() helper. 2024-09-04 18:18:23 +02:00
Shaun Ren
73ee5a135a vkd3d-shader/hlsl: Check for duplicate attributes in function declaration. 2024-09-04 18:18:23 +02:00
Petrichor Park
855b9713b8 vkd3d-shader/hlsl: Implement the sincos() intrinsic. 2024-09-04 18:16:37 +02:00
Petrichor Park
384810b4ba vkd3d-shader/hlsl: Implement the dst() intrinsic. 2024-09-04 18:08:24 +02:00
Francisco Casas
7ec44bd70b vkd3d-shader/hlsl: Parse the CompileShader() syntax. 2024-09-04 17:59:34 +02:00
Francisco Casas
45f18a7838 vkd3d-shader/hlsl: Parse the shader 'compile' syntax.
The hlsl_ir_compile node is introduced to represent the "compile"
syntax, and later the CompileShader() and ConstructGSWithSO()
constructs.

It basically represents a function call that remembers its arguments
using hlsl_srcs and keeps its own instruction block, which is discarded
when working on non-effect shaders.

For shader compilations it can be asserted that args_count is 1, and
that this argument (and the last node in hlsl_ir_effect_call.instrs)
is a regular hlsl_ir_call pointing to the declaration of the function
to be compiled.
2024-09-04 17:58:56 +02:00
Francisco Casas
379cd9b7b5 vkd3d-shader/hlsl: Save hlsl_ir_swizzles in the vsir_program for SM1. 2024-09-04 17:51:32 +02:00
Francisco Casas
b46eac35c0 vkd3d-shader/hlsl: Save hlsl_ir_stores in the vsir_program for SM1. 2024-09-04 17:51:32 +02:00
Francisco Casas
9aace1ac4e vkd3d-shader/hlsl: Save hlsl_ir_loads in the vsir_program for SM1. 2024-09-04 17:51:32 +02:00
Francisco Casas
23e3ec84f7 vkd3d-shader/hlsl: Save hlsl_ir_constants in the vsir_program for SM1. 2024-09-04 17:51:30 +02:00
Francisco Casas
a61846c28a vkd3d-shader/hlsl: Store SM1 sampler dcls on the vsir_program. 2024-09-04 17:47:47 +02:00
Francisco Casas
9a564872c5 vkd3d-shader/hlsl: Store SM1 constant dcls on the vsir_program. 2024-09-04 17:44:46 +02:00
Francisco Casas
7abf3c3a37 vkd3d-shader/hlsl: Introduce hlsl_ir_vsir_instruction_ref.
This node type will be deleted once the hlsl->vsir->d3dbc translation is
complete. For now it serves the purpose of allowing to keep both real
hlsl_ir_nodes and vsir_instructions in the hlsl_block, until all the
former can be translated into the latter.
2024-09-04 16:49:00 +02:00
Anna (navi) Figueiredo Gomes
3d8fc1a467 vkd3d-shader/spirv: Break long assembly lines.
Avoid overflowing the (Wine) debug log buffer when output lines are too
long, and keep spirv-text output more legible. The output is still valid
SPIR-V asm, as the assembler does not care for which kind of whitespace
is used.
2024-09-03 17:06:20 +02:00
Victor Chiletto
a39227c79c vkd3d-shader/hlsl: Fold logic AND and logic OR identities. 2024-09-03 15:11:16 +02:00
Nikolay Sivov
6d28cc131b vkd3d-shader/fx: Fix the unpacked size and stride fields of the fx_4_0 types.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-02 19:14:59 +02:00
Nikolay Sivov
9673b660d4 vkd3d-shader/fx: Expand BlendState array fields for fx_4_1 as well.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-02 19:14:59 +02:00
Nikolay Sivov
1ed4543007 vkd3d-shader/fx: Only add numeric variables when writing buffers.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-02 19:14:59 +02:00
Nikolay Sivov
ee2da76e6d vkd3d-shader/fx: Set structure field offsets in bytes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-09-02 19:14:59 +02:00
Henri Verbeet
7a74e79f2d vkd3d-shader/d3dbc: Return a vkd3d_decl_usage from hlsl_sm1_usage_from_semantic(). 2024-09-02 19:14:01 +02:00
Henri Verbeet
1c01560321 vkd3d-shader/tpf: Return a vkd3d_shader_sysval_semantic from hlsl_sm4_usage_from_semantic(). 2024-09-02 19:12:53 +02:00
Anna (navi) Figueiredo Gomes
f5205da8e9 vkd3d-shader/spirv: Pass a vkd3d_shader_descriptor_info1 structure to spirv_compiler_build_descriptor_variable(). 2024-09-02 19:10:19 +02:00
Anna (navi) Figueiredo Gomes
672a8f5ce9 vkd3d-shader/spirv: Pass a vkd3d_shader_descriptor_info1 structure to spirv_compiler_emit_sampler_declaration(). 2024-09-02 18:59:37 +02:00
Anna (navi) Figueiredo Gomes
22aad955ec vkd3d-shader/spirv: Pass a vkd3d_shader_descriptor_info1 structure to spirv_compiler_emit_cbv_declaration(). 2024-09-02 18:58:29 +02:00
Anna (navi) Figueiredo Gomes
2a52ccf2c6 vkd3d-shader/spirv: Pass a vkd3d_shader_descriptor_info1 structure to spirv_compiler_emit_resource_declaration(). 2024-09-02 18:54:19 +02:00
Giovanni Mascellani
527966580e vkd3d-shader: Dump the converted shader too. 2024-08-29 19:17:07 +02:00
Giovanni Mascellani
1a0d6a4db4 vkd3d-shader: Use a hash to build the filename when dumping shaders.
This way the same shader is always dumped to the same path and when
launching the same program over and over we avoid both creating new
copies of the same file each time and overwriting different dumped
shaders.
2024-08-29 19:14:27 +02:00
Henri Verbeet
0e72aba0bc Release 1.13. 2024-08-29 12:08:46 +02:00
Elizabeth Figura
eb71a1722a vkd3d-shader: Use an extended version of vkd3d_shader_immediate_constant in vkd3d_shader_parameter1.
This is a proposed API change in 946, which won't make it into this release.

The intent is to allow slightly larger constants to be specified in the updated
vkd3d_shader_parameter1 structure. In particular, this is large enough to pass
4-dimensional integer or float vectors inline, which the proposed clip plane
implementation will use, as well as other Direct3D FFP parameters.

We could also simply add vkd3d_shader_immediate_constant1 as a separate union
member in vkd3d_shader_parameter1, but this API is a bit cleaner and simpler.
2024-08-28 12:08:37 +02:00
Henri Verbeet
f318e565f2 vkd3d-shader/spirv: Decorate non-array descriptor variables as well.
Commits 343c7942e1 and
94c74d2c00 moved applying the NonReadable
and Coherent decorations from spirv_compiler_emit_resource_declaration()
to spirv_compiler_build_descriptor_variable(), but unfortunately missed
the non-array path in the latter function.

The missing NonReadable decoration causes segmentation faults in
rasteriser-ordered-views.shader_test (among others) on my Intel SKL GT2
setup in particular.
2024-08-26 11:24:01 +02:00
Conor McCarthy
738ecc9eb1 vkd3d-shader/spirv: Free the spirv parameter info. 2024-08-20 21:27:58 +02:00
Anna (navi) Figueiredo Gomes
94c74d2c00 vkd3d-shader/spirv: Avoid decorating variables multiple times with Coherent. 2024-08-20 21:25:15 +02:00
Anna (navi) Figueiredo Gomes
a47c23fa1f vkd3d-shader/spirv: Use unique SPIR-V variables for descriptors where visibility differs.
In the case two uav descriptors are mapped to the same variable, and one is
read from while the other is not, the variable would get the NonReadable
decorator, while being read from later.
2024-08-20 21:23:31 +02:00
Anna (navi) Figueiredo Gomes
343c7942e1 vkd3d-shader/spirv: Avoid decorating variables multiple times with NonReadable.
The existing code reuses the same SPIR-V variable for all descriptors mapped to
the same Vulkan binding, and applies the NonReadable decoration based on the
VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_READ only. This potentially causes the
decoration to be applied twice, should two non-read descriptors be mapped to
the same variable, which isn't allowed in SPIR-V, and the validator complains.
2024-08-20 21:20:33 +02:00
Nikolay Sivov
c8cc1b1a24 vkd3d-shader/fx: Fix the matrix type class for fx_2_0.
CTAB type correctly reflects matrix majority, unlike effects
type data that does not respond to majority modifiers at all.
It doesn't transpose default values either.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-19 14:21:59 +02:00
Nikolay Sivov
f0a2e4bc25 vkd3d-shader/glsl: Fix a typo in a few messages.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-19 14:20:21 +02:00
Nikolay Sivov
d1b8a7e745 vkd3d: Fix a few typos in the comments.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-19 14:17:41 +02:00
Petrichor Park
4467c655f0 vkd3d-shader/hlsl: Factor out add_binary_expr() and use it for assignment operators.
This fixes a lot of internal compiler errors with assignment operators,
especially bitwise ones. The bitwise-assignment test has the motivating
examples.
2024-08-19 14:15:43 +02:00
Nikolay Sivov
ebc039d128 vkd3d-shader/fx: Resolve NULL values for SamplerState.Texture field.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-15 17:53:46 +02:00
Nikolay Sivov
873b182021 vkd3d-shader/fx: Support NULL constants for object fields.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-15 17:53:46 +02:00
Nikolay Sivov
c3075d6fb4 vkd3d-shader/hlsl: Adjust NULL type properties to make it usable in transformations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-15 17:53:46 +02:00
Nikolay Sivov
aa0ea548e4 vkd3d-shader/fx: Handle SetPixelShader() and SetVertexShader().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-15 17:53:46 +02:00
Nikolay Sivov
2c533e494a vkd3d-shader/fx: Handle SetBlendState().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-15 17:53:46 +02:00
Nikolay Sivov
60ce81112b vkd3d-shader/fx: Support string annotations for fx_4+.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-14 22:00:35 +02:00
Nikolay Sivov
d4ae844bb6 vkd3d-shader/fx: Enable writing string objects for fx_4+.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-14 22:00:35 +02:00
Nikolay Sivov
89be723ad7 vkd3d-shader/hlsl: Treat "string" type name as case-insensitive.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-14 22:00:35 +02:00
Nikolay Sivov
1ce68cee2c vkd3d-shader/hlsl: Tokenize 'String' the same as 'string'.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-14 22:00:35 +02:00
Francisco Casas
412f91a14c vkd3d-shader/hlsl: Always work with the extern resource's component type.
We need to distinguish between the data type of a resource and the data
type of its components. These are usually the same except for 4.0
profiles where an array (or multi-dimensional array) of resources is
still considered a single resource, so it is possible for it to hold
more than one component.

In the latter case, we often need to access the type of a single
component (all components have the same type) instead of the type of the
whole array which often doesn't contain the required information, such
as sampler dimension.

This patch replaces the extern_resource.data_type field with the
extern_resource.component_type field, which points to the type of a
single component in the resource. Using it relieves many other code
paths from considering the possibility of the resource being an array.

This fixes runtime errors reported by UBSan, such as this:

    vkd3d/libs/vkd3d-shader/tpf.c:6075:87: runtime error: load of value 7, which is not a valid value for type '_Bool'

when trying to compile shaders that contain UAV arrays on 4.0 profiles.

Before this commit, tpf.c accesses the

    hlsl_type->e.resource.rasteriser_ordered

field, but on 4.0 and 4.1 profiles these code paths can also be reached
by UAV arrays which are HLSL_CLASS_ARRAY and this field is not supposed
to be accessed.

By coincidence, the value of hlsl_type->e.array.elements_count was being
read because these fields have the same offset in the hlsl_type.e union.
2024-08-14 21:57:21 +02:00
Henri Verbeet
114578fc8a vkd3d-shader/fx: Replace assert() with VKD3D_ASSERT(). 2024-08-13 21:20:28 +02:00
Francisco Casas
355d4c4a86 vkd3d-shader/hlsl: Skip writing string default values.
This causes a crash in the native compiler, but can only happen in
ps_5_0 were it is possible to declare structs that are both used in the
shader and contain strings.

    struct
    {
        float a;
        string b;
    } apple = {1, "foobar"};

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

In our case, hlsl_type_get_component_offset() triggered an assertion
failure because it does not expect the string type. So this is replaced
by an hlsl_error().
2024-08-13 21:19:04 +02:00
Francisco Casas
094e298c1c vkd3d-shader/hlsl: Parse string default values. 2024-08-13 21:19:01 +02:00
Nikolay Sivov
b4d957f848 vkd3d-shader/hlsl: Handle NULL constants.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-13 21:10:45 +02:00
Nikolay Sivov
d945d5e78c vkd3d-shader/hlsl: Check MS texture declaration without sample count only for used variables.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-13 21:10:29 +02:00
Anna (navi) Figueiredo Gomes
80b2a2eb55 vkd3d-shader/ir: Periodically flush buffers when tracing blocks.
Avoids overflowing the output buffer for the trace in cases where the
output is too long, which raises an exception.
2024-08-12 14:19:13 +02:00
Nikolay Sivov
b0ca3627bf vkd3d-shader/fx: Turn assignments to arrays to element assignments for certain states. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
25e1c3e374 vkd3d-shader/fx: Explicitly handle bool values in state entries. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
c81223d086 vkd3d-shader/fx: Handle states of a BlendState object. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
2affc8f5c5 vkd3d-shader/fx: Run full set of constants passes on state block entries values. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
f1e65ecc83 vkd3d-shader/fx: Enable writing BlendState variables. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
91e88fac2e vkd3d-shader/hlsl: Add parser support for BlendState type. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
1be0d99b76 vkd3d-shader/fx: Check destination array index when checking for duplicate state entries. 2024-08-12 14:15:14 +02:00
Nikolay Sivov
b23874dad6 vkd3d-shader/hlsl: Add parser support for GeometryShader type.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-08 23:42:37 +02:00
Nikolay Sivov
de48960b33 vkd3d-shader/fx: Add support for the OMSetRenderTargets() state. 2024-08-08 23:42:37 +02:00
Nikolay Sivov
c565a60b9e vkd3d-shader/fx: Add an array size field to the states description table. 2024-08-08 23:42:37 +02:00
Nikolay Sivov
d55a709992 vkd3d-shader/fx: Use more descriptive names for FX-specific types. 2024-08-08 23:42:37 +02:00
Nikolay Sivov
9fb23b9090 vkd3d-shader/fx: Handle "Texture" field of the sampler state objects.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2024-08-08 23:42:37 +02:00
Giovanni Mascellani
8b6ab9627d vkd3d-shader: Replace assert() with VKD3D_ASSERT() in vkd3d_shader_private.h. 2024-08-08 23:39:23 +02:00
Giovanni Mascellani
27bceec965 vkd3d-shader: Replace assert() with VKD3D_ASSERT() in vkd3d_shader_main.c. 2024-08-08 23:39:23 +02:00
Giovanni Mascellani
0294aa62f3 vkd3d-shader: Replace assert() with VKD3D_ASSERT() in tpf.c. 2024-08-08 23:38:02 +02:00
Giovanni Mascellani
d5126b4d98 vkd3d-shader: Replace assert() with VKD3D_ASSERT() in spirv.c. 2024-08-08 23:36:23 +02:00
Victor Chiletto
8c3a5e5458 vkd3d-shader/hlsl: Implement f16tof32 intrinsic. 2024-08-08 23:35:02 +02:00
Victor Chiletto
693e89c74e vkd3d-shader/hlsl: Push a new scope when compiling internal functions.
This allows for typedef usage without interfering with user code.
Thanks Zeb for the suggestion.
2024-08-08 23:35:02 +02:00
Francisco Casas
016be7e591 vkd3d-shader/hlsl: Lower non-constant row_major matrix loads for SM1. 2024-08-08 23:33:33 +02:00
Francisco Casas
87f01f5205 vkd3d-shader/hlsl: Remove SM1 fixme for matrix writemasks.
hlsl_ir_store instructions don't use writemasks for whole matrices.
2024-08-08 23:32:03 +02:00
Francisco Casas
9f515a9daa vkd3d-shader/hlsl: Lower non-constant array loads for SM1.
This is achieved by means of creating a variable storing zero,
loading every array element, comparing if the non-constant index
matches the index of that element at runtime, and in that case
store the corresponding element in the variable.

This seems to be the same strategy that the native compiler uses.
2024-08-08 23:30:39 +02:00
Francisco Casas
eb2d320596 vkd3d-shader/hlsl: Avoid dereferencing rel_offset if it is NULL.
We are currently using &offset_node->loc when offset_node is NULL.

A NULL dereference of rel_offset can also happen if
hlsl_offset_from_deref() fails because the dereference is out of
bounds.
2024-08-08 23:28:31 +02:00
Francisco Casas
e8354ac499 vkd3d-shader/hlsl: Parse string type. 2024-08-07 15:53:07 +02:00
Francisco Casas
652db433e1 vkd3d-shader/hlsl: Parse string escape sequences. 2024-08-07 15:51:43 +02:00
Francisco Casas
090df488ba vkd3d-shader/hlsl: Parse string constants. 2024-08-07 15:48:59 +02:00