summaryrefslogtreecommitdiff
path: root/tests/legalization
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-09-05 23:26:59 +0800
committerGitHub <noreply@github.com>2023-09-05 23:26:59 +0800
commit2c2294d3310b24fd73cd41ec51338a736f3a2886 (patch)
tree0e02393fa772e7741eb38079a79f5cacaa1ba7b0 /tests/legalization
parent641f7bdc4ea4f75385c30d833cce4619a411ec67 (diff)
SPIR-V image operations (#3163)
* Add __truncate and __sampledType for spirv_asm Allows some texture tests to start passing * add __isVector Currently unused * Add 1-vector legalization pass (WIP) * Add capabilities for image types * neaten instruction dumping * add 1-vector test * Add a couple of cases to vec1 legalization * Remove texture tests from expected failures * comment * regenerate vs projects * Remove redundant define form synchapi emulation * refactoring image methods * All sample functions refactored * Remove incorrect glsl intrinsics Partially addresses https://github.com/shader-slang/slang/issues/3174 * __subscript image ops via writing funcs * Extract texture struct writing from core.meta.slang * Abstract out cuda intrinsic * Remvoe erroneous call to opDecorateIndex * spirv asm IR utils * Correct position of loads for SPIR-V asm inst operands * Raise constructors to global scope during spir-v legalization * Correct snippet output * Implement most texture sampling ops for SPIR-V * Legalize 1-vectors for glsl too * Make SPIR-V inst operands non-hoistable * Better 1-vector legalization * Put textures in ptrs for spirv * insert missing break * Add vec1 legalization test * Add some missing pieces to slang-ir-insts * Greatly neaten vec1 legalization * a * Neaten vec1 legalization * Add image read and write intrinsics for spir-v * Squash warnings * regenerate vs projects * Drop redundant guards * Drop 5 tests from expected failure list * Inst numbering changes to cross compile tests * vec1 legalization tests only on vk * Correct location of asm op emit * Inline constant in spirv-asm * Correct signedness for lane in wave intrinsics * Extract element from float1 for cuda * squash warnings * Neaten spirv-emit * dedupe more capabilities * warnings * neaten assert * comments * comments
Diffstat (limited to 'tests/legalization')
-rw-r--r--tests/legalization/vec1.slang93
1 files changed, 93 insertions, 0 deletions
diff --git a/tests/legalization/vec1.slang b/tests/legalization/vec1.slang
new file mode 100644
index 000000000..f3de085b0
--- /dev/null
+++ b/tests/legalization/vec1.slang
@@ -0,0 +1,93 @@
+//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -output-using-type
+//TEST(smoke,compute):COMPARE_COMPUTE(filecheck-buffer=CHECK):-vk -shaderobj -emit-spirv-directly -output-using-type
+
+// CHECK: 23
+// CHECK-NEXT: 23
+// CHECK-NEXT: 23
+// CHECK-NEXT: 23
+
+// This test tests that the 1-vector legalization works correctly.
+
+//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer
+RWStructuredBuffer<float> outputBuffer;
+
+// This struct helps test that nested access through 1-vectors works
+struct V
+{
+ // 1-vector of 1-vector
+ vector<vector<float, 1>, 1> oo;
+
+ // 1-vector of n-vector
+ vector<vector<float, 4>, 1> on;
+
+ // n-vector of 1-vector
+ vector<vector<float, 1>, 4> no;
+};
+
+vector<int, 1> get1Vec(int x)
+{
+ return x;
+}
+
+V getV()
+{
+ V v;
+
+ // Test swizzle store
+ v.oo.x.x = 1;
+
+ // Test assigning into subscript
+ v.on[0].wzyx = float4(4,3,2,1);
+
+ // Test assigning from vector
+ v.no.x = vector<float, 1>(1);
+
+ // Test assigning from scalar
+ v.no.y.x = 2;
+
+ // Test assigning from vector of vector
+ v.no.wz = vector<vector<float, 1>, 2>(3,4);
+
+ return v;
+}
+
+float sumV(V v)
+{
+ return v.oo[0][0]
+ + v.on.x.x
+ + v.on.x.y
+ + v.on.x.z
+ + v.on.x.w
+ // Test arithmetic
+ + (v.no.x + v.no.y + v.no.z + v.no.w).x;
+}
+
+float3 splat(vector<float, 1> v)
+{
+ // Test swizzle
+ return v.xxx;
+}
+
+// This function helps test that this legalization happens with generic length
+// vectors specialized to 1
+float triangle<let N : int>()
+{
+ vector<float, N> v;
+ for(int i = 0; i < N; ++i)
+ v[i] = i+1;
+
+ float ret = 0;
+ for(int i = 0; i < N; ++i)
+ ret += v[i];
+ return ret;
+}
+
+[numthreads(4, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ const V v = getV();
+ outputBuffer[dispatchThreadID.x]
+ = sumV(v)
+ + triangle<1>()
+ + splat(v.oo.x).z;
+}