HLSL: inter-stage structure splitting.
This adds structure splitting, which among other things will enable GS support where input structs are passed, and thus become input arrays of structs in the GS inputs. That is a common GS case. The salient points of this PR are: * Structure splitting has been changed from "always between stages" to "only into the VS and out of the PS". It had previously happened between stages because it's not legal to pass a struct containing a builtin IO variable. * Structs passed between stages are now split into a struct containing ONLY user types, and a collection of loose builtin IO variables, if any. The user-part is passed as a normal struct between stages, which is valid SPIR-V now that the builtin IO is removed. * Internal to the shader, a sanitized struct (with IO qualifiers removed) is used, so that e.g, functions can work unmodified. * If a builtin IO such as Position occurs in an arrayed struct, for example as an input to a GS, the array reference is moved to the split-off loose variable, which is given the array dimension itself. When passing things around inside the shader, such as over a function call, the the original type is used in a sanitized form that removes the builtIn qualifications and makes them temporaries. This means internal function calls do not have to change. However, the type when returned from the shader will be member-wise copied from the internal sanitized one to the external type. The sanitized type is used in variable declarations. When copying split types and unsplit, if a sub-struct contains only user variables, it is copied as a single entity to avoid more AST verbosity. Above strategy arrived at with talks with @johnkslang. This is a big complex change. I'm inclined to leave it as a WIP until it can get some exposure to real world cases.
This commit is contained in:
parent
807a0d9e2f
commit
a2e7531057
18 changed files with 1615 additions and 482 deletions
|
|
@ -185,6 +185,9 @@ protected:
|
|||
|
||||
void inheritGlobalDefaults(TQualifier& dst) const;
|
||||
TVariable* makeInternalVariable(const char* name, const TType&) const;
|
||||
TVariable* makeInternalVariable(const TString& name, const TType& type) const {
|
||||
return makeInternalVariable(name.c_str(), type);
|
||||
}
|
||||
TVariable* declareNonArray(const TSourceLoc&, TString& identifier, TType&, bool track);
|
||||
void declareArray(const TSourceLoc&, TString& identifier, const TType&, TSymbol*&, bool track);
|
||||
TIntermNode* executeInitializer(const TSourceLoc&, TIntermTyped* initializer, TVariable* variable);
|
||||
|
|
@ -197,7 +200,7 @@ protected:
|
|||
|
||||
// Array and struct flattening
|
||||
bool shouldFlatten(const TType& type) const;
|
||||
TIntermTyped* flattenAccess(const TSourceLoc&, TIntermTyped* base, int member);
|
||||
TIntermTyped* flattenAccess(TIntermTyped* base, int member);
|
||||
bool shouldFlattenIO(const TType&) const;
|
||||
bool shouldFlattenUniform(const TType&) const;
|
||||
bool wasFlattened(const TIntermTyped* node) const;
|
||||
|
|
@ -205,11 +208,29 @@ protected:
|
|||
int addFlattenedMember(const TSourceLoc& loc, const TVariable&, const TType&, TFlattenData&, const TString& name, bool track);
|
||||
bool isFinalFlattening(const TType& type) const { return !(type.isStruct() || type.isArray()); }
|
||||
|
||||
// Structure splitting (splits interstage builtin types into its own struct)
|
||||
bool shouldSplit(const TSourceLoc& loc, const TType&);
|
||||
TIntermTyped* splitAccess(const TSourceLoc& loc, TIntermTyped*& base, int& member);
|
||||
TType& split(TType& type);
|
||||
void split(TIntermTyped*);
|
||||
void split(const TVariable&);
|
||||
bool wasSplit(const TIntermTyped* node) const;
|
||||
bool wasSplit(int id) const { return splitIoVars.find(id) != splitIoVars.end(); }
|
||||
TVariable* getSplitIoVar(const TIntermTyped* node) const;
|
||||
TVariable* getSplitIoVar(const TVariable* var) const;
|
||||
TVariable* getSplitIoVar(int id) const;
|
||||
void addInterstageIoToLinkage();
|
||||
|
||||
void flatten(const TSourceLoc& loc, const TVariable& variable);
|
||||
int flatten(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
|
||||
int flattenStruct(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
|
||||
int flattenArray(const TSourceLoc& loc, const TVariable& variable, const TType&, TFlattenData&, TString name);
|
||||
|
||||
// Type sanitization: return existing sanitized (temporary) type if there is one, else make new one.
|
||||
TType* sanitizeType(TType*);
|
||||
|
||||
void finish(); // post-processing
|
||||
|
||||
// Current state of parsing
|
||||
struct TPragma contextPragma;
|
||||
int loopNestingLevel; // 0 if outside all loops
|
||||
|
|
@ -275,6 +296,14 @@ protected:
|
|||
TVector<int> flattenLevel; // nested postfix operator level for flattening
|
||||
TVector<int> flattenOffset; // cumulative offset for flattening
|
||||
|
||||
// Sanitized type map. During declarations we use the sanitized form of the type
|
||||
// if it exists.
|
||||
TMap<const TTypeList*, TType*> sanitizedTypeMap;
|
||||
|
||||
// Structure splitting data:
|
||||
TMap<TBuiltInVariable, TVariable*> interstageIo; // new structure created for interstage IO from user structs.
|
||||
TMap<int, TVariable*> splitIoVars; // individual flattened variables
|
||||
|
||||
unsigned int nextInLocation;
|
||||
unsigned int nextOutLocation;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue