summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-01-22 11:06:20 -0500
committerGitHub <noreply@github.com>2020-01-22 11:06:20 -0500
commitc74a700681b0be44a74f16b0f9eaad05bba159d2 (patch)
tree6855baa362b336f17e199f1ad33242e73e98f6a7
parent346a56749c99e4e05d24ad6217f34dd5d44af189 (diff)
WIP HLSL intrinsic coverage (#1171)
* 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. * Works on CUDA/CPU. Problem with asint/asuint do not seem to be found. * Only asuint exists for double. * Support countbits on CUDA and C++. * Fix typo in C++ population count. * First pass at int vector intrinsic tests. * Swizzle for int. * Bit cast tests on CUDA. * Fix warning on gcc. * Fix bit-cast-double execution on CUDA. * scalar-int test working on gcc release.
-rw-r--r--prelude/slang-cpp-scalar-intrinsics.h22
-rw-r--r--prelude/slang-cuda-prelude.h7
-rw-r--r--source/slang/slang-emit-cpp.cpp6
-rw-r--r--source/slang/slang-hlsl-intrinsic-set.h4
-rw-r--r--tests/hlsl-intrinsic/bit-cast-double.slang (renamed from tests/compute/bit-cast-double.slang)3
-rw-r--r--tests/hlsl-intrinsic/bit-cast-double.slang.expected.txt (renamed from tests/compute/bit-cast-double.slang.expected.txt)0
-rw-r--r--tests/hlsl-intrinsic/bit-cast.slang (renamed from tests/compute/bit-cast.slang)1
-rw-r--r--tests/hlsl-intrinsic/bit-cast.slang.expected.txt (renamed from tests/compute/bit-cast.slang.expected.txt)0
-rw-r--r--tests/hlsl-intrinsic/scalar-int.slang25
-rw-r--r--tests/hlsl-intrinsic/scalar-int.slang.expected.txt4
-rw-r--r--tests/hlsl-intrinsic/scalar-uint.slang26
-rw-r--r--tests/hlsl-intrinsic/scalar-uint.slang.expected.txt4
-rw-r--r--tests/hlsl-intrinsic/vector-int.slang50
-rw-r--r--tests/hlsl-intrinsic/vector-int.slang.expected.txt4
-rw-r--r--tools/render-test/bind-location.cpp2
15 files changed, 154 insertions, 4 deletions
diff --git a/prelude/slang-cpp-scalar-intrinsics.h b/prelude/slang-cpp-scalar-intrinsics.h
index 63fe9c926..6c577733d 100644
--- a/prelude/slang-cpp-scalar-intrinsics.h
+++ b/prelude/slang-cpp-scalar-intrinsics.h
@@ -3,6 +3,11 @@
#include "../slang.h"
+#if SLANG_PROCESSOR_X86_64 && SLANG_VC
+// If we have visual studio and 64 bit processor, we can assume we have popcnt, and can include x86 intrinsics
+# include <intrin.h>
+#endif
+
#ifdef SLANG_PRELUDE_NAMESPACE
namespace SLANG_PRELUDE_NAMESPACE {
#endif
@@ -192,7 +197,22 @@ SLANG_FORCE_INLINE double U32_asdouble(uint32_t low, uint32_t hi)
return u.d;
}
-
+SLANG_FORCE_INLINE uint32_t U32_countbits(uint32_t v)
+{
+#if SLANG_GCC_FAMILY
+ return __builtin_popcount(v);
+#elif SLANG_PROCESSOR_X86_64 && SLANG_VC
+ return __popcnt(v);
+#else
+ uint32_t c = 0;
+ while (v)
+ {
+ c++;
+ v &= v - 1;
+ }
+ return c;
+#endif
+}
#ifdef SLANG_PRELUDE_NAMESPACE
diff --git a/prelude/slang-cuda-prelude.h b/prelude/slang-cuda-prelude.h
index 8d100b0db..f78814486 100644
--- a/prelude/slang-cuda-prelude.h
+++ b/prelude/slang-cuda-prelude.h
@@ -161,6 +161,13 @@ SLANG_CUDA_CALL double U32_asdouble(uint32_t low, uint32_t hi)
return u.d;
}
+SLANG_CUDA_CALL uint32_t U32_countbits(uint32_t v)
+{
+ // https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH__INTRINSIC__INT.html#group__CUDA__MATH__INTRINSIC__INT_1g43c9c7d2b9ebf202ff1ef5769989be46
+ return __popc(v);
+}
+
+
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index db442d131..5dd028182 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -969,6 +969,8 @@ void CPPSourceEmitter::_emitGetAtDefinition(const UnownedStringSlice& funcName,
IRType* srcType = funcType->getParamType(0);
+ emitSpecializedOperationDefinitionPreamble(specOp);
+
IRType* retType = specOp->returnType;
emitType(retType);
m_writer->emit("& ");
@@ -1046,6 +1048,8 @@ void CPPSourceEmitter::_emitConstructConvertDefinition(const UnownedStringSlice&
IRType* srcType = funcType->getParamType(1);
IRType* retType = specOp->returnType;
+ emitSpecializedOperationDefinitionPreamble(specOp);
+
emitType(retType);
writer->emit(" ");
writer->emit(funcName);
@@ -1112,6 +1116,8 @@ void CPPSourceEmitter::_emitConstructFromScalarDefinition(const UnownedStringSli
IRType* srcType = funcType->getParamType(1);
IRType* retType = specOp->returnType;
+ emitSpecializedOperationDefinitionPreamble(specOp);
+
emitType(retType);
writer->emit(" ");
writer->emit(funcName);
diff --git a/source/slang/slang-hlsl-intrinsic-set.h b/source/slang/slang-hlsl-intrinsic-set.h
index d55c908ae..df1677b17 100644
--- a/source/slang/slang-hlsl-intrinsic-set.h
+++ b/source/slang/slang-hlsl-intrinsic-set.h
@@ -123,7 +123,9 @@ just constructXXXFromScalar. Would be good if there was a suitable name to encom
x(ConstructFromScalar, "", 1) \
\
x(GetAt, "", 2) \
- x(SetAt, "", 3)
+ x(SetAt, "", 3) \
+ \
+ x(CountBits, "countbits", 1)
struct HLSLIntrinsic
{
diff --git a/tests/compute/bit-cast-double.slang b/tests/hlsl-intrinsic/bit-cast-double.slang
index 6b0925a58..b52c9de2b 100644
--- a/tests/compute/bit-cast-double.slang
+++ b/tests/hlsl-intrinsic/bit-cast-double.slang
@@ -1,7 +1,8 @@
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -cpu
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
-//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-slang -vk -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -cuda -compute
//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
RWStructuredBuffer<int> outputBuffer;
diff --git a/tests/compute/bit-cast-double.slang.expected.txt b/tests/hlsl-intrinsic/bit-cast-double.slang.expected.txt
index bc856dafa..bc856dafa 100644
--- a/tests/compute/bit-cast-double.slang.expected.txt
+++ b/tests/hlsl-intrinsic/bit-cast-double.slang.expected.txt
diff --git a/tests/compute/bit-cast.slang b/tests/hlsl-intrinsic/bit-cast.slang
index a8fec61e3..4ecd911d7 100644
--- a/tests/compute/bit-cast.slang
+++ b/tests/hlsl-intrinsic/bit-cast.slang
@@ -2,6 +2,7 @@
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute
//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer
diff --git a/tests/compute/bit-cast.slang.expected.txt b/tests/hlsl-intrinsic/bit-cast.slang.expected.txt
index f5414793f..f5414793f 100644
--- a/tests/compute/bit-cast.slang.expected.txt
+++ b/tests/hlsl-intrinsic/bit-cast.slang.expected.txt
diff --git a/tests/hlsl-intrinsic/scalar-int.slang b/tests/hlsl-intrinsic/scalar-int.slang
new file mode 100644
index 000000000..7fccc8645
--- /dev/null
+++ b/tests/hlsl-intrinsic/scalar-int.slang
@@ -0,0 +1,25 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int idx = int(dispatchThreadID.x);
+
+ int ti =0;
+
+ ti += max(2, idx);
+ ti += min(idx, 1);
+ ti += abs(idx - 2);
+ ti += (idx * 3) % 5;
+
+ ti += clamp(idx * 10, 11, 23);
+
+ outputBuffer[idx] = ti;
+} \ No newline at end of file
diff --git a/tests/hlsl-intrinsic/scalar-int.slang.expected.txt b/tests/hlsl-intrinsic/scalar-int.slang.expected.txt
new file mode 100644
index 000000000..4efe33dc6
--- /dev/null
+++ b/tests/hlsl-intrinsic/scalar-int.slang.expected.txt
@@ -0,0 +1,4 @@
+F
+12
+18
+20
diff --git a/tests/hlsl-intrinsic/scalar-uint.slang b/tests/hlsl-intrinsic/scalar-uint.slang
new file mode 100644
index 000000000..eb16bb3b8
--- /dev/null
+++ b/tests/hlsl-intrinsic/scalar-uint.slang
@@ -0,0 +1,26 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ uint idx = dispatchThreadID.x;
+
+ uint ti = 0;
+
+ ti += max(2, idx);
+ ti += min(idx, 1);
+ ti += (idx * 3) %5;
+
+ ti += clamp(idx * 10, 11, 23);
+
+ ti += countbits(idx * 13);
+
+ outputBuffer[idx] = ti;
+} \ No newline at end of file
diff --git a/tests/hlsl-intrinsic/scalar-uint.slang.expected.txt b/tests/hlsl-intrinsic/scalar-uint.slang.expected.txt
new file mode 100644
index 000000000..1a7befbe1
--- /dev/null
+++ b/tests/hlsl-intrinsic/scalar-uint.slang.expected.txt
@@ -0,0 +1,4 @@
+D
+14
+1B
+23
diff --git a/tests/hlsl-intrinsic/vector-int.slang b/tests/hlsl-intrinsic/vector-int.slang
new file mode 100644
index 000000000..9a3f1faaa
--- /dev/null
+++ b/tests/hlsl-intrinsic/vector-int.slang
@@ -0,0 +1,50 @@
+//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute
+//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int idx = int(dispatchThreadID.x);
+
+ int3 a = { idx + 10, idx - 9, idx + 3};
+ int3 b = { idx * 2, idx * 3, idx * 10};
+
+ int3 t = { 0, 0, 0};
+
+ t += max(a, b);
+ t += min(a, b);
+ t += abs(a);
+ t += b % 5;
+
+ t += clamp(a, int3(10), int3(23));
+
+ // Swizzle
+ t += a.zyx;
+ // Swizzle from scalar
+ t += idx.xxx;
+
+#if 0
+ // TODO(JS): On C++ not all accesses are turned into getAt/setAt, so disable for now.
+ // Reads
+ {
+ t += int3(a[idx % 3], a[0], b[2]);
+ }
+
+ // Writes
+ {
+ int3 v = int3(b[(idx + 1) % 3], b[(idx + 2) % 3], b[(idx + 3) % 3]);
+ v[1] += v[0];
+ v[idx & 1] += v[2];
+
+ t += v;
+ }
+#endif
+
+ outputBuffer[idx] = t.x + t.y + t.z;
+} \ No newline at end of file
diff --git a/tests/hlsl-intrinsic/vector-int.slang.expected.txt b/tests/hlsl-intrinsic/vector-int.slang.expected.txt
new file mode 100644
index 000000000..e4c658883
--- /dev/null
+++ b/tests/hlsl-intrinsic/vector-int.slang.expected.txt
@@ -0,0 +1,4 @@
+3C
+5B
+75
+8F
diff --git a/tools/render-test/bind-location.cpp b/tools/render-test/bind-location.cpp
index 30b9de0f8..114ca7e8e 100644
--- a/tools/render-test/bind-location.cpp
+++ b/tools/render-test/bind-location.cpp
@@ -482,7 +482,7 @@ BindLocation BindSet::toIndex(const BindLocation& loc, Index index) const
size_t baseOffset = loc.m_bindPointSet->m_points[category].m_offset;
- if (category == SLANG_PARAMETER_CATEGORY_UNIFORM && uniformValue != loc.m_value)
+ if (category == slang::ParameterCategory::Uniform && uniformValue != loc.m_value)
{
baseOffset = 0;
}