703 Commits

Author SHA1 Message Date
Henri Verbeet
e69f3da089 vkd3d-shader/hlsl: Set the "has_point_size" flag for vertex shaders outputting point sizes. 2025-09-11 16:09:46 +02:00
Henri Verbeet
84d3a8d167 vkd3d-shader/hlsl: Use VKD3DSPR_COMBINED_SAMPLER destination operands in sm1_generate_vsir_sampler_dcls().
That's what the d3d-asm target expects in shader_print_dcl_usage(), and
what vkd3d_shader_scan() requires to create correct descriptor
information.
2025-09-11 16:09:46 +02:00
Henri Verbeet
4569a9d5ba vkd3d-shader/hlsl: Set the "flat constant" count in sm1_generate_vsir().
Aside from being required in order to produce valid vsir, this is used
by vsir_program_scan() to generate descriptor information.
2025-09-11 16:09:46 +02:00
Henri Verbeet
2b5dc156c7 vkd3d-shader/hlsl: vsir constant buffer sizes are specified in bytes. 2025-09-11 16:09:46 +02:00
Henri Verbeet
7c0b70db85 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_resource_declaration(). 2025-09-11 16:08:58 +02:00
Henri Verbeet
06dadcfb42 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_cbv_declaration(). 2025-09-11 16:08:58 +02:00
Henri Verbeet
3a6ebfa826 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_push_constant_buffers(). 2025-09-11 16:08:58 +02:00
Henri Verbeet
91e69f41cf vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_dcl_indexable_temp(). 2025-09-11 16:08:58 +02:00
Henri Verbeet
f9d473b4fe vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_shader_epilogue_function(). 2025-09-11 16:08:58 +02:00
Henri Verbeet
de2095fda4 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_throw_invalid_dst_type_error_with_flags(). 2025-09-10 11:59:04 +02:00
Henri Verbeet
b326097473 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_shift_operation(). 2025-09-10 11:59:04 +02:00
Henri Verbeet
e7f3547c24 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_cast_operation(). 2025-09-10 11:59:04 +02:00
Henri Verbeet
81f229146c vkd3d-shader/ir: Handle all component types in vsir_data_type_from_component_type(). 2025-09-10 11:42:21 +02:00
Henri Verbeet
db704d2980 vkd3d-shader/spirv: Handle i64 component types. 2025-09-10 11:42:21 +02:00
Elizabeth Figura
446b59319b vkd3d-utils: Null-terminate the output of D3DPreprocess().
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58596
2025-09-10 11:40:03 +02:00
Elizabeth Figura
f52dc8a89a vkd3d-utils: Null-terminate the output of D3DDisassemble(). 2025-09-10 11:40:03 +02:00
Elizabeth Figura
df1c94dd60 vkd3d-shader: Document the null terminator appended for textual formats.
vkd3d_string_buffer uses vsnprintf() and therefore null-terminates when
appending, so no code changes are necessary.
2025-09-10 11:39:43 +02:00
Elizabeth Figura
bb7c95f7d6 tests: Test special characters. 2025-09-10 11:09:04 +02:00
Elizabeth Figura
7fe82bcd85 tests: Test null-termination. 2025-09-10 11:05:01 +02:00
Henri Verbeet
d26f75f12c vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_load_invocation_id(). 2025-09-09 15:02:08 +02:00
Henri Verbeet
361404a1d1 vkd3d-shader/spirv: Use spirv_get_type_id() in frag_coord_fixup(). 2025-09-09 15:02:08 +02:00
Henri Verbeet
34dbf38e83 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_draw_parameter_fixup(). 2025-09-09 15:02:08 +02:00
Henri Verbeet
f13c2932de vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_bool_to_double(). 2025-09-09 15:02:08 +02:00
Henri Verbeet
d98bbb2a9d vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_bool_to_float(). 2025-09-09 15:02:08 +02:00
Henri Verbeet
e569245e1f vkd3d-shader/hlsl: Implement constant folding of 'round' expressions. 2025-09-09 14:59:11 +02:00
Henri Verbeet
5a8a2bb15f tests/hlsl: Add a constant folding test for round(). 2025-09-09 14:59:11 +02:00
Henri Verbeet
23ee29a953 vkd3d-shader/hlsl: Implement constant folding of 'reinterpret' expressions.
As encountered in tests/hlsl/frexp.shader_test.
2025-09-09 14:59:11 +02:00
Henri Verbeet
e330ad2ac7 vkd3d-shader/hlsl: Implement constant folding of 'cos' expressions.
As encountered in tests/hlsl/trigonometry.shader_test.
2025-09-09 14:59:01 +02:00
Henri Verbeet
08e7806b7f vkd3d-shader/hlsl: Implement constant folding of 'sin' expressions.
As encountered in tests/hlsl/trigonometry.shader_test.
2025-09-09 14:51:15 +02:00
Henri Verbeet
d7a05d823c vkd3d-shader/hlsl: Implement constant folding of 'mad' expressions.
As encountered in tests/hlsl/trigonometry.shader_test.
2025-09-09 14:51:15 +02:00
Francisco Casas
7f4a186e6a vkd3d-shader/ir: Use iterators in struct vsir_cfg.
And therefore on the functions that use it, namely
vsir_program_structurize() and
vsir_program_materialize_undominated_ssas_to_temps() and their callees.
2025-09-09 14:51:15 +02:00
Francisco Casas
1aa6c767ea vkd3d-shader/ir: Merge the hull shader phase flattener into a single pass. 2025-09-09 14:50:34 +02:00
Francisco Casas
434d9dd117 vkd3d-shader/ir: Use iterators in flattener_flatten_phases(). 2025-09-09 14:24:06 +02:00
Henri Verbeet
bceb4d17ed vkd3d-shader/ir: Move the instruction array helpers to ir.c. 2025-09-09 14:17:51 +02:00
Francisco Casas
952e706883 vkd3d-shader/ir: Use iterators in control_point_normaliser_emit_hs_input(). 2025-09-09 12:40:06 +02:00
Francisco Casas
500d54d588 vkd3d-shader/ir: Avoid direct instruction array access in validation_error(). 2025-09-09 12:31:12 +02:00
Giovanni Mascellani
05b5a48c1d vkd3d-shader/msl: Reject UAV stores to multi-sampled resources.
Current versions of MSL don't support this, and it doesn't seem likely
that Direct3D source formats do either.
2025-09-09 12:10:44 +02:00
Giovanni Mascellani
26c51f53b7 vkd3d-shader/msl: Access resources as non-multisampled if the sample count is 1. 2025-09-09 12:08:36 +02:00
Henri Verbeet
6607b94ad7 vkd3d-shader/ir: Map 16-bit vsir types to 16-bit component types in vkd3d_component_type_from_data_type().
Mapping these to 32-bit types if needed is supposed to happen in the
frontends now.
2025-09-08 12:34:16 +02:00
Henri Verbeet
38078f2c51 vkd3d-shader/hlsl: Map HLSL_TYPE_HALF to VSIR_DATA_F32.
VSIR_DATA_F16 would require VKD3DSGF_FORCE_NATIVE_LOW_PRECISION, but we
don't currently implement that. vkd3d_component_type_from_data_type()
currently ends up doing this mapping for us in the SPIR-V backend, but
that's about to go away.
2025-09-08 12:34:16 +02:00
Henri Verbeet
ea90f7ae2e vkd3d-shader/dxil: Emit 16-bit indexable temporaries as 32-bit registers.
Unless the "native low precision" flag is enabled.
vkd3d_component_type_from_data_type() currently ends up doing this
mapping for us in the SPIR-V backend, but that's about to go away.
2025-09-08 12:34:16 +02:00
Henri Verbeet
e3118110bf vkd3d-shader/d3d-asm: Print data types for indexable temporary declarations. 2025-09-08 12:34:16 +02:00
Henri Verbeet
7851cbfd3d vkd3d-shader/msl: Do not pretend to support initialisers for indexable temporaries. 2025-09-08 12:33:44 +02:00
Elizabeth Figura
0096ae43e1 vkd3d-shader/hlsl: Remove liveness range tracking from the allocator.
We no longer use it.
2025-09-04 14:04:27 +02:00
Elizabeth Figura
a44d79a13c vkd3d-shader/hlsl: Use a simple counter for indexable temps. 2025-09-04 14:04:27 +02:00
Elizabeth Figura
8db9465693 vkd3d-shader/hlsl: Use unique temps for SINCOS. 2025-09-04 14:04:27 +02:00
Henri Verbeet
5f443593e3 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_bool_to_int64(). 2025-09-04 14:03:34 +02:00
Henri Verbeet
441088e4df vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_bool_to_int(). 2025-09-04 14:03:34 +02:00
Henri Verbeet
b9b883877d vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_int_to_bool(). 2025-09-04 14:03:34 +02:00
Henri Verbeet
2a71e96a58 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_get_descriptor_index(). 2025-09-04 14:03:34 +02:00
Henri Verbeet
0d8acc97a3 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_register_addressing(). 2025-09-04 14:03:34 +02:00
Henri Verbeet
cba58fdb59 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_comparison_operation(). 2025-09-04 14:02:51 +02:00
Henri Verbeet
535837ebfe vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_elementwise_operation(). 2025-09-04 14:02:51 +02:00
Henri Verbeet
6e68f29fa7 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_src_param(). 2025-09-04 14:02:51 +02:00
Henri Verbeet
8c94dc871d vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_dst_param(). 2025-09-04 14:02:51 +02:00
Henri Verbeet
eb5347278e vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_ssa_register(). 2025-09-04 14:02:51 +02:00
Shaun Ren
d8ea8894ab vkd3d-shader/hlsl: Support SM1 non-floating point CMP expressions. 2025-09-04 13:58:57 +02:00
Shaun Ren
df5ccd3ff0 tests/hlsl: Test ternary operations with integral vector operands. 2025-09-04 13:57:48 +02:00
Victor Chiletto
f9f37e2973 tests/hlsl: Add a reflection test for SRV structured buffers. 2025-09-04 13:49:14 +02:00
Victor Chiletto
d5fdfa5f79 vkd3d-shader/hlsl: Emit RDEF metadata for SRV structured buffers. 2025-09-04 13:48:28 +02:00
Victor Chiletto
ba4027f18e vkd3d-shader/hlsl: Force default majority for resource formats. 2025-09-04 13:39:46 +02:00
Victor Chiletto
8698874628 vkd3d-shader/hlsl: Emit vsir structured loads. 2025-09-04 13:39:03 +02:00
Victor Chiletto
ae450e5957 vkd3d-shader/hlsl: Use the packed byte size as the stride for structured buffer texture declarations. 2025-09-04 13:29:51 +02:00
Victor Chiletto
9bf94ff034 vkd3d-shader/hlsl: Emit texture declarations for SRV structured buffers. 2025-09-04 13:29:51 +02:00
Henri Verbeet
2aefcf5d99 vkd3d-shader/dxil: Use vkd3d_shader_parser_error() to report errors in vsir_data_type_from_dxil(). 2025-09-03 13:04:21 +02:00
Henri Verbeet
fdc1edb647 vkd3d-shader/d3d-asm: Check the actual index count in shader_print_register().
vsir_register_init() does initialise offsets to ~0u, but at this point
that's not something that should be relied on.
2025-09-03 13:02:36 +02:00
Shaun Ren
1083b31dfd vkd3d-shader/hlsl: Implement texCUBEbias(). 2025-09-03 12:01:34 +02:00
Shaun Ren
b9545f7422 tests/hlsl: Add sample bias tests for cube textures. 2025-09-03 12:01:18 +02:00
Shaun Ren
d037b45718 tests/shader_runner: Allocate the d3d11/d3d12 resource_data arrays dynamically. 2025-09-03 11:58:42 +02:00
Shaun Ren
40789b32e7 tests/shader_runner: Correct the d3d11/d3d12 subresource indexing calculations.
See D3D11CalcSubresource()/D3D12CalcSubresource() for reference.
2025-09-03 11:57:53 +02:00
Shaun Ren
f6cebdb26d tests/shader_runner: Correct the minification filter and mipmap mode calculations. 2025-09-03 11:55:36 +02:00
Henri Verbeet
d6bed4be37 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_get_buffer_parameter(). 2025-09-02 11:36:37 +02:00
Henri Verbeet
b68096f52d vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_emit_spec_constant(). 2025-09-02 11:36:37 +02:00
Henri Verbeet
c81b5398c2 vkd3d-shader/spirv: Use spirv_get_type_id() in spirv_compiler_get_type_id_for_reg(). 2025-09-02 11:36:37 +02:00
Henri Verbeet
23c042f8ee vkd3d-shader/spirv: Rename vkd3d_spirv_get_type_id_for_data_type() to spirv_get_type_id(). 2025-09-02 11:36:37 +02:00
Henri Verbeet
3c006b2ae9 vkd3d-shader/spirv: Rename vkd3d_spirv_get_type_id() to spirv_get_type_id_for_component_type(). 2025-09-02 11:36:37 +02:00
Henri Verbeet
744a49ea4d vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_uav_register(). 2025-09-02 11:35:34 +02:00
Henri Verbeet
3443206235 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_resource_register(). 2025-09-02 11:35:33 +02:00
Henri Verbeet
2be5348383 vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_sampler_register(). 2025-09-02 11:35:33 +02:00
Henri Verbeet
3063bbe3de vkd3d-shader/ir: Use vsir_data_type_get_name() in vsir_validate_label_register(). 2025-09-02 11:35:33 +02:00
Henri Verbeet
9f2e122239 vkd3d-shader/ir: Introduce vsir_data_type_get_name(). 2025-09-02 11:35:33 +02:00
Elizabeth Figura
02d70be6ef vkd3d-shader/hlsl: Use unique temps for per-component operations. 2025-09-02 11:33:25 +02:00
Elizabeth Figura
25ae2fcc84 vkd3d-shader/hlsl: Use unique temps for non-indexable variables. 2025-09-02 11:33:25 +02:00
Elizabeth Figura
933907d3b7 vkd3d-shader/ir: Reallocate temps. 2025-09-02 11:32:35 +02:00
Elizabeth Figura
887da605c5 vkd3d-shader/hlsl: Initialize the allocator with a type. 2025-09-02 11:26:30 +02:00
Henri Verbeet
979d7e4b85 vkd3d-shader/ir: Remove VSIR_OP_DCL_OUTPUT_TOPOLOGY instructions. 2025-09-01 15:15:32 +02:00
Henri Verbeet
392da43dd3 vkd3d-shader/ir: Remove VSIR_OP_DCL_INPUT_PRIMITIVE instructions. 2025-09-01 15:15:32 +02:00
Henri Verbeet
b9b9920593 vkd3d-shader/glsl: Implement support for VKD3DSPR_SAMPLEMASK registers. 2025-09-01 15:15:32 +02:00
Henri Verbeet
05b58c9963 vkd3d-shader/glsl: Handle SV_INSTANCE_ID inputs. 2025-09-01 15:15:32 +02:00
Henri Verbeet
9b375b3dae vkd3d-shader/glsl: Implement VSIR_OP_UREM. 2025-09-01 15:15:32 +02:00
Henri Verbeet
71ed37f26d vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in vsir_program_insert_vertex_fog(). 2025-09-01 15:14:07 +02:00
Henri Verbeet
9d5cbd7efd vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in vsir_program_insert_fragment_fog(). 2025-09-01 15:14:06 +02:00
Henri Verbeet
ebeb216f00 vkd3d-shader/ir: Generate location information in vsir_program_insert_point_coord(). 2025-09-01 15:14:06 +02:00
Henri Verbeet
b3162edea5 vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in vsir_program_insert_point_size_clamp(). 2025-09-01 15:14:06 +02:00
Henri Verbeet
a63762c4d3 vkd3d-shader/ir: Pass a NULL location to vkd3d_shader_error() in vsir_program_insert_point_size(). 2025-09-01 15:14:06 +02:00
Henri Verbeet
9497c6fb70 vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in vsir_program_insert_clip_planes().
And two "whole program" locations.
2025-09-01 15:14:06 +02:00
Francisco Casas
158f8b3cf6 vkd3d-shader/dxil: Use sm6_parser_add_instruction() in sm6_parser_descriptor_type_init(). 2025-08-29 15:06:39 +02:00
Francisco Casas
1ee42bd406 vkd3d-shader/dxil: Use vsir_program_append() in sm6_parser_add_instruction(). 2025-08-29 14:59:13 +02:00
Francisco Casas
49e189fec6 vkd3d-shader/dxil: Use vsir_program_append() in sm6_function_emit_blocks(). 2025-08-29 14:59:13 +02:00
Francisco Casas
f2ac70fa60 vkd3d-shader/ir: Use iterators in vsir_program_lower_switch_to_selection_ladder(). 2025-08-29 14:22:39 +02:00
Francisco Casas
9e72d8acb8 vkd3d-shader/ir: Introduce vsir_program_iterator_insert_before_and_move(). 2025-08-29 14:22:39 +02:00
Giovanni Mascellani
11cf9e918a vkd3d: Use MESSAGE when exceeding Vulkan descriptor limits in d3d12_command_list_update_descriptor_table().
Instead of using ERR. The intention here is to notify the user that the
Vulkan implementation isn't quite capable of doing what the application
requested, but when libvkd3d is compiled with -DVKD3D_ABORT_ON_ERR, ERR
will abort the process.

