summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compute/hlsl-scalar-float-intrinsic.slang88
-rw-r--r--tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt4
-rw-r--r--tests/compute/transcendental.slang1
-rw-r--r--tests/cross-compile/simple-cross-compile.slang109
-rw-r--r--tests/cross-compile/simple-cross-compile.slang.expected.txt4
-rw-r--r--tests/cuda/compile-to-cuda.slang2
-rw-r--r--tests/cuda/compile-to-cuda.slang.expected.txt16
7 files changed, 222 insertions, 2 deletions
diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang b/tests/compute/hlsl-scalar-float-intrinsic.slang
new file mode 100644
index 000000000..213db4b23
--- /dev/null
+++ b/tests/compute/hlsl-scalar-float-intrinsic.slang
@@ -0,0 +1,88 @@
+//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);
+
+ float f = idx * (1.0f / (4.0f - 1));
+
+ int it = 0;
+ float ft = 0.0f;
+
+ // fmod
+ // ft += f % 0.5f;
+
+ ft += sin(f);
+ ft += cos(f);
+ ft += tan(f);
+
+ ft += asin(f);
+ ft += acos(f);
+ ft += atan(f);
+
+ ft += atan2(f, 2.0);
+
+ {
+ float sf, cf;
+ sincos(f, sf, cf);
+
+ ft += sf;
+ ft += cf;
+ }
+
+ ft += rcp(1.0 + f);
+ ft += sign(f - 0.5);
+
+ ft += saturate(f * 4 - 2.0);
+
+ ft += sqrt(f);
+ ft += rsqrt(1.0f + f);
+
+ ft += exp2(f);
+ ft += exp(f);
+
+
+ ft += frac(f * 3);
+// ft += ceil(f * 5 - 3);
+
+ ft += floor(f * 10 - 7);
+ ft += trunc(f * 7);
+
+
+ ft += log(f + 10.0);
+ ft += log2(f * 3 + 2);
+
+ // ft += log10(f * 10 + 4);
+
+ ft += abs(f * 4 - 2.0f);
+
+ ft += min(0.5, f);
+ ft += max(f, 0.75);
+
+ ft += pow(0.5, f);
+
+ ft += smoothstep(0.2, 0.7, f);
+ ft += lerp(-100, 100, f);
+
+
+ ft += clamp(f, 0.1, 0.3);
+
+ ft += step(f, 0.5);
+
+ int vi = asint(f - f) + idx;
+
+ ft += float(vi);
+
+ uint vu = asuint(f);
+ ft += asfloat(vu);
+
+ outputBuffer[idx] = int(ft * 16);
+} \ No newline at end of file
diff --git a/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt b/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt
new file mode 100644
index 000000000..04d17659c
--- /dev/null
+++ b/tests/compute/hlsl-scalar-float-intrinsic.slang.expected.txt
@@ -0,0 +1,4 @@
+FFFFFA3C
+FFFFFEEC
+3CA
+8C1
diff --git a/tests/compute/transcendental.slang b/tests/compute/transcendental.slang
index aa40da752..bde43ee38 100644
--- a/tests/compute/transcendental.slang
+++ b/tests/compute/transcendental.slang
@@ -1,3 +1,4 @@
+//TEST(compute):COMPARE_COMPUTE:-cuda
//TEST(compute):COMPARE_COMPUTE:-cpu
//TEST(compute):COMPARE_COMPUTE:
//TEST(compute,vulcan):COMPARE_COMPUTE:-vk
diff --git a/tests/cross-compile/simple-cross-compile.slang b/tests/cross-compile/simple-cross-compile.slang
new file mode 100644
index 000000000..e5fe9d3cc
--- /dev/null
+++ b/tests/cross-compile/simple-cross-compile.slang
@@ -0,0 +1,109 @@
+//TEST(compute):COMPARE_COMPUTE:-cpu
+//TEST(compute):COMPARE_COMPUTE:-cuda
+
+enum Color
+{
+ Red,
+ Green = 2,
+ Blue,
+}
+
+int test(int val)
+{
+ Color c = Color.Red;
+
+ if(val > 1)
+ {
+ c = Color.Green;
+ }
+
+ if(c == Color.Red)
+ {
+ if(val & 1)
+ {
+ c = Color.Blue;
+ }
+ }
+
+ switch(c)
+ {
+ case Color.Red:
+ val = 1;
+ break;
+
+ case Color.Green:
+ val = 2;
+ break;
+
+ case Color.Blue:
+ val = 3;
+ break;
+
+ default:
+ val = -1;
+ break;
+ }
+
+ return (val << 4) + int(c);
+}
+
+float sum(float a[3])
+{
+ float total = a[0];
+ for (int i = 1; i < 3; ++i)
+ {
+ total += a[i];
+ }
+ return total;
+}
+
+struct Thing
+{
+ int a;
+ float b;
+};
+
+//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 tid = dispatchThreadID.x;
+
+ Thing thing = { 10, -1.0 };
+
+ float array[3] = { thing.a, 2, 3};
+
+ float anotherArray[] = { 1, 2, 5 };
+
+ array[0] += anotherArray[1];
+
+ matrix<float, 2, 3> mat = { { sum(array), 1, 2 }, { 3, 4, 5} };
+ vector<float, 2> vec = { float(tid + 1), float(tid + 2) };
+
+ vec += float2(7, 11);
+
+ vector<float, 3> vec2 = max(sin(mul(vec, mat)), float3(1, 2, -1));
+ vector<float, 3> vec3 = mul(vec, mat);
+
+ float3 vec4 = lerp(vec2, vec3, float3(tid * (1.0f / 4), 1, 1));
+
+ float3 crossVec = normalize(cross(vec4, vec4) + float3(2, 3, 1));
+
+ vec2.x = fmod(crossVec.y, crossVec.x);
+
+ vec2 = fmod(vec2, crossVec);
+
+ vec2 += (-vec2.zyx) * 2 + crossVec * length(crossVec) + reflect(vec4, normalize(crossVec));
+
+ vector<bool, 3> z = vec2 > 0;
+
+ int val = (int(tid) + (any(z) ? 1 : 0) + (all(z) ? 2 : 0)) % 100;
+
+ val = asint(asfloat(asuint(asfloat(val))));
+
+ val = test(val);
+
+ outputBuffer[tid] = val + int(dot(vec2, vec4));
+} \ No newline at end of file
diff --git a/tests/cross-compile/simple-cross-compile.slang.expected.txt b/tests/cross-compile/simple-cross-compile.slang.expected.txt
new file mode 100644
index 000000000..c99b80180
--- /dev/null
+++ b/tests/cross-compile/simple-cross-compile.slang.expected.txt
@@ -0,0 +1,4 @@
+147
+FFFFE732
+FFFFCCE6
+FFFFB6C7
diff --git a/tests/cuda/compile-to-cuda.slang b/tests/cuda/compile-to-cuda.slang
index be7d775bd..d7399d469 100644
--- a/tests/cuda/compile-to-cuda.slang
+++ b/tests/cuda/compile-to-cuda.slang
@@ -8,12 +8,10 @@ RWStructuredBuffer<int> outputBuffer : register(u0);
[numthreads(4, 1, 1)]
void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
-
int tid = int(dispatchThreadID.x);
outputBuffer[tid * 4] = tid;
outputBuffer[tid * 4 + 1] = tid + 1;
outputBuffer[tid * 4 + 2] = tid + 2;
outputBuffer[tid * 4 + 3] = tid + 3;
-
}
diff --git a/tests/cuda/compile-to-cuda.slang.expected.txt b/tests/cuda/compile-to-cuda.slang.expected.txt
new file mode 100644
index 000000000..27a9fcd89
--- /dev/null
+++ b/tests/cuda/compile-to-cuda.slang.expected.txt
@@ -0,0 +1,16 @@
+0
+1
+2
+3
+1
+2
+3
+4
+2
+3
+4
+5
+3
+4
+5
+6