Commit d569619d by Jamie Madill

translator: Fail compilation if precision emu unsupported.

The fuzzer uncovered a case where we were trying to emulate precision on HLSL 3.0, causing an ASSERT crash. BUG=chromium:653276 Change-Id: I2e666a1ff4f605541e25f04264146063559cb835 Reviewed-on: https://chromium-review.googlesource.com/394237Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 5b7d40b3
......@@ -15,6 +15,7 @@
#include "compiler/translator/CallDAG.h"
#include "compiler/translator/DeferGlobalInitializers.h"
#include "compiler/translator/EmulateGLFragColorBroadcast.h"
#include "compiler/translator/EmulatePrecision.h"
#include "compiler/translator/ForLoopUnroll.h"
#include "compiler/translator/Initialize.h"
#include "compiler/translator/InitializeParseContext.h"
......@@ -329,6 +330,18 @@ TIntermNode *TCompiler::compileTreeImpl(const char *const shaderStrings[],
if (success && shouldRunLoopAndIndexingValidation(compileOptions))
success = validateLimitations(root);
// Fail compilation if precision emulation not supported.
if (success && getResources().WEBGL_debug_shader_precision &&
getPragma().debugShaderPrecision)
{
if (!EmulatePrecision::SupportedInLanguage(outputType))
{
infoSink.info.prefix(EPrefixError);
infoSink.info << "Precision emulation not supported for this output type.";
success = false;
}
}
// Unroll for-loop markup needs to happen after validateLimitations pass.
if (success && (compileOptions & SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX))
{
......
......@@ -91,6 +91,7 @@ class RoundingHelperWriterHLSL : public RoundingHelperWriter
RoundingHelperWriter *RoundingHelperWriter::createHelperWriter(const ShShaderOutput outputLanguage)
{
ASSERT(EmulatePrecision::SupportedInLanguage(outputLanguage));
switch (outputLanguage)
{
case SH_HLSL_4_1_OUTPUT:
......@@ -98,9 +99,6 @@ RoundingHelperWriter *RoundingHelperWriter::createHelperWriter(const ShShaderOut
case SH_ESSL_OUTPUT:
return new RoundingHelperWriterESSL(outputLanguage);
default:
// Other languages not yet supported
ASSERT(outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT ||
IsGLSL130OrNewer(outputLanguage));
return new RoundingHelperWriterGLSL(outputLanguage);
}
}
......@@ -705,3 +703,17 @@ void EmulatePrecision::writeEmulationHelpers(TInfoSinkBase &sink,
roundingHelperWriter->writeCompoundAssignmentHelper(sink, it->lType, it->rType, "*", "mul");
}
// static
bool EmulatePrecision::SupportedInLanguage(const ShShaderOutput outputLanguage)
{
switch (outputLanguage)
{
case SH_HLSL_4_1_OUTPUT:
case SH_ESSL_OUTPUT:
return true;
default:
// Other languages not yet supported
return (outputLanguage == SH_GLSL_COMPATIBILITY_OUTPUT ||
IsGLSL130OrNewer(outputLanguage));
}
}
......@@ -32,6 +32,8 @@ class EmulatePrecision : public TLValueTrackingTraverser
const int shaderVersion,
const ShShaderOutput outputLanguage);
static bool SupportedInLanguage(const ShShaderOutput outputLanguage);
private:
struct TypePair
{
......
......@@ -1023,3 +1023,23 @@ TEST_F(DebugShaderPrecisionTest, ModfOutParameter)
ASSERT_TRUE(foundInAllGLSLCode("modf(angle_frm(u), o)"));
ASSERT_TRUE(foundInHLSLCode("modf(angle_frm(_u), _o)"));
}
#if defined(ANGLE_ENABLE_HLSL)
// Tests precision emulation with HLSL 3.0 output -- should error gracefully.
TEST(DebugShaderPrecisionNegativeTest, HLSL3Unsupported)
{
const std::string &shaderString =
"precision mediump float;\n"
"uniform float u;\n"
"void main() {\n"
" gl_FragColor = vec4(u);\n"
"}\n";
std::string infoLog;
std::string translatedCode;
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.WEBGL_debug_shader_precision = 1;
ASSERT_FALSE(compileTestShader(GL_FRAGMENT_SHADER, SH_GLES3_SPEC, SH_HLSL_3_0_OUTPUT,
shaderString, &resources, 0, &translatedCode, &infoLog));
}
#endif // defined(ANGLE_ENABLE_HLSL)
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