Translator: Fix zero-init of I/O block arrays

Bug: angleproject:6609
Change-Id: I8245e868fe6bc4798e74088916e1d8cdd0727b6b
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3260325
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
This commit is contained in:
Shahbaz Youssefi 2021-11-03 12:23:11 -04:00 коммит произвёл Angle LUCI CQ
Родитель d7090f5d71
Коммит e10768f07b
2 изменённых файлов: 46 добавлений и 7 удалений

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

@ -59,18 +59,16 @@ void AddZeroInitSequence(const TIntermTyped *initializedNode,
}
else if (initializedNode->getType().isInterfaceBlock())
{
const ImmutableString &name =
static_cast<const TIntermSymbol *>(initializedNode)->getName();
const TType &type = initializedNode->getType();
const TInterfaceBlock &interfaceBlock = *type.getInterfaceBlock();
const TFieldList &fieldList = interfaceBlock.fields();
for (size_t fieldIndex = 0; fieldIndex < fieldList.size(); ++fieldIndex)
{
const TField &field = *fieldList[fieldIndex];
TIntermTyped *blockReference = ReferenceGlobalVariable(name, *symbolTable);
TIntermTyped *fieldIndexRef = CreateIndexNode(static_cast<int>(fieldIndex));
TIntermTyped *fieldReference = new TIntermBinary(
TOperator::EOpIndexDirectInterfaceBlock, blockReference, fieldIndexRef);
const TField &field = *fieldList[fieldIndex];
TIntermTyped *fieldIndexRef = CreateIndexNode(static_cast<int>(fieldIndex));
TIntermTyped *fieldReference =
new TIntermBinary(TOperator::EOpIndexDirectInterfaceBlock,
initializedNode->deepCopy(), fieldIndexRef);
TIntermTyped *fieldZero = CreateZeroNode(*field.type());
TIntermTyped *assignment =
new TIntermBinary(TOperator::EOpAssign, fieldReference, fieldZero);

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

@ -14028,6 +14028,47 @@ void main()
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Tests initializing a shader IO block array using the shader translator option.
TEST_P(GLSLTest_ES31_InitShaderVariables, InitIOBlockArray)
{
ANGLE_SKIP_TEST_IF(!IsGLExtensionEnabled("GL_EXT_shader_io_blocks"));
const char kVS[] = R"(#version 310 es
#extension GL_EXT_shader_io_blocks : require
in vec4 position;
out BlockType {
vec4 blockMember;
} BlockTypeOut[2];
void main()
{
gl_Position = position;
})";
const char kFS[] = R"(#version 310 es
#extension GL_EXT_shader_io_blocks : require
precision mediump float;
out vec4 colorOut;
in BlockType {
vec4 blockMember;
} BlockTypeOut[2];
void main()
{
if (BlockTypeOut[0].blockMember == vec4(0) &&
BlockTypeOut[1].blockMember == vec4(0)) {
colorOut = vec4(0, 1, 0, 1);
} else {
colorOut = vec4(1, 0, 0, 1);
}
})";
ANGLE_GL_PROGRAM(testProgram, kVS, kFS);
drawQuad(testProgram, "position", 0.5f, 1.0f, true);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Tests initializing a shader IO block with a struct using the shader translator option.
TEST_P(GLSLTest_ES31_InitShaderVariables, InitIOBlockWithStruct)
{