Commit 0730e630 by Qin Jiajia Committed by Commit Bot

Fix needStructMapping

In previous logic, we didn't check the structure field member type. So when passing the non-struct member of a structure to a function, it would think that struct mapping was needed. In this patch, we add more checking so that struct mapping only happens when there are structure copy or passing a structure to a function. BUG=angleproject:2967 Change-Id: Ic98e884c8f8540e180cdf40a0e036ffef18c1689 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1638227 Commit-Queue: Jiajia Qin <jiajia.qin@intel.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 98f21671
...@@ -175,15 +175,27 @@ TReferencedBlock::TReferencedBlock(const TInterfaceBlock *aBlock, ...@@ -175,15 +175,27 @@ TReferencedBlock::TReferencedBlock(const TInterfaceBlock *aBlock,
bool OutputHLSL::needStructMapping(TIntermTyped *node) bool OutputHLSL::needStructMapping(TIntermTyped *node)
{ {
ASSERT(node->getBasicType() == EbtStruct);
for (unsigned int n = 0u; getAncestorNode(n) != nullptr; ++n) for (unsigned int n = 0u; getAncestorNode(n) != nullptr; ++n)
{ {
TIntermNode *ancestor = getAncestorNode(n); TIntermNode *ancestor = getAncestorNode(n);
const TIntermBinary *ancestorBinary = ancestor->getAsBinaryNode(); const TIntermBinary *ancestorBinary = ancestor->getAsBinaryNode();
if (ancestorBinary && ancestorBinary->getLeft()->getBasicType() == EbtStruct) if (ancestorBinary)
{ {
switch (ancestorBinary->getOp()) switch (ancestorBinary->getOp())
{ {
case EOpIndexDirectStruct: case EOpIndexDirectStruct:
{
const TStructure *structure = ancestorBinary->getLeft()->getType().getStruct();
const TIntermConstantUnion *index =
ancestorBinary->getRight()->getAsConstantUnion();
const TField *field = structure->fields()[index->getIConst(0)];
if (field->type()->getStruct() == nullptr)
{
return false;
}
break;
}
case EOpIndexDirect: case EOpIndexDirect:
case EOpIndexIndirect: case EOpIndexIndirect:
break; break;
......
...@@ -223,4 +223,33 @@ TEST_F(HLSLOutputTest, SameNameArray) ...@@ -223,4 +223,33 @@ TEST_F(HLSLOutputTest, SameNameArray)
EXPECT_TRUE(foundInCode("_arr1029[2]")); EXPECT_TRUE(foundInCode("_arr1029[2]"));
// The unique id of the new array, arr, is 1030 // The unique id of the new array, arr, is 1030
EXPECT_TRUE(foundInCode("_arr1030[2]")); EXPECT_TRUE(foundInCode("_arr1030[2]"));
} }
\ No newline at end of file
// Test that passing a non-struct member of a std140 structure to a function won't trigger the
// struct mapping.
TEST_F(HLSLOutputTest, NonStructMemberAsFunctionArgument)
{
constexpr char shaderString[] = R"(#version 300 es
precision highp float;
out vec4 my_FragColor;
struct InstancingData
{
vec4 data;
};
layout(std140) uniform InstanceBlock
{
InstancingData instances[8];
};
void main()
{
int index = int(gl_FragCoord.x);
float result = dot(instances[index].data, vec4(1.0, 1.0, 1.0, 1.0));
my_FragColor = vec4(result, 0.0, 0.0, 1.0);
})";
compile(shaderString);
EXPECT_FALSE(foundInCode("map_instances"));
}
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