HLSL: implement 4 (of 6) structuredbuffer types

This is a partial implemention of structurebuffers supporting:

* structured buffer types of:
*   StructuredBuffer
*   RWStructuredBuffer
*   ByteAddressBuffer
*   RWByteAddressBuffer

* Atomic operations on RWByteAddressBuffer

* Load/Load[234], Store/Store[234], GetDimensions methods (where allowed by type)

* globallycoherent flag

But NOT yet supporting:

* AppendStructuredBuffer / ConsumeStructuredBuffer types
* IncrementCounter/DecrementCounter methods

Please note: the stride returned by GetDimensions is as calculated by glslang for std430,
and may not match other environments in all cases.
This commit is contained in:
steve-lunarg
2017-02-12 17:50:28 -07:00
parent c8aed91524
commit 5da1f038d8
22 changed files with 3993 additions and 37 deletions

View File

@@ -406,6 +406,27 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node, TIntermNode*& node2)
}
}
TString* blockName = idToken.string;
// For structbuffers, we couldn't create the block type while accepting the
// template type, because we need the identifier name. Now that we have that,
// we can create the buffer type.
// TODO: how to determine this without looking for implicit array sizes?
if (variableType.getBasicType() == EbtBlock) {
const int memberCount = variableType.getStruct()->size();
assert(memberCount > 0);
TType* contentType = (*variableType.getStruct())[memberCount-1].type;
// Set the field name and qualifier from the declaration, now that we know it.
if (contentType->isRuntimeSizedArray()) {
contentType->getQualifier() = variableType.getQualifier();
blockName = nullptr; // this will be an anonymous block...
contentType->setFieldName(*idToken.string); // field name is declaration name
variableType.setTypeName(*idToken.string);
}
}
// Hand off the actual declaration
// TODO: things scoped within an annotation need their own name space;
@@ -414,7 +435,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& node, TIntermNode*& node2)
if (typedefDecl)
parseContext.declareTypedef(idToken.loc, *idToken.string, variableType);
else if (variableType.getBasicType() == EbtBlock)
parseContext.declareBlock(idToken.loc, variableType, idToken.string);
parseContext.declareBlock(idToken.loc, variableType, blockName);
else {
if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) {
// this isn't really an individual variable, but a member of the $Global buffer
@@ -533,8 +554,11 @@ bool HlslGrammar::acceptFullySpecifiedType(TType& type)
qualifier.layoutFormat = type.getQualifier().layoutFormat;
qualifier.precision = type.getQualifier().precision;
if (type.getQualifier().storage == EvqVaryingOut)
if (type.getQualifier().storage == EvqVaryingOut ||
type.getQualifier().storage == EvqBuffer) {
qualifier.storage = type.getQualifier().storage;
qualifier.readonly = type.getQualifier().readonly;
}
type.getQualifier() = qualifier;
}
@@ -609,6 +633,9 @@ bool HlslGrammar::acceptQualifier(TQualifier& qualifier)
if (! acceptLayoutQualifierList(qualifier))
return false;
continue;
case EHTokGloballyCoherent:
qualifier.coherent = true;
break;
// GS geometries: these are specified on stage input variables, and are an error (not verified here)
// for output variables.
@@ -1246,11 +1273,19 @@ bool HlslGrammar::acceptType(TType& type)
return acceptTextureType(type);
break;
case EHTokAppendStructuredBuffer:
case EHTokByteAddressBuffer:
case EHTokConsumeStructuredBuffer:
case EHTokRWByteAddressBuffer:
case EHTokRWStructuredBuffer:
case EHTokStructuredBuffer:
return acceptStructBufferType(type);
break;
case EHTokStruct:
case EHTokCBuffer:
case EHTokTBuffer:
return acceptStruct(type);
break;
case EHTokIdentifier:
// An identifier could be for a user-defined type.
@@ -1783,6 +1818,93 @@ bool HlslGrammar::acceptStruct(TType& type)
return true;
}
// struct_buffer
// : APPENDSTRUCTUREDBUFFER
// | BYTEADDRESSBUFFER
// | CONSUMESTRUCTUREDBUFFER
// | RWBYTEADDRESSBUFFER
// | RWSTRUCTUREDBUFFER
// | STRUCTUREDBUFFER
bool HlslGrammar::acceptStructBufferType(TType& type)
{
const EHlslTokenClass structBuffType = peek();
// TODO: globallycoherent
bool hasTemplateType = true;
bool readonly = false;
TStorageQualifier storage = EvqBuffer;
switch (structBuffType) {
case EHTokAppendStructuredBuffer:
unimplemented("AppendStructuredBuffer");
return false;
case EHTokByteAddressBuffer:
hasTemplateType = false;
readonly = true;
break;
case EHTokConsumeStructuredBuffer:
unimplemented("ConsumeStructuredBuffer");
return false;
case EHTokRWByteAddressBuffer:
hasTemplateType = false;
break;
case EHTokRWStructuredBuffer:
break;
case EHTokStructuredBuffer:
readonly = true;
break;
default:
return false; // not a structure buffer type
}
advanceToken(); // consume the structure keyword
// type on which this StructedBuffer is templatized. E.g, StructedBuffer<MyStruct> ==> MyStruct
TType* templateType = new TType;
if (hasTemplateType) {
if (! acceptTokenClass(EHTokLeftAngle)) {
expected("left angle bracket");
return false;
}
if (! acceptType(*templateType)) {
expected("type");
return false;
}
if (! acceptTokenClass(EHTokRightAngle)) {
expected("right angle bracket");
return false;
}
} else {
// byte address buffers have no explicit type.
TType uintType(EbtUint, storage);
templateType->shallowCopy(uintType);
}
// Create an unsized array out of that type.
// TODO: does this work if it's already an array type?
TArraySizes unsizedArray;
unsizedArray.addInnerSize(UnsizedArraySize);
templateType->newArraySizes(unsizedArray);
templateType->getQualifier().storage = storage;
templateType->getQualifier().readonly = readonly;
// Create block type. TODO: hidden internal uint member when needed
TTypeList* blockStruct = new TTypeList;
TTypeLoc member = { templateType, token.loc };
blockStruct->push_back(member);
TType blockType(blockStruct, "", templateType->getQualifier());
// It's not until we see the name during declaration that we can set the
// field name. That happens in HlslGrammar::acceptDeclaration.
type.shallowCopy(blockType);
return true;
}
// struct_declaration_list
// : struct_declaration SEMI_COLON struct_declaration SEMI_COLON ...
//

