HLSL: Correct use of isPerVertexBuiltIn() to be isClipOrCullDistance().

This allows removal of isPerVertexBuiltIn(). It also leads to
removal of addInterstageIoToLinkage(), which is no longer needed.

Includes related name improvements.
This commit is contained in:
John Kessenich
2017-08-04 13:51:54 -06:00
parent d319fb4e63
commit 2b4f77f2dc
28 changed files with 94 additions and 95 deletions

View File

@@ -1138,7 +1138,9 @@ TType& HlslParseContext::split(TType& type, TString name, const TType* outerStru
fixBuiltInIoType(ioVar->getWritableType());
interstageBuiltInIo[tInterstageIoData(memberType, *outerStructType)] = ioVar;
splitBuiltIns[tInterstageIoData(memberType, *outerStructType)] = ioVar;
if (!isClipOrCullDistance(ioVar->getType()))
trackLinkage(*ioVar);
// Merge qualifier from the user structure
mergeQualifiers(ioVar->getWritableType().getQualifier(), outerStructType->getQualifier());
@@ -1388,7 +1390,7 @@ void HlslParseContext::trackLinkage(TSymbol& symbol)
TBuiltInVariable biType = symbol.getType().getQualifier().builtIn;
if (biType != EbvNone)
builtInLinkageSymbols[biType] = symbol.clone();
builtInTessLinkageSymbols[biType] = symbol.clone();
TParseContextBase::trackLinkage(symbol);
}
@@ -1530,32 +1532,6 @@ void HlslParseContext::handleFunctionDeclarator(const TSourceLoc& loc, TFunction
error(loc, "function name is redeclaration of existing name", function.getName().c_str(), "");
}
// Finalization step: Add interstage IO variables to the linkage in canonical order.
void HlslParseContext::addInterstageIoToLinkage()
{
TSourceLoc loc;
loc.init();
std::vector<tInterstageIoData> io;
io.reserve(interstageBuiltInIo.size());
for (auto ioVar = interstageBuiltInIo.begin(); ioVar != interstageBuiltInIo.end(); ++ioVar)
io.push_back(ioVar->first);
// Our canonical order is the TBuiltInVariable numeric order.
std::sort(io.begin(), io.end());
// We have to (potentially) track two IO blocks, one in, one out. E.g, a GS may have a
// PerVertex block in both directions, possibly with different members.
for (int idx = 0; idx < int(io.size()); ++idx) {
TVariable* var = interstageBuiltInIo[io[idx]];
// Add the loose interstage IO to the linkage
if (! var->getType().isPerVertexBuiltIn(language))
trackLinkage(*var);
}
}
// For struct buffers with counters, we must pass the counter buffer as hidden parameter.
// This adds the hidden parameter to the parameter list in 'paramNodes' if needed.
// Otherwise, it's a no-op
@@ -1983,7 +1959,7 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
// an array element as indexed by invocation ID, which we might have to make up.
// This is required to match SPIR-V semantics.
if (language == EShLangTessControl) {
TIntermSymbol* invocationIdSym = findLinkageSymbol(EbvInvocationId);
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
// If there is no user declared invocation ID, we must make one.
if (invocationIdSym == nullptr) {
@@ -2532,7 +2508,7 @@ TIntermTyped* HlslParseContext::handleAssign(const TSourceLoc& loc, TOperator op
if (split && derefType.isBuiltIn()) {
// copy from interstage IO built-in if needed
const TIntermTyped* outer = isLeft ? outerLeft : outerRight;
subTree = intermediate.addSymbol(*interstageBuiltInIo.find(
subTree = intermediate.addSymbol(*splitBuiltIns.find(
HlslParseContext::tInterstageIoData(derefType, outer->getType()))->second);
// Arrayness of builtIn symbols isn't handled by the normal recursion:
@@ -8859,11 +8835,11 @@ void HlslParseContext::clearUniformInputOutput(TQualifier& qualifier)
}
// Return a symbol for the linkage variable of the given TBuiltInVariable type
TIntermSymbol* HlslParseContext::findLinkageSymbol(TBuiltInVariable biType) const
// Return a symbol for the tessellation linkage variable of the given TBuiltInVariable type
TIntermSymbol* HlslParseContext::findTessLinkageSymbol(TBuiltInVariable biType) const
{
const auto it = builtInLinkageSymbols.find(biType);
if (it == builtInLinkageSymbols.end()) // if it wasn't declared by the user, return nullptr
const auto it = builtInTessLinkageSymbols.find(biType);
if (it == builtInTessLinkageSymbols.end()) // if it wasn't declared by the user, return nullptr
return nullptr;
return intermediate.addSymbol(*it->second->getAsVariable());
@@ -8973,7 +8949,7 @@ void HlslParseContext::addPatchConstantInvocation()
TFunction& patchConstantFunction = const_cast<TFunction&>(*candidateList[0]);
const int pcfParamCount = patchConstantFunction.getParamCount();
TIntermSymbol* invocationIdSym = findLinkageSymbol(EbvInvocationId);
TIntermSymbol* invocationIdSym = findTessLinkageSymbol(EbvInvocationId);
TIntermSequence& epBodySeq = entryPointFunctionBody->getAsAggregate()->getSequence();
int outPatchParam = -1; // -1 means there isn't one.
@@ -9023,7 +8999,7 @@ void HlslParseContext::addPatchConstantInvocation()
// Presently, the only non-built-in we support is InputPatch, which is treated as
// a pseudo-built-in.
if (biType == EbvInputPatch) {
builtInLinkageSymbols[biType] = inputPatch;
builtInTessLinkageSymbols[biType] = inputPatch;
} else if (biType == EbvOutputPatch) {
// Nothing...
} else {
@@ -9069,7 +9045,7 @@ void HlslParseContext::addPatchConstantInvocation()
// find which built-in it is
const TBuiltInVariable biType = patchConstantFunction[p].getDeclaredBuiltIn();
inputArg = findLinkageSymbol(biType);
inputArg = findTessLinkageSymbol(biType);
if (inputArg == nullptr) {
error(loc, "unable to find patch constant function built-in variable", "", "");
@@ -9263,7 +9239,6 @@ void HlslParseContext::finish()
removeUnusedStructBufferCounters();
addPatchConstantInvocation();
addInterstageIoToLinkage();
TParseContextBase::finish();
}

View File

@@ -260,7 +260,6 @@ protected:
TVariable* getSplitIoVar(const TIntermTyped* node) const;
TVariable* getSplitIoVar(const TVariable* var) const;
TVariable* getSplitIoVar(int id) const;
void addInterstageIoToLinkage();
void addPatchConstantInvocation();
TIntermTyped* makeIntegerIndex(TIntermTyped*);
@@ -312,14 +311,14 @@ protected:
static bool isClipOrCullDistance(const TQualifier& qual) { return isClipOrCullDistance(qual.builtIn); }
static bool isClipOrCullDistance(const TType& type) { return isClipOrCullDistance(type.getQualifier()); }
// Pass through to base class after remembering builtin mappings.
// Pass through to base class after remembering built-in mappings.
using TParseContextBase::trackLinkage;
void trackLinkage(TSymbol& variable) override;
void finish() override; // post-processing
// Linkage symbol helpers
TIntermSymbol* findLinkageSymbol(TBuiltInVariable biType) const;
TIntermSymbol* findTessLinkageSymbol(TBuiltInVariable biType) const;
// Current state of parsing
int annotationNestingLevel; // 0 if outside all annotations
@@ -383,14 +382,14 @@ protected:
TMap<const TTypeList*, tIoKinds> ioTypeMap;
// Structure splitting data:
TMap<int, TVariable*> splitIoVars; // variables with the builtin interstage IO removed, indexed by unique ID.
TMap<int, TVariable*> splitIoVars; // variables with the built-in interstage IO removed, indexed by unique ID.
// Structuredbuffer shared types. Typically there are only a few.
TVector<TType*> structBufferTypes;
TMap<TString, bool> structBufferCounter;
// The builtin interstage IO map considers e.g, EvqPosition on input and output separately, so that we
// The built-in interstage IO map considers e.g, EvqPosition on input and output separately, so that we
// can build the linkage correctly if position appears on both sides. Otherwise, multiple positions
// are considered identical.
struct tInterstageIoData {
@@ -410,7 +409,7 @@ protected:
}
};
TMap<tInterstageIoData, TVariable*> interstageBuiltInIo; // individual builtin interstage IO vars, indexed by builtin type.
TMap<tInterstageIoData, TVariable*> splitBuiltIns; // split built-ins, indexed by built-in type.
TVariable* inputPatch;
unsigned int nextInLocation;
@@ -421,7 +420,7 @@ protected:
TIntermNode* entryPointFunctionBody;
TString patchConstantFunctionName; // hull shader patch constant function name, from function level attribute.
TMap<TBuiltInVariable, TSymbol*> builtInLinkageSymbols; // used for tessellation, finding declared builtins
TMap<TBuiltInVariable, TSymbol*> builtInTessLinkageSymbols; // used for tessellation, finding declared built-ins
TVector<TString> currentTypePrefix; // current scoping prefix for nested structures
TVector<TVariable*> implicitThisStack; // currently active 'this' variables for nested structures
@@ -447,7 +446,7 @@ protected:
TVector<tMipsOperatorData> mipsOperatorMipArg;
};
// This is the prefix we use for builtin methods to avoid namespace collisions with
// This is the prefix we use for built-in methods to avoid namespace collisions with
// global scope user functions.
// TODO: this would be better as a nonparseable character, but that would
// require changing the scanner.