Commit 84c11c53 by Jamie Madill Committed by Commit Bot

Vulkan: Implement sampler structs as function args.

Bug: angleproject:2494 Change-Id: Ia8e374846427b7140ab2565ae5b9b18409a76d96 Reviewed-on: https://chromium-review.googlesource.com/1117323 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent 5c8113d3
......@@ -55,6 +55,12 @@ class ImmutableStringBuilder
}
}
template <typename T>
static constexpr size_t GetHexCharCount()
{
return sizeof(T) * 2;
}
private:
inline static char *AllocateEmptyPoolCharArray(size_t strLength)
{
......
......@@ -219,4 +219,17 @@ bool TFunction::isImageFunction() const
(name() == kImageSizeName || name() == kImageLoadName || name() == kImageStoreName);
}
bool TFunction::hasSamplerInStructParams() const
{
for (size_t paramIndex = 0; paramIndex < mParamCount; ++paramIndex)
{
const TVariable *param = getParam(paramIndex);
if (param->getType().isStructureContainingSamplers())
{
return true;
}
}
return false;
}
} // namespace sh
......@@ -234,6 +234,7 @@ class TFunction : public TSymbol
bool isMain() const;
bool isImageFunction() const;
bool hasSamplerInStructParams() const;
// Note: Only to be used for static built-in functions!
constexpr TFunction(const TSymbolUniqueId &id,
......
......@@ -113,6 +113,8 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase
const TSymbol *findUserDefined(const ImmutableString &name) const;
TFunction *findUserDefinedFunction(const ImmutableString &name) const;
const TSymbol *findGlobal(const ImmutableString &name) const;
const TSymbol *findBuiltIn(const ImmutableString &name, int shaderVersion) const;
......@@ -157,8 +159,6 @@ class TSymbolTable : angle::NonCopyable, TSymbolTableBase
class TSymbolTableLevel;
TFunction *findUserDefinedFunction(const ImmutableString &name) const;
void initSamplerDefaultPrecision(TBasicType samplerType);
void initializeBuiltInVariables(sh::GLenum shaderType,
......
......@@ -267,9 +267,28 @@
1028 WIN LINUX MAC : dEQP-GLES2.functional.fbo.completeness.renderable.texture.depth.srgb8 = FAIL
// Vulkan failures
2494 VULKAN : dEQP-GLES2.functional.shaders.struct.uniform.sampler_in_function_arg_* = SKIP
2494 VULKAN : dEQP-GLES2.functional.shaders.struct.uniform.sampler_in_array_function_arg_* = SKIP
2592 VULKAN : dEQP-GLES2.functional.shaders.builtin_variable.depth_range* = SKIP
2598 VULKAN : dEQP-GLES2.functional.rasterization.primitives.line* = SKIP
2599 VULKAN : dEQP-GLES2.functional.rasterization.limits.points = SKIP
2601 VULKAN : dEQP-GLES2.functional.clipping.* = SKIP
2353 VULKAN : dEQP-GLES2.functional.polygon_offset.* = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.points.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangles.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangle_fan.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangle_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.lines.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.line_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.line_loop.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.indices.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.points.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangles.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangle_fan.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangle_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.lines.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.line_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.line_loop.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.random.* = SKIP
2444 VULKAN : dEQP-GLES2.functional.default_vertex_attrib.* = SKIP
// fixed format vertex data
2405 VULKAN : dEQP-GLES2.functional.vertex_arrays.multiple_attributes.input_types.3_byte2_vec2_byte2_vec2_fixed* = SKIP
......@@ -307,27 +326,6 @@
2405 VULKAN : dEQP-GLES2.functional.vertex_arrays.single_attribute.usages.buffer_0_0_fixed* = SKIP
2405 VULKAN : dEQP-GLES2.functional.vertex_arrays.single_attribute.usages.buffer_0_32_fixed* = SKIP
2405 VULKAN : dEQP-GLES2.functional.vertex_arrays.single_attribute.usages.buffer_0_8_fixed* = SKIP
2598 VULKAN : dEQP-GLES2.functional.rasterization.primitives.line* = SKIP
2599 VULKAN : dEQP-GLES2.functional.rasterization.limits.points = SKIP
2601 VULKAN : dEQP-GLES2.functional.clipping.* = SKIP
2353 VULKAN : dEQP-GLES2.functional.polygon_offset.* = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.points.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangles.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangle_fan.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.triangle_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.lines.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.line_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_arrays.line_loop.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.indices.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.points.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangles.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangle_fan.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.triangle_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.lines.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.line_strip.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.draw_elements.line_loop.default_attribute = SKIP
2444 VULKAN : dEQP-GLES2.functional.draw.random.* = SKIP
2444 VULKAN : dEQP-GLES2.functional.default_vertex_attrib.* = SKIP
// Vulkan AMD Windows specific failures
2602 VULKAN WIN AMD : dEQP-GLES2.functional.buffer.write.* = SKIP
......
......@@ -3224,15 +3224,104 @@ TEST_P(GLSLTest_ES3, VaryingStructUsedInFragmentShader)
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// This test covers passing a struct containing a sampler as a function argument.
TEST_P(GLSLTest, StructsWithSamplersAsFunctionArg)
{
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
const char kFragmentShader[] = R"(precision mediump float;
struct S { sampler2D samplerMember; };
uniform S uStruct;
uniform vec2 uTexCoord;
vec4 foo(S structVar)
{
return texture2D(structVar.samplerMember, uTexCoord);
}
void main()
{
gl_FragColor = foo(uStruct);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFragmentShader);
// Initialize the texture with green.
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
GLubyte texData[] = {0u, 255u, 0u, 255u};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Draw
glUseProgram(program);
GLint samplerMemberLoc = glGetUniformLocation(program, "uStruct.samplerMember");
ASSERT_NE(-1, samplerMemberLoc);
glUniform1i(samplerMemberLoc, 0);
GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord");
ASSERT_NE(-1, texCoordLoc);
glUniform2f(texCoordLoc, 0.5f, 0.5f);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
}
// This test covers passing a struct containing a sampler as a function argument.
TEST_P(GLSLTest, StructsWithSamplersAsFunctionArgWithPrototype)
{
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
const char kFragmentShader[] = R"(precision mediump float;
struct S { sampler2D samplerMember; };
uniform S uStruct;
uniform vec2 uTexCoord;
vec4 foo(S structVar);
vec4 foo(S structVar)
{
return texture2D(structVar.samplerMember, uTexCoord);
}
void main()
{
gl_FragColor = foo(uStruct);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFragmentShader);
// Initialize the texture with green.
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
GLubyte texData[] = {0u, 255u, 0u, 255u};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Draw
glUseProgram(program);
GLint samplerMemberLoc = glGetUniformLocation(program, "uStruct.samplerMember");
ASSERT_NE(-1, samplerMemberLoc);
glUniform1i(samplerMemberLoc, 0);
GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord");
ASSERT_NE(-1, texCoordLoc);
glUniform2f(texCoordLoc, 0.5f, 0.5f);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
}
// This test covers passing an array of structs containing samplers as a function argument.
TEST_P(GLSLTest, ArrayOfStructsWithSamplersAsFunctionArg)
{
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
// TODO(jmadill): Samplers in structs. http://anglebug.com/2494
ANGLE_SKIP_TEST_IF(IsVulkan());
const std::string &fragmentShader =
"precision mediump float;\n"
"struct S\n"
......@@ -3284,8 +3373,8 @@ TEST_P(GLSLTest, StructWithSamplerArrayAsFunctionArg)
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
// TODO(jmadill): Samplers in structs. http://anglebug.com/2494
ANGLE_SKIP_TEST_IF(IsVulkan());
// TODO(jmadill): Fix on Android if possible. http://anglebug.com/2703
ANGLE_SKIP_TEST_IF(IsAndroid() && IsVulkan());
const std::string &fragmentShader =
"precision mediump float;\n"
......@@ -3332,6 +3421,108 @@ TEST_P(GLSLTest, StructWithSamplerArrayAsFunctionArg)
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
}
// This test covers passing nested structs containing a sampler as a function argument.
TEST_P(GLSLTest, NestedStructsWithSamplersAsFunctionArg)
{
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
const char kFragmentShader[] = R"(precision mediump float;
struct S { sampler2D samplerMember; };
struct T { S nest; };
uniform T uStruct;
uniform vec2 uTexCoord;
vec4 foo2(S structVar)
{
return texture2D(structVar.samplerMember, uTexCoord);
}
vec4 foo(T structVar)
{
return foo2(structVar.nest);
}
void main()
{
gl_FragColor = foo(uStruct);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFragmentShader);
// Initialize the texture with green.
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
GLubyte texData[] = {0u, 255u, 0u, 255u};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Draw
glUseProgram(program);
GLint samplerMemberLoc = glGetUniformLocation(program, "uStruct.nest.samplerMember");
ASSERT_NE(-1, samplerMemberLoc);
glUniform1i(samplerMemberLoc, 0);
GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord");
ASSERT_NE(-1, texCoordLoc);
glUniform2f(texCoordLoc, 0.5f, 0.5f);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
}
// This test covers passing a compound structs containing a sampler as a function argument.
TEST_P(GLSLTest, CompoundStructsWithSamplersAsFunctionArg)
{
// Shader failed to compile on Android. http://anglebug.com/2114
ANGLE_SKIP_TEST_IF(IsAndroid() && IsAdreno() && IsOpenGLES());
const char kFragmentShader[] = R"(precision mediump float;
struct S { sampler2D samplerMember; bool b; };
uniform S uStruct;
uniform vec2 uTexCoord;
vec4 foo(S structVar)
{
if (structVar.b)
return texture2D(structVar.samplerMember, uTexCoord);
else
return vec4(1, 0, 0, 1);
}
void main()
{
gl_FragColor = foo(uStruct);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFragmentShader);
// Initialize the texture with green.
GLTexture tex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
GLubyte texData[] = {0u, 255u, 0u, 255u};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, texData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Draw
glUseProgram(program);
GLint samplerMemberLoc = glGetUniformLocation(program, "uStruct.samplerMember");
ASSERT_NE(-1, samplerMemberLoc);
glUniform1i(samplerMemberLoc, 0);
GLint texCoordLoc = glGetUniformLocation(program, "uTexCoord");
ASSERT_NE(-1, texCoordLoc);
glUniform2f(texCoordLoc, 0.5f, 0.5f);
GLint bLoc = glGetUniformLocation(program, "uStruct.b");
ASSERT_NE(-1, bLoc);
glUniform1i(bLoc, 1);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(1, 1, GLColor::green);
}
// Test that a global variable declared after main() works. This is a regression test for an issue
// in global variable initialization.
TEST_P(WebGLGLSLTest, GlobalVariableDeclaredAfterMain)
......
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