summaryrefslogtreecommitdiff
path: root/tests/spirv/large-struct.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2024-05-01 16:44:22 -0700
committerGitHub <noreply@github.com>2024-05-01 16:44:22 -0700
commit0bb826f8b92aec330875d0b966c1f4a6b99988bf (patch)
treef0d086d4bfb93e302fcb8232816842ccfc182480 /tests/spirv/large-struct.slang
parent4533c825fe628e08228037b846ee9d10004fd56f (diff)
SPIRV: Fix performance issue when handling large arrays. (#4064)
* SPIRV: Fix performance issue when handling large arrays. * Add test for packing. * Fix clang.
Diffstat (limited to 'tests/spirv/large-struct.slang')
-rw-r--r--tests/spirv/large-struct.slang32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/spirv/large-struct.slang b/tests/spirv/large-struct.slang
new file mode 100644
index 000000000..7738a5fcf
--- /dev/null
+++ b/tests/spirv/large-struct.slang
@@ -0,0 +1,32 @@
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -profile glsl_460
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-d3d12 -compute -output-using-type
+//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -output-using-type
+
+// Check that when generating spirv directly, we use a loop
+// to copy large arrays in input data out into a local variable, instead of emitting
+// unrolled code that reads each element of the array individually.
+
+struct WorkData
+{
+ float A[2*2];
+ float B[1024];
+
+ float Foo(uint i) { return A[i] * B[i]; }
+};
+
+//TEST_INPUT:set input = new WorkData{[1.0, 2.0, 3.0, 4.0], [10.0, 20.0, 30.0, 40.0]}
+ConstantBuffer<WorkData> input;
+
+//TEST_INPUT:set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4)
+RWStructuredBuffer<float> resultBuffer;
+
+// CHECK: OpLoopMerge
+
+[numthreads(2, 1, 1)]
+void computeMain(uint3 tid: SV_DispatchThreadID)
+{
+ // BUF: 10.0
+ // BUF: 40.0
+ resultBuffer[tid.x] = input.Foo(tid.x);
+} \ No newline at end of file