``` Datta: what have we given? My friend, blood shaking my heart The awful daring of a moment's surrender Which an age of prudence can never retract By this, and this only, we have existed Which is not to be found in our obituaries Or in memories draped by the beneficient spider Or under seals broken by the lean solicitor In our empty rooms ```
-- v3: vkd3d-shader: Allow compiling d3d bytecode to SPIR-V. tests: Avoid using "SV_Position" as a name for the vertex shader input. tests: Use struct vkd3d_shader_scan_signature_info to retrieve the VS input signature. vkd3d-shader: Do not scan DCL instructions which do not declare resources. vkd3d-shader: Do not scan the shader in vkd3d_shader_parser_compile() for assembly targets.
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/vkd3d_shader_main.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 2ee97e6ca..0600e7228 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1540,9 +1540,6 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
scan_info = *compile_info;
- if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0) - return ret; - switch (compile_info->target_type) { case VKD3D_SHADER_TARGET_D3D_ASM: @@ -1550,6 +1547,8 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser, break;
case VKD3D_SHADER_TARGET_GLSL: + if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0) + return ret; if (!(glsl_generator = vkd3d_glsl_generator_create(&parser->shader_version, message_context, &parser->location))) { @@ -1560,19 +1559,22 @@ static int vkd3d_shader_parser_compile(struct vkd3d_shader_parser *parser,
ret = vkd3d_glsl_generator_generate(glsl_generator, parser, out); vkd3d_glsl_generator_destroy(glsl_generator); + vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info); break;
case VKD3D_SHADER_TARGET_SPIRV_BINARY: case VKD3D_SHADER_TARGET_SPIRV_TEXT: + if ((ret = scan_with_parser(&scan_info, message_context, &scan_descriptor_info, parser)) < 0) + return ret; ret = spirv_compile(parser, &scan_descriptor_info, compile_info, out, message_context); + vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info); break;
default: /* Validation should prevent us from reaching this. */ - assert(0); + vkd3d_unreachable(); }
- vkd3d_shader_free_scan_descriptor_info1(&scan_descriptor_info); return ret; }
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/vkd3d_shader_main.c | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 0600e7228..49ce886af 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1073,6 +1073,9 @@ static int vkd3d_shader_scan_instruction(struct vkd3d_shader_scan_context *conte vkd3d_shader_scan_sampler_declaration(context, instruction); break; case VKD3DSIH_DCL: + if (instruction->declaration.semantic.resource_type == VKD3D_SHADER_RESOURCE_NONE) + break; + if (instruction->declaration.semantic.resource.reg.reg.type == VKD3DSPR_COMBINED_SAMPLER) { vkd3d_shader_scan_combined_sampler_declaration(context, &instruction->declaration.semantic);
From: Zebediah Figura zfigura@codeweavers.com
In order to allow retrieving it from d3dbc shaders. --- tests/shader_runner_vulkan.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/tests/shader_runner_vulkan.c b/tests/shader_runner_vulkan.c index f89b4d624..6843b6700 100644 --- a/tests/shader_runner_vulkan.c +++ b/tests/shader_runner_vulkan.c @@ -64,6 +64,8 @@ struct vulkan_shader_runner VkCommandBuffer cmd_buffer; VkDescriptorPool descriptor_pool;
+ struct vkd3d_shader_scan_signature_info vs_signatures; + struct vulkan_sampler { VkSampler vk_sampler; @@ -377,7 +379,7 @@ static void vulkan_runner_destroy_resource(struct shader_runner *r, struct resou free(resource); }
-static bool compile_shader(const struct vulkan_shader_runner *runner, const char *source, const char *type, +static bool compile_shader(struct vulkan_shader_runner *runner, const char *source, const char *type, struct vkd3d_shader_code *dxbc, struct vkd3d_shader_code *spirv) { struct vkd3d_shader_spirv_target_info spirv_info = {.type = VKD3D_SHADER_STRUCTURE_TYPE_SPIRV_TARGET_INFO}; @@ -513,6 +515,14 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char interface_info.push_constant_buffer_count = 1; interface_info.push_constant_buffers = &push_constants;
+ if (!strcmp(type, "vs")) + { + interface_info.next = &runner->vs_signatures; + + runner->vs_signatures.type = VKD3D_SHADER_STRUCTURE_TYPE_SCAN_SIGNATURE_INFO; + runner->vs_signatures.next = NULL; + } + ret = vkd3d_shader_compile(&info, spirv, &messages); if (messages && vkd3d_test_state.debug_level) trace("%s\n", messages); @@ -523,7 +533,7 @@ static bool compile_shader(const struct vulkan_shader_runner *runner, const char return true; }
-static bool create_shader_stage(const struct vulkan_shader_runner *runner, +static bool create_shader_stage(struct vulkan_shader_runner *runner, VkPipelineShaderStageCreateInfo *stage_info, const char *type, enum VkShaderStageFlagBits stage, const char *source, struct vkd3d_shader_code *dxbc_ptr) { @@ -591,7 +601,7 @@ static VkPipelineLayout create_pipeline_layout(const struct vulkan_shader_runner return pipeline_layout; }
-static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *runner, VkRenderPass render_pass, +static VkPipeline create_graphics_pipeline(struct vulkan_shader_runner *runner, VkRenderPass render_pass, VkPipelineLayout pipeline_layout, D3D_PRIMITIVE_TOPOLOGY primitive_topology) { VkPipelineInputAssemblyStateCreateInfo ia_desc = {.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO}; @@ -607,7 +617,6 @@ static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *ru VkPipelineColorBlendAttachmentState attachment_desc[MAX_RESOURCES] = {0}; VkVertexInputAttributeDescription input_attributes[32]; VkVertexInputBindingDescription input_bindings[32]; - struct vkd3d_shader_signature vs_input_signature; VkPipelineShaderStageCreateInfo stage_desc[2]; struct vkd3d_shader_code vs_dxbc; VkDevice device = runner->device; @@ -627,9 +636,6 @@ static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *ru return VK_NULL_HANDLE; }
- ret = vkd3d_shader_parse_input_signature(&vs_dxbc, &vs_input_signature, NULL); - ok(!ret, "Failed to parse input signature, error %d.\n", ret); - if (runner->r.input_element_count > ARRAY_SIZE(input_attributes)) fatal_error("Input element count %zu is too high.\n", runner->r.input_element_count);
@@ -639,7 +645,8 @@ static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *ru const struct input_element *element = &runner->r.input_elements[i]; const struct vkd3d_shader_signature_element *signature_element;
- signature_element = vkd3d_shader_find_signature_element(&vs_input_signature, element->name, element->index, 0); + signature_element = vkd3d_shader_find_signature_element(&runner->vs_signatures.input, element->name, element->index, 0); + ok(signature_element, "Cannot find signature element %s%u.\n", element->name, element->index);
attribute->location = signature_element->register_index; attribute->binding = element->slot; @@ -722,13 +729,13 @@ static VkPipeline create_graphics_pipeline(const struct vulkan_shader_runner *ru
VK_CALL(vkDestroyShaderModule(device, stage_desc[0].module, NULL)); VK_CALL(vkDestroyShaderModule(device, stage_desc[1].module, NULL)); - vkd3d_shader_free_shader_signature(&vs_input_signature); + vkd3d_shader_free_scan_signature_info(&runner->vs_signatures); vkd3d_shader_free_shader_code(&vs_dxbc);
return pipeline; }
-static VkPipeline create_compute_pipeline(const struct vulkan_shader_runner *runner, VkPipelineLayout pipeline_layout) +static VkPipeline create_compute_pipeline(struct vulkan_shader_runner *runner, VkPipelineLayout pipeline_layout) { VkComputePipelineCreateInfo pipeline_desc = {.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; VkPipeline pipeline;
From: Zebediah Figura zfigura@codeweavers.com
We use vkd3d_shader_find_signature_element() in the Vulkan runner, and vkd3d-shader translates SM1 position to "POSITION". --- tests/hlsl/entry-point-semantics.shader_test | 21 +++++++++++++------- tests/hlsl/for.shader_test | 3 ++- tests/hlsl/sample-bias.shader_test | 3 ++- tests/hlsl/struct-semantics.shader_test | 17 +++++++++++++--- tests/hlsl/trigonometry.shader_test | 3 ++- tests/shader_runner.c | 5 +++-- 6 files changed, 37 insertions(+), 15 deletions(-)
diff --git a/tests/hlsl/entry-point-semantics.shader_test b/tests/hlsl/entry-point-semantics.shader_test index d177b0376..b87dca4d9 100644 --- a/tests/hlsl/entry-point-semantics.shader_test +++ b/tests/hlsl/entry-point-semantics.shader_test @@ -2,9 +2,10 @@ % definition and its declarations.
[vertex shader] -void main(out float tex : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float tex : texcoord, out float4 out_pos : sv_position) { tex = 0.2; + out_pos = pos; }
[pixel shader fail] @@ -53,12 +54,13 @@ probe (0, 0) rgba (0.2, 0.2, 0.2, 0.2)
[vertex shader] -void main(out float4 tex[4] : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float4 tex[4] : texcoord, out float4 out_pos : sv_position) { tex[0] = float4(10.0, 11.0, 12.0, 13.0); tex[1] = float4(20.0, 21.0, 22.0, 23.0); tex[2] = float4(30.0, 31.0, 32.0, 33.0); tex[3] = float4(40.0, 41.0, 42.0, 43.0); + out_pos = pos; }
@@ -196,10 +198,11 @@ struct apple float4 tex[2] : TEXCOORD0; };
-void main(out apple apl, inout float4 pos : sv_position) +void main(float4 pos : position, out apple apl, out float4 out_pos : sv_position) { apl.tex[0] = float4(1, 2, 3, 4); apl.tex[1] = float4(10, 20, 30, 40); + out_pos = pos; }
[pixel shader] @@ -220,10 +223,11 @@ struct apple float2 tex : TEXCOORD0; };
-void main(out apple apls[2], inout float4 pos : sv_position) +void main(float4 pos : position, out apple apls[2], out float4 out_pos : sv_position) { apls[0].tex = float2(1, 2); apls[1].tex = float2(3, 4); + out_pos = pos; }
@@ -233,29 +237,32 @@ struct apple float2 f : SEMANTIC; };
-void main(out apple a, out apple b, inout float4 pos : sv_position) +void main(float4 pos : position, out apple a, out apple b, out float4 out_pos : sv_position) { a.f = float2(1, 2); b.f = float2(3, 4); + out_pos = pos; }
% Semantic names are case-insensitive. [vertex shader fail] -void main(out float2 a : sem0, out float2 b : SEM, inout float4 pos : sv_position) +void main(float4 pos : position, out float2 a : sem0, out float2 b : SEM, out float4 out_pos : sv_position) { a = float2(1, 2); b = float2(3, 4); + out_pos = pos; }
[vertex shader] -void main(out float4 tex[4] : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float4 tex[4] : texcoord, out float4 out_pos : sv_position) { tex[0] = float4(10.0, 11.0, 12.0, 13.0); tex[1] = float4(20.0, 21.0, 22.0, 23.0); tex[2] = float4(30.0, 31.0, 32.0, 33.0); tex[3] = float4(40.0, 41.0, 42.0, 43.0); + out_pos = pos; }
diff --git a/tests/hlsl/for.shader_test b/tests/hlsl/for.shader_test index 1392118b3..9407c81bc 100644 --- a/tests/hlsl/for.shader_test +++ b/tests/hlsl/for.shader_test @@ -1,7 +1,8 @@ [vertex shader] -void main(out float tex : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float tex : texcoord, out float4 out_pos : sv_position) { tex = pos.x; + out_pos = pos; }
[pixel shader] diff --git a/tests/hlsl/sample-bias.shader_test b/tests/hlsl/sample-bias.shader_test index e56945d06..5b7067b52 100644 --- a/tests/hlsl/sample-bias.shader_test +++ b/tests/hlsl/sample-bias.shader_test @@ -12,9 +12,10 @@ levels 2 0.0 0.0 1.0 0.0
[vertex shader] -void main(out float2 tex : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float2 tex : texcoord, out float4 out_pos : sv_position) { tex = pos.xy; + out_pos = pos; }
[pixel shader] diff --git a/tests/hlsl/struct-semantics.shader_test b/tests/hlsl/struct-semantics.shader_test index 43b07bb86..c88006eb8 100644 --- a/tests/hlsl/struct-semantics.shader_test +++ b/tests/hlsl/struct-semantics.shader_test @@ -1,6 +1,6 @@ [input layout] 0 r32g32b32a32 float texcoord -0 r32g32 float sv_position +0 r32g32 float position
[vertex buffer 0] 0.0 1.0 0.0 1.0 -2.0 -2.0 @@ -10,7 +10,16 @@
[vertex shader]
-struct vertex +struct in_vertex +{ + struct + { + float4 texcoord : texcoord; + float4 pos : position; + } m; +}; + +struct out_vertex { struct { @@ -19,8 +28,10 @@ struct vertex } m; };
-void main(inout struct vertex v) +void main(struct in_vertex i, out struct out_vertex o) { + o.m.pos = i.m.pos; + o.m.texcoord = i.m.texcoord; }
[pixel shader] diff --git a/tests/hlsl/trigonometry.shader_test b/tests/hlsl/trigonometry.shader_test index f52d01dea..859881199 100644 --- a/tests/hlsl/trigonometry.shader_test +++ b/tests/hlsl/trigonometry.shader_test @@ -1,7 +1,8 @@ [vertex shader] -void main(out float tex : texcoord, inout float4 pos : sv_position) +void main(float4 pos : position, out float tex : texcoord, out float4 out_pos : sv_position) { tex = (pos.x + 1) * 320; + out_pos = pos; }
[pixel shader] diff --git a/tests/shader_runner.c b/tests/shader_runner.c index 4847ec75b..9b373e017 100644 --- a/tests/shader_runner.c +++ b/tests/shader_runner.c @@ -579,8 +579,9 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) };
static const char vs_source[] = - "void main(inout float4 position : sv_position)\n" + "float4 main(float4 pos : position) : sv_position\n" "{\n" + " return pos;\n" "}";
if (!shader_runner_get_resource(runner, RESOURCE_TYPE_RENDER_TARGET, 0)) @@ -601,7 +602,7 @@ static void parse_test_directive(struct shader_runner *runner, const char *line) vkd3d_array_reserve((void **)&runner->input_elements, &runner->input_element_capacity, 1, sizeof(*runner->input_elements)); element = &runner->input_elements[0]; - element->name = strdup("sv_position"); + element->name = strdup("position"); element->slot = 0; element->format = DXGI_FORMAT_R32G32_FLOAT; element->texel_size = sizeof(*quad);
From: Zebediah Figura zfigura@codeweavers.com
--- libs/vkd3d-shader/vkd3d_shader_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libs/vkd3d-shader/vkd3d_shader_main.c b/libs/vkd3d-shader/vkd3d_shader_main.c index 49ce886af..de7a66e01 100644 --- a/libs/vkd3d-shader/vkd3d_shader_main.c +++ b/libs/vkd3d-shader/vkd3d_shader_main.c @@ -1626,14 +1626,10 @@ static int compile_d3d_bytecode(const struct vkd3d_shader_compile_info *compile_ return ret; }
- if (compile_info->target_type == VKD3D_SHADER_TARGET_D3D_ASM) - { - ret = vkd3d_dxbc_binary_to_text(&parser->instructions, &parser->shader_version, compile_info, out, VSIR_ASM_D3D); - vkd3d_shader_parser_destroy(parser); - return ret; - } + ret = vkd3d_shader_parser_compile(parser, compile_info, out, message_context);
- return VKD3D_ERROR; + vkd3d_shader_parser_destroy(parser); + return ret; }
static int compile_dxbc_dxil(const struct vkd3d_shader_compile_info *compile_info, @@ -1911,6 +1907,10 @@ const enum vkd3d_shader_target_type *vkd3d_shader_get_supported_target_types(
static const enum vkd3d_shader_target_type d3dbc_types[] = { + VKD3D_SHADER_TARGET_SPIRV_BINARY, +#ifdef HAVE_SPIRV_TOOLS + VKD3D_SHADER_TARGET_SPIRV_TEXT, +#endif VKD3D_SHADER_TARGET_D3D_ASM, };
I fixed the compiler warning by adding a vkd3d_unreachable(), but now builds are failing for what I think is the CI's fault?