Commit Graph

2562 Commits

Author SHA1 Message Date
Henri Verbeet
65b7154a22 vkd3d-shader/sm4: Set "dst_count" to 0 when we clear "dst" in shader_sm4_read_instruction().
VKD3D_SM4_OP_DCL_RESOURCE currently has 1 for "dst_count", but NULL for
"dst". This is largely harmless because we never attempt to access the
destination register of VKD3DSIH_DCL instructions, but nevertheless not
quite proper.
2023-03-13 22:09:49 +01:00
Zebediah Figura
da2435707b vkd3d-shader/hlsl: Fix some memory leaks in the function call rule. 2023-03-09 22:11:06 +01:00
Nikolay Sivov
193692bbcb vkd3d-shader/hlsl: Use array element type for array's regset.
Currently this affects SM1 compilation only, with a minimal example like this:

float4 var[3];
float4 main() : sv_target
{
    return var[1];
}
2023-03-09 22:10:39 +01:00
Nikolay Sivov
2880be647e vkd3d-shader/sm4: Write sample count field for multisampled texture declaration.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-03-08 20:15:11 +01:00
Nikolay Sivov
ae2f777a4d vkd3d-shader/hlsl: Parse multisample texture type names. 2023-03-08 20:15:09 +01:00
Nikolay Sivov
ee52ad8106 vkd3d-shader/trace: Output sample count for multisampled resources. 2023-03-08 20:15:06 +01:00
Conor McCarthy
9f6e6d3fcd vkd3d-shader/dxbc: Validate and skip the signature section header size.
Silences a very common warning.
2023-03-08 20:14:59 +01:00
Conor McCarthy
3b5316be82 vkd3d-shader/dxbc: Emit a shader error for an invalid signature data size. 2023-03-08 20:14:57 +01:00
Conor McCarthy
83e39e2650 vkd3d-shader/dxbc: Pass a message context to for_each_dxbc_section(). 2023-03-08 20:14:55 +01:00
Giovanni Mascellani
bb2fa97c33 vkd3d: Do not keep the CS queue locked while processing it.
d3d12_command_queue_flush_ops() can renter itself while processing signal
events. Since we don't use recursive mutexes, we currently have to check
some of the queue variables without holding the mutex, which is not safe.

This is solved by allowing the queue to release its mutex while it is
processing entries: when flushing, the queue is briefly locked, the
is_flushing flag is set, the queue content is copied away and the
queue is unlocked again. After having processed the entries, the
queue is locked again to check is something else was added in the
meantime. This is repeated until the queue is empty (or a wait operation
is blocking it).

This should also remove some latency when a thread pushes to the queue
while another one is processing it, but I didn't try to measure any
impact. While it is expected that with this patch the queue mutex
will be locked and unlocked more frequently, it should also remain
locked for less time, hopefully creating little contention.
2023-03-08 20:14:39 +01:00
Giovanni Mascellani
09d2c8d190 vkd3d: Always enqueue wait operations, even when they can be executed right away. 2023-03-08 20:14:39 +01:00
Giovanni Mascellani
9eba44396a vkd3d: Always enqueue signal operations, even when they can be executed right away. 2023-03-08 20:14:39 +01:00
Giovanni Mascellani
0d329ba168 vkd3d: Always enqueue execute operations, even when they can be executed right away.
The goal is to simplify the CS queue handling: with this and the following
changes operations are always started by d3d12_command_queue_flush_ops(),
in order to make further refactoring easier.

Notice that while with this change executing an operation on an empty CS
queue is a bit less efficient, it doesn't require more locking. On the other
hand, this change paves the road for executing CS operations without holding
the queue lock.
2023-03-08 20:14:35 +01:00
Giovanni Mascellani
0c6df49560 vkd3d: Hold the queue mutex when adding the queue to a blocked list.
Otherwise it could be added more than once.

