diff options
| author | Yong He <yonghe@outlook.com> | 2024-11-21 14:07:23 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-21 14:07:23 -0800 |
| commit | fdf061e278720ec066a1fac8f1f35a22e817bf2d (patch) | |
| tree | db6cc05613afacdb9c67a26695355ff1b0086d79 /tests/spirv | |
| parent | dcc7c6f009afc0f55e79ced050b772ea9d3b25ae (diff) | |
Add datalayout for constant buffers. (#5608)
* Add datalayout for constant buffers.
* Fixes.
* Fix test.
* Fix glsl codegen.
* Update spirv-specific doc.
* Fix test.
* Fix binding in the presense of specialization constants.
* address comments.
* Add a test for constant buffer layout.
Diffstat (limited to 'tests/spirv')
| -rw-r--r-- | tests/spirv/constant-buffer-layout.slang | 45 | ||||
| -rw-r--r-- | tests/spirv/push-constant-layout.slang | 26 | ||||
| -rw-r--r-- | tests/spirv/spec-constant-space.slang | 17 |
3 files changed, 88 insertions, 0 deletions
diff --git a/tests/spirv/constant-buffer-layout.slang b/tests/spirv/constant-buffer-layout.slang new file mode 100644 index 000000000..90aa1eef8 --- /dev/null +++ b/tests/spirv/constant-buffer-layout.slang @@ -0,0 +1,45 @@ +//TEST:SIMPLE(filecheck=SPIRV): -target spirv -emit-spirv-directly + +//SPIRV: ArrayStride 12 + +struct Test +{ +//SPIRV: Offset 0 + uint v0; + +//SPIRV: Offset 4 +// matrix always start on a new register + float3x3 v1; +//SPIRV: Offset 40 +// Non-matrix can pack with a partially filled register + uint v2; +}; + +ConstantBuffer<Test, ScalarDataLayout> buffer; + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name outputBuffer +RWStructuredBuffer<int> outputBuffer; + +__generic<T : IArithmetic, let N : int> +bool comp(vector<T,N> v1, vector<T,N> v2) +{ + for (uint i = 0; i < N; i++) + if (v1[i] != v2[i]) + return false; + + return true; +} + +[shader("compute")] +[numthreads(2, 2, 1)] +void computeMain() +{ + // CHECK: 64 + outputBuffer[0] = (true + && buffer.v0 == 1 + && comp(buffer.v1[0], float3(2, 3, 4)) + && comp(buffer.v1[1], float3(5, 6, 7)) + && comp(buffer.v1[2], float3(8, 9, 10)) + && buffer.v2 == 11 + ) ? 100 : 0; +}
\ No newline at end of file diff --git a/tests/spirv/push-constant-layout.slang b/tests/spirv/push-constant-layout.slang new file mode 100644 index 000000000..eb7d80f75 --- /dev/null +++ b/tests/spirv/push-constant-layout.slang @@ -0,0 +1,26 @@ +//TEST:SIMPLE(filecheck=CHECK): -target spirv -fvk-use-entrypoint-name +// CHECK-NOT: std140 +struct Transform +{ + float4 Tint; + float2x2 ScaleRot; + float2 Translation; +}; + +[[vk::push_constant]] +ConstantBuffer<Transform> transform1; + +RWStructuredBuffer<float> outputBuffer; + +[numthreads(1,1,1)] +void computeMain1() +{ + outputBuffer[0] = transform1.Translation.x; +} + +[numthreads(1,1,1)] +void computeMain2( + [vk::push_constant] ConstantBuffer<Transform> transform2) +{ + outputBuffer[0] = transform2.Translation.x; +}
\ No newline at end of file diff --git a/tests/spirv/spec-constant-space.slang b/tests/spirv/spec-constant-space.slang new file mode 100644 index 000000000..b4dd865c7 --- /dev/null +++ b/tests/spirv/spec-constant-space.slang @@ -0,0 +1,17 @@ +// Test that use of specialization constants does not cause space 0 to be reserved. + +//TEST:SIMPLE(filecheck=CHECK): -target spirv + +// CHECK-NOT: DescriptorSet 1 + +struct MyData { float4 val; RWStructuredBuffer<float> outputBuffer; } + + +[vk::specialization_constant] +const int kSpecializationConstant = 0; + +[NumThreads(1,1,1)] +void main(ParameterBlock<MyData> g_data) +{ + g_data.outputBuffer[0] = g_data.val.x; +}
\ No newline at end of file |
