Minor emit_buffer_block refactoring

Move buffer block variant dispatch into emit_buffer_block to match
emit_push_constant_block, move SSBO check into emit_buffer_block_legacy.
This commit is contained in:
Arseny Kapoulkine 2017-01-17 12:18:35 -08:00
Родитель 64c17b59e5
Коммит c5a821cdbf
2 изменённых файлов: 24 добавлений и 20 удалений

Просмотреть файл

@ -1000,9 +1000,28 @@ void CompilerGLSL::emit_push_constant_block_glsl(const SPIRVariable &var)
statement("");
}
void CompilerGLSL::emit_buffer_block(const SPIRVariable &var)
{
if (flattened_buffer_blocks.count(var.self))
{
emit_buffer_block_flattened(var);
}
else if (is_legacy())
{
emit_buffer_block_legacy(var);
}
else
{
emit_buffer_block_native(var);
}
}
void CompilerGLSL::emit_buffer_block_legacy(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
bool ssbo = (meta[type.self].decoration.decoration_flags & (1ull << DecorationBufferBlock)) != 0;
if (ssbo)
SPIRV_CROSS_THROW("SSBOs not supported in legacy targets.");
// We're emitting the push constant block as a regular struct, so disable the block qualifier temporarily.
// Otherwise, we will end up emitting layout() qualifiers on naked structs which is not allowed.
@ -1015,21 +1034,12 @@ void CompilerGLSL::emit_buffer_block_legacy(const SPIRVariable &var)
statement("");
}
void CompilerGLSL::emit_buffer_block(const SPIRVariable &var)
void CompilerGLSL::emit_buffer_block_native(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
bool ssbo = (meta[type.self].decoration.decoration_flags & (1ull << DecorationBufferBlock)) != 0;
bool is_restrict = (meta[var.self].decoration.decoration_flags & (1ull << DecorationRestrict)) != 0;
// By default, for legacy targets, fall back to declaring a uniform struct.
if (is_legacy())
{
if (ssbo)
SPIRV_CROSS_THROW("SSBOs not supported in legacy targets.");
emit_buffer_block_legacy(var);
return;
}
add_resource_name(var.self);
// Block names should never alias.
@ -1061,7 +1071,7 @@ void CompilerGLSL::emit_buffer_block(const SPIRVariable &var)
statement("");
}
void CompilerGLSL::emit_flattened_buffer_block(const SPIRVariable &var)
void CompilerGLSL::emit_buffer_block_flattened(const SPIRVariable &var)
{
auto &type = get<SPIRType>(var.basetype);
@ -1400,14 +1410,7 @@ void CompilerGLSL::emit_resources()
!is_hidden_variable(var) && (meta[type.self].decoration.decoration_flags &
((1ull << DecorationBlock) | (1ull << DecorationBufferBlock))))
{
if (flattened_buffer_blocks.count(var.self))
{
emit_flattened_buffer_block(var);
}
else
{
emit_buffer_block(var);
}
emit_buffer_block(var);
}
}
}

Просмотреть файл

@ -270,8 +270,9 @@ protected:
void emit_struct(SPIRType &type);
void emit_resources();
void emit_buffer_block(const SPIRVariable &type);
void emit_buffer_block_native(const SPIRVariable &var);
void emit_buffer_block_legacy(const SPIRVariable &var);
void emit_flattened_buffer_block(const SPIRVariable &type);
void emit_buffer_block_flattened(const SPIRVariable &type);
void emit_push_constant_block(const SPIRVariable &var);
void emit_push_constant_block_vulkan(const SPIRVariable &var);
void emit_push_constant_block_glsl(const SPIRVariable &var);