Note that the deleted comment is wrong: between when d3d12_command_queue_flush_ops()
returns and when the queue is added back to the blocked list, the queue
might have been pushed to and flushed an arbitrary number of times.
2023-03-08 20:14:31 +01:00
Giovanni Mascellani
ef8d272507 vkd3d: Mention the correct mutex in a comment. 2023-03-08 20:14:31 +01:00
Nikolay Sivov
a18f3d4dd5 vkd3d-shader/hlsl: Support distance() intrinsic. 2023-03-08 20:14:22 +01:00
Nikolay Sivov
d6b656641c vkd3d-shader/hlsl: Support rsqrt() intrinsic. 2023-03-08 20:14:20 +01:00
Zebediah Figura
a28ecaa135 vkd3d-shader/hlsl: Get rid of the check_invalid_matrix_modifiers() helper. 2023-02-28 22:07:01 +01:00
Zebediah Figura
5838364886 vkd3d-shader/hlsl: Apply latent majority modifiers to typedefs as well. 2023-02-28 22:07:00 +01:00
Zebediah Figura
322963add8 vkd3d-shader/hlsl: Do not set an initial latent matrix majority.
This change does nothing by itself.
2023-02-28 22:06:59 +01:00
Zebediah Figura
75ab9d31ef vkd3d-shader/hlsl: Store the matrix majority as a type modifiers bitmask. 2023-02-28 22:06:58 +01:00
Zebediah Figura
b3c620954b vkd3d-shader/hlsl: Apply latent type modifiers to matrix array typedefs. 2023-02-28 22:06:56 +01:00
Francisco Casas
af25d5bf96 vkd3d-shader/hlsl: Don't map src swizzles for SM1 dp3 and dp4 ops.
Without this patch, dp3 and dp4 map src swizzles to the dst writemask,
which is not correct.

Before b84f560bdf, these ops worked
despite this, because the dst register had, incorrectly, the full
writemask.