This allows running the tests on older NVIDIA GPUs with
-DVKD3D_ABORT_ON_ERR.
2025-08-28 20:08:50 +02:00
Henri Verbeet
d30c992039 vkd3d-shader/glsl: Implement VSIR_OP_UDIV_SIMPLE. 2025-08-28 20:06:32 +02:00
Henri Verbeet
86656b7544 vkd3d-shader/glsl: Implement VSIR_OP_SIN. 2025-08-28 20:06:32 +02:00
Henri Verbeet
ed438c1350 vkd3d-shader/glsl: Implement VSIR_OP_COS. 2025-08-28 20:06:32 +02:00
Henri Verbeet
9609903770 vkd3d-shader/glsl: Implement VSIR_OP_DSX and VSIR_OP_DSY. 2025-08-28 20:06:32 +02:00
Henri Verbeet
4c91f4aa9e vkd3d-shader/glsl: Implement support for static texel offsets in shader_glsl_ld(). 2025-08-28 20:06:32 +02:00
Henri Verbeet
a1edfc4008 vkd3d-shader/msl: Implement compute shaders. 2025-08-28 20:05:53 +02:00
Henri Verbeet
305c2c0db4 tests/shader_runner_metal: Implement compute shader dispatch. 2025-08-28 20:05:53 +02:00
Henri Verbeet
70cc85d98e vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in vsir_program_insert_alpha_test(). 2025-08-28 20:04:59 +02:00
Henri Verbeet
096b5ef80e vkd3d-shader/ir: Pass a NULL location to vkd3d_shader_error() in insert_alpha_test_before_ret(). 2025-08-28 20:04:59 +02:00
Henri Verbeet
25a4d849b8 vkd3d-shader/ir: Pass NULL locations to vkd3d_shader_error() in use_flat_interpolation(). 2025-08-28 20:04:59 +02:00
Henri Verbeet
78e354133e vkd3d-shader/ir: Generate location information in vsir_program_ensure_diffuse(). 2025-08-28 20:04:59 +02:00
Henri Verbeet
fdb24c0fe7 vkd3d-shader/ir: Generate location information in vsir_program_ensure_ret(). 2025-08-28 20:04:59 +02:00
Henri Verbeet
e3001fcaa4 vkd3d-common: Introduce VKD3D_SHADER_API_VERSION_CURRENT. 2025-08-28 20:04:02 +02:00
Andrey Gusev
d0098b0d59 vkd3d: Recognise VK_QUEUE_OPTICAL_FLOW_BIT_NV in debug_vk_queue_flags(). 2025-08-22 20:58:06 +02:00
Elizabeth Figura
4d8e2d658a vkd3d-shader/preproc: Do not make a copy of the buffer before returning it. 2025-08-22 20:53:21 +02:00
Elizabeth Figura
586d8c9a52 vkd3d-shader/glsl: Do not make a copy of the buffer before returning it. 2025-08-22 20:53:21 +02:00
Elizabeth Figura
c897e17c81 vkd3d-shader/hlsl: Ensure yacc tokens are positive.
Negative returns from yylex() signal EOF, which is not what we want here.
2025-08-22 20:51:46 +02:00
Elizabeth Figura
a696fc1376 vkd3d-shader: Dump shaders in vkd3d_shader_preprocess(). 2025-08-22 20:50:11 +02:00
Henri Verbeet
3b41d99fa9 vkd3d-shader/tpf: Store a pointer to the vsir program in struct vkd3d_shader_sm4_parser. 2025-08-21 16:28:28 +02:00
Henri Verbeet
433ca45789 vkd3d-shader/dxil: Store a pointer to the vsir program in struct sm6_parser. 2025-08-21 16:28:28 +02:00
Henri Verbeet
4039476c50 vkd3d-shader/d3dbc: Store a pointer to the vsir program in struct vkd3d_shader_sm1_parser. 2025-08-21 16:28:28 +02:00
Henri Verbeet
0ab5090ff1 vkd3d-shader/hlsl: Support MSL as target format. 2025-08-21 16:28:00 +02:00
Elizabeth Figura
b88fce0d39 vkd3d-shader/d3dbc: Move IFC lowering to vsir_program_lower_d3dbc_instructions(). 2025-08-21 16:26:52 +02:00
Elizabeth Figura
2256c9c7cc vkd3d-shader/d3dbc: Move TEXKILL lowering to vsir_program_lower_d3dbc_instructions(). 2025-08-21 16:23:44 +02:00
Elizabeth Figura
30a591c501 vkd3d-shader/d3dbc: Move d3dbc SINCOS lowering to vsir_program_lower_d3dbc_instructions(). 2025-08-21 16:23:20 +02:00
Elizabeth Figura
12639f703e vkd3d-shader/d3dbc: Move TEXLDL lowering to vsir_program_lower_d3dbc_instructions(). 2025-08-21 16:21:25 +02:00
Elizabeth Figura
fcc5640c3e vkd3d-shader/d3dbc: Move TEXLDD lowering to vsir_program_lower_d3dbc_instructions(). 2025-08-21 16:21:18 +02:00
Francisco Casas
4dcf0b7d05 vkd3d-shader/ir: Use iterators in vsir_program_validate(). 2025-08-21 16:17:38 +02:00
Francisco Casas
d3ad3e071a vkd3d-shader/ir: Use iterators in vsir_update_dcl_temps(). 2025-08-21 16:13:54 +02:00
Francisco Casas
e3fe2cec07 vkd3d-shader/ir: Use iterators in vsir_allocate_temp_registers(). 2025-08-21 16:13:24 +02:00
Francisco Casas
687a4ab243 vkd3d-shader/ir: Use iterators in track_liveness(). 2025-08-21 16:12:43 +02:00
Francisco Casas
5485429073 vkd3d-shader/ir: Use iterators in vsir_program_insert_vertex_fog(). 2025-08-21 16:08:20 +02:00
Francisco Casas
d74d28e8ac vkd3d-shader/ir: Use iterators in vsir_program_insert_fragment_fog(). 2025-08-21 16:06:59 +02:00
Henri Verbeet
5bbd44c063 vkd3d-shader: Implement scanning compute shader thread group size information.
Metal doesn't allow the thread group size to be specified by shaders,
instead requiring it to be specified by the dispatch API.
2025-08-21 16:02:44 +02:00
Shaun Ren
320c3c9652 vkd3d-shader/hlsl: Fold some general conditional identities.
The following conditional identities are applied:

  c ? x : x -> x
  false ? x : y -> y; true ? x : y -> x
  c ? true : false -> c; c ? false : true -> !c
  !c ? x : y -> c ? y : x

