summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-01-21 18:49:44 -0500
committerTim Foley <tfoleyNV@users.noreply.github.com>2020-01-21 15:49:44 -0800
commit5988ce80f580d57ce6718a61c86da6296caf0845 (patch)
tree5549f197d437c578556bb25d65d57ff213bbb55b /source
parent47392bc72b826b4ad427b703391a77e697735a65 (diff)
HLSL intrinsic coverage (#1169)
* Added hlsl-intrinsic test folder. Enabled ceil as works across targets. * log10 support. * Fix float % on CPU/CUDA to match HLSL which is fmod (not fremainder). * Added log10 tests back to scalar-float.slang * Don't add the ( for $Sx - it's clearer what's going on without it.
Diffstat (limited to 'source')
-rw-r--r--source/slang/hlsl.meta.slang14
-rw-r--r--source/slang/hlsl.meta.slang.h16
-rw-r--r--source/slang/slang-emit-c-like.cpp28
-rw-r--r--source/slang/slang-hlsl-intrinsic-set.h2
4 files changed, 52 insertions, 8 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 22a846eb7..2930494c0 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -952,9 +952,17 @@ __generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log(vector<T,
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log(matrix<T,N,M> x);
// Base-10 logarithm
-__generic<T : __BuiltinFloatingPointType> T log10(T x);
-__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log10(vector<T,N> x);
-__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log10(matrix<T,N,M> x);
+__generic<T : __BuiltinFloatingPointType>
+__target_intrinsic(glsl, "(log( $0 ) * $S0( 0.43429448190325182765112891891661) )" )
+T log10(T x);
+
+__generic<T : __BuiltinFloatingPointType, let N : int>
+__target_intrinsic(glsl, "(log( $0 ) * $S0(0.43429448190325182765112891891661) )" )
+vector<T,N> log10(vector<T,N> x);
+
+__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
+__target_intrinsic(glsl, "(log( $0 ) * $S0(0.43429448190325182765112891891661) )" )
+matrix<T,N,M> log10(matrix<T,N,M> x);
// Base-2 logarithm
__generic<T : __BuiltinFloatingPointType> T log2(T x);
diff --git a/source/slang/hlsl.meta.slang.h b/source/slang/hlsl.meta.slang.h
index 0abae51b0..a58709087 100644
--- a/source/slang/hlsl.meta.slang.h
+++ b/source/slang/hlsl.meta.slang.h
@@ -1028,9 +1028,17 @@ SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> lo
SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log(matrix<T,N,M> x);\n")
SLANG_RAW("\n")
SLANG_RAW("// Base-10 logarithm\n")
-SLANG_RAW("__generic<T : __BuiltinFloatingPointType> T log10(T x);\n")
-SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log10(vector<T,N> x);\n")
-SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log10(matrix<T,N,M> x);\n")
+SLANG_RAW("__generic<T : __BuiltinFloatingPointType> \n")
+SLANG_RAW("__target_intrinsic(glsl, \"(log( $0 ) * $S0( 0.43429448190325182765112891891661) )\" )\n")
+SLANG_RAW("T log10(T x);\n")
+SLANG_RAW("\n")
+SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int>\n")
+SLANG_RAW("__target_intrinsic(glsl, \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\" )\n")
+SLANG_RAW("vector<T,N> log10(vector<T,N> x);\n")
+SLANG_RAW("\n")
+SLANG_RAW("__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> \n")
+SLANG_RAW("__target_intrinsic(glsl, \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\" )\n")
+SLANG_RAW("matrix<T,N,M> log10(matrix<T,N,M> x);\n")
SLANG_RAW("\n")
SLANG_RAW("// Base-2 logarithm\n")
SLANG_RAW("__generic<T : __BuiltinFloatingPointType> T log2(T x);\n")
@@ -1579,7 +1587,7 @@ for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
sb << "};\n";
}
-SLANG_RAW("#line 1506 \"hlsl.meta.slang\"")
+SLANG_RAW("#line 1514 \"hlsl.meta.slang\"")
SLANG_RAW("\n")
SLANG_RAW("\n")
SLANG_RAW("\n")
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 1a2fbb0f4..ae6becf0f 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -1236,6 +1236,34 @@ void CLikeSourceEmitter::emitIntrinsicCallExpr(
}
break;
+ case 'S':
+ // Get the scalar type of a generic at specified index
+ {
+ SLANG_RELEASE_ASSERT(*cursor >= '0' && *cursor <= '9');
+ Index argIndex = (*cursor++) - '0';
+ SLANG_RELEASE_ASSERT(argCount > argIndex);
+
+ IRType* type = args[argIndex].get()->getDataType();
+
+ IRBasicType* underlyingType = nullptr;
+ if (auto basicType = as<IRBasicType>(type))
+ {
+ underlyingType = basicType;
+ }
+ else if (auto vectorType = as<IRVectorType>(type))
+ {
+ underlyingType = as<IRBasicType>(vectorType->getElementType());
+ }
+ else if (auto matrixType = as<IRMatrixType>(type))
+ {
+ underlyingType = as<IRBasicType>(matrixType->getElementType());
+ }
+
+ SLANG_ASSERT(underlyingType);
+
+ emitSimpleType(underlyingType);
+ }
+ break;
case 'p':
{
// If we are calling a D3D texturing operation in the form t.Foo(s, ...),
diff --git a/source/slang/slang-hlsl-intrinsic-set.h b/source/slang/slang-hlsl-intrinsic-set.h
index ee17dd571..d55c908ae 100644
--- a/source/slang/slang-hlsl-intrinsic-set.h
+++ b/source/slang/slang-hlsl-intrinsic-set.h
@@ -39,7 +39,7 @@ just constructXXXFromScalar. Would be good if there was a suitable name to encom
x(Lsh, "<<", 2) \
x(Rsh, ">>", 2) \
x(IRem, "%", 2) \
- x(FRem, "remainder", 2) \
+ x(FRem, "fmod", 2) \
\
x(Eql, "==", 2) \
x(Neq, "!=", 2) \