Skip to content

Commit

Permalink
HLSL: fix handling of uniform qualifier in entry point parameters (#2254
Browse files Browse the repository at this point in the history
)

* HLSL: Fix handling of uniforms in entry point parameters

* HLSL: fix handling of "uniform in"

* Tests: Update baseResults of hlsl.function.frag.out for #2254

* HLSL: fix uniforms in function parameters for opaque types
  • Loading branch information
rdb committed Jun 2, 2020
1 parent 999d4fd commit d8edfd8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4389,8 +4389,10 @@ bool TGlslangToSpvTraverser::writableParam(glslang::TStorageQualifier qualifier)
assert(qualifier == glslang::EvqIn ||
qualifier == glslang::EvqOut ||
qualifier == glslang::EvqInOut ||
qualifier == glslang::EvqUniform ||
qualifier == glslang::EvqConstReadOnly);
return qualifier != glslang::EvqConstReadOnly;
return qualifier != glslang::EvqConstReadOnly &&
qualifier != glslang::EvqUniform;
}

// Is parameter pass-by-original?
Expand Down
8 changes: 4 additions & 4 deletions Test/baseResults/hlsl.function.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ ERROR: node is still EOpNull!
0:12 Function Definition: fun4(u1;u1; ( temp 4-component vector of float)
0:12 Function Parameters:
0:12 'id1' ( in uint)
0:12 'id2' ( in uint)
0:12 'id2' ( uniform uint)
0:? Sequence
0:13 Branch: Return with expression
0:13 Construct vec4 ( temp 4-component vector of float)
0:13 Convert uint to float ( temp float)
0:13 component-wise multiply ( temp uint)
0:13 'id1' ( in uint)
0:13 'id2' ( in uint)
0:13 'id2' ( uniform uint)
0:17 Function Definition: fun1(i1; ( temp 4-component vector of float)
0:17 Function Parameters:
0:17 'index' ( in int)
Expand Down Expand Up @@ -84,14 +84,14 @@ ERROR: node is still EOpNull!
0:12 Function Definition: fun4(u1;u1; ( temp 4-component vector of float)
0:12 Function Parameters:
0:12 'id1' ( in uint)
0:12 'id2' ( in uint)
0:12 'id2' ( uniform uint)
0:? Sequence
0:13 Branch: Return with expression
0:13 Construct vec4 ( temp 4-component vector of float)
0:13 Convert uint to float ( temp float)
0:13 component-wise multiply ( temp uint)
0:13 'id1' ( in uint)
0:13 'id2' ( in uint)
0:13 'id2' ( uniform uint)
0:17 Function Definition: fun1(i1; ( temp 4-component vector of float)
0:17 Function Parameters:
0:17 'index' ( in int)
Expand Down
4 changes: 3 additions & 1 deletion hlsl/hlslGrammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,9 @@ bool HlslGrammar::acceptQualifier(TQualifier& qualifier)
qualifier.noContraction = true;
break;
case EHTokIn:
qualifier.storage = (qualifier.storage == EvqOut) ? EvqInOut : EvqIn;
if (qualifier.storage != EvqUniform) {
qualifier.storage = (qualifier.storage == EvqOut) ? EvqInOut : EvqIn;
}
break;
case EHTokOut:
qualifier.storage = (qualifier.storage == EvqIn) ? EvqInOut : EvqOut;
Expand Down
30 changes: 29 additions & 1 deletion hlsl/hlslParseHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2111,6 +2111,23 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
makeVariableInOut(*(*it));
}

// Add uniform parameters to the $Global uniform block.
TVector<TVariable*> opaque_uniforms;
for (int i = 0; i < userFunction.getParamCount(); i++) {
TType& paramType = *userFunction[i].type;
TString& paramName = *userFunction[i].name;
if (paramType.getQualifier().storage == EvqUniform) {
if (!paramType.containsOpaque()) {
// Add it to the global uniform block.
growGlobalUniformBlock(loc, paramType, paramName);
} else {
// Declare it as a separate variable.
TVariable *var = makeInternalVariable(paramName.c_str(), paramType);
opaque_uniforms.push_back(var);
}
}
}

// Synthesize the call

pushScope(); // matches the one in handleFunctionBody()
Expand All @@ -2131,6 +2148,7 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
TVector<TVariable*> argVars;
TIntermAggregate* synthBody = new TIntermAggregate();
auto inputIt = inputs.begin();
auto opaqueUniformIt = opaque_uniforms.begin();
TIntermTyped* callingArgs = nullptr;

for (int i = 0; i < userFunction.getParamCount(); i++) {
Expand All @@ -2149,6 +2167,17 @@ TIntermNode* HlslParseContext::transformEntryPoint(const TSourceLoc& loc, TFunct
intermediate.addSymbol(**inputIt)));
inputIt++;
}
if (param.type->getQualifier().storage == EvqUniform) {
if (!param.type->containsOpaque()) {
// Look it up in the $Global uniform block.
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg,
handleVariable(loc, param.name)));
} else {
intermediate.growAggregate(synthBody, handleAssign(loc, EOpAssign, arg,
intermediate.addSymbol(**opaqueUniformIt)));
++opaqueUniformIt;
}
}
}

// Call
Expand Down Expand Up @@ -6914,7 +6943,6 @@ void HlslParseContext::paramFix(TType& type)
type.getQualifier().storage = EvqConstReadOnly;
break;
case EvqGlobal:
case EvqUniform:
case EvqTemporary:
type.getQualifier().storage = EvqIn;
break;
Expand Down

0 comments on commit d8edfd8

Please sign in to comment.