Add tests for OpPtrAccessChain on Workgroup storage
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / data / vulkan / amber / spirv_assembly / instruction / compute / ptr_access_chain / workgroup_no_stride.amber
1 # Test OpPtrAccessChain applied to workgroup memory.
2 #
3 # Derived from the following OpenCL C:
4 #
5 #int get_data(local int *d);
6 #
7 #int get_data(local int *d) {
8 #   return d[1];
9 #}
10 #
11 #kernel void foo(global int *A, global int*B, global int*C) __attribute__((reqd_work_group_size(16,1,1))) {
12 #   local int data[17];
13 #   uint i = get_local_id(0);
14 #   data[i] = A[i] * B[i];
15 #
16 #   if (i == 0) data[16] = 0;
17 #
18 #   C[i] = get_data(&data[i]);
19 #}
20 #
21 # Compiled with `clspv -no-inline-single -cl-opt-disable <X.clc>`
22
23 [compute shader spirv]
24                OpCapability Shader
25                OpCapability VariablePointers
26                OpExtension "SPV_KHR_storage_buffer_storage_class"
27                OpExtension "SPV_KHR_variable_pointers"
28                OpMemoryModel Logical GLSL450
29                OpEntryPoint GLCompute %30 "main" %gl_LocalInvocationID
30                OpExecutionMode %30 LocalSize 16 1 1
31                OpSource OpenCL_C 120
32                OpDecorate %_runtimearr_uint ArrayStride 4
33                OpMemberDecorate %_struct_3 0 Offset 0
34                OpDecorate %_struct_3 Block
35                OpDecorate %gl_LocalInvocationID BuiltIn LocalInvocationId
36                OpDecorate %22 DescriptorSet 0
37                OpDecorate %22 Binding 0
38                OpDecorate %23 DescriptorSet 0
39                OpDecorate %23 Binding 1
40                OpDecorate %24 DescriptorSet 0
41                OpDecorate %24 Binding 2
42                OpDecorate %_arr_uint_uint_17 ArrayStride 4
43        %uint = OpTypeInt 32 0
44 %_runtimearr_uint = OpTypeRuntimeArray %uint
45   %_struct_3 = OpTypeStruct %_runtimearr_uint
46 %_ptr_StorageBuffer__struct_3 = OpTypePointer StorageBuffer %_struct_3
47 %_ptr_Workgroup_uint = OpTypePointer Workgroup %uint
48           %6 = OpTypeFunction %uint %_ptr_Workgroup_uint
49        %void = OpTypeVoid
50           %8 = OpTypeFunction %void
51      %v3uint = OpTypeVector %uint 3
52 %_ptr_Input_v3uint = OpTypePointer Input %v3uint
53 %_ptr_Input_uint = OpTypePointer Input %uint
54 %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
55     %uint_17 = OpConstant %uint 17
56 %_arr_uint_uint_17 = OpTypeArray %uint %uint_17
57 %_ptr_Workgroup__arr_uint_uint_17 = OpTypePointer Workgroup %_arr_uint_uint_17
58        %bool = OpTypeBool
59      %uint_1 = OpConstant %uint 1
60      %uint_0 = OpConstant %uint 0
61     %uint_16 = OpConstant %uint 16
62          %20 = OpVariable %_ptr_Workgroup__arr_uint_uint_17 Workgroup
63 %gl_LocalInvocationID = OpVariable %_ptr_Input_v3uint Input
64          %22 = OpVariable %_ptr_StorageBuffer__struct_3 StorageBuffer
65          %23 = OpVariable %_ptr_StorageBuffer__struct_3 StorageBuffer
66          %24 = OpVariable %_ptr_StorageBuffer__struct_3 StorageBuffer
67          %25 = OpFunction %uint Pure %6
68          %26 = OpFunctionParameter %_ptr_Workgroup_uint
69          %27 = OpLabel
70          %28 = OpPtrAccessChain %_ptr_Workgroup_uint %26 %uint_1
71          %29 = OpLoad %uint %28
72                OpReturnValue %29
73                OpFunctionEnd
74          %30 = OpFunction %void None %8
75          %31 = OpLabel
76          %32 = OpAccessChain %_ptr_Input_uint %gl_LocalInvocationID %uint_0
77          %33 = OpLoad %uint %32
78          %34 = OpAccessChain %_ptr_StorageBuffer_uint %22 %uint_0 %33
79          %35 = OpLoad %uint %34
80          %36 = OpAccessChain %_ptr_StorageBuffer_uint %23 %uint_0 %33
81          %37 = OpLoad %uint %36
82          %38 = OpIMul %uint %37 %35
83          %39 = OpAccessChain %_ptr_Workgroup_uint %20 %33
84                OpStore %39 %38
85          %40 = OpIEqual %bool %33 %uint_0
86                OpSelectionMerge %43 None
87                OpBranchConditional %40 %41 %43
88          %41 = OpLabel
89          %42 = OpAccessChain %_ptr_Workgroup_uint %20 %uint_16
90                OpStore %42 %uint_0
91                OpBranch %43
92          %43 = OpLabel
93          %44 = OpFunctionCall %uint %25 %39
94          %45 = OpAccessChain %_ptr_StorageBuffer_uint %24 %uint_0 %33
95                OpStore %45 %44
96                OpReturn
97                OpFunctionEnd
98
99 [test]
100 # A[]
101 ssbo 0:0 subdata int 0  0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
102 # B[]
103 ssbo 0:1 subdata int 0  1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
104 # The answer array C[]
105 ssbo 0:2 subdata int 0  -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
106
107 compute 1 1 1
108
109 probe ssbo int 0:2 0 ==  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 0