Translator: Validate precision for function args

In fragment shaders, float does not have a default precision.  Any
declaration of this type must therefore specify the precision if a
default one is not provided.

This was not validated for function arguments.

Bug: chromium:1255089
Change-Id: I0d17e226ec88610692ec7dd18793cf4d471f12e7
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3226314
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Tim Van Patten <timvp@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Shahbaz Youssefi 2021-10-18 16:22:40 -04:00 коммит произвёл Angle LUCI CQ
Родитель 02b73c2fd7
Коммит ef237faf66
4 изменённых файлов: 31 добавлений и 9 удалений

Просмотреть файл

@ -3959,17 +3959,20 @@ TFunction *TParseContext::parseFunctionDeclarator(const TSourceLoc &location, TF
for (size_t i = 0u; i < function->getParamCount(); ++i)
{
const TVariable *param = function->getParam(i);
if (param->getType().isStructSpecifier())
const TType &paramType = param->getType();
if (paramType.isStructSpecifier())
{
// ESSL 3.00.6 section 12.10.
error(location, "Function parameter type cannot be a structure definition",
function->name());
}
checkPrecisionSpecified(location, paramType.getPrecision(), paramType.getBasicType());
}
if (getShaderVersion() >= 300)
{
if (symbolTable.isUnmangledBuiltInName(function->name(), getShaderVersion(),
extensionBehavior()))
{

Просмотреть файл

@ -3334,6 +3334,25 @@ TEST_F(FragmentShaderValidationTest, FloatDeclarationNoQualifiersNoPrecision)
}
}
// Precision must be specified for floats. Test this with a function argument no qualifiers.
TEST_F(FragmentShaderValidationTest, FloatDeclarationNoQualifiersNoPrecisionFunctionArg)
{
const std::string &shaderString = R"(
int c(float x)
{
return int(x);
}
void main()
{
c(5.0);
})";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
}
}
// Check compiler doesn't crash on incorrect unsized array declarations.
TEST_F(FragmentShaderValidationTest, IncorrectUnsizedArray)
{

Просмотреть файл

@ -4611,7 +4611,7 @@ layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, r32f) uniform highp image2D image1[2][3];
layout(binding = 6, r32f) uniform highp image2D image2;
void testFunction(image2D imageOut[2][3])
void testFunction(highp image2D imageOut[2][3])
{
// image1 is an array of 1x1 images.
// image2 is a 1x4 image with the following data:
@ -5079,8 +5079,8 @@ TEST_P(GLSLTest_ES31, ParameterArraysOfArraysSampler)
"uniform mediump isampler2D test[2][3];\n"
"const vec2 ZERO = vec2(0.0, 0.0);\n"
"\n"
"bool check(isampler2D data[2][3]);\n"
"bool check(isampler2D data[2][3]) {\n"
"bool check(mediump isampler2D data[2][3]);\n"
"bool check(mediump isampler2D data[2][3]) {\n"
"#define DO_CHECK(i,j) \\\n"
" if (texture(data[i][j], ZERO) != ivec4(i+1, j+1, 0, 1)) { \\\n"
" return false; \\\n"
@ -5284,20 +5284,20 @@ TEST_P(GLSLTest_ES31, ParameterArrayArrayArraySampler)
"uniform mediump isampler2D test2[4];\n"
"const vec2 ZERO = vec2(0.0, 0.0);\n"
"\n"
"bool check1D(isampler2D arr[4], int x, int y) {\n"
"bool check1D(mediump isampler2D arr[4], int x, int y) {\n"
" if (texture(arr[0], ZERO) != ivec4(x, y, 0, 0)+1) return false;\n"
" if (texture(arr[1], ZERO) != ivec4(x, y, 1, 0)+1) return false;\n"
" if (texture(arr[2], ZERO) != ivec4(x, y, 2, 0)+1) return false;\n"
" if (texture(arr[3], ZERO) != ivec4(x, y, 3, 0)+1) return false;\n"
" return true;\n"
"}\n"
"bool check2D(isampler2D arr[3][4], int x) {\n"
"bool check2D(mediump isampler2D arr[3][4], int x) {\n"
" if (!check1D(arr[0], x, 0)) return false;\n"
" if (!check1D(arr[1], x, 1)) return false;\n"
" if (!check1D(arr[2], x, 2)) return false;\n"
" return true;\n"
"}\n"
"bool check3D(isampler2D arr[2][3][4]) {\n"
"bool check3D(mediump isampler2D arr[2][3][4]) {\n"
" if (!check2D(arr[0], 0)) return false;\n"
" if (!check2D(arr[1], 1)) return false;\n"
" return true;\n"

Просмотреть файл

@ -106,7 +106,7 @@ precision mediump float;
varying mediump vec2 texCoord;
uniform mediump samplerVideoWEBGL s;
vec4 wrapTextureVideoWEBGL(samplerVideoWEBGL sampler, vec2 coord)
vec4 wrapTextureVideoWEBGL(mediump samplerVideoWEBGL sampler, vec2 coord)
{
return textureVideoWEBGL(sampler, coord);
}