To solve this problem, write_sm1_binary_op_dot() is introduced,
similarly to write_sm4_binary_op_dot().
2023-02-27 22:12:38 +01:00
Giovanni Mascellani
a1c6bb85ad vkd3d-shader: Do not pass client-given strings as printf()-style format strings. 2023-02-27 22:12:26 +01:00
Henri Verbeet
b1e13d6e33 vkd3d-shader/dxbc: Introduce API for serialising DXBC blobs. 2023-02-23 21:47:27 +01:00
Henri Verbeet
c87492ed21 vkd3d-shader/dxbc: Introduce API for parsing DXBC blobs. 2023-02-23 21:47:26 +01:00
Henri Verbeet
d0d2130f74 vkd3d-shader/dxbc: Rename parse_dxbc() to for_each_dxbc_section(). 2023-02-23 21:47:23 +01:00
Henri Verbeet
a06320c1fc vkd3d-shader/dxbc: Pass a vkd3d_shader_code structure to parse_dxbc(). 2023-02-23 21:47:22 +01:00
Henri Verbeet
2f762465a6 vkd3d-shader/dxbc: Pass a vkd3d_shader_code structure to shader_extract_from_dxbc(). 2023-02-23 21:47:21 +01:00
Henri Verbeet
3a3acb5b7d vkd3d-shader/dxbc: Pass a vkd3d_shader_code structure to shader_parse_input_signature(). 2023-02-23 21:47:20 +01:00
Henri Verbeet
e2825f7658 vkd3d-shader/dxbc: Pass a vkd3d_shader_dxbc_section_desc structure to the parse_dxbc() section handler. 2023-02-23 21:47:19 +01:00
Henri Verbeet
5020781f76 vkd3d-shader/dxbc: Pass a vkd3d_shader_dxbc_section_desc structure to shader_parse_root_signature(). 2023-02-23 21:47:18 +01:00
Henri Verbeet
6c64f8a217 vkd3d-shader/dxbc: Pass a vkd3d_shader_dxbc_section_desc structure to shader_parse_signature(). 2023-02-23 21:47:16 +01:00
Henri Verbeet
bf3c012834 vkd3d-shader/dxbc: Rename the dxbc_writer_section structure to vkd3d_shader_dxbc_section_desc.
In preparation of exposing it in the public API.
2023-02-23 21:47:15 +01:00
Henri Verbeet
b59de4de5c vkd3d-shader/dxbc: Store DXBC section data as a vkd3d_shader_code structure. 2023-02-23 21:47:13 +01:00
Zebediah Figura
dea212688a vkd3d: Remove a double space in a trace message. 2023-02-23 21:46:49 +01:00
Nikolay Sivov
dd36215a00 vkd3d-shader/hlsl: Support case-insensitive lookup for builtin 'float' type.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-02-23 21:46:42 +01:00
Nikolay Sivov
df2d6d35e2 vkd3d-shader/hlsl: Use unsigned type for the 'dword' alias.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-02-23 21:46:40 +01:00
Nikolay Sivov
891217664a vkd3d-shader/hlsl: Support case-insensitive lookup for builtin 'dword' type. 2023-02-23 21:46:38 +01:00
Zebediah Figura
e10e12a10c vkd3d-shader: Avoid underflowing the indentation level.
Any shader that would underflow is invalid, but it is helpful to allow tracing even invalid shaders.
2023-02-22 18:28:19 +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
Francisco Casas
e0031d2a1f vkd3d-shader/hlsl: Keep an hlsl_reg for each register set in hlsl_ir_var. 2023-02-22 18:28:19 +01:00
Francisco Casas
5272c5f86a vkd3d-shader/hlsl: Obtain extern resources as a separate array in SM4. 2023-02-22 18:28:19 +01:00
Francisco Casas
d07247249a vkd3d-shader/hlsl: Store the type's register size for each register set. 2023-02-22 18:28:19 +01:00
Francisco Casas
315966dc21 vkd3d-shader/hlsl: Leave offset empty for array and struct derefs. 2023-02-22 18:28:19 +01:00
Zebediah Figura
7c1c2e6cc4 vkd3d-shader/hlsl: Parse the tex3D() intrinsic. 2023-02-22 18:28:19 +01:00
Zebediah Figura
645ec0167a vkd3d-shader/hlsl: Parse the tex2D() intrinsic. 2023-02-22 18:28:19 +01:00
Francisco Casas
9fdff25a3b vkd3d-shader/hlsl: Avoid segfault on missing sampler. 2023-02-22 18:28:19 +01:00
Nikolay Sivov
d86db8bcbe vkd3d-shader/hlsl: Support lit() intrinsic. 2023-02-21 21:09:52 +01:00
Francisco Casas
7f009f59ce vkd3d-shader/hlsl: Add a more specific error for missing compatible fn. definitions. 2023-02-20 21:59:54 +01:00
Francisco Casas
f08c0a7c03 vkd3d-shader/hlsl: Find compatible function overloads.
But still throw hlsl_fixme() when there is more than one.
Prioritizing among multiple compatible function overloads in the same way
as the native compiler would require systematic testing.
2023-02-20 21:59:53 +01:00
Francisco Casas
d279d34801 vkd3d-shader/hlsl: Parse array types in function parameters. 2023-02-20 21:59:51 +01:00
Francisco Casas
2a9b9f7530 vkd3d-shader/hlsl: Rename compatible_data_types() to be more specific. 2023-02-20 21:59:50 +01:00
Zebediah Figura
6767b7abbf vkd3d-shader/hlsl: Avoid warning for each variable when in/out modifiers are specified on non-parameters. 2023-02-20 21:59:45 +01:00
Zebediah Figura
72ec5563f8 vkd3d-shader/hlsl: Remove a redundant warning for mutually exclusive majority modifiers.
We will warn subsequently in apply_type_modifiers() or add_typedef().
2023-02-20 21:59:43 +01:00
Zebediah Figura
af65287423 vkd3d-shader/hlsl: Check for majority modifiers on non-matrices in apply_type_modifiers(). 2023-02-20 21:59:42 +01:00
Nikolay Sivov
e5b40092c2 vkd3d-shader/hlsl: Support all() intrinsic. 2023-02-20 21:59:37 +01:00
Francisco Casas
2142d31f13 vkd3d-shader/hlsl: Fix number of components when creating a swizzle in copy-prop.
Otherwise we may create nodes of different dimensions than the ones we
are replacing.

