diff options
| author | Yong He <yonghe@google.com> | 2019-01-25 17:44:24 -0800 |
|---|---|---|
| committer | Yong He <yonghe@google.com> | 2019-01-25 18:11:57 -0800 |
| commit | eefe2539373a2e17eda2f11c420908c0aebcac6d (patch) | |
| tree | d56d36118b83ba23cc1b817035ab4f5b54034c99 /source/slang | |
| parent | 864c38ee72991f414f2478ccacb462bfb11b4bca (diff) | |
Add GLSL translation rules for `SampleCmp`, `asint` and `asfloat`.
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/core.meta.slang | 26 | ||||
| -rw-r--r-- | source/slang/core.meta.slang.h | 26 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 20 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 20 |
4 files changed, 62 insertions, 30 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 0e8458218..e6bad3f50 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -875,15 +875,22 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; } - - // `SampleCmp()` and `SampleCmpLevelZero` - sb << "float SampleCmp(SamplerComparisonState s, "; - sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; - sb << "float compareValue"; - sb << ");\n"; - int baseCoordCount = kBaseTextureTypes[tt].coordCount; int arrCoordCount = baseCoordCount + isArray; + if (arrCoordCount <= 3) + { + // `SampleCmp()` and `SampleCmpLevelZero` + sb << "__target_intrinsic(glsl, \"texture($p, vec" << arrCoordCount + 1 << "($2, $3))\")"; + sb << "float SampleCmp(SamplerComparisonState s, "; + sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; + sb << "float compareValue"; + sb << ");\n"; + sb << "__target_intrinsic(glsl, \"texture($p, vec" << arrCoordCount + 1 << "($2, $3))\")"; + sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; + sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; + sb << "float compareValue"; + sb << ");\n"; + } if (arrCoordCount < 3) { int extCoordCount = arrCoordCount + 1; @@ -923,10 +930,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << ", vec" << baseCoordCount << "(0.0)"; sb << ")$z\")\n"; } - sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; - sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; - sb << "float compareValue"; - sb << ");\n"; + if( baseShape != TextureFlavor::Shape::ShapeCube ) { diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index 2cb0402f8..a29fc24ce 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -890,15 +890,22 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, float bias, "; sb << "constexpr int" << kBaseTextureTypes[tt].coordCount << " offset);\n"; } - - // `SampleCmp()` and `SampleCmpLevelZero` - sb << "float SampleCmp(SamplerComparisonState s, "; - sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; - sb << "float compareValue"; - sb << ");\n"; - int baseCoordCount = kBaseTextureTypes[tt].coordCount; int arrCoordCount = baseCoordCount + isArray; + if (arrCoordCount <= 3) + { + // `SampleCmp()` and `SampleCmpLevelZero` + sb << "__target_intrinsic(glsl, \"texture($p, vec" << arrCoordCount + 1 << "($2, $3))\")"; + sb << "float SampleCmp(SamplerComparisonState s, "; + sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; + sb << "float compareValue"; + sb << ");\n"; + sb << "__target_intrinsic(glsl, \"texture($p, vec" << arrCoordCount + 1 << "($2, $3))\")"; + sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; + sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; + sb << "float compareValue"; + sb << ");\n"; + } if (arrCoordCount < 3) { int extCoordCount = arrCoordCount + 1; @@ -938,10 +945,7 @@ for (int tt = 0; tt < kBaseTextureTypeCount; ++tt) sb << ", vec" << baseCoordCount << "(0.0)"; sb << ")$z\")\n"; } - sb << "float SampleCmpLevelZero(SamplerComparisonState s, "; - sb << "float" << kBaseTextureTypes[tt].coordCount + isArray << " location, "; - sb << "float compareValue"; - sb << ");\n"; + if( baseShape != TextureFlavor::Shape::ShapeCube ) { diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 541d12112..02eb332c8 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -368,10 +368,16 @@ bool any(matrix<T,N,M> x); double asdouble(uint lowbits, uint highbits);
// Reinterpret bits as a float (HLSL SM 4.0)
+__target_intrinsic(glsl, intBitsToFloat)
float asfloat( int x);
+__target_intrinsic(glsl, uintBitsToFloat)
float asfloat(uint x);
-__generic<let N : int> vector<float,N> asfloat(vector< int,N> x);
-__generic<let N : int> vector<float,N> asfloat(vector<uint,N> x);
+__generic<let N : int>
+__target_intrinsic(glsl, intBitsAsFloat)
+vector<float,N> asfloat(vector< int,N> x);
+__generic<let N : int>
+__target_intrinsic(glsl, uintBitsAsFloat)
+vector<float,N> asfloat(vector<uint,N> x);
__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix< int,N,M> x);
__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix<uint,N,M> x);
@@ -382,10 +388,16 @@ __generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> asin(vector<T __generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> asin(matrix<T,N,M> x);
// Reinterpret bits as an int (HLSL SM 4.0)
+__target_intrinsic(glsl, floatBitsToInt)
int asint(float x);
+__target_intrinsic(glsl, "uint($0)")
int asint(uint x);
-__generic<let N : int> vector<int,N> asint(vector<float,N> x);
-__generic<let N : int> vector<int,N> asint(vector<uint,N> x);
+
+__generic<let N : int>
+__target_intrinsic(glsl, floatBitsToInt)
+vector<int,N> asint(vector<float,N> x);
+__generic<let N : int>
+vector<int,N> asint(vector<uint,N> x);
__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<float,N,M> x);
__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<uint,N,M> x);
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h index 9fb06b4b0..9e6928dc0 100644 --- a/source/slang/hlsl.meta.slang.h +++ b/source/slang/hlsl.meta.slang.h @@ -413,10 +413,16 @@ SLANG_RAW("// Reinterpret bits as a double (HLSL SM 5.0)\n") SLANG_RAW("double asdouble(uint lowbits, uint highbits);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as a float (HLSL SM 4.0)\n") +SLANG_RAW("__target_intrinsic(glsl, intBitsToFloat)\n") SLANG_RAW("float asfloat( int x);\n") +SLANG_RAW("__target_intrinsic(glsl, uintBitsToFloat)\n") SLANG_RAW("float asfloat(uint x);\n") -SLANG_RAW("__generic<let N : int> vector<float,N> asfloat(vector< int,N> x);\n") -SLANG_RAW("__generic<let N : int> vector<float,N> asfloat(vector<uint,N> x);\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, intBitsAsFloat)\n") +SLANG_RAW("vector<float,N> asfloat(vector< int,N> x);\n") +SLANG_RAW("__generic<let N : int>\n") +SLANG_RAW("__target_intrinsic(glsl, uintBitsAsFloat)\n") +SLANG_RAW("vector<float,N> asfloat(vector<uint,N> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix< int,N,M> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix<uint,N,M> x);\n") SLANG_RAW("\n") @@ -427,10 +433,16 @@ SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> as SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> asin(matrix<T,N,M> x);\n") SLANG_RAW("\n") SLANG_RAW("// Reinterpret bits as an int (HLSL SM 4.0)\n") +SLANG_RAW("__target_intrinsic(glsl, floatBitsToInt)\n") SLANG_RAW("int asint(float x);\n") +SLANG_RAW("__target_intrinsic(glsl, \"uint($0)\")\n") SLANG_RAW("int asint(uint x);\n") -SLANG_RAW("__generic<let N : int> vector<int,N> asint(vector<float,N> x);\n") -SLANG_RAW("__generic<let N : int> vector<int,N> asint(vector<uint,N> x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<let N : int> \n") +SLANG_RAW("__target_intrinsic(glsl, floatBitsToInt)\n") +SLANG_RAW("vector<int,N> asint(vector<float,N> x);\n") +SLANG_RAW("__generic<let N : int> \n") +SLANG_RAW("vector<int,N> asint(vector<uint,N> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<float,N,M> x);\n") SLANG_RAW("__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<uint,N,M> x);\n") SLANG_RAW("\n") |
