209 Commits

Author SHA1 Message Date
Henri Verbeet
57d92a15cf Release 1.7. 2023-03-24 11:22:28 +01:00
Henri Verbeet
54b0165e32 vkd3d-shader: VKD3D_SHADER_COMPILE_OPTION_WRITE_TESS_GEOM_POINT_SIZE was introduced in vkd3d 1.7. 2023-03-20 21:28:13 +01:00
Nikolay Sivov
4110f1e547 vkd3d-shader: Fix a few typos in the comments. 2023-03-15 20:13:27 +01:00
Henri Verbeet
8509ec1e72 vkd3d-shader/spirv: Update the current source location in spirv_compiler_generate_spirv(). 2023-03-13 22:10:00 +01:00
Henri Verbeet
0a73c75db8 vkd3d-shader/glsl: Update the current source location in vkd3d_glsl_generator_generate().
Since the introduction of instruction arrays, the parser location no
longer matches the location of the current instruction. Ultimately we'll
likely want to add some kind of explicit location information to struct
vkd3d_shader_instruction_array, because we might do transformations that
change the order of the original instructions.
2023-03-13 22:09:58 +01:00
Henri Verbeet
685abf9c2d vkd3d-shader/sm4: Do not specify a destination register for VKD3D_SM4_OP_DCL_RESOURCE in opcode_table[].
We do not set one in shader_sm4_read_dcl_resource(), and
shader_sm4_read_instruction() explicitly sets this to 0.
2023-03-13 22:09:54 +01:00
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
9ea84ae8c9 tests/shader_runner: Use the global test_options structure.
Inspired by a patch by Giovanni Mascellani.
2023-03-10 21:13:05 +01:00
Giovanni Mascellani
c8a05a8b10 tests: Collect D3D12 test options in a dedicated structure. 2023-03-10 21:12:46 +01:00
Giovanni Mascellani
8d7159b4be tests: Initialize shader_runner fields after having zeroed the struct. 2023-03-10 21:12:44 +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
Henri Verbeet
d405295bc7 build: Fix the order of some .shader_test files. 2023-03-09 22:10:53 +01:00
Henri Verbeet
0c833056f6 build: Actually run asuint.shader_test. 2023-03-09 22:10:53 +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
Zebediah Figura
98624f2e8f include: Document that vkd3d_shader_signature may contain pointers into the input shader blob. 2023-03-08 20:14:49 +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
Giovanni Mascellani
6ccde9e82c vkd3d-shader: Make documentation for "messages" parameters self contained.
Otherwise it's not clear which clauses in vkd3d_shader_compile() really
apply to other functions. For example, many of the functions currently
refering to vkd3d_shader_compile() don't even take a vkd3d_shader_compile_info
parameter.
2023-02-28 22:07:12 +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
Zebediah Figura
2a412670ee tests: Add more tests for pack_matrix pragmas. 2023-02-28 22:06:54 +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
Giovanni Mascellani
5f904e5022 vkd3d-utils: Generate Doxygen documentation for vkd3d_utils.h. 2023-02-22 21:38:46 +01:00
Giovanni Mascellani
e5bbd05c98 vkd3d: Generate Doxygen documentation for vkd3d.h. 2023-02-22 21:38:46 +01:00
Giovanni Mascellani
6bdb0abf68 vkd3d-shader: Fix the Doxygen documentation for vkd3d_shader.h.
The \since field was too early, and prevented Doxygen from really
parsing the synopsis for vkd3d_shader.h.
2023-02-22 21:38:43 +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
7a7116eaab tests: Test allocation of unused objects. 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
Zebediah Figura
02e3be811b configure: Declare LFLAGS and YFLAGS as precious.
Normally AC_PROG_LEX and AC_PROG_YACC do this, but we demand flex and bison specifically.
2023-02-20 22:00:00 +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
9df54851c9 tests: Test array parameters on functions. 2023-02-20 21:59:51 +01:00
Francisco Casas
1b951c87f6 tests: Add more tests for broadcasts in function call args. 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
Zebediah Figura
1ee7a4e82a tests: Add more tests for majority modifier syntax. 2023-02-20 21:59:42 +01:00
Zebediah Figura
1c29b45c1f tests: Test macro expansion in pack_matrix pragmas. 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
Zebediah Figura
09c5ed27fe tests: Avoid performing a multi-component UAV load in uav-out-param.shader_test.
It requires caps beyond shader model 5.0.
2023-02-13 22:16:46 +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
721c7aa22c tests: Add more tests for function definitions. 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
68c232cfab tests: Test entry point semantics on function declarations. 2023-01-31 22:27:02 +01:00
Zebediah Figura
4954c36347 tests: Add more tests for early return from the entry point. 2023-01-31 22:27:02 +01:00
Zebediah Figura
7460d7adc2 tests: Add some tests for early return from user-defined functions. 2023-01-31 22:27:02 +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
ec00782eae vkd3d-shader/tests: Add some exp()/exp2() tests.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-01-26 21:52:29 +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
Francisco Casas
f33ca836d7 vkd3d-shader/hlsl: Make single-component swizzles retrieve a scalar. 2023-01-26 21:52:18 +01:00
Francisco Casas
edf86b2248 tests: Add tests for assignments to self with swizzles. 2023-01-26 21:52:18 +01:00
Francisco Casas
9d7ef64dc0 tests: Test swizzles on scalar values. 2023-01-26 21:52:18 +01:00
Francisco Casas
524029a062 tests: Test using single-component swizzles as indexes.
Vectors cannot be used as array indexes, however, single-component
swizzles (such as vec.x) can be used.

This suggests that single-component swizzles should actually be
scalars and not vectors of dimx = 1.

It is worth noting that the use of single-component swizzles on scalars
should still be allowed.
2023-01-26 21:52:16 +01:00
Francisco Casas
dd2168754d tests: Combine all the swizzle tests in a single file. 2023-01-26 21:52:16 +01:00
Giovanni Mascellani
d2f8a576a8 vkd3d-shader/hlsl: Avoid infinite loop and invalid derefs in copy-prop.
Co-authored-by: Francisco Casas <fcasas@codeweavers.com>
Co-authored-by: Zebediah Figura <zfigura@codeweavers.com>

Because copy_propagation_transform_object_load() replaces a deref
instead of an instruction, it is currently prone to two problems:

1- It can replace a deref with the same deref, returning true every
time and getting the compilation stuck in an endless loop of
copy-propagation iterations.

2- When performed multiple times in the same deref, the second time it
can replace the deref with a deref from a temp that is only valid in
another point of the program execution, resulting in an incorrect value.

This patch preempts this by avoiding replacing derefs when the new deref
doesn't point to a uniform variable. Because, uniform variables cannot
be written to.
2023-01-26 21:52:07 +01:00
Francisco Casas
17888f6493 tests: Test correct copy-prop object replacement. 2023-01-26 21:52:05 +01:00
Zebediah Figura
653cc02f4c vkd3d-shader/hlsl: Write SM4 thread ID registers. 2023-01-25 22:47:46 +01:00
Zebediah Figura
809a43f06b tests: Add a test for compute thread IDs. 2023-01-25 22:10:30 +01:00
Francisco Casas
404a2d6a3d vkd3d-shader/hlsl: Reinterpret minimum precision types as their regular counterparts.
Reinterpret min16float, min10float, min16int, min12int, and min16uint
as their regular counterparts: float, float, int, int, uint,
respectively.

A proper implementation would require adding minimum precision
indicators to all the dxbc-tpf instructions that use these types.
Consider the output of fxc 10.1 with the following shader:

    uniform int i;

    float4 main() : sv_target
    {
        min16float4 a = {0, 1, 2, i};
        min16int2 b = {4, i};
        min10float3 c = {6.4, 7, i};
        min12int d = 9.4;
        min16uint4x2 e = {14.4, 15, 16, 17, 18, 19, 20, i};

        return mul(e, b) + a + c.xyzx + d;
    }

However, if the graphics driver doesn't have minimum precision support,
it ignores the minimum precision indicators and runs at 32-bit
precision, which is equivalent as working with regular types.
2023-01-25 22:10:23 +01:00
Francisco Casas
4ce6a17053 tests: Test minimum-precision numeric types. 2023-01-25 22:10:23 +01:00
Nikolay Sivov
3c23e1713c vkd3d-shader/hlsl: Implement sqrt() for SM1. 2023-01-25 22:10:15 +01:00
Nikolay Sivov
b84b9349bf vkd3d-shader/hlsl: Handle RSQ output for SM1. 2023-01-25 22:10:13 +01:00
Nikolay Sivov
3e6fccdbf9 vkd3d-shader/hlsl: Support frac() intrinsic.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=34242
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2023-01-25 22:10:05 +01:00
Conor McCarthy
3db509383b vkd3d: Store a heap array index in each CBV/SRV/UAV descriptor.
A pointer to the containing descriptor heap can be derived from this
information.

