Skip to content

Commit

Permalink
Implement relaxed rule for opaque struct members
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourasse authored Nov 29, 2023
1 parent a3069e1 commit c59b876
Show file tree
Hide file tree
Showing 9 changed files with 2,739 additions and 2,139 deletions.
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 @@ -722,6 +722,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

0 comments on commit c59b876

Please sign in to comment.