summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-31 14:28:45 -0700
committerGitHub <noreply@github.com>2023-05-31 14:28:45 -0700
commit02bb741a8d1b4ed31a65c46b7e43d153b42a7b73 (patch)
tree1a548e812568de27b8fffcc2e251596e9d729177 /tests
parent5dd401e416e18fdfe904a66284b0cf56cf256ec7 (diff)
Preserve type cast during AST constant folding. (#2912)
* Preserve type cast during AST constant folding. Fixes #2891. * Fix. * Fix truncating. * fix test. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/language-feature/constants/type-cast-const.slang23
-rw-r--r--tests/language-feature/constants/type-cast-const.slang.expected.txt1
-rw-r--r--tests/language-feature/constants/type-cast-truncate.slang15
-rw-r--r--tests/language-feature/constants/type-cast-truncate.slang.expected.txt2
-rw-r--r--tests/pipeline/ray-tracing/ray-query-subroutine.slang2
5 files changed, 42 insertions, 1 deletions
diff --git a/tests/language-feature/constants/type-cast-const.slang b/tests/language-feature/constants/type-cast-const.slang
new file mode 100644
index 000000000..d0291aa7d
--- /dev/null
+++ b/tests/language-feature/constants/type-cast-const.slang
@@ -0,0 +1,23 @@
+//TEST(compute):COMPARE_COMPUTE:
+//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry computeMain -profile cs_5_0
+
+int check<let b : bool>(int x)
+{
+ // CHECK: int v{{.*}}[int(2)]
+ int v[((int)b) + 1];
+ for (int i = 0; i < ((int)b) + 1; i++)
+ v[i] = i;
+ return (int)v[x];
+}
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = check<true>(inVal + 1);
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/constants/type-cast-const.slang.expected.txt b/tests/language-feature/constants/type-cast-const.slang.expected.txt
new file mode 100644
index 000000000..56a6051ca
--- /dev/null
+++ b/tests/language-feature/constants/type-cast-const.slang.expected.txt
@@ -0,0 +1 @@
+1 \ No newline at end of file
diff --git a/tests/language-feature/constants/type-cast-truncate.slang b/tests/language-feature/constants/type-cast-truncate.slang
new file mode 100644
index 000000000..451d982f2
--- /dev/null
+++ b/tests/language-feature/constants/type-cast-truncate.slang
@@ -0,0 +1,15 @@
+//TEST(compute):COMPARE_COMPUTE: -output-using-type
+
+//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<int> outputBuffer;
+
+static const int c = (int8_t)255;
+
+[numthreads(1, 1, 1)]
+void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int tid = dispatchThreadID.x;
+ int inVal = tid;
+ int outVal = c;
+ outputBuffer[tid] = outVal;
+}
diff --git a/tests/language-feature/constants/type-cast-truncate.slang.expected.txt b/tests/language-feature/constants/type-cast-truncate.slang.expected.txt
new file mode 100644
index 000000000..a97ae25ba
--- /dev/null
+++ b/tests/language-feature/constants/type-cast-truncate.slang.expected.txt
@@ -0,0 +1,2 @@
+type: int32_t
+-1 \ No newline at end of file
diff --git a/tests/pipeline/ray-tracing/ray-query-subroutine.slang b/tests/pipeline/ray-tracing/ray-query-subroutine.slang
index 3279acc12..74489b6f8 100644
--- a/tests/pipeline/ray-tracing/ray-query-subroutine.slang
+++ b/tests/pipeline/ray-tracing/ray-query-subroutine.slang
@@ -7,7 +7,7 @@
RWStructuredBuffer<int> gOutput;
RaytracingAccelerationStructure gScene;
-float3 helper<let N : int>(RayQuery<N> q)
+float3 helper<let N : uint>(RayQuery<N> q)
{
RayDesc ray;
ray.Origin = 0;