View File

@@ -83,6 +83,7 @@ namespace glslang {
bool acceptAnnotations(TQualifier&);
bool acceptSamplerType(TType&);
bool acceptTextureType(TType&);
bool acceptStructBufferType(TType&);
bool acceptStruct(TType&);
bool acceptStructDeclarationList(TTypeList*&);
bool acceptFunctionParameters(TFunction&);

View File

@@ -790,6 +790,61 @@ TIntermTyped* HlslParseContext::handleUnaryMath(const TSourceLoc& loc, const cha
return childNode;
}
//
// Return true if the name is a sampler method
//
bool HlslParseContext::isSamplerMethod(const TString& name) const
{
return
name == "CalculateLevelOfDetail" ||
name == "CalculateLevelOfDetailUnclamped" ||
name == "Gather" ||
name == "GatherRed" ||
name == "GatherGreen" ||
name == "GatherBlue" ||
name == "GatherAlpha" ||
name == "GatherCmp" ||
name == "GatherCmpRed" ||
name == "GatherCmpGreen" ||
name == "GatherCmpBlue" ||
name == "GatherCmpAlpha" ||
name == "GetDimensions" ||
name == "GetSamplePosition" ||
name == "Load" ||
name == "Sample" ||
name == "SampleBias" ||
name == "SampleCmp" ||
name == "SampleCmpLevelZero" ||
name == "SampleGrad" ||
name == "SampleLevel";
}
//
// Return true if the name is a struct buffer method
//
bool HlslParseContext::isStructBufferMethod(const TString& name) const
{
return
name == "GetDimensions" ||
name == "Load" ||
name == "Load2" ||
name == "Load3" ||
name == "Load4" ||
name == "Store" ||
name == "Store2" ||
name == "Store3" ||
name == "Store4" ||
name == "InterlockedAdd" ||
name == "InterlockedAnd" ||
name == "InterlockedCompareExchange" ||
name == "InterlockedCompareStore" ||
name == "InterlockedExchange" ||
name == "InterlockedMax" ||
name == "InterlockedMin" ||
name == "InterlockedOr" ||
name == "InterlockedXor";
}
//
// Handle seeing a base.field dereference in the grammar.
//
@@ -804,35 +859,18 @@ TIntermTyped* HlslParseContext::handleDotDereference(const TSourceLoc& loc, TInt
//
if (field == "length") {
return intermediate.addMethod(base, TType(EbtInt), &field, loc);
} else if (field == "CalculateLevelOfDetail" ||
field == "CalculateLevelOfDetailUnclamped" ||
field == "Gather" ||
field == "GatherRed" ||
field == "GatherGreen" ||
field == "GatherBlue" ||
field == "GatherAlpha" ||
field == "GatherCmp" ||
field == "GatherCmpRed" ||
field == "GatherCmpGreen" ||
field == "GatherCmpBlue" ||
field == "GatherCmpAlpha" ||
field == "GetDimensions" ||
field == "GetSamplePosition" ||
field == "Load" ||
field == "Sample" ||
field == "SampleBias" ||
field == "SampleCmp" ||
field == "SampleCmpLevelZero" ||
field == "SampleGrad" ||
field == "SampleLevel") {
// If it's not a method on a sampler object, we fall through in case it is a struct member.
if (base->getType().getBasicType() == EbtSampler) {
const TSampler& sampler = base->getType().getSampler();
if (! sampler.isPureSampler()) {
const int vecSize = sampler.isShadow() ? 1 : 4; // TODO: handle arbitrary sample return sizes
return intermediate.addMethod(base, TType(sampler.type, EvqTemporary, vecSize), &field, loc);
}
} else if (isSamplerMethod(field) && base->getType().getBasicType() == EbtSampler) {
// If it's not a method on a sampler object, we fall through to let other objects have a go.
const TSampler& sampler = base->getType().getSampler();
if (! sampler.isPureSampler()) {
const int vecSize = sampler.isShadow() ? 1 : 4; // TODO: handle arbitrary sample return sizes
return intermediate.addMethod(base, TType(sampler.type, EvqTemporary, vecSize), &field, loc);
}
} else if (isStructBufferMethod(field) &&
base->getType().isRuntimeSizedArray() &&
(base->getQualifier().storage == EvqUniform || base->getQualifier().storage == EvqBuffer)) {
TType retType(base->getType(), 0);
return intermediate.addMethod(base, retType, &field, loc);
} else if (field == "Append" ||
field == "RestartStrip") {
// We cannot check the type here: it may be sanitized if we're not compiling a geometry shader, but
@@ -2236,6 +2274,236 @@ TIntermAggregate* HlslParseContext::handleSamplerTextureCombine(const TSourceLoc
return txcombine;
}
//
// Decompose structure buffer methods into AST
//
void HlslParseContext::decomposeStructBufferMethods(const TSourceLoc& loc, TIntermTyped*& node, TIntermNode* arguments)
{
if (!node || !node->getAsOperator())
return;
const TOperator op = node->getAsOperator()->getOp();
TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
TIntermTyped* argArray = argAggregate ? argAggregate->getSequence()[0]->getAsTyped() : nullptr; // array
// Bail out if not a block method
if (argArray == nullptr || !argArray->getType().isRuntimeSizedArray())
return;
switch (op) {
case EOpMethodLoad:
{
TIntermTyped* argIndex = argAggregate->getSequence()[1]->getAsTyped(); // index
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself.
const bool isByteAddressBuffer = (argArray->getBasicType() == EbtUint);
if (isByteAddressBuffer)
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex, intermediate.addConstantUnion(2, loc, true),
loc, TType(EbtInt));
// Index into the array to find the item being loaded.
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
node = intermediate.addIndex(idxOp, argArray, argIndex, loc);
const TType derefType(argArray->getType(), 0);
node->setType(derefType);
}
break;
case EOpMethodLoad2:
case EOpMethodLoad3:
case EOpMethodLoad4:
{
TIntermTyped* argIndex = argAggregate->getSequence()[1]->getAsTyped(); // index
TOperator constructOp = EOpNull;
int size = 0;
switch (op) {
case EOpMethodLoad2: size = 2; constructOp = EOpConstructVec2; break;
case EOpMethodLoad3: size = 3; constructOp = EOpConstructVec3; break;
case EOpMethodLoad4: size = 4; constructOp = EOpConstructVec4; break;
default: assert(0);
}
TIntermTyped* body = nullptr;
// First, we'll store the address in a variable to avoid multiple shifts
// (we must convert the byte address to an item address)
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
intermediate.addConstantUnion(2, loc, true), loc, TType(EbtInt));
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
TIntermTyped* vec = nullptr;
// These are only valid on (rw)byteaddressbuffers, so we can always perform the >>2
// address conversion.
for (int idx=0; idx<size; ++idx) {
TIntermTyped* offsetIdx = byteAddrIdxVar;
// add index offset
if (idx != 0)
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx, intermediate.addConstantUnion(idx, loc, true),
loc, TType(EbtInt));
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
vec = intermediate.growAggregate(vec, intermediate.addIndex(idxOp, argArray, offsetIdx, loc));
}
vec->setType(TType(argArray->getBasicType(), EvqTemporary, size));
vec->getAsAggregate()->setOperator(constructOp);
body = intermediate.growAggregate(body, vec);
body->setType(vec->getType());
body->getAsAggregate()->setOperator(EOpSequence);
node = body;
}
break;
case EOpMethodStore:
case EOpMethodStore2:
case EOpMethodStore3:
case EOpMethodStore4:
{
TIntermTyped* argIndex = argAggregate->getSequence()[1]->getAsTyped(); // address
TIntermTyped* argValue = argAggregate->getSequence()[2]->getAsTyped(); // value
// Index into the array to find the item being loaded.
// Byte address buffers index in bytes (only multiples of 4 permitted... not so much a byte address
// buffer then, but that's what it calls itself.
int size = 0;
switch (op) {
case EOpMethodStore: size = 1; break;
case EOpMethodStore2: size = 2; break;
case EOpMethodStore3: size = 3; break;
case EOpMethodStore4: size = 4; break;
default: assert(0);
}
TIntermAggregate* body = nullptr;
// First, we'll store the address in a variable to avoid multiple shifts
// (we must convert the byte address to an item address)
TIntermTyped* byteAddrIdx = intermediate.addBinaryNode(EOpRightShift, argIndex,
intermediate.addConstantUnion(2, loc, true), loc, TType(EbtInt));
TVariable* byteAddrSym = makeInternalVariable("byteAddrTemp", TType(EbtInt, EvqTemporary));
TIntermTyped* byteAddrIdxVar = intermediate.addSymbol(*byteAddrSym, loc);
body = intermediate.growAggregate(body, intermediate.addAssign(EOpAssign, byteAddrIdxVar, byteAddrIdx, loc));
for (int idx=0; idx<size; ++idx) {
TIntermTyped* offsetIdx = byteAddrIdxVar;
TIntermTyped* idxConst = intermediate.addConstantUnion(idx, loc, true);
// add index offset
if (idx != 0)
offsetIdx = intermediate.addBinaryNode(EOpAdd, offsetIdx, idxConst, loc, TType(EbtInt));
const TOperator idxOp = (offsetIdx->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
TIntermTyped* lValue = intermediate.addIndex(idxOp, argArray, offsetIdx, loc);
TIntermTyped* rValue = (size == 1) ? argValue :
intermediate.addIndex(EOpIndexDirect, argValue, idxConst, loc);
TIntermTyped* assign = intermediate.addAssign(EOpAssign, lValue, rValue, loc);
body = intermediate.growAggregate(body, assign);
}
body->setOperator(EOpSequence);
node = body;
}
break;
case EOpMethodGetDimensions:
{
const int numArgs = argAggregate->getSequence().size();
TIntermTyped* argNumItems = argAggregate->getSequence()[1]->getAsTyped(); // out num items
TIntermTyped* argStride = numArgs > 2 ? argAggregate->getSequence()[2]->getAsTyped() : nullptr; // out stride
TIntermAggregate* body = nullptr;
// Length output:
if (argArray->getType().isRuntimeSizedArray()) {
TIntermTyped* lengthCall = intermediate.addBuiltInFunctionCall(loc, EOpArrayLength, true, argArray,
argNumItems->getType());
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems, lengthCall, loc);
body = intermediate.growAggregate(body, assign, loc);
} else {
const int length = argArray->getType().getOuterArraySize();
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argNumItems, intermediate.addConstantUnion(length, loc, true), loc);
body = intermediate.growAggregate(body, assign, loc);
}
// Stride output:
if (argStride != nullptr) {
int size;
int stride;
intermediate.getBaseAlignment(argArray->getType(), size, stride, false,
argArray->getType().getQualifier().layoutMatrix == ElmRowMajor);
TIntermTyped* assign = intermediate.addAssign(EOpAssign, argStride, intermediate.addConstantUnion(stride, loc, true), loc);
body = intermediate.growAggregate(body, assign);
}
body->setOperator(EOpSequence);
node = body;
}
break;
case EOpInterlockedAdd:
case EOpInterlockedAnd:
case EOpInterlockedExchange:
case EOpInterlockedMax:
case EOpInterlockedMin:
case EOpInterlockedOr:
case EOpInterlockedXor:
case EOpInterlockedCompareExchange:
case EOpInterlockedCompareStore:
{
// We'll replace the first argument with the block dereference, and let
// downstream decomposition handle the rest.
TIntermSequence& sequence = argAggregate->getSequence();
TIntermTyped* argIndex = sequence[1]->getAsTyped(); // index
argIndex = intermediate.addBinaryNode(EOpRightShift, argIndex, intermediate.addConstantUnion(2, loc, true),
loc, TType(EbtInt));
const TOperator idxOp = (argIndex->getQualifier().storage == EvqConst) ? EOpIndexDirect : EOpIndexIndirect;
TIntermTyped* element = intermediate.addIndex(idxOp, argArray, argIndex, loc);
const TType derefType(argArray->getType(), 0);
element->setType(derefType);
// Replace the numeric byte offset parameter with array reference.
sequence[1] = element;
sequence.erase(sequence.begin(), sequence.begin()+1);
}
break;
default:
break; // most pass through unchanged
}
}
//
// Decompose DX9 and DX10 sample intrinsics & object methods into AST
//
@@ -2264,6 +2532,15 @@ void HlslParseContext::decomposeSampleMethods(const TSourceLoc& loc, TIntermType
const TOperator op = node->getAsOperator()->getOp();
const TIntermAggregate* argAggregate = arguments ? arguments->getAsAggregate() : nullptr;
// Bail out if not a sampler method
if (arguments != nullptr) {
if ((argAggregate != nullptr && argAggregate->getSequence()[0]->getAsTyped()->getBasicType() != EbtSampler))
return;
if (argAggregate == nullptr && arguments->getAsTyped()->getBasicType() != EbtSampler)
return;
}
switch (op) {
// **** DX9 intrinsics: ****
case EOpTexture:
@@ -3359,9 +3636,27 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct
//
// Find it in the symbol table.
//
const TFunction* fnCandidate;
const TFunction* fnCandidate = nullptr;
bool builtIn;
fnCandidate = findFunction(loc, *function, builtIn, arguments);
// TODO: this needs improvement: there's no way at present to look up a signature in
// the symbol table for an arbitrary type. This is a temporary hack until that ability exists.
// It will have false positives, since it doesn't check arg counts or types.
if (arguments && arguments->getAsAggregate()) {
if (arguments->getAsAggregate()->getSequence()[0]->getAsTyped()->getType().isRuntimeSizedArray()) {
if (isStructBufferMethod(function->getName())) {
const TString mangle = function->getName() + "(";
TSymbol* symbol = symbolTable.find(mangle, &builtIn);
if (symbol)
fnCandidate = symbol->getAsFunction();
}
}
}
if (fnCandidate == nullptr)
fnCandidate = findFunction(loc, *function, builtIn, arguments);
if (fnCandidate) {
// This is a declared function that might map to
// - a built-in operator,
@@ -3407,9 +3702,10 @@ TIntermTyped* HlslParseContext::handleFunctionCall(const TSourceLoc& loc, TFunct
// output conversions.
const TIntermTyped* fnNode = result;
decomposeIntrinsic(loc, result, arguments); // HLSL->AST intrinsic decompositions
decomposeSampleMethods(loc, result, arguments); // HLSL->AST sample method decompositions
decomposeGeometryMethods(loc, result, arguments); // HLSL->AST geometry method decompositions
decomposeStructBufferMethods(loc, result, arguments); // HLSL->AST struct buffer method decompositions
decomposeIntrinsic(loc, result, arguments); // HLSL->AST intrinsic decompositions
decomposeSampleMethods(loc, result, arguments); // HLSL->AST sample method decompositions
decomposeGeometryMethods(loc, result, arguments); // HLSL->AST geometry method decompositions
// Convert 'out' arguments. If it was a constant folded built-in, it won't be an aggregate anymore.
// Built-ins with a single argument aren't called with an aggregate, but they also don't have an output.

View File

@@ -84,6 +84,7 @@ public:
TIntermTyped* handleFunctionCall(const TSourceLoc&, TFunction*, TIntermTyped*);
void decomposeIntrinsic(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeSampleMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeStructBufferMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
void decomposeGeometryMethods(const TSourceLoc&, TIntermTyped*& node, TIntermNode* arguments);
TIntermTyped* handleLengthMethod(const TSourceLoc&, TFunction*, TIntermNode*);
void addInputArgumentConversions(const TFunction&, TIntermTyped*&);
@@ -243,6 +244,10 @@ protected:
void correctUniform(TQualifier& qualifier);
void clearUniformInputOutput(TQualifier& qualifier);
// Test method names
bool isSamplerMethod(const TString& name) const;
bool isStructBufferMethod(const TString& name) const;
// Pass through to base class after remembering builtin mappings.
using TParseContextBase::trackLinkage;
void trackLinkage(TSymbol& variable) override;

View File

@@ -850,6 +850,26 @@ void TBuiltInParseablesHlsl::initialize(int /*version*/, EProfile /*profile*/, c
{ "Append", "-", "-", "-", "-", EShLangGS },
{ "RestartStrip", "-", "-", "-", "-", EShLangGS },
// Methods for structurebuffers. TODO: wildcard type matching.
{ "Load", nullptr, nullptr, "-", "-", EShLangAll },
{ "Load2", nullptr, nullptr, "-", "-", EShLangAll },
{ "Load3", nullptr, nullptr, "-", "-", EShLangAll },
{ "Load4", nullptr, nullptr, "-", "-", EShLangAll },
{ "Store", nullptr, nullptr, "-", "-", EShLangAll },
{ "Store2", nullptr, nullptr, "-", "-", EShLangAll },
{ "Store3", nullptr, nullptr, "-", "-", EShLangAll },
{ "Store4", nullptr, nullptr, "-", "-", EShLangAll },
{ "GetDimensions", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedAdd", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedAnd", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedCompareExchange", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedCompareStore", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedExchange", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedMax", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedMin", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedOr", nullptr, nullptr, "-", "-", EShLangAll },
{ "InterlockedXor", nullptr, nullptr, "-", "-", EShLangAll },
// Mark end of list, since we want to avoid a range-based for, as some compilers don't handle it yet.
{ nullptr, nullptr, nullptr, nullptr, nullptr, 0 },
};
@@ -1144,6 +1164,15 @@ void TBuiltInParseablesHlsl::identifyBuiltIns(int /*version*/, EProfile /*profil
symbolTable.relateToOperator("CalculateLevelOfDetail", EOpMethodCalculateLevelOfDetail);
symbolTable.relateToOperator("CalculateLevelOfDetailUnclamped", EOpMethodCalculateLevelOfDetailUnclamped);
// Structure buffer methods (excluding associations already made above for texture methods w/ same name)
symbolTable.relateToOperator("Load2", EOpMethodLoad2);
symbolTable.relateToOperator("Load3", EOpMethodLoad3);
symbolTable.relateToOperator("Load4", EOpMethodLoad4);
symbolTable.relateToOperator("Store", EOpMethodStore);
symbolTable.relateToOperator("Store2", EOpMethodStore2);
symbolTable.relateToOperator("Store3", EOpMethodStore3);
symbolTable.relateToOperator("Store4", EOpMethodStore4);
// SM5 Texture methods
symbolTable.relateToOperator("GatherRed", EOpMethodGatherRed);
symbolTable.relateToOperator("GatherGreen", EOpMethodGatherGreen);

View File

@@ -118,6 +118,7 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["out"] = EHTokOut;
(*KeywordMap)["inout"] = EHTokInOut;
(*KeywordMap)["layout"] = EHTokLayout;
(*KeywordMap)["globallycoherent"] = EHTokGloballyCoherent;
(*KeywordMap)["point"] = EHTokPoint;
(*KeywordMap)["line"] = EHTokLine;
@@ -319,6 +320,13 @@ void HlslScanContext::fillInKeywordMap()
(*KeywordMap)["RWTexture3D"] = EHTokRWTexture3d;
(*KeywordMap)["RWBuffer"] = EHTokRWBuffer;
(*KeywordMap)["AppendStructuredBuffer"] = EHTokAppendStructuredBuffer;
(*KeywordMap)["ByteAddressBuffer"] = EHTokByteAddressBuffer;
(*KeywordMap)["ConsumeStructuredBuffer"] = EHTokConsumeStructuredBuffer;
(*KeywordMap)["RWByteAddressBuffer"] = EHTokRWByteAddressBuffer;
(*KeywordMap)["RWStructuredBuffer"] = EHTokRWStructuredBuffer;
(*KeywordMap)["StructuredBuffer"] = EHTokStructuredBuffer;
(*KeywordMap)["struct"] = EHTokStruct;
(*KeywordMap)["cbuffer"] = EHTokCBuffer;
(*KeywordMap)["tbuffer"] = EHTokTBuffer;
@@ -527,6 +535,7 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokInOut:
case EHTokPrecise:
case EHTokLayout:
case EHTokGloballyCoherent:
return keyword;
// primitive types
@@ -722,6 +731,12 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier()
case EHTokRWTexture2darray:
case EHTokRWTexture3d:
case EHTokRWBuffer:
case EHTokAppendStructuredBuffer:
case EHTokByteAddressBuffer:
case EHTokConsumeStructuredBuffer:
case EHTokRWByteAddressBuffer:
case EHTokRWStructuredBuffer:
case EHTokStructuredBuffer:
return keyword;
// variable, user type, ...

View File

@@ -65,6 +65,7 @@ enum EHlslTokenClass {
EHTokOut,
EHTokInOut,
EHTokLayout,
EHTokGloballyCoherent,
// primitive types
EHTokPoint,
@@ -256,6 +257,14 @@ enum EHlslTokenClass {
EHTokRWTexture3d,
EHTokRWBuffer,
// Structure buffer variants
EHTokAppendStructuredBuffer,
EHTokByteAddressBuffer,
EHTokConsumeStructuredBuffer,
EHTokRWByteAddressBuffer,
EHTokRWStructuredBuffer,
EHTokStructuredBuffer,
// variable, user type, ...
EHTokIdentifier,
EHTokTypeName,