PE build of vkd3d uses Windows critical sections for synchronisation,
and these slow down on the very high lock/unlock rate during multithreaded
descriptor copying in Shadow of the Tomb Raider. This patch speeds up the
demo by about 8%. By comparison, using SRW locks in the allocators and
locking them for read only where applicable is about 4% faster.
2023-01-25 22:10:01 +01:00
Conor McCarthy
d14f42be9d vkd3d-shader/spirv: Pass a parser pointer to spirv_compiler_generate_spirv(). 2023-01-24 18:11:16 +01:00
Conor McCarthy
2a5ae0a8c6 vkd3d-shader/sm4: Use the instruction array interface in compile_dxbc_tpf(). 2023-01-24 18:11:14 +01:00
Conor McCarthy
2d3f05184f vkd3d-shader/glsl: Use the instruction array interface in vkd3d_glsl_generator_generate(). 2023-01-24 18:11:13 +01:00
Conor McCarthy
2559d622de vkd3d-shader: Use the instruction array interface in scan_with_parser(). 2023-01-24 18:11:12 +01:00
Conor McCarthy
e9a2642d6a vkd3d-shader/trace: Use the instruction array interface in vkd3d_dxbc_binary_to_text(). 2023-01-24 18:11:10 +01:00
Conor McCarthy
e8cb90608d vkd3d-shader: Initialise the instruction array in vkd3d_shader_parser_init(). 2023-01-24 18:11:10 +01:00
Conor McCarthy
a9aaa59df0 vkd3d-shader/sm4: Store parsed instructions in an array. 2023-01-24 18:11:08 +01:00
Conor McCarthy
007f894b94 vkd3d-shader/sm1: Store parsed instructions in an array. 2023-01-24 18:11:06 +01:00
Francisco Casas
6b82ba9488 vkd3d-shader/hlsl: Fold swizzle chains. 2023-01-24 18:10:53 +01:00
Zebediah Figura
b7d34e8307 vkd3d-shader/hlsl: Apply copy propagation to swizzled loads. 2023-01-24 18:10:50 +01:00
Francisco Casas
18adf0d726 vkd3d-shader/hlsl: Use aoffimmis when writing gather resource loads.
If the offset of a gather resource load can be represented as an
aoffimmi (vectori of ints from -8 to 7), use one.
This is of particular importance for 4.0 profiles, where this is the only
valid way of representing offsets for this operation.
2023-01-24 18:10:49 +01:00
Francisco Casas
c2a7a40d3a vkd3d-shader/hlsl: Replace loads with constants in copy prop.
If a hlsl_ir_load loads a variable whose components are stored from different
instructions, copy propagation doesn't replace it.

But if all these instructions are constants (which currently is the case
for value constructors), the load could be replaced with a constant value.
Which is expected in some other instructions, e.g. texel_offsets when
using aoffimmi modifiers.

For instance, this shader:

```
sampler s;
Texture2D t;

float4 main() : sv_target
{
    return t.Gather(s, float2(0.6, 0.6), int2(0, 0));
}
```

results in the following IR before applying the patch:
```
  float | 6.00000024e-01
  float | 6.00000024e-01
   uint | 0
        | = (<constructor-2>[@4].x @2)
   uint | 1
        | = (<constructor-2>[@6].x @3)
 float2 | <constructor-2>
    int | 0
    int | 0
   uint | 0
        | = (<constructor-5>[@11].x @9)
   uint | 1
        | = (<constructor-5>[@13].x @10)
   int2 | <constructor-5>
 float4 | gather_red(resource = t, sampler = s, coords = @8, offset = @15)
        | return
        | = (<output-sv_target0> @16)
```

and this IR afterwards:
```
 float2 | {6.00000024e-01 6.00000024e-01 }
   int2 | {0 0 }
 float4 | gather_red(resource = t, sampler = s, coords = @2, offset = @3)
        | return
        | = (<output-sv_target0> @4)
```
2023-01-24 18:10:45 +01:00
Zebediah Figura
8c2b8ff245 vkd3d-shader/hlsl: Synthesize the swizzle and replace the instruction inside of copy_propagation_compute_replacement().
Rename it to copy_propagation_replace_with_single_instr() accordingly.

The idea is to introduce a constant vector replacement pass which will do the
same thing.
2023-01-24 18:10:41 +01:00
Zebediah Figura
5d34790402 vkd3d-shader/hlsl: Call copy_propagation_get_value() directly in copy_propagation_transform_object_load().
copy_propagation_compute_replacement() is not doing very much for us, and
conceptually is a bit of an odd fit anyway, since it's meant to deal with
multi-component types.
2023-01-24 18:10:40 +01:00
Zebediah Figura
8fd30aa87d vkd3d-shader/hlsl: Add some swizzle manipulation definitions. 2023-01-24 18:10:39 +01:00
Francisco Casas
337b4c5db0 tests: Test constant propagation through swizzles.
The Load() method offsets are used for these tests since these must
solve to constants in order to pass.
2023-01-24 18:10:38 +01:00
Francisco Casas
cf17882189 vkd3d-shader/hlsl: Support offset argument for the texture Load() method. 2023-01-24 18:10:36 +01:00
Francisco Casas
7a7b17d0e1 tests: Test offset argument for the texture Load() method. 2023-01-24 18:10:36 +01:00
Giovanni Mascellani
1717dc0516 tests: Print DLL versions when running tests on Windows. 2023-01-24 18:10:22 +01:00
Giovanni Mascellani
2445743002 tests: Run d3d9 and d3d12 tests on non-cross builds too.
On cross builds, shaders are compiled with d3dcompiler_47.dll and
run with d3dN.dll. On non-cross builds, shaders are compiled with
vkd3d-shader and run with d3dN.dll (on Windows) or Vulkan and vkd3d
(on Linux).
2023-01-24 18:10:17 +01:00
Giovanni Mascellani
44d9e2d728 tests: Distinguish between cross and non-cross Win32 builds.
Now the tests compile correctly on non-cross Win32 builds.
2023-01-24 18:10:15 +01:00
Zebediah Figura
9c817e5e6d vkd3d-shader/hlsl: Forbid recursive calls. 2023-01-19 19:16:27 +01:00
Zebediah Figura
503be4243c tests/shader_runner: Explicitly track the expected shader compilation HRESULT instead of using a boolean flag. 2023-01-19 19:16:26 +01:00
Zebediah Figura
521f22e57a vkd3d-shader/hlsl: Store a non-constant hlsl_ir_function_decl pointer in struct hlsl_ir_call. 2023-01-19 19:16:25 +01:00
Zebediah Figura
447463e590 vkd3d-shader/hlsl: Remove the unused "intrinsic" argument from hlsl_add_function(). 2023-01-19 19:16:24 +01:00
Zebediah Figura
6c2472ce16 vkd3d-shader/hlsl: Remove some unnecessary YYABORTs from the func_prototype_no_attrs rule. 2023-01-19 19:16:22 +01:00
Francisco Casas
13c8e8b856 vkd3d-shader/hlsl: Parse step() intrinsic. 2023-01-19 19:16:17 +01:00
Francisco Casas
4e1a4a76d9 tests: Test step() intrinsic. 2023-01-19 19:16:17 +01:00
Francisco Casas
6fbf2b3e75 vkd3d-shader/hlsl: Parse sqrt() intrinsic. 2023-01-19 19:16:16 +01:00
Francisco Casas
7dbc879e2d tests: Test sqrt() intrinsic. 2023-01-19 19:16:16 +01:00
Francisco Casas
8d5f16d803 vkd3d-shader/hlsl: Support cos() intrinsic. 2023-01-19 19:16:15 +01:00
Francisco Casas
3239ea5ff1 vkd3d-shader/hlsl: Support sin() intrinsic. 2023-01-19 19:16:14 +01:00
Francisco Casas
b65c450101 vkd3d-shader/hlsl: Add additional tests for sin() and cos(). 2023-01-19 19:16:13 +01:00
Francisco Casas
2b1ec0cfe5 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_scope. 2023-01-19 19:16:08 +01:00
Francisco Casas
eabd742f3e vkd3d-shader/hlsl: Add field-level documentation to function structs. 2023-01-19 19:16:07 +01:00
Francisco Casas
c68d0ecfe0 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_buffer. 2023-01-19 19:16:06 +01:00
Francisco Casas
ba56833bb5 vkd3d-shader/hlsl: Add documentation to small hlsl.h structs. 2023-01-19 19:16:04 +01:00
Francisco Casas
06b52c0343 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_deref. 2023-01-19 19:15:59 +01:00
Francisco Casas
f33d433621 vkd3d-shader/hlsl: Add documentation to struct hlsl_reg. 2023-01-19 19:15:57 +01:00
Francisco Casas
aab9886021 vkd3d-shader/hlsl: Allow uninitialized static objects.
validate_static_object_references() validates that uninitialized static
objects are not referenced in the shader.

In case a static variable contains both numeric and object types, the
"Static variables cannot have both numeric and resource components."
error should preempt uninitialized numeric values to reach further
compilation steps.
2023-01-19 12:29:41 +01:00
Francisco Casas
17d6a4411e vkd3d-shader/hlsl: Validate that non-uniform objects are not referenced.
Note that in the future we should call
validate_static_object_references() after DCE and pruning branches,
because shaders such as these compile (at least in more modern versions
of the native compiler):

Branch pruning:
```
static RWTexture2D<float> tex;

float4 main() : sv_target
{
    if (0)
    {
        tex[int2(0, 0)] = 2;
    }
    return 0;
}
```

DCE:
```
static Texture2D tex;
uniform uint i;

float4 main() : sv_target
{
    float4 unused = tex.Load(int3(0, 1, 2));

    return 0;
}
```

These are "todo" tests in hlsl-static-initializer.shader_test
that depend on this.
2023-01-19 12:29:39 +01:00
Francisco Casas
97c9669544 tests: Add additional object references tests. 2023-01-19 12:29:39 +01:00
Giovanni Mascellani
207643b8e8 tests: Test proper initialization of static structs to zero. 2023-01-19 12:29:39 +01:00
Francisco Casas
5cfc8d378f vkd3d-shader/hlsl: Initialize static variables to 0 by default.
We are currently not initializing static values to zero by default.

Consider the following shader:
```hlsl
static float4 va;

float4 main() : sv_target
{
  return va;
}
```
we get the following output:
```
ps_5_0
dcl_output o0.xyzw
dcl_temps 2
mov r0.xyzw, r1.xyzw
mov o0.xyzw, r0.xyzw
ret
```
where r1.xyzw is not initialized.

This patch solves this by assigning the static variable the value of an
uint 0, and thus, relying on complex broadcasts.

This seems to be the behaviour of the 9.29.952.3111 version of the native
compiler, since it retrieves the following error on a shader that lacks
an initializer on a data type with object components:

```
error X3017: cannot convert from 'uint' to 'struct <unnamed>'
```
2023-01-19 12:29:36 +01:00
Zebediah Figura
61f0d6d151 vkd3d-shader/hlsl: Get rid of the "intrinsic" field of struct hlsl_ir_function.
We have a different system of generating intrinsics, which makes it easier to
deal with "polymorphic" arithmetic functions.

