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

HLSL: fix handling of uniform qualifier in entry point parameters #2254

Merged
merged 4 commits into from
Jun 2, 2020
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
4 changes: 3 additions & 1 deletion SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4388,8 +4388,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