Lastly, for expression chains x, y in a conditional expression
  c ? x : y,
we evaluate all conditionals in the expression chains with the
condition c, assuming c is true (for x), or false (for y).
2025-08-21 16:00:51 +02:00
Shaun Ren
245430002a vkd3d-shader/hlsl: Fold some general unary identities.
The following unary identities are applied:

  ||x|| -> |x|
  |-x| -> |x|
  ~(~x) -> x
  f(g(x)) -> g(x), where f(), g() are floor() or ceil() functions.
  -(-x) -> x
  !!x -> x
  !(x == y) -> x != y, !(x < y) -> x >= y, etc (for integers).
2025-08-21 16:00:46 +02:00
Shaun Ren
45e549c1b2 vkd3d-shader/msl: Implement VSIR_OP_UGE. 2025-08-21 15:32:37 +02:00
Shaun Ren
b8776bb6bd vkd3d-shader/glsl: Implement VSIR_OP_UGE. 2025-08-21 15:32:37 +02:00
Shaun Ren
4c37800f52 vkd3d-shader/hlsl: Check whether "expr" has more than 2 operands in hlsl_normalize_binary_exprs(). 2025-08-21 15:32:27 +02:00
Petrichor Park
d964d55b4a vkd3d-shader/hlsl: Implement the frexp() intrinsic. 2025-08-21 15:29:27 +02:00
Petrichor Park
ea6104cf5e tests/hlsl: Add some tests for the frexp() intrinsic. 2025-08-21 15:29:27 +02:00
Petrichor Park
0b8abe754a tests: Normalise NAN values in compare_float() and compare_double().
I.e., ignore the mantissa/payload of NAN values.
2025-08-21 15:29:27 +02:00
Henri Verbeet
a083748626 tests/shader_runner: Use read_f64() to parse "uniform" directives. 2025-08-21 15:29:27 +02:00
Henri Verbeet
31136ead05 tests/shader_runner: Use read_f32() to parse "uniform" directives. 2025-08-21 15:29:27 +02:00
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
209 changed files with 21613 additions and 9783 deletions

