diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-21 18:49:44 -0500 |
|---|---|---|
| committer | Tim Foley <tfoleyNV@users.noreply.github.com> | 2020-01-21 15:49:44 -0800 |
| commit | 5988ce80f580d57ce6718a61c86da6296caf0845 (patch) | |
| tree | 5549f197d437c578556bb25d65d57ff213bbb55b | |
| parent | 47392bc72b826b4ad427b703391a77e697735a65 (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.
| -rw-r--r-- | prelude/slang-cpp-scalar-intrinsics.h | 2 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang | 14 | ||||
| -rw-r--r-- | source/slang/hlsl.meta.slang.h | 16 | ||||
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 28 | ||||
| -rw-r--r-- | source/slang/slang-hlsl-intrinsic-set.h | 2 | ||||
| -rw-r--r-- | tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt | 4 | ||||
| -rw-r--r-- | tests/hlsl-intrinsic/scalar-float.slang (renamed from tests/compute/hlsl-scalar-float-intrinsic.slang) | 15 | ||||
| -rw-r--r-- | tests/hlsl-intrinsic/scalar-float.slang.expected.txt | 4 |
8 files changed, 67 insertions, 18 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h index e89338186..63fe9c926 100644 --- a/prelude/slang-cpp-scalar-intrinsics.h +++ b/prelude/slang-cpp-scalar-intrinsics.h @@ -49,6 +49,7 @@ SLANG_FORCE_INLINE float F32_acos(float f) { return ::acosf(f); } SLANG_FORCE_INLINE float F32_atan(float f) { return ::atanf(f); } SLANG_FORCE_INLINE float F32_log2(float f) { return ::log2f(f); } SLANG_FORCE_INLINE float F32_log(float f) { return ::logf(f); } +SLANG_FORCE_INLINE float F32_log10(float f) { return ::log10f(f); } SLANG_FORCE_INLINE float F32_exp2(float f) { return ::exp2f(f); } SLANG_FORCE_INLINE float F32_exp(float f) { return ::expf(f); } SLANG_FORCE_INLINE float F32_abs(float f) { return ::fabsf(f); } @@ -106,6 +107,7 @@ SLANG_FORCE_INLINE double F64_acos(double f) { return ::acos(f); } SLANG_FORCE_INLINE double F64_atan(double f) { return ::atan(f); } SLANG_FORCE_INLINE double F64_log2(double f) { return ::log2(f); } SLANG_FORCE_INLINE double F64_log(double f) { return ::log(f); } +SLANG_FORCE_INLINE double F64_log10(float f) { return ::log10(f); } SLANG_FORCE_INLINE double F64_exp2(double f) { return ::exp2(f); } SLANG_FORCE_INLINE double F64_exp(double f) { return ::exp(f); } SLANG_FORCE_INLINE double F64_abs(double f) { return ::fabs(f); } 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) \ diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt b/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt deleted file mode 100644 index 04d17659c..000000000 --- a/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt +++ /dev/null @@ -1,4 +0,0 @@ -FFFFFA3C -FFFFFEEC -3CA -8C1 diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang b/tests/hlsl-intrinsic/scalar-float.slang index 213db4b23..a1982bbb8 100644 --- a/tests/compute/hlsl-scalar-float-intrinsic.slang +++ b/tests/hlsl-intrinsic/scalar-float.slang @@ -12,13 +12,13 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { int idx = int(dispatchThreadID.x); - float f = idx * (1.0f / (4.0f - 1)); + float f = idx * (1.0f / (4.0f)); int it = 0; float ft = 0.0f; // fmod - // ft += f % 0.5f; + ft += int(((f % 0.11f) * 100) + 0.5); ft += sin(f); ft += cos(f); @@ -51,7 +51,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) ft += frac(f * 3); -// ft += ceil(f * 5 - 3); + ft += ceil(f * 5 - 3); ft += floor(f * 10 - 7); ft += trunc(f * 7); @@ -59,9 +59,12 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) ft += log(f + 10.0); ft += log2(f * 3 + 2); - - // ft += log10(f * 10 + 4); - + + { + float v[] = { 1, 10, 100, 1000 }; + ft += int(log10(v[idx]) + 0.5f); + } + ft += abs(f * 4 - 2.0f); ft += min(0.5, f); diff --git a/tests/hlsl-intrinsic/scalar-float.slang.expected.txt b/tests/hlsl-intrinsic/scalar-float.slang.expected.txt new file mode 100644 index 000000000..3ad5914c4 --- /dev/null +++ b/tests/hlsl-intrinsic/scalar-float.slang.expected.txt @@ -0,0 +1,4 @@ +FFFFFA0C +FFFFFDF4 +1ED +5EE |
