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

@ -23,7 +23,7 @@ gl_FragCoord origin is upper left
0:27 Constant: 0:27 Constant:
0:27 0 (const uint) 0:27 0 (const uint)
0:27 v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float) 0:27 v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float)
0:27 'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3}) 0:27 'anon@2' (layout(set=10 binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
0:27 Constant: 0:27 Constant:
0:27 0 (const uint) 0:27 0 (const uint)
0:27 v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float) 0:27 v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float)
@ -34,7 +34,7 @@ gl_FragCoord origin is upper left
0:? Linker Objects 0:? Linker Objects
0:? 'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1}) 0:? 'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1})
0:? 'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2}) 0:? 'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2})
0:? 'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3}) 0:? 'anon@2' (layout(set=10 binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
0:? 'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7}) 0:? 'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
@ -65,7 +65,7 @@ gl_FragCoord origin is upper left
0:27 Constant: 0:27 Constant:
0:27 0 (const uint) 0:27 0 (const uint)
0:27 v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float) 0:27 v3: direct index for structure (layout(column_major std140 ) uniform 4-component vector of float)
0:27 'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3}) 0:27 'anon@2' (layout(set=10 binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
0:27 Constant: 0:27 Constant:
0:27 0 (const uint) 0:27 0 (const uint)
0:27 v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float) 0:27 v4: direct index for structure (layout(column_major std430 offset=16 ) buffer 4-component vector of float)
@ -76,7 +76,7 @@ gl_FragCoord origin is upper left
0:? Linker Objects 0:? Linker Objects
0:? 'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1}) 0:? 'anon@0' (layout(column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v1})
0:? 'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2}) 0:? 'anon@1' (layout(column_major std430 ) buffer block{layout(column_major std430 ) buffer 4-component vector of float v2})
0:? 'anon@2' (layout(binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3}) 0:? 'anon@2' (layout(set=10 binding=2 column_major std140 ) uniform block{layout(column_major std140 ) uniform 4-component vector of float v3, layout(column_major std140 offset=20 ) uniform int i3})
0:? 'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7}) 0:? 'anon@3' (layout(binding=8 column_major std430 ) buffer block{layout(column_major std430 offset=16 ) buffer 4-component vector of float v4, layout(column_major std430 offset=48 ) buffer int i4, layout(column_major std430 offset=60 ) buffer float f1, layout(column_major std430 offset=64 ) buffer float f3, layout(column_major std430 offset=68 ) buffer float f4, layout(column_major std430 offset=72 ) buffer float f5, layout(column_major std430 ) buffer float f6, layout(column_major std430 ) buffer float f7})
// Module Version 10000 // Module Version 10000
@ -122,7 +122,7 @@ gl_FragCoord origin is upper left
MemberDecorate 28 0 Offset 0 MemberDecorate 28 0 Offset 0
MemberDecorate 28 1 Offset 20 MemberDecorate 28 1 Offset 20
Decorate 28 Block Decorate 28 Block
Decorate 30 DescriptorSet 0 Decorate 30 DescriptorSet 10
Decorate 30 Binding 2 Decorate 30 Binding 2
MemberDecorate 34 0 Offset 16 MemberDecorate 34 0 Offset 16
MemberDecorate 34 1 Offset 48 MemberDecorate 34 1 Offset 48

View File

@ -6,7 +6,7 @@ tbuffer {
float4 v2; float4 v2;
}; };
cbuffer cbufName : register(b2) { cbuffer cbufName : register(b2, space10) {
float4 v3; float4 v3;
int i3 : packoffset(c1.y); int i3 : packoffset(c1.y);
}; };

View File

@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1470" #define GLSLANG_REVISION "Overload400-PrecQual.1472"
#define GLSLANG_DATE "05-Sep-2016" #define GLSLANG_DATE "05-Sep-2016"

View File

@ -2591,11 +2591,11 @@ void HlslGrammar::acceptArraySpecifier(TArraySizes*& arraySizes)
} }
// post_decls // post_decls
// : COLON semantic // optional // : COLON semantic // optional
// COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional // COLON PACKOFFSET LEFT_PAREN c[Subcomponent][.component] RIGHT_PAREN // optional
// COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt RIGHT_PAREN // optional // COLON REGISTER LEFT_PAREN [shader_profile,] Type#[subcomp]opt (COMMA SPACEN)opt RIGHT_PAREN // optional
// COLON LAYOUT layout_qualifier_list // COLON LAYOUT layout_qualifier_list
// annotations // optional // annotations // optional
// //
void HlslGrammar::acceptPostDecls(TQualifier& qualifier) void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
{ {
@ -2632,7 +2632,8 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
expected("layout, semantic, packoffset, or register"); expected("layout, semantic, packoffset, or register");
return; return;
} else if (*idToken.string == "register") { } 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)) { if (! acceptTokenClass(EHTokLeftParen)) {
expected("("); expected("(");
return; return;
@ -2643,7 +2644,8 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
expected("register number description"); expected("register number description");
return; 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 // Then we didn't really see the registerDesc yet, it was
// actually the profile. Adjust... // actually the profile. Adjust...
profile = registerDesc; profile = registerDesc;
@ -2666,11 +2668,20 @@ void HlslGrammar::acceptPostDecls(TQualifier& qualifier)
break; break;
} }
} }
// (COMMA SPACEN)opt
HlslToken spaceDesc;
if (acceptTokenClass(EHTokComma)) {
if (! acceptIdentifier(spaceDesc)) {
expected ("space identifier");
return;
}
}
// RIGHT_PAREN
if (! acceptTokenClass(EHTokRightParen)) { if (! acceptTokenClass(EHTokRightParen)) {
expected(")"); expected(")");
break; break;
} }
parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent); parseContext.handleRegister(registerDesc.loc, qualifier, profile.string, *registerDesc.string, subComponent, spaceDesc.string);
} else { } else {
// semantic, in idToken.string // semantic, in idToken.string
parseContext.handleSemantic(idToken.loc, qualifier, *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. // 'desc' is the type# part.
// //
void HlslParseContext::handleRegister(const TSourceLoc& loc, TQualifier& qualifier, const glslang::TString* profile, 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) if (profile != nullptr)
warn(loc, "ignoring shader_profile", "register", ""); 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]); warn(loc, "ignoring unrecognized register type", "register", "%c", desc[0]);
break; 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, void handlePackOffset(const TSourceLoc&, TQualifier&, const glslang::TString& location,
const glslang::TString* component); const glslang::TString* component);
void handleRegister(const TSourceLoc&, TQualifier&, const glslang::TString* profile, const glslang::TString& desc, 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); TIntermAggregate* handleSamplerTextureCombine(const TSourceLoc& loc, TIntermTyped* argTex, TIntermTyped* argSampler);