"count" is the number of components of the source deref (without
considering the swizzle), while "instr_component_count" is the actual
number of components of the instruction to be replaced.
2023-02-20 21:59:31 +01:00
Nikolay Sivov
e7bc634307 vkd3d-shader/hlsl: Support reflect() intrinsic.
Tests authored by Giovanni.
2023-02-20 21:59:23 +01:00
Giovanni Mascellani
7c3dadce6b vkd3d-shader/hlsl: Write SM4 break instructions. 2023-02-15 21:53:21 +01:00
Nikolay Sivov
99acf5038e vkd3d-shader/hlsl: Use mul only for two scalars for dot(). 2023-02-15 21:53:15 +01:00
Zebediah Figura
0e60f4cc69 vkd3d-shader/hlsl: Always set ctx->cur_function in the func_prototype_no_attrs rule.
Fixes: 4c46075d86
2023-02-14 21:52:59 +01:00
Zebediah Figura
cd6e8b5540 vkd3d-shader/hlsl: Allow empty parameter lists to be specified as "(void)". 2023-02-14 21:52:57 +01:00
Zebediah Figura
58445da64b vkd3d-shader/hlsl: Allow the final expression in a for loop initializer to be omitted. 2023-02-13 22:16:56 +01:00
Zebediah Figura
38964214cd vkd3d-shader/hlsl: Handle early return after a CF block only if there was actually a return somewhere in the CF block. 2023-02-13 22:16:55 +01:00
Zebediah Figura
4b944517b7 vkd3d-shader/hlsl: Inline function calls. 2023-02-13 22:16:53 +01:00
Zebediah Figura
6177cea31f vkd3d-shader/hlsl: Emit a hlsl_fixme() for unhandled instruction types when writing bytecode.
This was originally left alone in order to allow functions without early return
to succeed, since in that case we would already emit the correct bytecode
despite not handling the HLSL_IR_JUMP_RETURN instruction.

Now that we lower return statements, however, any unhandled instructions are
either definitely going to result in invalid bytecode, or rare enough that it's
not worth returning success anyway.
2023-02-13 22:16:52 +01:00
Zebediah Figura
8bdee6681b vkd3d-shader/hlsl: Lower return statements. 2023-02-13 22:16:51 +01:00
Zebediah Figura
0cf39f3c63 vkd3d-shader/hlsl: Emit a hlsl_fixme() if multiple valid entry point definitions are given. 2023-02-13 22:16:49 +01:00
Zebediah Figura
bb41c3b5fe vkd3d-shader/hlsl: Skip functions that don't have a body when looking for the entry point. 2023-02-13 22:16:48 +01:00
Giovanni Mascellani
8e087b0f17 vkd3d: Use a dedicated mutex to protect the blocked queues. 2023-02-13 22:16:44 +01:00
Giovanni Mascellani
df36026633 vkd3d: Do not read max_pending_value without holding the fence's mutex. 2023-02-13 22:16:44 +01:00
Giovanni Mascellani
e076fd9c77 vkd3d: Do not read blocked_queue_count without holding the device mutex. 2023-02-13 22:16:42 +01:00
Nikolay Sivov
240b2f966f vkd3d-shader/hlsl: Support abs() for SM1. 2023-02-09 18:03:19 +01:00
Francisco Casas
902ddee557 vkd3d-shader/hlsl: Fix SM1 dp2add swizzles.
SM1 dp2add doesn't map src swizzles to the dst writemask, also it
expects the last argument to have a replicate swizzle.

Before this patch we were writing the operation as:
```
dp2add r0.x, r1.x, r0.x, r2.x
```

and now it is:
```
dp2add r0.x, r1.xyxx, r0.xyxx, r2.x
```

dp2add now has its own function, write_sm1_dp2add(), since it seems to
be the only instruction with this structure.

Ideally we would be using the default swizzles for the first two src
arguments:
```
dp2add r0.x, r1, r0, r2.x
```
since, according to native's documentation, these are supported for all
sm < 4.

But this change -- along with following the convention of repeating the
last component of the swizzle when fewer than 4 components are to be
specified -- would require more global changes, probably in
hlsl_swizzle_from_writemask() and hlsl_map_swizzle().
2023-02-08 22:09:42 +01:00
Francisco Casas
d01729921c vkd3d-shader/hlsl: Map SM1 src swizzles outside write_sm1_instruction().
Not every instruction expects src swizzles to be mapped according to the
dst writemasks, so this logic must be outside this function.
2023-02-08 22:09:41 +01:00
Francisco Casas
b84f560bdf vkd3d-shader/hlsl: Set writemasks correctly for SM1 scalar and vector types.
Because of the change introduced in

f21693b2 vkd3d-shader/hlsl: Use reg_size as component count when allocating a single register.

SM1 scalars and vectors were not longer getting the correct writemask
when they are allocated.

This happened because they have to reserve the whole register even if
they only use some of its components, so their reg_size may differ from
the number of components.

This commit fixes that.
2023-02-08 22:09:39 +01:00
Francisco Casas
6b4a4c4c6d vkd3d-shader/hlsl: Expect component count in allocate_register().
This in order to set the correct writemasks for SM1 registers.
2023-02-08 22:09:38 +01:00
Francisco Casas
0ecac994d0 vkd3d-shader/hlsl: Rename 'component_count' arguments to 'reg_size'.
component_count will be used in the next patch for the actual number of
components of the type and not its register size.
2023-02-08 22:09:36 +01:00
Zebediah Figura
ab601d65cd vkd3d-shader: Initialize the parameter allocator head.
This fixes a memory leak.

