HLSL: Support register(..., spaceN) for setting the descriptor set.

This was suggested in issue #454.
This commit is contained in:
John Kessenich
2016-09-05 16:03:12 -06:00
parent e3218e270e
commit cfd7ce87cd
6 changed files with 49 additions and 16 deletions

View File

@@ -2591,11 +2591,11 @@ void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
}
// post_decls
// : COLON semantic // optional
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
// COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt RIGHT_PAREN // optional
// : COLON semantic // optional
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
// COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN // optional
// COLON LAYOUT layout_qualifier_list
// annotations // optional
// annotations // optional
//
void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
{
@@ -2632,7 +2632,8 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
expected("layout, semantic, packoffset, or register");
return;
} else if (*idToken.string == "register") {
// REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt RIGHT_PAREN
// REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN
// LEFT_PAREN
if (! acceptTokenClass(EHTokLeftParen)) {
expected("(");
return;
@@ -2643,7 +2644,8 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
expected("register number description");
return;
}
if (acceptTokenClass(EHTokComma)) {
if (registerDesc.string->size() > 1 && !isdigit((*registerDesc.string)[1]) &&
acceptTokenClass(EHTokComma)) {
// Then we didn't really see the registerDesc yet, it was
// actually the profile. Adjust...
profile = registerDesc;
@@ -2666,11 +2668,20 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
break;
}
}
// (COMMA SPACEN)opt
HlslToken spaceDesc;
if (acceptTokenClass(EHTokComma)) {
if (! acceptIdentifier(spaceDesc)) {
expected ("space identifier");
return;
}
}
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) {
expected(")");
break;
}
parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent);
parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string);
} else {
// semantic, in idToken.string
parseContext.handleSemantic(idToken.loc, qualifier, *idToken.string);

View File

@@ -2523,7 +2523,7 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TQualifier& quali
// 'desc' is the type# part.
//
void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString* profile,
const glslang::TString& desc, int subComponent)
const glslang::TString& desc, int subComponent, const glslang::TString* spaceDesc)
{
if (profile != nullptr)
warn(loc, "ignoring shader_profile", "register", "");
@@ -2555,6 +2555,28 @@ void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifi
warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]);
break;
}
// space
unsigned int setNumber;
const auto crackSpace = [&]() {
const int spaceLen = 5;
if (spaceDesc->size() < spaceLen + 1)
return false;
if (spaceDesc->compare(0, spaceLen, "space") != 0)
return false;
if (! isdigit((*spaceDesc)[spaceLen]))
return false;
setNumber = atoi(spaceDesc->substr(spaceLen, spaceDesc->size()).c_str());
return true;
};
if (spaceDesc) {
if (! crackSpace()) {
error(loc, "expected spaceN", "register", "");
return;
}
qualifier.layoutSet = setNumber;
}
}
//

View File

@@ -102,7 +102,7 @@ public:
void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location,
const glslang::TString* component);
void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc,
int subComponent);
int subComponent, const glslang::TString*);
TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);