Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement relaxed rule for opaque struct members #3365

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,585 changes: 893 additions & 692 deletions Test/baseResults/vk.relaxed.frag.out

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions Test/vk.relaxed.frag
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ uniform vec4 a;
uniform vec2 b = vec2(0, 0); // initializer will be ignored
layout(location = 0) uniform vec2 c; // location qualifier will be ignored
uniform vec4 d[10];

struct SamplerArray{
sampler2D tn[4];
};

uniform struct e {
vec2 x;
float y;
uint z;
sampler2D t0;
SamplerArray samplers;
} structUniform;

// opaque types will not be grouped into uniform block
Expand Down Expand Up @@ -64,11 +71,15 @@ uint bar() {
vec4 foo() {
float f = j + bufferInstance.j + structUniform.y + structUniform.z;
vec2 v2 = b + c + structUniform.x;
vec4 v4 = a + d[0] + d[1] + d[2] + k + bufferInstance.k + texture(t1, vec2(0, 0));
vec4 v4 = a + d[0] + d[1] + d[2] + k + bufferInstance.k + texture(t1, vec2(0, 0)) + texture(structUniform.t0, vec2(0, 0));
return vec4(f) * vec4(v2, 1, 1) * v4;
}

vec4 baz(SamplerArray samplers) {
return texture(samplers.tn[0], vec2(0, 0)) + texture(samplers.tn[1], vec2(0, 0)) + texture(samplers.tn[2], vec2(0, 0)) + texture(samplers.tn[3], vec2(0, 0));
}

void main() {
float j = float(bar());
o = j * foo();
}
o = j * foo() + baz(structUniform.samplers);
}
34 changes: 34 additions & 0 deletions glslang/MachineIndependent/Intermediate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,40 @@ TIntermAggregate* TIntermediate::growAggregate(TIntermNode* left, TIntermNode* r
return aggNode;
}

TIntermAggregate* TIntermediate::mergeAggregate(TIntermNode* left, TIntermNode* right)
{
if (left == nullptr && right == nullptr)
return nullptr;

TIntermAggregate* aggNode = nullptr;
if (left != nullptr)
aggNode = left->getAsAggregate();
if (aggNode == nullptr || aggNode->getOp() != EOpNull) {
aggNode = new TIntermAggregate;
if (left != nullptr)
aggNode->getSequence().push_back(left);
}

TIntermAggregate* rhsagg = right->getAsAggregate();
if (rhsagg == nullptr || rhsagg->getOp() != EOpNull)
aggNode->getSequence().push_back(right);
else
aggNode->getSequence().insert(aggNode->getSequence().end(),
rhsagg->getSequence().begin(),
rhsagg->getSequence().end());

return aggNode;
}

TIntermAggregate* TIntermediate::mergeAggregate(TIntermNode* left, TIntermNode* right, const TSourceLoc& loc)
{
TIntermAggregate* aggNode = mergeAggregate(left, right);
if (aggNode)
aggNode->setLoc(loc);

return aggNode;
}

//
// Turn an existing node into an aggregate.
//
Expand Down
18 changes: 18 additions & 0 deletions glslang/MachineIndependent/ParseContextBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,24 @@ void TParseContextBase::finish()
if (parsingBuiltins)
return;

for (const TString& relaxedSymbol : relaxedSymbols)
{
TSymbol* symbol = symbolTable.find(relaxedSymbol);
TType& type = symbol->getWritableType();
for (const TTypeLoc& typeLoc : *type.getStruct())
{
if (typeLoc.type->isOpaque())
{
typeLoc.type->getSampler() = TSampler{};
typeLoc.type->setBasicType(EbtInt);
TString fieldName("/*");
fieldName.append(typeLoc.type->getFieldName());
fieldName.append("*/");
typeLoc.type->setFieldName(fieldName);
}
}
}

// Transfer the linkage symbols to AST nodes, preserving order.
TIntermAggregate* linkage = new TIntermAggregate;
for (auto i = linkageSymbols.begin(); i != linkageSymbols.end(); ++i)
Expand Down
Loading