923 Commits

Author SHA1 Message Date
Henri Verbeet
f732fb7889 Release 1.17. 2025-08-21 12:52:13 +02:00
Brendan Shanks
44fffee5e1 tests: Add dxcompiler.h to .gitignore. 2025-08-14 10:34:44 +02:00
Brendan Shanks
bb2a6a0322 include: Add additional generated files to .gitignore. 2025-08-14 10:34:44 +02:00
Henri Verbeet
975ba8f9da vkd3d-shader: Document that vkd3d_shader_scan() supports HLSL sources. 2025-08-14 10:33:45 +02:00
Francisco Casas
7007a1e264 vkd3d-compiler: Set a default target type even when preprocessing.
We largely ignore the target type when preprocessing, but still
dereference options.target_type in a couple of places. E.g. when setting
info.target_type. We could add more checks for options.preprocess_only
to account for that, but it seems more robust to make sure
options.target_type is never NULL.
2025-08-13 16:12:50 +02:00
Henri Verbeet
cab0bd07e5 vkd3d-shader/glsl: Resolve SSA values.
Since commit eaebef4265 we may receive
vsir generated from HLSL sources, which typically contains SSA values.
We could previously receive vsir with SSA values as well, but HLSL
sources would go through d3dbc/tpf as an intermediate step, making the
resulting vsir much less likely to contain SSA values.
2025-08-13 15:56:06 +02:00
Henri Verbeet
9336b4647c vkd3d-shader/d3d-asm: Resolve SSA values when outputting SM<6 assembly.
In particular, since commit eaebef4265 we
may receive vsir generated from HLSL sources, which typically contains
SSA values.
2025-08-13 15:55:31 +02:00
Henri Verbeet
8334386d99 vkd3d-shader/spirv: Avoid emitting duplicate built-in inputs in spirv_compiler_emit_input().
This works around an issue introduced by commit
66cb2815f0. SV_PRIMITIVE_ID inputs in
geometry shaders use VKD3DSPR_PRIMID registers, and we create the
corresponding SPIR-V inputs using spirv_compiler_emit_io_register().
Unfortunately we also have an input signature element for the same
input, and simply creating another PrimitiveId input would run into
VUID-StandaloneSpirv-OpEntryPoint-09658.

Before the commit mentioned above, we'd use DCL_INPUT instructions to
emit input declarations, and these would help to distinguish whether
VKD3DSPR_INPUT or VKD3DSPR_PRIMID registers were used for primitive ID
inputs. Note that we can't simply ignore input signature element with
SIGNATURE_TARGET_LOCATION_UNUSED; the DXIL parser emits SV_SAMPLE_INDEX
inputs with that target location, but does require them to use a
VKD3DSPR_INPUT register.
2025-08-13 15:54:12 +02:00
Francisco Casas
880cb1083f vkd3d-shader/ir: Use iterators in vsir_program_insert_point_coord(). 2025-08-07 20:43:28 +02:00
Francisco Casas
a91b880afa vkd3d-shader/ir: Use iterators in vsir_program_insert_point_size_clamp(). 2025-08-07 20:43:28 +02:00
Francisco Casas
0ed34c22c9 vkd3d-shader/ir: Use iterators in vsir_program_insert_point_size(). 2025-08-07 20:43:28 +02:00
Francisco Casas
14643b02f6 vkd3d-shader/ir: Use iterators in vsir_program_insert_clip_planes(). 2025-08-07 20:43:28 +02:00
Francisco Casas
bd52ed8918 vkd3d-shader/ir: Use iterators in vsir_program_insert_alpha_test(). 2025-08-07 20:43:28 +02:00
Henri Verbeet
f7890fc54c vkd3d-shader/hlsl: Support HLSL sources in vkd3d_shader_scan(). 2025-08-07 20:40:01 +02:00
Henri Verbeet
f95fc28851 vkd3d-shader/hlsl: Return a vsir program from hlsl_compile_shader().
This largely brings the HLSL frontend in line with the other frontends.
2025-08-07 20:40:01 +02:00
Henri Verbeet
85603dc9c6 vkd3d-shader/hlsl: Initialise the vsir program in hlsl_compile_shader().
Mostly in preparation for returning a vsir program from
hlsl_compile_shader() in the next commit.
2025-08-07 20:37:41 +02:00
Henri Verbeet
e7be5aa9fd vkd3d-shader/hlsl: Pass a vkd3d_shader_source_list pointer to hlsl_ctx_init().
Instead of storing the list inside struct hlsl_ctx. The source file
names in the list are used by the location information that the HLSL
frontend produces, and end up being referenced by the vsir program. If
we want the vsir program to be able to outlive the hlsl_ctx, its
location information can't reference data owned by the hlsl_ctx.
2025-08-07 20:33:24 +02:00
Henri Verbeet
7c37fc6a8b vkd3d-shader: Introduce struct vkd3d_shader_source_list. 2025-08-07 20:33:24 +02:00
Henri Verbeet
e4bb77ecef vkd3d-shader: Cleanup the vsir program on vsir_program_transform_early() failure in vsir_parse(). 2025-08-07 20:33:24 +02:00
Elizabeth Figura
f9bb84e5ef vkd3d-shader/d3dbc: Lower TEXCRD. 2025-08-07 19:30:29 +02:00
Elizabeth Figura
731b94f6f9 vkd3d-shader/d3dbc: Lower 1.4 TEXLD. 2025-08-07 19:05:25 +02:00
Elizabeth Figura
9c605c942c vkd3d-shader/d3dbc: Normalize ps 1.x output. 2025-08-07 18:55:40 +02:00
Elizabeth Figura
a4f69d4ae6 vkd3d-shader/d3dbc: Move TEXLD lowering to d3dbc_parse(). 2025-08-07 18:52:46 +02:00
Elizabeth Figura
2201c32e6d vkd3d-shader: Add descriptors from SAMPLE instructions if necessary.
This has no effect now, but will once we start lowering sm1 texturing
instructions before vsir_program_scan() is called.
2025-08-07 16:15:47 +02:00
Francisco Casas
f6d0c689ee vkd3d-shader/ir: Use iterators in vsir_program_materialise_phi_ssas_to_temps(). 2025-08-06 18:24:19 +02:00
Francisco Casas
aab02b1bca vkd3d-shader/ir: Use iterators in vsir_program_flatten_hull_shader_phases(). 2025-08-06 18:23:33 +02:00
Francisco Casas
6c840b80d6 vkd3d-shader/ir: Use iterators in cf_flattener_iterate_instruction_array(). 2025-08-06 18:19:55 +02:00
Francisco Casas
e428528a7c vkd3d-shader/ir: Use iterators in vsir_program_remove_dead_code(). 2025-08-06 18:19:55 +02:00
Francisco Casas
f818d052cd vkd3d-shader/ir: Remove the io_normaliser.instructions field.
It's effectively unused, and struct vkd3d_shader_instruction_array is
not meant to be copied by value. If io_normaliser.instructions were to
be modified it might leave program->instructions in an inconsistent
state.
2025-08-06 12:54:54 +02:00
Francisco Casas
b3badec039 vkd3d-shader/ir: Use iterators in vsir_program_normalise_io_registers(). 2025-08-06 12:53:52 +02:00
Francisco Casas
304caa885f vkd3d-shader/ir: Use iterators in vsir_program_normalise_flat_constants(). 2025-08-06 12:53:52 +02:00
Francisco Casas
37ca1b55c9 vkd3d-shader/ir: Use iterators in instruction_array_normalise_hull_shader_control_point_io(). 2025-08-06 12:53:52 +02:00
Francisco Casas
97e3877aa4 vkd3d-shader/ir: Use iterators in vsir_program_remap_output_signature(). 2025-08-06 12:53:52 +02:00
Francisco Casas
6dc9ff1bd8 vkd3d-shader/ir: Use iterators in vsir_program_ensure_diffuse().
The change in vsir_program_iterator_next() is necessary to allow us to
introduce instructions before the iterator using:

    vsir_program_iterator_prev(&it);
    vsir_program_iterator_inset_after(&it, n);
    vsir_program_iterator_next(&it);

This since (it.idx == SIZE_MAX) is equivalent to the iterator being
before the beginning of the list.
2025-08-06 12:53:37 +02:00
Henri Verbeet
ce20f9d4b2 tests/shader_runner_d3d12: Check whether the d3d12 device supports geometry shaders. 2025-08-06 12:04:16 +02:00
Henri Verbeet
47a183c75b tests/d3d12: Check whether the d3d12 device supports geometry shaders. 2025-08-06 12:04:16 +02:00
Shaun Ren
4bb880f9ed vkd3d-shader/hlsl: Support interlocked operations on non-indexed groupshared variables. 2025-08-05 16:33:08 +02:00
Shaun Ren
8d0d8d106b vkd3d-shader/hlsl: Support stores to raw groupshared variables. 2025-08-05 16:32:34 +02:00
Shaun Ren
c8d2d40b91 vkd3d-shader/hlsl: Support loads from groupshared variables. 2025-08-05 16:18:26 +02:00
Shaun Ren
fa560b589e vkd3d-shader/hlsl: Emit dcl_tgsm_raw instructions for raw groupshared variables. 2025-08-05 16:09:45 +02:00
Shaun Ren
3802344e97 vkd3d-shader/hlsl: Allocate groupshared registers. 2025-08-05 16:06:07 +02:00
Victor Chiletto
e615e435d9 vkd3d-shader/hlsl: Split matrix copies from resource loads. 2025-08-05 14:25:50 +02:00
Victor Chiletto
e718546ee5 vkd3d-shader/hlsl: Transform hlsl_ir_index into structured buffers into field specific hlsl_ir_resource_loads. 2025-08-05 14:25:50 +02:00
Victor Chiletto
5dbf859029 vkd3d-shader/hlsl: Parse SRV structured buffers. 2025-08-05 14:25:50 +02:00
Victor Chiletto
161d463f3c tests/hlsl: Add a few extra structured buffer matrix load + swizzle tests. 2025-08-05 14:25:44 +02:00
Henri Verbeet
721859005f tests: Strip reflection data from dxbc-tpf-hex shaders. 2025-08-04 15:00:02 +02:00
Henri Verbeet
243207701b tests/shader_runner: Parse hex blobs as a list of 32-bit integers. 2025-08-04 15:00:02 +02:00
Francisco Casas
5dca0da2da vkd3d-shader/hlsl: Use vsir_program_append() in generate_vsir_add_program_instruction(). 2025-08-04 14:58:14 +02:00
Francisco Casas
be5a9c2ca8 vkd3d-shader/hlsl: Use vsir_program_append() in sm1_generate_vsir_sampler_dcls(). 2025-08-04 14:52:50 +02:00
Francisco Casas
81488ce330 vkd3d-shader/hlsl: Use vsir_program_append() in sm1_generate_vsir_constant_defs(). 2025-08-04 14:47:58 +02:00
Francisco Casas
8717fe9c47 vkd3d-shader/dxil: Use iterators in sm6_parser_globals_init(). 2025-08-04 14:40:17 +02:00
Giovanni Mascellani
3817df1164 tests/shader_runner_metal: Run the Metal shader runner with DXIL shaders. 2025-08-04 14:34:23 +02:00
Giovanni Mascellani
d898923b1c tests/shader_runner_metal: Allow checking shader model 5.1 too. 2025-08-04 14:34:23 +02:00
Giovanni Mascellani
1d71cf9af1 vkd3d-shader/msl: Allocate SSA registers to temporaries. 2025-08-04 14:34:23 +02:00
Giovanni Mascellani
bec000b88e vkd3d-shader: Enable converting DXIL to MSL.
Only trivial shaders work so far.
2025-08-04 14:34:01 +02:00
Conor McCarthy
691dd49e49 vkd3d-shader/dxil: Handle SV_PrimitiveId outputs. 2025-08-04 11:54:46 +02:00
Conor McCarthy
1293db7536 tests/hlsl: Add a test for SV_PrimitiveId inputs and outputs. 2025-08-04 11:54:46 +02:00
Henri Verbeet
bd3d0f3495 vkd3d-shader/ir: Use vsir_program_append() in vsir_program_ensure_ret().
I think this is slightly nicer. It also happens to avoid a
-Warray-bounds warning on some versions of gcc that suggests the "ins"
pointer returned by vsir_program_iterator_next() may be NULL.
2025-07-31 15:01:29 +02:00
Conor McCarthy
b9fe19701c vkd3d-shader/dxil: Handle SV_ViewportArrayIndex. 2025-07-31 14:55:33 +02:00
Conor McCarthy
cd8cea6913 tests: Replace test_ps_viewport_index() with a shader runner test.
Mainly to allow testing the functionality in question with DXIL shaders
as well.
2025-07-31 14:55:33 +02:00
Henri Verbeet
55fe8df979 vkd3d: Set the maximum viewport count in d3d12_pipeline_state_get_or_create_pipeline().
VK_DYNAMIC_STATE_VIEWPORT and VK_DYNAMIC_STATE_SCISSOR specify that
viewports and scissor rectangles are dynamic state, but not their
counts.

It took a while to notice this issue because the existing code seemed to
largely work as intended on hardware implementations, but tests using
the additional viewports would fail on llvmpipe.
2025-07-31 14:55:33 +02:00
Henri Verbeet
74d8c23f71 include: Remove some redudant TAG_* definintions from vkd3d_shader_util.h.
We already have all of these in vkd3d_common.h.
2025-07-31 14:54:59 +02:00
Elizabeth Figura
d0ce3e61bf tests/hlsl: Add a regression test for packed SV_IsFrontFace.
This tests f0906e9c5c.
2025-07-31 14:54:15 +02:00
Elizabeth Figura
75cb4336ec vkd3d-shader/ir: Record the previous temp count before allocating any SSA values.
Due to the unintentional placement of this line, we were inadvertently
allocating every SSA value to a unique temp register, overflowing limits.
2025-07-30 15:36:38 +02:00
Henri Verbeet
67fd9bb76b vkd3d-shader/ir: Free program parameters on failure in vsir_program_init() if needed. 2025-07-30 15:35:54 +02:00
Henri Verbeet
f6a9def564 vkd3d-shader/spirv: Update the SPIR-V grammar JSON to the vulkan-sdk-1.4.313.0 release. 2025-07-30 15:11:19 +02:00
Henri Verbeet
bb2979aa4c vkd3d-shader/hlsl: Generate vsir signatures in hlsl_emit_vsir(). 2025-07-29 13:15:22 +02:00
Henri Verbeet
49b857c5b7 vkd3d-shader/hlsl: Initialise the vsir program in hlsl_emit_vsir(). 2025-07-29 13:15:22 +02:00
Henri Verbeet
dbaecb3f36 vkd3d-shader/hlsl: Introduce hlsl_compile_effect().
The goal being to allow hlsl_compile_shader() to return a vsir program.
2025-07-29 13:14:30 +02:00
Giovanni Mascellani
6805612918 vkd3d-shader: Use the structure names when creating the parameter allocators.
So that it doesn't depend on the instruction array implementation.
2025-07-29 13:13:53 +02:00
Giovanni Mascellani
247fbd869a vkd3d-shader/ir: Use iterators in vsir_program_ensure_ret(). 2025-07-29 13:12:58 +02:00
Giovanni Mascellani
812f6faa11 vkd3d-shader/ir: Use iterators in vsir_program_normalize_addr(). 2025-07-29 12:53:00 +02:00
Giovanni Mascellani
50afaf4ac6 vkd3d-shader: Use iterators in vsir_program_scan(). 2025-07-29 12:53:00 +02:00
Giovanni Mascellani
aba355896f vkd3d-shader/hlsl: Reject geometry shaders with instance count.
We currently emit a warning and miscompile them.
2025-07-29 12:51:06 +02:00
Giovanni Mascellani
22f84317c0 vkd3d-shader/ir: Check that GSINSTID registers have dimension VEC4.
I had set it to SCALAR in an earlier commit, but I hadn't noticed
it failed validation.

Also fix the HLSL compiler to emit them accordingly.

Fixes: dfc18781cc
2025-07-29 12:51:06 +02:00
Giovanni Mascellani
3797c922a5 tests/hlsl: Test SV_GSInstanceID. 2025-07-29 12:50:23 +02:00
Giovanni Mascellani
52b9ef0426 vkd3d-shader/spirv: Support precise flags on SAMPLE_INFO instructions. 2025-07-29 12:31:36 +02:00
Giovanni Mascellani
53754f0583 vkd3d-shader/spirv: Support precise flags on RESINFO instructions. 2025-07-29 12:31:23 +02:00
Giovanni Mascellani
bdccdd9996 vkd3d-shader/d3d-asm: Emit precise flags for a number of opcodes.
I've seen them specifically on RESINFO, but it general it makes
sense to print them for any opcode that expects a bit field in
the flags.
2025-07-29 12:28:09 +02:00
Giovanni Mascellani
f7866df201 vkd3d-shader/dxil: Emit gather offsets as signed.
This is important for the MSL generator, otherwise invalid MSL
is emitted.
2025-07-28 16:32:40 +02:00
Giovanni Mascellani
3cf35ce22e vkd3d-shader/msl: Convert the results of load and sample operations to the destination data type.
This should eventually go away when we properly enforce vsir typing,
but since for the moment we're resolving to hack, let's at least
make it compatible with DXIL.
2025-07-28 16:31:57 +02:00
Giovanni Mascellani
7df92b6e50 vkd3d-shader/msl: Reject shaders with duplicate I/O target locations.
We'll have to handle them eventually, but let's avoid generating
invalid code in the meantime.
2025-07-28 16:27:58 +02:00
Giovanni Mascellani
9476a235b2 vkd3d-shader/msl: Use the union type for SAMPLEMASK registers.
Function msl_print_assignment() doesn't currently handle bitcasts
when the left operand has a specific (rather than a union) type.

We could also fix the function, and maybe it wouldn't be a bad
idea anyway, but using the union type seems more in the spirit
of the MSL backend anyway.
2025-07-28 16:27:58 +02:00
Giovanni Mascellani
16b06c295b vkd3d-shader/msl: Emit indexable temps with the appropriate component count. 2025-07-28 16:27:58 +02:00
Giovanni Mascellani
6ed0bd0bab vkd3d-shader/msl: Ignore the interpolation mode for output variables.
They are meaningless, but some frontends (e.g., DXIL) set them
nevertheless.
2025-07-28 16:27:58 +02:00
Francisco Casas
19bc3ec104 vkd3d-shader/ir: Validate flags in RESINFO operations. 2025-07-28 16:26:16 +02:00
Francisco Casas
3a0a96b851 vkd3d-shader/ir: Validate flags in SAMPLE_INFO operations. 2025-07-28 16:26:16 +02:00
Nikolay Sivov
a4f5225229 vkd3d: Return success from d3d12_device_EnumerateMetaCommands().
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-07-28 16:24:04 +02:00
Nikolay Sivov
2c49f04411 vkd3d-shader/fx: Do not attempt to parse expressions without code section. 2025-07-28 16:22:13 +02:00
Nikolay Sivov
dcd1747f12 vkd3d-shader/fx: Handle regular shader blobs when parsing the state data.
For the pass shader states this blob will contain compiled shaders, for other
state types it will contain expression code. Complex state data is stored separately,
tracing it back to actual state type will require keeping track of already parsed states.
2025-07-28 16:21:32 +02:00
Henri Verbeet
0652cb4adb demos/teapot: Add specular lighting. 2025-07-28 16:12:19 +02:00
Henri Verbeet
9b0087a111 vkd3d-shader/spirv: Emit OpLine instructions. 2025-07-28 16:11:29 +02:00
Henri Verbeet
b3cac7b86d vkd3d-shader: Call vsir_program_scan() for d3d-asm targets in vsir_program_compile().
Like we do for every other target.
2025-07-28 16:11:06 +02:00
Henri Verbeet
eaebef4265 vkd3d-shader/hlsl: Emit vsir from hlsl_emit_bytecode(). 2025-07-28 16:10:15 +02:00
Henri Verbeet
4300e6c8b5 vkd3d-shader/ir: Allow source operands of shift operations to have different data types. 2025-07-28 16:10:15 +02:00
Henri Verbeet
b3e367b099 vkd3d-shader/tpf: Update the comment describing the data type mapping in init_sm4_lookup_tables().
"R", "S", and "U" were removed, and "*" was added.
2025-07-24 19:12:49 +02:00
Henri Verbeet
a4c25b81c5 vkd3d-shader/hlsl: Get rid of the "hlsl" argument to hlsl_compile_shader(). 2025-07-23 17:25:19 +02:00
Henri Verbeet
f02405350e vkd3d-shader/ir: Consistently use VSIR_DATA_U32 for resinfo_uint destination operands.
Much like we do for sample_info_uint.
2025-07-23 17:23:40 +02:00
Henri Verbeet
b88be5b92b vkd3d-shader/ir: Consistently use VSIR_DATA_U32 for sample_info_uint destination operands.
The HLSL compiler already did this; the TPF and DXIL parsers did not.
Previously spirv_compiler_emit_sample_info() was unable to correctly
handle VSIR_DATA_U32 destinations; the new version is arguably simpler
as well.
2025-07-23 17:23:40 +02:00
Henri Verbeet
b8c73e4a2c vkd3d-shader/spirv: Use spirv_compiler_error() to report unhandled resinfo flags. 2025-07-23 17:23:40 +02:00
Henri Verbeet
ed2a06af35 vkd3d-shader/spirv: Use spirv_compiler_error() to report unhandled sample_info flags. 2025-07-23 17:23:40 +02:00
Henri Verbeet
7295a8d0b5 vkd3d-shader/ir: Explicitly initialise the "resource_data_type" field in vsir_instruction_init().
This depended on VKD3D_DATA_FLOAT/VSIR_DATA_F32 being the first
enumeration value, but that's no longer the case.
shader_dump_instruction() compares this against VSIR_DATA_F32 to
determine whether to call shader_dump_resource_data_type().
2025-07-23 17:23:01 +02:00
Henri Verbeet
795211141f vkd3d-shader/ir: Rename VKD3D_DATA_BOOL to VSIR_DATA_BOOL. 2025-07-23 17:19:28 +02:00
Henri Verbeet
aebe64ecac vkd3d-shader/ir: Rename VKD3D_DATA_UNUSED to VSIR_DATA_UNUSED. 2025-07-23 17:19:28 +02:00
Henri Verbeet
f74b56622a vkd3d-shader/ir: Rename VKD3D_DATA_CONTINUED to VSIR_DATA_CONTINUED. 2025-07-23 17:19:28 +02:00
Henri Verbeet
ca24aada9a vkd3d-shader/ir: Rename VKD3D_DATA_MIXED to VSIR_DATA_MIXED. 2025-07-23 17:19:28 +02:00
Henri Verbeet
b055a16e03 vkd3d-shader/ir: Rename VKD3D_DATA_OPAQUE to VSIR_DATA_OPAQUE. 2025-07-23 17:19:28 +02:00
Henri Verbeet
ed695cc551 vkd3d-shader/ir: Rename VKD3D_DATA_SNORM to VSIR_DATA_SNORM. 2025-07-23 17:19:28 +02:00
Henri Verbeet
ed27427508 vkd3d-shader/ir: Rename VKD3D_DATA_UNORM to VSIR_DATA_UNORM. 2025-07-23 17:19:28 +02:00
Giovanni Mascellani
2f4be1dbb6 vkd3d-shader: Use size_t in the string buffer. 2025-07-23 17:16:47 +02:00
Giovanni Mascellani
17ffd21113 vkd3d-shader/ir: Use size_t in the instruction array. 2025-07-23 17:16:43 +02:00
Giovanni Mascellani
bb51b976df vkd3d-shader/ir: Use size_t in the parameter allocator.
The idea is to, by default, use size_t for any quantity that is
a memory size or an array index.
2025-07-23 17:16:38 +02:00
Nikolay Sivov
83e54bdc0c vkd3d-shader/hlsl: Handle HLSL_RESOURCE_SAMPLE_LOD in sm1_generate_vsir_instr_resource_load().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58063
2025-07-23 17:06:21 +02:00
Nikolay Sivov
969b6f5946 vkd3d-shader/ir: Handle TEXLDL instructions in vsir_program_lower_instructions().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58063
2025-07-23 17:02:05 +02:00
Anna (navi) Figueiredo Gomes
a7266284ee vkd3d-shader/hlsl: Move hlsl_ir_function_decl->extern_vars to a local variable. 2025-07-23 16:56:06 +02:00
Anna (navi) Figueiredo Gomes
db80f09c7a vkd3d-shader/hlsl: Don't create a temporary copy for a uniform if one already exists.
This can currently never happen, because we only ever process each uniform
once. However, this will change once we support compiling multiple shaders
in effects.
2025-07-23 16:37:54 +02:00
Anna (navi) Figueiredo Gomes
f4d95af91d vkd3d-shader/hlsl: Add temporary variables to "dummy_scope" in prepend_uniform_copy().
These are not looked up by name, so we don't need them in a specific scope.

Moreover, since we generate the temporaries using the same storage
modifiers as the uniforms, hlsl_emit_bytecode() will treat them as new
uniforms if run multiple times. That function is currently only run
once, but this will change when compiling shaders in effects.
2025-07-23 16:33:35 +02:00
Anna (navi) Figueiredo Gomes
66895e2605 vkd3d-shader/hlsl: Reset "extern_vars" before processing "entry_func" in hlsl_emit_bytecode(). 2025-07-23 16:32:34 +02:00
Francisco Casas
844f33025e vkd3d-shader/hlsl: Dump processed function bodies. 2025-07-23 16:31:59 +02:00
Anna (navi) Figueiredo Gomes
f420e25fd5 vkd3d-shader/hlsl: Clone the entry point body and redirect processing to the clone. 2025-07-23 15:54:52 +02:00
Giovanni Mascellani
68cd72c7fc vkd3d-shader/ir: Validate ROUND_NI instructions. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
b3db78e3c1 vkd3d-shader/ir: Validate ROUND_NE instructions. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
f3f8056800 vkd3d-shader/ir: Validate RCP instructions. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
59738c7a4a vkd3d-shader/ir: Validate ORD instructions. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
6266f89827 vkd3d-shader/ir: Validate OR operations. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
1c7c66912b vkd3d-shader/ir: Validate NOT operations. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
4789295e91 vkd3d-shader/ir: Validate NEU operations. 2025-07-22 17:11:51 +02:00
Giovanni Mascellani
3234c428b3 vkd3d-shader/ir: Validate NEO operations. 2025-07-22 17:11:50 +02:00
Giovanni Mascellani
14ee6b86e0 vkd3d-shader/d3dbc: Use iterators in d3dbc_write_program_instructions(). 2025-07-22 17:11:19 +02:00
Giovanni Mascellani
4a1ca99cba vkd3d-shader/d3dbc: Use vsir_program_append() in d3dbc_parse(). 2025-07-22 17:11:19 +02:00
Giovanni Mascellani
42f53c82f3 vkd3d-shader/d3d-asm: Use iterators in d3d_asm_compile(). 2025-07-22 17:11:13 +02:00
Giovanni Mascellani
ddb65aac35 vkd3d-shader/glsl: Use iterators in vkd3d_glsl_generator_generate(). 2025-07-22 17:01:04 +02:00
Giovanni Mascellani
01068dada2 vkd3d-shader/msl: Use iterators in msl_generator_generate(). 2025-07-22 16:57:25 +02:00
Giovanni Mascellani
7d9a86790e vkd3d-shader/spirv: Use iterators in spirv_compiler_generate_spirv(). 2025-07-22 16:56:07 +02:00
Giovanni Mascellani
7e76e62db7 vkd3d-shader/tpf: Use iterators in tpf_write_program(). 2025-07-22 16:52:24 +02:00
Giovanni Mascellani
0789578175 vkd3d-shader/ir: Introduce vsir_program_append().
To append an instruction to the end of the vsir program.
2025-07-22 15:12:37 +02:00
Henri Verbeet
b4bf2af315 vkd3d-shader/ir: Consistently use VKD3D_DATA_UNUSED for STREAM registers. 2025-07-22 14:59:27 +02:00
Henri Verbeet
1487764e23 vkd3d-shader/ir: Rename VKD3D_DATA_UINT64 to VSIR_DATA_U64. 2025-07-22 14:57:26 +02:00
Henri Verbeet
742cce9a08 vkd3d-shader/ir: Rename VKD3D_DATA_UINT to VSIR_DATA_U32. 2025-07-22 14:57:26 +02:00
Henri Verbeet
163b87444f vkd3d-shader/ir: Rename VKD3D_DATA_UINT16 to VSIR_DATA_U16. 2025-07-22 14:57:26 +02:00
Henri Verbeet
40bbd61abd vkd3d-shader/ir: Rename VKD3D_DATA_UINT8 to VSIR_DATA_U8. 2025-07-22 14:57:26 +02:00
Henri Verbeet
a04e4e4010 vkd3d-shader/ir: Rename VKD3D_DATA_INT to VSIR_DATA_I32. 2025-07-22 14:57:26 +02:00
Henri Verbeet
8f05fbc75d demos/teapot: Animate the camera. 2025-07-22 14:56:51 +02:00
Giovanni Mascellani
13c9826c30 vkd3d-shader/ir: Check that OUTSTENCILREF registers have dimension SCALAR. 2025-07-22 14:55:18 +02:00
Giovanni Mascellani
7b36453b9d vkd3d-shader/ir: Check that PRIMID registers have dimension SCALAR. 2025-07-22 14:55:18 +02:00
Giovanni Mascellani
b3c1fb6740 vkd3d-shader/ir: Check that OUTPOINTID registers have dimension SCALAR. 2025-07-22 14:55:18 +02:00
Giovanni Mascellani
dfc18781cc vkd3d-shader/ir: Check that GSINSTID registers have dimension SCALAR. 2025-07-22 14:55:18 +02:00
Giovanni Mascellani
b02c3759be vkd3d-shader/ir: Check that SAMPLEMASK registers have dimension SCALAR.
Also fix the DXIL parser to emit them accordingly.
2025-07-22 14:55:18 +02:00
Giovanni Mascellani
226afa47c4 vkd3d-shader/ir: Check that THREADID registers have dimension VEC4. 2025-07-22 14:55:18 +02:00
Elizabeth Figura
f0906e9c5c vkd3d-shader/spirv: Use left-shifted writemasks for private variables for inputs.
One of the effects of I/O normalization, when it was introduced, was to shift
the writemask of all semantics to become 0-based—e.g., to convert .yz to .xy.
It did this by modifying the shader code, but did *not* modify the signature
masks.

The SPIR-V compiler, at the time, used both the write mask on the dcl_input
instruction and the signature masks. It also, due to the requirements of the
SPIR-V format, performed the same normalization, left-shifting each mask to
become zero-based. Despite this normalization now being performed earlier in
the aforementioned VSIR pass, the handling in the SPIR-V backend was never
removed.

When 66cb2815f0 was written, I either incorrectly
assumed that the signature mask was equal to the dcl_input write mask (at least,
in any well-formed shader), or (less likely) I noticed that the discrepancy
might exist but believed that the left-shifting normalization performed by the
spirv compiler covered all cases.

In either case it turns out there is one case where the difference was not
handled by the spirv compiler either. That is the case of a varying which has
a fixup function and therefore needs a private variable, which is currently true
for the SV_VertexID, SV_InstanceID, and SV_IsFrontFace varyings.

Thus, if one of those varyings has a signature mask other than .x, we currently
copy the SPIR-V builtin value to the relevant component of the private variable,
but subsequent code will load from the .x variable due to the normalization done
by shader_src_param_io_normalise().