1099
ANNOUNCE

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,83 @@
# 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

View File

@@ -140,6 +140,7 @@ vkd3d_shader_tests = \
tests/hlsl/fog.shader_test \
tests/hlsl/for.shader_test \
tests/hlsl/frac.shader_test \
tests/hlsl/frexp.shader_test \
tests/hlsl/function-cast.shader_test \
tests/hlsl/function-overload.shader_test \
tests/hlsl/function-return.shader_test \
@@ -199,6 +200,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 \
@@ -214,6 +216,8 @@ vkd3d_shader_tests = \
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 \
@@ -223,6 +227,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 \
@@ -237,6 +242,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 \
@@ -299,6 +305,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 \
@@ -325,6 +332,7 @@ vkd3d_test_headers = \
vkd3d_demos = \
demos/vkd3d-gears \
demos/vkd3d-teapot \
demos/vkd3d-triangle
vkd3d_demos_headers = \
@@ -419,7 +427,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 15:0:14
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
@@ -454,7 +462,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 17:0:16
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
@@ -467,7 +475,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:2: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
@@ -549,6 +557,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)
@@ -657,6 +677,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
@@ -706,6 +727,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

View File

@@ -1,5 +1,5 @@
AC_PREREQ([2.69])
AC_INIT([vkd3d],[1.16])
AC_INIT([vkd3d],[1.17])
AC_CONFIG_AUX_DIR([bin])
AC_CONFIG_MACRO_DIR([m4])

