Skip to content

Commit

Permalink
GLSL: Handle empty block declarations.
Browse files Browse the repository at this point in the history
Similar fix as for structs.
  • Loading branch information
HansKristian-Work committed Oct 11, 2023
1 parent 73726f3 commit 7562018
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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()
{
}

21 changes: 21 additions & 0 deletions shaders-no-opt/asm/comp/empty-ubo-block.noeliminate.asm.comp
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7562018

Please sign in to comment.