diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-02-09 21:27:26 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-09 21:27:26 -0800 |
| commit | 214a1fced7c53b81c00bec67fa2b91a357d5ece4 (patch) | |
| tree | 05f0e2cab9478a62022e7aad54b9ddfc9bd58b0c /source/slang/ir-legalize-types.cpp | |
| parent | c7c97ad4bb62b83efd6e26cdd4f38ebf164ec40e (diff) | |
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.
Diffstat (limited to 'source/slang/ir-legalize-types.cpp')
| -rw-r--r-- | source/slang/ir-legalize-types.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/source/slang/ir-legalize-types.cpp b/source/slang/ir-legalize-types.cpp index 9234af8f5..4e3bafd31 100644 --- a/source/slang/ir-legalize-types.cpp +++ b/source/slang/ir-legalize-types.cpp @@ -13,6 +13,7 @@ #include "ir.h" #include "ir-insts.h" #include "legalize-types.h" +#include "mangle.h" namespace Slang { @@ -277,7 +278,7 @@ static LegalVal legalizeLoad( for (auto ee : legalPtrVal.getTuple()->elements) { TuplePseudoVal::Element element; - element.fieldDeclRef = ee.fieldDeclRef; + element.mangledName = ee.mangledName; element.val = legalizeLoad(context, ee.val); tupleVal->elements.Add(element); @@ -366,11 +367,13 @@ static LegalVal legalizeFieldAddress( case LegalVal::Flavor::pair: { + String mangledFieldName = getMangledName(fieldDeclRef.getDecl()); + // There are two sides, the ordinary and the special, // and we basically just dispatch to both of them. auto pairVal = legalPtrOperand.getPair(); auto pairInfo = pairVal->pairInfo; - auto pairElement = pairInfo->findElement(fieldDeclRef); + auto pairElement = pairInfo->findElement(mangledFieldName); if (!pairElement) { SLANG_UNEXPECTED("didn't find tuple element"); @@ -424,6 +427,8 @@ static LegalVal legalizeFieldAddress( case LegalVal::Flavor::tuple: { + String mangledFieldName = getMangledName(fieldDeclRef.getDecl()); + // The operand is a tuple of pointer-like // values, we want to extract the element // corresponding to a field. We will handle @@ -432,7 +437,7 @@ static LegalVal legalizeFieldAddress( auto ptrTupleInfo = legalPtrOperand.getTuple(); for (auto ee : ptrTupleInfo->elements) { - if (ee.fieldDeclRef.Equals(fieldDeclRef)) + if (ee.mangledName == mangledFieldName) { return ee.val; } @@ -542,7 +547,7 @@ static LegalVal legalizeGetElementPtr( auto elemType = tupleType->elements[ee].type; TuplePseudoVal::Element resElem; - resElem.fieldDeclRef = ptrElem.fieldDeclRef; + resElem.mangledName = ptrElem.mangledName; resElem.val = legalizeGetElementPtr( context, elemType, @@ -1001,7 +1006,7 @@ static LegalVal declareVars( for (auto ee : tupleType->elements) { - auto fieldLayout = getFieldLayout(typeLayout, ee.fieldDeclRef); + auto fieldLayout = getFieldLayout(typeLayout, ee.mangledName); RefPtr<TypeLayout> fieldTypeLayout = fieldLayout ? fieldLayout->typeLayout : nullptr; // If we are processing layout information, then @@ -1026,7 +1031,7 @@ static LegalVal declareVars( globalNameInfo); TuplePseudoVal::Element element; - element.fieldDeclRef = ee.fieldDeclRef; + element.mangledName = ee.mangledName; element.val = fieldVal; tupleVal->elements.Add(element); } |