This fixes a regression introduced by 66cb2815f0.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57433
2025-07-22 14:51:09 +02:00
Giovanni Mascellani
decc155cca vkd3d-shader/ir: Split updating DCL_TEMPS instructions to a dedicated pass.
So that it can be used in other contexts as well. And so that
register allocation can be run also when there is no need to update
or create DCL_TEMPS instructions.
2025-07-21 12:31:08 +02:00
Giovanni Mascellani
079e989b8e vkd3d-shader/ir: Update the program TEMP count when allocating TEMP registers. 2025-07-21 12:26:10 +02:00
Giovanni Mascellani
f5cd0b4a15 vkd3d-shader/ir: Check that THREADGROUPID registers have dimension VEC4. 2025-07-21 12:23:34 +02:00
Giovanni Mascellani
59253a5e7f vkd3d-shader/ir: Check that LOCALTHREADID registers have dimension VEC4. 2025-07-21 12:23:34 +02:00
Giovanni Mascellani
834f762cb5 vkd3d-shader/ir: Check that DEPTHOUTLE registers have dimension SCALAR.
Also fix the DXIL parser to emit them accordingly.
2025-07-21 12:23:34 +02:00
Giovanni Mascellani
18ef9a4f9f vkd3d-shader/ir: Check that DEPTHOUTGE registers have dimension SCALAR.
Also fix the DXIL parser to emit them accordingly.
2025-07-21 12:23:34 +02:00
Giovanni Mascellani
9f453fbb66 vkd3d-shader/ir: Check that DEPTHOUT registers have dimension SCALAR.
Also fix the DXIL parser to emit them accordingly.
2025-07-21 12:23:32 +02:00
Giovanni Mascellani
3d23ef6bf8 vkd3d-shader/ir: Check that COVERAGE registers have dimension VEC4.
Also fix the HLSL compiler and DXIL parser to emit them accordingly.
2025-07-21 12:21:23 +02:00
Giovanni Mascellani
ee0447b973 vkd3d-shader/ir: Check that LOCALTHREADINDEX registers have dimension VEC4.
Also fix the HLSL compiler and DXIL parser to emit them accordingly.
2025-07-21 12:18:49 +02:00
Giovanni Mascellani
61c46f95da vkd3d-shader/ir: Validate MUL operations. 2025-07-21 12:16:16 +02:00
Giovanni Mascellani
87545dc4fd vkd3d-shader/ir: Validate MIN operations. 2025-07-21 12:16:16 +02:00
Giovanni Mascellani
366c899a00 vkd3d-shader/ir: Validate MAX operations. 2025-07-21 12:16:16 +02:00
Giovanni Mascellani
5dd226ffeb vkd3d-shader/ir: Validate MAD operations. 2025-07-21 12:16:16 +02:00
Giovanni Mascellani
2237e251fa vkd3d-shader/ir: Validate LTU operations. 2025-07-21 12:16:16 +02:00
Giovanni Mascellani
34cb8c63f4 vkd3d-shader/ir: Validate LTO operations. 2025-07-21 12:16:14 +02:00
Giovanni Mascellani
a8e8a9ee64 vkd3d-shader/ir: Validate LOG operations. 2025-07-21 12:14:22 +02:00
Henri Verbeet
db149cd8cf vkd3d-shader/ir: Rename VKD3D_DATA_DOUBLE to VSIR_DATA_F64. 2025-07-21 12:10:43 +02:00
Henri Verbeet
c5c1c03430 vkd3d-shader/ir: Rename VKD3D_DATA_FLOAT to VSIR_DATA_F32. 2025-07-21 12:10:43 +02:00
Henri Verbeet
d1dcbc26e5 vkd3d-shader/ir: Rename VKD3D_DATA_HALF to VSIR_DATA_F16. 2025-07-21 12:10:43 +02:00
Henri Verbeet
0126beb3b2 vkd3d-shader/ir: Rename enum vkd3d_data_type to vsir_data_type. 2025-07-21 12:10:43 +02:00
Henri Verbeet
53dd048ad5 demos/teapot: Add a flat shading toggle. 2025-07-21 12:09:44 +02:00
Giovanni Mascellani
8d4222764c vkd3d-shader/ir: Use the iterator in vsir_program_lower_texldp(). 2025-07-21 12:07:08 +02:00
Giovanni Mascellani
5407c8b975 vkd3d-shader/ir: Use the iterator in vsir_program_lower_sm4_sincos(). 2025-07-21 12:07:08 +02:00
Giovanni Mascellani
55b8002bf6 vkd3d-shader/ir: Use the iterator in vsir_program_lower_sm1_sincos(). 2025-07-21 12:06:46 +02:00
Giovanni Mascellani
c1f7720075 vkd3d-shader/ir: Use the iterator in vsir_program_lower_udiv(). 2025-07-21 12:02:57 +02:00
Francisco Casas
0f18d25987 tests: Test semantic cascading signatures. 2025-07-21 11:57:01 +02:00
Francisco Casas
faeff50548 tests/hlsl: Add additional semantic cascading tests.
These test make the shader runner segfault before implementing it,
because it miscompiles and there are unused input layout elements.
So they are on their own commit.
2025-07-21 11:57:01 +02:00
Francisco Casas
a9a5c77222 vkd3d-shader/hlsl: Make input semantics on structs cascade down onto the fields. 2025-07-21 11:57:01 +02:00
Francisco Casas
7e9834ee36 vkd3d-shader/hlsl: Make output semantics on structs cascade down onto the fields. 2025-07-21 11:57:00 +02:00
Francisco Casas
f08fed5ffb vkd3d-shader/hlsl: Don't pass the semantic index in add_semantic_var(). 2025-07-21 11:57:00 +02:00
Francisco Casas
28f74a73aa vkd3d-shader/hlsl: Use the index in the hlsl_semantic when prepending input copies. 2025-07-21 11:57:00 +02:00
Francisco Casas
4f5d34265c vkd3d-shader/hlsl: Use the index in the hlsl_semantic when appending output copies. 2025-07-21 11:55:57 +02:00
Francisco Casas
9836c88ac6 tests/hlsl: Add semantic cascading tests.
Co-authored-by: Petrichor Park <ppark@codeweavers.com>
2025-07-21 11:20:14 +02:00
Giovanni Mascellani
7e66d0db6f vkd3d-shader/ir: Do not print a message for registers that are not being allocated. 2025-07-17 14:11:01 +02:00
Giovanni Mascellani
e9d3b9dfd3 vkd3d-shader/ir: Set dimension to VEC4 when converting SSAs to TEMPs. 2025-07-17 14:11:01 +02:00
Giovanni Mascellani
a7807dea08 vkd3d-shader/ir: Validate FTOU operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
ccc82a184b vkd3d-shader/ir: Validate FTOI operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
2c1d210d21 vkd3d-shader/ir: Validate ITOI operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
791a93d0b1 vkd3d-shader/ir: Validate ITOF operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
68ad2becdb vkd3d-shader/ir: Validate ISNAN operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
fb1fc9eb38 vkd3d-shader/ir: Validate ISINF operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
df18a05303 vkd3d-shader/ir: Validate ISFINITE operations. 2025-07-17 14:08:10 +02:00
Giovanni Mascellani
b287e7959c vkd3d-shader/ir: Sort vsir_validator_instructions[] alphabetically. 2025-07-17 14:08:06 +02:00
Giovanni Mascellani
195e62430e vkd3d-shader/ir: Use the iterator in vsir_program_lower_precise_mad(). 2025-07-17 14:04:28 +02:00
Giovanni Mascellani
a12d64fba1 vkd3d-shader/ir: Use the iterator in vsir_program_lower_texkill(). 2025-07-17 14:04:28 +02:00
Giovanni Mascellani
9867d48c3a vkd3d-shader/ir: Use the iterator in vsir_program_lower_ifc(). 2025-07-17 14:04:28 +02:00
Giovanni Mascellani
2d848b5bc0 vkd3d-shader/ir: Introduce an abstraction to iterate through vsir instructions. 2025-07-17 14:04:00 +02:00
Giovanni Mascellani
ba545669cd vkd3d-shader/ir: Validate ISHR operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
126ff8e4f5 vkd3d-shader/ir: Validate ISHL operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
94d999bd8a vkd3d-shader/ir: Validate IREM operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
636e9a91bb vkd3d-shader/ir: Validate INEG operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
7d92142fe0 vkd3d-shader/ir: Validate INE operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
d288d3c088 vkd3d-shader/ir: Validate IMIN operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
2a62b7035c vkd3d-shader/ir: Validate IMAX operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
5fc8baabfb vkd3d-shader/ir: Validate IMAD operations. 2025-07-16 18:07:26 +02:00
Giovanni Mascellani
56247130c1 vkd3d-shader/ir: Validate UAV flags in vsir programs. 2025-07-16 17:44:13 +02:00
Giovanni Mascellani
32bf71ba96 vkd3d-shader/ir: Validate descriptor flags in vsir programs. 2025-07-16 17:34:35 +02:00
Evan Tang
9c040caa40 vkd3d: Get rid of the default fragment shader from d3d12_pipeline_state_init_graphics().
Vulkan does support rendering without a fragment shader, and this seems
to work fine on current drivers. This commit gets rid of the last
embedded shader binary in libvkd3d, and may have a slight performance
advantage on hardware/drivers able to take advantage of the absence of a
fragment shader.
2025-07-16 17:30:11 +02:00
Evan Tang
5c0e6747b8 tests/d3d12: Add a colour attachment to test_draw_depth_no_ps().
To show that draws without fragment shader should leave colour
attachments unmodified.
2025-07-16 17:28:43 +02:00
Evan Tang
39db6731c0 vkd3d: Mask colour writes on graphics pipelines without fragment shaders.
Vulkan leaves the contents of colour attachments undefined in this case.
2025-07-16 16:54:55 +02:00
Nikolay Sivov
3163e589bc vkd3d-shader/fx: Explicitly handle bool state values when parsing.
For bools 0/1 values are treated as named values, outside of this
range it's zero/non-zero.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-07-14 18:38:21 +02:00
Nikolay Sivov
46c75137c7 vkd3d-shader/fx: Use the correct value range for bools in fx_4_0 state values.
The earlier fix a06ecb6867 is missing this.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-07-14 18:38:21 +02:00
Giovanni Mascellani
1a5a2969be vkd3d/resource: Write null descriptors with their correct type when using mutable descriptor types.
This fixes crashes in test_null_srv() and test_null_uav() with
llvmpipe and NVIDIA GPUs.
2025-07-14 18:37:13 +02:00
Giovanni Mascellani
fb91bd7b8b vkd3d: Move vkd3d_vk_descriptor_set_index_from_vk_descriptor_type() to resource.c.
It's only used there.
2025-07-14 18:36:35 +02:00
Nikolay Sivov
fc77bddb9c vkd3d-shader/fx: Improve register naming in the disassembly output.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-07-14 18:29:10 +02:00
Giovanni Mascellani
15561c1e56 vkd3d-shader/ir: Do not make a local copy of the instructions array in vsir_program_flatten_hull_shader_phases(). 2025-07-14 18:25:24 +02:00
Giovanni Mascellani
44ca7b7b1b vkd3d-shader/ir: Handle SSA registers when flattening hull shader phases.
Currently when a phase is duplicated more than once SSA registers
are not refreshed, therefore they are invalidly assigned more than
once.
2025-07-14 18:19:23 +02:00
Giovanni Mascellani
ad1aa739c2 vkd3d-shader/ir: Collect the hull shader phase flattener code together. 2025-07-14 18:19:23 +02:00
Henri Verbeet
b6725a3a00 demos/teapot: Add diffuse lighting. 2025-07-14 18:18:09 +02:00
Henri Verbeet
00f53b72a1 tests/shader_runner_gl: Implement geometry shaders. 2025-07-14 18:16:41 +02:00
Henri Verbeet
673c26a040 vkd3d-shader/msl: Implement VKD3DSGF_FORCE_EARLY_DEPTH_STENCIL. 2025-07-14 18:13:43 +02:00
Henri Verbeet
1a20395e6f vkd3d-shader/msl: Implement VSIR_OP_STORE_UAV_TYPED. 2025-07-14 18:13:43 +02:00
Henri Verbeet
955fff7570 tests/shader_runner_metal: Implement buffer textures. 2025-07-14 18:13:43 +02:00
Henri Verbeet
90b6412daa vkd3d-shader/msl: Implement VSIR_OP_UMAX and VSIR_OP_UMIN. 2025-07-14 18:13:43 +02:00
Giovanni Mascellani
ed464a4f4c vkd3d-shader/ir: Validate ILT instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
715d23ebbb vkd3d-shader/ir: Validate IGE instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
9f455667eb vkd3d-shader/ir: Validate IEQ instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
c29e8188ff vkd3d-shader/ir: Validate IADD instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
4d1fabd350 vkd3d-shader/ir: Validate HTAN instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
e954f75862 vkd3d-shader/ir: Validate HSIN instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
5dd452a5c7 vkd3d-shader/ir: Validate HCOS instructions. 2025-07-14 18:12:22 +02:00
Giovanni Mascellani
cc42581a34 tests/hlsl: Test uint64 comparisons. 2025-07-14 18:12:03 +02:00
Giovanni Mascellani
395d456386 tests/hlsl: Test int64 comparisons. 2025-07-14 18:10:20 +02:00
Giovanni Mascellani
98b0ca544a vkd3d-shader/ir: Test the data type when validating comparison operations.
I had forgot that bit.
2025-07-14 18:06:55 +02:00
Elizabeth Figura
0c3250122c vkd3d-shader/spirv: Do not use OpCopyMemory for partial writemasks in spirv_compiler_emit_mov().
This fixes instructions like "mov r0.xy, r1.xyzw".
2025-06-26 17:44:34 +02:00
Elizabeth Figura
f2238deea9 tests/hlsl: Add tests for cube textures. 2025-06-26 17:40:10 +02:00
Elizabeth Figura
e312207124 tests/shader_runner: Add support for cube resources. 2025-06-26 17:38:55 +02:00
Elizabeth Figura
b58ff893a5 tests/hlsl: Add tests for 3D textures. 2025-06-26 17:32:10 +02:00
Elizabeth Figura
587c2dc76e tests/shader_runner: Add support for 3D resources. 2025-06-26 17:31:34 +02:00
Henri Verbeet
04d3996b07 demos/teapot: Add an fps counter. 2025-06-26 16:09:42 +02:00
Henri Verbeet
22ebccfeb7 vkd3d-shader/ir: Create SSA values with the corresponding dimension in vsir_program_lower_udiv(). 2025-06-26 16:08:32 +02:00
Henri Verbeet
043f6f21b0 vkd3d-shader/ir: Create SSA values with the corresponding dimension in vsir_program_lower_sm4_sincos().
For example, in the final test from trigonometry.shader_test, we have:

    sincos r1.x <v4:float>, null <float>, l(3.00000000e+01) <s:float>

which currently gets turned into

    mov sr0.xyzw <v4:float>, l(3.00000000e+01) <s:float>
    sin r1.x <v4:float>, sr0.xyzw <v4:float>

That doesn't seem ideal, and should possibly be rejected by the
validator, but ends up working out well enough for the SPIR-V backend.
It's a bit more problematic to deal with for the GLSL backend.
2025-06-26 16:02:38 +02:00
Francisco Casas
96cd4cc954 vkd3d-shader/ir: Avoid a compiler warning in vsir_block_list_init().
The following warning appears during compilation with
gcc 15.1.1 20250425:

  In function 'vsir_block_list_init',
      inlined from 'vsir_block_init' at vkd3d/libs/vkd3d-shader/ir.c:3821:5,
      inlined from 'vsir_cfg_init' at vkd3d/libs/vkd3d-shader/ir.c:4285:28:
  vkd3d/libs/vkd3d-shader/ir.c:3758:5: warning: 'memset' writing 24 bytes into a region of size 0 overflows the destination [-Wstringop-overflow=]
   3758 |     memset(list, 0, sizeof(*list));
        |     ^
  In function 'vsir_cfg_init':
  lto1: note: destination object is likely at address zero

looking at the code in vsir_cfg_init() this seems like an spurious
warning. Looking on the internet, these bogus warnings with memset()
seem to be a common occurrence.

memset() is replaced with a zero value assignment to avoid this.
2025-06-26 15:56:43 +02:00
Francisco Casas
3376015d88 vkd3d-shader/hlsl: Update the enum hlsl_sampler_dim comment. 2025-06-26 15:55:58 +02:00
Giovanni Mascellani
3c469edc8e vkd3d-shader/ir: Validate GEU instructions. 2025-06-25 16:53:19 +02:00
Giovanni Mascellani
e267ea9551 vkd3d-shader/ir: Validate GEO instructions. 2025-06-25 16:52:28 +02:00
Giovanni Mascellani
8feeb07900 vkd3d-shader/ir: Validate FREM instructions. 2025-06-25 16:51:58 +02:00
Giovanni Mascellani
32cab7c81e vkd3d-shader/ir: Validate FRC instructions. 2025-06-25 16:51:02 +02:00
Giovanni Mascellani
afec7cc96b vkd3d-shader/ir: Validate EXP instructions. 2025-06-25 16:50:03 +02:00
Giovanni Mascellani
8cf7a12502 vkd3d-shader/ir: Validate EQU instructions. 2025-06-25 16:48:45 +02:00
Giovanni Mascellani
a6e6e36994 vkd3d-shader/ir: Validate DEQO instructions. 2025-06-25 16:47:52 +02:00
Giovanni Mascellani
17b0e0d1d9 vkd3d-shader/ir: Validate EQO instructions. 2025-06-25 16:46:59 +02:00
Giovanni Mascellani
596f02210d vkd3d-shader/ir: Lower UDIV to UDIV_SIMPLE and UREM. 2025-06-25 16:44:00 +02:00
Giovanni Mascellani
82ef9bf2e5 vkd3d-shader/ir: Introduce VSIR_OP_UREM.
It is meant to compute the unsigned integer remainder.
2025-06-25 16:43:34 +02:00
Giovanni Mascellani
78e0f8412d vkd3d-shader/ir: Introduce VSIR_OP_UDIV_SIMPLE.
It is meant to compute the unsigned integer division, without
computing the modulo at the same time.
2025-06-25 16:40:43 +02:00
Giovanni Mascellani
ada09d003d vkd3d-shader/ir: Repurpose IDIV to compute plain signed division.
It doesn't compute signed remainder any more.
2025-06-25 16:39:50 +02:00
Giovanni Mascellani
823a8724de vkd3d-shader/ir: Introduce VSIR_OP_IREM.
It is meant to compute the signed integer remainder.
2025-06-25 16:38:38 +02:00
Evan Tang
f4a4e2afec vkd3d: Replace the resource count field of struct d3d12_heap with an internal refcount.
When a heap was released at the same time as the last resource on that
heap, it was possible for both to see each other's
refcount/resource_count as 0 and both would try to destroy the heap.

Avoid that by converting "resource_count" to an internal refcount, which
holds an extra +1 if the main refcount is nonzero. The final release
will then be synchronized between the two since both will operate on
"internal_refcount".
2025-06-25 16:06:49 +02:00
Henri Verbeet
752a48f4ac vkd3d-shader/msl: Implement VSIR_OP_IMAX. 2025-06-25 16:00:34 +02:00
Henri Verbeet
543ee120fc vkd3d-shader/msl: Implement VSIR_OP_DSX_FINE and VSIR_OP_DSY_FINE. 2025-06-25 16:00:31 +02:00
Henri Verbeet
b9ce945e61 vkd3d-shader/msl: Implement VSIR_OP_DSX_COARSE and VSIR_OP_DSY_COARSE. 2025-06-25 16:00:27 +02:00
Henri Verbeet
06a0453762 vkd3d-shader/msl: Implement VSIR_OP_DSX and VSIR_OP_DSY. 2025-06-25 16:00:22 +02:00
Henri Verbeet
cdfaeb209a vkd3d-shader/msl: Implement VSIR_OP_CONTINUE. 2025-06-25 16:00:15 +02:00
Henri Verbeet
d219cccc99 vkd3d-shader/ir: Rename the VKD3DSIH_* enum elements to VSIR_OP_*. 2025-06-25 15:53:41 +02:00
Elizabeth Figura
cd43ab1ca2 vkd3d-shader/ir: Allow bitwise operations on VKD3D_DATA_INT. 2025-06-25 15:46:39 +02:00
Elizabeth Figura
bcb2acbdab vkd3d-shader/hlsl: Set the destination data type to UINT in sm4_generate_vsir_cast_from_bool().
Validation checks that the source and destination types are both integer.
2025-06-25 15:46:27 +02:00
Elizabeth Figura
a1eb53df3c vkd3d-shader/hlsl: Set the data type in sm4_generate_vsir_reg_from_deref(). 2025-06-25 15:43:15 +02:00
Elizabeth Figura
ecb19b33ba vkd3d-shader/hlsl: Output sm1 semantics with unique register_index values.
Match the register_index values from the d3dbc reader.
2025-06-25 15:43:15 +02:00
Elizabeth Figura
41cacba5ce vkd3d-shader/hlsl: Convert descriptor registers to pre-5.1 form in the TPF writer.
Rather than in the HLSL writer. This way we output vsir consistent with the vsir
we read, and the vsir that the backends expect [bringing us one step closer to
being able to feed the HLSL frontend directly into the individual backends.]
2025-06-25 15:42:51 +02:00
Giovanni Mascellani
3a4f95aca6 vkd3d-shader/ir: Do not crash when registers cannot be resolved to signature elements. 2025-06-25 15:40:12 +02:00
Elizabeth Figura
5452e79a19 vkd3d-shader/d3d-asm: Handle INT_MIN in shader_print_int_literal(). 2025-06-24 15:51:31 +02:00
Henri Verbeet
c2a01fff1e vkd3d-shader/msl: Implement support for static texel offsets in msl_sample(). 2025-06-24 15:32:59 +02:00
Henri Verbeet
6f8ce6df72 vkd3d-shader/msl: Implement VKD3DSIH_GATHER4_PO. 2025-06-24 15:32:59 +02:00
Henri Verbeet
449804623a vkd3d-shader/msl: Implement VKD3DSIH_GATHER4_C. 2025-06-24 15:32:59 +02:00
Henri Verbeet
841cf65a41 vkd3d-shader/msl: Implement VKD3DSIH_GATHER4. 2025-06-24 15:32:59 +02:00
Henri Verbeet
3cc404759d vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_LOD. 2025-06-24 15:32:59 +02:00
Giovanni Mascellani
99db7270f0 vkd3d-shader/ir: Validate DSY_FINE instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
cbd508fce6 vkd3d-shader/ir: Validate DSY_COARSE instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
7acebfc978 vkd3d-shader/ir: Validate DSY instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
6bf25800c2 vkd3d-shader/ir: Validate DSX_FINE instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
95e095992d vkd3d-shader/ir: Validate DSX_COARSE instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
96bb2953cc vkd3d-shader/ir: Validate DSX instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
ad320776a1 vkd3d-shader/ir: Validate DRCP instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
19c2734d31 vkd3d-shader/ir: Validate DNE instructions. 2025-06-24 15:31:39 +02:00
Giovanni Mascellani
bcaa1d50b0 vkd3d-shader/ir: Validate data types for destination shifts. 2025-06-24 15:28:00 +02:00
Giovanni Mascellani
1862c28b90 vkd3d-shader/ir: Validate data types for SATURATE destination modifiers. 2025-06-24 15:27:48 +02:00
Giovanni Mascellani
318d7466a8 vkd3d-shader/ir: Validate data types for NOT source modifiers. 2025-06-24 15:27:38 +02:00
Giovanni Mascellani
65c23999e8 vkd3d-shader/ir: Validate data types for ABSNEG source modifiers. 2025-06-24 15:27:29 +02:00
Giovanni Mascellani
0252e2e660 vkd3d-shader/ir: Validate data types for ABS source modifiers. 2025-06-24 15:27:02 +02:00
Henri Verbeet
85dcbf7a51 demos/teapot: Add on-screen help. 2025-06-24 15:24:16 +02:00
Giovanni Mascellani
31581b0002 vkd3d-shader/ir: Lower IMUL and UMUL to IMUL_LOW. 2025-06-24 15:21:13 +02:00
Giovanni Mascellani
4a39db797b vkd3d-shader/ir: Introduce VKD3DSIH_IMUL_LOW.
It is meant to compute the lower word of an integer multiplication.
2025-06-24 15:15:56 +02:00
Shaun Ren
f3dec58423 vkd3d-shader/hlsl: Ignore the 'groupshared' modifier for non-compute shaders. 2025-06-24 14:54:25 +02:00
Shaun Ren
4ede2f1365 vkd3d-shader/hlsl: Allow memory barriers in SM4+ target profiles. 2025-06-24 14:51:34 +02:00
Shaun Ren
84a0a8ae86 vkd3d-shader/hlsl: Handle nodes with NULL data types in hlsl_replace_node(). 2025-06-24 14:50:43 +02:00
Shaun Ren
3bf232e841 vkd3d-shader/hlsl: Only dump store writemasks for single register types.
This fixes a segfault on matrix stores in dump_ir_store().
2025-06-24 14:50:21 +02:00
Conor McCarthy
d8edf20c2b vkd3d-shader/dxil: Convert constant buffer minimum-precision source registers. 2025-06-23 20:12:31 +02:00
Conor McCarthy
dda2ec1814 vkd3d-shader/ir: Allow constant buffer loads to have a minimum precision.
DXIL constant buffer loads can have precision modifiers.
2025-06-23 20:07:53 +02:00
Shaun Ren
b8cbe03308 vkd3d-shader/hlsl: Remove a leftover TODO message.
The max output size check for stream outputs is done via
validate_max_output_size().
2025-06-23 18:29:27 +02:00
Nikolay Sivov
ba5d5a8091 vkd3d-shader/fx: Fix the order of the "MaterialDiffuse" and "MaterialAmbient" state entries.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:28:41 +02:00
Nikolay Sivov
92c711a7d5 vkd3d-shader/fx: Add a format-specific callback to write state assignments.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:27:11 +02:00
Nikolay Sivov
3537feb45c vkd3d-shader/fx: Move entry count updates out of the state block writing helper.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:17:48 +02:00
Nikolay Sivov
43a29044d6 vkd3d-shader/fx: Move state decomposition to the fx_4_0-specific writing path.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:16:17 +02:00
Nikolay Sivov
9f9cf59b6e vkd3d-shader/fx: Use the same state data helpers for both fx_2_0 and fx_4+.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:12:27 +02:00
Nikolay Sivov
99d61aeb89 vkd3d-shader/fx: Use a version-independent structure for states.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-23 18:12:27 +02:00
Giovanni Mascellani
f6af47f9b6 vkd3d-shader/ir: Validate data types for DW source modifiers. 2025-06-23 18:11:22 +02:00
Giovanni Mascellani
bc4dda75dd vkd3d-shader/ir: Validate data types for DZ source modifiers. 2025-06-23 18:11:12 +02:00
Giovanni Mascellani
6ef23544f4 vkd3d-shader/ir: Validate data types for X2NEG source modifiers. 2025-06-23 18:11:01 +02:00
Giovanni Mascellani
2d783da3a7 vkd3d-shader/ir: Validate data types for X2 source modifiers. 2025-06-23 18:10:50 +02:00
Giovanni Mascellani
eec2b13dc6 vkd3d-shader/ir: Validate data types for COMP source modifiers. 2025-06-23 18:10:25 +02:00
Giovanni Mascellani
a115cd9ec0 vkd3d-shader/ir: Validate DMUL instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
402c2bf10a vkd3d-shader/ir: Validate DMOV instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
32746c664d vkd3d-shader/ir: Validate DMIN instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
2f4038bae7 vkd3d-shader/ir: Validate DMAX instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
bd4681622d vkd3d-shader/ir: Validate DLT instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
dc33622919 vkd3d-shader/ir: Validate DIV instructions. 2025-06-23 18:07:09 +02:00
Giovanni Mascellani
666eb98ab6 vkd3d-shader/ir: Validate DGEO instructions. 2025-06-23 18:06:20 +02:00
Giovanni Mascellani
227df56c6c vkd3d-shader/ir: Validate DFMA instructions. 2025-06-23 18:00:55 +02:00
Giovanni Mascellani
2b922e6b8e vkd3d-shader/ir: Validate DDIV instructions. 2025-06-23 18:00:55 +02:00
Giovanni Mascellani
ead690a17a vkd3d-shader/ir: Validate DADD instructions. 2025-06-23 18:00:55 +02:00
Henri Verbeet
be2c8041d0 vkd3d-shader/d3dbc: Use TAG_CTAB in d3dbc_compile(). 2025-06-23 18:00:34 +02:00
Henri Verbeet
e5bf48a2ba vkd3d-shader/spirv: Do not require VKD3D_SHADER_BINDING_FLAG_IMAGE for sampler descriptors. 2025-06-23 18:00:10 +02:00
Francisco Casas
83979ec07a tests/hlsl: Fix up point-sprite.shader_test.
Write the shaders so that texcoord's register index in the vertex output
signature matches the register index in the pixel input signature
(o0 and v0 in this case) in SM4.
2025-06-23 17:59:20 +02:00
Francisco Casas
2e0cbff3a0 vkd3d-shader/hlsl: Allocate return variables before other outputs.
point-sprite.shader_test is not technically well formed since, in SM4,
the vertex output signature should be:

// Output signature:
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// sv_position              0   xyzw        0      POS   float   xyzw
// texcoord                 0   xy          1     NONE   float   xy

and the pixel input signature should be:

// Input signature:
// Name                 Index   Mask Register SysValue  Format   Used
// -------------------- ----- ------ -------- -------- ------- ------
// texcoord                 0   xy          0     NONE   float   xy

so we are not passing "texcoord" properly to the pixel shader, even on
Windows.
2025-06-23 17:56:40 +02:00
Francisco Casas
e0359c5299 tests/hlsl: Test the allocation order of return semantics. 2025-06-23 17:53:03 +02:00
Francisco Casas
cf726cf521 tests/shader_runner_d3d12: Handle the "bug" qualifier on state creation failure. 2025-06-23 17:50:37 +02:00
Henri Verbeet
46265061c3 vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_GRAD. 2025-06-23 17:48:07 +02:00
Henri Verbeet
db89687807 vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_C_LZ 2025-06-23 17:48:07 +02:00
Henri Verbeet
f30510a9b3 vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_C. 2025-06-23 17:48:07 +02:00
Henri Verbeet
0c8bc0f42c vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE_B. 2025-06-23 17:48:07 +02:00
Henri Verbeet
af8b3f94e7 vkd3d-shader/msl: Implement VKD3DSIH_SAMPLE. 2025-06-23 17:48:07 +02:00
Elizabeth Figura
d5237ec1cc vkd3d-shader/hlsl: Output SSA registers where possible. 2025-06-23 17:44:11 +02:00
Elizabeth Figura
288020bce8 vkd3d-shader/ir: Allocate SSA registers to temps. 2025-06-23 17:39:12 +02:00
Elizabeth Figura
7b9d04fff8 vkd3d-shader/ir: Track liveness in the SSA allocator. 2025-06-23 17:34:28 +02:00
Elizabeth Figura
5e4c61eba6 vkd3d-shader/ir: Introduce a stub SSA to temp allocation pass. 2025-06-23 17:32:59 +02:00
Elizabeth Figura
34dbd60e01 vkd3d-shader/hlsl: Add a register type field to struct hlsl_reg.
This will be used for temps. After moving temp allocation to vsir, some of these
will be VKD3DSPR_SSA, and some will not.
2025-06-23 17:28:40 +02:00
Conor McCarthy
9d490b83d4 vkd3d-shader/dxil: Add a null check for the type when validating non-void operands. 2025-06-19 20:45:28 +02:00
Conor McCarthy
c3110d2f94 vkd3d-shader/dxil: Check the destination value is invalid after calling a void function handler. 2025-06-19 20:45:28 +02:00
Conor McCarthy
a410c448ce vkd3d-shader/dxil: Validate the function return type after calling the handler.
The handler writes the destination value.
2025-06-19 20:44:54 +02:00
Nikolay Sivov
f135f7fe07 vkd3d-shader/hlsl: Add a stub for the noise() intrinsic.
This function is used in tx_1_0 code, but is also supported in
fx_2_0 and fx_4_0 expressions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-19 20:36:27 +02:00
Giovanni Mascellani
93e1a8c784 vkd3d-shader/ir: Lower tpf SINCOS to the new COS and SIN instructions. 2025-06-19 20:33:09 +02:00
Giovanni Mascellani
37c2f709d1 vkd3d-shader/ir: Lower d3dbc SINCOS to the new COS and SIN instructions. 2025-06-19 20:32:55 +02:00
Giovanni Mascellani
6f092fb84a vkd3d-shader/ir: Introduce opcode SIN.
It is meant to compute sine.
2025-06-19 20:32:50 +02:00
Giovanni Mascellani
322f2e5496 vkd3d-shader/ir: Introduce opcode COS.
It is meant to compute cosine, and gradually replace SINCOS, at
least from a certain point in the pipeline on.
2025-06-19 20:32:41 +02:00
Giovanni Mascellani
b7fbd3c0f0 vkd3d-shader/ir: Validate data types for SIGNNEG source modifiers. 2025-06-19 20:11:41 +02:00
Giovanni Mascellani
3689d3076c vkd3d-shader/ir: Validate data types for SIGN source modifiers. 2025-06-19 20:10:21 +02:00
Giovanni Mascellani
e1ca552173 vkd3d-shader/ir: Validate data types for BIASNEG source modifiers. 2025-06-19 20:08:52 +02:00
Giovanni Mascellani
b2e1c3b90a vkd3d-shader/ir: Validate data types for BIAS source modifiers. 2025-06-19 20:06:35 +02:00
Giovanni Mascellani
eb3383b04e vkd3d-shader/ir: Validate data types for NEG source modifiers. 2025-06-19 20:03:17 +02:00
Giovanni Mascellani
46fac7f264 tests: Add a test for the partial precision destination modifier. 2025-06-19 19:48:56 +02:00
Giovanni Mascellani
4da83fe83b vkd3d-shader/ir: Validate ATAN instructions. 2025-06-19 19:28:42 +02:00
Giovanni Mascellani
813021e60b vkd3d-shader/ir: Validate ASIN instructions. 2025-06-19 19:28:42 +02:00
Giovanni Mascellani
16e142465c vkd3d-shader/ir: Validate AND instructions. 2025-06-19 19:28:41 +02:00
Giovanni Mascellani
0edd654c9e vkd3d-shader/ir: Validate ADD instructions. 2025-06-19 19:24:36 +02:00
Giovanni Mascellani
475e16b87f vkd3d-shader/ir: Validate ACOS instructions. 2025-06-19 19:24:36 +02:00
Giovanni Mascellani
65e896fd60 vkd3d-shader/ir: Validate ABS instructions. 2025-06-19 19:24:06 +02:00
Henri Verbeet
5911e410a8 demos/teapot: Add a tessellation demo. 2025-06-18 15:51:11 +02:00
Henri Verbeet
d572f4ac1f vkd3d: Use the DXBC checksum to construct a shader source name. 2025-06-18 15:50:18 +02:00
Henri Verbeet
cef3e07e3d vkd3d-shader/spirv: Emit an OpSource instruction with the source name. 2025-06-18 15:50:18 +02:00
Giovanni Mascellani
8b78747629 vkd3d-shader/dxil: Emit 16-bit UNDEFINED and INVALID values as minimum precision registers. 2025-06-18 15:48:55 +02:00
Giovanni Mascellani
b05153e6f9 vkd3d-shader/dxil: Emit 16-bit GROUPSHAREDMEM values as minimum precision registers. 2025-06-18 15:48:55 +02:00
Giovanni Mascellani
39603f4bc2 vkd3d-shader/dxil: Emit 16-bit structured TGSMs as minimum precision. 2025-06-18 15:48:55 +02:00
Giovanni Mascellani
5e1c8056ae vkd3d-shader/dxil: Emit 16-bit raw TGSMs as minimum precision. 2025-06-18 15:48:55 +02:00
Giovanni Mascellani
7c0da1747a vkd3d-shader/dxil: Allow constant zero values to be floating point.
This fixes commit 59fb3a7893, where
the floating point alternative was mistakenly ignored.
2025-06-16 17:41:20 +02:00
Nikolay Sivov
d08673bad1 vkd3d-shader/d3dbc: Use the actual instruction length in d3dbc_write_instruction().
The current calculation doesn't take indirect addressing into account.
This issue is easy to spot in disassembly, when we don't skip correctly
to the next instruction. On Windows the disassembler does not depend on
this it seems and skips naturally after processing all parameters that
may or may not use indirect addressing.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 17:35:37 +02:00
Nikolay Sivov
7281f4ed39 vkd3d-shader/fx: Add support for tx -> text output.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:19:47 +02:00
Nikolay Sivov
586b2b5a79 vkd3d-shader/fx: Add the "noise" opcode name.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:07:35 +02:00
Nikolay Sivov
e28af05957 vkd3d-shader/fx: Output indirect register access in arguments.
This uses the notation from Wine's d3dx9 effects runtime implementation.
Indirect addressing in fx_4_0 looks pretty much broken - it compiles
to something that produces non-sensical text disassembly and fails
runtime effect creation.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:06:41 +02:00
Nikolay Sivov
3f6013ea27 vkd3d-shader/fx: Output value expressions for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:04:52 +02:00
Nikolay Sivov
ddb433d552 vkd3d-shader/fx: Explicitly check all known state assignment types for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:04:52 +02:00
Nikolay Sivov
590ea03255 vkd3d-shader/fx: Remove the unused fx_4_fxlc_argument type.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-16 16:04:34 +02:00
Giovanni Mascellani
bf92190924 vkd3d-shader/ir: Rename VKD3D_SHADER_ERROR_VSIR_INVALID_HANDLER to VKD3D_SHADER_ERROR_VSIR_INVALID_OPCODE.
Following the way it is currently called in the code.
2025-06-16 16:03:07 +02:00
Henri Verbeet
c3c36d8517 demos: Introduce a helper function to create a projection matrix. 2025-06-16 16:02:23 +02:00
Henri Verbeet
eb988e95e1 vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_alu_instruction(). 2025-06-16 16:01:14 +02:00
Henri Verbeet
f46c8ea03c vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_ext_glsl_instruction(). 2025-06-16 16:01:14 +02:00
Henri Verbeet
81279b763b vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_bitfield_instruction(). 2025-06-16 16:01:14 +02:00
Henri Verbeet
0778fb93df vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_comparison_instruction(). 2025-06-16 16:01:14 +02:00
Henri Verbeet
616fea0c2b vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_deriv_instruction(). 2025-06-16 16:01:14 +02:00
Henri Verbeet
a8ca1f95c5 demos: Map the Win32 A-Z keys to a-z.
Matching what we produce on XCB and macOS.
2025-06-11 20:31:34 +02:00
Henri Verbeet
229f792db6 demos: Print the GPU and platform we're running on. 2025-06-11 20:30:39 +02:00
Henri Verbeet
8eeefc2906 vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_sample(). 2025-06-11 20:28:38 +02:00
Henri Verbeet
d92ef93611 vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_emit_atomic_instruction(). 2025-06-11 20:28:38 +02:00
Henri Verbeet
6aeb168d63 vkd3d-shader/spirv: Use vsir_opcode_get_name() in spirv_compiler_handle_instruction(). 2025-06-11 20:28:38 +02:00
Henri Verbeet
dfb3494600 vkd3d-shader/msl: Use vsir_opcode_get_name() in msl_unhandled(). 2025-06-11 20:28:38 +02:00
Henri Verbeet
a5ff884605 vkd3d-shader/ir: Use vsir_opcode_get_name() in the validator. 2025-06-11 20:28:38 +02:00
Henri Verbeet
9c2643b9f7 vkd3d-shader/msl: Implement VKD3DSIH_LD2DMS. 2025-06-11 20:27:54 +02:00
Henri Verbeet
2d90f51d57 tests/shader_runner_metal: Implement resource copies. 2025-06-11 20:27:54 +02:00
Henri Verbeet
5899d8f54b vkd3d-shader/msl: Implement VKD3DSIH_XOR. 2025-06-11 20:27:54 +02:00
Henri Verbeet
36a999e09f vkd3d-shader/msl: Implement VKD3DSIH_ULT. 2025-06-11 20:27:54 +02:00
Henri Verbeet
6a159a5565 vkd3d-shader/msl: Implement VKD3DSIH_INEG. 2025-06-11 20:27:54 +02:00
Nikolay Sivov
1913f5e6f9 vkd3d-shader/fx: Parse array selector expressions for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 20:09:05 +02:00
Nikolay Sivov
90032acbcf vkd3d-shader/fx: Rename the constant argument helper to be version-neutral.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 20:08:59 +02:00
Nikolay Sivov
d403705de9 vkd3d-shader/fx: Add a helper to print literals.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 20:07:38 +02:00
Nikolay Sivov
b098af3ef8 vkd3d-shader/fx: Use more generic names for the literal constant array.
It's going to be reused for 64-bit floats too.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 20:07:25 +02:00
Nikolay Sivov
f525399545 vkd3d-shader/fx: Read instruction arguments in full before printing them.
The binary format stores destination argument after sources. Each
argument takes either 3 tokens or 5 tokens, when indexed. For simplicity
read them all first, and print destination first.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 20:04:27 +02:00
Nikolay Sivov
d6a4084321 vkd3d-shader/fx: Use a version-neutral name for the opcode table.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 18:25:42 +02:00
Nikolay Sivov
47b9316a86 vkd3d-shader/fx: Give fxlvm-specific constants a version-neutral name.
Those are reusable for fx_2_0 preshaders.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-11 18:21:30 +02:00
Giovanni Mascellani
94cbb333f8 vkd3d-shader/dxil: Emit 16-bit ICB values as minimum precision registers. 2025-06-11 18:20:23 +02:00
Giovanni Mascellani
0b5a96d963 vkd3d-shader/dxil: Emit 16-bit SSA values as minimum precision registers. 2025-06-11 18:20:23 +02:00
Giovanni Mascellani
73940cde73 vkd3d-shader/dxil: Emit 16-bit IDXTEMP values as minimum precision registers. 2025-06-11 18:20:23 +02:00
Giovanni Mascellani
5e86d5c21b vkd3d-shader/dxil: Emit 16-bit arrays as minimum precision types.
The type is not explicitly annotated as minimum precision, because
no backend currently cares about that bit anyway. We're still
relying on the fact that in SM 6.0 16-bit types are always
understood as minimum precision.
2025-06-11 18:20:20 +02:00
Giovanni Mascellani
1d780e1a6b vkd3d-shader/dxil: Emit 16-bit CONSTANT values as minimum precision registers. 2025-06-11 18:10:12 +02:00
Henri Verbeet
14477b1066 demos: Allow Vulkan to determine the swapchain image count.
We currently always use 3. That's not a bad choice, but doesn't take the
minImageCount/maxImageCount of the Vulkan implementation into account.
2025-06-10 17:51:15 +02:00
Henri Verbeet
cea7b4e920 tests/shader_runner: Introduce the "f32" probe format. 2025-06-10 17:49:13 +02:00
Henri Verbeet
9c987e5a0b tests/shader_runner: Introduce the "u32" probe format. 2025-06-10 17:48:19 +02:00
Henri Verbeet
95cf0a8b2c tests/shader_runner: Introduce the "i32" probe format. 2025-06-10 17:47:32 +02:00
Henri Verbeet
73820756d1 tests/shader_runner: Introduce the "f64" probe format. 2025-06-10 17:46:51 +02:00
Henri Verbeet
b09e9159ba tests/shader_runner: Introduce the "u64" probe format. 2025-06-10 17:46:51 +02:00
Henri Verbeet
261cdb0f29 tests/shader_runner: Rename the "ri64" probe format to "i64". 2025-06-10 17:46:51 +02:00
Henri Verbeet
7dfa9e8f81 vkd3d-shader/msl: Implement VKD3DSIH_DISCARD. 2025-06-10 17:45:06 +02:00
Henri Verbeet
f538085e41 vkd3d-shader/msl: Implement switches. 2025-06-10 17:45:06 +02:00
Henri Verbeet
79be1d3051 vkd3d-shader/msl: Implement loops. 2025-06-10 17:45:06 +02:00
Henri Verbeet
a570932b82 vkd3d-shader/msl: Implement VKD3DSIH_IMUL. 2025-06-10 17:45:06 +02:00
Henri Verbeet
a2eb3324d4 vkd3d-shader/msl: Implement VKD3DSIH_ILT. 2025-06-10 17:45:06 +02:00
Henri Verbeet
83ed825e5a vkd3d-shader/ir: Use vsir_opcode_get_name() in vsir_program_lower_instructions(). 2025-06-10 17:44:18 +02:00
Henri Verbeet
c8e6d35e17 vkd3d-shader/glsl: Use vsir_opcode_get_name() in shader_glsl_unhandled(). 2025-06-10 17:44:18 +02:00
Henri Verbeet
66c0530a05 vkd3d-shader/d3dbc: Use vsir_opcode_get_name() in d3dbc_write_vsir_instruction(). 2025-06-10 17:44:18 +02:00
Henri Verbeet
6a06929f6b vkd3d-shader/d3dbc: Use vsir_opcode_get_name() in shader_sm1_get_opcode_info_from_vsir_instruction(). 2025-06-10 17:44:18 +02:00
Henri Verbeet
1214359022 vkd3d-shader/ir: Introduce vsir_opcode_get_name(). 2025-06-10 17:44:18 +02:00
Giovanni Mascellani
1b389f29c5 vkd3d-shader/dxil: Remove field "reg" from struct sm6_value.
The VSIR register is now always generated dynamically and we
don't have to carry it around.
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
20d8ba7f8d vkd3d-shader/dxil: Introduce sm6_value_get_constant_float().
Similarly to sm6_value_get_constant_uint() and
sm6_value_get_constant_uint64().
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
873043226c vkd3d-shader/dxil: Rewrite sm6_parser_init_ssa_value() in terms of the SM6 value.
Instead of using the VSIR register.
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
59fb3a7893 vkd3d-shader/dxil: Rewrite sm6_value_is_constant_zero() in terms of the SM6 value.
Instead of using the VSIR register.
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
31e4cbba2e vkd3d-shader/dxil: Rewrite sm6_value_get_constant_uint64() in terms of the SM6 value.
Instead of using the VSIR register.
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
2e3f99e61e vkd3d-shader/dxil: Rewrite sm6_value_get_constant_uint() in terms of the SM6 value.
Instead of using the VSIR register.
2025-06-10 17:40:17 +02:00
Giovanni Mascellani
f4f2617584 vkd3d-shader/dxil: Rewrite sm6_value_is_ssa() in terms of the value type. 2025-06-10 17:40:17 +02:00
Giovanni Mascellani
361ecd6cf5 vkd3d-shader/dxil: Rewrite sm6_value_is_undef() in terms of the value type. 2025-06-10 17:40:17 +02:00
Giovanni Mascellani
0ac20b3029 vkd3d-shader/dxil: Rewrite sm6_value_is_constant() in terms of the value type. 2025-06-10 17:40:17 +02:00
Nikolay Sivov
fcb5650dbf vkd3d-shader/fx: Use a separate table for sampler states in fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-10 17:39:30 +02:00
Nikolay Sivov
b22ebe73bc vkd3d-shader/fx: Do not print padding bytes of fx_2_0 strings. 2025-06-10 17:39:18 +02:00
Nikolay Sivov
8aacee8eae vkd3d-shader/fx: Add a few missing fxlc opcode names.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-10 17:34:41 +02:00
Giovanni Mascellani
8da518f2cd tests: Fix the shader model requirements for a ps_5_0 shader.
In practice this is irrelevant, but better get our tests
consistent.
2025-06-09 16:22:19 +02:00
Giovanni Mascellani
45ef9fdbe8 tests: Add a test about discontiguous input swizzles in bytecode format. 2025-06-09 16:22:19 +02:00
Henri Verbeet
d881356ab2 vkd3d-shader/msl: Implement VKD3DSIH_IGE. 2025-06-09 16:20:53 +02:00
Henri Verbeet
3673b65485 vkd3d-shader/msl: Implement VKD3DSIH_IADD. 2025-06-09 16:20:53 +02:00
Henri Verbeet
cc33439f19 vkd3d-shader/msl: Implement VKD3DSIH_EQO. 2025-06-09 16:20:53 +02:00
Henri Verbeet
fc6249a228 vkd3d-shader/msl: Implement support for VKD3DSPR_SAMPLEMASK registers. 2025-06-09 16:20:53 +02:00
Henri Verbeet
ea5cf883fa vkd3d-shader/msl: Implement support for VKD3DSPR_IDXTEMP registers. 2025-06-09 16:20:53 +02:00
Francisco Casas
66d0c2a426 tests/d3d12: Avoid out-of-bounds access when evaluating ok() args (ubsan).
Compiling and running with UBSan reported the following errors:

