From eb580d665620f90a44fb38527ebdb93fb1c63cb5 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 29 Jul 2020 13:02:25 +0200 Subject: [PATCH] Ensure that we use primary alias type when emitting flattened members. --- spirv_glsl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 7d2929c7..b37d79ac 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -2142,6 +2142,10 @@ void CompilerGLSL::emit_flattened_io_block_member(const std::string &basename, c assert(member_type->basetype != SPIRType::Struct); + // We're overriding struct member names, so ensure we do so on the primary type. + if (parent_type->type_alias) + parent_type = &get(parent_type->type_alias); + // Sanitize underscores because joining the two identifiers might create more than 1 underscore in a row, // which is not allowed. flattened_name = sanitize_underscores(flattened_name); @@ -2185,10 +2189,14 @@ void CompilerGLSL::emit_flattened_io_block_struct(const std::string &basename, c void CompilerGLSL::emit_flattened_io_block(const SPIRVariable &var, const char *qual) { - auto &type = get(var.basetype); - if (!type.array.empty()) + auto &var_type = get(var.basetype); + if (!var_type.array.empty()) SPIRV_CROSS_THROW("Array of varying structs cannot be flattened to legacy-compatible varyings."); + // Emit flattened types based on the type alias. Normally, we are never supposed to emit + // struct declarations for aliased types. + auto &type = var_type.type_alias ? get(var_type.type_alias) : var_type; + auto old_flags = ir.meta[type.self].decoration.decoration_flags; // Emit the members as if they are part of a block to get all qualifiers. ir.meta[type.self].decoration.decoration_flags.set(DecorationBlock);