Fixes: 007f894b94
2023-02-07 22:15:08 +01:00
Nikolay Sivov
91a70c7dda vkd3d-shader/hlsl: Handle saturate() for SM1.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-02-07 22:15:06 +01:00
Zebediah Figura
77d716c811 vkd3d-shader/hlsl: Add functions to the global list inside the func_prototype rule. 2023-02-07 22:15:06 +01:00
Zebediah Figura
4c46075d86 vkd3d-shader/hlsl: Use the original hlsl_ir_function_decl struct rather than allocating a new one for each definition.
We need to make sure every invocation points to the same hlsl_ir_function_decl
and the same parameters.

This fixes some invalid memory accesses.
2023-02-07 22:15:06 +01:00
Zebediah Figura
25d49b518d vkd3d-shader/hlsl: Put synthetic variables into a dummy scope.
Prevent them from being ever looked up.

Our naming scheme for synthetic variables already effectively prevents this, but
this is better for clarity. We also will need to be able to move some named
variables into a dummy scope to account for complexities around function
definition and declarations.
2023-02-07 22:15:06 +01:00
Zebediah Figura
8755a92196 vkd3d-shader/hlsl: Add a hlsl_cleanup_semantic() helper. 2023-02-07 22:15:06 +01:00
Zebediah Figura
cb2c89a589 vkd3d-shader/hlsl: Store function parameters in an array. 2023-02-07 22:15:06 +01:00
Zebediah Figura
898fc9e198 vkd3d: Fix checking for failure from SleepConditionVariableCS().
Fixes: 552926cfca
2023-02-07 22:15:06 +01:00
Matteo Bruni
2e074ebce7 vkd3d: Initialize image aspect for NULL SRVs. 2023-02-07 22:08:00 +01:00
Giovanni Mascellani
552926cfca vkd3d: Do not allow synchronization primitives to fail.
In practice they never fail. If they fail, it means that there
is some underlying platform problem and there is little we can do
anyway. Under pthreads function prototypes allow returning failure,
but that's only used for "error checking" mutexes, which we
don't use.

On the other hand, error handling in vkd3d is rather inconsistent:
sometimes the errors are ignored, sometimes logged, sometimes
passed to the caller. It's hard to handle failures appropriately
if you can't even keep your state consistent, so I think it's
better to avoid trying, assume that synchronization primitives do
not fail and at least have consistent logging if something goes
wrong.
2023-02-02 20:51:27 +01:00
Zebediah Figura
a66fe31fe5 vkd3d: Do not write the point size for SPIR-V shaders.
We disable shaderTessellationAndGeometryPointSize.
2023-02-02 20:51:19 +01:00
Zebediah Figura
8fc8d34ea0 vkd3d-shader/spirv: Introduce an option to control whether point size is written. 2023-02-02 20:51:18 +01:00
Nikolay Sivov
06f300ec59 vkd3d-shader/hlsl: Support dot() for SM1. 2023-02-02 20:51:12 +01:00
Zebediah Figura
aa3badbd9d vkd3d-shader/hlsl: Emit a hlsl_fixme() for HLSL_IR_CALL instructions.
Avoid outputting invalid shaders.
2023-01-31 22:27:00 +01:00
Philip Rebohle
f9e7cb6345 include: Fix incorrect UpdateTileMappings declaration.
Signed-off-by: Philip Rebohle <philip.rebohle@tu-dortmund.de>
2023-01-26 21:52:39 +01:00
Nikolay Sivov
8bb023e5af vkd3d-shader/hlsl: Support exp() intrinsic. 2023-01-26 21:52:28 +01:00
Nikolay Sivov
8ca2f65bc1 vkd3d-shader/hlsl: Support exp2() intrinsic. 2023-01-26 21:52:26 +01:00
Nikolay Sivov
fa971f32bc vkd3d-shader/hlsl: Write 'exp' instructions for SM1. 2023-01-26 21:52:25 +01:00
Nikolay Sivov
335f741630 vkd3d-shader/hlsl: Add a helper to write per-component unary instructions. 2023-01-26 21:52:24 +01:00