Defining and storing intrinsics as hlsl_ir_function_decls would also require
more space in memory (and more optimization passes to get rid of the parameter
variables), and doesn't really save us any effort in terms of source code.
2023-01-13 17:32:44 +01:00
Zebediah Figura
9cc7aaf5a1 vkd3d-shader/hlsl: Forbid returning void expressions from void functions. 2023-01-13 17:32:43 +01:00
Zebediah Figura
b29d3489de vkd3d-shader/hlsl: Generate IR for user-defined function calls. 2023-01-13 17:32:42 +01:00
Zebediah Figura
30550c0831 vkd3d-shader/hlsl: Avoid assuming that expressions have at least one argument. 2023-01-13 17:32:40 +01:00
Zebediah Figura
22a1a478ea tests: Test specifying a UAV address as an in/out parameter to a function. 2023-01-13 17:32:39 +01:00
Francisco Casas
3fbe272659 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_src. 2023-01-11 16:03:55 +01:00
Francisco Casas
04108c0e21 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_ir_node. 2023-01-11 16:03:54 +01:00
Francisco Casas
9157a5e73f vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_ctx. 2023-01-11 16:03:52 +01:00
Francisco Casas
8ff3698699 vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_ir_var. 2023-01-11 16:03:51 +01:00
Francisco Casas
0a2732428c vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_struct_field. 2023-01-11 16:03:49 +01:00
Francisco Casas
3a53da7f5b vkd3d-shader/hlsl: Add field-level documentation to struct hlsl_type. 2023-01-11 16:03:48 +01:00
Francisco Casas
cc811dc3c2 vkd3d-shader/hlsl: Rename hlsl_struct_field.modifiers to "storage_modifiers". 2023-01-11 16:03:47 +01:00
Francisco Casas
4dbbb8beb4 vkd3d-shader/hlsl: Rename hlsl_ir_var.modifiers to "storage_modifiers". 2023-01-11 16:03:45 +01:00
Francisco Casas
23bd2d9ad8 vkd3d-shader/hlsl: Rename HLSL_STORAGE_VOLATILE to HLSL_MODIFIER_VOLATILE. 2023-01-11 16:03:43 +01:00
Fabian Maurer
9519fcb562 vkd3d-shader/hlsl: Fix typo (Coverity).
I assume this is a typo, right now it doesn't make sense.

Signed-off-by: Fabian Maurer <dark.shadow4@web.de>
2023-01-11 16:03:16 +01:00
Francisco Casas
5b1030e0cb vkd3d-shader/hlsl: Use add_unary_arithmetic_expr() in intrinsic_pow().
Using add_unary_arithmetic_expr() instead of hlsl_new_unary_expr()
allows the intrinsic to work with matrices.

Otherwise we get:

E5017: Aborting due to not yet implemented feature: Copying from unsupported node type.

because an HLSL_IR_EXPR reaches split_matrix_copies().
2023-01-11 16:02:59 +01:00
Francisco Casas
6770ecbdf4 vkd3d-shader/hlsl: Introduce elementwise_intrinsic_float_convert_args(). 2023-01-11 16:02:57 +01:00
Francisco Casas
9ceed76a9c vkd3d-shader/hlsl: Convert elementwise intrinsics args to the proper common type. 2023-01-11 16:02:56 +01:00
Francisco Casas
86c35fc79d tests: Test for common type conversion for element-wise intrinsics.
Some intrinsics have different rules for the allowed data types than
expressions:

- Vectors and matrices at the same time are not allowed, regardless of
  their dimensions. Even if they have the same number of components.

- Any combination of matrices is always allowed, even those when no
  matrix fits inside another, e.g.:
  float2x3 is compatible with float3x2, resulting in float 2x2.
  The common data type is the min on each dimension.

This is the case for max, pow, ldexp, clamp and smoothstep; which suggest that
it is the case for all intrinsics where the operation is applied element-wise.

Tests for mul() are also added as a counter-example where the operation
is not element-wise.
2023-01-11 16:02:53 +01:00
Francisco Casas
a7bb5a0835 vkd3d-shader/hlsl: Support smoothstep() intrinsic. 2023-01-11 16:02:52 +01:00
Francisco Casas
09e7218539 vkd3d-shader/hlsl: Support transpose() intrinsic. 2023-01-11 16:02:50 +01:00
103 changed files with 8004 additions and 2269 deletions

View File

@@ -1,16 +1,17 @@
The Wine team is proud to announce that release 1.6 of vkd3d, the Direct3D to The Wine team is proud to announce that release 1.7 of vkd3d, the Direct3D to
Vulkan translation library, is now available. Vulkan translation library, is now available.
This release contains improvements that are listed in the release notes below. This release contains improvements that are listed in the release notes below.
The main highlights are: The main highlights are:
- Initial support for HLSL compute shaders. - Support for many more HLSL features and intrinsics.
- More support for HLSL features and intrinsics. - Much improved support for the Direct3D shader model 1/2/3 HLSL profiles.
- Public vkd3d-shader API for parsing and serialising DXBC blobs.
- Miscellaneous bug fixes. - Miscellaneous bug fixes.
The source is available from the following location: The source is available from the following location:
https://dl.winehq.org/vkd3d/source/vkd3d-1.6.tar.xz https://dl.winehq.org/vkd3d/source/vkd3d-1.7.tar.xz
The current source can also be pulled directly from the git repository: The current source can also be pulled directly from the git repository:
@@ -21,40 +22,49 @@ for the complete list.
---------------------------------------------------------------- ----------------------------------------------------------------
What's new in vkd3d 1.6 What's new in vkd3d 1.7
======================= =======================
*** libvkd3d-shader *** libvkd3d-shader
- New features for the HLSL source type: - New features for the HLSL source type:
- Initial support for compute shaders. - Support for calling user-defined functions.
- Improved support for initialisation and assignment of compound objects - Support for array parameters to user-defined functions.
like structures and arrays, including casts and implicit conversions. - Much improved support for the Direct3D shader model 1/2/3 profiles.
- Support for loads and stores of texture resource unordered-access views. - Support for the SV_DispatchThreadID, SV_GroupID, and SV_GroupThreadID
- Support for function attributes. In particular, the required "numthreads" compute shader system-value semantics.
attribute for compute shader entry points is now supported. - Support for the optional "offset" parameter of the texture object Load()
- Support for the asuint() intrinsic function. method.
- Support for the length() intrinsic function. - Support for the all() intrinsic function.
- Support for the normalize() intrinsic function. - Support for the distance() intrinsic function.
- Support for integer division and modulus. - Support for the exp() and exp2() intrinsic functions.
- Support for taking the absolute value of integers. - Support for the frac() intrinsic function.
- Support for floating-point modulus. - Support for the lit() intrinsic function.
- Support for the reflect() intrinsic function.
- Support for the sin() and cos() intrinsic functions.
- Support for the smoothstep() intrinsic function.
- Support for the sqrt() and rsqrt() intrinsic functions.
- Support for the step() intrinsic function.
- Support for the transpose() intrinsic function.
- Support for the case-insensitive variants of the "float" and "dword" data
types.
- Partial support for minimum precision data types like "min16float". These
are currently interpreted as their regular counterparts.
- Improved constant propagation support, in particular to constant
propagation through swizzles.
- HLSL static variables are now properly zero-initialised.
- The Direct3D shader model 4 and 5 disassembler outputs sample counts for
multi-sampled resource declarations.
- New interfaces: - New interfaces:
- The VKD3D_SHADER_DESCRIPTOR_INFO_FLAG_UAV_ATOMICS descriptor info flag is - vkd3d_shader_parse_dxbc() provides support for parsing DXBC blobs.
used to indicate that atomic operations are used on unordered-access view - vkd3d_shader_serialize_dxbc() provides support for serialising DXBC blobs.
descriptors. - vkd3d_shader_free_dxbc() is used to free vkd3d_shader_dxbc_desc
structures, as returned by vkd3d_shader_parse_dxbc().
- The VKD3D_SHADER_COMPILE_OPTION_WRITE_TESS_GEOM_POINT_SIZE compile option
*** libvkd3d-common can be used to specify whether SPIR-V shaders targeting Vulkan
environments should write point sizes for geometry and tessellation
- vkd3d debug output is prefixed with "vkd3d:" in order to make it easier to shaders. If left unspecified, point sizes will be written.
distinguish from output produced by applications or other libraries.
*** demos
- The demos now use libvkd3d-shader to compile HLSL shaders at run-time.

View File

@@ -8,6 +8,7 @@ Chip Davis
Conor McCarthy Conor McCarthy
David Gow David Gow
Derek Lesho Derek Lesho
Fabian Maurer
Francisco Casas Francisco Casas
Francois Gouget Francois Gouget
Giovanni Mascellani Giovanni Mascellani

View File

@@ -1,4 +1,4 @@
Copyright 2016-2022 the Vkd3d project authors (see the file AUTHORS for a Copyright 2016-2023 the Vkd3d project authors (see the file AUTHORS for a
complete list) complete list)
Vkd3d is free software; you can redistribute it and/or modify it under Vkd3d is free software; you can redistribute it and/or modify it under

View File

