From eefe2539373a2e17eda2f11c420908c0aebcac6d Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 25 Jan 2019 17:44:24 -0800 Subject: Add GLSL translation rules for `SampleCmp`, `asint` and `asfloat`. --- source/slang/core.meta.slang | 26 +++++++++++++++----------- source/slang/core.meta.slang.h | 26 +++++++++++++++----------- source/slang/hlsl.meta.slang | 20 ++++++++++++++++---- source/slang/hlsl.meta.slang.h | 20 ++++++++++++++++---- 4 files changed, 62 insertions(+), 30 deletions(-) (limited to 'source') 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 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 vector asfloat(vector< int,N> x); -__generic vector asfloat(vector x); +__generic +__target_intrinsic(glsl, intBitsAsFloat) +vector asfloat(vector< int,N> x); +__generic +__target_intrinsic(glsl, uintBitsAsFloat) +vector asfloat(vector x); __generic matrix asfloat(matrix< int,N,M> x); __generic matrix asfloat(matrix x); @@ -382,10 +388,16 @@ __generic vector asin(vector matrix asin(matrix 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 vector asint(vector x); -__generic vector asint(vector x); + +__generic +__target_intrinsic(glsl, floatBitsToInt) +vector asint(vector x); +__generic +vector asint(vector x); __generic matrix asint(matrix x); __generic matrix asint(matrix 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 vector asfloat(vector< int,N> x);\n") -SLANG_RAW("__generic vector asfloat(vector x);\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, intBitsAsFloat)\n") +SLANG_RAW("vector asfloat(vector< int,N> x);\n") +SLANG_RAW("__generic\n") +SLANG_RAW("__target_intrinsic(glsl, uintBitsAsFloat)\n") +SLANG_RAW("vector asfloat(vector x);\n") SLANG_RAW("__generic matrix asfloat(matrix< int,N,M> x);\n") SLANG_RAW("__generic matrix asfloat(matrix x);\n") SLANG_RAW("\n") @@ -427,10 +433,16 @@ SLANG_RAW("__generic vector as SLANG_RAW("__generic matrix asin(matrix 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 vector asint(vector x);\n") -SLANG_RAW("__generic vector asint(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic \n") +SLANG_RAW("__target_intrinsic(glsl, floatBitsToInt)\n") +SLANG_RAW("vector asint(vector x);\n") +SLANG_RAW("__generic \n") +SLANG_RAW("vector asint(vector x);\n") SLANG_RAW("__generic matrix asint(matrix x);\n") SLANG_RAW("__generic matrix asint(matrix x);\n") SLANG_RAW("\n") -- cgit v1.2.3