tests/d3d12.c:31063:5: runtime error: index 4 out of bounds for type 'float [4][8]'
tests/d3d12.c:31063:5: runtime error: index 8 out of bounds for type 'float [8]'
tests/d3d12.c:31063:5: runtime error: load of address 0x557ee85a1500 with insufficient space for an object of type 'const float'
tests/d3d12.c:31248:5: runtime error: index 4 out of bounds for type 'float [4][4]'
tests/d3d12.c:31248:5: runtime error: index 4 out of bounds for type 'float [4]'
tests/d3d12.c:31248:5: runtime error: load of address 0x557ee85a10d0 with insufficient space for an object of type 'const float'
2025-06-09 16:09:22 +02:00
Giovanni Mascellani
d65be3d0c5 tests: Skip test_graphics_compute_queue_synchronization() on paravirtualized MoltenVK.
This used to work when the macOS runner had a Sonoma host system.
Now it has Sequoia, even if the guest is still Sonoma, and the
test crashes with:

    [mvk-error] VK_TIMEOUT: MTLCommandBuffer "vkQueueSubmit MTLCommandBuffer on Queue 3-0" execution failed (code 2): Caused GPU Hang Error (00000003:kIOGPUCommandBufferCallbackErrorHang)
    vkd3d:56072:err:vkd3d_wait_for_gpu_timeline_semaphore Failed to wait for Vulkan timeline semaphore, vr -4.

Upgrading MoltenVK or the guest to Sequoia doesn't seem to help.
I haven't investigated the problem, but my experience is that
the paravirtualized Metal driver has a number of problems.
2025-06-05 16:50:15 +02:00
Giovanni Mascellani
7e134f85a4 vkd3d-shader/dxil: Do not set the value type in sm6_parser_function_init().
It is rewritten in all branches that produce a value.

VALUE_TYPE_REG is therefore never set and can be retired at last.
2025-06-05 16:05:09 +02:00
Giovanni Mascellani
0e406cf0a8 vkd3d-shader/dxil: Do not set the value type in sm6_parser_declare_global().
It is rewritten in all branches.
2025-06-05 16:05:09 +02:00
Giovanni Mascellani
00b3fb96d9 vkd3d-shader/dxil: Store a SM6 value in sm6_phi.
Rather than a VSIR register.
2025-06-05 16:05:09 +02:00
Giovanni Mascellani
a9a3100cca vkd3d-shader/dxil: Represent non uniformness in the SM6 value. 2025-06-05 16:05:09 +02:00
Giovanni Mascellani
af5e5fe31b vkd3d-shader/dxil: Generate specialized values in sm6_parser_emit_cast() for trivial casts.
There is currently no need to make a special case for 16-bit
values, since the SPIR-V backend currently confuses them with
32-bit values. The generated VSIR code is not correct, but that
will have to be handled at a different level.
2025-06-05 16:05:09 +02:00
Elizabeth Figura
5e6def0843 vkd3d-shader/preproc: Store EOF state per buffer.
We may immediately push a new file or expansion.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=43481
2025-06-05 16:04:02 +02:00
Elizabeth Figura
d768ea6709 vkd3d-shader/preproc: Swap to the INITIAL state after ending a buffer. 2025-06-05 16:04:02 +02:00
Elizabeth Figura
0eb5fee633 vkd3d-shader/preproc: Parse comments in #include and #line directives. 2025-06-05 16:04:02 +02:00
Henri Verbeet
5ea697b8eb vkd3d-shader/msl: Handle SV_SAMPLE_INDEX inputs. 2025-06-05 15:58:44 +02:00
Henri Verbeet
34d8be3b2e tests/shader_runner_metal: Set the pipeline sample count in metal_runner_draw(). 2025-06-05 15:58:44 +02:00
Henri Verbeet
a8defb4e21 tests/shader_runner_metal: Implement multi-sample readback. 2025-06-05 15:58:44 +02:00
Henri Verbeet
1cdfed919a vkd3d-shader/msl: Simplify SV_DEPTH handling. 2025-06-05 15:58:44 +02:00
Henri Verbeet
cf312e14a9 vkd3d-shader/msl: Handle SV_VERTEX_ID inputs. 2025-06-05 15:58:44 +02:00
Henri Verbeet
e948098ae3 vkd3d-shader/msl: Handle SV_POSITION inputs. 2025-06-05 15:58:44 +02:00
Henri Verbeet
f14a0dfe07 vkd3d-shader/msl: Implement support for indirect constant buffer addressing. 2025-06-05 15:58:01 +02:00
Henri Verbeet
0b829db149 vkd3d-shader/msl: Continue when the SRV descriptor binding isn't specified in msl_ld().
Mostly to aid debugging.
2025-06-05 15:55:01 +02:00
Henri Verbeet
fadcbf3eeb vkd3d-shader/msl: Slightly improve the error messages for unspecified descriptor bindings.
This also makes them consistent with the ones used by the GLSL backend.
2025-06-05 15:55:01 +02:00
Henri Verbeet
6a93c503cd vkd3d-shader/msl: Get rid of the "lod" field of struct msl_resource_type_info.
1D read() is specified to support a level/lod parameter. The MSL
specification claims it needs to be 0 because "mipmaps are not supported
for 1D textures", but that restriction isn't documented for the
"mipmapLevelCount" property of MTLTextureDescriptor. Other APIs do
supported mipmapped 1D textures. Multi-sample textures aren't supported
by msl_ld(), so we don't need to worry about them.
2025-06-05 15:55:01 +02:00
Henri Verbeet
02d7d6038d vkd3d-shader/msl: Reject cube and multi-sample texel fetches in msl_ld().
The cube variants are simply disallowed in Direct3D, and currently
mishandled by msl_ld(). It's less clear whether multi-sample fetches
should be allowed, and how they're supposed to behave if they are,
although typically the "ld2dms" instruction would be used for those.
They're not supported on the MSL side either way.
2025-06-05 15:55:01 +02:00
Henri Verbeet
671fbfea7d vkd3d-shader/msl: Ensure we have a non-NULL "resource_type_info" pointer in msl_ld().
Since we're going to dereference it.
2025-06-05 15:55:01 +02:00
Giovanni Mascellani
87fe08fe0e tests/hlsl: Test TGSMs with minimum precision unsigned integers. 2025-06-05 15:50:23 +02:00
Giovanni Mascellani
1d77d51ca4 tests/hlsl: Test some quirks of TGSMs with SM < 5.0.
I'm not specifically interested in that, but since I ran into
those idiosyncrasies while writing other TGSM tests I decided that
it might turn out useful to keep them.
2025-06-05 15:50:04 +02:00
Giovanni Mascellani
bda2be3423 vkd3d-shader/hlsl: Reject programs with group shared variables.
Currently the modifier is ignored and the program is miscompiled.
2025-06-05 15:50:04 +02:00
Giovanni Mascellani
0236308866 tests/hlsl: Test minimum precision IDXTEMP registers. 2025-06-05 15:50:01 +02:00
Giovanni Mascellani
f1b36edc07 ci: Enable testing with DXC again on macOS.
This was disabled by commit 653e4f47ac.
2025-06-04 13:07:17 +02:00
Giovanni Mascellani
a4c727ac40 tests: Mark some tests in calculate-lod.shader_test as buggy on MoltenVK < 1.2.11. 2025-06-04 13:04:53 +02:00
Giovanni Mascellani
c82d1aac4d tests: Mark some tests in arithmetic-int-uniform.shader_test as buggy on MoltenVK < 1.2.11.
The bug is already solved on recent MoltenVK versions, but the CI
is stuck with 1.2.9, so it's useful to filter these failures out.
2025-06-04 13:04:53 +02:00
Giovanni Mascellani
7f04060f33 vkd3d-shader/dxil: Handle 16-bit values uniformly in sm6_map_cast_op().
This makes the logic more transparent, and it eases handling
native 16-bit values once they will be supported.
2025-06-04 13:03:57 +02:00
Giovanni Mascellani
b9ce828451 vkd3d-shader/dxil: Validate that floating-point extension casts increase bit width. 2025-06-04 13:01:51 +02:00
Giovanni Mascellani
a91fb0523a vkd3d-shader/dxil: Validate that integer extension casts increase bit width. 2025-06-04 13:01:51 +02:00
Giovanni Mascellani
a90b74baaa vkd3d-shader/dxil: Validate that floating-point truncation casts decrease bit width.
Similarly to the integer case.
2025-06-04 13:01:45 +02:00
Giovanni Mascellani
0e006715d8 vkd3d-shader/dxil: Do not use field "reg" in of sm6_value when writing bitcasts.
It's going to be removed; the generated register data type is the
right thing to look at here.
2025-06-04 12:34:21 +02:00
Elizabeth Figura
9552dab5aa vkd3d-shader: Use the correct union members for raw and structured resources. 2025-06-04 12:10:39 +02:00
Henri Verbeet
85d2703c03 tests/shader_runner: Introduce a "tessellation-shader" cap.
Similar to how we have the "geometry-shader" cap. In principle shader
model 5+ implies support for tessellation shaders, but the Vulkan,
OpenGL, and Metal runners are able to support most of shader model 5+
without the underlying GPU (or API) necessarily supporting tessellation
shaders.
2025-06-04 12:10:10 +02:00
Shaun Ren
2b257caea9 vkd3d-shader/hlsl: Don't optimize semantic register allocations in SM1.
This matches the behaviour of fxc/d3dcompiler.
2025-06-02 20:53:00 +02:00
Nikolay Sivov
b6ef417e71 vkd3d-shader/fx: Handle bool types when parsing fx_2_0 assignment values. 2025-06-02 20:51:38 +02:00
Nikolay Sivov
c895f63a1c vkd3d-shader/fx: Fix a crash in fx -> d3d-asm when named values are not defined. 2025-06-02 20:51:38 +02:00
Nikolay Sivov
108f4fe47e vkd3d-shader/fx: Fix reading the assignment value base type when parsing fx_2_0. 2025-06-02 20:51:33 +02:00
Nikolay Sivov
4e2fefdfdf vkd3d-shader/fx: Use correct array sizes for the fx_2_0 states. 2025-06-02 20:43:44 +02:00
Nikolay Sivov
4ef4baa6bf vkd3d-shader/fx: Fix some typos in fx_2_0 state names. 2025-06-02 20:43:44 +02:00
Nikolay Sivov
68386f5180 vkd3d-shader/fx: Print packoffset() modifiers in fx -> d3d-asm output.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-02 20:43:44 +02:00
Nikolay Sivov
6b2800fa99 vkd3d-shader/fx: Print explicit buffer bind points in fx -> d3d-asm output.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-02 20:43:27 +02:00
Nikolay Sivov
e33189546a vkd3d-shader/fx: Use variable unpacked size when setting buffer sizes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-06-02 20:41:37 +02:00
Giovanni Mascellani
9f0185f304 vkd3d-shader/msl: Support the ABSNEG source modifier. 2025-06-02 20:36:42 +02:00
Giovanni Mascellani
bc0dd891c3 vkd3d-shader/glsl: Support the ABSNEG source modifier. 2025-06-02 20:35:48 +02:00
Giovanni Mascellani
ed60dd5926 tests: Add a test for the ABSNEG source modifier. 2025-06-02 20:33:13 +02:00
Giovanni Mascellani
10be58a74f vkd3d-shader/msl: Ignore the PARTIALPRECISION destination modifier. 2025-06-02 20:33:01 +02:00
Giovanni Mascellani
9f5db1e3e4 vkd3d-shader/glsl: Ignore the PARTIALPRECISION destination modifier. 2025-06-02 20:32:46 +02:00
Giovanni Mascellani
df8b611334 vkd3d-shader/msl: Accept and ignore the REFACTORING_ALLOWED global flag. 2025-06-02 20:32:36 +02:00
Giovanni Mascellani
5998723e7c vkd3d-shader/glsl: Accept and ignore the REFACTORING_ALLOWED global flag. 2025-06-02 20:31:19 +02:00
Giovanni Mascellani
215dfe0450 tests/hlsl: Mark some tests in wave-ops-float.shader_test as buggy on MoltenVK.
I haven't investigated the problem, but since the tests work for
other implementations and MoltenVK is not always perfect it's likely
that the problem is there.
2025-06-02 20:22:58 +02:00
Giovanni Mascellani
0b9268a91b tests/hlsl: Mark some tests in geometry.shader_test as buggy on MoltenVK.
They use geometry shaders, which MoltenVK doesn't support. However
D3D12 has no way to indicate they're unsupported, so the problem
doesn't surface as a failed draw, but rather as a draw that doesn't
do anything.
2025-06-02 20:22:43 +02:00
Giovanni Mascellani
ea4f1dece5 tests/hlsl: Mark a test in entry-point-semantics.shader_test as buggy on MoltenVK with DXIL.
It seems that SPIRV-Cross is generating bad MSL code, and Metal
rejects it.
2025-06-02 20:22:35 +02:00
Giovanni Mascellani
c8b07e9fa6 tests/hlsl: Mark a test in register-reservation-resources.shader_test as todo on MoltenVK with DXIL.
I haven't investigated what's happening.
2025-06-02 20:22:22 +02:00
Giovanni Mascellani
898bc5c4c8 tests/hlsl: Mark a test in sm6-uav-rwtexture.shader_test as todo on MoltenVK.
I haven't investigated what's happening.
2025-06-02 20:22:12 +02:00
Giovanni Mascellani
de8dbdc2cb tests/hlsl: Add a test reading from a minimum precision floating-point array. 2025-06-02 20:18:30 +02:00
Giovanni Mascellani
12da0f9d24 tests/hlsl: Add some more minimum precision floating-point tests. 2025-06-02 20:18:21 +02:00
Giovanni Mascellani
308d3aa676 tests/hlsl: Add a test reading from a minimum precision signed integer array. 2025-06-02 20:18:09 +02:00
Giovanni Mascellani
7f7077a156 tests/hlsl: Use the appropriate RTV format in shader-interstage-interface.shader_test. 2025-06-02 20:18:04 +02:00
Giovanni Mascellani
8106c5a199 tests/hlsl: Test the interstage interface for minimum precision types. 2025-06-02 20:17:56 +02:00
Giovanni Mascellani
752b13b111 tests/hlsl: Test sampling with minimum precision floating-point numbers. 2025-06-02 20:17:48 +02:00
Elizabeth Figura
847c008b49 vkd3d-shader/ir: Split TEX into two separate vsir opcodes.
The two have the same d3dbc opcode, but have different names and different semantics.
2025-06-02 20:13:52 +02:00
Elizabeth Figura
b25362e036 vkd3d-shader/ir: Split TEXCOORD into two separate vsir opcodes.
The two have the same d3dbc opcode, but have different names and different semantics.
2025-06-02 20:12:27 +02:00
Henri Verbeet
618d8e6a4a vkd3d-shader/msl: Make the generated main function static.
We only need to export the entry point.
2025-06-02 20:11:08 +02:00
Henri Verbeet
7929ba9747 vkd3d-shader: Move vkd3d_siv_from_sysval_indexed() to hlsl_codegen.c. 2025-06-02 20:10:46 +02:00
Henri Verbeet
9983d9c4de tests/hlsl: Slightly adjust the bias values in the sample-bias tests.
The expected λ value for the tests in question is about 0.59, which
after linear mipmap interpolation should result in a sampled value of
about 0.41. The quantisation step was added to allow results as high as
0.43, as seen on some implementations.

AMD Radeon Pro Vega 20 on macOS 15.5 returns a sampled value of about
0.39, with both Vulkan/MoltenVK and MSL/Metal. This is not an issue with
the bias calculation; the same behaviour could be reproduced with
SampleLevel(), as used in the sample-level tests, if those tests used
more exciting values for the "level" parameter. It also doesn't appear
to be a general Metal issue; Intel UHD Graphics 630 does return the
expected values on the same setup. Instead, this appears to be a mipmap
interpolation issue on this particular GPU/driver. Mapping the sampled
values for "level" from 0.0 to 1.0, it seems the interpolation factor
used is "saturate(frac(λ) * 1.25 - 0.125)", instead of the normal
"frac(λ)".

Fascinating as that may be, the test here mainly cares about whether the
bias value was applied correctly, and in that regard a sampled value of
0.39 isn't any worse than the 0.43 we already accept. This commit
adjusts the bias value so that the expected sampled value is 0.45, which
makes the accepted error the same on both the positive and negative
side.
2025-06-02 20:08:04 +02:00
Shaun Ren
d5dcf31123 vkd3d-shader/hlsl: Store stream index in struct hlsl_semantic.
In addition, support stream indices in tpf_write_signature().
2025-06-02 19:59:22 +02:00
Shaun Ren
d368d18527 vkd3d-shader/hlsl: Generate vsir instructions for indexed output streams in geometry shaders. 2025-06-02 19:53:25 +02:00
Shaun Ren
7da7ccaf45 vkd3d-shader/hlsl: Emit dcl_stream instructions for SM5 geometry shaders. 2025-06-02 19:53:25 +02:00
Giovanni Mascellani
a743d9ae60 vkd3d-shader/dxil: Remove bitcast helpers.
They are useless, since the source is already a union with the
needed types.
2025-06-02 19:52:25 +02:00
Giovanni Mascellani
0a1e7b5f64 vkd3d-shader/dxil: Generate CONSTANT values in sm6_parser_constants_init() for null scalars. 2025-06-02 19:52:25 +02:00
Giovanni Mascellani
79ec2fe9f2 vkd3d-shader/dxil: Generate specialized values in sm6_parser_constants_init() for casts.
Depending on the casted operand, the generated values can be
ICB, IDXTEMP or GROUPSHAREDMEM.

The cast decoding code is entirely moved to the second pass, so
that we avoid abusing registers to temporarily store other data.
2025-06-02 19:51:22 +02:00
Giovanni Mascellani
93fb51c899 vkd3d-shader/dxil: Generate CONSTANT values in sm6_parser_constants_init() for floating-point values. 2025-06-02 19:46:23 +02:00
Giovanni Mascellani
d36e37555a vkd3d-shader/dxil: Generate CONSTANT values in sm6_parser_constants_init() for integer values. 2025-06-02 19:46:23 +02:00
Giovanni Mascellani
c050c8be75 vkd3d-shader/dxil: Do not touch the parser current value in instruction_dst_param_init_temp_vector().
The stored value is never read, the caller will overwrite it with
the SSA register generated by the whole DXIL instruction.

Since the helper is always used for UINT instructions, change and
rename it accordingly, so we don't have the problem of finding out
which data type to use.
2025-06-02 19:45:54 +02:00
Nikolay Sivov
87ec2d9897 vkd3d-shader/fx: Fix writing fx_2_0 structure parameters.
Currently structure type descriptions get interleaved with variable
length string data. The solution is to write all fixed length fields
first, then append strings.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-27 20:24:24 +02:00
Giovanni Mascellani
bb50117747 ci: Really use DXC 1.8.2502 for macOS.
In theory commit 7b07d77396 already
did that, but in practice it ended up picking a commit from the
1.8.2405 branch, where a few of our tests fail. Since I hope to
soon enable DXC for macOS again, it's useful to fix that oversight.
2025-05-27 19:44:27 +02:00
Giovanni Mascellani
365f6d3be9 tests/hlsl: Mark some tests in uav-atomics.shader_test as working on MoltenVK. 2025-05-27 19:32:45 +02:00
Giovanni Mascellani
85dcd03642 tests/hlsl: Mark some tests in wave-ops-int.shader_test as buggy on MoltenVK.
It seems that SPIRV-Cross is generating bad MSL code, and Metal
rejects it.
2025-05-27 19:32:35 +02:00
Giovanni Mascellani
9ab1cadaa5 tests/hlsl: Mark some tests in wave-ops-uint.shader_test as buggy on MoltenVK.
It seems that SPIRV-Cross is generating bad MSL code, and Metal
rejects it.
2025-05-27 19:32:19 +02:00
Giovanni Mascellani
6fe0d71ae1 tests/hlsl: Mark a test in gather-offset.shader_test as buggy on MoltenVK with d3d12.
It seems that SPIRV-Cross is generating bad MSL code, and Metal
rejects it.
2025-05-27 19:31:38 +02:00
Giovanni Mascellani
70c51984c9 tests/hlsl: Mark some tests in clip-cull-distance.shader_test as buggy on MoltenVK with d3d12.
They either use geometry shaders or cull distances, which MoltenVK
doesn't support. However d3d12 has no way to indicate they're
unsupported, so the problem doesn't surface as a failed draw,
but rather as a draw that doesn't do anything.
2025-05-27 19:30:21 +02:00
Giovanni Mascellani
7261b40df7 tests/hlsl: Mark a test in object-references.shader_test as todo on MoltenVK with DXIL.
I haven't investigated what's happening in detail. However vkd3d
emits this message, which makes me think the problem is ours:

    vkd3d:62178588:fixme:spirv_compiler_get_descriptor_binding Could not find descriptor binding for type 0, space 0, registers [0:2], shader type 0.
2025-05-27 19:29:56 +02:00
Giovanni Mascellani
e6267dd6b4 tests/hlsl: Do not test for overflowing 16-bit texture sampling.
The behavior is not uniform across drivers; in my tests AMD
performs as expected by the test, but WARP and NVIDIA return
infinity.
2025-05-27 17:45:09 +02:00
Giovanni Mascellani
bd1b737e4e tests/hlsl: Test minimum precision stride for floating point numbers too. 2025-05-27 17:45:07 +02:00
Giovanni Mascellani
d214f9ebca tests/hlsl: Test minimum precision stride for signed integers too. 2025-05-27 17:43:07 +02:00
Giovanni Mascellani
6a699d2872 tests/hlsl: Test minimum precision floating point numbers. 2025-05-27 17:40:29 +02:00
Giovanni Mascellani
1496ddc52f tests/hlsl: Test native 16-bit floating point numbers. 2025-05-27 17:40:29 +02:00
Giovanni Mascellani
deb3b74c66 tests/hlsl: Test casting 16-bit integers to doubles. 2025-05-27 17:40:12 +02:00
Giovanni Mascellani
adca5a66e7 tests/hlsl: Test casting minimum precision integers to doubles. 2025-05-27 17:20:19 +02:00
Giovanni Mascellani
f7c2fbfe85 tests/hlsl: Test casting doubles to minimum precision integers. 2025-05-27 17:20:14 +02:00
Henri Verbeet
ffafa7fdaa tests/hlsl: Get rid of a MSL todo in geometry.shader_test.
The Metal/MSL runner doesn't support geometry shaders, so the test is
never executed on that runner.
2025-05-27 17:15:10 +02:00
Henri Verbeet
ee85e6b534 tests/hlsl: Require the "geometry-shader" cap for the relevant clip/cull-distance tests. 2025-05-27 17:15:10 +02:00
Henri Verbeet
5581c42a79 tests/shader_runner_d3d11: Direct3D 11 supports geometry shaders. 2025-05-27 17:15:10 +02:00
Henri Verbeet
0a28abd8f6 tests/shader_runner_metal: Try harder to find a suitable device. 2025-05-27 17:12:36 +02:00
Henri Verbeet
e17a98f870 vkd3d-shader: Remove some newlines from vkd3d-shader error messages. 2025-05-27 17:12:13 +02:00
Nikolay Sivov
c4c7f10d99 vkd3d-shader/fx: Fix the total buffer size calculation in write_fx_4_buffer().
The total size should take variable alignment/padding into account.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-24 21:32:22 +02:00
Nikolay Sivov
2e40154801 vkd3d-shader/fx: Use the correct field indices when writing structure default values.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-24 21:27:01 +02:00
Nikolay Sivov
a06ecb6867 vkd3d-shader/fx: Use the correct value range for bool initializers.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-24 21:24:59 +02:00
Nikolay Sivov
11d4fcff46 vkd3d-shader/fx: Handle nameless structure types.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-24 21:19:42 +02:00
Shaun Ren
a4e43402e5 vkd3d-shader/hlsl: Support void pass-through hull shader control point functions. 2025-05-24 21:13:00 +02:00
Shaun Ren
e7b2ca28ab vkd3d-shader/hlsl: Fix the register string for patch arrays in debug_register(). 2025-05-24 21:03:56 +02:00
Elizabeth Figura
f5e0c47811 vkd3d-shader/ir: Use add_signature_element() to add clip planes.
In particular, ensure that the semantic name is not NULL. This is necessary to
avoid a crash when a later pass using vsir_signature_find_element_by_name(),
e.g. vsir_program_insert_vertex_fog(), iterates over the signature including the
new element.
2025-05-24 21:02:17 +02:00
Giovanni Mascellani
3fb662c9e7 tests/hlsl: Remove some tests from minimum-precision.shader_test.
Most of them fail on any native implementation I can put my hands
on, including the CI. Equivalent, but hopefully better, tests
were added to arithmetic-uint.shader_test and
arithmetic-int-uniform.shader_test.
2025-05-24 21:00:32 +02:00
Giovanni Mascellani
cb1ee9cdd5 tests/hlsl: Test minimum precision 16-bit signed integers. 2025-05-24 20:59:34 +02:00
Giovanni Mascellani
a477502a05 tests/hlsl: Test minimum precision 16-bit unsigned integers. 2025-05-24 20:57:42 +02:00
Giovanni Mascellani
fdc173506e tests/hlsl: Test minimum precision stride in constant buffers. 2025-05-24 20:54:42 +02:00
Giovanni Mascellani
bd6dbd096f vkd3d-shader/dxil: Reimplement aggregate indexing using specialized value types.
As opposed to just touching the vsir register description, which
should be removed soon.
2025-05-24 20:44:45 +02:00
Giovanni Mascellani
6a85df013b vkd3d-shader/dxil: Pass a reference to the SM6 parser to sm6_register_from_value(). 2025-05-24 20:44:45 +02:00
Giovanni Mascellani
b0940729ff vkd3d-shader/dxil: Pass a reference to the SM6 parser to src_param_init_from_value(). 2025-05-24 20:44:45 +02:00
Giovanni Mascellani
6b9df6b7a5 vkd3d-shader/dxil: Pass a reference to the SM6 parser to src_params_init_from_operands(). 2025-05-24 20:44:45 +02:00
Henri Verbeet
fe747b065f vkd3d-shader: Also output vkd3d_shader_vnote() messages using WARN. 2025-05-24 20:41:39 +02:00
Henri Verbeet
ef3e10a14e vkd3d-shader: Also output vkd3d_shader_vwarning() messages using WARN. 2025-05-24 20:41:39 +02:00
Henri Verbeet
9156de0593 vkd3d-shader: Also output vkd3d_shader_verror() messages using WARN. 2025-05-24 20:41:39 +02:00
Shaun Ren
4eab50755e tests: Test signature reflection for geometry shader outputs. 2025-05-24 20:38:36 +02:00
Shaun Ren
a58b1f7011 vkd3d-shader/hlsl: Implement output semantics for geometry shaders. 2025-05-24 20:38:36 +02:00
Shaun Ren
18ec4caded vkd3d-shader/tpf: Read the DCL_OUTPUT_SGV instruction.
Introduce VSIR op VKD3DSIH_DCL_OUTPUT_SGV.
2025-05-24 20:38:36 +02:00
Henri Verbeet
a93d258a86 Release 1.16. 2025-05-20 11:35:48 +02:00
Henri Verbeet
379b297d2c build: Add the Objective-C API JSON to the distribution. 2025-05-15 14:13:07 +02:00
Henri Verbeet
07d8fe0462 build: Add the SPIR-V grammar JSON to the distribution. 2025-05-15 14:13:07 +02:00
Giovanni Mascellani
129b3a8c4b tests: Check that shader-visible descriptor heaps have a valid GPU descriptor handle start.
We currently check that non-shader-visible heaps have a NULL
handle, but that doesn't seem to be guaranteed: beside WARP, also
NVIDIA drivers still return a valid pointer. And that's a pretty
useless check anyway; rather, check that shader-visible heaps
have a valid pointer, which is more interesting.
2025-05-15 14:11:10 +02:00
Giovanni Mascellani
1aa33ebc80 tests: Allow creating GPU upload heaps.
They are write-combine heaps on L1 memory, and were introduced
recently in Direct3D 12.
2025-05-15 14:10:53 +02:00
Giovanni Mascellani
d5410e3115 tests: Expect success when creating resources in certain cases.
Currently the tests expect that creating buffers in COMMON or
COPY_SOURCE state on UPLOAD heaps or in COMMON state on READBACK
heaps leads to a failure. I tested WARP, AMD and NVIDIA, and in
all cases the operations is successful.

I think the D3D12 runtime used reject resources created in the
configurations detailed above, but it doesn't any more (both
using the latest Agility SDK and the runtime distributed with
an updated Windows 11 system). However the CI still uses an
earlier runtime, so the old behavior is still allowed as
broken.
2025-05-15 14:09:23 +02:00
Henri Verbeet
f5a26fd2b8 vkd3d-shader/dxil: Document the supported dxbc-dxil transformations. 2025-05-14 15:10:44 +02:00
Henri Verbeet
1efbcebed4 build: Sort the $(vkd3d_shader_tests) list. 2025-05-14 15:10:18 +02:00
Elizabeth Figura
c1adf54a44 vkd3d-shader/hlsl: Forbid referring to typedefs with "struct". 2025-05-14 15:09:48 +02:00
Elizabeth Figura
8ca50a2f7e tests/hlsl: Add more tests for struct syntax. 2025-05-14 15:09:42 +02:00
Elizabeth Figura
5ad2e7ee6d vkd3d-shader/hlsl: Fix an incorrect error message for referring to non-struct types with "struct".
We cannot be redefining struct types in this rule, only referring to already
defined types. Struct type definition is handled by named_struct_spec, which
complains if the type was defined at all, regardless of class.
2025-05-14 15:08:13 +02:00
Elizabeth Figura
bfa655a01f vkd3d-shader/ir: Use the .w component of the existing swizzle when lowering texldb. 2025-05-14 15:07:46 +02:00
Elizabeth Figura
e16176672a vkd3d-shader/hlsl: Validate "numthreads" attribute values. 2025-05-14 14:56:42 +02:00
Elizabeth Figura
cfb59828f3 tests/hlsl: Add more tests for the "numthreads" attribute. 2025-05-14 14:56:42 +02:00
Elizabeth Figura
a06b9f6646 vkd3d-shader/hlsl: Do not emit HLSL_OP1_ABS for unsigned types. 2025-05-14 14:55:59 +02:00
Elizabeth Figura
cdc74a9377 vkd3d-shader/hlsl: Emit an error when min16uint is used in d3dbc target profiles.
Fixes: 18ca7affad
2025-05-14 14:12:19 +02:00
Elizabeth Figura
8f6616993b vkd3d-shader/spirv: Do not declare inputs with an empty used_mask.
This is motivated by SampleId, whose presence or absence determines whether a
fragment shader runs at sample frequency or not.

In HLSL, if SV_SampleIndex is declared but not used, this results in a signature
entry, but no dcl instruction (and a zero used mask in the signature entry).
Whether the shader will actually run at sample frequency is inconsistent. NVidia
does, AMD does not, and WARP does for d3d12 but not for d3d11.

Previously vkd3d-shader relied on the dcl instruction, thereby aligning with
AMD. This was changed by 66cb2815f0. This commit
restores the previous behaviour.
2025-05-14 14:09:28 +02:00
Elizabeth Figura
65e1ef047f vkd3d-shader/spirv: Return void from spirv_compiler_emit_input(). 2025-05-14 14:09:28 +02:00
Elizabeth Figura
d40422592a vkd3d-shader/ir: Merge tess factor used masks together.
Encountered with the domain shader in
test_domain_shader_one_patch_constant_input().
2025-05-14 14:09:21 +02:00
Henri Verbeet
d4032f7d09 demos: Build with -fno-lto.
Some versions of Clang do not properly pass include paths to the
assembler when LTO is enabled. That's a problem for the DEMO_EMBED macro
used by the demos, since it relies on .incbin. To make matters even
better, compilation fails, but doesn't return an error code; the
resulting binary is simply broken. Fortunately we don't really care
about LTO for the demos, so we can simply disable it. See also
https://github.com/llvm/llvm-project/issues/112920

