Commit 38fee6f1 by bajones@chromium.org

Merged EXT_frag_depth changes into dx11proto branch

BUG=429 Review URL: https://codereview.appspot.com/9738048 git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@2419 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 2b02f861
......@@ -218,6 +218,7 @@ typedef struct
int OES_EGL_image_external;
int ARB_texture_rectangle;
int EXT_draw_buffers;
int EXT_frag_depth;
// Set to 1 if highp precision is supported in the fragment language.
// Default is 0.
......
......@@ -108,6 +108,7 @@ enum TQualifier
// built-ins written by fragment shader
EvqFragColor,
EvqFragData,
EvqFragDepth,
// end of list
EvqLast
......@@ -139,6 +140,7 @@ inline const char* getQualifierString(TQualifier q)
case EvqFrontFacing: return "FrontFacing"; break;
case EvqFragColor: return "FragColor"; break;
case EvqFragData: return "FragData"; break;
case EvqFragDepth: return "FragDepth"; break;
default: return "unknown qualifier";
}
}
......
......@@ -546,6 +546,10 @@ void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
if (spec != SH_CSS_SHADERS_SPEC) {
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragColor"), TType(EbtFloat, EbpMedium, EvqFragColor, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData[gl_MaxDrawBuffers]"), TType(EbtFloat, EbpMedium, EvqFragData, 4)));
if (resources.EXT_frag_depth) {
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragDepthEXT"), TType(EbtFloat, resources.FragmentPrecisionHigh ? EbpHigh : EbpMedium, EvqFragDepth, 1)));
symbolTable.relateToExtension("gl_FragDepthEXT", "GL_EXT_frag_depth");
}
} else {
symbolTable.insert(*new TVariable(NewPoolTString("css_MixColor"), TType(EbtFloat, EbpMedium, EvqGlobal, 4)));
symbolTable.insert(*new TVariable(NewPoolTString("css_ColorMatrix"), TType(EbtFloat, EbpMedium, EvqGlobal, 4, true)));
......@@ -663,4 +667,6 @@ void InitExtensionBehavior(const ShBuiltInResources& resources,
extBehavior["GL_ARB_texture_rectangle"] = EBhUndefined;
if (resources.EXT_draw_buffers)
extBehavior["GL_EXT_draw_buffers"] = EBhUndefined;
if (resources.EXT_frag_depth)
extBehavior["GL_EXT_frag_depth"] = EBhUndefined;
}
......@@ -19,3 +19,17 @@ bool TOutputGLSL::writeVariablePrecision(TPrecision)
{
return false;
}
void TOutputGLSL::visitSymbol(TIntermSymbol* node)
{
TInfoSinkBase& out = objSink();
if (node->getSymbol() == "gl_FragDepthEXT")
{
out << "gl_FragDepth";
}
else
{
TOutputGLSLBase::visitSymbol(node);
}
}
......@@ -20,6 +20,7 @@ public:
protected:
virtual bool writeVariablePrecision(TPrecision);
virtual void visitSymbol(TIntermSymbol* node);
};
#endif // CROSSCOMPILERGLSL_OUTPUTGLSL_H_
......@@ -55,6 +55,7 @@ OutputHLSL::OutputHLSL(TParseContext &context, const ShBuiltInResources& resourc
mUsesPointCoord = false;
mUsesFrontFacing = false;
mUsesPointSize = false;
mUsesFragDepth = false;
mUsesXor = false;
mUsesMod1 = false;
mUsesMod2v = false;
......@@ -230,6 +231,11 @@ void OutputHLSL::header()
}
out << "};\n";
if (mUsesFragDepth)
{
out << "static float gl_Depth = 0.0;\n";
}
if (mUsesFragCoord)
{
out << "static float4 gl_FragCoord = float4(0, 0, 0, 0);\n";
......@@ -844,6 +850,11 @@ void OutputHLSL::header()
out << "#define GL_USES_POINT_SIZE\n";
}
if (mUsesFragDepth)
{
out << "#define GL_USES_FRAG_DEPTH\n";
}
if (mUsesDepthRange)
{
out << "#define GL_USES_DEPTH_RANGE\n";
......@@ -1171,6 +1182,11 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
mUsesPointSize = true;
out << name;
}
else if (name == "gl_FragDepthEXT")
{
mUsesFragDepth = true;
out << "gl_Depth";
}
else
{
TQualifier qualifier = node->getQualifier();
......
......@@ -108,6 +108,7 @@ class OutputHLSL : public TIntermTraverser
bool mUsesPointCoord;
bool mUsesFrontFacing;
bool mUsesPointSize;
bool mUsesFragDepth;
bool mUsesXor;
bool mUsesMod1;
bool mUsesMod2v;
......
......@@ -925,6 +925,27 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
return static_cast<const TFunction*>(symbol);
}
bool TParseContext::isVariableBuiltIn(const TVariable* var)
{
bool builtIn = false;
// First find by unmangled name to check whether the function name has been
// hidden by a variable name or struct typename.
const TSymbol* symbol = symbolTable.find(var->getName(), &builtIn);
if (symbol == 0) {
symbol = symbolTable.find(var->getMangledName(), &builtIn);
}
if (symbol == 0) {
return false;
}
if (!symbol->isVariable()) {
return false;
}
return builtIn;
}
//
// Initializers show up in several places in the grammar. Have one set of
// code to handle them here.
......
......@@ -105,6 +105,7 @@ struct TParseContext {
bool containsSampler(TType& type);
bool areAllChildConst(TIntermAggregate* aggrNode);
const TFunction* findFunction(const TSourceLoc& line, TFunction* pfnCall, bool *builtIn = 0);
bool isVariableBuiltIn(const TVariable* pVar);
bool executeInitializer(const TSourceLoc& line, TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable = 0);
......
......@@ -127,6 +127,7 @@ void ShInitBuiltInResources(ShBuiltInResources* resources)
resources->OES_EGL_image_external = 0;
resources->ARB_texture_rectangle = 0;
resources->EXT_draw_buffers = 0;
resources->EXT_frag_depth = 0;
// Disable highp precision in fragment shader by default.
resources->FragmentPrecisionHigh = 0;
......
......@@ -223,10 +223,8 @@ void TSymbolTableLevel::relateToOperator(const char* name, TOperator op)
void TSymbolTableLevel::relateToExtension(const char* name, const TString& ext)
{
for (tLevel::iterator it = level.begin(); it != level.end(); ++it) {
if (it->second->isFunction()) {
TFunction* function = static_cast<TFunction*>(it->second);
if (function->getName() == name)
function->relateToExtension(ext);
}
TSymbol* symbol = it->second;
if (symbol->getName() == name)
symbol->relateToExtension(ext);
}
}
......@@ -50,13 +50,16 @@ public:
virtual bool isVariable() const { return false; }
void setUniqueId(int id) { uniqueId = id; }
int getUniqueId() const { return uniqueId; }
virtual void dump(TInfoSink &infoSink) const = 0;
virtual void dump(TInfoSink &infoSink) const = 0;
void relateToExtension(const TString& ext) { extension = ext; }
const TString& getExtension() const { return extension; }
private:
DISALLOW_COPY_AND_ASSIGN(TSymbol);
const TString *name;
unsigned int uniqueId; // For real comparing during code generation
TString extension;
};
//
......@@ -156,9 +159,6 @@ public:
void relateToOperator(TOperator o) { op = o; }
TOperator getBuiltInOp() const { return op; }
void relateToExtension(const TString& ext) { extension = ext; }
const TString& getExtension() const { return extension; }
void setDefined() { defined = true; }
bool isDefined() { return defined; }
......@@ -175,7 +175,6 @@ private:
TType returnType;
TString mangledName;
TOperator op;
TString extension;
bool defined;
};
......
......@@ -197,7 +197,14 @@ variable_identifier
context->error(@1, "variable expected", $1.string->c_str());
context->recover();
}
variable = static_cast<const TVariable*>(symbol);
if (context->isVariableBuiltIn(variable) &&
!variable->getExtension().empty() &&
context->extensionErrorCheck(@1, variable->getExtension())) {
context->recover();
}
}
// don't delete $1.string, it's used by error recovery, and the pool
......
......@@ -713,27 +713,27 @@ static const yytype_int16 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
0, 179, 179, 180, 183, 219, 222, 235, 240, 245,
251, 254, 329, 332, 433, 443, 456, 464, 564, 567,
575, 578, 584, 588, 595, 601, 610, 618, 673, 683,
686, 696, 706, 727, 728, 729, 734, 735, 743, 754,
755, 763, 774, 778, 779, 789, 799, 809, 822, 823,
833, 846, 850, 854, 858, 859, 872, 873, 886, 887,
900, 901, 918, 919, 932, 933, 934, 935, 936, 940,
943, 954, 962, 989, 994, 1008, 1045, 1048, 1055, 1063,
1084, 1105, 1115, 1143, 1148, 1158, 1163, 1173, 1176, 1179,
1182, 1188, 1195, 1198, 1220, 1238, 1262, 1285, 1289, 1307,
1315, 1347, 1367, 1388, 1397, 1420, 1423, 1429, 1437, 1445,
1453, 1463, 1470, 1473, 1476, 1482, 1485, 1500, 1504, 1508,
1512, 1516, 1521, 1526, 1531, 1536, 1541, 1546, 1551, 1556,
1561, 1566, 1571, 1576, 1580, 1584, 1592, 1600, 1604, 1617,
1617, 1631, 1631, 1640, 1643, 1659, 1695, 1699, 1705, 1712,
1727, 1731, 1735, 1736, 1742, 1743, 1744, 1745, 1746, 1750,
1751, 1751, 1751, 1761, 1762, 1766, 1766, 1767, 1767, 1772,
1775, 1785, 1788, 1794, 1795, 1799, 1807, 1811, 1821, 1826,
1843, 1843, 1848, 1848, 1855, 1855, 1863, 1866, 1872, 1875,
1881, 1885, 1892, 1899, 1906, 1913, 1924, 1933, 1937, 1944,
1947, 1953, 1953
0, 179, 179, 180, 183, 226, 229, 242, 247, 252,
258, 261, 336, 339, 440, 450, 463, 471, 571, 574,
582, 585, 591, 595, 602, 608, 617, 625, 680, 690,
693, 703, 713, 734, 735, 736, 741, 742, 750, 761,
762, 770, 781, 785, 786, 796, 806, 816, 829, 830,
840, 853, 857, 861, 865, 866, 879, 880, 893, 894,
907, 908, 925, 926, 939, 940, 941, 942, 943, 947,
950, 961, 969, 996, 1001, 1015, 1052, 1055, 1062, 1070,
1091, 1112, 1122, 1150, 1155, 1165, 1170, 1180, 1183, 1186,
1189, 1195, 1202, 1205, 1227, 1245, 1269, 1292, 1296, 1314,
1322, 1354, 1374, 1395, 1404, 1427, 1430, 1436, 1444, 1452,
1460, 1470, 1477, 1480, 1483, 1489, 1492, 1507, 1511, 1515,
1519, 1523, 1528, 1533, 1538, 1543, 1548, 1553, 1558, 1563,
1568, 1573, 1578, 1583, 1587, 1591, 1599, 1607, 1611, 1624,
1624, 1638, 1638, 1647, 1650, 1666, 1702, 1706, 1712, 1719,
1734, 1738, 1742, 1743, 1749, 1750, 1751, 1752, 1753, 1757,
1758, 1758, 1758, 1768, 1769, 1773, 1773, 1774, 1774, 1779,
1782, 1792, 1795, 1801, 1802, 1806, 1814, 1818, 1828, 1833,
1850, 1850, 1855, 1855, 1862, 1862, 1870, 1873, 1879, 1882,
1888, 1892, 1899, 1906, 1913, 1920, 1931, 1940, 1944, 1951,
1954, 1960, 1960
};
#endif
......@@ -2262,7 +2262,14 @@ yyreduce:
context->error((yylsp[(1) - (1)]), "variable expected", (yyvsp[(1) - (1)].lex).string->c_str());
context->recover();
}
variable = static_cast<const TVariable*>(symbol);
if (context->isVariableBuiltIn(variable) &&
!variable->getExtension().empty() &&
context->extensionErrorCheck((yylsp[(1) - (1)]), variable->getExtension())) {
context->recover();
}
}
// don't delete $1.string, it's used by error recovery, and the pool
......
......@@ -2582,6 +2582,7 @@ void Context::initExtensionString()
}
extensionString += "GL_EXT_texture_storage ";
extensionString += "GL_EXT_frag_depth ";
// ANGLE-specific extensions
if (supportsDepthTextures())
......
......@@ -1225,6 +1225,7 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
std::string varyingSemantic = (mUsesPointSize && shaderModel == 3) ? "COLOR" : "TEXCOORD";
std::string targetSemantic = (shaderModel >= 4) ? "SV_Target" : "COLOR";
std::string positionSemantic = (shaderModel >= 4) ? "SV_Position" : "POSITION";
std::string depthSemantic = (shaderModel >= 4) ? "SV_Depth" : "DEPTH";
// special varyings that use reserved registers
int reservedRegisterIndex = registers;
......@@ -1479,6 +1480,11 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
pixelHLSL += " float4 gl_Color" + str(renderTargetIndex) + " : " + targetSemantic + str(renderTargetIndex) + ";\n";
}
if (fragmentShader->mUsesFragDepth)
{
pixelHLSL += " float gl_Depth : " + depthSemantic + ";\n";
}
pixelHLSL += "};\n"
"\n";
......@@ -1592,6 +1598,11 @@ bool ProgramBinary::linkVaryings(InfoLog &infoLog, int registers, const Varying
pixelHLSL += " output.gl_Color" + str(renderTargetIndex) + " = gl_Color[" + str(sourceColorIndex) + "];\n";
}
if (fragmentShader->mUsesFragDepth)
{
pixelHLSL += " output.gl_Depth = gl_Depth;\n";
}
pixelHLSL += "\n"
" return output;\n"
"}\n";
......
......@@ -247,6 +247,7 @@ void Shader::initializeCompiler()
resources.EXT_draw_buffers = mRenderer->getMaxRenderTargets() > 1;
// resources.OES_EGL_image_external = mRenderer->getShareHandleSupport() ? 1 : 0; // TODO: commented out until the extension is actually supported.
resources.FragmentPrecisionHigh = 1; // Shader Model 2+ always supports FP24 (s16e7) which corresponds to highp
resources.EXT_frag_depth = 1; // Shader Model 2+ always supports explicit depth output
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
......@@ -305,6 +306,7 @@ void Shader::parseVaryings()
mUsesPointSize = strstr(mHlsl, "GL_USES_POINT_SIZE") != NULL;
mUsesPointCoord = strstr(mHlsl, "GL_USES_POINT_COORD") != NULL;
mUsesDepthRange = strstr(mHlsl, "GL_USES_DEPTH_RANGE") != NULL;
mUsesFragDepth = strstr(mHlsl, "GL_USES_FRAG_DEPTH") != NULL;
}
}
......@@ -337,6 +339,7 @@ void Shader::uncompile()
mUsesPointSize = false;
mUsesPointCoord = false;
mUsesDepthRange = false;
mUsesFragDepth = false;
mActiveUniforms.clear();
}
......
......@@ -106,6 +106,7 @@ class Shader
bool mUsesPointSize;
bool mUsesPointCoord;
bool mUsesDepthRange;
bool mUsesFragDepth;
static void *mFragmentCompiler;
static void *mVertexCompiler;
......
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