diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 92dab960d556e61692bbdc8c29188e9e228d0fbb..492c9120e8ffd57796474fe3181da533c3073cf8 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -2431,7 +2431,6 @@ spv::Id TGlslangToSpvTraverser::convertGlslangStructToSpvType(const glslang::TTy // Create a vector of struct types for SPIR-V to consume std::vector<spv::Id> spvMembers; int memberDelta = 0; // how much the member's index changes from glslang to SPIR-V, normally 0, except sometimes for blocks - int locationOffset = 0; // for use across struct members, when they are called recursively for (int i = 0; i < (int)glslangMembers->size(); i++) { glslang::TType& glslangMember = *(*glslangMembers)[i].type; if (glslangMember.hiddenMember()) { @@ -2448,11 +2447,9 @@ spv::Id TGlslangToSpvTraverser::convertGlslangStructToSpvType(const glslang::TTy glslang::TQualifier memberQualifier = glslangMember.getQualifier(); InheritQualifiers(memberQualifier, qualifier); - // manually inherit location; it's more complex + // manually inherit location if (! memberQualifier.hasLocation() && qualifier.hasLocation()) - memberQualifier.layoutLocation = qualifier.layoutLocation + locationOffset; - if (qualifier.hasLocation()) - locationOffset += glslangIntermediate->computeTypeLocationSize(glslangMember); + memberQualifier.layoutLocation = qualifier.layoutLocation; // recurse spvMembers.push_back(convertGlslangToSpvType(glslangMember, explicitLayout, memberQualifier)); @@ -2515,29 +2512,12 @@ void TGlslangToSpvTraverser::decorateStructType(const glslang::TType& type, addMemberDecoration(spvType, member, memory[i]); } - // Compute location decoration; tricky based on whether inheritance is at play and - // what kind of container we have, etc. - // TODO: This algorithm (and it's cousin above doing almost the same thing) should - // probably move to the linker stage of the front end proper, and just have the - // answer sitting already distributed throughout the individual member locations. - int location = -1; // will only decorate if present or inherited + // Location assignment was already completed correctly by the front end, + // just track whether a member needs to be decorated. // Ignore member locations if the container is an array, as that's - // ill-specified and decisions have been made to not allow this anyway. - // The object itself must have a location, and that comes out from decorating the object, - // not the type (this code decorates types). - if (! type.isArray()) { - if (memberQualifier.hasLocation()) { // no inheritance, or override of inheritance - // struct members should not have explicit locations - assert(type.getBasicType() != glslang::EbtStruct); - location = memberQualifier.layoutLocation; - } else if (type.getBasicType() != glslang::EbtBlock) { - // If it is a not a Block, (...) Its members are assigned consecutive locations (...) - // The members, and their nested types, must not themselves have Location decorations. - } else if (qualifier.hasLocation()) // inheritance - location = qualifier.layoutLocation + locationOffset; - } - if (location >= 0) - builder.addMemberDecoration(spvType, member, spv::DecorationLocation, location); + // ill-specified and decisions have been made to not allow this. + if (! type.isArray() && memberQualifier.hasLocation()) + builder.addMemberDecoration(spvType, member, spv::DecorationLocation, memberQualifier.layoutLocation); if (qualifier.hasLocation()) // track for upcoming inheritance locationOffset += glslangIntermediate->computeTypeLocationSize(glslangMember); diff --git a/Test/baseResults/spv.450.tesc.out b/Test/baseResults/spv.450.tesc.out index 18da599e9b9f90daaa6c8a50671499a6a63547a3..6b4325b953c6dfc4b603c5183b41671fdd88e9f8 100755 --- a/Test/baseResults/spv.450.tesc.out +++ b/Test/baseResults/spv.450.tesc.out @@ -36,11 +36,8 @@ spv.450.tesc Decorate 11(TheBlock) Block Decorate 16(tcBlock) Location 12 MemberDecorate 17(SingleBlock) 0 Patch - MemberDecorate 17(SingleBlock) 0 Location 2 MemberDecorate 17(SingleBlock) 1 Patch - MemberDecorate 17(SingleBlock) 1 Location 3 MemberDecorate 17(SingleBlock) 2 Patch - MemberDecorate 17(SingleBlock) 2 Location 4 Decorate 17(SingleBlock) Block Decorate 19(singleBlock) Location 2 MemberDecorate 20(bn) 0 Patch