Commit 65ee230f by John Kessenich

HLSL: Add tests and refine what decorations are passed through per stage/in/out.

parent bf47286f
......@@ -2248,8 +2248,10 @@ void TGlslangToSpvTraverser::decorateStructType(const glslang::TType& type,
addMemberDecoration(spvType, member, TranslateLayoutDecoration(glslangMember, memberQualifier.layoutMatrix));
addMemberDecoration(spvType, member, TranslatePrecisionDecoration(glslangMember));
// Add interpolation and auxiliary storage decorations only to top-level members of Input and Output storage classes
if (type.getQualifier().storage == glslang::EvqVaryingIn || type.getQualifier().storage == glslang::EvqVaryingOut) {
if (type.getBasicType() == glslang::EbtBlock) {
if (type.getQualifier().storage == glslang::EvqVaryingIn ||
type.getQualifier().storage == glslang::EvqVaryingOut) {
if (type.getBasicType() == glslang::EbtBlock ||
glslangIntermediate->getSource() == glslang::EShSourceHlsl) {
addMemberDecoration(spvType, member, TranslateInterpolationDecoration(memberQualifier));
addMemberDecoration(spvType, member, TranslateAuxiliaryStorageDecoration(memberQualifier));
}
......
......@@ -284,6 +284,10 @@ gl_FragCoord origin is upper left
MemberName 94($Global) 2 "ff6"
Name 96 ""
Decorate 43(input) Location 0
MemberDecorate 46(IN_S) 1 Flat
MemberDecorate 46(IN_S) 2 NoPerspective
MemberDecorate 46(IN_S) 2 Centroid
MemberDecorate 46(IN_S) 3 Centroid
Decorate 48(s) Location 1
Decorate 71(s_ff1) BuiltIn FrontFacing
Decorate 86(@entryPointOutput) Location 0
......
......@@ -92,7 +92,7 @@ Shader version: 450
0:? 'e' (temp 4-component vector of float)
0:8 move second child to first child (temp 2-element array of 4-component vector of float)
0:8 m: direct index for structure (temp 2-element array of 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 0 (const int)
0:8 m: direct index for structure (temp 2-element array of 4-component vector of float)
......@@ -101,7 +101,7 @@ Shader version: 450
0:8 0 (const int)
0:8 move second child to first child (temp 2-component vector of uint)
0:8 coord: direct index for structure (temp 2-component vector of uint)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 1 (const int)
0:8 coord: direct index for structure (temp 2-component vector of uint)
......@@ -109,8 +109,8 @@ Shader version: 450
0:8 Constant:
0:8 1 (const int)
0:8 move second child to first child (temp 4-component vector of float)
0:8 b: direct index for structure (smooth temp 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 b: direct index for structure (temp 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 2 (const int)
0:8 b: direct index for structure (temp 4-component vector of float)
......@@ -118,7 +118,7 @@ Shader version: 450
0:8 Constant:
0:8 2 (const int)
0:? Linker Objects
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:? 'd' (layout(location=0 ) in 4-component vector of float)
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
......@@ -225,7 +225,7 @@ Shader version: 450
0:? 'e' (temp 4-component vector of float)
0:8 move second child to first child (temp 2-element array of 4-component vector of float)
0:8 m: direct index for structure (temp 2-element array of 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 0 (const int)
0:8 m: direct index for structure (temp 2-element array of 4-component vector of float)
......@@ -234,7 +234,7 @@ Shader version: 450
0:8 0 (const int)
0:8 move second child to first child (temp 2-component vector of uint)
0:8 coord: direct index for structure (temp 2-component vector of uint)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 1 (const int)
0:8 coord: direct index for structure (temp 2-component vector of uint)
......@@ -242,8 +242,8 @@ Shader version: 450
0:8 Constant:
0:8 1 (const int)
0:8 move second child to first child (temp 4-component vector of float)
0:8 b: direct index for structure (smooth temp 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:8 b: direct index for structure (temp 4-component vector of float)
0:8 '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:8 Constant:
0:8 2 (const int)
0:8 b: direct index for structure (temp 4-component vector of float)
......@@ -251,7 +251,7 @@ Shader version: 450
0:8 Constant:
0:8 2 (const int)
0:? Linker Objects
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, smooth temp 4-component vector of float b})
0:? '@entryPointOutput' (out structure Position{temp 2-element array of 4-component vector of float m, temp 2-component vector of uint coord, temp 4-component vector of float b})
0:? 'd' (layout(location=0 ) in 4-component vector of float)
0:? 'm[0]' (layout(location=1 ) in 4-component vector of float)
0:? 'm[1]' (layout(location=2 ) in 4-component vector of float)
......
struct T {
float f : packoffset(c4.y); // artificial, but validates all different treatments: uniform offset
centroid float g; // interpolant input
float d: SV_DepthGreaterEqual; // fragment output
float4 normal; // non-IO
};
T s; // loose uniform
cbuffer buff {
T t : packoffset(c5.z);
};
T main(T t : myInput) : SV_Target0
{
T local;
return local;
}
......@@ -411,6 +411,13 @@ public:
void clearInterstage()
{
clearInterpolation();
patch = false;
sample = false;
}
void clearInterpolation()
{
centroid = false;
smooth = false;
flat = false;
......@@ -418,8 +425,6 @@ public:
#ifdef AMD_EXTENSIONS
explicitInterp = false;
#endif
patch = false;
sample = false;
}
void clearMemory()
......
......@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1791"
#define GLSLANG_DATE "05-Feb-2017"
#define GLSLANG_REVISION "Overload400-PrecQual.1792"
#define GLSLANG_DATE "06-Feb-2017"
......@@ -530,7 +530,7 @@ void TParseContextBase::parseSwizzleSelector(const TSourceLoc& loc, const TStrin
// Make the passed-in variable information become a member of the
// global uniform block. If this doesn't exist yet, make it.
//
void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName)
void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName, TTypeList* typeList)
{
// make the global block, if not yet made
if (globalUniformBlock == nullptr) {
......@@ -548,6 +548,8 @@ void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberTyp
TType* type = new TType;
type->shallowCopy(memberType);
type->setFieldName(memberName);
if (typeList)
type->setStruct(typeList);
TTypeLoc typeLoc = {type, loc};
globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc);
}
......
......@@ -139,7 +139,7 @@ public:
// TODO: This could perhaps get its own object, but the current design doesn't work
// yet when new uniform variables are declared between function definitions, so
// this is pending getting a fully functional design.
virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName);
virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName, TTypeList* typeList = nullptr);
virtual bool insertGlobalUniformBlock();
virtual bool lValueErrorCheck(const TSourceLoc&, const char* op, TIntermTyped*);
......
......@@ -219,6 +219,7 @@ INSTANTIATE_TEST_CASE_P(
{"hlsl.structarray.flatten.frag", "main"},
{"hlsl.structarray.flatten.geom", "main"},
{"hlsl.structin.vert", "main"},
{"hlsl.structIoFourWay.frag", "main"},
{"hlsl.intrinsics.vert", "VertexShaderFunction"},
{"hlsl.matType.frag", "PixelShaderFunction"},
{"hlsl.matType.bool.frag", "main"},
......
......@@ -159,10 +159,16 @@ bool HlslParseContext::shouldConvertLValue(const TIntermNode* node) const
return false;
}
void HlslParseContext::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName)
void HlslParseContext::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName, TTypeList* newTypeList)
{
newTypeList = nullptr;
correctUniform(memberType.getQualifier());
TParseContextBase::growGlobalUniformBlock(loc, memberType, memberName);
if (memberType.isStruct()) {
auto it = ioTypeMap.find(memberType.getStruct());
if (it != ioTypeMap.end() && it->second.uniform)
newTypeList = it->second.uniform;
}
TParseContextBase::growGlobalUniformBlock(loc, memberType, memberName, newTypeList);
}
//
......@@ -5381,8 +5387,12 @@ void HlslParseContext::declareStruct(const TSourceLoc& loc, TString& structName,
}
if (newLists.uniform == nullptr &&
newLists.input == nullptr &&
newLists.output == nullptr)
newLists.output == nullptr) {
// Won't do any IO caching, clear up the type and get out now.
for (auto member = type.getStruct()->begin(); member != type.getStruct()->end(); ++member)
clearUniformInputOutput(member->type->getQualifier());
return;
}
// We have IO involved.
......@@ -5471,6 +5481,11 @@ TIntermNode* HlslParseContext::declareVariable(const TSourceLoc& loc, TString& i
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
if (type.isStruct()) {
auto it = ioTypeMap.find(type.getStruct());
if (it != ioTypeMap.end())
type.setStruct(it->second.uniform);
}
break;
default:
break;
......@@ -6011,6 +6026,22 @@ void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TS
{
assert(type.getWritableStruct() != nullptr);
// Clean up top-level decorations that don't belong.
switch (type.getQualifier().storage) {
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
break;
case EvqVaryingIn:
correctInput(type.getQualifier());
break;
case EvqVaryingOut:
correctOutput(type.getQualifier());
break;
default:
break;
}
TTypeList& typeList = *type.getWritableStruct();
// fix and check for member storage qualifiers and types that don't belong within a block
for (unsigned int member = 0; member < typeList.size(); ++member) {
......@@ -6019,6 +6050,31 @@ void HlslParseContext::declareBlock(const TSourceLoc& loc, TType& type, const TS
const TSourceLoc& memberLoc = typeList[member].loc;
globalQualifierFix(memberLoc, memberQualifier);
memberQualifier.storage = type.getQualifier().storage;
if (memberType.isStruct()) {
// clean up and pick up the right set of decorations
auto it = ioTypeMap.find(memberType.getStruct());
switch (type.getQualifier().storage) {
case EvqUniform:
case EvqBuffer:
correctUniform(type.getQualifier());
if (it != ioTypeMap.end() && it->second.uniform)
type.setStruct(it->second.uniform);
break;
case EvqVaryingIn:
correctInput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.input)
type.setStruct(it->second.input);
break;
case EvqVaryingOut:
correctOutput(type.getQualifier());
if (it != ioTypeMap.end() && it->second.output)
type.setStruct(it->second.output);
break;
default:
break;
}
}
}
// This might be a redeclaration of a built-in block. If so, redeclareBuiltinBlock() will
......@@ -6602,15 +6658,16 @@ bool HlslParseContext::isInputBuiltIn(const TQualifier& qualifier) const
}
}
// Return true if there are decorations to preserve for input-like storage,
// except for builtIn.
// Return true if there are decorations to preserve for input-like storage.
bool HlslParseContext::hasInput(const TQualifier& qualifier) const
{
if (qualifier.hasAnyLocation())
return true;
if (language != EShLangVertex && language != EShLangCompute &&
(qualifier.isInterpolation() || qualifier.isAuxiliary()))
if (language == EShLangFragment && (qualifier.isInterpolation() || qualifier.centroid || qualifier.sample))
return true;
if (language == EShLangTessEvaluation && qualifier.patch)
return true;
if (isInputBuiltIn(qualifier))
......@@ -6630,6 +6687,8 @@ bool HlslParseContext::isOutputBuiltIn(const TQualifier& qualifier) const
case EbvCullDistance:
return language != EShLangFragment && language != EShLangCompute;
case EbvFragDepth:
case EbvFragDepthGreater:
case EbvFragDepthLesser:
case EbvSampleMask:
return language == EShLangFragment;
case EbvLayer:
......@@ -6645,15 +6704,16 @@ bool HlslParseContext::isOutputBuiltIn(const TQualifier& qualifier) const
}
}
// Return true if there are decorations to preserve for output-like storage,
// except for builtIn.
// Return true if there are decorations to preserve for output-like storage.
bool HlslParseContext::hasOutput(const TQualifier& qualifier) const
{
if (qualifier.hasAnyLocation())
return true;
if (language != EShLangFragment && language != EShLangCompute &&
(qualifier.hasXfb() || qualifier.isInterpolation() || qualifier.isAuxiliary()))
if (language != EShLangFragment && language != EShLangCompute && qualifier.hasXfb())
return true;
if (language == EShLangTessControl && qualifier.patch)
return true;
if (language == EShLangGeometry && qualifier.hasStream())
......@@ -6671,6 +6731,13 @@ void HlslParseContext::correctInput(TQualifier& qualifier)
clearUniform(qualifier);
if (language == EShLangVertex)
qualifier.clearInterstage();
if (language != EShLangTessEvaluation)
qualifier.patch = false;
if (language != EShLangFragment) {
qualifier.clearInterpolation();
qualifier.sample = false;
}
qualifier.clearStreamLayout();
qualifier.clearXfbLayout();
......@@ -6688,6 +6755,8 @@ void HlslParseContext::correctOutput(TQualifier& qualifier)
qualifier.clearStreamLayout();
if (language == EShLangFragment)
qualifier.clearXfbLayout();
if (language != EShLangTessControl)
qualifier.patch = false;
switch (qualifier.builtIn) {
case EbvFragDepthGreater:
......
......@@ -161,7 +161,7 @@ public:
void pushSwitchSequence(TIntermSequence* sequence) { switchSequenceStack.push_back(sequence); }
void popSwitchSequence() { switchSequenceStack.pop_back(); }
virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName) override;
virtual void growGlobalUniformBlock(TSourceLoc&, TType&, TString& memberName, TTypeList* typeList = nullptr) override;
// Apply L-value conversions. E.g, turning a write to a RWTexture into an ImageStore.
TIntermTyped* handleLvalue(const TSourceLoc&, const char* op, TIntermTyped* node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment