From 5988ce80f580d57ce6718a61c86da6296caf0845 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Tue, 21 Jan 2020 18:49:44 -0500 Subject: 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. --- source/slang/hlsl.meta.slang | 14 +++++++++++--- source/slang/hlsl.meta.slang.h | 16 ++++++++++++---- source/slang/slang-emit-c-like.cpp | 28 ++++++++++++++++++++++++++++ source/slang/slang-hlsl-intrinsic-set.h | 2 +- 4 files changed, 52 insertions(+), 8 deletions(-) (limited to 'source') 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 vector log(vector matrix log(matrix x); // Base-10 logarithm -__generic T log10(T x); -__generic vector log10(vector x); -__generic matrix log10(matrix x); +__generic +__target_intrinsic(glsl, "(log( $0 ) * $S0( 0.43429448190325182765112891891661) )" ) +T log10(T x); + +__generic +__target_intrinsic(glsl, "(log( $0 ) * $S0(0.43429448190325182765112891891661) )" ) +vector log10(vector x); + +__generic +__target_intrinsic(glsl, "(log( $0 ) * $S0(0.43429448190325182765112891891661) )" ) +matrix log10(matrix x); // Base-2 logarithm __generic 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 vector lo SLANG_RAW("__generic matrix log(matrix x);\n") SLANG_RAW("\n") SLANG_RAW("// Base-10 logarithm\n") -SLANG_RAW("__generic T log10(T x);\n") -SLANG_RAW("__generic vector log10(vector x);\n") -SLANG_RAW("__generic matrix log10(matrix x);\n") +SLANG_RAW("__generic \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\n") +SLANG_RAW("__target_intrinsic(glsl, \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\" )\n") +SLANG_RAW("vector log10(vector x);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic \n") +SLANG_RAW("__target_intrinsic(glsl, \"(log( $0 ) * $S0(0.43429448190325182765112891891661) )\" )\n") +SLANG_RAW("matrix log10(matrix x);\n") SLANG_RAW("\n") SLANG_RAW("// Base-2 logarithm\n") SLANG_RAW("__generic 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(type)) + { + underlyingType = basicType; + } + else if (auto vectorType = as(type)) + { + underlyingType = as(vectorType->getElementType()); + } + else if (auto matrixType = as(type)) + { + underlyingType = as(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) \ -- cgit v1.2.3