Thanks to Giovanni for tracking down some of the pieces of this issue.
2025-05-14 14:06:37 +02:00
Henri Verbeet
3c8fd8a2f2 ci: Build the demos on macOS. 2025-05-12 15:38:01 +02:00
Henri Verbeet
a2d5358ac6 demos: Avoid objc_msgSend_fpret() on ARM64 macOS.
It's unavailable, and unnecessary.
2025-05-12 15:38:01 +02:00
Giovanni Mascellani
dd34899e97 vkd3d-shader/dxil: Call register_get_float_value() directly in sm6_value_get_constant_float().
sm6_metadata_get_float_value() already calls sm6_value_is_constant()
itself, and some compilers (rightly) emit a warning that the conversion
of UINT_MAX to float changes the value.
2025-05-12 15:37:27 +02:00
Anna (navi) Figueiredo Gomes
820430001f vkd3d-shader/hlsl: Use the source data type in clone_interlocked(). 2025-05-12 15:31:09 +02:00
Elizabeth Figura
4a5411aa6e vkd3d-shader/hlsl: Return a uint1 from GetRenderTargetSampleCount(). 2025-05-12 15:29:23 +02:00
Elizabeth Figura
4cdea712d0 tests/hlsl: Show that GetRenderTargetSampleCount() returns a vector. 2025-05-12 15:28:49 +02:00
Giovanni Mascellani
42df4517c6 vkd3d-shader/dxil: Generate GROUPSHAREDMEM values in sm6_parser_declare_tgsm_structured(). 2025-05-12 15:24:23 +02:00
Giovanni Mascellani
fd918062d6 vkd3d-shader/dxil: Generate GROUPSHAREDMEM values in sm6_parser_declare_tgsm_raw(). 2025-05-12 15:24:23 +02:00
Giovanni Mascellani
cb5a548740 vkd3d-shader/dxil: Generate IDXTEMP values in sm6_parser_declare_indexable_temp(). 2025-05-12 15:24:23 +02:00
Giovanni Mascellani
8635a7ff6e vkd3d-shader/dxil: Generate ICB values in sm6_parser_declare_icb(). 2025-05-12 15:24:23 +02:00
Giovanni Mascellani
1d88638bd3 vkd3d-shader/dxil: Rename VALUE_TYPE_ICB to VALUE_TYPE_DATA.
And other related identifiers similarly.

Currently we use VALUE_TYPE_ICB to indicate a raw chunk of data
(which can be used as an immediate constant buffer, but also for
initializing an indexable temporary) and VALUE_TYPE_REG with
register type VKD3DSPR_IMMCONSTBUFFER to indicate an actual ICB
register.

