From e55bc76fd270039f6727e9f8bcbb216db1896cca Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Thu, 3 Oct 2024 15:43:33 +0200 Subject: [PATCH] vkd3d-shader/glsl: Implement support for VKD3D_SHADER_COMPONENT_UINT inputs. --- libs/vkd3d-shader/glsl.c | 48 ++++++++++++++----- .../shader-interstage-interface.shader_test | 2 +- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index d85d4723..4b8504c9 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -1008,7 +1008,19 @@ static void shader_glsl_shader_prologue(struct vkd3d_glsl_generator *gen) } else { - vkd3d_string_buffer_printf(buffer, " = shader_in_%u", i); + switch (e->component_type) + { + case VKD3D_SHADER_COMPONENT_UINT: + vkd3d_string_buffer_printf(buffer, " = uintBitsToFloat(shader_in_%u)", i); + break; + default: + vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, + "Internal compiler error: Unhandled input component type %#x.", e->component_type); + /* fall through */ + case VKD3D_SHADER_COMPONENT_FLOAT: + vkd3d_string_buffer_printf(buffer, " = shader_in_%u", i); + break; + } } } else @@ -1616,24 +1628,17 @@ static void shader_glsl_generate_input_declarations(struct vkd3d_glsl_generator const struct shader_signature *signature = &gen->program->input_signature; struct vkd3d_string_buffer *buffer = gen->buffer; const struct signature_element *e; - unsigned int i; + unsigned int i, count; if (!gen->interstage_input) { - for (i = 0; i < signature->element_count; ++i) + for (i = 0, count = 0; i < signature->element_count; ++i) { e = &signature->elements[i]; if (e->target_location == SIGNATURE_TARGET_LOCATION_UNUSED || e->sysval_semantic) continue; - if (e->component_type != VKD3D_SHADER_COMPONENT_FLOAT) - { - vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, - "Internal compiler error: Unhandled component type %#x.", e->component_type); - continue; - } - if (e->min_precision != VKD3D_SHADER_MINIMUM_PRECISION_NONE) { vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, @@ -1648,15 +1653,32 @@ static void shader_glsl_generate_input_declarations(struct vkd3d_glsl_generator continue; } - vkd3d_string_buffer_printf(buffer, - "layout(location = %u) in vec4 shader_in_%u;\n", e->target_location, i); + vkd3d_string_buffer_printf(buffer, "layout(location = %u) in ", e->target_location); + switch (e->component_type) + { + case VKD3D_SHADER_COMPONENT_UINT: + vkd3d_string_buffer_printf(buffer, "uvec4"); + break; + case VKD3D_SHADER_COMPONENT_FLOAT: + vkd3d_string_buffer_printf(buffer, "vec4"); + break; + default: + vkd3d_string_buffer_printf(buffer, "", e->component_type); + vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, + "Internal compiler error: Unhandled input component type %#x.", e->component_type); + break; + } + vkd3d_string_buffer_printf(buffer, " shader_in_%u;\n", i); + ++count; } + if (count) + vkd3d_string_buffer_printf(buffer, "\n"); } else if (gen->limits.input_count) { shader_glsl_generate_interface_block(gen, signature, "in", gen->limits.input_count); + vkd3d_string_buffer_printf(buffer, "\n"); } - vkd3d_string_buffer_printf(buffer, "\n"); } static void shader_glsl_generate_output_declarations(struct vkd3d_glsl_generator *gen) diff --git a/tests/hlsl/shader-interstage-interface.shader_test b/tests/hlsl/shader-interstage-interface.shader_test index d678e7ac..bb8bd575 100644 --- a/tests/hlsl/shader-interstage-interface.shader_test +++ b/tests/hlsl/shader-interstage-interface.shader_test @@ -52,5 +52,5 @@ void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, } [test] -todo(glsl) draw triangle strip 4 +draw triangle strip 4 probe (0, 0) rgba (10.0, 8.0, 7.0, 3.0)