@@ -43,15 +43,18 @@ vkd3d_cross_tests = \
vkd3d_shader_tests = \ vkd3d_shader_tests = \
tests/abs.shader_test \ tests/abs.shader_test \
tests/all.shader_test \
tests/arithmetic-float.shader_test \ tests/arithmetic-float.shader_test \
tests/arithmetic-float-uniform.shader_test \ tests/arithmetic-float-uniform.shader_test \
tests/arithmetic-int.shader_test \ tests/arithmetic-int.shader_test \
tests/arithmetic-int-uniform.shader_test \ tests/arithmetic-int-uniform.shader_test \
tests/arithmetic-uint.shader_test \ tests/arithmetic-uint.shader_test \
tests/array-parameters.shader_test \
tests/asuint.shader_test \
tests/bitwise.shader_test \ tests/bitwise.shader_test \
tests/cast-broadcast.shader_test \ tests/cast-broadcast.shader_test \
tests/cast-componentwise-equal.shader_test \
tests/cast-componentwise-compatible.shader_test \ tests/cast-componentwise-compatible.shader_test \
tests/cast-componentwise-equal.shader_test \
tests/cast-to-float.shader_test \ tests/cast-to-float.shader_test \
tests/cast-to-half.shader_test \ tests/cast-to-half.shader_test \
tests/cast-to-int.shader_test \ tests/cast-to-int.shader_test \
@@ -59,7 +62,12 @@ vkd3d_shader_tests = \
tests/cbuffer.shader_test \ tests/cbuffer.shader_test \
tests/compute.shader_test \ tests/compute.shader_test \
tests/conditional.shader_test \ tests/conditional.shader_test \
tests/distance.shader_test \
tests/entry-point-semantics.shader_test \
tests/exp.shader_test \
tests/floor.shader_test \ tests/floor.shader_test \
tests/frac.shader_test \
tests/function-return.shader_test \
tests/hlsl-array-dimension.shader_test \ tests/hlsl-array-dimension.shader_test \
tests/hlsl-attributes.shader_test \ tests/hlsl-attributes.shader_test \
tests/hlsl-bool-cast.shader_test \ tests/hlsl-bool-cast.shader_test \
@@ -75,13 +83,13 @@ vkd3d_shader_tests = \
tests/hlsl-gather-offset.shader_test \ tests/hlsl-gather-offset.shader_test \
tests/hlsl-gather.shader_test \ tests/hlsl-gather.shader_test \
tests/hlsl-initializer-flatten.shader_test \ tests/hlsl-initializer-flatten.shader_test \
tests/hlsl-initializer-invalid-arg-count.shader_test \
tests/hlsl-initializer-implicit-array.shader_test \ tests/hlsl-initializer-implicit-array.shader_test \
tests/hlsl-initializer-invalid-arg-count.shader_test \
tests/hlsl-initializer-local-array.shader_test \ tests/hlsl-initializer-local-array.shader_test \
tests/hlsl-initializer-objects.shader_test \ tests/hlsl-initializer-matrix.shader_test \
tests/hlsl-initializer-nested.shader_test \ tests/hlsl-initializer-nested.shader_test \
tests/hlsl-initializer-numeric.shader_test \ tests/hlsl-initializer-numeric.shader_test \
tests/hlsl-initializer-matrix.shader_test \ tests/hlsl-initializer-objects.shader_test \
tests/hlsl-initializer-static-array.shader_test \ tests/hlsl-initializer-static-array.shader_test \
tests/hlsl-initializer-struct.shader_test \ tests/hlsl-initializer-struct.shader_test \
tests/hlsl-intrinsic-override.shader_test \ tests/hlsl-intrinsic-override.shader_test \
@@ -99,21 +107,26 @@ vkd3d_shader_tests = \
tests/hlsl-numeric-types.shader_test \ tests/hlsl-numeric-types.shader_test \
tests/hlsl-numthreads.shader_test \ tests/hlsl-numthreads.shader_test \
tests/hlsl-return-implicit-conversion.shader_test \ tests/hlsl-return-implicit-conversion.shader_test \
tests/hlsl-return-void.shader_test \
tests/hlsl-shape.shader_test \ tests/hlsl-shape.shader_test \
tests/hlsl-single-numeric-initializer.shader_test \ tests/hlsl-single-numeric-initializer.shader_test \
tests/hlsl-smoothstep.shader_test \
tests/hlsl-state-block-syntax.shader_test \ tests/hlsl-state-block-syntax.shader_test \
tests/hlsl-static-initializer.shader_test \ tests/hlsl-static-initializer.shader_test \
tests/hlsl-storage-qualifiers.shader_test \ tests/hlsl-storage-qualifiers.shader_test \
tests/hlsl-struct-array.shader_test \ tests/hlsl-struct-array.shader_test \
tests/hlsl-struct-assignment.shader_test \ tests/hlsl-struct-assignment.shader_test \
tests/hlsl-struct-semantics.shader_test \ tests/hlsl-struct-semantics.shader_test \
tests/hlsl-transpose.shader_test \
tests/hlsl-type-names.shader_test \
tests/hlsl-vector-indexing.shader_test \ tests/hlsl-vector-indexing.shader_test \
tests/hlsl-vector-indexing-uniform.shader_test \ tests/hlsl-vector-indexing-uniform.shader_test \
tests/lit.shader_test \
tests/logic-operations.shader_test \ tests/logic-operations.shader_test \
tests/majority-syntax.shader_test \
tests/math.shader_test \ tests/math.shader_test \
tests/matrix-semantics.shader_test \ tests/matrix-semantics.shader_test \
tests/max.shader_test \ tests/max.shader_test \
tests/minimum-precision.shader_test \
tests/multiple-rt.shader_test \ tests/multiple-rt.shader_test \
tests/nointerpolation.shader_test \ tests/nointerpolation.shader_test \
tests/object-references.shader_test \ tests/object-references.shader_test \
@@ -124,24 +137,25 @@ vkd3d_shader_tests = \
tests/preproc-invalid.shader_test \ tests/preproc-invalid.shader_test \
tests/preproc-macro.shader_test \ tests/preproc-macro.shader_test \
tests/preproc-misc.shader_test \ tests/preproc-misc.shader_test \
tests/reflect.shader_test \
tests/register-reservations.shader_test \
tests/return.shader_test \
tests/round.shader_test \ tests/round.shader_test \
tests/sampler.shader_test \ tests/sampler.shader_test \
tests/sampler-offset.shader_test \ tests/sampler-offset.shader_test \
tests/saturate.shader_test \ tests/saturate.shader_test \
tests/shader-interstage-interface.shader_test \ tests/shader-interstage-interface.shader_test \
tests/swizzle-0.shader_test \ tests/sqrt.shader_test \
tests/swizzle-1.shader_test \ tests/step.shader_test \
tests/swizzle-2.shader_test \ tests/swizzle-constant-prop.shader_test \
tests/swizzle-3.shader_test \ tests/swizzles.shader_test \
tests/swizzle-4.shader_test \
tests/swizzle-5.shader_test \
tests/swizzle-6.shader_test \
tests/swizzle-7.shader_test \
tests/texture-load.shader_test \ tests/texture-load.shader_test \
tests/texture-load-offset.shader_test \
tests/texture-load-typed.shader_test \ tests/texture-load-typed.shader_test \
tests/trigonometry.shader_test \ tests/trigonometry.shader_test \
tests/uav.shader_test \ tests/uav.shader_test \
tests/uav-load.shader_test \ tests/uav-load.shader_test \
tests/uav-out-param.shader_test \
tests/writemask-assignop-0.shader_test \ tests/writemask-assignop-0.shader_test \
tests/writemask-assignop-1.shader_test \ tests/writemask-assignop-1.shader_test \
tests/writemask-assignop-2.shader_test \ tests/writemask-assignop-2.shader_test \
@@ -245,7 +259,7 @@ libvkd3d_shader_la_SOURCES = \
libs/vkd3d-shader/vkd3d_shader_main.c \ libs/vkd3d-shader/vkd3d_shader_main.c \
libs/vkd3d-shader/vkd3d_shader_private.h libs/vkd3d-shader/vkd3d_shader_private.h
libvkd3d_shader_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_SHADER_SOURCE -I$(srcdir)/libs/vkd3d-shader @SPIRV_TOOLS_CFLAGS@ libvkd3d_shader_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_SHADER_SOURCE -I$(srcdir)/libs/vkd3d-shader @SPIRV_TOOLS_CFLAGS@
libvkd3d_shader_la_LDFLAGS = $(AM_LDFLAGS) -version-info 5:0:4 libvkd3d_shader_la_LDFLAGS = $(AM_LDFLAGS) -version-info 6:0:5
libvkd3d_shader_la_LIBADD = libvkd3d-common.la @SPIRV_TOOLS_LIBS@ -lm libvkd3d_shader_la_LIBADD = libvkd3d-common.la @SPIRV_TOOLS_LIBS@ -lm
if HAVE_LD_VERSION_SCRIPT if HAVE_LD_VERSION_SCRIPT
libvkd3d_shader_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-shader/vkd3d_shader.map libvkd3d_shader_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-shader/vkd3d_shader.map
@@ -279,7 +293,7 @@ libvkd3d_la_SOURCES = \
libs/vkd3d/vkd3d_shaders.h \ libs/vkd3d/vkd3d_shaders.h \
libs/vkd3d/vulkan_procs.h libs/vkd3d/vulkan_procs.h
libvkd3d_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_SOURCE libvkd3d_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_SOURCE
libvkd3d_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:0:6 libvkd3d_la_LDFLAGS = $(AM_LDFLAGS) -version-info 8:0:7
libvkd3d_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la @DL_LIBS@ @PTHREAD_LIBS@ libvkd3d_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la @DL_LIBS@ @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT if HAVE_LD_VERSION_SCRIPT
libvkd3d_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d/vkd3d.map libvkd3d_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d/vkd3d.map
@@ -291,7 +305,7 @@ libvkd3d_utils_la_SOURCES = \
libs/vkd3d-utils/vkd3d_utils_main.c \ libs/vkd3d-utils/vkd3d_utils_main.c \
libs/vkd3d-utils/vkd3d_utils_private.h libs/vkd3d-utils/vkd3d_utils_private.h
libvkd3d_utils_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_UTILS_SOURCE libvkd3d_utils_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_UTILS_SOURCE
libvkd3d_utils_la_LDFLAGS = $(AM_LDFLAGS) -version-info 4:2:3 libvkd3d_utils_la_LDFLAGS = $(AM_LDFLAGS) -version-info 4:3:3
libvkd3d_utils_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la libvkd3d.la @PTHREAD_LIBS@ libvkd3d_utils_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la libvkd3d.la @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT if HAVE_LD_VERSION_SCRIPT
libvkd3d_utils_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-utils/vkd3d_utils.map libvkd3d_utils_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-utils/vkd3d_utils.map
@@ -328,6 +342,8 @@ tests_hlsl_d3d12_LDADD = $(LDADD) @DL_LIBS@
tests_shader_runner_LDADD = $(LDADD) @DL_LIBS@ tests_shader_runner_LDADD = $(LDADD) @DL_LIBS@
tests_shader_runner_SOURCES = \ tests_shader_runner_SOURCES = \
tests/shader_runner.c \ tests/shader_runner.c \
tests/shader_runner_d3d9.c \
tests/shader_runner_d3d11.c \
tests/shader_runner_d3d12.c \ tests/shader_runner_d3d12.c \
tests/shader_runner_vulkan.c tests/shader_runner_vulkan.c
tests_vkd3d_api_LDADD = libvkd3d.la @DL_LIBS@ tests_vkd3d_api_LDADD = libvkd3d.la @DL_LIBS@
@@ -409,7 +425,7 @@ dummy-vkd3d-version:
## Cross-compile tests ## Cross-compile tests
cross_implibs = crosslibs/d3d12 cross_implibs = crosslibs/d3d12
CROSS_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/include CROSS_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/include
CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=0 CROSS_CFLAGS = -g -O2 -Wall -municode ${CROSS_CPPFLAGS} -D__USE_MINGW_ANSI_STDIO=0 -DVKD3D_CROSSTEST=1
EXTRA_DIST += $(cross_implibs:=.cross32.def) $(cross_implibs:=.cross64.def) EXTRA_DIST += $(cross_implibs:=.cross32.def) $(cross_implibs:=.cross64.def)
EXTRA_DIST += tests/shader_runner_d3d11.c tests/shader_runner_d3d9.c EXTRA_DIST += tests/shader_runner_d3d11.c tests/shader_runner_d3d9.c

