Commit 183d7e24 by Olli Etuaho

Remove predefined precision qualifiers from ESSL3 samplers

New sampler types in ESSL3 should not have default precision qualifiers. This is specified in ESSL 3.00.4 section 4.5.4. BUG=angleproject:1222 TEST=angle_unittests Change-Id: I9c8e7a5fbb4278db80de79bcaeebaf23e64242a0 Reviewed-on: https://chromium-review.googlesource.com/312048 Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 6328667d
......@@ -423,11 +423,6 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
floatingPoint.secondarySize = 1;
floatingPoint.array = false;
TPublicType sampler;
sampler.primarySize = 1;
sampler.secondarySize = 1;
sampler.array = false;
switch(shaderType)
{
case GL_FRAGMENT_SHADER:
......@@ -440,14 +435,15 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
default:
assert(false && "Language not supported");
}
// We set defaults for all the sampler types, even those that are
// Set defaults for sampler types that have default precision, even those that are
// only available if an extension exists.
for (int samplerType = EbtGuardSamplerBegin + 1;
samplerType < EbtGuardSamplerEnd; ++samplerType)
{
sampler.type = static_cast<TBasicType>(samplerType);
symbolTable.setDefaultPrecision(sampler, EbpLow);
}
// New sampler types in ESSL3 don't have default precision. ESSL1 types do.
initSamplerDefaultPrecision(EbtSampler2D);
initSamplerDefaultPrecision(EbtSamplerCube);
// SamplerExternalOES is specified in the extension to have default precision.
initSamplerDefaultPrecision(EbtSamplerExternalOES);
// It isn't specified whether Sampler2DRect has default precision.
initSamplerDefaultPrecision(EbtSampler2DRect);
InsertBuiltInFunctions(shaderType, shaderSpec, resources, symbolTable);
......@@ -456,6 +452,17 @@ bool TCompiler::InitBuiltInSymbolTable(const ShBuiltInResources &resources)
return true;
}
void TCompiler::initSamplerDefaultPrecision(TBasicType samplerType)
{
ASSERT(samplerType > EbtGuardSamplerBegin && samplerType < EbtGuardSamplerEnd);
TPublicType sampler;
sampler.primarySize = 1;
sampler.secondarySize = 1;
sampler.array = false;
sampler.type = samplerType;
symbolTable.setDefaultPrecision(sampler, EbpLow);
}
void TCompiler::setResourceString()
{
std::ostringstream strstream;
......
......@@ -179,6 +179,8 @@ class TCompiler : public TShHandleBase
bool tagUsedFunctions();
void internalTagUsedFunction(size_t index);
void initSamplerDefaultPrecision(TBasicType samplerType);
// Removes unused function declarations and prototypes from the AST
class UnusedPredicate;
bool pruneUnusedFunctions(TIntermNode *root);
......
......@@ -226,24 +226,25 @@ bool TParseContext::precisionErrorCheck(const TSourceLoc &line,
{
if (!mChecksPrecisionErrors)
return false;
switch (type)
if (precision == EbpUndefined)
{
case EbtFloat:
if (precision == EbpUndefined)
{
switch (type)
{
case EbtFloat:
error(line, "No precision specified for (float)", "");
return true;
}
break;
case EbtInt:
if (precision == EbpUndefined)
{
case EbtInt:
case EbtUInt:
UNREACHABLE(); // there's always a predeclared qualifier
error(line, "No precision specified (int)", "");
return true;
}
break;
default:
return false;
default:
if (IsSampler(type))
{
error(line, "No precision specified (sampler)", "");
return true;
}
}
}
return false;
}
......
......@@ -280,7 +280,7 @@ TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const
int level = static_cast<int>(precisionStack.size()) - 1;
assert(level >= 0); // Just to be safe. Should not happen.
// If we dont find anything we return this. Should we error check this?
// If we dont find anything we return this. Some types don't have predefined default precision.
TPrecision prec = EbpUndefined;
while (level >= 0)
{
......
......@@ -1334,3 +1334,22 @@ TEST_F(MalformedShaderTest, DefaultPrecisionUint)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Test that sampler3D needs to be precision qualified.
// ESSL 3.00.4 section 4.5.4: New ESSL 3.00 sampler types don't have predefined precision.
TEST_F(MalformedShaderTest, NoPrecisionSampler3D)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"uniform sampler3D s;\n"
"out vec4 my_FragColor;\n"
"void main()\n"
"{\n"
" my_FragColor = vec4(0.0);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
......@@ -265,7 +265,7 @@ class MipmapTestES3 : public ANGLETest
const std::string fragmentShaderSourceArray = SHADER_SOURCE
( #version 300 es\n
precision highp float;
uniform sampler2DArray tex;
uniform highp sampler2DArray tex;
uniform int slice;
in vec2 texcoord;
out vec4 out_FragColor;
......@@ -303,7 +303,7 @@ class MipmapTestES3 : public ANGLETest
const std::string fragmentShaderSource3D = SHADER_SOURCE
( #version 300 es\n
precision highp float;
uniform sampler3D tex;
uniform highp sampler3D tex;
uniform float slice;
uniform float lod;
in vec2 texcoord;
......
......@@ -278,7 +278,7 @@ class TextureTestES3 : public ANGLETest
const std::string fragmentShaderSource2DArray =
"#version 300 es\n"
"precision highp float;\n"
"uniform sampler2DArray tex2DArray;\n"
"uniform highp sampler2DArray tex2DArray;\n"
"in vec2 texcoord;\n"
"out vec4 fragColor;\n"
"void main()\n"
......
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