View File

@@ -38,6 +38,7 @@
#define COBJMACROS
#include <vkd3d_d3d12.h>
#include <inttypes.h>
#include <math.h>
#ifdef __WIN32__
#define DEMO_ASM_PUSHSECTION ".section rdata\n\t"
@@ -79,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
{
@@ -98,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;
@@ -115,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;
@@ -123,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;

View File

@@ -70,6 +70,8 @@ static inline void demo_window_cleanup(struct demo_window *window)
struct demo_swapchain
{
IDXGISwapChain3 *swapchain;
unsigned int buffer_count;
char device_name[128];
};
static inline void demo_cleanup(struct demo *demo)
@@ -97,6 +99,11 @@ 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);
@@ -137,9 +144,14 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
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;
@@ -147,6 +159,27 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
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;
@@ -162,6 +195,7 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
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))
@@ -174,6 +208,11 @@ fail:
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);
@@ -190,6 +229,11 @@ static inline ID3D12Resource *demo_swapchain_get_back_buffer(struct demo_swapcha
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);

View File

@@ -176,12 +176,19 @@ static demo_key demo_key_from_nsevent(id event)
{
enum vkey
{
kVK_ANSI_A = 0x00,
kVK_Escape = 0x35,
kVK_LeftArrow = 0x7b,
kVK_RightArrow = 0x7c,
kVK_DownArrow = 0x7d,
kVK_UpArrow = 0x7e,
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;
@@ -192,12 +199,19 @@ static demo_key demo_key_from_nsevent(id event)
}
lookup[] =
{
{kVK_ANSI_A, 'a'},
{kVK_Escape, DEMO_KEY_ESCAPE},
{kVK_LeftArrow, DEMO_KEY_LEFT},
{kVK_RightArrow, DEMO_KEY_RIGHT},
{kVK_UpArrow, DEMO_KEY_UP},
{kVK_DownArrow, DEMO_KEY_DOWN},
{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);

View File

@@ -28,7 +28,7 @@
#ifdef HAVE_XCB
# define VK_USE_PLATFORM_XCB_KHR
#endif
#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_16
#define VKD3D_UTILS_API_VERSION VKD3D_API_VERSION_1_17
#include <vkd3d.h>
#include <vkd3d_utils.h>
#ifdef HAVE_XCB
@@ -59,6 +59,7 @@ DECLARE_VK_PFN(vkCreateXcbSurfaceKHR)
DECLARE_VK_PFN(vkDestroyFence)
DECLARE_VK_PFN(vkDestroySurfaceKHR)
DECLARE_VK_PFN(vkDestroySwapchainKHR)
DECLARE_VK_PFN(vkGetPhysicalDeviceProperties)
DECLARE_VK_PFN(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
DECLARE_VK_PFN(vkGetPhysicalDeviceSurfaceFormatsKHR)
DECLARE_VK_PFN(vkGetPhysicalDeviceSurfaceSupportKHR)
@@ -228,6 +229,7 @@ static void load_vulkan_procs(void)
LOAD_VK_PFN(vkDestroyFence)
LOAD_VK_PFN(vkDestroySurfaceKHR)
LOAD_VK_PFN(vkDestroySwapchainKHR)
LOAD_VK_PFN(vkGetPhysicalDeviceProperties)
LOAD_VK_PFN(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
LOAD_VK_PFN(vkGetPhysicalDeviceSurfaceFormatsKHR)
LOAD_VK_PFN(vkGetPhysicalDeviceSurfaceSupportKHR)
@@ -239,6 +241,7 @@ static void load_vulkan_procs(void)
struct demo_swapchain
{
VkPhysicalDeviceProperties vk_device_properties;
VkSurfaceKHR vk_surface;
VkSwapchainKHR vk_swapchain;
VkFence vk_fence;
@@ -310,6 +313,11 @@ static inline void demo_get_dpi(struct demo *demo, double *dpi_x, double *dpi_y)
demo->get_dpi(demo, dpi_x, dpi_y);
}
static inline const char *demo_get_platform_name(void)
{
return "vkd3d";
}
static inline void demo_process_events(struct demo *demo)
{
demo->process_events(demo);
@@ -392,9 +400,13 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
if (vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_physical_device, vk_surface, &surface_caps) < 0)
goto fail;
if ((surface_caps.maxImageCount && desc->buffer_count > surface_caps.maxImageCount)
|| desc->buffer_count < surface_caps.minImageCount
|| desc->width > surface_caps.maxImageExtent.width || desc->width < surface_caps.minImageExtent.width
image_count = desc->buffer_count;
if (image_count < surface_caps.minImageCount)
image_count = surface_caps.minImageCount;
else if (surface_caps.maxImageCount && image_count > surface_caps.maxImageCount)
image_count = surface_caps.maxImageCount;
if (desc->width > surface_caps.maxImageExtent.width || desc->width < surface_caps.minImageExtent.width
|| desc->height > surface_caps.maxImageExtent.height || desc->height < surface_caps.minImageExtent.height
|| !(surface_caps.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR))
goto fail;
@@ -432,7 +444,7 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
vk_swapchain_desc.pNext = NULL;
vk_swapchain_desc.flags = 0;
vk_swapchain_desc.surface = vk_surface;
vk_swapchain_desc.minImageCount = desc->buffer_count;
vk_swapchain_desc.minImageCount = image_count;
vk_swapchain_desc.imageFormat = format;
vk_swapchain_desc.imageColorSpace = VK_COLOR_SPACE_SRGB_NONLINEAR_KHR;
vk_swapchain_desc.imageExtent.width = desc->width;
@@ -471,6 +483,7 @@ static inline struct demo_swapchain *demo_swapchain_create(ID3D12CommandQueue *c
free(vk_images);
goto fail;
}
vkGetPhysicalDeviceProperties(vk_physical_device, &swapchain->vk_device_properties);
swapchain->vk_surface = vk_surface;
swapchain->vk_swapchain = vk_swapchain;
swapchain->vk_fence = vk_fence;
@@ -540,6 +553,11 @@ fail:
return NULL;
}
static inline const char *demo_swapchain_get_device_name(struct demo_swapchain *swapchain)
{
return swapchain->vk_device_properties.deviceName;
}
static inline unsigned int demo_swapchain_get_current_back_buffer_index(struct demo_swapchain *swapchain)
{
return swapchain->current_buffer;
@@ -555,6 +573,11 @@ static inline ID3D12Resource *demo_swapchain_get_back_buffer(struct demo_swapcha
return resource;
}
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)
{
VkPresentInfoKHR present_desc;

View File

@@ -127,18 +127,23 @@ static demo_key demo_key_from_win32_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)
{

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:
@@ -850,6 +833,7 @@ 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))
@@ -880,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);

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);
@@ -396,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);