Since we are now switching to represent the register type directly
in the SM6 value, it seems sensible to use VALUE_TYPE_ICB for an
ICB register. Indeed, since what we're currently describing with
VALUE_TYPE_ICB is not necessarily related to an ICB register, it
makes sense to use a more general name, which is therefore being
introduced with this commit.
2025-05-12 15:24:23 +02:00
Nikolay Sivov
960244bf1e vkd3d-shader/fx: Use appropriate BlendState description when tracing.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-06 19:01:09 +02:00
Nikolay Sivov
5d5d892830 vkd3d-shader/fx: Use the same BlendState states description for both fx_4_1 and fx_5_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-06 18:58:03 +02:00
Nikolay Sivov
d660a0d2ae tests: Add a fx_4_1 compilation test for the BlendState states.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-05-06 18:58:03 +02:00
Giovanni Mascellani
fd1f74f44d vkd3d-shader/dxil: Generate INVALID values in sm6_parser_emit_unhandled(). 2025-05-06 18:55:19 +02:00
Giovanni Mascellani
44e0b17606 vkd3d-shader/dxil: Generate INVALID values in sm6_parser_constants_init(). 2025-05-06 18:55:18 +02:00
Giovanni Mascellani
7381598310 vkd3d-shader/dxil: Generate UNDEFINED values in sm6_parser_constants_init().
VALUE_TYPE_UNDEFINED means that a value is explicitly undefined,
equivalently to what was first represented with is_undefined.
VALUE_TYPE_INVALID will be introduced for values that arise from
invalid programs.
2025-05-06 18:55:18 +02:00
Giovanni Mascellani
e9e02884e5 vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_phi(). 2025-05-06 18:55:18 +02:00
Giovanni Mascellani
7c344bdfd0 vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_cmpxchg(). 2025-05-06 18:55:18 +02:00
Giovanni Mascellani
326f3624d9 vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_dx_sincos(). 2025-05-06 18:55:18 +02:00
Giovanni Mascellani
527c1518f2 vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_dx_atomic_binop(). 2025-05-06 18:55:18 +02:00
Henri Verbeet
b389fa89e4 demos: Make the demos work in the macOS build. 2025-05-06 18:42:09 +02:00
Francisco Casas
7b07d77396 ci: Update the DXC version used on the CI to 1.8.2502. 2025-05-06 18:39:02 +02:00
Henri Verbeet
cb4b5641ea vkd3d: Handle multiple fence NULL event waits in d3d12_device_SetEventOnMultipleFenceCompletion(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
3fabac3f70 vkd3d: Handle multiple fence ANY waits in d3d12_device_SetEventOnMultipleFenceCompletion(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
9222f5e5b1 vkd3d: Handle multiple fence ALL waits in d3d12_device_SetEventOnMultipleFenceCompletion(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
52b947a005 vkd3d: Handle single fence waits in d3d12_device_SetEventOnMultipleFenceCompletion().
By forwarding to ID3D12Fence_SetEventOnCompletion().
2025-05-06 18:29:06 +02:00
Henri Verbeet
3ea84156c7 vkd3d: Validate the fence count in d3d12_device_SetEventOnMultipleFenceCompletion(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
75ce9cef92 tests/d3d12: Test ID3D12Device1_SetEventOnMultipleFenceCompletion(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
e54070c2d7 vkd3d: Introduce d3d12_fence_add_waiting_event(). 2025-05-06 18:29:06 +02:00
Henri Verbeet
615dce0eaa vkd3d: Introduce struct vkd3d_null_event.
This effectively moves "null_event_cond" from struct d3d12_fence and
"latch" from struct vkd3d_waiting_event together into a separate
structure, as well as storing the signalling function in struct
vkd3d_waiting_event instead of getting it from struct d3d12_device. I
think that largely makes sense on its own, but storing the signalling
function in struct vkd3d_waiting_event also allows us to more easily
implement d3d12_device_SetEventOnMultipleFenceCompletion() in a
subsequent commit.
2025-05-06 18:29:06 +02:00
Giovanni Mascellani
4289ec60a1 vkd3d-shader/dxil: Do not encode the offset twice for structured TGSM loads.
Currently structured TGSM loads are encoded to something like this:

    ld_structured sr12 <s:float>, sr1 <s:uint>, l(0) <s:uint>, g0[sr1 <s:uint> + 0] <s:float>

Notice how the TGSM offset, expressed by sr1, is encoded twice in
the instruction. In TPF there is no expectation of two indices
in the resource source, so let's avoid producing it for DXIL as
well. The same instruction will therefore become:

    ld_structured sr12 <s:float>, sr1 <s:uint>, l(0) <s:uint>, g0 <s:float>
2025-05-05 15:14:26 +02:00
Giovanni Mascellani
9fdaee1529 vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_binop(). 2025-05-05 15:10:15 +02:00
Giovanni Mascellani
31f8ed1d1e vkd3d-shader/dxil: Generate SSA values in sm6_parser_emit_atomicrmw(). 2025-05-05 15:10:15 +02:00
Giovanni Mascellani
fae03b2ba5 vkd3d-shader/dxil: Generate SSA values in instruction_dst_param_init_ssa_scalar(). 2025-05-05 15:10:15 +02:00
Giovanni Mascellani
bd73de7198 vkd3d-shader/dxil: Generate SSA values in instruction_dst_param_init_ssa_vector(). 2025-05-05 15:10:14 +02:00
Giovanni Mascellani
b8c6092a16 vkd3d-shader/dxil: Generate SSA values in sm6_parser_get_value_idx_by_ref(). 2025-05-05 15:08:29 +02:00
Giovanni Mascellani
9e7ad75944 vkd3d-shader/dxil: Move the VSIR register in the SM6 value outside of the union.
It will eventually disappear, but while it's replaced with other
union members it shouldn't interfere with them.
2025-05-05 15:02:58 +02:00
Giovanni Mascellani
648a60d4c8 vkd3d-shader/dxil: Introduce a uniform interface to synthesize a register from a SM6 value. 2025-05-05 15:02:57 +02:00
Giovanni Mascellani
8b58ce9e85 vkd3d-shader/dxil: Have sm6_parser_emit_reg_composite_construct() accept an array of registers.
Rather than an array of pointers to registers. This makes it nicer
to use with registers that are synthesized on the fly, a situation
that already exists and is likely to become more common in future
commits.
2025-05-05 15:01:36 +02:00
Shaun Ren
5b06fe83df vkd3d-shader/hlsl: Generate vsir instructions for stream output operations. 2025-05-05 14:54:07 +02:00
Shaun Ren
c8c1e270e0 vkd3d-shader/hlsl: Validate maximum output size in geometry shaders. 2025-05-05 14:43:53 +02:00
Shaun Ren
729a3ac089 vkd3d-shader/hlsl: Append output copies for stream output Append() invocations. 2025-05-05 14:30:16 +02:00
Shaun Ren
34b4b34f2c vkd3d-shader/hlsl: Use a block in append_output_copy*(). 2025-05-05 14:30:16 +02:00
Francisco Casas
e6db0ab614 tests: Add tests for DeviceMemoryBarrierWithGroupSync(). 2025-05-05 14:27:35 +02:00
Francisco Casas
b89f0bc730 vkd3d-shader/hlsl: Generate vsir for HLSL_IR_SYNC operations.
The following table shows how each intrinsic maps to d3d assembly and the
flags that appear in the tpf bytecode, in binary.

    GroupMemoryBarrier()                   sync_g               0010
    GroupMemoryBarrierWithGroupSync()      sync_g_t             0011
    DeviceMemoryBarrier()                  sync_uglobal         1000
    DeviceMemoryBarrierWithGroupSync()     sync_uglobal_t       1001
    AllMemoryBarrier()                     sync_uglobal_g       1010
    AllMemoryBarrierWithGroupSync()        sync_uglobal_g_t     1011
2025-05-05 14:17:47 +02:00
Francisco Casas
a975c56695 vkd3d-shader/hlsl: Mark stores dirty on interlocked operation in vectorize_stores(). 2025-05-05 14:15:23 +02:00
Francisco Casas
758a4bef09 vkd3d-shader/hlsl: Parse barriers.
And introduce hlsl_ir_sync to represent them.
2025-05-05 14:15:14 +02:00
Giovanni Mascellani
541060215e vkd3d-shader/dxil: Create vsir registers from DXIL handles when needed.
The idea is that sm6_value and related structures should not commit
to a specific vsir register representation yet, because at the time
they are created some information might be still unavailable. For
instance, it might be not yet known whether the program is using
native 16-bit types or minimum precision types. vsir registers
should only be synthesized during instruction emission.

Field "reg" in struct sm6_value will be handled in a later commit.
2025-04-30 16:58:31 +02:00
Elizabeth Figura
315247bf02 vkd3d-shader: Normalize TEXKILL to use a source register. 2025-04-30 16:51:44 +02:00
Giovanni Mascellani
50ca4a2101 vkd3d-shader/msl: Use the standard helper to print bitcasts. 2025-04-30 16:23:35 +02:00
Giovanni Mascellani
bb78c06193 vkd3d-shader/msl: Introduce msl_print_bitcast(). 2025-04-30 16:22:48 +02:00
Giovanni Mascellani
a1f48d2575 vkd3d-shader/msl: Introduce msl_print_src(). 2025-04-30 16:17:50 +02:00
Andrey Gusev
8882d324a6 vkd3d-shader/ir: Store the actual return value in shader_signature_map_patch_constant_index_ranges(). 2025-04-28 12:49:27 +02:00
Andrey Gusev
c69d2ab0ae vkd3d-shader/dxil: Store the actual return value in sm6_parser_signatures_init(). 2025-04-28 12:47:57 +02:00
Henri Verbeet
dfe3ad5551 demos: Make the demos work in the Windows build.
Commit 02fe9f5bdf introduced linking the
Windows build of the demos with d3d12 and dxgi, while also still linking
to libvkd3d-utils.la. That happens to more or less work on Wine; we get
vkd3d-utils' D3D12CreateDevice(), and Wine's
IDXGIFactory2_CreateSwapChainForHwnd(), but because Wine's
implementation of d3d12 swapchains uses vkd3d, we're able to use the
resulting swapchain buffers even though the instance of vkd3d used by
Wine may not be the same instance of vkd3d used by the demos. Perhaps
unsurprisingly, things don't go nearly as well on Windows.

We could of course stop linking the demos to vkd3d-utils on Windows, but
that's not that interesting; we're trying to show what vkd3d can do
here, not what d3d12 can do.
2025-04-28 12:16:10 +02:00
Henri Verbeet
883ffc5fd6 demos: Split demo_win32.h.
Much like we did for demo_xcb.h, demo_win32.h now just has the bits for
creating windows and handling events, while demo_d3d12.h has the d3d12
and dxgi bits.
2025-04-28 12:14:36 +02:00
Henri Verbeet
ceb2787d46 ci: Install mingw-w64-tools in the Linux image.
For the build-mingw-32 and build-mingw-64 jobs. These currently end up
picking up Linux pkg-config instead of MinGW pkg-config, which in turn
causes configure to pick up Linux OpenGL and XCB. We happen to get away
with that at the moment because none of the code using HAVE_OPENGL or
HAVE_XCB ends up getting built for Windows, but that's about to change.
Specifically, we'd like to build the vkd3d versions of the demos for
Windows.
2025-04-23 18:13:07 +02:00
Henri Verbeet
aa8161a7ad build: Do not add libvkd3d-shader.la to DEMOS_LDADD twice.
Commit e3f78706ec added libvkd3d-shader.la
to LDADD, but didn't remove it from DEMOS_LDADD.
2025-04-23 18:12:54 +02:00
Henri Verbeet
88bbc106c7 vkd3d-shader/spirv: We can parse up to SPIR-V 1.6.
The main reason to care at this point is that we actually emit SPIR-V 1.3
ourselves in some cases.
2025-04-23 18:12:39 +02:00
Conor McCarthy
4c8c31fa2e tests/hlsl: Add a shader model 5.1 test to srv-byteaddressbuffer.shader_test.
Some code paths for TPF handling are not tested if no 5.1 shaders are
compiled.
2025-04-23 18:11:42 +02:00
Conor McCarthy
c75b318805 vkd3d-shader/tpf: Emit the resource data type only for typed resource declarations. 2025-04-23 18:10:51 +02:00
Shaun Ren
5d29554fed tests/hlsl: Add geometry shader stream output syntax tests. 2025-04-23 18:03:59 +02:00
Shaun Ren
2a89b23ede vkd3d-shader/hlsl: Validate and record stream output objects.
Validation should only be done for stream outputs that are used.
2025-04-23 18:01:06 +02:00
Shaun Ren
f2f44b054d vkd3d-shader/hlsl: Allocate registers for stream output objects.
All stream output objects need to have a stream index allocated,
whether they are used or not.

We allocate stream outputs here, before other objects are allocated,
because the stream index is needed to create the appropriate output
semantic variables during append_output_copy(), which will be called
in a lowering pass for the Append() method.
2025-04-23 17:54:54 +02:00
Shaun Ren
d620ad4942 vkd3d-shader/hlsl: Introduce HLSL_REGSET_STREAM_OUTPUTS regset. 2025-04-23 17:54:54 +02:00
Shaun Ren
8059608af9 vkd3d-shader/hlsl: Parse the RestartStrip() method for stream outputs. 2025-04-23 17:54:54 +02:00
Shaun Ren
9525eb2f0c vkd3d-shader/hlsl: Parse the Append() method for stream outputs. 2025-04-23 17:54:54 +02:00
Shaun Ren
9b65cc8895 vkd3d-shader/hlsl: Support HLSL_CLASS_STREAM_OUTPUT in hlsl type helpers. 2025-04-23 17:54:54 +02:00
Giovanni Mascellani
6ca9395368 tests/d3d12: Skip testing NULL VBVs on NVIDIA on Windows.
It seems that the NVIDIA drivers leaves VBVs bindings untouched
when they are NULL (or the GPU buffer address is NULL), instead of
setting them to a null binding.

Differently from other cases of inconsistent behaviour between AMD
and NVIDIA, here I'm explicitly marking the NVIDIA behaviour as
broken, because the expected behaviour is spelled out explicitly
(at least for the D3D12 specification standards).
2025-04-21 14:43:59 +02:00
Giovanni Mascellani
bc637f2633 tests/d3d12: Do not validate the semantic of uint-clearing R11G11B10_FLOAT resources.
Implementations have no consistent behaviour.
2025-04-21 14:43:27 +02:00
Giovanni Mascellani
c1d04b84c7 tests/d3d12: Do not test out-of-bound UAV uint clears.
The behaviour is not uniform: AMD truncates, NVIDIA saturates.
2025-04-21 14:40:44 +02:00
Giovanni Mascellani
f890db872a tests/d3d12: Do not allow texture creation to fail when testing UAV uint clears.
If the format is supported texture creation should always succeed.
2025-04-21 14:40:31 +02:00
Giovanni Mascellani
f932af7f18 tests/d3d12: Check that B5G6R5_UNORM and B5G5R5A1_UNORM are supported before testing them.
They are not always available on NVIDIA GPUs.
2025-04-21 14:36:39 +02:00
Giovanni Mascellani
4324817c68 tests/d3d12: Set the descriptor heap when clearing UAVs. 2025-04-21 14:32:58 +02:00
Giovanni Mascellani
c764f71cf5 vkd3d-shader/ir: Validate that DEPTHOUTLE registers aren't used as sources. 2025-04-16 16:46:38 +02:00
Giovanni Mascellani
ee7895465c vkd3d-shader/ir: Validate that DEPTHOUTGE registers aren't used as sources. 2025-04-16 16:46:28 +02:00
Giovanni Mascellani
834017c198 vkd3d-shader/ir: Validate that DEPTHOUT registers aren't used as sources. 2025-04-16 16:46:05 +02:00
Giovanni Mascellani
a189a4cfb7 tests/hlsl: Do not test the implicit passthrough control point phase for SM6. 2025-04-16 16:43:45 +02:00
Giovanni Mascellani
dbd1938ce4 tests/hlsl: Fix the precision for a 16-bit arithmetic test. 2025-04-16 16:42:20 +02:00
Giovanni Mascellani
3186d66596 tests/hlsl: Do not test dst() on integer arguments with SM6.
That seems to hit a DXC bug we're not interested into.
2025-04-16 16:36:58 +02:00
Giovanni Mascellani
9db9f3bdaf tests/hlsl: Do not test 16-bit out-of-bound varyings. 2025-04-16 16:35:23 +02:00
Giovanni Mascellani
26656808e6 tests/hlsl: Remove a test in which a function reads an "out" argument.
The code doesn't make sense in the first place, even if it's
accepted by the compiler, so it makes sense that the behaviour
is undefined. And indeed the behaviour is different on AMD (4 is
returned), NVIDIA (QNaN is returned) and WARP (device is removed).
2025-04-16 16:30:19 +02:00
Giovanni Mascellani
df1aecb7bd tests/hlsl: Do not test 16-bit out-of-bound UAV writes. 2025-04-16 16:28:42 +02:00
Giovanni Mascellani
0ac661f571 tests/hlsl: Do not test 16-bit out-of-bound SRV buffer reads.
They do not behave consistently between AMD, NVIDIA and WARP, so
there is little point enforcing a specific behaviour.
2025-04-16 16:25:26 +02:00
Giovanni Mascellani
64bd2af015 tests/shader_runner_d3d9: Request the adapter specified on the command line. 2025-04-16 16:24:39 +02:00
Francisco Casas
9378d51b18 vkd3d-shader/hlsl: Remove the unnecessary "instr" field from the parser %union. 2025-04-16 16:22:42 +02:00
Francisco Casas
77941b131e vkd3d-shader/hlsl: Add switch_case destructors to the parser. 2025-04-16 16:21:51 +02:00
Francisco Casas
ff5f9cbcb6 vkd3d-shader/hlsl: Add parse_variable_def destructors to the parser. 2025-04-16 16:21:45 +02:00
Francisco Casas
f3ba7a84f4 vkd3d-shader/hlsl: Avoid leaking blocks on YYABORT.
Currently program errors might result on instructions that use
ctx->error_instr as src. In case we hit YYABORT while parsing another
part of the HLSL source, we have to make sure that the block that
contains the instruction is properly cleaned up, or we might hit the

    vkd3d:590273:err:hlsl_free_instr Failed assertion: list_empty(&node->uses)

assertion when hlsl_ctx_cleanup() is called after the YYABORT.

Consider the following shader:

    float4 main() : sv_target
    {
        // Statement A
        int p = foo;      // initializer argument is ERROR.
        // Statement B
        undeclared_fun(); // triggers YYABORT.
    }

Statement A will src the ctx->error_instr because of the undeclared
identifier and Statement B will trigger an YYABORT because of the
undeclared function.
2025-04-16 16:01:35 +02:00
Francisco Casas
128688a573 vkd3d-shader/hlsl: Avoid leaking declaration_statement blocks. 2025-04-16 16:00:18 +02:00
Francisco Casas
58706474ec vkd3d-shader/hlsl: Make struct_declaration_without_vars return void. 2025-04-16 15:58:40 +02:00
Giovanni Mascellani
922cb47a4b vkd3d-shader/ir: Validate descriptor counts in vsir programs. 2025-04-16 15:56:59 +02:00
Giovanni Mascellani
be94a37e23 vkd3d-shader/ir: Validate descriptor resource data types in vsir programs. 2025-04-16 15:52:46 +02:00
Giovanni Mascellani
01f47e00f2 vkd3d-shader/ir: Validate descriptor resource types in vsir programs. 2025-04-16 15:49:32 +02:00
Giovanni Mascellani
0da80c1f25 vkd3d-shader/ir: Validate descriptor types in vsir programs. 2025-04-16 15:46:20 +02:00
Giovanni Mascellani
869e6ef583 vkd3d-shader: Describe the resource data types of samplers as NONE.
It used to be UINT before, but it doesn't make any sense.
2025-04-16 15:42:31 +02:00
Giovanni Mascellani
f02ea94c42 vkd3d-shader/d3d-asm: Trace register names for I/O declarations. 2025-04-14 21:57:27 +02:00
Giovanni Mascellani
0417f4f162 vkd3d-shader/d3d-asm: Include the program descriptors when tracing vsir code. 2025-04-14 21:57:15 +02:00
Giovanni Mascellani
bac6949365 vkd3d-shader/d3d-asm: Expose the raw value if unknown in shader_dump_data_type(). 2025-04-14 21:55:26 +02:00
Giovanni Mascellani
fd16bba29d vkd3d-shader/d3d-asm: Expose the raw value if unknown in shader_dump_resource_type(). 2025-04-14 21:55:26 +02:00
Henri Verbeet
f4e10ea9d5 vkd3d-shader/d3d-asm: Include the I/O signatures when tracing vsir code. 2025-04-14 21:55:26 +02:00
Giovanni Mascellani
24e61cf74e vkd3d-shader: Represent resource data types as vkd3d_data_type in struct vkd3d_shader_descriptor_info1. 2025-04-14 21:55:26 +02:00
Giovanni Mascellani
4412a83655 tests: Create structured buffers with the appropriate stride.
The stride didn't match the structure size used in the shader.

This didn't seem to be a problem on AMD and WARP, but it was
on NVIDIA on Windows. Specifically, it seems that the buffer
is read using the shader structure size (so most tests pass),
but bounds are checked using the buffer stride, so a test
returned zero simply because an out-of-bounds read was detected.
2025-04-14 15:56:01 +02:00
Giovanni Mascellani
85e848289b tests/shader_runner_d3d11: Do not create CPU-readable multisample resolution textures.
Unless the D3D11_FEATURE_DATA_D3D11_OPTIONS2.MapOnDefaultTextures
feature is supported, textures with default usage cannot be read by the
CPU; and there isn't a need to either, since we're going through a
staging texture anyway.

This worked on AMD and WARP, but failed on NVIDIA on Windows.
2025-04-14 15:54:27 +02:00
Henri Verbeet
4e783e2d66 tests/shader_runner: Get rid of enum texture_data_type. 2025-04-14 15:48:24 +02:00
Francisco Casas
7b21059ee5 vkd3d-shader/hlsl: Support the .Length property for Textures.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=57686
2025-04-14 15:47:16 +02:00
Francisco Casas
2dce34d7e0 tests/hlsl: Test the object .Length property. 2025-04-14 15:41:47 +02:00
Elizabeth Figura
0c18736370 vkd3d-shader/ir: Validate SSA write masks. 2025-04-14 15:32:15 +02:00
Elizabeth Figura
d91d552a5e vkd3d-shader/ir: Introduce a vsir_dst_param_init_null() helper. 2025-04-14 15:32:12 +02:00
Elizabeth Figura
1a1f1f1369 vkd3d-shader/hlsl: Set the right interpolation mode in the vsir signature. 2025-04-14 15:29:19 +02:00
Elizabeth Figura
7331c70e9e vkd3d-shader/hlsl: Set the sysval for more sm1 semantics.
To match the sysval we set when reading them.
2025-04-14 15:29:19 +02:00
Feifan He
ba7a9a0b29 vkd3d-shader/msl: Implement VKD3DSIH_LD.
Co-authored-by: Giovanni Mascellani <gmascellani@codeweavers.com>
2025-04-14 15:27:02 +02:00
Feifan He
015a751ea0 tests/shader_runner_metal: Add texture support.
Co-authored-by: Giovanni Mascellani <gmascellani@codeweavers.com>
2025-04-14 14:50:51 +02:00
Giovanni Mascellani
3493688a4d vkd3d-shader/msl: Access descriptors with a type-erased array.
Currently a descriptor set is represented with a structure
whose fields are the various descriptors that the shader is
going to use, each of them qualified with its type. This model
doesn't match very well what happens with D3D12 and with Vulkan
and descriptor indexing and mutable descriptors, where many
descriptor of different types can overlap, and only at shader
runtime it is decided which of them must be used.

Therefore with this patch a descriptor is represented as a
structure whose fields carry no intrinsic typing information,
but are reinterpreted according to the shader behavior on
each access. For the moment there is just one field, but more
will be added to account for fancier descriptor types and
to workaround Metal limitations.

When completed, this design will be similar in spirit to what
the Metal shader converter does, with little technical
differences.

This choice has a couple of drawbacks:

 1. shader debugging with Xcode is less comfortable, because
    the shader doesn't carry static descriptor typing
    information and Xcode is therefore less able to provide
    useful context;

 2. it requires tier 2 argument buffer support and macOS
    version >= 13, which includes guarantees on the runtime
    layout for descriptors.

Supporting descriptor indexing and mutable descriptors is
considered to be worthy of those drawbacks, though, is
effectively required by many applications and appears to be
the first goal we should aim for. If needed, in the future
we might also add support for older hardware, at least for
shaders that do not make use of advanced features.
2025-04-14 14:45:14 +02:00
Giovanni Mascellani
ed677a8f32 tests/shader_runner_metal: Do not use shared buffers.
They are not supported on non-Apple discrete GPUs. Instead make
them managed (if they are short lived) or private.
2025-04-14 14:38:39 +02:00
Feifan He
e5bb3a5233 tests/shader_runner_metal: Introduce a helper to encode the argument buffer.
Co-authored-by: Giovanni Mascellani <gmascellani@codeweavers.com>
2025-04-14 14:38:39 +02:00
Giovanni Mascellani
eb9e254b8c tests/shader_runner_metal: Handle multisampled 2D texture arrays properly.
They're not supported by the shader runner anyway, but there's no
reason to make the code subtly wrong.
2025-04-14 14:38:38 +02:00
Giovanni Mascellani
cbce3a8631 tests/shader_runner: Always set descriptor heaps. 2025-04-09 16:42:16 +02:00
Giovanni Mascellani
bb8f1304ba tests/d3d12: Always set descriptor heaps.
It seems AMD and WARP are not particularly sensitive to that, but
NVIDIA drivers crash if descriptor heaps are not set.
2025-04-09 16:41:33 +02:00
Conor McCarthy
fdd21470b9 tests/hlsl: Test casts from double to 16-bit integer types. 2025-04-09 16:39:07 +02:00
Conor McCarthy
bb8b4f3827 tests/hlsl: Test casts to 16-bit uint. 2025-04-09 16:22:19 +02:00
Conor McCarthy
3c950e5977 tests/hlsl: Test casts to 16-bit int. 2025-04-09 16:20:58 +02:00
Conor McCarthy
88a85024e2 tests/hlsl: Test casts to 16-bit float. 2025-04-09 16:20:53 +02:00
Giovanni Mascellani
7fb288819a vkd3d-shader/msl: Set the prefix to "unknown" for unhandled shader types in msl_generator_init().
Like we do for GLSL; there's no reason to abort compilation here. Note
that this also avoids leaking "gen->buffer" and "gen->string_buffers" on
the error path.
2025-04-09 16:08:15 +02:00
Shaun Ren
0c139ef7a0 vkd3d-shader/hlsl: Add special allocation rules for patch constant data. 2025-04-09 16:02:12 +02:00
Shaun Ren
7ba84b7787 tests: Add signature reflection tests for register allocation rules in tessellation shaders. 2025-04-09 16:02:12 +02:00
Shaun Ren
d3b32fefa3 vkd3d-shader/tpf: Support SV_RenderTargetArrayIndex/SV_ViewportArrayIndex sysvals in tessellation shaders. 2025-04-09 16:02:12 +02:00
Shaun Ren
05f8dd8273 vkd3d-shader/hlsl: Prioritize smaller writemasks for all allocators in allocate_semantic_registers(). 2025-04-09 16:02:12 +02:00
Shaun Ren
ec2f18ab17 vkd3d-shader/hlsl: Free all allocators in allocate_semantic_registers(). 2025-04-09 16:02:12 +02:00
Shaun Ren
d1df10ac86 vkd3d-shader/hlsl: Use dcl_output_siv for patch constant function sysval outputs. 2025-04-09 16:02:12 +02:00
Henri Verbeet
70655012ab demos: Move the vkd3d parts of demo_xcb.h into a separate header.
So that they can be used for e.g. Wayland or macOS support. Or Windows,
if we're so inclined.
2025-04-08 20:38:26 +02:00
Henri Verbeet
b12e3d8eec demos: Get rid of some unused includes.
These were used for demo_load_shader(), but that was removed some time
ago in commit aa5d48eec4.
2025-04-08 20:38:26 +02:00
Victor Chiletto
89d3e667e0 tests/hlsl: Add tests for SRV structured buffers. 2025-04-08 19:31:40 +02:00
Victor Chiletto
cc9f4ac587 tests/hlsl: Attempt to deduce the data type of unspecified type texture data.
Try parsing first as integer, and if the parse stops at a decimal separator, parse as float.
2025-04-08 19:18:57 +02:00
Victor Chiletto
7b21183f45 tests/shader_runner_d3d12: Pass the structure byte stride for SRVs. 2025-04-08 19:18:56 +02:00
Anna (navi) Figueiredo Gomes
3e8b56c509 vkd3d-shader/fx: Don't cast between int and uint in state blocks. 2025-04-08 19:14:15 +02:00
Anna (navi) Figueiredo Gomes
8866a43b2d tests/hlsl: Add some fx_4_0 state tests. 2025-04-08 19:14:15 +02:00
Elizabeth Figura
f576ecc992 vkd3d-shader/hlsl: Introduce a compiler pass to vectorize stores. 2025-04-03 20:29:20 +02:00
Elizabeth Figura
1a999f74fc vkd3d-shader/hlsl: Introduce a compiler pass to vectorize expressions. 2025-04-03 20:29:20 +02:00
Giovanni Mascellani
7b4a29da81 tests: Mark a todo as resolved on MoltenVK 1.2.12.
Technically it is not, the Vulkan commands we're generating are
still not correct. But let's get rid of the failure message.
2025-04-03 20:28:31 +02:00
Giovanni Mascellani
653e4f47ac ci: Disable testing with DXC on macOS.
With this we can finally disallow failure for the macOS CI script,
which is more valuable than checking DXC. Eventually DXC tests
will have to be fixed, though.
2025-04-03 20:28:27 +02:00
Giovanni Mascellani
aab8ba02d8 tests: Mark a number of test failures as buggy on macOS before Sequoia.
It's hard to pinpoint exactly what's going wrong with these
tests. They seem to be related to atomics and GPU timestamps,
both categories that are known to have problems on MoltenVK in a
way or another; those failures clearly depend on a few factors
like the MoltenVK version, the macOS version and whether we're in
a virtual machine or not, but the exact dependency on those factors
is hard to describe (for example, in general the paravirtualized
device offered inside virtual machines has a lot more problems than
real devices, but I've seen tests, fixed all other conditions,
working on the paravirtualized device and not on the real device).

The only thing all tests in this batch have in common is that I've
never seen them fail on a Sequoia system, thus I've settled for
using just that as the bug_if() condition. Ultimately, wasting a
lot of time to get to the bottom of each single test failure is
pointless, and being able to mark the CI job as not allowed to
fail gives better regression protection than investigating each
of those. Also, I routinely run the tests on a Sequoia system, so
if these tests get broken this is going to be noticed anyway.
2025-04-03 20:26:26 +02:00
Nikolay Sivov
2540081988 vkd3d-shader/fx: Accept int(0) as well as uint(0) constant value for object-type states.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-04-02 19:34:25 +02:00
Nikolay Sivov
4ff14104b0 vkd3d-shader/fx: Set GeometryShader state type as an object type.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-04-02 19:34:25 +02:00
Elizabeth Figura
ea21dddec9 vkd3d-shader/hlsl: Allow compiling directly to GLSL. 2025-04-02 19:33:41 +02:00
Elizabeth Figura
33cd10581e vkd3d-shader/glsl: Invert gl_FragCoord w. 2025-04-02 19:32:39 +02:00
Francisco Casas
4b9c23272a vkd3d-shader/ir: Reset instruction pointers after shader_instruction_array_insert_at().
Every call to shader_instruction_array_insert_at() means a possible
reallocation of all vsir instructions in the program. This means that all
previous pointers are potentially no longer valid.

We are currently using these potentially invalid pointers in some cases,
usually in the form of "ins->location". This commit fixes these.

I moved all pointer changes to right after the call to
shader_instruction_array_insert_at() to make this more evident.
2025-04-02 19:25:12 +02:00
Giovanni Mascellani
875c5df519 vkd3d-shader/ir: Validate register id and index for CONSTBUFFER registers. 2025-04-02 19:24:10 +02:00
Giovanni Mascellani
c181f147ce vkd3d-shader/ir: Validate register id and index for SAMPLER registers. 2025-04-02 19:08:50 +02:00
Giovanni Mascellani
9b7256c0c8 vkd3d-shader/ir: Validate register id and index for UAV registers. 2025-04-02 19:08:00 +02:00
Giovanni Mascellani
10d8760134 vkd3d-shader/ir: Validate register id and index for RESOURCE registers. 2025-04-02 19:06:43 +02:00
Shaun Ren
3e44bd4e5b tests/hlsl: Add a test for copy-propagation of uniform texture object writes. 2025-04-02 18:51:10 +02:00
Shaun Ren
7aebed0eea vkd3d-shader/hlsl: Ensure that uniform objects are never written to in copy_propagation_transform_object_load(). 2025-04-02 18:49:52 +02:00
Shaun Ren
b1d8915440 vkd3d-shader/hlsl: Divert written uniform derefs to temps before copy-propagation passes.
The following pixel shader currently triggers an infinite loop during
copy propagation, which is fixed by this commit:

    sampler s;
    Texture2D t1, t2;

    float4 main() : sv_target
    {
        Texture2D t = t1;
        t1 = t2;
        t2 = t;
        return t1.Sample(s, float2(0, 0)) + t2.Sample(s, float2(0, 0));
    }

The infinite loop occurs because copy_propagation_transform_object_load()
replaces t1 in the resource_load(t1, ...) instruction
with t2, t1, t2, ... repeatedly.
2025-04-02 18:49:52 +02:00
Francisco Casas
3ead8d532b vkd3d-shader/hlsl: Allow non-constant deref propagation on SM1.
Note that we still have to preempt the propagation to SM1 pixel shader
uniforms. Otherwise this will turn the many constant derefs that appear
from the <index-val> copy generated in lower_index_loads() into a single
non-constant deref, causing it to allocate all the registers instead of
up until the last one used.
2025-04-02 18:27:16 +02:00
Francisco Casas
f65e6265e0 vkd3d-shader/ir: Normalise MOVA and d3dbc indirect addressing. 2025-04-02 18:27:16 +02:00
Francisco Casas
fd02d69dda vkd3d-shader/hlsl: Implement indirect addressing for d3dbc target profiles. 2025-04-02 18:26:03 +02:00
Francisco Casas
0e0ed72652 vkd3d-shader/d3dbc: Respect "idx_count" when writing registers.
Some SM1 src registers have idx_count = 0, in which case we have to
respect that instead of always reading reg->reg.idx[0].offset even when
it is invalid.
2025-04-02 18:06:48 +02:00
Francisco Casas
2327f87e37 tests/hlsl: Test SM1 vertex shader uniform allocation on indirect addressing.
Here, a vertex shader version of the previous test by Shaun is
introduced. Note that in this case the uniform allocates all 4 registers
instead of 3 because it is indirectly addressed.
2025-04-02 18:06:48 +02:00
Francisco Casas
b6ce1479fe tests/hlsl: Test vertex shader uniform indirect addressing.
Note that, for indexes with a decimal part, the behavior is different
depending on whether it is a temp load or a direct uniform load (which
can only happen on vertex shaders). The former rounds to the
closest-to-zero, while the latter rounds to the nearest even.
2025-04-02 18:06:18 +02:00
Elizabeth Figura
20b76f87bf vkd3d-shader/hlsl: Initialize the temp count for sm1. 2025-04-02 17:58:26 +02:00
Elizabeth Figura
7cb5a7bebc vkd3d-shader/hlsl: Leave the swizzle zero for VSIR_DIMENSION_NONE registers. 2025-04-02 17:58:26 +02:00
Elizabeth Figura
950f78041a vkd3d-shader/hlsl: Initialize the vsir dimension for sm1. 2025-04-02 17:58:26 +02:00
Elizabeth Figura
856f4b55f6 vkd3d-shader/hlsl: Set the correct index count for sm1 DEPTHOUT. 2025-04-02 17:58:26 +02:00
Elizabeth Figura
227e2cc0f5 vkd3d-shader/hlsl: Use vsir_*_from_hlsl_node() helpers in more places. 2025-04-02 17:58:18 +02:00
Henri Verbeet
110edf32d0 demos: Add basic DPI handling. 2025-03-19 14:10:24 +01:00
Nikolay Sivov
21e08955d3 vkd3d-shader/fx: Pad fx_2_0 object data blobs with zeroes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-18 15:56:32 +01:00
Giovanni Mascellani
803bf59654 tests: Mark an early depth stencil test as buggy on MoltenVK.
On MoltenVK it seems that all draws are always executed,
independently of the early depth stencil test. The problem doesn't
seem to belong to vkd3d or MoltenVK, because the generated Metal
commands look correct. I tried looking at a GPU capture with Xcode,
which was not very conclusive because it doesn't state clearly
whether early fragment tests were passed or not. Sometimes it
says that a fragment shader execution had no thread execution
data, which I interpret as the early fragment tests having
prevented the fragment shader from running, but it's not really
consistent, and it's never clear which results are based on
software simulation and which on the hardware run.

However taking everything into account I think the most likely
explanation is some incorrect optimization at the Metal level.
2025-03-18 15:55:29 +01:00
Giovanni Mascellani
05f7f03dab tests: Mark a queue synchronization test as buggy on MoltenVK.
The graphics pipeline triggers an internal error in the Metal
pipeline compiler, with a completely generic error message. I have
no idea what the actual problem is.
2025-03-18 15:53:59 +01:00
Shaun Ren
8f19d02501 tests: Add a signature reflection test for geometry shader inputs. 2025-03-18 15:46:07 +01:00
Shaun Ren
62c00be873 vkd3d-shader/tpf: Emit geometry shader property declarations. 2025-03-18 15:46:07 +01:00
Shaun Ren
bd055fac1c vkd3d-shader/hlsl: Store geometry shader properties in struct vsir_program. 2025-03-18 15:46:02 +01:00
Shaun Ren
b1ace5763a vkd3d-shader/hlsl: Implement input semantics for geometry shaders. 2025-03-18 15:40:11 +01:00
Shaun Ren
8af3173955 vkd3d-shader/hlsl: Support input primitive arrays in geometry shaders. 2025-03-18 15:40:11 +01:00
Giovanni Mascellani
2377db33db vkd3d-shader: Represent descriptor information in the vsir program. 2025-03-18 15:38:01 +01:00
Giovanni Mascellani
4308fa3f68 vkd3d-shader/spirv: Do not steal the instruction array from the vsir program.
There is no need, and it only complicates tracking ownership.
2025-03-18 15:37:57 +01:00
Giovanni Mascellani
fc520e7b4c vkd3d-shader/spirv: Do not store duplicate references to the signatures.
They are already available through the program.
2025-03-18 15:34:16 +01:00
Giovanni Mascellani
5ce03258b5 vkd3d-shader/spirv: Immediately store a reference to the program in the SPIR-V generator.
So it doesn't have to be passed around uselessly.
2025-03-18 15:34:04 +01:00
Giovanni Mascellani
549659dab6 vkd3d-shader/spirv: Run the vsir passes before creating the SPIR-V generator.
This makes it more similar to the MSL and GLSL generators. It also looks
like a cleaner design, the backend is supposed to get access to the vsir
program after it has gone through the pipeline.
2025-03-18 15:33:27 +01:00
Francisco Casas
ea99d2c2cd vkd3d-shader/hlsl: Lower integer modulus for d3dbc target profiles. 2025-03-18 15:27:04 +01:00
Francisco Casas
828afe188c vkd3d-shader/hlsl: Don't lower integer MOD and DIV on const passes for d3dbc target profiles.
These bitwise operations are not available in these profiles.
2025-03-18 15:27:03 +01:00
Francisco Casas
e3923876c0 tests/hlsl: Test integer division with big integers.
Similarly to the modulus operator, d3dbc results with constant folding
are different from results when constant folding cannot be applied, and
different from tpf results.
2025-03-18 15:25:41 +01:00
Francisco Casas
080672478d tests/hlsl: Test integer modulus with big integers.
Note that in d3dbc target profiles it gives different results when this
operation is constant folded compared to when it is not.

This suggests that whatever pass lowers the modulus operation to d3dbc
operations doesn't do it before constant folding.

Also note that when constant folded, d3dbc results differ from tpf
results for negative operands, because of the loss of precision that
happens when NEG is constant folded.

So the same integer modulus expression can have 3 different results
depending on the context.
2025-03-18 15:21:43 +01:00
Francisco Casas
a3f80061b1 tests/hlsl: Test for loss of precision on integer negation in d3dbc target profiles. 2025-03-18 14:25:26 +01:00
Elizabeth Figura
bc382c6835 vkd3d-shader/hlsl: Reuse shader model 1-3 constants. 2025-03-18 14:21:02 +01:00
Giovanni Mascellani
e418bbcfac tests: Mark a test about resource aliasing as todo on MoltenVK.
As far as I know there is no way to implement this properly on
Vulkan, and all the other Vulkan implementations essentially work
by luck. In Vulkan the initial layout of a resource must always be
UNDEFINED or PREINITIALIZED and it must be transitioned away from
before any meaningful use of that image is done. Therefore it's
possible to alias two images and let the second one inherit the
content in the first one only if both already exist (and are in
the same layout) before the first writing is done. If, as in this
example, the second image is created after the first one has
already been written to, the obligatory transition away from
UNDEFINED or PREINITIALIZED will potentially wipe out the content.

Therefore I am marking this as todo, not as a bug. I might also be
that there is a bug in MoltenVK, and ultimately that's the reason
why we're reading invalid data, but technically the Vulkan
commands we generate are incorrect anyway.
2025-03-17 15:14:23 +01:00
Giovanni Mascellani
44072062ff tests: Transition texture state to inherit aliased data.
When textures[1] is read for the second time it is aliased to
textures[0]. But textures[0] was left in COPY_DEST state (since
its creation), and textures[1] is currently recreated in COPY_SOURCE
state, which AFAIU is invalid. So recreate textures[1] in COPY_DEST
state and then transition it before reading it.
2025-03-17 15:14:23 +01:00
Giovanni Mascellani
c3f01d7db9 tests: Mark two other tessellation tests as buggy on MoltenVK.
I haven't investigated the actual problem here, but the generated
Vulkan commands look correct (and work with basically all other
Vulkan implementations) and MoltenVK is known to have incomplete
tessellation support, so it's likely that the problem is there.
2025-03-17 15:14:23 +01:00
Giovanni Mascellani
8cf61c859d tests: Mark a few other timestamp query tests as buggy on MoltenVK.
Similarly to 5d4edba925, it seems
that sometimes MoltenVK returns 0 to timestamp queries. It
doesn't happen deterministically and it might depend on the
hardware (I have seen differences between the M2 I used some
time ago and the M3 Max I have now).
2025-03-17 15:14:23 +01:00
Giovanni Mascellani
101f070f12 ci: Define VKD3D_TEST_DEBUG when running the CI scripts.
Essentially to make d3d12.log more readable.
2025-03-17 15:14:23 +01:00
Henri Verbeet
0dff53ada7 build: Add @DL_LIBS@ to tests_vkd3d_shader_api_LDADD.
It uses dxcompiler_create(), which (potentially) uses dlopen().
2025-03-17 15:13:42 +01:00
Giovanni Mascellani
674614cc7a vkd3d-shader/ir: Disallow IMMCONSTBUFFER registers in destination parameters. 2025-03-17 15:12:13 +01:00
Giovanni Mascellani
0761d73e9c vkd3d-shader/ir: Disallow CONSTBUFFER registers in destination parameters. 2025-03-17 15:12:13 +01:00
Giovanni Mascellani
0c9c29fb34 vkd3d-shader/ir: Validate CONSTBUFFER registers. 2025-03-17 15:11:52 +01:00
Henri Verbeet
808931b108 vkd3d-shader/glsl: Implement VKD3DSIH_XOR. 2025-03-17 15:07:51 +01:00
Nikolay Sivov
ba79890398 vkd3d-shader/fx: Support dumping parameter and array selector assignments for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 15:05:14 +01:00
Nikolay Sivov
ff7591171b vkd3d-shader/fx: Dump complex state value blobs for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 14:54:26 +01:00
Nikolay Sivov
fb16ae2325 vkd3d-shader/fx: Add support for dumping fx_2_0 shader blobs.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 14:48:12 +01:00
Nikolay Sivov
36e1a0ceae vkd3d-shader/fx: Add support for parsing fx_2_0 sampler states.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 14:46:36 +01:00
Nikolay Sivov
3e86484091 vkd3d-shader/fx: Read fx_2_0 assignment data outside of its dumping helper.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 14:46:36 +01:00
Nikolay Sivov
fb5d53bf57 vkd3d-shader/fx: Add a helper to escape printed strings.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-17 14:46:18 +01:00
Giovanni Mascellani
fc4316f664 tests/shader_runner: Avoid creating devices for backends that won't execute.
My main motivation to this is avoiding generating a lot of useless
log lines from other executors when I'm interested in just one of
them, but I can imagine this also somewhat improving efficiency.
2025-03-17 14:01:22 +01:00
Giovanni Mascellani
0b273ea88c tests: Store the compiler string in the shader runner capabilities.
Just like the executor.
2025-03-17 13:50:19 +01:00
Shaun Ren
a4f58be00c vkd3d-shader/hlsl: Remove the unused hlsl_array_type_to_string() declaration.
Accidentally introduced in 870c68dd27.
2025-03-13 14:02:26 +01:00
Elizabeth Figura
c9a5f586b7 vkd3d-shader/hlsl: Zero-initialize "nonconst_i" and "ret_swizzle" in copy_propagation_replace_with_deref().
GCC without LTO is unable to determine that these are never used
uninitialized.
2025-03-13 13:59:05 +01:00
Francisco Casas
09b9f8ff9f vkd3d-shader/hlsl: Fix invalidation of the wrong components in copy-propagation.
Fixes: 1bba18aa75.
2025-03-12 22:14:25 +01:00
Francisco Casas
bff9068a7f tests: Add a hard test for copy-propagation invalidation.
This test is currently miscompiling on SM4 because
copy_propagation_invalidate_variable_from_deref_recurse() is not always
invalidating the right components.
2025-03-12 22:14:15 +01:00
Elizabeth Figura
a87b1efbd2 vkd3d-shader/hlsl: Don't invalidate OOB constant derefs. 2025-03-12 22:09:57 +01:00
Elizabeth Figura
193e40c271 vkd3d-shader/hlsl: Stop checking for failure from intrinsic_float_convert_arg(). 2025-03-12 22:02:39 +01:00
Elizabeth Figura
7b5b5dbb8d vkd3d-shader/hlsl: Do not abort when performing an invalid implicit cast. 2025-03-12 22:02:39 +01:00
Elizabeth Figura
2ee19c4d34 vkd3d-shader/hlsl: Do not abort when performing an invalid explicit cast. 2025-03-12 22:02:39 +01:00
Elizabeth Figura
25f476c7ad vkd3d-shader/hlsl: Return an error expression from add_cast() on allocation failure. 2025-03-12 22:02:39 +01:00
Elizabeth Figura
0642531c2a vkd3d-shader/hlsl: Introduce hlsl_block_add_swizzle(). 2025-03-12 22:02:31 +01:00
Elizabeth Figura
f8c53fae37 vkd3d-shader/hlsl: Introduce hlsl_block_add_resource_load(). 2025-03-12 22:02:21 +01:00
Henri Verbeet
b9ebf87114 vkd3d-shader/hlsl: Do not collect expressions across different operations in hlsl_normalize_binary_exprs(). 2025-03-12 21:34:17 +01:00
Henri Verbeet
b4296e1a2d tests/hlsl: Add another constant folding test. 2025-03-12 21:34:02 +01:00
Shaun Ren
dd1072a99b tests/hlsl: Add geometry shader syntax tests. 2025-03-12 21:21:35 +01:00
Shaun Ren
ae5261b98b vkd3d-shader/hlsl: Forbid output parameters in geometry shaders.
Outputs in geometry shaders must be written to streams.
2025-03-12 21:15:15 +01:00
Shaun Ren
4137ea5ab7 vkd3d-shader/hlsl: Validate stream output parameters in geometry shaders. 2025-03-12 21:13:59 +01:00
Shaun Ren
b650e7a503 vkd3d-shader/hlsl: Validate stream output object declarations.
Valid stream output objects must be single-element containing a
PointStream/LineStream/TriangleStream object.

Moreover, stream output objects cannot be declared globally.
2025-03-12 21:12:56 +01:00
Shaun Ren
870c68dd27 vkd3d-shader/hlsl: Validate and record input primitive types in geometry shaders. 2025-03-12 21:11:46 +01:00
Shaun Ren
57bb28e841 vkd3d-shader/hlsl: Parse primitive type modifiers in geometry shaders. 2025-03-12 20:42:59 +01:00
Shaun Ren
e880b11626 vkd3d-shader/hlsl: Parse the maxvertexcount attribute. 2025-03-12 20:42:15 +01:00
Francisco Casas
7be7e589a9 vkd3d-shader/hlsl: Lower TRUNC expressions for SM1.
Basically, separate lower_casts_to_int() into the lowering of the CAST
and the lowering of the TRUNC, so that TRUNCs that are not part of a
cast are lowered as well.
2025-03-12 18:26:23 +01:00
Shaun Ren
1b03676a36 tests/hlsl: Add dynamic addressing copy-propagation tests. 2025-03-12 18:22:01 +01:00
Shaun Ren
7ab7b2ab8b vkd3d-shader/hlsl: Implement copy-propagation of derefs with a non-constant index.
We implement a transformation that propagates loads with a single
non-constant index in its deref path. Consider a load of the form
var[[a0][a1]...[i]...[an]], where ak are integral constants, and i is
an arbitrary non-constant node. If, for all j, the following holds:

  var[[a0][a1]...[j]...[an]] = x[[c0*j + d0][c1*j + d1]...[cm*j + dm]],

where ck, dk are constants, then we can replace the load with
x[[c0*i + d0]...[cm*i + dm]]. This pass is implemented by
copy_propagation_replace_with_deref().
2025-03-12 18:16:59 +01:00
Shaun Ren
f484527cfb vkd3d-shader/hlsl: Rename init_deref() to hlsl_init_deref(). 2025-03-12 17:22:44 +01:00
Shaun Ren
2bc7fa568f vkd3d-shader/hlsl: Introduce component_index_from_deref_path_node(). 2025-03-12 17:19:56 +01:00
Shaun Ren
2368ff6637 vkd3d-shader/hlsl: Introduce simplify_exprs().
Also invoke simplify_exprs() after replace_deref_path_with_offset().
2025-03-12 17:18:52 +01:00
Shaun Ren
c6f18c9394 vkd3d-shader/hlsl: Support indirect addressing of uniforms in sm4_generate_vsir_reg_from_deref(). 2025-03-12 17:14:52 +01:00
Shaun Ren
f6c35144e4 vkd3d-shader/hlsl: Support patch arrays in hlsl_reg_from_deref(). 2025-03-12 17:10:32 +01:00
Shaun Ren
261b5120f6 vkd3d-shader/hlsl: Allow non-constant indices in register_deref_usage(). 2025-03-12 17:10:32 +01:00
Shaun Ren
1c2434f4d3 vkd3d-shader/hlsl: Allow uint1-typed deref path nodes.
When derefs with non-constant indices are copy-propagated, it is
possible to end up with uint1-typed path nodes.

Also, introduce hlsl_is_vec1().
2025-03-12 17:09:35 +01:00
Shaun Ren
766492d1cc vkd3d-shader/glsl: Implement support for indirect constant buffer addressing. 2025-03-12 17:06:47 +01:00
Shaun Ren
16b0afc192 vkd3d-shader/tpf: Write non-zero static offsets in relative addressing mode in sm4_write_register_index(). 2025-03-12 17:04:52 +01:00
Henri Verbeet
81dc67b1ef demos: Add copyright headers to the HLSL shaders. 2025-03-10 15:18:07 +01:00
Elizabeth Figura
8f28956108 vkd3d-shader/hlsl: Fix writing the sincos extra constants.
Fixes: 4ed16108f0
2025-03-10 15:17:19 +01:00
Elizabeth Figura
d075c3c274 vkd3d-shader/hlsl: Fix temp allocation for ps 1.x.
Iterate over the extern vars, not the parameters. The synthesized inputs and
output don't go in the function parameters.

Fixes: 8b57a612d7
2025-03-10 15:17:19 +01:00
Nikolay Sivov
553e37314a vkd3d-shader/fx: Print string object entries for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-10 15:14:32 +01:00
Nikolay Sivov
3749171656 vkd3d-shader/fx: Output object initialiser IDs for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-10 15:14:24 +01:00
Giovanni Mascellani
d34f5fbae2 tests/shader_runner: Allow selecting the compiler. 2025-03-10 15:12:45 +01:00
Giovanni Mascellani
5a898254b0 tests/shader_runner: Allow selecting the executor. 2025-03-10 15:12:33 +01:00
Petrichor Park
f05386e006 tests/shader_runner: Allow controlling which shader models to run via command line.
Adds new flags --sm-min and --sm-max. They each take a shader model
identifier, with the same syntax as in the test harness. If either is
present, then it will only run tests within the (inclusive) range.
Omitting one allows anything as the min/max.
2025-03-10 15:12:25 +01:00
Henri Verbeet
2f260a344e build: Get rid of some redundant instances of "checking" in AC_MSG_CHECKING messages.
AC_MSG_CHECKING already prints "checking" itself.
2025-03-10 15:03:23 +01:00
Elizabeth Figura
f4042ba752 vkd3d-shader/hlsl: Add a hlsl_block_add_resource_store() helper. 2025-03-10 14:56:11 +01:00
Elizabeth Figura
e7ff5da5b1 vkd3d-shader/hlsl: Add a hlsl_block_add_index() helper. 2025-03-10 14:56:11 +01:00
Elizabeth Figura
e5cabeafe5 vkd3d-shader/hlsl: Add a hlsl_block_add_loop() helper. 2025-03-10 14:56:11 +01:00
Elizabeth Figura
62196b2bf1 vkd3d-shader/hlsl: Add a hlsl_block_add_if() helper. 2025-03-10 14:56:11 +01:00
Elizabeth Figura
20aa37237d vkd3d-shader/hlsl: Add a hlsl_block_add_jump() helper. 2025-03-10 14:56:11 +01:00
Henri Verbeet
5d55a5894c vkd3d-shader/spirv: Handle "BitEnum" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
00039ba629 vkd3d-shader/spirv: Handle "ValueEnum" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
321154d25a vkd3d-shader/spirv: Handle "LiteralString" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
0e092aef70 vkd3d-shader/spirv: Handle "LiteralInteger" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
8afeb13035 vkd3d-shader/spirv: Handle "IdResultType" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
b9e78f2e2e vkd3d-shader/spirv: Handle "IdResult" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
e83f4f40f9 vkd3d-shader/spirv: Handle "IdRef" operands. 2025-03-10 14:47:03 +01:00
Henri Verbeet
bebc550f02 vkd3d-shader/spirv: Implement outputting opcode names. 2025-03-10 14:47:00 +01:00
Henri Verbeet
997f3f8266 vkd3d-shader/spirv: Implement outputting instruction offsets. 2025-03-10 14:45:06 +01:00
Giovanni Mascellani
8c785f1dc9 vkd3d-shader/spirv: Emit immediate words for unhandled instructions.
The assembler can parse these to reconstruct the original bytecode.
2025-03-10 14:45:06 +01:00
Nikolay Sivov
1417af2eab vkd3d-shader/fx: Add support for parsing numeric states in fx_2_0 passes.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-06 17:21:10 +01:00
Nikolay Sivov
fb76e5daa2 vkd3d-shader/fx: Add support for parsing fx_2_0 parameters.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-06 17:21:10 +01:00
Henri Verbeet
36b8186021 vkd3d-shader/fx: Handle parser failures in fx_parse(). 2025-03-06 17:19:28 +01:00
Henri Verbeet
a6fda3e65d vkd3d-shader/fx: Output error messages for invalid sizes. 2025-03-06 17:19:28 +01:00
Elizabeth Figura
18ca7affad vkd3d-shader/hlsl: Make min16uint into a first-class type.
And properly implement translation into some binary enumerations.
2025-03-06 17:15:15 +01:00
Elizabeth Figura
16be9181a0 vkd3d-shader/hlsl: Pass the correct type to base_type_get_semantic_equivalent(). 2025-03-06 17:15:15 +01:00
Elizabeth Figura
3cf4a4e95e vkd3d-shader/hlsl: Use common hlsl_type_is_integer() and hlsl_base_type_is_integer() helpers. 2025-03-06 17:15:15 +01:00
Elizabeth Figura
bd34ec1fb3 vkd3d-shader/hlsl: Emit the minimum-precision SFI0 flag. 2025-03-06 17:15:15 +01:00
Elizabeth Figura
6cdfe38319 vkd3d-shader/hlsl: Emit minimum-precision signatures. 2025-03-06 17:15:15 +01:00
Elizabeth Figura
c2ca6b6bdf vkd3d-shader/hlsl: Emit the minimum-precision global flag when minimum-precision semantics are used.
There are other things we need to check, but this is a start.
2025-03-06 17:15:15 +01:00
Elizabeth Figura
055625448b vkd3d-shader/hlsl: Add a hlsl_block_add_simple_load() helper. 2025-03-05 14:12:12 +01:00
Elizabeth Figura
d52df527ba vkd3d-shader/hlsl: Add a hlsl_block_add_load_index() helper. 2025-03-05 14:12:12 +01:00
Elizabeth Figura
7b486fe239 vkd3d-shader/hlsl: Return an error expr from hlsl_add_load_component() on allocation failure. 2025-03-05 14:12:12 +01:00
Elizabeth Figura
009f5765df vkd3d-shader/hlsl: Return void from hlsl_block_add_store_component(). 2025-03-05 14:12:12 +01:00
Elizabeth Figura
9e3ac35669 vkd3d-shader/hlsl: Pass the target block to hlsl_new_store_component(). 2025-03-05 14:12:12 +01:00
Henri Verbeet
5ab5a721a1 vkd3d-shader/spirv: Do not sign-extend *ptr in vkd3d_spirv_build_string().
"char" is (potentially) signed, so casting it to uint32_t will
sign-extend it. Because we use |= to assign it to "word", and don't
otherwise mask out the higher bits either, we effectively set subsequent
bytes in the same word to 0xff for input bytes > 0x7f. That potentially
includes the \0 terminator. For example, "é" (U+00e9) is "\xc3\xa9"
when encoded as UTF-8, and would get us 0xffffffc3 instead of
0x0000a9c3.
2025-03-05 14:10:58 +01:00
Nikolay Sivov
871c9c61a5 vkd3d-shader/fx: Fix const strings array types.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-05 14:09:58 +01:00
Nikolay Sivov
1c43b7b55c vkd3d-shader/fx: Add support for parsing fx_2_0 annotations.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-05 14:02:09 +01:00
Nikolay Sivov
db7c22d9d6 vkd3d-shader/fx: Parse technique and pass blocks for fx_2_0.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-05 14:01:53 +01:00
Anna (navi) Figueiredo Gomes
50254c284b vkd3d-shader: Parse angle bracket initializer in state blocks.
While fxc allows full expressions inside the angle brackets, we don't parse that
yet as it'd be quite a mess to properly do so with yacc, and I'm not aware of any
game doing so in their shaders.
2025-03-03 18:00:23 +01:00
Anna (navi) Figueiredo Gomes
9809bda0e5 tests/hlsl: Add angle bracket state block syntax test. 2025-03-03 18:00:23 +01:00
Nikolay Sivov
9f09ac6893 vkd3d-shader/fx: Fix condition when printing literal constant arguments.
To reproduce:

float4 v;

SamplerState s
{
    BorderColor = 0.1 + v*0.2;
};

Expression should use more than one literal constant,
as a scalar in operation that involves a vector.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-03-03 17:54:17 +01:00
Giovanni Mascellani
aa032f31bb vkd3d: Split Vulkan debug messages.
So that they do not get truncated if they're too long.
2025-03-03 17:53:17 +01:00
Elizabeth Figura
e76c596d56 vkd3d-shader/hlsl: Add a hlsl_block_add_simple_store() helper. 2025-03-03 17:48:03 +01:00
Elizabeth Figura
fc4f440245 vkd3d-shader/hlsl: Add a hlsl_block_add_store_index() helper. 2025-03-03 17:48:03 +01:00
Elizabeth Figura
eafc97bcb3 vkd3d-shader/hlsl: Pass the target block to hlsl_new_load_component(). 2025-03-03 17:48:03 +01:00
Elizabeth Figura
d053f3665d vkd3d-shader/hlsl: Pass a block to hlsl_new_void_expr(). 2025-03-03 17:48:03 +01:00
Elizabeth Figura
662d60ad6b vkd3d-shader/hlsl: Add a hlsl_block_add_expr() helper. 2025-03-03 17:48:03 +01:00
Francisco Casas
f24cc55c14 vkd3d-shader/hlsl: Remove lower_nonfloat_exprs().
The only purpose it has at this point is wrapping integer DIV in casts,
which can be moved to lower_division().
2025-03-03 17:47:42 +01:00
Francisco Casas
7cb1970952 vkd3d-shader/hlsl: Don't cast all expressions to float.
Instead, allow half, bool, int, and uint, expressions that map to the
same float op to reach sm1_generate_vsir_instr_expr().
2025-03-03 17:26:15 +01:00
Anna (navi) Figueiredo Gomes
0ce2b1359f tests/hlsl: Add lower sm1 saturate test. 2025-03-03 17:25:20 +01:00
Henri Verbeet
57518d5312 ci: Install libjson-perl. 2025-03-02 17:08:51 +01:00
Giovanni Mascellani
8297ea9aa6 vkd3d/device: Require VK_KHR_zero_initialize_workgroup_memory when appropriate.
That extension (and the corresponding feature) must be enabled when
the Initializer operand is used for workgroup variables.
2025-02-26 16:11:50 +01:00
Nikolay Sivov
e746a4c12f vkd3d-shader/fx: Improve state object nesting for the fx -> text output.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-02-24 16:19:07 +01:00
Nikolay Sivov
09226543fe vkd3d-shader/fx: Implement parsing complex value and index expressions.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-02-24 16:19:07 +01:00
Henri Verbeet
58aed8fd0d vkd3d-shader/fx: Use vkd3d_string_buffer_print_f32() in parse_fx_4_numeric_value().
Instead of "%f". vkd3d_string_buffer_print_f32() will use sufficient
precision to represent the stored value exactly, and will use '.' as
decimal separator regardless of the current locale.
2025-02-24 16:19:07 +01:00
Elizabeth Figura
2989373212 vkd3d-shader/hlsl: Add a hlsl_block_add_binary_expr() helper. 2025-02-24 16:19:07 +01:00
Elizabeth Figura
858b6a3e0b vkd3d-shader/hlsl: Add a hlsl_block_add_cast() helper. 2025-02-24 16:19:07 +01:00
Elizabeth Figura
2e09257d94 vkd3d-shader/hlsl: Add a hlsl_block_add_unary_expr() helper. 2025-02-24 16:19:07 +01:00
Elizabeth Figura
b7ea23303e vkd3d-shader/hlsl: Add a hlsl_block_add_float_constant() helper. 2025-02-24 16:19:07 +01:00
Elizabeth Figura
e830cdee71 vkd3d-shader/hlsl: Inline add_pow_expr().
The helper is used in one place.
2025-02-24 16:19:07 +01:00
Conor McCarthy
439652f023 tests: Replace test_vs_ps_relative_addressing() with a shader runner test.
Besides simply being more compact, this allows the test to cover more
shader types, perhaps most notably DXIL.
2025-02-24 16:19:01 +01:00
Henri Verbeet
1fd89abcc3 vkd3d-shader: Enable DXIL support in the default configuration. 2025-02-24 15:10:08 +01:00
Henri Verbeet
73c0356861 tests: Add a shader model 6 signature reflection test for different types. 2025-02-24 15:10:08 +01:00
Henri Verbeet
fe4143ad19 vkd3d-shader/dxil: Generate I/O signatures with 16-bit component types for native 16-bit shaders.
Which incidentally matches the I/O signatures from the DXBC container.
2025-02-24 15:10:08 +01:00
Henri Verbeet
f5d702b09a vkd3d-shader/dxbc: Validate component types in shader_parse_signature(). 2025-02-24 15:10:08 +01:00
Henri Verbeet
b8d740ebfc vkd3d-shader/dxbc: Output messages for invalid semantic name references in shader_parse_signature(). 2025-02-24 15:10:08 +01:00
Henri Verbeet
3bcdb85ddc vkd3d-shader/dxbc: Set the "elements_capacity" field as well in shader_parse_signature().
Leaving it as 0 mostly ends up doing the right thing in practice, but isn't
quite right.
2025-02-24 15:10:08 +01:00
Giovanni Mascellani
2feb3a3bba vkd3d: Take the root signature from shaders when creating graphics pipelines.
If the root signature wasn't explicitly specified.

This fixes a failure in The Touryst.
2025-02-20 16:00:55 +01:00
Giovanni Mascellani
42b65e80cf tests: Test embedding the root signature in shaders for graphics pipelines. 2025-02-20 15:59:22 +01:00
Henri Verbeet
0796af7b4b vkd3d: Avoid vkd3d_shader_parse_input_signature(). 2025-02-20 15:57:26 +01:00
Henri Verbeet
2e62e9ea7e vkd3d-shader: Handle arrayed elements in vkd3d_shader_signature_from_shader_signature(). 2025-02-20 15:57:26 +01:00
Henri Verbeet
ce5164e26e tests: Add a signature reflection test for arrayed inputs and outputs. 2025-02-20 15:57:26 +01:00
Henri Verbeet
4e28d1c658 vkd3d-shader/dxbc: Do not extract I/O signatures for DXIL shaders.
The DXIL parser doesn't need them.
2025-02-20 15:57:26 +01:00
Henri Verbeet
f4a3d17269 vkd3d-shader/dxil: Avoid using the I/O signatures from the DXBC container.
We currently generate our own I/O signatures inside the DXIL parser, but
use the element counts from the DXBC container signatures to allocate
the input_params/output_params/patch_constant_params arrays. That
happens to work for well-behaved inputs, but it's asking for trouble.
2025-02-20 15:57:26 +01:00
Henri Verbeet
970a1a2b35 vkd3d-shader/dxbc: Update the vkd3d_shader_parse_input_signature() documentation for dxbc-dxil shaders. 2025-02-20 15:57:26 +01:00
Elizabeth Figura
d5a2ff5c12 vkd3d-shader/hlsl: Add a hlsl_block_add_int_constant() helper. 2025-02-20 15:56:31 +01:00
Elizabeth Figura
992d20def3 vkd3d-shader/hlsl: Add a hlsl_block_add_uint_constant() helper. 2025-02-20 15:50:13 +01:00
Elizabeth Figura
79ad8c9354 vkd3d-shader/hlsl: Handle error instructions in hlsl_new_swizzle().
We already check for error instructions when parsing swizzles, but if allocation
fails at codegen time we would like to avoid asserting when subsequently
constructing a swizzle.
2025-02-20 15:49:40 +01:00
Elizabeth Figura
4072aa4a4b vkd3d-shader/hlsl: Remove the type equality assertions in hlsl_new_ternary_expr().
Similar to d1c2ae3f0e, this is a bit too strict
and may prevent e.g. simultaneous use of float and float1 at codegen time.

However, in this case the inciting factor is that in the case of allocation
failure at codegen time, we would like to allow one or more arguments to have
error type.
2025-02-20 15:48:25 +01:00
Elizabeth Figura
ba868ed4a6 vkd3d-shader/hlsl: Skip transformation passes on error.
The primary motivation here is to avoid needing to worry about instructions
potentially pointing to the preallocated error instruction in the case of
allocation failure.

This doesn't cover all passes, but none of the other passes make assumptions
about instruction sources.
2025-02-20 15:48:24 +01:00
Francisco Casas
153b7c8460 vkd3d-shader/hlsl: Run folding passes again after lower_nonconstant_array_loads.
This is because lower_nonconstant_array_loads() can potentially turn
nonconstant loads into constant loads, allowing copy-prop to turn these
loads into previous instructions, which might help other passes as well.

This patch lowers the number of required temps for the following ps_2_0
shader from 19 to 16:

    int i;
    float3x3 mats[4];

    float4 main() : sv_target
    {
        return mul(mats[i], float3(1, 2, 3)).xyzz;
    }
2025-02-20 15:44:09 +01:00
Francisco Casas
e60c89c532 tests: Test unused invalid samples with a static sampler. 2025-02-20 15:44:09 +01:00
Francisco Casas
321fda9c26 vkd3d-shader/hlsl: Only use the temp copy for variables that are written.
This can save a significant amount of temp registers because it allows to
avoid referencing the temp (and having to store it) when not needed.

For instance, this patch lowers the number of required temps for the
following ps_2_0 shader from 24 to 19:

    int i;
    float3x3 mats[4];

    float4 main() : sv_target
    {
        return mul(mats[i], float3(1, 2, 3)).xyzz;
    }

Also, it is needed for SM1 vertex shader relative addressing since
non-constant loads are required to be directly on the uniform ('c'
registers) instead of the temp, and non-constant loads cannot be
transformed by copy propagation.
2025-02-20 15:44:09 +01:00
Elizabeth Figura
8e6ddb0c1a vkd3d-shader/hlsl: Don't mark extern variables with an explicit first_write or last_read.
Fix the last few places that care.
2025-02-20 15:44:09 +01:00
Francisco Casas
1d74ff075e vkd3d-make/hlsl: Trace the number of registers allocated in allocate_temp_registers(). 2025-02-20 15:44:04 +01:00
Nikolay Sivov
f830ac1206 vkd3d-shader/preproc: Do not attempt to load empty included files.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
2025-02-20 15:40:34 +01:00
Giovanni Mascellani
07b7975d09 vkd3d: Put all root descriptors in a single Vulkan descriptor set when using Vulkan heaps.
Since 4a94bfc2f6 we segregate
different D3D12 descriptor types in different Vulkan descriptor sets.
This change was introduced to reduce descriptor wasting when
allocating a new descriptor pool; that can be very useful when
using virtual heaps, which have to often cycle through many
descriptors, but it is expected to have limited impact for Vulkan
heaps, given that in that case most descriptors are allocated through
the descriptor heap rather than through the command allocator.

Instead, it has a rather detrimental effect with Vulkan heaps,
because it tends to use many more Vulkan descriptor sets than
necessary, often with just a handful of descriptors each. This
causes a regression on some Vulkan implementations that support
too few descriptor sets.

With this change we revert to a situation similar to before,
stuffing all the descriptors that do not live in a root
descriptor table in as few descriptor sets as possible (at most
one or two, depending on whether push descriptors are used).
2025-02-19 17:58:23 +01:00
Giovanni Mascellani
6415c6b0e0 vkd3d: Rename push_descriptor_set to root_descriptor_set.
Soon it won't be used necessarily for push descriptors anymore, but
it will still contain root descriptors.
2025-02-19 17:57:15 +01:00
Conor McCarthy
67d8cf744c tests/hlsl: Add a conditional 16-bit test. 2025-02-19 17:53:57 +01:00
Conor McCarthy
36f9510bb3 tests/hlsl: Add interstage interface 16-bit tests. 2025-02-19 17:52:05 +01:00
Conor McCarthy
6ee650f316 tests/hlsl: Add a typed SRV load 16-bit test. 2025-02-19 17:48:38 +01:00
Conor McCarthy
2b325d3b59 tests/hlsl: Add a TGSM 16-bit test. 2025-02-19 17:47:29 +01:00
Conor McCarthy
94b8747da4 tests/hlsl: Add a sampler 16-bit test. 2025-02-19 17:46:05 +01:00
Conor McCarthy
e355cdbae0 tests/hlsl: Add typed buffer SRV 16-bit tests. 2025-02-19 17:44:59 +01:00
Giovanni Mascellani
a7337bc999 vkd3d: Require extension VK_KHR_maintenance2.
We're already implicitly using it for image layouts in which
either depth or stencil is writeable and the other is not.
Correspondingly, add the _KHR suffix in those cases, so the
extension usage is more evident.

According to the Vulkan Hardware Database, only four reports
without this extension were filed since 2023, and all of them
for configurations we likely don't target.
2025-02-19 17:41:30 +01:00
Francisco Casas
604fe3ccee tests/test-driver: Merge the same consecutive tags togeter. 2025-02-19 17:36:19 +01:00
Francisco Casas
681b839419 tests/test-driver: Group together tags in the same line and shader model. 2025-02-19 17:36:19 +01:00
Francisco Casas
72b603780c tests/test-driver: Print the shader model for the detailed output of the hlsl backend. 2025-02-19 17:36:19 +01:00
Francisco Casas
3aecbc5ac1 vkd3d-shader/hlsl: Also dump preprocessed shaders.
This could be useful since there are many shaders that contain `#include`
directives or use parameter-defined macros and we can't reproduce bugs
from the source alone.
2025-02-19 17:34:24 +01:00
Giovanni Mascellani
665c29f0be vkd3d-shader/tpf: Allow I/O index ranges to not intersect a signature element for a given register.
The current TPF validator enforces that for each register involved
in a DCL_INDEX_RANGE instruction there must be a signature element
for that register and the DCL_INDEX_RANGE write mask. This is an
excessively strong request, and causes some shaders from The Falconeer
to be invalidly rejected.

The excessively strong check was needed to avoid triggering a bug
in the I/O normaliser. Since that bug is now solved, the check
can be relaxed.
2025-02-19 17:30:25 +01:00
Giovanni Mascellani
4b84fb486b vkd3d-shader/ir: Handle index ranges that do not touch a signature element for each register.
A good part of the I/O normaliser job is to merge together signature
elements that are spanned by DCL_INDEX_RANGE instructions. The
current algorithm assumes that each index range touches exactly
one signature element for each index spanned by the range. The
assumption is used in shader_signature_merge() in the form of
expecting that, if the index range is N registers long, then,
once you find the first signature element of an index range, the
other elements that will have to be merged with it are exactly the
following N-1 according to the order given by
signature_element_register_compare() or
signature_element_mask_compare(), depending on the signature type.

This doesn't necessarily happen. For example, The Falconeer has a
few hull shaders in which this happens:

    hs_fork_phase
    dcl_hs_fork_phase_instance_count 13
    dcl_input vForkInstanceId
    dcl_output o4.z
    dcl_output o5.z
    dcl_output o6.z
    dcl_output o7.z
    dcl_output o12.z
    dcl_output o13.z
    dcl_output o14.z
    dcl_output o15.z
    dcl_output o16.z
    dcl_output o17.z
    dcl_output o18.z
    dcl_output o19.z
    dcl_output o20.z
    dcl_temps 1
    dcl_index_range o4.z 17
    iadd r0.x, vForkInstanceId.x, l(4)
    ult r0.y, vForkInstanceId.x, l(4)
    movc r0.x, r0.y, vForkInstanceId.x, r0.x
    mov o[r0.x + 4].z, l(0)
    ret

Here the index range "skips" o8.z through o11.z, because those
registers only use mask .xy. The current algorithm fails on such
a shader.

Even depending on the signature element order doesn't look ideal.
I don't have a full counterexample for that, but it looks fragile,
especially given that the register allocation algorithm in FXC is
notoriously full of unexpected corner cases.

We solve both problems by slightly changing the architecture of
the normaliser: first we move computing the masks for the merge
signature element from signature_element_range_expand_mask(),
which is executed while merging signature, to
io_normaliser_add_index_range(), which is executed before merging
signatures. Then, while we are merging signatures, we can decide
for each single signature element whether it has to be retained
or not, and how it should be patched. The algorithm becomes
independent of the order, because each signature element can be
processed individually.
2025-02-19 17:30:00 +01:00
Giovanni Mascellani
b5350f9387 vkd3d-shader/ir: Use a structure to record range data in the I/O normaliser.
In order to make it able to have other fields.
2025-02-19 17:01:54 +01:00
Giovanni Mascellani
ec7bac7ba7 vkd3d-shader/ir: Report errors in the I/O normaliser instead of asserting.
The assumptions the I/O normaliser makes on its input program are
rather intricated. In theory the VSIR validator checks should be
strong enough, but the validator isn't run by default anyway.
Whether the TPF parser validation is strong enough is not
completely clear to me, and considering that the I/O normaliser
could end up being used on different programs as well it's
probably better to revalidate locally just in case.
2025-02-19 17:01:54 +01:00
Giovanni Mascellani
8887501042 tests: Test I/O index ranges not intersecting a signature element for a given register.
Since this test depend on the specific code generated by the
native d3dcompiler we add the possibility to specify a "raw"
shader using a hex format. When the shader assembler is finally
available they should be replaced with assembly code.
2025-02-19 17:01:17 +01:00
Giovanni Mascellani
84a59fe4c0 tests: Enable tessellation shaders in the Vulkan shader runner. 2025-02-19 16:22:04 +01:00
237 changed files with 49278 additions and 12204 deletions

1096
ANNOUNCE

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,182 @@
# What's new in vkd3d 1.17 (21 August 2025)
### libvkd3d
- The EnumerateMetaCommands() method of the ID3D12Device5 interface is
implemented.
### libvkd3d-shader
- Several new features and improvements for the HLSL source type:
- Initial thread group shared memory support.
- Improved support for geometry shaders: shader model 5 multiple output
streams, as well as SV_IsFrontFace, SV_RenderTargetArrayIndex, and
SV_ViewportArrayIndex outputs.
- Structure variable input/output semantics are propagated to the
constituent structure fields.
- Shader entry point return values are allocated before any other outputs
in the output signature. This matches d3dcompiler/fxc more closely.
- Hull shader control point pass-through.
- Reflection information can be retrieved using vkd3d_shader_scan().
- Improved preprocessor handling of comments inside include directives, as
well as inclusion of empty files.
- Memory barrier intrinsics are supported in shader model 4 target
profiles. Previous these were only supported in shader model 5 target
profiles.
- Parser support for the noise() intrinsic. Although the intrinsic itself
isn't implemented, parser support for the intrinsic is required to allow
compilation of any other shaders in the same source file to succeed as
well.
- Parser support for StructuredBuffer resources.
- Various new features and improvements for the effects (FX) source type:
- Shader blob assignments and FXLVM value expressions in fx_2_0 effects.
- Nameless structure types.
- Explicit constant buffer bind points and constant packing offsets.
- The d3ds_noiseswiz, ge, lt, and noise FXLVM operations.
- The experimental Metal Shading Language (MSL) target supports the
following features:
- Texture sampling and gather operations.
- Loops and switches.
- Screen-space partial derivatives.
- Various integer arithmetic and comparison operations.
- Indirect addressing of constant buffers.
- Indexable temporary registers.
- Fragment shader output sample coverage masks.
- SV_Position and SV_SampleIndex fragment shader inputs.
- SV_VertexID inputs.
- When the experimental MSL target is enabled, the dxbc-dxil source type
can be used in combination with the msl target type to convert DXIL
shaders to MSL.
- The new tx source type can be used in combination with the d3d-asm
target type to disassemble D3DX tx_1_0 texture shaders.
- The FX target takes alignment and padding into account in fx_4_0 buffer
size calculations.
- The SPIR-V target is capable of outputting OpSource and OpLine debug
information.
- The core grammar for the experimental SPIR-V disassembler has been updated
to the vulkan-sdk-1.4.313.0 release.
- New interfaces:
- The VKD3D_SHADER_SOURCE_TX source type specifies D3DX tx_1_0 texture
shaders.
### vkd3d-compiler
- The new tx source type specifies D3DX tx_1_0 texture shaders.
### demos
- The new vkd3d-teapot demo uses tessellation shaders to render a version of
Martin Newell's famous teapot. It should be noted that current versions of
MoltenVK unfortunately do not support all features required to execute
this demo correctly.
# What's new in vkd3d 1.16 (20 May 2025)
### libvkd3d
- DXIL shaders are supported in the default configuration. Previously this
required building vkd3d with the -DVKD3D_SHADER_UNSUPPORTED_DXIL
preprocessor option. The also raises the maximum supported shader model to
version 6.0.
- Graphics pipeline state objects can be created from shaders with embedded
root signatures. This was already possible for compute pipeline state
objects.
- The SetEventOnMultipleFenceCompletion() method of the ID3D12Device1
interface is implemented.
- When the VK_KHR_zero_initialize_workgroup_memory extension is supported,
libvkd3d supports zero-initialising compute shader thread group shared
memory.
- The VK_KHR_maintenance2 extension is now explicitly required. libvkd3d
already unconditionally used features provided by this extension, but
unfortunately didn't explicitly require it. Support for this extension is
widespread, and the extension is part of Vulkan 1.1.
### libvkd3d-shader
- The previously experimental support for compiling DXIL shaders is now a
supported feature and enabled by default. Please note that this feature is
nevertheless still far from perfect.
- New features for the HLSL source type:
- Initial support for geometry shaders.
- Indirect addressing in shader model 1-3 target profiles.
- Modulus and truncation operations in shader model 1-3 target profiles.
- Vectorised output code.
- Further improved constant folding and propagation.
- The following intrinsic functions are supported:
- AllMemoryBarrier()
- AllMemoryBarrierWithGroupSync()
- DeviceMemoryBarrier()
- DeviceMemoryBarrierWithGroupSync()
- GroupMemoryBarrier()
- GroupMemoryBarrierWithGroupSync()
- The .Length Texture object property.
- The SV_RenderTargetArrayIndex and SV_ViewportArrayIndex semantics in
tessellation shaders.
- Disassembler support for binary fx_2_0 effects.
- Experimental built-in support for disassembling SPIR-V shaders, enabled by
building vkd3d with the -DVKD3D_SHADER_UNSUPPORTED_SPIRV_PARSER
preprocessor option. When enabled, the built-in SPIR-V disassembler is
used instead of SPIRV-Tools for the spirv-text target type, as well as
for the debug output enabled by the VKD3D_SHADER_DEBUG environment
variable.
- The experimental OpenGL Shading Language (GLSL) target supports indirect
addressing of constant buffers.
- The experimental Metal Shading Language (MSL) target supports texture
loads.
- New interfaces:
- The VKD3D_SHADER_COMPILE_OPTION_FEATURE_ZERO_INITIALIZE_WORKGROUP_MEMORY
flag indicates support for zero-initialising workgroup memory in the
SPIR-V target environment.
- The VKD3D_SHADER_COMPONENT_INT64 enumeration value indicates a 64-bit
signed integer value.
- The VKD3D_SHADER_COMPONENT_FLOAT16 enumeration value indicates a 16-bit
IEEE floating-point value.
- The VKD3D_SHADER_COMPONENT_UINT16 enumeration value indicates a 16-bit
unsigned integer value.
- The VKD3D_SHADER_COMPONENT_INT16 enumeration value indicates a 16-bit
signed integer value.
- When targeting VKD3D_SHADER_API_1_16, the
VKD3D_SHADER_RESOURCE_DATA_NONE enumeration value is returned for the
resource_data_type field in the vkd3d_shader_descriptor_info structure
for sampler descriptors. VKD3D_SHADER_API_1_15 and before use the
VKD3D_SHADER_RESOURCE_DATA_UINT enumeration value for this.
### demos
- The vkd3d demos now work on both the Microsoft Windows and Apple macOS
builds. The macOS versions of the vkd3d demos are completely new in vkd3d
1.16, while the Windows demos could previously be built, but only worked
on Wine. Note that the vkd3d demos produced by a Windows build of vkd3d
are distinct from those produced by the make crosstest target: the
former are Vulkan applications using vkd3d, while the latter are Direct3D
12 applications.
- The vkd3d demos have basic support for DPI scaling.
### build
- Perl and the JSON Perl module have been added as build dependencies.
These are used for the experimental built-in SPIR-V disassembler, as well
as for the macOS versions of the vkd3d demos.
# What's new in vkd3d 1.15 (19 February 2025)
### libvkd3d

View File

@@ -2,6 +2,12 @@ ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = @VKD3D_CFLAGS@
AM_CPPFLAGS = -I$(srcdir)/include -I$(srcdir)/include/private -I$(builddir)/include/private
AM_LDFLAGS = -no-undefined
VKD3D_PERL = $(PERL) -w
objc_headers = \
include/private/appkit.h \
include/private/foundation.h \
include/private/quartzcore.h
widl_headers = \
include/vkd3d_d3d12.h \
@@ -63,6 +69,7 @@ vkd3d_shader_tests = \
tests/hlsl/asint.shader_test \
tests/hlsl/asuint.shader_test \
tests/hlsl/attributes.shader_test \
tests/hlsl/barriers.shader_test \
tests/hlsl/bitwise-assignment.shader_test \
tests/hlsl/bitwise.shader_test \
tests/hlsl/bool-cast.shader_test \
@@ -108,6 +115,7 @@ vkd3d_shader_tests = \
tests/hlsl/effect-compile.shader_test \
tests/hlsl/effect-initial-values-fx_2.shader_test \
tests/hlsl/effect-initial-values-fx_4.shader_test \
tests/hlsl/effect-pass-states-fx_4.shader_test \
tests/hlsl/effect-pass-states-fx_5.shader_test \
tests/hlsl/effect-shader-objects-fx_2.shader_test \
tests/hlsl/effect-shader-objects-fx_5.shader_test \
@@ -116,6 +124,7 @@ vkd3d_shader_tests = \
tests/hlsl/effect-technique-fx_5.shader_test \
tests/hlsl/effect-variables-fx_2.shader_test \
tests/hlsl/effect-variables-fx_4.shader_test \
tests/hlsl/effect-variables-fx_4_1.shader_test \
tests/hlsl/effect-variables-fx_5.shader_test \
tests/hlsl/entry-point-semantics.shader_test \
tests/hlsl/eval-attrib.shader_test \
@@ -124,11 +133,11 @@ vkd3d_shader_tests = \
tests/hlsl/f16tof32.shader_test \
tests/hlsl/f32tof16.shader_test \
tests/hlsl/faceforward.shader_test \
tests/hlsl/fog.shader_test \
tests/hlsl/ffp-point-size.shader_test \
tests/hlsl/float-comparison.shader_test \
tests/hlsl/floor.shader_test \
tests/hlsl/fmod.shader_test \
tests/hlsl/fog.shader_test \
tests/hlsl/for.shader_test \
tests/hlsl/frac.shader_test \
tests/hlsl/function-cast.shader_test \
@@ -140,6 +149,7 @@ vkd3d_shader_tests = \
tests/hlsl/gather-cmp.shader_test \
tests/hlsl/gather-offset.shader_test \
tests/hlsl/gather.shader_test \
tests/hlsl/geometry-shader-syntax.shader_test \
tests/hlsl/geometry.shader_test \
tests/hlsl/get-sample-pos.shader_test \
tests/hlsl/getdimensions.shader_test \
@@ -166,6 +176,7 @@ vkd3d_shader_tests = \
tests/hlsl/is-front-face.shader_test \
tests/hlsl/isinf.shader_test \
tests/hlsl/ldexp.shader_test \
tests/hlsl/length-property.shader_test \
tests/hlsl/length.shader_test \
tests/hlsl/lerp.shader_test \
tests/hlsl/lhs-cast.shader_test \
@@ -188,6 +199,7 @@ vkd3d_shader_tests = \
tests/hlsl/multiple-rt.shader_test \
tests/hlsl/nested-arrays.shader_test \
tests/hlsl/nointerpolation.shader_test \
tests/hlsl/noise.shader_test \
tests/hlsl/non-const-indexing.shader_test \
tests/hlsl/normalize.shader_test \
tests/hlsl/null.shader_test \
@@ -198,10 +210,13 @@ vkd3d_shader_tests = \
tests/hlsl/object-parameters.shader_test \
tests/hlsl/object-references.shader_test \
tests/hlsl/patch-syntax.shader_test \
tests/hlsl/pixel-position.shader_test \
tests/hlsl/point-sprite.shader_test \
tests/hlsl/pointer-cast.shader_test \
tests/hlsl/pow.shader_test \
tests/hlsl/precise-modifier.shader_test \
tests/hlsl/primitive-id.shader_test \
tests/hlsl/ps1-sampler.shader_test \
tests/hlsl/rasteriser-ordered-views.shader_test \
tests/hlsl/rcp.shader_test \
tests/hlsl/reflect.shader_test \
@@ -211,6 +226,7 @@ vkd3d_shader_tests = \
tests/hlsl/register-reservations-resources.shader_test \
tests/hlsl/register-reservations-space.shader_test \
tests/hlsl/return-implicit-conversion.shader_test \
tests/hlsl/return-semantics.shader_test \
tests/hlsl/return.shader_test \
tests/hlsl/round.shader_test \
tests/hlsl/rt-array-index.shader_test \
@@ -225,6 +241,7 @@ vkd3d_shader_tests = \
tests/hlsl/sampler.shader_test \
tests/hlsl/saturate.shader_test \
tests/hlsl/scope.shader_test \
tests/hlsl/semantic-cascading.shader_test \
tests/hlsl/shade-mode.shader_test \
tests/hlsl/shader-interstage-interface.shader_test \
tests/hlsl/shader-point-size.shader_test \
@@ -241,6 +258,7 @@ vkd3d_shader_tests = \
tests/hlsl/sqrt.shader_test \
tests/hlsl/srv-buffers.shader_test \
tests/hlsl/srv-byteaddressbuffer.shader_test \
tests/hlsl/srv-structuredbuffer.shader_test \
tests/hlsl/state-block-function-syntax.shader_test \
tests/hlsl/state-block-syntax.shader_test \
tests/hlsl/static-initializer.shader_test \
@@ -251,6 +269,7 @@ vkd3d_shader_tests = \
tests/hlsl/struct-assignment.shader_test \
tests/hlsl/struct-inheritance.shader_test \
tests/hlsl/struct-semantics.shader_test \
tests/hlsl/struct-syntax.shader_test \
tests/hlsl/switch.shader_test \
tests/hlsl/swizzle-constant-prop.shader_test \
tests/hlsl/swizzle-matrix.shader_test \
@@ -285,6 +304,7 @@ vkd3d_shader_tests = \
tests/hlsl/vector-indexing-uniform.shader_test \
tests/hlsl/vector-indexing.shader_test \
tests/hlsl/vertex-shader-ops.shader_test \
tests/hlsl/vp-array-index.shader_test \
tests/hlsl/wave-ops-float.shader_test \
tests/hlsl/wave-ops-int.shader_test \
tests/hlsl/wave-ops-uint.shader_test \
@@ -311,14 +331,19 @@ vkd3d_test_headers = \
vkd3d_demos = \
demos/vkd3d-gears \
demos/vkd3d-teapot \
demos/vkd3d-triangle
vkd3d_demos_headers = \
demos/demo.h \
demos/demo_d3d12.h \
demos/demo_macos.h \
demos/demo_vkd3d.h \
demos/demo_win32.h \
demos/demo_xcb.h
BUILT_SOURCES = $(widl_headers) \
BUILT_SOURCES = $(objc_headers) $(widl_headers) \
include/private/spirv_grammar.h \
include/private/vkd3d_version.h
noinst_LTLIBRARIES = libvkd3d-common.la
@@ -377,6 +402,7 @@ nodist_libvkd3d_shader_la_SOURCES = $(vkd3d_shader_yyfiles)
libvkd3d_shader_la_SOURCES = \
include/private/list.h \
include/private/rbtree.h \
include/private/spirv_grammar.h \
include/private/vkd3d_common.h \
include/private/vkd3d_memory.h \
include/vkd3d_shader.h \
@@ -400,7 +426,7 @@ libvkd3d_shader_la_SOURCES = \
libs/vkd3d-shader/vkd3d_shader_main.c \
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_LDFLAGS = $(AM_LDFLAGS) -version-info 14:0:13
libvkd3d_shader_la_LDFLAGS = $(AM_LDFLAGS) -version-info 16:0:15
libvkd3d_shader_la_LIBADD = libvkd3d-common.la @SPIRV_TOOLS_LIBS@ -lm
if HAVE_LD_VERSION_SCRIPT
libvkd3d_shader_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-shader/vkd3d_shader.map
@@ -435,7 +461,7 @@ libvkd3d_la_SOURCES = \
libs/vkd3d/vkd3d_shaders.h \
libs/vkd3d/vulkan_procs.h
libvkd3d_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_SOURCE
libvkd3d_la_LDFLAGS = $(AM_LDFLAGS) -version-info 16:0:15
libvkd3d_la_LDFLAGS = $(AM_LDFLAGS) -version-info 18:0:17
libvkd3d_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la @DL_LIBS@ @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT
libvkd3d_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d/vkd3d.map
@@ -448,7 +474,7 @@ libvkd3d_utils_la_SOURCES = \
libs/vkd3d-utils/vkd3d_utils_main.c \
libs/vkd3d-utils/vkd3d_utils_private.h
libvkd3d_utils_la_CFLAGS = $(AM_CFLAGS) -DLIBVKD3D_UTILS_SOURCE
libvkd3d_utils_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:1:6
libvkd3d_utils_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:3:6
libvkd3d_utils_la_LIBADD = libvkd3d-common.la libvkd3d-shader.la libvkd3d.la @PTHREAD_LIBS@
if HAVE_LD_VERSION_SCRIPT
libvkd3d_utils_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libs/vkd3d-utils/vkd3d_utils.map
@@ -513,7 +539,7 @@ tests_vkd3d_api_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
tests_vkd3d_api_LDADD = libvkd3d.la @DL_LIBS@
tests_vkd3d_shader_api_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
tests_vkd3d_shader_api_CFLAGS = $(AM_CFLAGS) @OPENGL_CFLAGS@
tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la @OPENGL_LIBS@
tests_vkd3d_shader_api_LDADD = libvkd3d-shader.la @OPENGL_LIBS@ @DL_LIBS@
SHADER_TEST_LOG_COMPILER = tests/shader_runner
SHADER_TEST_LOG_DRIVER = $(srcdir)/tests/test-driver.sh
endif
@@ -521,8 +547,8 @@ endif
EXTRA_DIST += $(vkd3d_shader_tests)
if BUILD_DEMOS
DEMOS_LDADD = $(LDADD) libvkd3d-shader.la @DL_LIBS@ @DEMO_LIBS@
DEMOS_CFLAGS = $(AM_CFLAGS) @DEMO_CFLAGS@ -Wa,-I$(srcdir)/demos
DEMOS_LDADD = $(LDADD) @DL_LIBS@ @DEMO_LIBS@
DEMOS_CFLAGS = $(AM_CFLAGS) @DEMO_CFLAGS@ -I$(srcdir)/demos -Wa,-I$(srcdir)/demos
bin_PROGRAMS += $(vkd3d_demos)
demos_vkd3d_gears_SOURCES = demos/gears.c demos/gears.hlsl
@@ -530,6 +556,18 @@ demos_vkd3d_gears_CFLAGS = $(DEMOS_CFLAGS)
demos_vkd3d_gears_LDADD = $(DEMOS_LDADD) -lm
demos/vkd3d_gears-gears.$(OBJEXT): demos/gears.hlsl
teapot_shaders = \
demos/teapot.hlsl \
demos/text.hlsl
demos_vkd3d_teapot_SOURCES = \
$(teapot_shaders) \
demos/etl16-unicode.h \
demos/teapot.c \
demos/teapot.h
demos_vkd3d_teapot_CFLAGS = $(DEMOS_CFLAGS)
demos_vkd3d_teapot_LDADD = $(DEMOS_LDADD) -lm
demos/vkd3d_teapot-teapot.$(OBJEXT): $(teapot_shaders)
demos_vkd3d_triangle_SOURCES = demos/triangle.c demos/triangle.hlsl
demos_vkd3d_triangle_CFLAGS = $(DEMOS_CFLAGS)
demos_vkd3d_triangle_LDADD = $(DEMOS_LDADD)
@@ -537,6 +575,17 @@ demos/vkd3d_triangle-triangle.$(OBJEXT): demos/triangle.hlsl
endif
noinst_HEADERS = $(vkd3d_test_headers) $(vkd3d_demos_headers)
dist_noinst_SCRIPTS = libs/vkd3d-shader/make_spirv demos/make_objc
VKD3D_V_PERL = $(vkd3d_v_perl_@AM_V@)
vkd3d_v_perl_ = $(vkd3d_v_perl_@AM_DEFAULT_V@)
vkd3d_v_perl_0 = @echo " PERL " $@;
vkd3d_v_perl_1 =
CLEANFILES += $(objc_headers)
${objc_headers}: %.h: demos/make_objc %.json
@$(MKDIR_P) $(@D)
$(VKD3D_V_PERL)$(VKD3D_PERL) $^ > $@.tmp && mv $@.tmp $@
VKD3D_V_WIDL = $(vkd3d_v_widl_@AM_V@)
vkd3d_v_widl_ = $(vkd3d_v_widl_@AM_DEFAULT_V@)
@@ -546,7 +595,11 @@ vkd3d_v_widl_1 =
if HAVE_WIDL
CLEANFILES += $(widl_headers)
endif
EXTRA_DIST += $(widl_headers) $(widl_headers:.h=.idl)
EXTRA_DIST += \
$(widl_headers) \
$(widl_headers:.h=.idl) \
$(objc_headers:.h=.json) \
include/private/spirv.core.grammar.json
$(widl_headers): %.h: %.idl
if HAVE_WIDL
$(VKD3D_V_WIDL)$(WIDL) -I$(srcdir)/include -h -o $@ $<
@@ -578,6 +631,10 @@ libvkd3d.pc: $(srcdir)/libs/vkd3d/libvkd3d.pc.in Makefile
-e 's![@]PACKAGE_VERSION[@]!$(PACKAGE_VERSION)!g' \
$< > $@
include/private/spirv_grammar.h: libs/vkd3d-shader/make_spirv include/private/spirv.core.grammar.json
@$(MKDIR_P) $(@D)
$(VKD3D_V_PERL)$(VKD3D_PERL) $^ > $@.tmp && mv $@.tmp $@
include/private/vkd3d_version.h: dummy-vkd3d-version
@$(MKDIR_P) include/private
version=`(GIT_DIR=$(top_srcdir)/.git git rev-parse --short HEAD 2>/dev/null || echo '') \
@@ -586,7 +643,7 @@ include/private/vkd3d_version.h: dummy-vkd3d-version
&& (echo $$version | cmp -s - $@) \
|| echo $$version >$@ || ($(RM) $@ && exit 1)
.SILENT: include/private/vkd3d_version.h
CLEANFILES += include/private/vkd3d_version.h
CLEANFILES += include/private/spirv_grammar.h include/private/vkd3d_version.h
.PHONY: dummy-vkd3d-version
dummy-vkd3d-version:
@@ -619,6 +676,7 @@ endif
if BUILD_DEMOS
CROSS32_EXEFILES += $(vkd3d_demos:demos/vkd3d-%=demos/%.cross32.exe)
demos/gears.cross32.exe: demos/gears.hlsl
demos/teapot.cross32.exe: $(teapot_shaders)
demos/triangle.cross32.exe: demos/triangle.hlsl
endif
@@ -668,6 +726,7 @@ endif
if BUILD_DEMOS
CROSS64_EXEFILES += $(vkd3d_demos:demos/vkd3d-%=demos/%.cross64.exe)
demos/gears.cross64.exe: demos/gears.hlsl
demos/teapot.cross64.exe: $(teapot_shaders)
demos/triangle.cross64.exe: demos/triangle.hlsl
endif

9
README
View File

@@ -9,7 +9,8 @@ similar, but not identical, to Direct3D 12.
Building vkd3d
==============
Vkd3d depends on SPIRV-Headers and Vulkan-Headers (>= 1.3.228).
Vkd3d depends on SPIRV-Headers and Vulkan-Headers (>= 1.3.228), as well as Perl
and libjson-perl.
Vkd3d generates some of its headers from IDL files. If you are using the
release tarballs, then these headers are pre-generated and are included. If
@@ -149,12 +150,6 @@ in future versions of vkd3d.
emitted; this can be useful for developers to make error conditions as
conspicuous as possible.
* VKD3D_SHADER_UNSUPPORTED_DXIL - enable DXIL (DirectX Intermediate Language)
support in vkd3d-shader, which is disabled by default because it is not
considered ready for release yet. Please note that this feature is not
currently supported, and it might change in a non-compatible way before it is
released.
* VKD3D_SHADER_UNSUPPORTED_GLSL - enable GLSL (GL Shading Language) support in
vkd3d-shader, which is disabled by default because it is not considered ready
for release yet. Please note that this feature is not currently supported,

View File

@@ -1,10 +1,11 @@
AC_PREREQ([2.69])
AC_INIT([vkd3d],[1.15])
AC_INIT([vkd3d],[1.17])
AC_CONFIG_AUX_DIR([bin])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS(include/config.h)
AC_ARG_VAR([PERL], [The Perl 5 language interpreter])
AC_ARG_VAR([WIDL], [widl IDL compiler])
AC_ARG_VAR([CROSSCC32], [32-bit Windows cross compiler])
AC_ARG_VAR([CROSSCC64], [64-bit Windows cross compiler])
@@ -32,6 +33,11 @@ AC_PROG_MKDIR_P
VKD3D_PROG_WIDL(3, 21)
AS_IF([test "x$WIDL" = "xno"], [AC_MSG_WARN([widl is required to build header files.])])
AC_CHECK_PROGS([PERL], [perl], [none])
AS_IF([test "$PERL" = "none"], [AC_MSG_ERROR([no suitable perl found. Please install the 'perl-base' package.])])
VKD3D_CHECK_PERL_MODULE([JSON],
[AC_MSG_ERROR([perl module 'JSON' not found. Please install the 'libjson-perl' package.])])
AC_CHECK_PROGS([FLEX], [flex], [none])
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])
@@ -178,15 +184,20 @@ AC_CHECK_FUNCS([pthread_threadid_np])
dnl Makefiles
case $host_os in
mingw32*)
AC_SUBST([DEMO_LIBS],["-ld3d12 -ldxgi -lgdi32"])
AC_SUBST([DEMO_LIBS],["-lgdi32"])
AC_SUBST([DEMO_CFLAGS],["-municode"])
;;
darwin*)
AC_SUBST([DEMO_LIBS],["-framework Foundation -framework AppKit -framework QuartzCore"])
AC_SUBST([DEMO_CFLAGS],[""])
;;
*) AS_IF([test "x$enable_demos" = "xyes" -a "x$HAVE_XCB" != "xyes"],
[AC_MSG_ERROR([libxcb is required for demos.])])
AC_SUBST([DEMO_LIBS],[$XCB_LIBS])
AC_SUBST([DEMO_CFLAGS],[$XCB_CFLAGS])
;;
esac
VKD3D_CHECK_CFLAGS([-fno-lto], [DEMO_CFLAGS="$DEMO_CFLAGS -fno-lto"])
AM_CONDITIONAL([BUILD_DEMOS], [test "x$enable_demos" = "xyes"])
AM_CONDITIONAL([BUILD_DOC], [test $DX_FLAG_doc = 1])
AM_CONDITIONAL([BUILD_TESTS], [test "x$enable_tests" != "xno"])

View File

@@ -38,18 +38,23 @@
#define COBJMACROS
#include <vkd3d_d3d12.h>
#include <inttypes.h>
#include <math.h>
#ifdef __WIN32__
#define DEMO_ASM_PUSHSECTION ".section rdata\n\t"
#define DEMO_ASM_POPSECTION ".text\n\t"
#define DEMO_ASM_OBJECT_TYPE(name)
#elif defined(__APPLE__)
#define DEMO_ASM_PUSHSECTION ".pushsection __TEXT,__const\n\t"
#define DEMO_ASM_POPSECTION ".popsection\n\t"
#define DEMO_ASM_OBJECT_TYPE(name)
#else
#define DEMO_ASM_PUSHSECTION ".pushsection .rodata\n\t"
#define DEMO_ASM_POPSECTION ".popsection\n\t"
#define DEMO_ASM_OBJECT_TYPE(name) ".type "name", @object\n\t"
#endif
#if defined(__WIN32__) && defined(__i386__)
#if (defined(__WIN32__) && defined(__i386__)) || defined(__APPLE__)
#define DEMO_ASM_NAME(name) "_"#name
#else
#define DEMO_ASM_NAME(name) #name
@@ -75,14 +80,27 @@
extern const uint8_t name[]; \
__asm__(DEMO_EMBED_ASM(DEMO_ASM_NAME(name), file))
#if defined(__GNUC__) || defined(__clang__)
# ifdef __MINGW_PRINTF_FORMAT
# define DEMO_PRINTF_FUNC(fmt, args) __attribute__((format(__MINGW_PRINTF_FORMAT, fmt, args)))
# else
# define DEMO_PRINTF_FUNC(fmt, args) __attribute__((format(printf, fmt, args)))
# endif
#else
# define DEMO_PRINTF_FUNC(fmt, args)
#endif
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*x))
#define DEMO_KEY_UNKNOWN 0x0000
#define DEMO_KEY_ESCAPE 0xff1b
#define DEMO_KEY_LEFT 0xff51
#define DEMO_KEY_UP 0xff52
#define DEMO_KEY_RIGHT 0xff53
#define DEMO_KEY_DOWN 0xff54
#define DEMO_KEY_UNKNOWN 0x0000
#define DEMO_KEY_ESCAPE 0xff1b
#define DEMO_KEY_LEFT 0xff51
#define DEMO_KEY_UP 0xff52
#define DEMO_KEY_RIGHT 0xff53
#define DEMO_KEY_DOWN 0xff54
#define DEMO_KEY_KP_ADD 0xffab
#define DEMO_KEY_KP_SUBTRACT 0xffad
#define DEMO_KEY_F1 0xffbe
struct demo_vec3
{
@@ -94,6 +112,26 @@ struct demo_vec4
float x, y, z, w;
};
struct demo_uvec2
{
uint32_t x, y;
};
struct demo_uvec4
{
uint32_t x, y, z, w;
};
struct demo_matrix
{
float m[4][4];
};
struct demo_patch
{
uint16_t p[4][4];
};
struct demo_swapchain_desc
{
unsigned int width;
@@ -111,6 +149,36 @@ static inline void demo_vec3_set(struct demo_vec3 *v, float x, float y, float z)
v->z = z;
}
static inline void demo_vec3_subtract(struct demo_vec3 *v, const struct demo_vec3 *a, const struct demo_vec3 *b)
{
demo_vec3_set(v, a->x - b->x, a->y - b->y, a->z - b->z);
}
static inline float demo_vec3_dot(const struct demo_vec3 *a, const struct demo_vec3 *b)
{
return a->x * b->x + a->y * b->y + a->z * b->z;
}
static inline float demo_vec3_length(const struct demo_vec3 *v)
{
return sqrtf(demo_vec3_dot(v, v));
}
static inline void demo_vec3_scale(struct demo_vec3 *v, const struct demo_vec3 *a, float s)
{
demo_vec3_set(v, a->x * s, a->y * s, a->z *s);
}
static inline void demo_vec3_normalise(struct demo_vec3 *v, const struct demo_vec3 *a)
{
demo_vec3_scale(v, a, 1.0f / demo_vec3_length(a));
}
static inline void demo_vec3_cross(struct demo_vec3 *v, const struct demo_vec3 *a, const struct demo_vec3 *b)
{
demo_vec3_set(v, a->y * b->z - a->z * b->y, a->z * b->x - a->x * b->z, a->x * b->y - a->y * b->x);
}
static inline void demo_vec4_set(struct demo_vec4 *v, float x, float y, float z, float w)
{
v->x = x;
@@ -119,6 +187,60 @@ static inline void demo_vec4_set(struct demo_vec4 *v, float x, float y, float z,
v->w = w;
}
static inline void demo_matrix_look_at_rh(struct demo_matrix *m, const struct demo_vec3 *eye,
const struct demo_vec3 *ref, const struct demo_vec3 *up)
{
struct demo_vec3 f, s, t, u;
demo_vec3_subtract(&f, eye, ref);
demo_vec3_normalise(&f, &f);
demo_vec3_cross(&s, up, &f);
demo_vec3_normalise(&s, &s);
demo_vec3_cross(&u, &f, &s);
demo_vec3_set(&t, demo_vec3_dot(&s, eye), demo_vec3_dot(&u, eye), demo_vec3_dot(&f, eye));
*m = (struct demo_matrix)
{{
{ s.x, u.x, f.x, 0.0f},
{ s.y, u.y, f.y, 0.0f},
{ s.z, u.z, f.z, 0.0f},
{-t.x, -t.y, -t.z, 1.0f},
}};
}
static inline void demo_matrix_multiply(struct demo_matrix *out,
const struct demo_matrix *a, const struct demo_matrix *b)
{
unsigned int i, j;
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
out->m[i][j] = a->m[i][0] * b->m[0][j]
+ a->m[i][1] * b->m[1][j]
+ a->m[i][2] * b->m[2][j]
+ a->m[i][3] * b->m[3][j];
}
}
}
static inline void demo_matrix_perspective_rh(struct demo_matrix *m, float w, float h, float z_near, float z_far)
{
float sx = 2.0 * z_near / w;
float sy = 2.0 * z_near / h;
float sz = z_far / (z_near - z_far);
float d = z_near * sz;
*m = (struct demo_matrix)
{{
{ sx, 0.0f, 0.0f, 0.0f},
{0.0f, sy, 0.0f, 0.0f},
{0.0f, 0.0f, sz, -1.0f},
{0.0f, 0.0f, d, 0.0f},
}};
}
static inline void demo_rasterizer_desc_init_default(D3D12_RASTERIZER_DESC *desc)
{
desc->FillMode = D3D12_FILL_MODE_SOLID;
@@ -174,9 +296,11 @@ static inline HRESULT demo_create_root_signature(ID3D12Device *device,
return hr;
}
#ifdef _WIN32
#include "demo_win32.h"
#ifdef VKD3D_CROSSTEST
#include "demo_d3d12.h"
#else
#define INFINITE VKD3D_INFINITE
#include "demo_xcb.h"
# ifndef _WIN32
# define INFINITE VKD3D_INFINITE
# endif
#include "demo_vkd3d.h"
#endif

261
demos/demo_d3d12.h Normal file
View File

@@ -0,0 +1,261 @@
/*
* Copyright 2016 Józef Kucia for CodeWeavers
* Copyright 2016 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <vkd3d_dxgi1_4.h>
#include <vkd3d_d3dcompiler.h>
#include <stdbool.h>
#include <stdio.h>
struct demo_win32
{
UINT (*GetDpiForSystem)(void);
};
struct demo
{
union
{
struct demo_win32 win32;
} u;
size_t window_count;
void *user_data;
void (*idle_func)(struct demo *demo, void *user_data);
};
struct demo_window
{
struct demo *demo;
void *user_data;
void (*expose_func)(struct demo_window *window, void *user_data);
void (*key_press_func)(struct demo_window *window, demo_key key, void *user_data);
};
static inline bool demo_window_init(struct demo_window *window, struct demo *demo, void *user_data)
{
window->demo = demo;
window->user_data = user_data;
window->expose_func = NULL;
window->key_press_func = NULL;
++demo->window_count;
return true;
}
static inline void demo_window_cleanup(struct demo_window *window)
{
--window->demo->window_count;
}
#include "demo_win32.h"
struct demo_swapchain
{
IDXGISwapChain3 *swapchain;
unsigned int buffer_count;
char device_name[128];
};
static inline void demo_cleanup(struct demo *demo)
{
demo_win32_cleanup(demo);
}
static inline bool demo_init(struct demo *demo, void *user_data)
{
if (!demo_win32_init(&demo->u.win32))
{
fprintf(stderr, "Failed to initialise demo.\n");
return false;
}
demo->window_count = 0;
demo->user_data = user_data;
demo->idle_func = NULL;
return true;
}
static inline void demo_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
{
demo_win32_get_dpi(demo, dpi_x, dpi_y);
}
static inline const char *demo_get_platform_name(void)
{
return "Direct3D 12";
}
static inline void demo_process_events(struct demo *demo)
{
demo_win32_process_events(demo);
}
static inline void demo_set_idle_func(struct demo *demo,
void (*idle_func)(struct demo *demo, void *user_data))
{
demo->idle_func = idle_func;
}
static inline void demo_window_destroy(struct demo_window *window)
{
demo_window_win32_destroy(window);
}
static inline struct demo_window *demo_window_create(struct demo *demo, const char *title,
unsigned int width, unsigned int height, void *user_data)
{
return demo_window_win32_create(demo, title, width, height, user_data);
}
static inline void demo_window_set_expose_func(struct demo_window *window,
void (*expose_func)(struct demo_window *window, void *user_data))
{
window->expose_func = expose_func;
}
static inline void demo_window_set_key_press_func(struct demo_window *window,
void (*key_press_func)(struct demo_window *window, demo_key key, void *user_data))
{
window->key_press_func = key_press_func;
}
static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *command_queue,
struct demo_window *window, const struct demo_swapchain_desc *desc)
{
struct demo_window_win32 *window_win32 = CONTAINING_RECORD(window, struct demo_window_win32, w);
DXGI_SWAP_CHAIN_DESC1 swapchain_desc;
struct demo_swapchain *swapchain;
DXGI_ADAPTER_DESC adapter_desc;
IDXGISwapChain1 *swapchain1;
IDXGIFactory2 *factory;
IDXGIAdapter *adapter;
ID3D12Device *device;
unsigned int i;
HRESULT hr;
LUID luid;
if (!(swapchain = malloc(sizeof(*swapchain))))
return NULL;
if (FAILED(CreateDXGIFactory1(&IID_IDXGIFactory2, (void **)&factory)))
goto fail;
if (FAILED(ID3D12CommandQueue_GetDevice(command_queue, &IID_ID3D12Device, (void **)&device)))
goto fail;
luid = ID3D12Device_GetAdapterLuid(device);
ID3D12Device_Release(device);
sprintf(swapchain->device_name, "Unknown");
for (i = 0; IDXGIFactory2_EnumAdapters(factory, i, &adapter) == S_OK; ++i)
{
hr = IDXGIAdapter_GetDesc(adapter, &adapter_desc);
IDXGIAdapter_Release(adapter);
if (FAILED(hr))
continue;
if (adapter_desc.AdapterLuid.LowPart == luid.LowPart
&& adapter_desc.AdapterLuid.HighPart == luid.HighPart)
{
snprintf(swapchain->device_name, ARRAY_SIZE(swapchain->device_name), "%ls", adapter_desc.Description);
break;
}
}
memset(&swapchain_desc, 0, sizeof(swapchain_desc));
swapchain_desc.BufferCount = desc->buffer_count;
swapchain_desc.Width = desc->width;
swapchain_desc.Height = desc->height;
swapchain_desc.Format = desc->format;
swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapchain_desc.SampleDesc.Count = 1;
hr = IDXGIFactory2_CreateSwapChainForHwnd(factory, (IUnknown *)command_queue,
window_win32->window, &swapchain_desc, NULL, NULL, &swapchain1);
IDXGIFactory2_Release(factory);
if (FAILED(hr))
goto fail;
swapchain->buffer_count = desc->buffer_count;
hr = IDXGISwapChain1_QueryInterface(swapchain1, &IID_IDXGISwapChain3, (void **)&swapchain->swapchain);
IDXGISwapChain1_Release(swapchain1);
if (FAILED(hr))
goto fail;
return swapchain;
fail:
free(swapchain);
return NULL;
}
static inline const char *demo_swapchain_get_device_name(struct demo_swapchain *swapchain)
{
return swapchain->device_name;
}
static inline unsigned int demo_swapchain_get_current_back_buffer_index(struct demo_swapchain *swapchain)
{
return IDXGISwapChain3_GetCurrentBackBufferIndex(swapchain->swapchain);
}
static inline ID3D12Resource *demo_swapchain_get_back_buffer(struct demo_swapchain *swapchain, unsigned int index)
{
ID3D12Resource *buffer;
if (FAILED(IDXGISwapChain3_GetBuffer(swapchain->swapchain, index,
&IID_ID3D12Resource, (void **)&buffer)))
return NULL;
return buffer;
}
static inline unsigned int demo_swapchain_get_back_buffer_count(struct demo_swapchain *swapchain)
{
return swapchain->buffer_count;
}
static inline void demo_swapchain_present(struct demo_swapchain *swapchain)
{
IDXGISwapChain3_Present(swapchain->swapchain, 1, 0);
}
static inline void demo_swapchain_destroy(struct demo_swapchain *swapchain)
{
IDXGISwapChain3_Release(swapchain->swapchain);
free(swapchain);
}
static inline HANDLE demo_create_event(void)
{
return CreateEventA(NULL, FALSE, FALSE, NULL);
}
static inline unsigned int demo_wait_event(HANDLE event, unsigned int ms)
{
return WaitForSingleObject(event, ms);
}
static inline void demo_destroy_event(HANDLE event)
{
CloseHandle(event);
}

324
demos/demo_macos.h Normal file
View File

@@ -0,0 +1,324 @@
/*
* Copyright 2025 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
typedef long NSInteger;
typedef unsigned long NSUInteger;
typedef struct NSPoint
{
double x, y;
} NSPoint;
typedef struct NSRect
{
double x, y;
double w, h;
} NSRect;
#define BOOL OBJC_BOOL
#include "private/appkit.h"
#include "private/foundation.h"
#include "private/quartzcore.h"
#undef BOOL
extern const id NSDefaultRunLoopMode;
enum NSBackingStoreType
{
NSBackingStoreBuffered = 2,
};
enum NSEventType
{
NSEventTypeKeyDown = 0xa,
NSEventTypeApplicationDefined = 0xf,
};
enum NSWindowStyleMask
{
NSWindowStyleMaskBorderless = 0x0000,
NSWindowStyleMaskTitled = 0x0001,
NSWindowStyleMaskClosable = 0x0002,
NSWindowStyleMaskMiniaturizable = 0x0004,
NSWindowStyleMaskResizable = 0x0008,
NSWindowStyleMaskUtilityWindow = 0x0010,
NSWindowStyleMaskDocModalWindow = 0x0040,
NSWindowStyleMaskNonactivatingPanel = 0x0080,
NSWindowStyleMaskUnifiedTitleAndToolbar = 0x1000,
NSWindowStyleMaskHUDWindow = 0x2000,
NSWindowStyleMaskFullScreen = 0x4000,
NSWindowStyleMaskFullSizeContentView = 0x8000,
};
enum
{
DemoWindowDestroyed,
};
struct demo_window_macos
{
struct demo_window w;
id window;
id layer;
};
static struct demo_window_macos *demo_macos_find_macos_window(struct demo *demo, id window)
{
size_t i;
for (i = 0; i < demo->window_count; ++i)
{
struct demo_window_macos *window_macos = CONTAINING_RECORD(demo->windows[i], struct demo_window_macos, w);
if (window_macos->window == window)
return window_macos;
}
return NULL;
}
static VkSurfaceKHR demo_window_macos_create_vk_surface(struct demo_window *window, VkInstance vk_instance)
{
struct demo_window_macos *window_macos = CONTAINING_RECORD(window, struct demo_window_macos, w);
struct VkMetalSurfaceCreateInfoEXT surface_desc;
VkSurfaceKHR vk_surface;
id l, v;
l = window_macos->layer = CAMetalLayer_layer();
CAMetalLayer_setContentsScale(l, NSScreen_backingScaleFactor(NSScreen_mainScreen()));
v = NSWindow_contentView(window_macos->window);
NSView_setLayer(v, l);
NSView_setWantsLayer(v, true);
surface_desc.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT;
surface_desc.pNext = NULL;
surface_desc.flags = 0;
surface_desc.pLayer = l;
if (vkCreateMetalSurfaceEXT(vk_instance, &surface_desc, NULL, &vk_surface) < 0)
return VK_NULL_HANDLE;
return vk_surface;
}
static void demo_window_macos_destroy(struct demo_window *window)
{
struct demo_window_macos *window_macos = CONTAINING_RECORD(window, struct demo_window_macos, w);
NSWindow_close(window_macos->window);
}
static void demo_window_macos_destroyed(struct demo_window_macos *window_macos)
{
CAMetalLayer_release(window_macos->layer);
NSWindow_release(window_macos->window);
demo_window_cleanup(&window_macos->w);
free(window_macos);
}
static struct demo_window *demo_window_macos_create(struct demo *demo,
const char *title, unsigned int width, unsigned int height, void *user_data)
{
unsigned long style = NSWindowStyleMaskTitled | NSWindowStyleMaskClosable;
struct demo_window_macos *window_macos;
NSRect r = {0, 0, width, height};
double scale;
id w, s;
if (!(window_macos = malloc(sizeof(*window_macos))))
return NULL;
if (!demo_window_init(&window_macos->w, demo, user_data,
demo_window_macos_create_vk_surface, demo_window_macos_destroy))
{
free(window_macos);
return NULL;
}
s = NSScreen_mainScreen();
scale = NSScreen_backingScaleFactor(s);
r.w /= scale;
r.h /= scale;
w = window_macos->window = class_createInstance(objc_getClass("DemoWindow"), 0);
NSWindow_initWithContentRect(w, r, style, NSBackingStoreBuffered, true, s);
NSWindow_setReleasedWhenClosed(w, false);
NSWindow_setDelegate(w, w);
NSWindow_center(w);
NSWindow_setTitle(w, NSString_stringWithUTF8String(title));
NSWindow_makeKeyAndOrderFront(w, nil);
window_macos->layer = nil;
return &window_macos->w;
}
static void demo_macos_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
{
*dpi_x = *dpi_y = 96.0 * NSScreen_backingScaleFactor(NSScreen_mainScreen());
}
static demo_key demo_key_from_nsevent(id event)
{
enum vkey
{
kVK_ANSI_A = 0x00,
kVK_ANSI_F = 0x03,
kVK_ANSI_W = 0x0d,
kVK_ANSI_Equal = 0x18,
kVK_ANSI_Minus = 0x1b,
kVK_Escape = 0x35,
kVK_ANSI_KeypadPlus = 0x45,
kVK_ANSI_KeypadMinus = 0x4e,
kVK_F1 = 0x7a,
kVK_LeftArrow = 0x7b,
kVK_RightArrow = 0x7c,
kVK_DownArrow = 0x7d,
kVK_UpArrow = 0x7e,
} vkey;
size_t i;
static const struct
{
enum vkey vkey;
demo_key demo_key;
}
lookup[] =
{
{kVK_ANSI_A, 'a'},
{kVK_ANSI_F, 'f'},
{kVK_ANSI_W, 'w'},
{kVK_ANSI_Equal, '='},
{kVK_ANSI_Minus, '-'},
{kVK_Escape, DEMO_KEY_ESCAPE},
{kVK_ANSI_KeypadPlus, DEMO_KEY_KP_ADD},
{kVK_ANSI_KeypadMinus, DEMO_KEY_KP_SUBTRACT},
{kVK_F1, DEMO_KEY_F1},
{kVK_LeftArrow, DEMO_KEY_LEFT},
{kVK_RightArrow, DEMO_KEY_RIGHT},
{kVK_DownArrow, DEMO_KEY_DOWN},
{kVK_UpArrow, DEMO_KEY_UP},
};
vkey = NSEvent_keyCode(event);
for (i = 0; i < ARRAY_SIZE(lookup); ++i)
{
if (lookup[i].vkey == vkey)
return lookup[i].demo_key;
}
return DEMO_KEY_UNKNOWN;
}
static void demo_macos_process_events(struct demo *demo)
{
struct demo_window_macos *window_macos;
struct demo_window *window;
id a, event;
size_t i;
for (i = 0; i < demo->window_count; ++i)
{
if ((window = demo->windows[i])->expose_func)
window->expose_func(window, window->user_data);
}
a = NSApplication_sharedApplication();
while (demo->window_count)
{
if (!demo->idle_func)
{
if (!(event = NSApplication_nextEventMatchingMask(a, ~(uint64_t)0,
NSDate_distantFuture(), NSDefaultRunLoopMode, true)))
break;
}
else if (!(event = NSApplication_nextEventMatchingMask(a, ~(uint64_t)0, nil, NSDefaultRunLoopMode, true)))
{
demo->idle_func(demo, demo->user_data);
continue;
}
switch (NSEvent_type(event))
{
case NSEventTypeKeyDown:
if (NSMenu_performKeyEquivalent(NSApplication_mainMenu(a), event))
continue;
if (!(window_macos = demo_macos_find_macos_window(demo, NSEvent_window(event)))
|| !window_macos->w.key_press_func)
break;
window_macos->w.key_press_func(&window_macos->w,
demo_key_from_nsevent(event), window_macos->w.user_data);
continue;
case NSEventTypeApplicationDefined:
if (NSEvent_subtype(event) != DemoWindowDestroyed
|| !(window_macos = demo_macos_find_macos_window(demo, NSEvent_window(event))))
break;
demo_window_macos_destroyed(window_macos);
continue;
}
NSApplication_sendEvent(a, event);
}
}
static void DemoWindow_windowWillClose(id window, SEL sel, id notification)
{
id event;
event = NSEvent_otherEventWithType(NSEventTypeApplicationDefined, (NSPoint){0.0, 0.0},
0, 0.0, NSWindow_windowNumber(window), nil, DemoWindowDestroyed, 0, 0);
NSApplication_postEvent(NSApplication_sharedApplication(), event, true);
}
static void demo_macos_cleanup(struct demo *demo)
{
}
static bool demo_macos_init(struct demo_macos *macos)
{
id application, item, menu, submenu;
Class c;
if ((c = objc_allocateClassPair(objc_getClass("NSWindow"), "DemoWindow", 0)))
{
class_addMethod(c, sel_registerName("windowWillClose:"), (IMP)DemoWindow_windowWillClose, "v@:@");
objc_registerClassPair(c);
}
application = NSApplication_sharedApplication();
NSApplication_setActivationPolicy(application, 0);
menu = NSMenu_new();
submenu = NSMenu_new();
NSMenu_addItemWithTitle(submenu, NSString_stringWithUTF8String("Quit"),
sel_registerName("terminate:"), NSString_stringWithUTF8String("q"));
item = NSMenuItem_new();
NSMenuItem_setSubmenu(item, submenu);
NSMenu_release(submenu);
NSMenu_addItem(menu, item);
NSMenuItem_release(item);
NSApplication_setMainMenu(application, menu);
NSMenu_release(menu);
NSApplication_finishLaunching(application);
return true;
}

640
demos/demo_vkd3d.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -17,85 +17,108 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <vkd3d_dxgi1_4.h>
#include <vkd3d_d3dcompiler.h>
#include <stdbool.h>
#include <stdio.h>
#define DEMO_WIN32_WINDOW_CLASS_NAME L"demo_wc"
#define DEMO_WINDOW_CLASS_NAME L"demo_wc"
struct demo
struct demo_window_win32
{
size_t window_count;
bool quit;
struct demo_window w;
void *user_data;
void (*idle_func)(struct demo *demo, void *user_data);
};
struct demo_window
{
HINSTANCE instance;
HWND hwnd;
struct demo *demo;
void *user_data;
void (*expose_func)(struct demo_window *window, void *user_data);
void (*key_press_func)(struct demo_window *window, demo_key key, void *user_data);
HWND window;
};
struct demo_swapchain
#ifndef VKD3D_CROSSTEST
static VkSurfaceKHR demo_window_win32_create_vk_surface(struct demo_window *window, VkInstance vk_instance)
{
IDXGISwapChain3 *swapchain;
};
struct demo_window_win32 *window_win32 = CONTAINING_RECORD(window, struct demo_window_win32, w);
struct VkWin32SurfaceCreateInfoKHR surface_desc;
VkSurfaceKHR vk_surface;
static inline struct demo_window *demo_window_create(struct demo *demo, const char *title,
surface_desc.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
surface_desc.pNext = NULL;
surface_desc.flags = 0;
surface_desc.hinstance = window_win32->instance;
surface_desc.hwnd = window_win32->window;
if (vkCreateWin32SurfaceKHR(vk_instance, &surface_desc, NULL, &vk_surface) < 0)
return VK_NULL_HANDLE;
return vk_surface;
}
#endif
static void demo_window_win32_destroy(struct demo_window *window)
{
struct demo_window_win32 *window_win32 = CONTAINING_RECORD(window, struct demo_window_win32, w);
DestroyWindow(window_win32->window);
}
static void demo_window_win32_destroyed(struct demo_window *window)
{
struct demo_window_win32 *window_win32 = CONTAINING_RECORD(window, struct demo_window_win32, w);
demo_window_cleanup(&window_win32->w);
free(window_win32);
}
static struct demo_window *demo_window_win32_create(struct demo *demo, const char *title,
unsigned int width, unsigned int height, void *user_data)
{
struct demo_window_win32 *window_win32;
RECT rect = {0, 0, width, height};
struct demo_window *window;
int title_size;
WCHAR *title_w;
DWORD style;
if (!(window = malloc(sizeof(*window))))
if (!(window_win32 = malloc(sizeof(*window_win32))))
return NULL;
#ifdef VKD3D_CROSSTEST
if (!demo_window_init(&window_win32->w, demo, user_data))
#else
if (!demo_window_init(&window_win32->w, demo, user_data,
demo_window_win32_create_vk_surface, demo_window_win32_destroy))
#endif
{
free(window_win32);
return NULL;
}
title_size = MultiByteToWideChar(CP_UTF8, 0, title, -1, NULL, 0);
if (!(title_w = calloc(title_size, sizeof(*title_w))))
{
free(window);
demo_window_cleanup(&window_win32->w);
free(window_win32);
return NULL;
}
MultiByteToWideChar(CP_UTF8, 0, title, -1, title_w, title_size);
window->instance = GetModuleHandle(NULL);
window->user_data = user_data;
window->expose_func = NULL;
window->key_press_func = NULL;
window_win32->instance = GetModuleHandle(NULL);
style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE;
AdjustWindowRect(&rect, style, FALSE);
window->hwnd = CreateWindowExW(0, DEMO_WINDOW_CLASS_NAME, title_w, style, CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, window->instance, NULL);
window_win32->window = CreateWindowExW(0, DEMO_WIN32_WINDOW_CLASS_NAME, title_w, style, CW_USEDEFAULT,
CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, window_win32->instance, NULL);
free(title_w);
if (!window->hwnd)
if (!window_win32->window)
{
free(window);
demo_window_cleanup(&window_win32->w);
free(window_win32);
return NULL;
}
SetWindowLongPtrW(window->hwnd, GWLP_USERDATA, (LONG_PTR)window);
window->demo = demo;
++demo->window_count;
SetWindowLongPtrW(window_win32->window, GWLP_USERDATA, (LONG_PTR)window_win32);
return window;
return &window_win32->w;
}
static inline void demo_window_destroy(struct demo_window *window)
static void demo_win32_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
{
DestroyWindow(window->hwnd);
struct demo_win32 *win32 = &demo->u.win32;
*dpi_x = *dpi_y = win32->GetDpiForSystem();
}
static inline demo_key demo_key_from_vkey(DWORD vkey)
static demo_key demo_key_from_win32_vkey(DWORD vkey)
{
static const struct
{
@@ -104,18 +127,23 @@ static inline demo_key demo_key_from_vkey(DWORD vkey)
}
lookup[] =
{
{VK_ESCAPE, DEMO_KEY_ESCAPE},
{VK_LEFT, DEMO_KEY_LEFT},
{VK_RIGHT, DEMO_KEY_RIGHT},
{VK_UP, DEMO_KEY_UP},
{VK_DOWN, DEMO_KEY_DOWN},
{VK_OEM_MINUS, '-'},
{VK_OEM_PLUS, '='},
{VK_ESCAPE, DEMO_KEY_ESCAPE},
{VK_LEFT, DEMO_KEY_LEFT},
{VK_UP, DEMO_KEY_UP},
{VK_RIGHT, DEMO_KEY_RIGHT},
{VK_DOWN, DEMO_KEY_DOWN},
{VK_ADD, DEMO_KEY_KP_ADD},
{VK_SUBTRACT, DEMO_KEY_KP_SUBTRACT},
{VK_F1, DEMO_KEY_F1},
};
unsigned int i;
if (vkey >= '0' && vkey <= '9')
return vkey;
if (vkey >= 'A' && vkey <= 'Z')
return vkey;
return vkey + 0x20;
for (i = 0; i < ARRAY_SIZE(lookup); ++i)
{
@@ -126,46 +154,33 @@ static inline demo_key demo_key_from_vkey(DWORD vkey)
return DEMO_KEY_UNKNOWN;
}
static inline LRESULT CALLBACK demo_window_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
static LRESULT CALLBACK demo_win32_window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
struct demo_window *window = (void *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
struct demo_window_win32 *window_win32 = (void *)GetWindowLongPtrW(window, GWLP_USERDATA);
switch (message)
{
case WM_PAINT:
if (window && window->expose_func)
window->expose_func(window, window->user_data);
if (window_win32 && window_win32->w.expose_func)
window_win32->w.expose_func(&window_win32->w, window_win32->w.user_data);
return 0;
case WM_KEYDOWN:
if (!window->key_press_func)
if (!window_win32->w.key_press_func)
break;
window->key_press_func(window, demo_key_from_vkey(wparam), window->user_data);
window_win32->w.key_press_func(&window_win32->w,
demo_key_from_win32_vkey(wparam), window_win32->w.user_data);
return 0;
case WM_DESTROY:
if (!--window->demo->window_count)
window->demo->quit = true;
free(window);
demo_window_win32_destroyed(&window_win32->w);
return 0;
}
return DefWindowProcW(hwnd, message, wparam, lparam);
return DefWindowProcW(window, message, wparam, lparam);
}
static inline void demo_window_set_key_press_func(struct demo_window *window,
void (*key_press_func)(struct demo_window *window, demo_key key, void *user_data))
{
window->key_press_func = key_press_func;
}
static inline void demo_window_set_expose_func(struct demo_window *window,
void (*expose_func)(struct demo_window *window, void *user_data))
{
window->expose_func = expose_func;
}
static inline void demo_process_events(struct demo *demo)
static void demo_win32_process_events(struct demo *demo)
{
MSG msg = {0};
@@ -186,18 +201,28 @@ static inline void demo_process_events(struct demo *demo)
break;
TranslateMessage(&msg);
DispatchMessageW(&msg);
if (demo->quit)
if (!demo->window_count)
PostQuitMessage(0);
}
}
static inline bool demo_init(struct demo *demo, void *user_data)
static void demo_win32_cleanup(struct demo *demo)
{
UnregisterClassW(DEMO_WIN32_WINDOW_CLASS_NAME, GetModuleHandle(NULL));
}
static inline UINT demo_win32_GetDpiForSystem(void)
{
return 96;
}
static bool demo_win32_init(struct demo_win32 *win32)
{
WNDCLASSEXW wc;
wc.cbSize = sizeof(wc);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = demo_window_proc;
wc.lpfnWndProc = demo_win32_window_proc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
@@ -205,110 +230,15 @@ static inline bool demo_init(struct demo *demo, void *user_data)
wc.hCursor = LoadCursorW(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = DEMO_WINDOW_CLASS_NAME;
wc.lpszClassName = DEMO_WIN32_WINDOW_CLASS_NAME;
wc.hIconSm = LoadIconW(NULL, IDI_WINLOGO);
if (!RegisterClassExW(&wc))
return false;
demo->window_count = 0;
demo->quit = false;
demo->user_data = user_data;
demo->idle_func = NULL;
if ((win32->GetDpiForSystem = (void *)GetProcAddress(GetModuleHandleA("user32"), "GetDpiForSystem")))
SetProcessDPIAware();
else
win32->GetDpiForSystem = demo_win32_GetDpiForSystem;
return true;
}
static inline void demo_cleanup(struct demo *demo)
{
UnregisterClassW(DEMO_WINDOW_CLASS_NAME, GetModuleHandle(NULL));
}
static inline void demo_set_idle_func(struct demo *demo,
void (*idle_func)(struct demo *demo, void *user_data))
{
demo->idle_func = idle_func;
}
static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *command_queue,
struct demo_window *window, const struct demo_swapchain_desc *desc)
{
DXGI_SWAP_CHAIN_DESC1 swapchain_desc;
struct demo_swapchain *swapchain;
IDXGISwapChain1 *swapchain1;
IDXGIFactory2 *factory;
HRESULT hr;
if (!(swapchain = malloc(sizeof(*swapchain))))
return NULL;
if (FAILED(CreateDXGIFactory1(&IID_IDXGIFactory2, (void **)&factory)))
goto fail;
memset(&swapchain_desc, 0, sizeof(swapchain_desc));
swapchain_desc.BufferCount = desc->buffer_count;
swapchain_desc.Width = desc->width;
swapchain_desc.Height = desc->height;
swapchain_desc.Format = desc->format;
swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapchain_desc.SampleDesc.Count = 1;
hr = IDXGIFactory2_CreateSwapChainForHwnd(factory, (IUnknown *)command_queue,
window->hwnd, &swapchain_desc, NULL, NULL, &swapchain1);
IDXGIFactory2_Release(factory);
if (FAILED(hr))
goto fail;
hr = IDXGISwapChain1_QueryInterface(swapchain1, &IID_IDXGISwapChain3, (void **)&swapchain->swapchain);
IDXGISwapChain1_Release(swapchain1);
if (FAILED(hr))
goto fail;
return swapchain;
fail:
free(swapchain);
return NULL;
}
static inline unsigned int demo_swapchain_get_current_back_buffer_index(struct demo_swapchain *swapchain)
{
return IDXGISwapChain3_GetCurrentBackBufferIndex(swapchain->swapchain);
}
static inline ID3D12Resource *demo_swapchain_get_back_buffer(struct demo_swapchain *swapchain, unsigned int index)
{
ID3D12Resource *buffer;
if (FAILED(IDXGISwapChain3_GetBuffer(swapchain->swapchain, index,
&IID_ID3D12Resource, (void **)&buffer)))
return NULL;
return buffer;
}
static inline void demo_swapchain_present(struct demo_swapchain *swapchain)
{
IDXGISwapChain3_Present(swapchain->swapchain, 1, 0);
}
static inline void demo_swapchain_destroy(struct demo_swapchain *swapchain)
{
IDXGISwapChain3_Release(swapchain->swapchain);
free(swapchain);
}
static inline HANDLE demo_create_event(void)
{
return CreateEventA(NULL, FALSE, FALSE, NULL);
}
static inline unsigned int demo_wait_event(HANDLE event, unsigned int ms)
{
return WaitForSingleObject(event, ms);
}
static inline void demo_destroy_event(HANDLE event)
{
CloseHandle(event);
}

File diff suppressed because it is too large Load Diff

145
demos/etl16-unicode.h Normal file
View File

@@ -0,0 +1,145 @@
/*
* Copyright 2025 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* The glyph data is derived from etl16-unicode.bdf as found on
* ftp://ftp.ring.gr.jp/pub/X/opengroup/contrib/fonts/etl-unicode.tar.gz
* with the following license:
*
* Public domain font. Share and enjoy.
*/
/* Each line in etl16_unicode[] below contains the bitmap data for a single
* 8x16 glyph, starting at ASCII 0x20 (space). Each byte corresponds to a
* single line in the glyph.
*
* The BDF bitmap data is essentially the same format we're using here, so we
* could have extracted the glyphs manually, or perhaps using a small script.
* However, bdf2psf can do most of the work for us, by creating a PSF1 font
* from the BDF.
*
* A PSF1 font has a 4 byte header, followed by at least 256 glyphs.
* For a 8x16 font, each glyph consists of 16 bytes, one byte for each row.
*
* We're not interested in control characters or extended ASCII, so we skip
* the first 0x4 (header) + 0x20 (control characters) * 0x10 = 516 bytes, and
* extract the next (0x80 - 0x20) * 0x10 = 1536 bytes:
*
* bdf2psf etl16-unicode.bdf standard.equivalents ascii.set 256 /dev/stdout | xxd -i -c 16 -s 516 -l 1536
*
* and we're done.
*/
static const uint8_t etl16_unicode[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x66, 0x22, 0x22, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0x12, 0x7e, 0x24, 0x24, 0x7e, 0x48, 0x48, 0x48, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x3e, 0x49, 0x48, 0x38, 0x0e, 0x09, 0x49, 0x3e, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0x4a, 0x4a, 0x34, 0x08, 0x08, 0x16, 0x29, 0x29, 0x46, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x39, 0x45, 0x42, 0x46, 0x39, 0x00, 0x00,
0x00, 0x00, 0x18, 0x08, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x00,
0x00, 0x00, 0x00, 0x20, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x49, 0x2a, 0x1c, 0x2a, 0x49, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x08, 0x08, 0x7f, 0x08, 0x08, 0x08, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x40, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x02, 0x0c, 0x10, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x02, 0x1c, 0x02, 0x02, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x0c, 0x14, 0x24, 0x44, 0x44, 0x7e, 0x04, 0x04, 0x04, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c, 0x02, 0x02, 0x02, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1c, 0x20, 0x40, 0x40, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x02, 0x02, 0x04, 0x04, 0x04, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x02, 0x04, 0x38, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x10, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x08, 0x10, 0x20, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x02, 0x04, 0x08, 0x08, 0x00, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1c, 0x22, 0x4a, 0x56, 0x52, 0x52, 0x52, 0x4e, 0x20, 0x1e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x78, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x78, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x40, 0x40, 0x40, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x40, 0x40, 0x4e, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x44, 0x44, 0x38, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x44, 0x48, 0x50, 0x60, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x66, 0x66, 0x5a, 0x5a, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x62, 0x62, 0x52, 0x52, 0x4a, 0x4a, 0x46, 0x46, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x66, 0x3c, 0x03, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7c, 0x42, 0x42, 0x42, 0x7c, 0x48, 0x44, 0x44, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x41, 0x22, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x5a, 0x66, 0x66, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x24, 0x18, 0x18, 0x24, 0x24, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x41, 0x41, 0x22, 0x22, 0x14, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x7e, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00,
0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x02, 0x00, 0x00,
0x00, 0x00, 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00,
0x00, 0x00, 0x18, 0x24, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x00,
0x00, 0x00, 0x18, 0x10, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x02, 0x3e, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00,
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x40, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x3a, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x40, 0x40, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3a, 0x44, 0x44, 0x44, 0x38, 0x20, 0x3c, 0x42, 0x42, 0x3c,
0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x08, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0x04, 0x00, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x48, 0x30,
0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x62, 0x42, 0x42, 0x42, 0x42, 0x62, 0x5c, 0x40, 0x40,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x46, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x02, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0x42, 0x40, 0x30, 0x0c, 0x02, 0x42, 0x3c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0c, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3a, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x36, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x42, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1a, 0x02, 0x02, 0x3c,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x7e, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0c, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x0c, 0x00,
0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x00, 0x30, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x10, 0x10, 0x08, 0x08, 0x30, 0x00,
0x00, 0x00, 0x00, 0x31, 0x49, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xfc, 0x1b, 0x26, 0xef, 0xc8, 0xe0, 0x43, 0x20, 0x89, 0x58, 0x62, 0x5e, 0x79, 0xba, 0xee, 0x7e,
};

View File

@@ -45,7 +45,6 @@
#include <sys/time.h>
#include <assert.h>
#include <stdio.h>
#include <math.h>
#include "demo.h"
DEMO_EMBED(gears_hlsl, "gears.hlsl");
@@ -59,7 +58,7 @@ struct cxg_fence
struct cxg_cb_data
{
float mvp_matrix[16];
struct demo_matrix mvp_matrix;
float normal_matrix[12];
};
@@ -120,14 +119,17 @@ struct cx_gears
ID3D12Device *device;
ID3D12CommandQueue *command_queue;
struct demo_swapchain *swapchain;
struct
{
ID3D12Resource *render_target;
ID3D12CommandAllocator *command_allocator;
ID3D12GraphicsCommandList *command_list;
} *swapchain_images;
ID3D12DescriptorHeap *rtv_heap, *dsv_heap;
unsigned int rtv_descriptor_size;
ID3D12Resource *render_targets[3];
ID3D12CommandAllocator *command_allocator[3];
ID3D12RootSignature *root_signature;
ID3D12PipelineState *pipeline_state_smooth, *pipeline_state_flat;
ID3D12GraphicsCommandList *command_list[3];
ID3D12Resource *ds, *cb, *vb[2], *ib;
D3D12_VERTEX_BUFFER_VIEW vbv[2];
D3D12_INDEX_BUFFER_VIEW ibv;
@@ -142,7 +144,7 @@ struct cx_gears
static void cxg_populate_command_list(struct cx_gears *cxg, unsigned int rt_idx)
{
ID3D12GraphicsCommandList *command_list = cxg->command_list[rt_idx];
ID3D12GraphicsCommandList *command_list = cxg->swapchain_images[rt_idx].command_list;
static const float clear_colour[] = {0.0f, 0.0f, 0.0f, 1.0f};
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle, dsv_handle;
@@ -150,10 +152,11 @@ static void cxg_populate_command_list(struct cx_gears *cxg, unsigned int rt_idx)
HRESULT hr;
size_t i;
hr = ID3D12CommandAllocator_Reset(cxg->command_allocator[rt_idx]);
hr = ID3D12CommandAllocator_Reset(cxg->swapchain_images[rt_idx].command_allocator);
assert(SUCCEEDED(hr));
hr = ID3D12GraphicsCommandList_Reset(command_list, cxg->command_allocator[rt_idx], cxg->pipeline_state_flat);
hr = ID3D12GraphicsCommandList_Reset(command_list,
cxg->swapchain_images[rt_idx].command_allocator, cxg->pipeline_state_flat);
assert(SUCCEEDED(hr));
ID3D12GraphicsCommandList_SetGraphicsRootSignature(command_list, cxg->root_signature);
@@ -165,7 +168,7 @@ static void cxg_populate_command_list(struct cx_gears *cxg, unsigned int rt_idx)
barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
barrier.Transition.pResource = cxg->render_targets[rt_idx];
barrier.Transition.pResource = cxg->swapchain_images[rt_idx].render_target;
barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
@@ -226,44 +229,24 @@ static void cxg_wait_for_previous_frame(struct cx_gears *cxg)
static void cxg_update_mvp(struct cx_gears *cxg)
{
struct demo_matrix projection, world;
float s1 = sinf(cxg->theta);
float c1 = cosf(cxg->theta);
float s2 = sinf(cxg->phi);
float c2 = cosf(cxg->phi);
float z_offset = -40.0f;
float z_max = 60.0f;
float z_min = 5.0f;
float sx = z_min;
float sy = z_min * cxg->aspect_ratio;
float sz = -((z_max + z_min) / (z_max - z_min));
float d = (-2.0f * z_max * z_min) / (z_max - z_min);
unsigned int i, j;
float world[] =
{
c1, s2 * s1, c2 * -s1, 0.0f,
0.0f, c2, s2, 0.0f,
s1, -s2 * c1, c2 * c1, 0.0f,
0.0f, 0.0f, z_offset, 1.0f,
};
float projection[] =
{
sx, 0.0f, 0.0f, 0.0f,
0.0f, sy, 0.0f, 0.0f,
0.0f, 0.0f, sz, -1.0f,
0.0f, 0.0f, d, 0.0f,
};
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
cxg->cb_data->mvp_matrix[i * 4 + j] = projection[j] * world[i * 4]
+ projection[j + 4] * world[i * 4 + 1]
+ projection[j + 8] * world[i * 4 + 2]
+ projection[j + 12] * world[i * 4 + 3];
}
}
memcpy(cxg->cb_data->normal_matrix, world, sizeof(cxg->cb_data->normal_matrix));
world = (struct demo_matrix)
{{
{ c1, s2 * s1, c2 * -s1, 0.0f},
{0.0f, c2, s2, 0.0f},
{ s1, -s2 * c1, c2 * c1, 0.0f},
{0.0f, 0.0f, z_offset, 1.0f},
}};
demo_matrix_perspective_rh(&projection, 2.0f, 2.0f / cxg->aspect_ratio, 5.0f, 60.0f);
demo_matrix_multiply(&cxg->cb_data->mvp_matrix, &world, &projection);
memcpy(cxg->cb_data->normal_matrix, &world, sizeof(cxg->cb_data->normal_matrix));
}
static void cxg_render_frame(struct cx_gears *cxg)
@@ -295,7 +278,7 @@ static void cxg_render_frame(struct cx_gears *cxg)
demo_vec4_set(&cxg->instance_data[2].transform, cosf(a), sinf(a), -3.1f, 4.2f);
ID3D12CommandQueue_ExecuteCommandLists(cxg->command_queue, 1,
(ID3D12CommandList **)&cxg->command_list[cxg->rt_idx]);
(ID3D12CommandList **)&cxg->swapchain_images[cxg->rt_idx].command_list);
demo_swapchain_present(cxg->swapchain);
cxg_wait_for_previous_frame(cxg);
}
@@ -304,16 +287,14 @@ static void cxg_destroy_pipeline(struct cx_gears *cxg)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cxg->command_allocator); ++i)
{
ID3D12CommandAllocator_Release(cxg->command_allocator[i]);
}
for (i = 0; i < ARRAY_SIZE(cxg->render_targets); ++i)
{
ID3D12Resource_Release(cxg->render_targets[i]);
}
ID3D12DescriptorHeap_Release(cxg->dsv_heap);
ID3D12DescriptorHeap_Release(cxg->rtv_heap);
for (i = 0; i < demo_swapchain_get_back_buffer_count(cxg->swapchain); ++i)
{
ID3D12CommandAllocator_Release(cxg->swapchain_images[i].command_allocator);
ID3D12Resource_Release(cxg->swapchain_images[i].render_target);
}
free(cxg->swapchain_images);
demo_swapchain_destroy(cxg->swapchain);
ID3D12CommandQueue_Release(cxg->command_queue);
ID3D12Device_Release(cxg->device);
@@ -325,7 +306,7 @@ static void cxg_load_pipeline(struct cx_gears *cxg)
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle;
D3D12_DESCRIPTOR_HEAP_DESC heap_desc;
D3D12_COMMAND_QUEUE_DESC queue_desc;
unsigned int i;
unsigned int i, rt_count;
HRESULT hr;
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&cxg->device);
@@ -338,16 +319,19 @@ static void cxg_load_pipeline(struct cx_gears *cxg)
&IID_ID3D12CommandQueue, (void **)&cxg->command_queue);
assert(SUCCEEDED(hr));
swapchain_desc.buffer_count = ARRAY_SIZE(cxg->render_targets);
swapchain_desc.buffer_count = 3;
swapchain_desc.format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapchain_desc.width = cxg->width;
swapchain_desc.height = cxg->height;
cxg->swapchain = demo_swapchain_create(cxg->command_queue, cxg->window, &swapchain_desc);
assert(cxg->swapchain);
rt_count = demo_swapchain_get_back_buffer_count(cxg->swapchain);
cxg->swapchain_images = calloc(rt_count, sizeof(*cxg->swapchain_images));
assert(cxg->swapchain_images);
cxg->rt_idx = demo_swapchain_get_current_back_buffer_index(cxg->swapchain);
memset(&heap_desc, 0, sizeof(heap_desc));
heap_desc.NumDescriptors = ARRAY_SIZE(cxg->render_targets);
heap_desc.NumDescriptors = rt_count;
heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
hr = ID3D12Device_CreateDescriptorHeap(cxg->device, &heap_desc,
@@ -357,10 +341,10 @@ static void cxg_load_pipeline(struct cx_gears *cxg)
cxg->rtv_descriptor_size = ID3D12Device_GetDescriptorHandleIncrementSize(cxg->device,
D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
rtv_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(cxg->rtv_heap);
for (i = 0; i < ARRAY_SIZE(cxg->render_targets); ++i)
for (i = 0; i < rt_count; ++i)
{
cxg->render_targets[i] = demo_swapchain_get_back_buffer(cxg->swapchain, i);
ID3D12Device_CreateRenderTargetView(cxg->device, cxg->render_targets[i], NULL, rtv_handle);
cxg->swapchain_images[i].render_target = demo_swapchain_get_back_buffer(cxg->swapchain, i);
ID3D12Device_CreateRenderTargetView(cxg->device, cxg->swapchain_images[i].render_target, NULL, rtv_handle);
rtv_handle.ptr += cxg->rtv_descriptor_size;
}
@@ -371,10 +355,10 @@ static void cxg_load_pipeline(struct cx_gears *cxg)
&IID_ID3D12DescriptorHeap, (void **)&cxg->dsv_heap);
assert(SUCCEEDED(hr));
for (i = 0; i < ARRAY_SIZE(cxg->command_allocator); ++i)
for (i = 0; i < rt_count; ++i)
{
hr = ID3D12Device_CreateCommandAllocator(cxg->device, D3D12_COMMAND_LIST_TYPE_DIRECT,
&IID_ID3D12CommandAllocator, (void **)&cxg->command_allocator[i]);
&IID_ID3D12CommandAllocator, (void **)&cxg->swapchain_images[i].command_allocator);
assert(SUCCEEDED(hr));
}
}
@@ -397,8 +381,8 @@ static void cxg_destroy_assets(struct cx_gears *cxg)
ID3D12Resource_Unmap(cxg->cb, 0, NULL);
ID3D12Resource_Release(cxg->cb);
ID3D12Resource_Release(cxg->ds);
for (i = 0; i < ARRAY_SIZE(cxg->command_list); ++i)
ID3D12GraphicsCommandList_Release(cxg->command_list[i]);
for (i = 0; i < demo_swapchain_get_back_buffer_count(cxg->swapchain); ++i)
ID3D12GraphicsCommandList_Release(cxg->swapchain_images[i].command_list);
ID3D12PipelineState_Release(cxg->pipeline_state_smooth);
ID3D12PipelineState_Release(cxg->pipeline_state_flat);
ID3D12RootSignature_Release(cxg->root_signature);
@@ -727,13 +711,13 @@ static void cxg_load_assets(struct cx_gears *cxg)
ID3D10Blob_Release(ps_flat);
ID3D10Blob_Release(ps_smooth);
for (i = 0; i < ARRAY_SIZE(cxg->command_list); ++i)
for (i = 0; i < demo_swapchain_get_back_buffer_count(cxg->swapchain); ++i)
{
hr = ID3D12Device_CreateCommandList(cxg->device, 0, D3D12_COMMAND_LIST_TYPE_DIRECT,
cxg->command_allocator[i], cxg->pipeline_state_flat,
&IID_ID3D12GraphicsCommandList, (void **)&cxg->command_list[i]);
cxg->swapchain_images[i].command_allocator, cxg->pipeline_state_flat,
&IID_ID3D12GraphicsCommandList, (void **)&cxg->swapchain_images[i].command_list);
assert(SUCCEEDED(hr));
hr = ID3D12GraphicsCommandList_Close(cxg->command_list[i]);
hr = ID3D12GraphicsCommandList_Close(cxg->swapchain_images[i].command_list);
assert(SUCCEEDED(hr));
}
@@ -808,7 +792,6 @@ static void cxg_key_press(struct demo_window *window, demo_key key, void *user_d
switch (key)
{
case 'a':
case 'A':
cxg->animate = !cxg->animate;
break;
case DEMO_KEY_ESCAPE:
@@ -849,12 +832,17 @@ static int cxg_main(void)
{
unsigned int width = 300, height = 300;
struct cx_gears cxg;
double dpi_x, dpi_y;
size_t i;
memset(&cxg, 0, sizeof(cxg));
if (!demo_init(&cxg.demo, &cxg))
return EXIT_FAILURE;
demo_set_idle_func(&cxg.demo, cxg_idle);
demo_get_dpi(&cxg.demo, &dpi_x, &dpi_y);
width *= dpi_x / 96.0;
height *= dpi_y / 96.0;
cxg.window = demo_window_create(&cxg.demo, "Vkd3d Gears", width, height, &cxg);
demo_window_set_key_press_func(cxg.window, cxg_key_press);
demo_window_set_expose_func(cxg.window, cxg_expose);
@@ -876,10 +864,13 @@ static int cxg_main(void)
cxg_load_pipeline(&cxg);
cxg_load_assets(&cxg);
cxg_populate_command_list(&cxg, 0);
cxg_populate_command_list(&cxg, 1);
cxg_populate_command_list(&cxg, 2);
for (i = 0; i < demo_swapchain_get_back_buffer_count(cxg.swapchain); ++i)
{
cxg_populate_command_list(&cxg, i);
}
printf("vkd3d-gears: Running on \"%s\" using %s.\n",
demo_swapchain_get_device_name(cxg.swapchain), demo_get_platform_name());
demo_process_events(&cxg.demo);
cxg_wait_for_previous_frame(&cxg);

View File

@@ -1,3 +1,21 @@
/*
* Copyright 2016 Henri Verbeet for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
cbuffer gear_block : register(b0)
{
float4x4 mvp_matrix;

151
demos/make_objc Executable file
View File

@@ -0,0 +1,151 @@
#!/usr/bin/perl -w
#
# Copyright 2025 Henri Verbeet
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
use strict;
use warnings;
use JSON;
use open ':utf8';
binmode STDOUT, ':utf8';
sub method_name($)
{
shift->{selector} =~ s/(:.*)//r;
}
sub method_parameters($$)
{
my ($method, $method_type) = @_;
my $parameters = join ", ", $method_type eq "class" ? () : "id self",
map {"$_->{type} $_->{name}"} @{$method->{parameters}};
length $parameters ? $parameters : "void";
}
sub send_function($)
{
shift->{'return-float'} ? "vkd3d_objc_msgSend_fpret" : "objc_msgSend";
}
sub invocation_type($$)
{
my ($method, $method_type) = @_;
"$method->{'return-type'} (*)(" . join(", ", $method_type eq "class" ? "Class" : "id", "SEL",
map {$_->{type}} @{$method->{parameters}}) . ")";
}
sub invocation_parameters($$$)
{
my ($method, $interface_name, $method_type) = @_;
join ", ", $method_type eq "class" ? "objc_getClass(\"$interface_name\")" : "self",
"sel_registerName(\"$method->{selector}\")", map {$_->{name}} @{$method->{parameters}};
}
sub invocation($$$)
{
my ($method, $interface_name, $method_type) = @_;
($method->{'return-type'} eq "void" ? "" : "return ")
. "((${\invocation_type $method, $method_type})f)"
. "(${\invocation_parameters $method, $interface_name, $method_type});";
}
sub print_method($$$)
{
my ($method, $interface_name, $method_type) = @_;
print "static inline $method->{'return-type'} "
. "${interface_name}_${\method_name $method}(${\method_parameters $method, $method_type})\n";
print "{\n";
print " void *f = ${\send_function $method};\n";
print " ${\invocation $method, $interface_name, $method_type}\n";
print "}\n\n";
}
sub print_property($$)
{
my ($property, $interface_name) = @_;
my $method =
{
'return-type' => $property->{type},
'return-float' => $property->{float},
selector => $property->{getter} // $property->{name},
};
my $method_type = $property->{class} ? "class" : "instance";
print_method $method, $interface_name, $method_type;
if (!$property->{readonly})
{
$method->{'return-type'} = "void";
$method->{'return-float'} = 0;
$method->{selector} = "set${\ucfirst $property->{name}}:";
$method->{parameters} = [$property];
print_method $method, $interface_name, $method_type;
}
}
sub print_interface(_)
{
my ($interface) = @_;
print_method $_, $interface->{name}, "class" foreach (@{$interface->{'class-methods'}});
print_method $_, $interface->{name}, "instance" foreach (@{$interface->{'instance-methods'}});
print_property $_, $interface->{name} foreach (@{$interface->{properties}});
}
sub print_header($)
{
my ($grammar) = @_;
my $guard = "__VKD3D_${\uc $grammar->{name}}_H__";
print "/*\n";
print " * This file is automatically generated.\n";
print " * The original source is covered by the following license:\n";
print " *\n";
print map {" * $_" =~ s/ +$//r . "\n"} @{$grammar->{copyright}};
print " */\n\n";
print "#ifndef $guard\n";
print "#define $guard\n\n";
print "#include <objc/objc-runtime.h>\n\n";
print "#ifdef __arm64__\n";
print "# define vkd3d_objc_msgSend_fpret objc_msgSend\n";
print "#else\n";
print "# define vkd3d_objc_msgSend_fpret objc_msgSend_fpret\n";
print "#endif /* __arm64__ */\n\n";
print_interface foreach (@{$grammar->{interfaces}});
print "#undef vkd3d_objc_msgSend_fpret\n\n";
print "#endif /* $guard */\n";
}
die "No input file specified.\n" unless @ARGV;
print_header do
{
local $/;
open my $fh, '<', $ARGV[0] or die $!;
decode_json <$fh>;
};

1083
demos/teapot.c Normal file

File diff suppressed because it is too large Load Diff

129
demos/teapot.h Normal file
View File

@@ -0,0 +1,129 @@
/*
* Copyright 2025 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Teapot data adapted from freeglut's fg_teapot_data.h with the following license:
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* The data is of course ultimately derived from Martin Newell's famous
* teapot, also known as the Utah teapot.
*/
/* Rim, body, lid, and bottom data must be rotated along all four quadrants;
* handle and spout data is flipped (negate y values) only. */
static const struct demo_patch teapot_rotate_patches[] =
{
{{{ 0, 1, 2, 3}, { 4, 5, 6, 7}, { 8, 9, 10, 11}, { 12, 13, 14, 15}}}, /* rim */
{{{ 12, 13, 14, 15}, { 16, 17, 18, 19}, { 20, 21, 22, 23}, { 24, 25, 26, 27}}}, /* body */
{{{ 24, 25, 26, 27}, { 28, 29, 30, 31}, { 32, 33, 34, 35}, { 36, 37, 38, 39}}},
{{{ 40, 40, 40, 40}, { 43, 44, 45, 46}, { 47, 47, 47, 47}, { 48, 49, 50, 51}}}, /* lid */
{{{ 48, 49, 50, 51}, { 52, 53, 54, 55}, { 56, 57, 58, 59}, { 60, 61, 62, 63}}},
{{{ 64, 64, 64, 64}, { 65, 66, 67, 68}, { 69, 70, 71, 72}, { 39, 38, 37, 36}}}, /* bottom */
},
teapot_flip_patches[] =
{
{{{ 73, 74, 75, 76}, { 77, 78, 79, 80}, { 81, 82, 83, 84}, { 85, 86, 87, 88}}}, /* handle */
{{{ 85, 86, 87, 88}, { 89, 90, 91, 92}, { 93, 94, 95, 96}, { 97, 98, 99, 100}}},
{{{101, 102, 103, 104}, {105, 106, 107, 108}, {109, 110, 111, 112}, {113, 114, 115, 116}}}, /* spout */
{{{113, 114, 115, 116}, {117, 118, 119, 120}, {121, 122, 123, 124}, {125, 126, 127, 128}}},
};
static const struct demo_vec3 teapot_control_points[] =
{
{ 1.40000f, 0.00000f, 2.40000f}, { 1.40000f, -0.78400f, 2.40000f},
{ 0.78400f, -1.40000f, 2.40000f}, { 0.00000f, -1.40000f, 2.40000f},
{ 1.33750f, 0.00000f, 2.53125f}, { 1.33750f, -0.74900f, 2.53125f},
{ 0.74900f, -1.33750f, 2.53125f}, { 0.00000f, -1.33750f, 2.53125f},
{ 1.43750f, 0.00000f, 2.53125f}, { 1.43750f, -0.80500f, 2.53125f},
{ 0.80500f, -1.43750f, 2.53125f}, { 0.00000f, -1.43750f, 2.53125f},
{ 1.50000f, 0.00000f, 2.40000f}, { 1.50000f, -0.84000f, 2.40000f},
{ 0.84000f, -1.50000f, 2.40000f}, { 0.00000f, -1.50000f, 2.40000f},
{ 1.75000f, 0.00000f, 1.87500f}, { 1.75000f, -0.98000f, 1.87500f},
{ 0.98000f, -1.75000f, 1.87500f}, { 0.00000f, -1.75000f, 1.87500f},
{ 2.00000f, 0.00000f, 1.35000f}, { 2.00000f, -1.12000f, 1.35000f},
{ 1.12000f, -2.00000f, 1.35000f}, { 0.00000f, -2.00000f, 1.35000f},
{ 2.00000f, 0.00000f, 0.90000f}, { 2.00000f, -1.12000f, 0.90000f},
{ 1.12000f, -2.00000f, 0.90000f}, { 0.00000f, -2.00000f, 0.90000f},
{ 2.00000f, 0.00000f, 0.45000f}, { 2.00000f, -1.12000f, 0.45000f},
{ 1.12000f, -2.00000f, 0.45000f}, { 0.00000f, -2.00000f, 0.45000f},
{ 1.50000f, 0.00000f, 0.22500f}, { 1.50000f, -0.84000f, 0.22500f},
{ 0.84000f, -1.50000f, 0.22500f}, { 0.00000f, -1.50000f, 0.22500f},
{ 1.50000f, 0.00000f, 0.15000f}, { 1.50000f, -0.84000f, 0.15000f},
{ 0.84000f, -1.50000f, 0.15000f}, { 0.00000f, -1.50000f, 0.15000f},
{ 0.00000f, 0.00000f, 3.15000f}, { 0.00000f, -0.00200f, 3.15000f},
{ 0.00200f, 0.00000f, 3.15000f}, { 0.80000f, 0.00000f, 3.15000f},
{ 0.80000f, -0.45000f, 3.15000f}, { 0.45000f, -0.80000f, 3.15000f},
{ 0.00000f, -0.80000f, 3.15000f}, { 0.00000f, 0.00000f, 2.85000f},
{ 0.20000f, 0.00000f, 2.70000f}, { 0.20000f, -0.11200f, 2.70000f},
{ 0.11200f, -0.20000f, 2.70000f}, { 0.00000f, -0.20000f, 2.70000f},
{ 0.40000f, 0.00000f, 2.55000f}, { 0.40000f, -0.22400f, 2.55000f},
{ 0.22400f, -0.40000f, 2.55000f}, { 0.00000f, -0.40000f, 2.55000f},
{ 1.30000f, 0.00000f, 2.55000f}, { 1.30000f, -0.72800f, 2.55000f},
{ 0.72800f, -1.30000f, 2.55000f}, { 0.00000f, -1.30000f, 2.55000f},
{ 1.30000f, 0.00000f, 2.40000f}, { 1.30000f, -0.72800f, 2.40000f},
{ 0.72800f, -1.30000f, 2.40000f}, { 0.00000f, -1.30000f, 2.40000f},
{ 0.00000f, 0.00000f, 0.00000f}, { 0.00000f, -1.42500f, 0.00000f},
{ 0.79800f, -1.42500f, 0.00000f}, { 1.42500f, -0.79800f, 0.00000f},
{ 1.42500f, 0.00000f, 0.00000f}, { 0.00000f, -1.50000f, 0.07500f},
{ 0.84000f, -1.50000f, 0.07500f}, { 1.50000f, -0.84000f, 0.07500f},
{ 1.50000f, 0.00000f, 0.07500f}, {-1.60000f, 0.00000f, 2.02500f},
{-1.60000f, -0.30000f, 2.02500f}, {-1.50000f, -0.30000f, 2.25000f},
{-1.50000f, 0.00000f, 2.25000f}, {-2.30000f, 0.00000f, 2.02500f},
{-2.30000f, -0.30000f, 2.02500f}, {-2.50000f, -0.30000f, 2.25000f},
{-2.50000f, 0.00000f, 2.25000f}, {-2.70000f, 0.00000f, 2.02500f},
{-2.70000f, -0.30000f, 2.02500f}, {-3.00000f, -0.30000f, 2.25000f},
{-3.00000f, 0.00000f, 2.25000f}, {-2.70000f, 0.00000f, 1.80000f},
{-2.70000f, -0.30000f, 1.80000f}, {-3.00000f, -0.30000f, 1.80000f},
{-3.00000f, 0.00000f, 1.80000f}, {-2.70000f, 0.00000f, 1.57500f},
{-2.70000f, -0.30000f, 1.57500f}, {-3.00000f, -0.30000f, 1.35000f},
{-3.00000f, 0.00000f, 1.35000f}, {-2.50000f, 0.00000f, 1.12500f},
{-2.50000f, -0.30000f, 1.12500f}, {-2.65000f, -0.30000f, 0.93750f},
{-2.65000f, 0.00000f, 0.93750f}, {-2.00000f, 0.00000f, 0.90000f},
{-2.00000f, -0.30000f, 0.90000f}, {-1.90000f, -0.30000f, 0.60000f},
{-1.90000f, 0.00000f, 0.60000f}, { 1.70000f, 0.00000f, 1.42500f},
{ 1.70000f, -0.66000f, 1.42500f}, { 1.70000f, -0.66000f, 0.60000f},
{ 1.70000f, 0.00000f, 0.60000f}, { 2.60000f, 0.00000f, 1.42500f},
{ 2.60000f, -0.66000f, 1.42500f}, { 3.10000f, -0.66000f, 0.82500f},
{ 3.10000f, 0.00000f, 0.82500f}, { 2.30000f, 0.00000f, 2.10000f},
{ 2.30000f, -0.25000f, 2.10000f}, { 2.40000f, -0.25000f, 2.02500f},
{ 2.40000f, 0.00000f, 2.02500f}, { 2.70000f, 0.00000f, 2.40000f},
{ 2.70000f, -0.25000f, 2.40000f}, { 3.30000f, -0.25000f, 2.40000f},
{ 3.30000f, 0.00000f, 2.40000f}, { 2.80000f, 0.00000f, 2.47500f},
{ 2.80000f, -0.25000f, 2.47500f}, { 3.52500f, -0.25000f, 2.49375f},
{ 3.52500f, 0.00000f, 2.49375f}, { 2.90000f, 0.00000f, 2.47500f},
{ 2.90000f, -0.15000f, 2.47500f}, { 3.45000f, -0.15000f, 2.51250f},
{ 3.45000f, 0.00000f, 2.51250f}, { 2.80000f, 0.00000f, 2.40000f},
{ 2.80000f, -0.15000f, 2.40000f}, { 3.20000f, -0.15000f, 2.40000f},
{ 3.20000f, 0.00000f, 2.40000f}
};

265
demos/teapot.hlsl Normal file
View File

@@ -0,0 +1,265 @@
/*
* Copyright 2025 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define M_PI 3.14159265
cbuffer teapot_cb : register(b0)
{
float4x4 mvp_matrix;
float3 eye;
float level;
uint wireframe, flat;
};
struct control_point
{
float4 position : SV_POSITION;
};
struct patch_constant_data
{
float edges[4] : SV_TessFactor;
float inside[2] : SV_InsideTessFactor;
};
struct gs_in
{
float4 position : SV_POSITION;
float3 pos : POSITION;
float3 normal : NORMAL;
};
struct ps_in
{
float4 position : SV_POSITION;
float3 pos : POSITION;
float3 normal : NORMAL;
float2 barycentric : BARYCENTRIC;
};
float4 vs_main(float4 position : POSITION, uint id : SV_InstanceID) : SV_POSITION
{
/* Mirror/flip patches based on the instance ID. */
position.w = -1.0;
if (id & 1)
position.yw = -position.yw;
if (id & 2)
position.xw = -position.xw;
return position;
}
struct patch_constant_data patch_constant(InputPatch<control_point, 16> input)
{
struct patch_constant_data output;
output.edges[0] = level;
output.edges[1] = level;
output.edges[2] = level;
output.edges[3] = level;
output.inside[0] = level;
output.inside[1] = level;
return output;
}
[domain("quad")]
[outputcontrolpoints(16)]
[outputtopology("triangle_ccw")]
[partitioning("integer")]
[patchconstantfunc("patch_constant")]
struct control_point hs_main(InputPatch<control_point, 16> input, uint i : SV_OutputControlPointID)
{
/* Reorder mirrored/flipped control points. */
if (input[0].position.w < 0.0)
{
uint u = i % 4, v = i / 4;
return input[v * 4 + (3 - u)];
}
return input[i];
}
float3 eval_quadratic(float3 p0, float3 p1, float3 p2, float t)
{
return lerp(lerp(p0, p1, t), lerp(p1, p2, t), t);
}
float3 eval_cubic(float3 p0, float3 p1, float3 p2, float3 p3, float t)
{
return lerp(eval_quadratic(p0, p1, p2, t),
eval_quadratic(p1, p2, p3, t), t);
}
struct gs_in eval_patch(float2 t, float4 p[16])
{
float3 position, normal, q[4], u, v;
struct gs_in o;
q[0] = eval_cubic( p[0].xyz, p[1].xyz, p[2].xyz, p[3].xyz, t.x);
q[1] = eval_cubic( p[4].xyz, p[5].xyz, p[6].xyz, p[7].xyz, t.x);
q[2] = eval_cubic( p[8].xyz, p[9].xyz, p[10].xyz, p[11].xyz, t.x);
q[3] = eval_cubic(p[12].xyz, p[13].xyz, p[14].xyz, p[15].xyz, t.x);
u = eval_quadratic(q[0], q[1], q[2], t.y) - eval_quadratic(q[1], q[2], q[3], t.y);
q[0] = eval_cubic(p[0].xyz, p[4].xyz, p[8].xyz, p[12].xyz, t.y);
q[1] = eval_cubic(p[1].xyz, p[5].xyz, p[9].xyz, p[13].xyz, t.y);
q[2] = eval_cubic(p[2].xyz, p[6].xyz, p[10].xyz, p[14].xyz, t.y);
q[3] = eval_cubic(p[3].xyz, p[7].xyz, p[11].xyz, p[15].xyz, t.y);
v = eval_quadratic(q[0], q[1], q[2], t.x) - eval_quadratic(q[1], q[2], q[3], t.x);
position = eval_cubic(q[0], q[1], q[2], q[3], t.x);
o.position = mul(mvp_matrix, float4(position, 1.0));
o.pos = position;
/* The patches for the bottom of the teapot and the top of its lid are
* degenerate. Technically this isn't the right way to deal with that, but
* it's easy and gets the right result for these patches. */
if (length(v) == 0.0)
normal = cross(p[4].xyz - p[0].xyz, p[7].xyz - p[3].xyz);
else
normal = cross(u, v);
o.normal = normalize(normal);
return o;
}
[domain("quad")]
struct gs_in ds_main(struct patch_constant_data input,
float2 tess_coord : SV_DomainLocation, const OutputPatch<control_point, 16> patch)
{
return eval_patch(tess_coord, patch);
}
[maxvertexcount(3)]
void gs_main(triangle struct gs_in i[3], inout TriangleStream<struct ps_in> stream)
{
struct ps_in v[3];
float3 n;
v[0].position = i[0].position;
v[0].pos = i[0].pos;
v[0].normal = i[0].normal;
v[0].barycentric = float2(1.0, 0.0);
v[1].position = i[1].position;
v[1].pos = i[1].pos;
v[1].normal = i[1].normal;
v[1].barycentric = float2(0.0, 1.0);
v[2].position = i[2].position;
v[2].pos = i[2].pos;
v[2].normal = i[2].normal;
v[2].barycentric = float2(0.0, 0.0);
if (flat)
{
n = normalize(cross(i[1].pos - i[0].pos, i[2].pos - i[0].pos));
v[0].normal = n;
v[1].normal = n;
v[2].normal = n;
}
stream.Append(v[0]);
stream.Append(v[1]);
stream.Append(v[2]);
}
/* Lambertian diffuse. */
float3 brdf_lambert(float3 diffuse)
{
return diffuse / M_PI;
}
/* The Schlick Fresnel approximation:
*
* R(θ) ≈ R₀ + (1 - R₀)(1 - c̅o̅s̅ θ)⁵
*/
float3 fresnel_schlick(float3 r0, float cos_theta)
{
return lerp(r0, 1.0, pow(1.0 - cos_theta, 5.0));
}
float g1(float cos_theta, float alpha_sq)
{
return cos_theta + sqrt(alpha_sq + (cos_theta - alpha_sq * cos_theta) * cos_theta);
}
/* Trowbridge-Reitz, "Average irregularity representation of a rough surface for ray reflection".
* Also known as "GGX".
*
* G1(θ) = 2 / (1 + sqrt(α² + (1 - α²)c̅o̅s̅² θ))
* G(θᵢ, θₒ) = G1(θᵢ) * G1(θₒ)
*
* This returns G / (4 c̅o̅s̅ θᵢ c̅o̅s̅ θₒ)
*/
float geometric_att_trowbridge_reitz(float cos_theta_i, float cos_theta_o, float alpha_sq)
{
return 1.0 / (g1(cos_theta_i, alpha_sq) * g1(cos_theta_o, alpha_sq));
}
/* Trowbridge-Reitz, "Average irregularity representation of a rough surface for ray reflection".
* Also known as "GGX".
*
* D(θ) = α² / π((cos² θ)(α² - 1) + 1)²
*/
float ndf_trowbridge_reitz(float cos_theta_h, float alpha_sq)
{
float f = (cos_theta_h * alpha_sq - cos_theta_h) * cos_theta_h + 1.0;
return alpha_sq / (M_PI * f * f);
}
float4 ps_main(struct ps_in i) : SV_TARGET
{
float3 barycentric, diffuse, diffuse_colour, radiance, specular, f, h, n, v;
float alpha, alpha_sq, cos_theta_h, cos_theta_i, cos_theta_o, d, g, wire;
float3 light_dir = normalize(float3(5.0, 5.0, 10.0));
float3 light_colour = float3(1.0, 0.95, 0.88);
float3 light_irradiance = 5.0 * light_colour;
float3 base_colour = float3(0.8, 0.8, 0.8);
float3 f0 = float3(0.04, 0.04, 0.04);
float3 ambient = 0.3 * light_colour;
float roughness = 0.2;
float metallic = 0.3;
n = normalize(i.normal);
v = normalize(eye - i.pos);
h = normalize(light_dir + v);
cos_theta_h = dot(n, h);
cos_theta_i = saturate(dot(n, light_dir));
cos_theta_o = saturate(dot(n, v));
diffuse_colour = base_colour * (float3(1.0, 1.0, 1.0) - f0) * (1.0 - metallic);
alpha = roughness * roughness;
alpha_sq = alpha * alpha;
/* Cook-Torrance. The division by (4 c̅o̅s̅ θᵢ c̅o̅s̅ θₒ) is folded into G. */
f = fresnel_schlick(lerp(f0, base_colour, metallic), dot(v, h));
g = geometric_att_trowbridge_reitz(cos_theta_i, cos_theta_o, alpha_sq);
d = ndf_trowbridge_reitz(cos_theta_h, alpha_sq);
diffuse = (1.0 - f) * brdf_lambert(diffuse_colour);
specular = f * g * d;
radiance = (diffuse + specular) * light_irradiance * cos_theta_i;
radiance += ambient * base_colour;
barycentric = float3(i.barycentric, 1.0 - (i.barycentric.x + i.barycentric.y));
barycentric /= fwidth(barycentric);
wire = wireframe ? min(min(barycentric.x, barycentric.y), barycentric.z) : 1.0;
return float4(lerp(float3(1.00, 0.69, 0.0), saturate(radiance), saturate(wire)), 1.0);
}

95
demos/text.hlsl Normal file
View File

@@ -0,0 +1,95 @@
/*
* Copyright 2025 Henri Verbeet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
cbuffer text_cb : register(b0)
{
uint4 screen_size;
uint4 glyphs[96];
};
Buffer<uint> text : register(t0);
struct text_run
{
float4 colour : COLOUR;
uint2 position : POSITION;
uint start_idx : IDX; /* The start offset of the run in the "text" Buffer. */
uint char_count : COUNT;
uint reverse : REVERSE;
float scale : SCALE;
};
struct ps_in
{
float4 position : SV_POSITION;
float2 texcoord : TEXCOORD;
uint start_idx : IDX; /* The start offset of the run in the "text" Buffer. */
uint reverse : REVERSE;
float4 colour : COLOUR;
};
struct ps_in vs_main(struct text_run t, uint id : SV_VertexID)
{
float2 pixel, pos, size;
struct ps_in o;
pixel = float2(2.0, 2.0) / float2(screen_size.x, screen_size.y);
pos = pixel * t.position - float2(1.0, 1.0);
size = pixel * t.scale * float2(t.char_count * 9.0, 16.0);
o.position.x = (id & 0x1) * size.x + pos.x;
o.position.y = ((id >> 1) & 0x1) * size.y + pos.y;
o.position.z = 0.0;
o.position.w = 1.0;
o.texcoord.x = (id & 0x1) * t.char_count;
o.texcoord.y = (~id >> 1) & 0x1;
o.start_idx = t.start_idx;
o.reverse = t.reverse;
o.colour = t.colour;
return o;
}
float4 ps_main(struct ps_in i) : SV_TARGET
{
uint idx, glyph_id, row;
uint4 glyph;
uint2 texel;
/* We determine the current character based on the start offset and texture
* coordinate. We then lookup the corresponding glyph in glyphs[]. */
idx = i.start_idx + i.texcoord.x;
glyph_id = text[idx] - 0x20;
glyph = glyphs[glyph_id];
/* Find the row within the glyph bitmap, and then the pixel within that row.
* Note that we apply dot stretching here; a single pixel in the source
* glyph results in two pixels in the output. */
texel = frac(i.texcoord.xy) * float2(9, 16);
row = (glyph[texel.y / 4] >> (8 * (texel.y % 4))) & 0xff;
if (!(i.reverse ^ (((row | (row << 1)) >> (8 - texel.x)) & 0x1)))
discard;
/* Scan line gaps. */
if (uint(i.position.y) & 1)
return float4(i.colour.xyz * (screen_size.z >= 2 ? 0.5 : 0.8), 1.0);
return i.colour;
}

View File

@@ -72,7 +72,7 @@ struct cx_triangle
struct demo_swapchain *swapchain;
ID3D12DescriptorHeap *rtv_heap;
unsigned int rtv_descriptor_size;
ID3D12Resource *render_targets[3];
ID3D12Resource **render_targets;
ID3D12CommandAllocator *command_allocator;
ID3D12RootSignature *root_signature;
@@ -164,10 +164,11 @@ static void cxt_destroy_pipeline(struct cx_triangle *cxt)
unsigned int i;
ID3D12CommandAllocator_Release(cxt->command_allocator);
for (i = 0; i < ARRAY_SIZE(cxt->render_targets); ++i)
for (i = 0; i < demo_swapchain_get_back_buffer_count(cxt->swapchain); ++i)
{
ID3D12Resource_Release(cxt->render_targets[i]);
}
free(cxt->render_targets);
ID3D12DescriptorHeap_Release(cxt->rtv_heap);
demo_swapchain_destroy(cxt->swapchain);
ID3D12CommandQueue_Release(cxt->command_queue);
@@ -180,7 +181,7 @@ static void cxt_load_pipeline(struct cx_triangle *cxt)
D3D12_DESCRIPTOR_HEAP_DESC rtv_heap_desc;
D3D12_CPU_DESCRIPTOR_HANDLE rtv_handle;
D3D12_COMMAND_QUEUE_DESC queue_desc;
unsigned int i;
unsigned int i, rt_count;
HRESULT hr;
hr = D3D12CreateDevice(NULL, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&cxt->device);
@@ -193,16 +194,19 @@ static void cxt_load_pipeline(struct cx_triangle *cxt)
&IID_ID3D12CommandQueue, (void **)&cxt->command_queue);
assert(SUCCEEDED(hr));
swapchain_desc.buffer_count = ARRAY_SIZE(cxt->render_targets);
swapchain_desc.buffer_count = 3;
swapchain_desc.format = DXGI_FORMAT_B8G8R8A8_UNORM;
swapchain_desc.width = cxt->width;
swapchain_desc.height = cxt->height;
cxt->swapchain = demo_swapchain_create(cxt->command_queue, cxt->window, &swapchain_desc);
assert(cxt->swapchain);
rt_count = demo_swapchain_get_back_buffer_count(cxt->swapchain);
cxt->render_targets = calloc(rt_count, sizeof(*cxt->render_targets));
assert(cxt->render_targets);
cxt->frame_idx = demo_swapchain_get_current_back_buffer_index(cxt->swapchain);
memset(&rtv_heap_desc, 0, sizeof(rtv_heap_desc));
rtv_heap_desc.NumDescriptors = ARRAY_SIZE(cxt->render_targets);
rtv_heap_desc.NumDescriptors = rt_count;
rtv_heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
rtv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
hr = ID3D12Device_CreateDescriptorHeap(cxt->device, &rtv_heap_desc,
@@ -212,7 +216,7 @@ static void cxt_load_pipeline(struct cx_triangle *cxt)
cxt->rtv_descriptor_size = ID3D12Device_GetDescriptorHandleIncrementSize(cxt->device,
D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
rtv_handle = ID3D12DescriptorHeap_GetCPUDescriptorHandleForHeapStart(cxt->rtv_heap);
for (i = 0; i < ARRAY_SIZE(cxt->render_targets); ++i)
for (i = 0; i < rt_count; ++i)
{
cxt->render_targets[i] = demo_swapchain_get_back_buffer(cxt->swapchain, i);
ID3D12Device_CreateRenderTargetView(cxt->device, cxt->render_targets[i], NULL, rtv_handle);
@@ -368,12 +372,16 @@ static int cxt_main(void)
{
unsigned int width = 640, height = 480;
struct cx_triangle cxt;
double dpi_x, dpi_y;
memset(&cxt, 0, sizeof(cxt));
if (!demo_init(&cxt.demo, NULL))
return EXIT_FAILURE;
demo_get_dpi(&cxt.demo, &dpi_x, &dpi_y);
width *= dpi_x / 96.0;
height *= dpi_y / 96.0;
cxt.window = demo_window_create(&cxt.demo, "Vkd3d Triangle", width, height, &cxt);
demo_window_set_expose_func(cxt.window, cxt_render_frame);
demo_window_set_key_press_func(cxt.window, cxt_key_press);
@@ -392,6 +400,8 @@ static int cxt_main(void)
cxt_load_pipeline(&cxt);
cxt_load_assets(&cxt);
printf("vkd3d-triangle: Running on \"%s\" using %s.\n",
demo_swapchain_get_device_name(cxt.swapchain), demo_get_platform_name());
demo_process_events(&cxt.demo);
cxt_wait_for_previous_frame(&cxt);

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