diff options
Diffstat (limited to '3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp')
-rw-r--r-- | 3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp | 115 |
1 files changed, 111 insertions, 4 deletions
diff --git a/3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp b/3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp index 69c1e37f869..7b0365f4f92 100644 --- a/3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp +++ b/3rdparty/bgfx/3rdparty/glslang/hlsl/hlslScanContext.cpp @@ -47,7 +47,6 @@ #include "../glslang/MachineIndependent/ParseHelper.h" #include "hlslScanContext.h" #include "hlslTokens.h" -//#include "Scan.h" // preprocessor includes #include "../glslang/MachineIndependent/preprocessor/PpContext.h" @@ -82,6 +81,7 @@ struct str_hash // After a single process-level initialization, this is read only and thread safe std::unordered_map<const char*, glslang::EHlslTokenClass, str_hash, str_eq>* KeywordMap = nullptr; std::unordered_set<const char*, str_hash, str_eq>* ReservedSet = nullptr; +std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>* SemanticMap = nullptr; }; @@ -118,6 +118,8 @@ void HlslScanContext::fillInKeywordMap() (*KeywordMap)["out"] = EHTokOut; (*KeywordMap)["inout"] = EHTokInOut; (*KeywordMap)["layout"] = EHTokLayout; + (*KeywordMap)["globallycoherent"] = EHTokGloballyCoherent; + (*KeywordMap)["inline"] = EHTokInline; (*KeywordMap)["point"] = EHTokPoint; (*KeywordMap)["line"] = EHTokLine; @@ -129,6 +131,9 @@ void HlslScanContext::fillInKeywordMap() (*KeywordMap)["LineStream"] = EHTokLineStream; (*KeywordMap)["TriangleStream"] = EHTokTriangleStream; + (*KeywordMap)["InputPatch"] = EHTokInputPatch; + (*KeywordMap)["OutputPatch"] = EHTokOutputPatch; + (*KeywordMap)["Buffer"] = EHTokBuffer; (*KeywordMap)["vector"] = EHTokVector; (*KeywordMap)["matrix"] = EHTokMatrix; @@ -316,10 +321,19 @@ 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)["class"] = EHTokClass; (*KeywordMap)["struct"] = EHTokStruct; (*KeywordMap)["cbuffer"] = EHTokCBuffer; (*KeywordMap)["tbuffer"] = EHTokTBuffer; (*KeywordMap)["typedef"] = EHTokTypedef; + (*KeywordMap)["this"] = EHTokThis; (*KeywordMap)["true"] = EHTokBoolConstant; (*KeywordMap)["false"] = EHTokBoolConstant; @@ -343,7 +357,6 @@ void HlslScanContext::fillInKeywordMap() ReservedSet->insert("auto"); ReservedSet->insert("catch"); ReservedSet->insert("char"); - ReservedSet->insert("class"); ReservedSet->insert("const_cast"); ReservedSet->insert("enum"); ReservedSet->insert("explicit"); @@ -362,7 +375,6 @@ void HlslScanContext::fillInKeywordMap() ReservedSet->insert("sizeof"); ReservedSet->insert("static_cast"); ReservedSet->insert("template"); - ReservedSet->insert("this"); ReservedSet->insert("throw"); ReservedSet->insert("try"); ReservedSet->insert("typename"); @@ -370,6 +382,73 @@ void HlslScanContext::fillInKeywordMap() ReservedSet->insert("unsigned"); ReservedSet->insert("using"); ReservedSet->insert("virtual"); + + SemanticMap = new std::unordered_map<const char*, glslang::TBuiltInVariable, str_hash, str_eq>; + + // in DX9, all outputs had to have a semantic associated with them, that was either consumed + // by the system or was a specific register assignment + // in DX10+, only semantics with the SV_ prefix have any meaning beyond decoration + // Fxc will only accept DX9 style semantics in compat mode + // Also, in DX10 if a SV value is present as the input of a stage, but isn't appropriate for that + // stage, it would just be ignored as it is likely there as part of an output struct from one stage + // to the next + bool bParseDX9 = false; + if (bParseDX9) { + (*SemanticMap)["PSIZE"] = EbvPointSize; + (*SemanticMap)["FOG"] = EbvFogFragCoord; + (*SemanticMap)["DEPTH"] = EbvFragDepth; + (*SemanticMap)["VFACE"] = EbvFace; + (*SemanticMap)["VPOS"] = EbvFragCoord; + } + + (*SemanticMap)["SV_POSITION"] = EbvPosition; + (*SemanticMap)["SV_CLIPDISTANCE"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE0"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE1"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE2"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE3"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE4"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE5"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE6"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE7"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE8"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE9"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE10"] = EbvClipDistance; + (*SemanticMap)["SV_CLIPDISTANCE11"] = EbvClipDistance; + (*SemanticMap)["SV_CULLDISTANCE"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE0"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE1"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE2"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE3"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE4"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE5"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE6"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE7"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE8"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE9"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE10"] = EbvCullDistance; + (*SemanticMap)["SV_CULLDISTANCE11"] = EbvCullDistance; + (*SemanticMap)["SV_VERTEXID"] = EbvVertexIndex; + (*SemanticMap)["SV_VIEWPORTARRAYINDEX"] = EbvViewportIndex; + (*SemanticMap)["SV_TESSFACTOR"] = EbvTessLevelOuter; + (*SemanticMap)["SV_SAMPLEINDEX"] = EbvSampleId; + (*SemanticMap)["SV_RENDERTARGETARRAYINDEX"] = EbvLayer; + (*SemanticMap)["SV_PRIMITIVEID"] = EbvPrimitiveId; + (*SemanticMap)["SV_OUTPUTCONTROLPOINTID"] = EbvInvocationId; + (*SemanticMap)["SV_ISFRONTFACE"] = EbvFace; + (*SemanticMap)["SV_INSTANCEID"] = EbvInstanceIndex; + (*SemanticMap)["SV_INSIDETESSFACTOR"] = EbvTessLevelInner; + (*SemanticMap)["SV_GSINSTANCEID"] = EbvInvocationId; + (*SemanticMap)["SV_DISPATCHTHREADID"] = EbvGlobalInvocationId; + (*SemanticMap)["SV_GROUPTHREADID"] = EbvLocalInvocationId; + (*SemanticMap)["SV_GROUPINDEX"] = EbvLocalInvocationIndex; + (*SemanticMap)["SV_GROUPID"] = EbvWorkGroupId; + (*SemanticMap)["SV_DOMAINLOCATION"] = EbvTessCoord; + (*SemanticMap)["SV_DEPTH"] = EbvFragDepth; + (*SemanticMap)["SV_COVERAGE"] = EbvSampleMask; + (*SemanticMap)["SV_DEPTHGREATEREQUAL"] = EbvFragDepthGreater; + (*SemanticMap)["SV_DEPTHLESSEQUAL"] = EbvFragDepthLesser; + (*SemanticMap)["SV_STENCILREF"] = EbvStencilRef; } void HlslScanContext::deleteKeywordMap() @@ -378,15 +457,26 @@ void HlslScanContext::deleteKeywordMap() KeywordMap = nullptr; delete ReservedSet; ReservedSet = nullptr; + delete SemanticMap; + SemanticMap = nullptr; } -// Wrapper for tokenizeClass()"] = to get everything inside the token. +// Wrapper for tokenizeClass() to get everything inside the token. void HlslScanContext::tokenize(HlslToken& token) { EHlslTokenClass tokenClass = tokenizeClass(token); token.tokenClass = tokenClass; } +glslang::TBuiltInVariable HlslScanContext::mapSemantic(const char* upperCase) +{ + auto it = SemanticMap->find(upperCase); + if (it != SemanticMap->end()) + return it->second; + else + return glslang::EbvNone; +} + // // Fill in token information for the next token, except for the token class. // Returns the enum value of the token class of the next token found. @@ -460,6 +550,8 @@ EHlslTokenClass HlslScanContext::tokenizeClass(HlslToken& token) case PpAtomDecrement: return EHTokDecOp; case PpAtomIncrement: return EHTokIncOp; + case PpAtomColonColon: return EHTokColonColon; + case PpAtomConstInt: parserToken->i = ppToken.ival; return EHTokIntConstant; case PpAtomConstUint: parserToken->i = ppToken.ival; return EHTokUintConstant; case PpAtomConstFloat: parserToken->d = ppToken.dval; return EHTokFloatConstant; @@ -524,6 +616,8 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier() case EHTokInOut: case EHTokPrecise: case EHTokLayout: + case EHTokGloballyCoherent: + case EHTokInline: return keyword; // primitive types @@ -540,6 +634,11 @@ EHlslTokenClass HlslScanContext::tokenizeIdentifier() case EHTokTriangleStream: return keyword; + // Tessellation patches + case EHTokInputPatch: + case EHTokOutputPatch: + return keyword; + case EHTokBuffer: case EHTokVector: case EHTokMatrix: @@ -714,13 +813,21 @@ 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, ... + case EHTokClass: case EHTokStruct: case EHTokTypedef: case EHTokCBuffer: case EHTokTBuffer: + case EHTokThis: return keyword; case EHTokBoolConstant: |