View File

@@ -158,8 +158,7 @@ build-mac:
- mkdir artifacts
- export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:$PATH"
- export VK_DRIVER_FILES="$PWD/image/moltenvk/MoltenVK_icd.json"
# Currently disabled because it has too many failures
#- export SONAME_LIBDXCOMPILER="$PWD/image/dxc/libdxcompiler.dylib"
- export SONAME_LIBDXCOMPILER="$PWD/image/dxc/libdxcompiler.dylib"
- system_profiler SPSoftwareDataType SPHardwareDataType > artifacts/systeminfo.txt
- vulkaninfo > artifacts/vulkaninfo.txt
- git rebase $CI_MERGE_REQUEST_DIFF_BASE_SHA --exec ./gitlab/build-mac

View File

@@ -41,12 +41,10 @@ image-mac:
- mkdir image/dxc
- mkdir image/moltenvk
# The specified commit includes an update to the DirectXShaderCompiler's
# CMakeList.txt which makes it compatible with cmake (4+).
- git clone https://github.com/microsoft/DirectXShaderCompiler.git
- git clone --recursive --branch v1.8.2502 https://github.com/microsoft/DirectXShaderCompiler.git
- cd DirectXShaderCompiler
- git checkout 3035d316c35289b68e8fc9d8cf21d86a204fb0e2
- git submodule update --init --recursive
# Include a fix for CMake 4+.
- git cherry-pick 3035d316c35289b68e8fc9d8cf21d86a204fb0e2
- mkdir build
- cd build
- cmake .. -C ../cmake/caches/PredefinedParams.cmake -D CMAKE_BUILD_TYPE=Release

5
include/.gitignore vendored
View File

@@ -1,9 +1,14 @@
config.h
config.h.in
private/appkit.h
private/foundation.h
private/quartzcore.h
private/spirv_grammar.h
private/vkd3d_version.h
stamp-h1
vkd3d_d3d12.h
vkd3d_d3d12sdklayers.h
vkd3d_d3d12shader.h
vkd3d_d3dcommon.h
vkd3d_d3dx9shader.h
vkd3d_dxgi.h

File diff suppressed because it is too large Load Diff

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