View File

@@ -1,5 +1,5 @@
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([vkd3d],[1.6]) AC_INIT([vkd3d],[1.7])
AC_CONFIG_AUX_DIR([bin]) AC_CONFIG_AUX_DIR([bin])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
@@ -32,9 +32,11 @@ AS_IF([test "x$WIDL" = "xno"], [AC_MSG_WARN([widl is required to build header fi
AC_CHECK_PROGS([FLEX], [flex], [none]) AC_CHECK_PROGS([FLEX], [flex], [none])
AS_IF([test "$FLEX" = "none"], [AC_MSG_ERROR([no suitable flex found. Please install the 'flex' package.])]) AS_IF([test "$FLEX" = "none"], [AC_MSG_ERROR([no suitable flex found. Please install the 'flex' package.])])
AC_ARG_VAR([LFLAGS], [extra flags for flex])
AC_CHECK_PROGS([BISON], [bison], [none]) AC_CHECK_PROGS([BISON], [bison], [none])
AS_IF([test "$BISON" = "none"], [AC_MSG_ERROR([no suitable bison found. Please install the 'bison' package.])]) AS_IF([test "$BISON" = "none"], [AC_MSG_ERROR([no suitable bison found. Please install the 'bison' package.])])
AC_ARG_VAR([YFLAGS], [extra flags for bison])
DX_PS_FEATURE([OFF]) DX_PS_FEATURE([OFF])
DX_INIT_DOXYGEN([vkd3d], [Doxyfile], [doc]) DX_INIT_DOXYGEN([vkd3d], [Doxyfile], [doc])

View File

@@ -19,7 +19,7 @@
#define VK_NO_PROTOTYPES #define VK_NO_PROTOTYPES
#define VK_USE_PLATFORM_XCB_KHR #define VK_USE_PLATFORM_XCB_KHR
#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_6 #define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_7
#include "config.h" #include "config.h"
#include <vkd3d.h> #include <vkd3d.h>
#include <vkd3d_utils.h> #include <vkd3d_utils.h>

View File

@@ -186,6 +186,30 @@ static inline void list_move_tail( struct list *dst, struct list *src )
list_move_before( dst, src ); list_move_before( dst, src );
} }
/* move the slice of elements from begin to end inclusive to the head of dst */
static inline void list_move_slice_head( struct list *dst, struct list *begin, struct list *end )
{
struct list *dst_next = dst->next;
begin->prev->next = end->next;
end->next->prev = begin->prev;
dst->next = begin;
dst_next->prev = end;
begin->prev = dst;
end->next = dst_next;
}
/* move the slice of elements from begin to end inclusive to the tail of dst */
static inline void list_move_slice_tail( struct list *dst, struct list *begin, struct list *end )
{
struct list *dst_prev = dst->prev;
begin->prev->next = end->next;
end->next->prev = begin->prev;
dst_prev->next = begin;
dst->prev = end;
begin->prev = dst_prev;
end->next = dst;
}
/* iterate through the list */ /* iterate through the list */
#define LIST_FOR_EACH(cursor,list) \ #define LIST_FOR_EACH(cursor,list) \
for ((cursor) = (list)->next; (cursor) != (list); (cursor) = (cursor)->next) for ((cursor) = (list)->next; (cursor) != (list); (cursor) = (cursor)->next)

View File

@@ -34,6 +34,18 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/**
* \file vkd3d.h
*
* This file contains definitions for the vkd3d library.
*
* The vkd3d library is a 3D graphics library built on top of
* Vulkan. It has an API very similar, but not identical, to
* Direct3D 12.
*
* \since 1.0
*/
enum vkd3d_structure_type enum vkd3d_structure_type
{ {
/* 1.0 */ /* 1.0 */
@@ -63,6 +75,7 @@ enum vkd3d_api_version
VKD3D_API_VERSION_1_4, VKD3D_API_VERSION_1_4,
VKD3D_API_VERSION_1_5, VKD3D_API_VERSION_1_5,
VKD3D_API_VERSION_1_6, VKD3D_API_VERSION_1_6,
VKD3D_API_VERSION_1_7,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_API_VERSION), VKD3D_FORCE_32_BIT_ENUM(VKD3D_API_VERSION),
}; };

View File

@@ -2263,6 +2263,7 @@ interface ID3D12CommandQueue : ID3D12Pageable
void UpdateTileMappings(ID3D12Resource *resource, UINT region_count, void UpdateTileMappings(ID3D12Resource *resource, UINT region_count,
const D3D12_TILED_RESOURCE_COORDINATE *region_start_coordinates, const D3D12_TILED_RESOURCE_COORDINATE *region_start_coordinates,
const D3D12_TILE_REGION_SIZE *region_sizes, const D3D12_TILE_REGION_SIZE *region_sizes,
ID3D12Heap *heap,
UINT range_count, UINT range_count,
const D3D12_TILE_RANGE_FLAGS *range_flags, const D3D12_TILE_RANGE_FLAGS *range_flags,
UINT *heap_range_offsets, UINT *heap_range_offsets,

View File

@@ -30,12 +30,12 @@ extern "C" {
/** /**
* \file vkd3d_shader.h * \file vkd3d_shader.h
* *
* \since 1.2
*
* This file contains definitions for the vkd3d-shader library. * This file contains definitions for the vkd3d-shader library.
* *
* The vkd3d-shader library provides multiple utilities related to the * The vkd3d-shader library provides multiple utilities related to the
* compilation, transformation, and reflection of GPU shaders. * compilation, transformation, and reflection of GPU shaders.
*
* \since 1.2
*/ */
/** \since 1.3 */ /** \since 1.3 */
@@ -48,6 +48,7 @@ enum vkd3d_shader_api_version
VKD3D_SHADER_API_VERSION_1_4, VKD3D_SHADER_API_VERSION_1_4,
VKD3D_SHADER_API_VERSION_1_5, VKD3D_SHADER_API_VERSION_1_5,
VKD3D_SHADER_API_VERSION_1_6, VKD3D_SHADER_API_VERSION_1_6,
VKD3D_SHADER_API_VERSION_1_7,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_API_VERSION), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_API_VERSION),
}; };
@@ -150,6 +151,18 @@ enum vkd3d_shader_compile_option_name
VKD3D_SHADER_COMPILE_OPTION_API_VERSION = 0x00000004, VKD3D_SHADER_COMPILE_OPTION_API_VERSION = 0x00000004,
/** \a value is a member of enum vkd3d_shader_compile_option_typed_uav. \since 1.5 */ /** \a value is a member of enum vkd3d_shader_compile_option_typed_uav. \since 1.5 */
VKD3D_SHADER_COMPILE_OPTION_TYPED_UAV = 0x00000005, VKD3D_SHADER_COMPILE_OPTION_TYPED_UAV = 0x00000005,
/**
* If \a value is nonzero, write the point size for Vulkan tessellation and
* geometry shaders. This option should be enabled if and only if the
* shaderTessellationAndGeometryPointSize feature is enabled. The default
* value is nonzero, i.e. write the point size.
*
* This option is supported by vkd3d_shader_compile() for the SPIR-V target
* type and Vulkan targets; it should not be enabled otherwise.
*
* \since 1.7
*/
VKD3D_SHADER_COMPILE_OPTION_WRITE_TESS_GEOM_POINT_SIZE = 0x00000006,
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_NAME), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_COMPILE_OPTION_NAME),
}; };
@@ -1460,6 +1473,46 @@ enum vkd3d_shader_swizzle_component
VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SWIZZLE_COMPONENT), VKD3D_FORCE_32_BIT_ENUM(VKD3D_SHADER_SWIZZLE_COMPONENT),
}; };
/**
* A description of a DXBC section.
*
* \since 1.7
*/
struct vkd3d_shader_dxbc_section_desc
{
/** The section tag. */
uint32_t tag;
/** The contents of the section. */
struct vkd3d_shader_code data;
};
/**
* A description of a DXBC blob, as returned by vkd3d_shader_parse_dxbc().
*
* \since 1.7
*/
struct vkd3d_shader_dxbc_desc
{
/**
* The DXBC tag. This will always be "DXBC" in structures returned by
* this version of vkd3d-shader.
*/
uint32_t tag;
/** A checksum of the DXBC contents. */
uint32_t checksum[4];
/**
* The DXBC version. This will always be 1 in structures returned by this
* version of vkd3d-shader.
*/
unsigned int version;
/** The total size of the DXBC blob. */
size_t size;
/** The number of sections contained in the DXBC. */
size_t section_count;
/** Descriptions of the sections contained in the DXBC. */
struct vkd3d_shader_dxbc_section_desc *sections;
};
/** /**
* A mask selecting one component from a vkd3d-shader swizzle. The component has * A mask selecting one component from a vkd3d-shader swizzle. The component has
* type \ref vkd3d_shader_swizzle_component. * type \ref vkd3d_shader_swizzle_component.
@@ -1596,7 +1649,7 @@ VKD3D_SHADER_API const enum vkd3d_shader_target_type *vkd3d_shader_get_supported
* vkd3d_shader_compile_info. Regardless of the requested level, if this * vkd3d_shader_compile_info. Regardless of the requested level, if this
* parameter is NULL, no compilation messages will be returned. * parameter is NULL, no compilation messages will be returned.
* \n * \n
* If no compilation messages are produced by the compiler, this parameter may * If no messages are produced by the compiler, this parameter may
* receive NULL instead of a valid string pointer. * receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
@@ -1645,10 +1698,15 @@ VKD3D_SHADER_API void vkd3d_shader_free_shader_code(struct vkd3d_shader_code *co
* needed. * needed.
* *
* \param messages Optional output location for error or informational messages * \param messages Optional output location for error or informational messages
* produced by the compiler. * produced by the parser.
* \n * \n
* This parameter behaves identically to the \a messages parameter of * This string is null-terminated and UTF-8 encoded.
* vkd3d_shader_compile(). * \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* If no messages are produced by the parser, this parameter may
* receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
*/ */
@@ -1683,10 +1741,15 @@ VKD3D_SHADER_API void vkd3d_shader_free_root_signature(
* vkd3d_shader_free_shader_code() when no longer needed. * vkd3d_shader_free_shader_code() when no longer needed.
* *
* \param messages Optional output location for error or informational messages * \param messages Optional output location for error or informational messages
* produced by the compiler. * produced by the serializer.
* \n * \n
* This parameter behaves identically to the \a messages parameter of * This string is null-terminated and UTF-8 encoded.
* vkd3d_shader_compile(). * \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* If no messages are produced by the serializer, this parameter may
* receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
*/ */
@@ -1733,10 +1796,19 @@ VKD3D_SHADER_API int vkd3d_shader_convert_root_signature(struct vkd3d_shader_ver
* depending on their structure type. * depending on their structure type.
* *
* \param messages Optional output location for error or informational messages * \param messages Optional output location for error or informational messages
* produced by the compiler. * produced by the parser.
* \n * \n
* This parameter behaves identically to the \a messages parameter of * This string is null-terminated and UTF-8 encoded.
* vkd3d_shader_compile(). * \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* The messages returned can be regulated with the \a log_level member of struct
* vkd3d_shader_compile_info. Regardless of the requested level, if this
* parameter is NULL, no compilation messages will be returned.
* \n
* If no messages are produced by the parser, this parameter may
* receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
*/ */
@@ -1768,12 +1840,20 @@ VKD3D_SHADER_API void vkd3d_shader_free_scan_descriptor_info(
* Members of \a signature may be allocated by vkd3d-shader. The signature * Members of \a signature may be allocated by vkd3d-shader. The signature
* should be freed with vkd3d_shader_free_shader_signature() when no longer * should be freed with vkd3d_shader_free_shader_signature() when no longer
* needed. * needed.
* \n
* The signature may contain pointers into the input shader, and should only be
* accessed while the input shader remains valid.
* *
* \param messages Optional output location for error or informational messages * \param messages Optional output location for error or informational messages
* produced by the compiler. * produced by the parser.
* \n * \n
* This parameter behaves identically to the \a messages parameter of * This string is null-terminated and UTF-8 encoded.
* vkd3d_shader_compile(). * \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* If no messages are produced by the parser, this parameter may
* receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
*/ */
@@ -1829,10 +1909,19 @@ VKD3D_SHADER_API void vkd3d_shader_free_shader_signature(struct vkd3d_shader_sig
* vkd3d_shader_free_shader_code() when no longer needed. * vkd3d_shader_free_shader_code() when no longer needed.
* *
* \param messages Optional output location for error or informational messages * \param messages Optional output location for error or informational messages
* produced by the compiler. * produced by the preprocessor.
* \n * \n
* This parameter behaves identically to the \a messages parameter of * This string is null-terminated and UTF-8 encoded.
* vkd3d_shader_compile(). * \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* The messages returned can be regulated with the \a log_level member of struct
* vkd3d_shader_compile_info. Regardless of the requested level, if this
* parameter is NULL, no compilation messages will be returned.
* \n
* If no messages are produced by the preprocessor, this parameter may
* receive NULL instead of a valid string pointer.
* *
* \return A member of \ref vkd3d_result. * \return A member of \ref vkd3d_result.
* *
@@ -1853,6 +1942,85 @@ VKD3D_SHADER_API int vkd3d_shader_preprocess(const struct vkd3d_shader_compile_i
*/ */
VKD3D_SHADER_API void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback); VKD3D_SHADER_API void vkd3d_shader_set_log_callback(PFN_vkd3d_log callback);
/**
* Free the contents of a vkd3d_shader_dxbc_desc structure allocated by
* another vkd3d-shader function, such as vkd3d_shader_parse_dxbc().
*
* This function may free the \ref vkd3d_shader_dxbc_desc.sections member, but
* does not free the structure itself.
*
* \param dxbc The vkd3d_shader_dxbc_desc structure to free.
*
* \since 1.7
*/
VKD3D_SHADER_API void vkd3d_shader_free_dxbc(struct vkd3d_shader_dxbc_desc *dxbc);
/**
* Parse a DXBC blob contained in a vkd3d_shader_code structure.
*
* \param dxbc A vkd3d_shader_code structure containing the DXBC blob to parse.
*
* \param flags A set of flags modifying the behaviour of the function. No
* flags are defined for this version of vkd3d-shader, and this parameter
* should be set to 0.
*
* \param desc A vkd3d_shader_dxbc_desc structure describing the contents of
* the DXBC blob. Its vkd3d_shader_dxbc_section_desc structures will contain
* pointers into the input blob; its contents are only valid while the input
* blob is valid. The contents of this structure should be freed with
* vkd3d_shader_free_dxbc() when no longer needed.
*
* \param messages Optional output location for error or informational messages
* produced by the parser.
* \n
* This string is null-terminated and UTF-8 encoded.
* \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* If no messages are produced by the parser, this parameter may
* receive NULL instead of a valid string pointer.
*
* \return A member of \ref vkd3d_result.
*
* \since 1.7
*/
VKD3D_SHADER_API int vkd3d_shader_parse_dxbc(const struct vkd3d_shader_code *dxbc,
uint32_t flags, struct vkd3d_shader_dxbc_desc *desc, char **messages);
/**
* Serialize a DXBC description into a blob stored in a vkd3d_shader_code
* structure.
*
* \param section_count The number of DXBC sections to serialize.
*
* \param sections An array of vkd3d_shader_dxbc_section_desc structures
* to serialize.
*
* \param dxbc A pointer to a vkd3d_shader_code structure in which the
* serialized blob will be stored.
* \n
* The output blob is allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_shader_code() when no longer needed.
*
* \param messages Optional output location for error or informational messages
* produced by the serializer.
* \n
* This string is null-terminated and UTF-8 encoded.
* \n
* The messages are allocated by vkd3d-shader and should be freed with
* vkd3d_shader_free_messages() when no longer needed.
* \n
* If no messages are produced by the serializer, this parameter may
* receive NULL instead of a valid string pointer.
*
* \return A member of \ref vkd3d_result.
*
* \since 1.7
*/
VKD3D_SHADER_API int vkd3d_shader_serialize_dxbc(size_t section_count,
const struct vkd3d_shader_dxbc_section_desc *sections, struct vkd3d_shader_code *dxbc, char **messages);
#endif /* VKD3D_SHADER_NO_PROTOTYPES */ #endif /* VKD3D_SHADER_NO_PROTOTYPES */
/** Type of vkd3d_shader_get_version(). */ /** Type of vkd3d_shader_get_version(). */
@@ -1909,6 +2077,15 @@ typedef void (*PFN_vkd3d_shader_preprocess)(struct vkd3d_shader_compile_info *co
/** Type of vkd3d_shader_set_log_callback(). \since 1.4 */ /** Type of vkd3d_shader_set_log_callback(). \since 1.4 */
typedef void (*PFN_vkd3d_shader_set_log_callback)(PFN_vkd3d_log callback); typedef void (*PFN_vkd3d_shader_set_log_callback)(PFN_vkd3d_log callback);
/** Type of vkd3d_shader_free_dxbc(). \since 1.7 */
typedef void (*PFN_vkd3d_shader_free_dxbc)(struct vkd3d_shader_dxbc_desc *dxbc);
/** Type of vkd3d_shader_parse_dxbc(). \since 1.7 */
typedef int (*PFN_vkd3d_shader_parse_dxbc)(const struct vkd3d_shader_code *dxbc,
uint32_t flags, struct vkd3d_shader_dxbc_desc *desc, char **messages);
/** Type of vkd3d_shader_serialize_dxbc(). \since 1.7 */
typedef int (*PFN_vkd3d_shader_serialize_dxbc)(size_t section_count,
const struct vkd3d_shader_dxbc_section_desc *sections, struct vkd3d_shader_code *dxbc, char **messages);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@@ -29,6 +29,17 @@
extern "C" { extern "C" {
#endif /* __cplusplus */ #endif /* __cplusplus */
/**
* \file vkd3d_utils.h
*
* This file contains definitions for the vkd3d-utils library.
*
* The vkd3d-utils library is a collections of routines to ease the
* porting of a Direct3D 12 application to vkd3d.
*
* \since 1.0
*/
#define VKD3D_WAIT_OBJECT_0 (0) #define VKD3D_WAIT_OBJECT_0 (0)
#define VKD3D_WAIT_TIMEOUT (1) #define VKD3D_WAIT_TIMEOUT (1)
#define VKD3D_WAIT_FAILED (~0u) #define VKD3D_WAIT_FAILED (~0u)

View File

@@ -210,13 +210,6 @@ struct vkd3d_shader_sm1_parser
const uint32_t *start, *end; const uint32_t *start, *end;
bool abort; bool abort;
struct vkd3d_shader_src_param src_rel_addr[4];
struct vkd3d_shader_src_param pred_rel_addr;
struct vkd3d_shader_src_param dst_rel_addr;
struct vkd3d_shader_src_param src_param[4];
struct vkd3d_shader_src_param pred_param;
struct vkd3d_shader_dst_param dst_param;
struct vkd3d_shader_parser p; struct vkd3d_shader_parser p;
}; };
@@ -556,33 +549,50 @@ static void shader_sm1_destroy(struct vkd3d_shader_parser *parser)
{ {
struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser); struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser);
shader_instruction_array_destroy(&parser->instructions);
free_shader_desc(&sm1->p.shader_desc); free_shader_desc(&sm1->p.shader_desc);
vkd3d_free(sm1); vkd3d_free(sm1);
} }
static void shader_sm1_read_src_param(struct vkd3d_shader_sm1_parser *sm1, const uint32_t **ptr, static void shader_sm1_read_src_param(struct vkd3d_shader_sm1_parser *sm1, const uint32_t **ptr,
struct vkd3d_shader_src_param *src_param, struct vkd3d_shader_src_param *src_rel_addr) struct vkd3d_shader_src_param *src_param)
{ {
struct vkd3d_shader_src_param *src_rel_addr = NULL;
uint32_t token, addr_token; uint32_t token, addr_token;
shader_sm1_read_param(sm1, ptr, &token, &addr_token); shader_sm1_read_param(sm1, ptr, &token, &addr_token);
if (has_relative_address(token)) if (has_relative_address(token))
{
if (!(src_rel_addr = shader_parser_get_src_params(&sm1->p, 1)))
{
vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY,
"Out of memory.");
sm1->abort = true;
return;
}
shader_sm1_parse_src_param(addr_token, NULL, src_rel_addr); shader_sm1_parse_src_param(addr_token, NULL, src_rel_addr);
else }
src_rel_addr = NULL;
shader_sm1_parse_src_param(token, src_rel_addr, src_param); shader_sm1_parse_src_param(token, src_rel_addr, src_param);
} }
static void shader_sm1_read_dst_param(struct vkd3d_shader_sm1_parser *sm1, const uint32_t **ptr, static void shader_sm1_read_dst_param(struct vkd3d_shader_sm1_parser *sm1, const uint32_t **ptr,
struct vkd3d_shader_dst_param *dst_param, struct vkd3d_shader_src_param *dst_rel_addr) struct vkd3d_shader_dst_param *dst_param)
{ {
struct vkd3d_shader_src_param *dst_rel_addr = NULL;
uint32_t token, addr_token; uint32_t token, addr_token;
shader_sm1_read_param(sm1, ptr, &token, &addr_token); shader_sm1_read_param(sm1, ptr, &token, &addr_token);
if (has_relative_address(token)) if (has_relative_address(token))
{
if (!(dst_rel_addr = shader_parser_get_src_params(&sm1->p, 1)))
{
vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY,
"Out of memory.");
sm1->abort = true;
return;
}
shader_sm1_parse_src_param(addr_token, NULL, dst_rel_addr); shader_sm1_parse_src_param(addr_token, NULL, dst_rel_addr);
else }
dst_rel_addr = NULL;
shader_sm1_parse_dst_param(token, dst_rel_addr, dst_param); shader_sm1_parse_dst_param(token, dst_rel_addr, dst_param);
} }
@@ -731,10 +741,13 @@ static void shader_sm1_validate_instruction(struct vkd3d_shader_sm1_parser *sm1,
static void shader_sm1_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins) static void shader_sm1_read_instruction(struct vkd3d_shader_parser *parser, struct vkd3d_shader_instruction *ins)
{ {
struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser); struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser);
struct vkd3d_shader_src_param *src_params, *predicate;
const struct vkd3d_sm1_opcode_info *opcode_info; const struct vkd3d_sm1_opcode_info *opcode_info;
struct vkd3d_shader_dst_param *dst_param;
const uint32_t **ptr = &parser->ptr; const uint32_t **ptr = &parser->ptr;
uint32_t opcode_token; uint32_t opcode_token;
const uint32_t *p; const uint32_t *p;
bool predicated;
unsigned int i; unsigned int i;
shader_sm1_read_comment(sm1); shader_sm1_read_comment(sm1);
@@ -761,11 +774,18 @@ static void shader_sm1_read_instruction(struct vkd3d_shader_parser *parser, stru
ins->coissue = opcode_token & VKD3D_SM1_COISSUE; ins->coissue = opcode_token & VKD3D_SM1_COISSUE;
ins->raw = false; ins->raw = false;
ins->structured = false; ins->structured = false;
ins->predicate = opcode_token & VKD3D_SM1_INSTRUCTION_PREDICATED ? &sm1->pred_param : NULL; predicated = !!(opcode_token & VKD3D_SM1_INSTRUCTION_PREDICATED);
ins->predicate = predicate = predicated ? shader_parser_get_src_params(parser, 1) : NULL;
ins->dst_count = opcode_info->dst_count; ins->dst_count = opcode_info->dst_count;
ins->dst = &sm1->dst_param; ins->dst = dst_param = shader_parser_get_dst_params(parser, ins->dst_count);
ins->src_count = opcode_info->src_count; ins->src_count = opcode_info->src_count;
ins->src = sm1->src_param; ins->src = src_params = shader_parser_get_src_params(parser, ins->src_count);
if ((!predicate && predicated) || (!src_params && ins->src_count) || (!dst_param && ins->dst_count))
{
vkd3d_shader_parser_error(parser, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY, "Out of memory.");
goto fail;
}
ins->resource_type = VKD3D_SHADER_RESOURCE_NONE; ins->resource_type = VKD3D_SHADER_RESOURCE_NONE;
ins->resource_stride = 0; ins->resource_stride = 0;
ins->resource_data_type[0] = VKD3D_DATA_FLOAT; ins->resource_data_type[0] = VKD3D_DATA_FLOAT;
@@ -790,32 +810,32 @@ static void shader_sm1_read_instruction(struct vkd3d_shader_parser *parser, stru
} }
else if (ins->handler_idx == VKD3DSIH_DEF) else if (ins->handler_idx == VKD3DSIH_DEF)
{ {
shader_sm1_read_dst_param(sm1, &p, &sm1->dst_param, &sm1->dst_rel_addr); shader_sm1_read_dst_param(sm1, &p, dst_param);
shader_sm1_read_immconst(sm1, &p, &sm1->src_param[0], VKD3D_IMMCONST_VEC4, VKD3D_DATA_FLOAT); shader_sm1_read_immconst(sm1, &p, &src_params[0], VKD3D_IMMCONST_VEC4, VKD3D_DATA_FLOAT);
} }
else if (ins->handler_idx == VKD3DSIH_DEFB) else if (ins->handler_idx == VKD3DSIH_DEFB)
{ {
shader_sm1_read_dst_param(sm1, &p, &sm1->dst_param, &sm1->dst_rel_addr); shader_sm1_read_dst_param(sm1, &p, dst_param);
shader_sm1_read_immconst(sm1, &p, &sm1->src_param[0], VKD3D_IMMCONST_SCALAR, VKD3D_DATA_UINT); shader_sm1_read_immconst(sm1, &p, &src_params[0], VKD3D_IMMCONST_SCALAR, VKD3D_DATA_UINT);
} }
else if (ins->handler_idx == VKD3DSIH_DEFI) else if (ins->handler_idx == VKD3DSIH_DEFI)
{ {
shader_sm1_read_dst_param(sm1, &p, &sm1->dst_param, &sm1->dst_rel_addr); shader_sm1_read_dst_param(sm1, &p, dst_param);
shader_sm1_read_immconst(sm1, &p, &sm1->src_param[0], VKD3D_IMMCONST_VEC4, VKD3D_DATA_INT); shader_sm1_read_immconst(sm1, &p, &src_params[0], VKD3D_IMMCONST_VEC4, VKD3D_DATA_INT);
} }
else else
{ {
/* Destination token */ /* Destination token */
if (ins->dst_count) if (ins->dst_count)
shader_sm1_read_dst_param(sm1, &p, &sm1->dst_param, &sm1->dst_rel_addr); shader_sm1_read_dst_param(sm1, &p, dst_param);
/* Predication token */ /* Predication token */
if (ins->predicate) if (ins->predicate)
shader_sm1_read_src_param(sm1, &p, &sm1->pred_param, &sm1->pred_rel_addr); shader_sm1_read_src_param(sm1, &p, predicate);
/* Other source tokens */ /* Other source tokens */
for (i = 0; i < ins->src_count; ++i) for (i = 0; i < ins->src_count; ++i)
shader_sm1_read_src_param(sm1, &p, &sm1->src_param[i], &sm1->src_rel_addr[i]); shader_sm1_read_src_param(sm1, &p, &src_params[i]);
} }
if (sm1->abort) if (sm1->abort)
@@ -851,20 +871,9 @@ static bool shader_sm1_is_end(struct vkd3d_shader_parser *parser)
return false; return false;
} }
static void shader_sm1_reset(struct vkd3d_shader_parser *parser)
{
struct vkd3d_shader_sm1_parser *sm1 = vkd3d_shader_sm1_parser(parser);
parser->ptr = sm1->start;
parser->failed = false;
}
const struct vkd3d_shader_parser_ops shader_sm1_parser_ops = const struct vkd3d_shader_parser_ops shader_sm1_parser_ops =
{ {
.parser_reset = shader_sm1_reset,
.parser_destroy = shader_sm1_destroy, .parser_destroy = shader_sm1_destroy,
.parser_read_instruction = shader_sm1_read_instruction,
.parser_is_end = shader_sm1_is_end,
}; };
static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1, static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1,
@@ -922,7 +931,10 @@ static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1,
sm1->start = &code[1]; sm1->start = &code[1];
sm1->end = &code[token_count]; sm1->end = &code[token_count];
vkd3d_shader_parser_init(&sm1->p, message_context, compile_info->source_name, &version, &shader_sm1_parser_ops); /* Estimate instruction count to avoid reallocation in most shaders. */
if (!vkd3d_shader_parser_init(&sm1->p, message_context, compile_info->source_name, &version, &shader_sm1_parser_ops,
code_size != ~(size_t)0 ? token_count / 4u + 4 : 16))
return VKD3D_ERROR_OUT_OF_MEMORY;
shader_desc = &sm1->p.shader_desc; shader_desc = &sm1->p.shader_desc;
shader_desc->byte_code = code; shader_desc->byte_code = code;
shader_desc->byte_code_size = code_size; shader_desc->byte_code_size = code_size;
@@ -934,6 +946,8 @@ static enum vkd3d_result shader_sm1_init(struct vkd3d_shader_sm1_parser *sm1,
int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info, int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compile_info,
struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser) struct vkd3d_shader_message_context *message_context, struct vkd3d_shader_parser **parser)
{ {
struct vkd3d_shader_instruction_array *instructions;
struct vkd3d_shader_instruction *ins;
struct vkd3d_shader_sm1_parser *sm1; struct vkd3d_shader_sm1_parser *sm1;
int ret; int ret;
@@ -950,6 +964,28 @@ int vkd3d_shader_sm1_parser_create(const struct vkd3d_shader_compile_info *compi
return ret; return ret;
} }
instructions = &sm1->p.instructions;
while (!shader_sm1_is_end(&sm1->p))
{
if (!shader_instruction_array_reserve(instructions, instructions->count + 1))
{
ERR("Failed to allocate instructions.\n");
vkd3d_shader_parser_error(&sm1->p, VKD3D_SHADER_ERROR_D3DBC_OUT_OF_MEMORY, "Out of memory.");
shader_sm1_destroy(&sm1->p);
return VKD3D_ERROR_OUT_OF_MEMORY;
}
ins = &instructions->elements[instructions->count];
shader_sm1_read_instruction(&sm1->p, ins);
if (ins->handler_idx == VKD3DSIH_INVALID)
{
WARN("Encountered unrecognized or invalid instruction.\n");
shader_sm1_destroy(&sm1->p);
return VKD3D_ERROR_INVALID_SHADER;
}
++instructions->count;
}
*parser = &sm1->p; *parser = &sm1->p;
return VKD3D_OK; return VKD3D_OK;

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,7 @@ struct vkd3d_glsl_generator
{ {
struct vkd3d_shader_version version; struct vkd3d_shader_version version;
struct vkd3d_string_buffer buffer; struct vkd3d_string_buffer buffer;
const struct vkd3d_shader_location *location; struct vkd3d_shader_location location;
struct vkd3d_shader_message_context *message_context; struct vkd3d_shader_message_context *message_context;
bool failed; bool failed;
}; };
@@ -38,7 +38,7 @@ struct vkd3d_glsl_generator *vkd3d_glsl_generator_create(const struct vkd3d_shad
memset(generator, 0, sizeof(*generator)); memset(generator, 0, sizeof(*generator));
generator->version = *version; generator->version = *version;
vkd3d_string_buffer_init(&generator->buffer); vkd3d_string_buffer_init(&generator->buffer);
generator->location = location; generator->location = *location;
generator->message_context = message_context; generator->message_context = message_context;
return generator; return generator;
} }
@@ -50,7 +50,7 @@ static void VKD3D_PRINTF_FUNC(3, 4) vkd3d_glsl_compiler_error(
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vkd3d_shader_verror(generator->message_context, generator->location, error, fmt, args); vkd3d_shader_verror(generator->message_context, &generator->location, error, fmt, args);
va_end(args); va_end(args);
generator->failed = true; generator->failed = true;
} }
@@ -93,28 +93,20 @@ static void vkd3d_glsl_handle_instruction(struct vkd3d_glsl_generator *generator
int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator, int vkd3d_glsl_generator_generate(struct vkd3d_glsl_generator *generator,
struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *out) struct vkd3d_shader_parser *parser, struct vkd3d_shader_code *out)
{ {
unsigned int i;
void *code; void *code;
struct vkd3d_shader_instruction ins;
vkd3d_string_buffer_printf(&generator->buffer, "#version 440\n\n"); vkd3d_string_buffer_printf(&generator->buffer, "#version 440\n\n");
vkd3d_string_buffer_printf(&generator->buffer, "void main()\n{\n"); vkd3d_string_buffer_printf(&generator->buffer, "void main()\n{\n");
while (!vkd3d_shader_parser_is_end(parser)) generator->location.column = 0;
for (i = 0; i < parser->instructions.count; ++i)
{ {
vkd3d_shader_parser_read_instruction(parser, &ins); generator->location.line = i + 1;
vkd3d_glsl_handle_instruction(generator, &parser->instructions.elements[i]);
if (ins.handler_idx == VKD3DSIH_INVALID)
{
vkd3d_glsl_compiler_error(generator,
VKD3D_SHADER_ERROR_GLSL_INTERNAL,
"Encountered unrecognized or invalid instruction.");
break;
}
vkd3d_glsl_handle_instruction(generator, &ins);
} }
if (parser->failed || generator->failed) if (generator->failed)
return VKD3D_ERROR_INVALID_SHADER; return VKD3D_ERROR_INVALID_SHADER;
vkd3d_string_buffer_printf(&generator->buffer, "}\n"); vkd3d_string_buffer_printf(&generator->buffer, "}\n");

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -181,7 +181,7 @@ row_major {return KW_ROW_MAJOR; }
yylval->name = hlsl_strdup(ctx, yytext); yylval->name = hlsl_strdup(ctx, yytext);
if (hlsl_get_var(ctx->cur_scope, yytext) || hlsl_get_function(ctx, yytext)) if (hlsl_get_var(ctx->cur_scope, yytext) || hlsl_get_function(ctx, yytext))
return VAR_IDENTIFIER; return VAR_IDENTIFIER;
else if (hlsl_get_type(ctx->cur_scope, yytext, true)) else if (hlsl_get_type(ctx->cur_scope, yytext, true, true))
return TYPE_IDENTIFIER; return TYPE_IDENTIFIER;
else else
return NEW_IDENTIFIER; return NEW_IDENTIFIER;
@@ -233,14 +233,14 @@ row_major {return KW_ROW_MAJOR; }
struct hlsl_ctx *ctx = yyget_extra(yyscanner); struct hlsl_ctx *ctx = yyget_extra(yyscanner);
TRACE("#pragma setting row_major mode.\n"); TRACE("#pragma setting row_major mode.\n");
ctx->matrix_majority = HLSL_ROW_MAJOR; ctx->matrix_majority = HLSL_MODIFIER_ROW_MAJOR;
BEGIN(pp_ignore); BEGIN(pp_ignore);
} }
<pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) { <pp_pragma>pack_matrix{WS}*\({WS}*column_major{WS}*\) {
struct hlsl_ctx *ctx = yyget_extra(yyscanner); struct hlsl_ctx *ctx = yyget_extra(yyscanner);
TRACE("#pragma setting column_major mode.\n"); TRACE("#pragma setting column_major mode.\n");
ctx->matrix_majority = HLSL_COLUMN_MAJOR; ctx->matrix_majority = HLSL_MODIFIER_COLUMN_MAJOR;
BEGIN(pp_ignore); BEGIN(pp_ignore);
} }
<pp_pragma>{NEWLINE} { <pp_pragma>{NEWLINE} {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -509,6 +509,8 @@ bool hlsl_fold_constant_exprs(struct hlsl_ctx *ctx, struct hlsl_ir_node *instr,
if (instr->type != HLSL_IR_EXPR) if (instr->type != HLSL_IR_EXPR)
return false; return false;
expr = hlsl_ir_expr(instr); expr = hlsl_ir_expr(instr);
if (!expr->operands[0].node)
return false;
if (instr->data_type->type > HLSL_CLASS_VECTOR) if (instr->data_type->type > HLSL_CLASS_VECTOR)
return false; return false;
@@ -601,7 +603,7 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
{ {
struct hlsl_ir_constant *value, *res; struct hlsl_ir_constant *value, *res;
struct hlsl_ir_swizzle *swizzle; struct hlsl_ir_swizzle *swizzle;
unsigned int i, swizzle_bits; unsigned int i;
if (instr->type != HLSL_IR_SWIZZLE) if (instr->type != HLSL_IR_SWIZZLE)
return false; return false;
@@ -613,12 +615,8 @@ bool hlsl_fold_constant_swizzles(struct hlsl_ctx *ctx, struct hlsl_ir_node *inst
if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc))) if (!(res = hlsl_new_constant(ctx, instr->data_type, &instr->loc)))
return false; return false;
swizzle_bits = swizzle->swizzle;
for (i = 0; i < swizzle->node.data_type->dimx; ++i) for (i = 0; i < swizzle->node.data_type->dimx; ++i)
{ res->value[i] = value->value[hlsl_swizzle_get_component(swizzle->swizzle, i)];
res->value[i] = value->value[swizzle_bits & 3];
swizzle_bits >>= 2;
}
list_add_before(&swizzle->node.entry, &res->node.entry); list_add_before(&swizzle->node.entry, &res->node.entry);
hlsl_replace_node(&swizzle->node, &res->node); hlsl_replace_node(&swizzle->node, &res->node);

Some files were not shown because too many files have changed in this diff Show More