From bf71b13797767ea14fa2ab05e2317a9709440978 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Sun, 6 Oct 2024 00:10:19 +0200 Subject: [PATCH] vkd3d-shader/glsl: Implement support for compute shaders. --- libs/vkd3d-shader/glsl.c | 16 ++++++++++++++-- tests/hlsl/compute.shader_test | 2 +- tests/hlsl/uav-out-param.shader_test | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libs/vkd3d-shader/glsl.c b/libs/vkd3d-shader/glsl.c index c6126536..c8efdae3 100644 --- a/libs/vkd3d-shader/glsl.c +++ b/libs/vkd3d-shader/glsl.c @@ -2068,6 +2068,14 @@ static void shader_glsl_generate_declarations(struct vkd3d_glsl_generator *gen) { const struct vsir_program *program = gen->program; struct vkd3d_string_buffer *buffer = gen->buffer; + const struct vsir_thread_group_size *group_size; + + if (program->shader_version.type == VKD3D_SHADER_TYPE_COMPUTE) + { + group_size = &program->thread_group_size; + vkd3d_string_buffer_printf(buffer, "layout(local_size_x = %u, local_size_y = %u, local_size_z = %u) in;\n\n", + group_size->x, group_size->y, group_size->z); + } shader_glsl_generate_descriptor_declarations(gen); shader_glsl_generate_input_declarations(gen); @@ -2149,6 +2157,10 @@ static void shader_glsl_init_limits(struct vkd3d_glsl_generator *gen, const stru limits->input_count = 32; limits->output_count = 8; break; + case VKD3D_SHADER_TYPE_COMPUTE: + limits->input_count = 0; + limits->output_count = 0; + break; default: vkd3d_glsl_compiler_error(gen, VKD3D_SHADER_ERROR_GLSL_INTERNAL, "Internal compiler error: Unhandled shader type %#x.", version->type); @@ -2179,8 +2191,8 @@ static void vkd3d_glsl_generator_init(struct vkd3d_glsl_generator *gen, gen->prefix = "unknown"; } shader_glsl_init_limits(gen, &program->shader_version); - gen->interstage_input = type != VKD3D_SHADER_TYPE_VERTEX; - gen->interstage_output = type != VKD3D_SHADER_TYPE_PIXEL; + gen->interstage_input = type != VKD3D_SHADER_TYPE_VERTEX && type != VKD3D_SHADER_TYPE_COMPUTE; + gen->interstage_output = type != VKD3D_SHADER_TYPE_PIXEL && type != VKD3D_SHADER_TYPE_COMPUTE; gen->interface_info = vkd3d_find_struct(compile_info->next, INTERFACE_INFO); gen->offset_info = vkd3d_find_struct(compile_info->next, DESCRIPTOR_OFFSET_INFO); diff --git a/tests/hlsl/compute.shader_test b/tests/hlsl/compute.shader_test index bd378e93..d9e77ff2 100644 --- a/tests/hlsl/compute.shader_test +++ b/tests/hlsl/compute.shader_test @@ -18,5 +18,5 @@ void main() } [test] -todo(glsl) dispatch 1 1 1 +dispatch 1 1 1 probe uav 0 (0, 0) r (-123.0) diff --git a/tests/hlsl/uav-out-param.shader_test b/tests/hlsl/uav-out-param.shader_test index 7169ec03..5e5dc657 100644 --- a/tests/hlsl/uav-out-param.shader_test +++ b/tests/hlsl/uav-out-param.shader_test @@ -26,7 +26,7 @@ void main() } [test] -todo(glsl) dispatch 1 1 1 +dispatch 1 1 1 probe uav 0 (0, 0) rgba (0.4, 0.1, 0.2, 0.3) [uav 0]