Implement conservative depth layout qualifiers. Based partly on a submission.

git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@27758 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
John Kessenich 2014-08-18 21:27:53 +00:00
parent d6c72a44ab
commit d1888f83f6
9 changed files with 124 additions and 15 deletions

View file

@ -305,6 +305,16 @@ enum TLayoutFormat {
ElfCount
};
enum TLayoutDepth {
EldNone,
EldAny,
EldGreater,
EldLess,
EldUnchanged,
EldCount
};
class TQualifier {
public:
void clear()
@ -645,6 +655,16 @@ public:
default: return "none";
}
}
static const char* getLayoutDepthString(TLayoutDepth d)
{
switch (d) {
case EldAny: return "depth_any";
case EldGreater: return "depth_greater";
case EldLess: return "depth_less";
case EldUnchanged: return "depth_unchanged";
default: return "none";
}
}
static const char* getGeometryString(TLayoutGeometry geometry)
{
switch (geometry) {
@ -703,6 +723,7 @@ struct TShaderQualifiers {
bool pointMode;
int localSize[3]; // compute shader
bool earlyFragmentTests; // fragment input
TLayoutDepth layoutDepth;
void init()
{
@ -718,6 +739,7 @@ struct TShaderQualifiers {
localSize[1] = 1;
localSize[2] = 1;
earlyFragmentTests = false;
layoutDepth = EldNone;
}
// Merge in characteristics from the 'src' qualifier. They can override when
@ -746,6 +768,8 @@ struct TShaderQualifiers {
}
if (src.earlyFragmentTests)
earlyFragmentTests = true;
if (src.layoutDepth)
layoutDepth = src.layoutDepth;
}
};
@ -1160,10 +1184,8 @@ public:
p += snprintf(p, end - p, "offset=%d ", qualifier.layoutOffset);
if (qualifier.hasAlign())
p += snprintf(p, end - p, "align=%d ", qualifier.layoutAlign);
if (qualifier.hasFormat())
p += snprintf(p, end - p, "%s ", TQualifier::getLayoutFormatString(qualifier.layoutFormat));
if (qualifier.hasXfbBuffer() && qualifier.hasXfbOffset())
p += snprintf(p, end - p, "xfb_buffer=%d ", qualifier.layoutXfbBuffer);
if (qualifier.hasXfbOffset())

View file

@ -2565,8 +2565,14 @@ TSymbol* TParseContext::redeclareBuiltinVariable(TSourceLoc loc, const TString&
error(loc, "can only change layout qualification of", "redeclaration", symbol->getName().c_str());
if (qualifier.storage != EvqVaryingOut)
error(loc, "cannot change output storage qualification of", "redeclaration", symbol->getName().c_str());
// TODO 4.2: gl_FragDepth redeclaration
}
if (publicType.layoutDepth != EldNone) {
if (intermediate.inIoAccessed("gl_FragDepth"))
error(loc, "cannot redeclare after use", "gl_FragDepth", "");
if (! intermediate.setDepth(publicType.layoutDepth))
error(loc, "all redeclarations must use the same depth layout on", "redeclaration", symbol->getName().c_str());
}
}
// TODO: semantics quality: separate smooth from nothing declared, then use IsInterpolation for several tests above
return symbol;
@ -2965,8 +2971,8 @@ void TParseContext::finalErrorCheck()
// Layout qualifier stuff.
//
// Put the id's layout qualification into the public type. This is before we know any
// type information for error checking.
// Put the id's layout qualification into the public type, for qualifiers not having a number set.
// This is before we know any type information for error checking.
void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType, TString& id)
{
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
@ -3105,12 +3111,20 @@ void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType,
publicType.shaderQualifiers.earlyFragmentTests = true;
return;
}
for (TLayoutDepth depth = (TLayoutDepth)(EldNone + 1); depth < EldCount; depth = (TLayoutDepth)(depth+1)) {
if (id == TQualifier::getLayoutDepthString(depth)) {
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "depth layout qualifier");
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, 0, "depth layout qualifier");
publicType.shaderQualifiers.layoutDepth = depth;
return;
}
}
}
error(loc, "unrecognized layout identifier, or qualifier requires assignment (e.g., binding = 4)", id.c_str(), "");
}
// Put the id's layout qualifier value into the public type. This is before we know any
// type information for error checking.
// Put the id's layout qualifier value into the public type, for qualifiers having a number set.
// This is before we know any type information for error checking.
void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType, TString& id, const TIntermTyped* node)
{
const char* feature = "layout-id value";
@ -3742,6 +3756,8 @@ TIntermNode* TParseContext::declareVariable(TSourceLoc loc, TString& identifier,
if (identifier != "gl_FragCoord" && (publicType.shaderQualifiers.originUpperLeft || publicType.shaderQualifiers.pixelCenterInteger))
error(loc, "can only apply origin_upper_left and pixel_center_origin to gl_FragCoord", "layout qualifier", "");
if (identifier != "gl_FragDepth" && publicType.shaderQualifiers.layoutDepth != EldNone)
error(loc, "can only apply depth layout to gl_FragDepth", "layout qualifier", "");
// Check for redeclaration of built-ins and/or attempting to declare a reserved name
bool newDeclaration = false; // true if a new entry gets added to the symbol table

View file

@ -621,6 +621,8 @@ void TIntermediate::output(TInfoSink& infoSink, bool tree)
infoSink.debug << "gl_FragCoord origin is upper left\n";
if (earlyFragmentTests)
infoSink.debug << "using early_fragment_tests\n";
if (depthLayout != EldNone)
infoSink.debug << "using " << TQualifier::getLayoutDepthString(depthLayout) << "\n";
break;
case EShLangCompute:

View file

@ -83,6 +83,11 @@ void TIntermediate::merge(TInfoSink& infoSink, TIntermediate& unit)
if (! earlyFragmentTests)
earlyFragmentTests = unit.earlyFragmentTests;
if (depthLayout == EldNone)
depthLayout = unit.depthLayout;
else if (depthLayout != unit.depthLayout)
error(infoSink, "Contradictory depth layouts");
if (inputPrimitive == ElgNone)
inputPrimitive = unit.inputPrimitive;
else if (inputPrimitive != unit.inputPrimitive)

View file

@ -112,7 +112,7 @@ public:
explicit TIntermediate(EShLanguage l, int v = 0, EProfile p = ENoProfile) : language(l), treeRoot(0), profile(p), version(v),
numMains(0), numErrors(0), recursive(false),
invocations(0), vertices(0), inputPrimitive(ElgNone), outputPrimitive(ElgNone), pixelCenterInteger(false), originUpperLeft(false),
vertexSpacing(EvsNone), vertexOrder(EvoNone), pointMode(false), earlyFragmentTests(false), xfbMode(false)
vertexSpacing(EvsNone), vertexOrder(EvoNone), pointMode(false), earlyFragmentTests(false), depthLayout(EldNone), xfbMode(false)
{
localSize[0] = 1;
localSize[1] = 1;
@ -250,6 +250,14 @@ public:
bool getPixelCenterInteger() const { return pixelCenterInteger; }
void setEarlyFragmentTests() { earlyFragmentTests = true; }
bool getEarlyFragmentTests() const { return earlyFragmentTests; }
bool setDepth(TLayoutDepth d)
{
if (depthLayout != EldNone)
return depthLayout == d;
depthLayout = d;
return true;
}
TLayoutDepth getDepth() const { return depthLayout; }
void addToCallGraph(TInfoSink&, const TString& caller, const TString& callee);
void merge(TInfoSink&, TIntermediate&);
@ -304,6 +312,7 @@ protected:
bool pointMode;
int localSize[3];
bool earlyFragmentTests;
TLayoutDepth depthLayout;
bool xfbMode;
typedef std::list<TCall> TGraph;