HLSL: Implement the register production.
This commit is contained in:
@@ -2521,10 +2521,10 @@ void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
|
||||
}
|
||||
|
||||
// post_decls
|
||||
// : COLON semantic // optional
|
||||
// COLON PACKOFFSET LEFT_PAREN ... RIGHT_PAREN // optional
|
||||
// COLON REGISTER // optional
|
||||
// annotations // optional
|
||||
// : COLON semantic // optional
|
||||
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
|
||||
// COLON REGISTER LEFT_PAREN [shader_profile,] Type# RIGHT_PAREN // optional
|
||||
// annotations // optional
|
||||
//
|
||||
void HlslGrammar::acceptPostDecls(TType& type)
|
||||
{
|
||||
@@ -2533,6 +2533,7 @@ void HlslGrammar::acceptPostDecls(TType& type)
|
||||
if (acceptTokenClass(EHTokColon)) {
|
||||
HlslToken idToken;
|
||||
if (acceptTokenClass(EHTokPackOffset)) {
|
||||
// PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN
|
||||
if (! acceptTokenClass(EHTokLeftParen)) {
|
||||
expected("(");
|
||||
return;
|
||||
@@ -2558,23 +2559,31 @@ void HlslGrammar::acceptPostDecls(TType& type)
|
||||
expected("semantic or packoffset or register");
|
||||
return;
|
||||
} else if (*idToken.string == "register") {
|
||||
// REGISTER LEFT_PAREN [shader_profile,] Type# RIGHT_PAREN
|
||||
if (! acceptTokenClass(EHTokLeftParen)) {
|
||||
expected("(");
|
||||
return;
|
||||
}
|
||||
acceptTokenClass(EHTokIdentifier);
|
||||
acceptTokenClass(EHTokComma);
|
||||
acceptTokenClass(EHTokIdentifier);
|
||||
acceptTokenClass(EHTokLeftBracket);
|
||||
if (peekTokenClass(EHTokIntConstant))
|
||||
advanceToken();
|
||||
acceptTokenClass(EHTokRightBracket);
|
||||
HlslToken registerDesc;
|
||||
if (! acceptIdentifier(registerDesc)) {
|
||||
expected("register number description");
|
||||
return;
|
||||
}
|
||||
HlslToken profile;
|
||||
if (acceptTokenClass(EHTokComma)) {
|
||||
// then we didn't really see the registerDesc yet, it was
|
||||
// actually the profile
|
||||
profile = registerDesc;
|
||||
if (! acceptIdentifier(registerDesc)) {
|
||||
expected("register number description");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (! acceptTokenClass(EHTokRightParen)) {
|
||||
expected(")");
|
||||
break;
|
||||
}
|
||||
// TODO: process the register information
|
||||
// b2 means buffer 2
|
||||
parseContext.handleRegister(registerDesc.loc, type, profile.string, *registerDesc.string);
|
||||
} else {
|
||||
// semantic, in idToken.string
|
||||
parseContext.handleSemantic(type, *idToken.string);
|
||||
|
||||
@@ -2135,7 +2135,7 @@ void HlslParseContext::handleSemantic(TType& type, const TString& semantic)
|
||||
}
|
||||
|
||||
//
|
||||
// Handle seeing something like ": packoffset( c[Subcomponent][.component] )"
|
||||
// Handle seeing something like "PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN"
|
||||
//
|
||||
// 'location' has the "c[Subcomponent]" part.
|
||||
// 'component' points to the "component" part, or nullptr if not present.
|
||||
@@ -2155,7 +2155,7 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, cons
|
||||
}
|
||||
|
||||
type.getQualifier().layoutOffset = 16 * atoi(location.substr(1, location.size()).c_str());
|
||||
if (component) {
|
||||
if (component != nullptr) {
|
||||
int componentOffset = 0;
|
||||
switch ((*component)[0]) {
|
||||
case 'x': componentOffset = 0; break;
|
||||
@@ -2174,6 +2174,41 @@ void HlslParseContext::handlePackOffset(const TSourceLoc& loc, TType& type, cons
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle seeing something like "REGISTER LEFT_PAREN [shader_profile,] Type# RIGHT_PAREN"
|
||||
//
|
||||
// 'profile' points to the shader_profile part, or nullptr if not present.
|
||||
// 'desc' is the type# part.
|
||||
//
|
||||
void HlslParseContext::handleRegister(const TSourceLoc& loc, TType& type, const glslang::TString* profile,
|
||||
const glslang::TString& desc)
|
||||
{
|
||||
if (profile != nullptr)
|
||||
warn(loc, "ignoring shader_profile", "register", "");
|
||||
|
||||
if (desc.size() < 2) {
|
||||
error(loc, "expected register type and number", "register", "");
|
||||
return;
|
||||
}
|
||||
|
||||
if (! isdigit(desc[1])) {
|
||||
error(loc, "expected register number after register type", "register", "");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (desc[0]) {
|
||||
case 'b':
|
||||
case 't':
|
||||
case 'c':
|
||||
case 's':
|
||||
type.getQualifier().layoutBinding = atoi(desc.substr(1, desc.size()).c_str());
|
||||
break;
|
||||
default:
|
||||
warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Same error message for all places assignments don't work.
|
||||
//
|
||||
|
||||
@@ -96,6 +96,7 @@ public:
|
||||
TFunction* handleConstructorCall(const TSourceLoc&, const TType&);
|
||||
void handleSemantic(TType& type, const TString& semantic);
|
||||
void handlePackOffset(const TSourceLoc&, TType& type, const glslang::TString& location, const glslang::TString* component);
|
||||
void handleRegister(const TSourceLoc&, TType& type, const glslang::TString* profile, const glslang::TString& desc);
|
||||
|
||||
TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user