Merge pull request #2271 from ben-clayton/fold-hlsl
Untangle build target cyclic dependencies (approach #2)
diff --git a/Test/hlsl.sample.dx9.frag b/Test/hlsl.sample.dx9.frag
index 2609419..ed82c52 100644
--- a/Test/hlsl.sample.dx9.frag
+++ b/Test/hlsl.sample.dx9.frag
@@ -3,7 +3,7 @@
sampler1D g_sam1D : register(t1);
sampler2D g_sam2D : register(t2);
sampler3D g_sam3D : register(t3);
-samplerCube g_samCube : register(t4);
+samplerCUBE g_samCube : register(t4);
struct PS_OUTPUT
{
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index 94c2dd5..5ac9824 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -1,3 +1,3 @@
// This header is generated by the make-revision script.
-#define GLSLANG_PATCH_LEVEL 3795
+#define GLSLANG_PATCH_LEVEL 3801
diff --git a/hlsl/hlslParseables.cpp b/hlsl/hlslParseables.cpp
index a63ecb6..ccc865e 100644
--- a/hlsl/hlslParseables.cpp
+++ b/hlsl/hlslParseables.cpp
@@ -56,18 +56,6 @@
namespace { // anonymous namespace functions
-const bool UseHlslTypes = true;
-
-const char* BaseTypeName(const char argOrder, const char* scalarName, const char* vecName, const char* matName)
-{
- switch (argOrder) {
- case 'S': return scalarName;
- case 'V': return vecName;
- case 'M': return matName;
- default: return "UNKNOWN_TYPE";
- }
-}
-
// arg order queries
bool IsSamplerType(const char argType) { return argType == 'S' || argType == 's'; }
bool IsArrayed(const char argOrder) { return argOrder == '@' || argOrder == '&' || argOrder == '#'; }
@@ -216,8 +204,7 @@
return 0; // none found.
}
-// Create and return a type name. This is done in GLSL, not HLSL conventions, until such
-// time as builtins are parsed using the HLSL parser.
+// Create and return a type name, using HLSL type conventions.
//
// order: S = scalar, V = vector, M = matrix
// argType: F = float, D = double, I = int, U = uint, B = bool, S = sampler
@@ -252,63 +239,35 @@
char order = *argOrder;
- if (UseHlslTypes) {
- switch (type) {
- case '-': s += "void"; break;
- case 'F': s += "float"; break;
- case 'D': s += "double"; break;
- case 'I': s += "int"; break;
- case 'U': s += "uint"; break;
- case 'L': s += "int64_t"; break;
- case 'M': s += "uint64_t"; break;
- case 'B': s += "bool"; break;
- case 'S': s += "sampler"; break;
- case 's': s += "SamplerComparisonState"; break;
- case 'T': s += ((isBuffer && isImage) ? "RWBuffer" :
- isSubpass ? "SubpassInput" :
- isBuffer ? "Buffer" :
- isImage ? "RWTexture" : "Texture"); break;
- case 'i': s += ((isBuffer && isImage) ? "RWBuffer" :
- isSubpass ? "SubpassInput" :
- isBuffer ? "Buffer" :
- isImage ? "RWTexture" : "Texture"); break;
- case 'u': s += ((isBuffer && isImage) ? "RWBuffer" :
- isSubpass ? "SubpassInput" :
- isBuffer ? "Buffer" :
- isImage ? "RWTexture" : "Texture"); break;
- default: s += "UNKNOWN_TYPE"; break;
- }
-
- if (isSubpass && isMS)
- s += "MS";
-
- } else {
- switch (type) {
- case '-': s += "void"; break;
- case 'F': s += BaseTypeName(order, "float", "vec", "mat"); break;
- case 'D': s += BaseTypeName(order, "double", "dvec", "dmat"); break;
- case 'I': s += BaseTypeName(order, "int", "ivec", "imat"); break;
- case 'U': s += BaseTypeName(order, "uint", "uvec", "umat"); break;
- case 'B': s += BaseTypeName(order, "bool", "bvec", "bmat"); break;
- case 'S': s += "sampler"; break;
- case 's': s += "samplerShadow"; break;
- case 'T': // fall through
- case 'i': // ...
- case 'u': // ...
- if (type != 'T') // create itexture, utexture, etc
- s += type;
-
- s += ((isImage && isBuffer) ? "imageBuffer" :
- isSubpass ? "subpassInput" :
- isImage ? "image" :
- isBuffer ? "samplerBuffer" :
- "texture");
- break;
-
- default: s += "UNKNOWN_TYPE"; break;
- }
+ switch (type) {
+ case '-': s += "void"; break;
+ case 'F': s += "float"; break;
+ case 'D': s += "double"; break;
+ case 'I': s += "int"; break;
+ case 'U': s += "uint"; break;
+ case 'L': s += "int64_t"; break;
+ case 'M': s += "uint64_t"; break;
+ case 'B': s += "bool"; break;
+ case 'S': s += "sampler"; break;
+ case 's': s += "SamplerComparisonState"; break;
+ case 'T': s += ((isBuffer && isImage) ? "RWBuffer" :
+ isSubpass ? "SubpassInput" :
+ isBuffer ? "Buffer" :
+ isImage ? "RWTexture" : "Texture"); break;
+ case 'i': s += ((isBuffer && isImage) ? "RWBuffer" :
+ isSubpass ? "SubpassInput" :
+ isBuffer ? "Buffer" :
+ isImage ? "RWTexture" : "Texture"); break;
+ case 'u': s += ((isBuffer && isImage) ? "RWBuffer" :
+ isSubpass ? "SubpassInput" :
+ isBuffer ? "Buffer" :
+ isImage ? "RWTexture" : "Texture"); break;
+ default: s += "UNKNOWN_TYPE"; break;
}
+ if (isSubpass && isMS)
+ s += "MS";
+
// handle fixed vector sizes, such as float3, and only ever 3.
const int fixedVecSize = FixedVecSize(argOrder);
if (fixedVecSize != 0)
@@ -324,7 +283,7 @@
case 1: s += "1D"; break;
case 2: s += (isMS ? "2DMS" : "2D"); break;
case 3: s += "3D"; break;
- case 4: s += "Cube"; break;
+ case 4: s += (type == 'S'? "CUBE" : "Cube"); break;
default: s += "UNKNOWN_SAMPLER"; break;
}
}
@@ -357,26 +316,24 @@
if (isArrayed)
s += "Array";
- // For HLSL, append return type for texture types
- if (UseHlslTypes) {
- switch (type) {
- case 'i': s += "<int"; s += dim0Char; s += ">"; break;
- case 'u': s += "<uint"; s += dim0Char; s += ">"; break;
- case 'T': s += "<float"; s += dim0Char; s += ">"; break;
- default: break;
- }
+ switch (type) {
+ case 'i': s += "<int"; s += dim0Char; s += ">"; break;
+ case 'u': s += "<uint"; s += dim0Char; s += ">"; break;
+ case 'T': s += "<float"; s += dim0Char; s += ">"; break;
+ default: break;
}
return s;
}
-// The GLSL parser can be used to parse a subset of HLSL prototypes. However, many valid HLSL prototypes
-// are not valid GLSL prototypes. This rejects the invalid ones. Thus, there is a single switch below
-// to enable creation of the entire HLSL space.
+// This rejects prototypes not normally valid for GLSL and it's way of finding
+// overloaded built-ins under implicit type conversion.
+//
+// It is possible that this is not needed, but that would require some tweaking
+// of other rules to get the same results.
inline bool IsValid(const char* cname, char retOrder, char retType, char argOrder, char argType, int dim0, int dim1)
{
const bool isVec = (argOrder == 'V');
- const bool isMat = (argOrder == 'M');
const std::string name(cname);
@@ -387,26 +344,6 @@
if (!IsTextureType(argOrder) && (isVec && dim0 == 1)) // avoid vec1
return false;
- if (UseHlslTypes) {
- // NO further restrictions for HLSL
- } else {
- // GLSL parser restrictions
- if ((isMat && (argType == 'I' || argType == 'U' || argType == 'B')) ||
- (retOrder == 'M' && (retType == 'I' || retType == 'U' || retType == 'B')))
- return false;
-
- if (isMat && dim0 == 1 && dim1 == 1) // avoid mat1x1
- return false;
-
- if (isMat && dim1 == 1) // TODO: avoid mat Nx1 until we find the right GLSL profile
- return false;
-
- if (name == "GetRenderTargetSamplePosition" ||
- name == "tex1D" ||
- name == "tex1Dgrad")
- return false;
- }
-
return true;
}
@@ -461,12 +398,10 @@
{
TString& s = commonBuiltins;
- const int first = (UseHlslTypes ? 1 : 2);
-
- for (int xRows = first; xRows <=4; xRows++) {
- for (int xCols = first; xCols <=4; xCols++) {
+ for (int xRows = 1; xRows <=4; xRows++) {
+ for (int xCols = 1; xCols <=4; xCols++) {
const int yRows = xCols;
- for (int yCols = first; yCols <=4; yCols++) {
+ for (int yCols = 1; yCols <=4; yCols++) {
const int retRows = xRows;
const int retCols = yCols;
@@ -917,7 +852,7 @@
{ "WaveActiveAllEqual", "S", "B", "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveAllEqualBool", "S", "B", "S", "B", EShLangPSCS, false},
{ "WaveActiveCountBits", "S", "U", "S", "B", EShLangPSCS, false},
-
+
{ "WaveActiveSum", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveProduct", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
{ "WaveActiveBitAnd", nullptr, nullptr, "SV", "DFUI", EShLangPSCS, false},
diff --git a/hlsl/hlslScanContext.cpp b/hlsl/hlslScanContext.cpp
index 28a66bb..5af321f 100644
--- a/hlsl/hlslScanContext.cpp
+++ b/hlsl/hlslScanContext.cpp
@@ -317,7 +317,7 @@
(*KeywordMap)["sampler1D"] = EHTokSampler1d;
(*KeywordMap)["sampler2D"] = EHTokSampler2d;
(*KeywordMap)["sampler3D"] = EHTokSampler3d;
- (*KeywordMap)["samplerCube"] = EHTokSamplerCube;
+ (*KeywordMap)["samplerCUBE"] = EHTokSamplerCube;
(*KeywordMap)["sampler_state"] = EHTokSamplerState;
(*KeywordMap)["SamplerState"] = EHTokSamplerState;
(*KeywordMap)["SamplerComparisonState"] = EHTokSamplerComparisonState;