Commit cdf50444 by Jamie Madill Committed by Commit Bot

Add test for sampler struct rewriting indexing.

The concern originally was that rewriting sampler structs could lead to incorrect behaviour for indexing. The test attempts to cover this but doesn't repro. It possibly is not an issue. Bug: angleproject:2494 Change-Id: Ibc34b08b5cee3b6ff82d150a64f1768aae64396f Reviewed-on: https://chromium-review.googlesource.com/1117321Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarLuc Ferron <lucferron@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent fa5d84be
...@@ -121,8 +121,6 @@ class Traverser final : public TIntermTraverser ...@@ -121,8 +121,6 @@ class Traverser final : public TIntermTraverser
TFieldList *newFieldList = new TFieldList; TFieldList *newFieldList = new TFieldList;
ASSERT(structure->containsSamplers()); ASSERT(structure->containsSamplers());
// Removing the sampler field may produce struct indexing bugs.
// TODO(jmadill): Fix potential bug. http://anglebug.com/2494
for (const TField *field : structure->fields()) for (const TField *field : structure->fields())
{ {
const TType &fieldType = *field->type(); const TType &fieldType = *field->type();
......
...@@ -2970,6 +2970,60 @@ void main() ...@@ -2970,6 +2970,60 @@ void main()
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green); EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
} }
// Tests that rewriting samplers in structs doesn't mess up indexing.
TEST_P(GLSLTest, SamplerInStructMemberIndexing)
{
const char kVertexShader[] = R"(attribute vec2 position;
varying vec2 texCoord;
void main()
{
gl_Position = vec4(position, 0, 1);
texCoord = position * 0.5 + vec2(0.5);
})";
const char kFragmentShader[] = R"(precision mediump float;
struct S { sampler2D samp; bool b; };
uniform S uni;
varying vec2 texCoord;
void main()
{
if (uni.b)
{
gl_FragColor = texture2D(uni.samp, texCoord);
}
else
{
gl_FragColor = vec4(1, 0, 0, 1);
}
})";
ANGLE_GL_PROGRAM(program, kVertexShader, kFragmentShader);
glUseProgram(program);
GLint bLoc = glGetUniformLocation(program, "uni.b");
ASSERT_NE(-1, bLoc);
GLint sampLoc = glGetUniformLocation(program, "uni.samp");
ASSERT_NE(-1, sampLoc);
glUniform1i(bLoc, 1);
std::array<GLColor, 4> kGreenPixels = {
{GLColor::green, GLColor::green, GLColor::green, GLColor::green}};
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
kGreenPixels.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
drawQuad(program, "position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Tests two nameless struct uniforms. // Tests two nameless struct uniforms.
TEST_P(GLSLTest, TwoEmbeddedStructUniforms) TEST_P(GLSLTest, TwoEmbeddedStructUniforms)
{ {
......
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