blob: 22f93bcd1dde76af078f52be61605dd9b70be7d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
//TEST:SIMPLE(filecheck=CUDA): -target cuda -entry compute_main -stage compute
//TEST:SIMPLE(filecheck=SPV): -target spirv
// Test that we can defer loading big structured buffer elements.
struct Bottom
{
float bigArray[1024];
float bottomGetValue(int index) { return bigArray[index]; }
}
struct Root
{
Bottom bottom;
}
StructuredBuffer<Root> sb;
RWStructuredBuffer<float> outputBuffer;
// Check that we don't load the entire `Root` struct and then do ElementExtract to get to `bigArray[0]`.
// Instead we use access chain all the way to point to the required array element, and load just a single float.
// SPV: OpEntryPoint
// SPV: %[[SBPTRARRAY:[A-Za-z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer__arr_float_int_1024
// SPV: %[[SBPTR:[A-Za-z0-9_]+]] = OpAccessChain %_ptr_StorageBuffer_float %[[SBPTRARRAY]]
// SPV: %[[VALUE:[A-Za-z0-9_]+]] = OpLoad %float %[[SBPTR]]
// SPV: OpStore %{{.*}} %[[VALUE]]
// CUDA: __device__ float Bottom_bottomGetValue{{.*}}(uint [[PARAM0:[A-Za-z0-9_]+]], int [[PARAM1:[A-Za-z0-9_]+]])
// CUDA: __ldg(&(&(&(globalParams_0->sb_0){{\[}}[[PARAM0]]{{\]}})->bottom_0)->bigArray_0{{\[}}[[PARAM1]]{{\]}});
[shader("compute")]
[numthreads(1, 1, 1)]
void compute_main(uint3 tid: SV_DispatchThreadID)
{
outputBuffer[0] = sb[tid.x].bottom.bottomGetValue(0);
}
|