HLSL: Add ConstantBuffer<T> syntax
Note: multi-dimension arrays of ConstantBuffer objects will go through uniform flattening.
This commit is contained in:
@@ -476,7 +476,8 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
|
||||
if (typedefDecl)
|
||||
parseContext.declareTypedef(idToken.loc, *fullName, variableType);
|
||||
else if (variableType.getBasicType() == EbtBlock) {
|
||||
parseContext.declareBlock(idToken.loc, variableType, fullName);
|
||||
parseContext.declareBlock(idToken.loc, variableType, fullName,
|
||||
variableType.isArray() ? &variableType.getArraySizes() : nullptr);
|
||||
parseContext.declareStructBufferCounter(idToken.loc, variableType, *fullName);
|
||||
} else {
|
||||
if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) {
|
||||
@@ -1364,6 +1365,9 @@ bool HlslGrammar::acceptType(TType& type, TIntermNode*& nodeList)
|
||||
return acceptStructBufferType(type);
|
||||
break;
|
||||
|
||||
case EHTokConstantBuffer:
|
||||
return acceptConstantBufferType(type);
|
||||
|
||||
case EHTokClass:
|
||||
case EHTokStruct:
|
||||
case EHTokCBuffer:
|
||||
@@ -1944,6 +1948,47 @@ bool HlslGrammar::acceptStruct(TType& type, TIntermNode*& nodeList)
|
||||
return deferredSuccess;
|
||||
}
|
||||
|
||||
// constantbuffer
|
||||
// : CONSTANTBUFFER LEFT_ANGLE type RIGHT_ANGLE
|
||||
bool HlslGrammar::acceptConstantBufferType(TType& type)
|
||||
{
|
||||
if (! acceptTokenClass(EHTokConstantBuffer))
|
||||
return false;
|
||||
|
||||
if (! acceptTokenClass(EHTokLeftAngle)) {
|
||||
expected("left angle bracket");
|
||||
return false;
|
||||
}
|
||||
|
||||
TType templateType;
|
||||
if (! acceptType(templateType)) {
|
||||
expected("type");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! acceptTokenClass(EHTokRightAngle)) {
|
||||
expected("right angle bracket");
|
||||
return false;
|
||||
}
|
||||
|
||||
TQualifier postDeclQualifier;
|
||||
postDeclQualifier.clear();
|
||||
postDeclQualifier.storage = EvqUniform;
|
||||
|
||||
if (templateType.isStruct()) {
|
||||
// Make a block from the type parsed as the template argument
|
||||
TTypeList* typeList = templateType.getWritableStruct();
|
||||
new(&type) TType(typeList, "", postDeclQualifier); // sets EbtBlock
|
||||
|
||||
type.getQualifier().storage = EvqUniform;
|
||||
|
||||
return true;
|
||||
} else {
|
||||
parseContext.error(token.loc, "non-structure type in ConstantBuffer", "", "");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// struct_buffer
|
||||
// : APPENDSTRUCTUREDBUFFER
|
||||
// | BYTEADDRESSBUFFER
|
||||
|
||||
@@ -87,6 +87,7 @@ namespace glslang {
|
||||
bool acceptSamplerType(TType&);
|
||||
bool acceptTextureType(TType&);
|
||||
bool acceptStructBufferType(TType&);
|
||||
bool acceptConstantBufferType(TType&);
|
||||
bool acceptStruct(TType&, TIntermNode*& nodeList);
|
||||
bool acceptStructDeclarationList(TTypeList*&, TIntermNode*& nodeList, TVector<TFunctionDeclarator>&);
|
||||
bool acceptMemberFunctionDefinition(TIntermNode*& nodeList, const TType&, const TString& memberName,
|
||||
|
||||
@@ -331,6 +331,7 @@ void HlslScanContext::fillInKeywordMap()
|
||||
(*KeywordMap)["class"] = EHTokClass;
|
||||
(*KeywordMap)["struct"] = EHTokStruct;
|
||||
(*KeywordMap)["cbuffer"] = EHTokCBuffer;
|
||||
(*KeywordMap)["ConstantBuffer"] = EHTokConstantBuffer;
|
||||
(*KeywordMap)["tbuffer"] = EHTokTBuffer;
|
||||
(*KeywordMap)["typedef"] = EHTokTypedef;
|
||||
(*KeywordMap)["this"] = EHTokThis;
|
||||
@@ -827,6 +828,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
|
||||
case EHTokStruct:
|
||||
case EHTokTypedef:
|
||||
case EHTokCBuffer:
|
||||
case EHTokConstantBuffer:
|
||||
case EHTokTBuffer:
|
||||
case EHTokThis:
|
||||
case EHTokNamespace:
|
||||
|
||||
@@ -275,6 +275,7 @@ enum EHlslTokenClass {
|
||||
EHTokTypedef,
|
||||
EHTokThis,
|
||||
EHTokNamespace,
|
||||
EHTokConstantBuffer,
|
||||
|
||||
// constant
|
||||
EHTokFloatConstant,
|
||||
|
||||
Reference in New Issue
Block a user