GLSL: Handle empty block declarations.

Similar fix as for structs.
This commit is contained in:
Hans-Kristian Arntzen 2023-10-11 13:03:21 +02:00
parent 73726f37c5
commit 75620181bc
3 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,12 @@
#version 460
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 15, std140) uniform type_Primitive
{
int empty_struct_member;
} Primitive;
void main()
{
}

View File

@ -0,0 +1,21 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 460
OpName %main "main"
OpName %type_Primitive "type_Primitive"
OpName %Primitive "Primitive"
OpDecorate %type_Primitive Block
OpDecorate %Primitive DescriptorSet 0
OpDecorate %Primitive Binding 15
%void = OpTypeVoid
%3 = OpTypeFunction %void
%type_Primitive = OpTypeStruct
%_ptr_Uniform_type_Primitive = OpTypePointer Uniform %type_Primitive
%Primitive = OpVariable %_ptr_Uniform_type_Primitive Uniform
%main = OpFunction %void None %3
%5 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -2465,6 +2465,10 @@ void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
i++;
}
// Don't declare empty blocks in GLSL, this is not allowed.
if (type_is_empty(type) && !backend.supports_empty_struct)
statement("int empty_struct_member;");
// var.self can be used as a backup name for the block name,
// so we need to make sure we don't disturb the name here on a recompile.
// It will need to be reset if we have to recompile.