From 214a1fced7c53b81c00bec67fa2b91a357d5ece4 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Fri, 9 Feb 2018 21:27:26 -0800 Subject: Handling of duplicate global shader parameter declarations (#405) * Issue error when shader parameter type doesn't match between translation units We currently allow users to compile different translation units at the same time for the vertex and fragment shader, and those different translation units might contain distinct declarations for the "same" parameter. Furthermore, those declarations might use distinct declaratins of the "same" type. We currently bind those as if they were one parameter, which means we assume they have types that are actually equivalent. Unfortunately, things break when that isn't the case. This change adds error messages when parameter declarations that are determined to be the "same" don't have types that are either equiavlent or match "structurally" (same names, same fields, and field types match recursively). Ideally most users won't see these errors, because they will only submit single files to the compiler. Eventually we may actually decide to require that case and simplify our logic. * Support types with layout coming from a "matching" type Because of how the front-end performs parameter binding, we can end up in cases where a variable is given a `TypeLayout` based on a "matching" type from another translation unit (because the "same" shader parmaeter got declared in multiple TUs). This change tries to support that use case by avoiding absolute field decl-refs in the representation used for type legalization, so that we don't end up in a situation where we look up field layout based on information that doesn't match. --- source/slang/legalize-types.cpp | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'source/slang/legalize-types.cpp') diff --git a/source/slang/legalize-types.cpp b/source/slang/legalize-types.cpp index d0cf2ab69..c90b12558 100644 --- a/source/slang/legalize-types.cpp +++ b/source/slang/legalize-types.cpp @@ -232,10 +232,11 @@ struct TupleTypeBuilder break; } + String mangledFieldName = getMangledName(fieldDeclRef.getDecl()); PairInfo::Element pairElement; pairElement.flags = 0; - pairElement.fieldDeclRef = fieldDeclRef; + pairElement.mangledName = mangledFieldName; pairElement.fieldPairInfo = elementPairInfo; // We will always add a field to the "ordinary" @@ -272,7 +273,7 @@ struct TupleTypeBuilder pairElement.flags |= PairInfo::kFlag_hasSpecial; TuplePseudoType::Element specialElement; - specialElement.fieldDeclRef = fieldDeclRef; + specialElement.mangledName = mangledFieldName; specialElement.type = specialType; specialElements.Add(specialElement); } @@ -557,7 +558,7 @@ static LegalType createLegalUniformBufferType( { TuplePseudoType::Element newElement; - newElement.fieldDeclRef = ee.fieldDeclRef; + newElement.mangledName = ee.mangledName; newElement.type = LegalType::implicitDeref(ee.type); bufferPseudoTupleType->elements.Add(newElement); @@ -657,7 +658,7 @@ static LegalType createLegalPtrType( { TuplePseudoType::Element newElement; - newElement.fieldDeclRef = ee.fieldDeclRef; + newElement.mangledName = ee.mangledName; newElement.type = createLegalPtrType( context, typeDeclRef, @@ -772,7 +773,7 @@ static LegalType wrapLegalType( { TuplePseudoType::Element element; - element.fieldDeclRef = ee.fieldDeclRef; + element.mangledName = ee.mangledName; element.type = wrapLegalType( context, ee.type, @@ -988,8 +989,8 @@ RefPtr getDerefTypeLayout( } RefPtr getFieldLayout( - TypeLayout* typeLayout, - DeclRef fieldDeclRef) + TypeLayout* typeLayout, + String const& mangledFieldName) { if (!typeLayout) return nullptr; @@ -1013,9 +1014,13 @@ RefPtr getFieldLayout( if (auto structTypeLayout = dynamic_cast(typeLayout)) { - RefPtr fieldLayout; - if (structTypeLayout->mapVarToLayout.TryGetValue(fieldDeclRef.getDecl(), fieldLayout)) - return fieldLayout; + for(auto ff : structTypeLayout->fields) + { + if(mangledFieldName == getMangledName(ff->varDecl) ) + { + return ff; + } + } } return nullptr; -- cgit v1.2.3