From ee6bbd30f8b4c7e9d73124272cc0eec03093ddec Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 3 Sep 2022 15:05:33 +0300 Subject: [PATCH] Validate that compute shaders specify a workgroup size --- source/glsl/validate.cpp | 9 +++++++++ source/glsl/validate.h | 1 + tests/glsl/missing_workgroup_size.glsl | 10 ++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/glsl/missing_workgroup_size.glsl diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 4c135892..5a28fcb6 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -60,6 +60,11 @@ void DeclarationValidator::apply(Stage &s, const Features &f) if(!have_output_vertex_count) error(*global_err_node, "No vertex count qualifier found on output"); } + else if(s.type==Stage::COMPUTE) + { + if(!have_workgroup_size) + error(*global_err_node, "No workgroup size qualifier found"); + } } const char *DeclarationValidator::describe_variable(ScopeType scope) @@ -193,7 +198,11 @@ void DeclarationValidator::visit(Layout &layout) value = false; } else if(q.name=="local_size_x" || q.name=="local_size_y" || q.name=="local_size_z") + { allowed = (stage->type==Stage::COMPUTE && iface_layout && iface_layout->interface=="in"); + if(allowed) + have_workgroup_size = true; + } else if(q.name=="rgba32f" || q.name=="rgba16f" || q.name=="rg32f" || q.name=="rg16f" || q.name=="r32f" || q.name=="r16f" || q.name=="rgba16" || q.name=="rgba8" || q.name=="rg16" || q.name=="rg8" || q.name=="r16" || q.name=="r8" || q.name=="rgba16_snorm" || q.name=="rgba8_snorm" || q.name=="rg16_snorm" || q.name=="rg8_snorm" || q.name=="r16_snorm" || q.name=="r8_snorm") diff --git a/source/glsl/validate.h b/source/glsl/validate.h index f5620435..3166c39b 100644 --- a/source/glsl/validate.h +++ b/source/glsl/validate.h @@ -47,6 +47,7 @@ private: bool have_input_primitive = false; bool have_output_primitive = false; bool have_output_vertex_count = false; + bool have_workgroup_size = false; public: void apply(Stage &, const Features &); diff --git a/tests/glsl/missing_workgroup_size.glsl b/tests/glsl/missing_workgroup_size.glsl new file mode 100644 index 00000000..376ebaad --- /dev/null +++ b/tests/glsl/missing_workgroup_size.glsl @@ -0,0 +1,10 @@ +#pragma MSP stage(compute) +layout(r32f) uniform image2D img; +void main() +{ + imageStore(img, ivec2(gl_GlobalInvocationID.xy), vec4(1.0)); +} + +/* Expected error: +:3: No workgroup size qualifier found +*/ -- 2.45.2