This commit is contained in:
2026-05-06 23:44:13 +02:00
parent a5f787d80f
commit fd7038b853
1574 changed files with 365439 additions and 0 deletions
@@ -0,0 +1,171 @@
[require]
VK_KHR_spirv_1_4
VariablePointerFeatures.variablePointersStorageBuffer
[compute shader spirv]
; Test operates on a SSBO (%in_var) containing a runtime array of an array of four ints.
; Size of the runtime array is passed another SSBO (%n_var).
; Each invocation writes out the result of OpPtrDiff
; for elements of the input runtime array to index 16 of the corresponding output
; variable. Pointers are based the gid'th element vs the zero'th element.
; Each invocation loops 4 times and writes out results each for OpPtrDiff.
; The pointers are the lid'th element of gid'th element of
; the runtime array vs the iteration count element of the gid'th element of
; the runtime array.
OpCapability Shader
OpCapability VariablePointersStorageBuffer
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %in_var %diff_var %n_var %lid_var %gid_var
OpExecutionMode %main LocalSize 4 1 1
OpDecorate %struct_4 Block
OpMemberDecorate %struct_4 0 Offset 0
OpDecorate %runtime_4 ArrayStride 16
OpDecorate %struct_17 Block
OpMemberDecorate %struct_17 0 Offset 0
OpDecorate %runtime_17 ArrayStride 68
OpDecorate %n_struct Block
OpMemberDecorate %n_struct 0 Offset 0
OpDecorate %array_4 ArrayStride 4
OpDecorate %array_17 ArrayStride 4
OpDecorate %in_var DescriptorSet 0
OpDecorate %in_var Binding 0
OpDecorate %diff_var DescriptorSet 0
OpDecorate %diff_var Binding 1
OpDecorate %n_var DescriptorSet 0
OpDecorate %n_var Binding 2
OpDecorate %lid_var BuiltIn LocalInvocationId
OpDecorate %gid_var BuiltIn WorkgroupId
%void = OpTypeVoid
%bool = OpTypeBool
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_4 = OpConstant %int 4
%int_16 = OpConstant %int 16
%int_17 = OpConstant %int 17
%int3 = OpTypeVector %int 3
%ptr_input_int3 = OpTypePointer Input %int3
%array_4 = OpTypeArray %int %int_4
%runtime_4 = OpTypeRuntimeArray %array_4
%struct_4 = OpTypeStruct %runtime_4
%ptr_struct_4 = OpTypePointer StorageBuffer %struct_4
%ptr_array_4 = OpTypePointer StorageBuffer %array_4
%array_17 = OpTypeArray %int %int_17
%runtime_17 = OpTypeRuntimeArray %array_17
%struct_17 = OpTypeStruct %runtime_17
%ptr_struct_17 = OpTypePointer StorageBuffer %struct_17
%ptr_array_17 = OpTypePointer StorageBuffer %array_17
%ptr_int = OpTypePointer StorageBuffer %int
%n_struct = OpTypeStruct %int
%ptr_n_struct = OpTypePointer Uniform %n_struct
%ptr_n = OpTypePointer Uniform %int
%in_var = OpVariable %ptr_struct_4 StorageBuffer
%diff_var = OpVariable %ptr_struct_17 StorageBuffer
%n_var = OpVariable %ptr_n_struct Uniform
%lid_var = OpVariable %ptr_input_int3 Input
%gid_var = OpVariable %ptr_input_int3 Input
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
%n_gep = OpAccessChain %ptr_n %n_var %int_0
%n = OpLoad %int %n_gep
%gid = OpLoad %int3 %gid_var
%gid_x = OpCompositeExtract %int %gid 0
%lid = OpLoad %int3 %lid_var
%lid_x = OpCompositeExtract %int %lid 0
%array_gep_0 = OpAccessChain %ptr_array_4 %in_var %int_0 %int_0
%array_gep = OpAccessChain %ptr_array_4 %in_var %int_0 %gid_x
%cmp_gid = OpSGreaterThanEqual %bool %gid_x %n
OpSelectionMerge %body None
OpBranchConditional %cmp_gid %ret %body
%ret = OpLabel
OpReturn
%body = OpLabel
%cmp_lid = OpIEqual %bool %lid_x %int_1
OpSelectionMerge %loop None
OpBranchConditional %cmp_lid %then %loop
%then = OpLabel
; Compute results for outer array
%large_diff = OpPtrDiff %int %array_gep %array_gep_0
%large_diff_gep = OpAccessChain %ptr_int %diff_var %int_0 %gid_x %int_16
OpStore %large_diff_gep %large_diff
;
OpBranch %loop
%loop = OpLabel
%i = OpPhi %int %int_0 %body %int_0 %then %inc_i %loop
%inc_i = OpIAdd %int %i %int_1
%i_cmp = OpIEqual %bool %inc_i %int_4
%lid_offset = OpIMul %int %lid_x %int_4
%gep_offset = OpIAdd %int %lid_offset %i
; Compute results for inner array
%ref_gep = OpAccessChain %ptr_int %array_gep %lid_x
%cmp_gep = OpAccessChain %ptr_int %array_gep %i
%diff = OpPtrDiff %int %ref_gep %cmp_gep
%diff_gep = OpAccessChain %ptr_int %diff_var %int_0 %gid_x %gep_offset
OpStore %diff_gep %diff
;
OpLoopMerge %exit %loop None
OpBranchConditional %i_cmp %exit %loop
%exit = OpLabel
OpReturn
OpFunctionEnd
[test]
ssbo 0:0 2048
ssbo 0:1 2176
uniform ubo 0:2 int 0 32
compute entrypoint main
compute 32 1 1
# diff var
probe ssbo int 0:1 0 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 0
probe ssbo int 0:1 68 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 1
probe ssbo int 0:1 136 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 2
probe ssbo int 0:1 204 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 3
probe ssbo int 0:1 272 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 4
probe ssbo int 0:1 340 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 5
probe ssbo int 0:1 408 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 6
probe ssbo int 0:1 476 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 7
probe ssbo int 0:1 544 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 8
probe ssbo int 0:1 612 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 9
probe ssbo int 0:1 680 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 10
probe ssbo int 0:1 748 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 11
probe ssbo int 0:1 816 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 12
probe ssbo int 0:1 884 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 13
probe ssbo int 0:1 952 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 14
probe ssbo int 0:1 1020 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 15
probe ssbo int 0:1 1088 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 16
probe ssbo int 0:1 1156 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 17
probe ssbo int 0:1 1224 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 18
probe ssbo int 0:1 1292 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 19
probe ssbo int 0:1 1360 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 20
probe ssbo int 0:1 1428 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 21
probe ssbo int 0:1 1496 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 22
probe ssbo int 0:1 1564 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 23
probe ssbo int 0:1 1632 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 24
probe ssbo int 0:1 1700 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 25
probe ssbo int 0:1 1768 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 26
probe ssbo int 0:1 1836 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 27
probe ssbo int 0:1 1904 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 28
probe ssbo int 0:1 1972 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 29
probe ssbo int 0:1 2040 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 30
probe ssbo int 0:1 2108 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 31
@@ -0,0 +1,153 @@
[require]
VK_KHR_spirv_1_4
VariablePointerFeatures.variablePointersStorageBuffer
[compute shader spirv]
; Tests pointer comparisons with variable pointers
; Stores an array of pointers in Function storage class that point into input
; SSBO. Each iteration produces an int2 result containing two OpPtrDiffs
; Pointers evolve by incrementing or decrementing by 1 each iteration (overall
; ratio is 2:1).
; All uses of OpPtrDiff are within %in_var, so we only need
; VariablePointersStorageBuffer capability and the corresponding Vulkan
; feature bit.
OpCapability Shader
OpCapability VariablePointersStorageBuffer
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %in_var %out_var
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %int_rta ArrayStride 4
OpDecorate %in_struct Block
OpMemberDecorate %in_struct 0 Offset 0
OpMemberDecorate %in_struct 1 Offset 4
OpDecorate %in_var DescriptorSet 0
OpDecorate %in_var Binding 0
OpDecorate %int2_rta ArrayStride 8
OpDecorate %out_struct Block
OpMemberDecorate %out_struct 0 Offset 0
OpDecorate %out_var DescriptorSet 0
OpDecorate %out_var Binding 1
OpDecorate %ptr_ssbo_int ArrayStride 4
%void = OpTypeVoid
%bool = OpTypeBool
%uint = OpTypeInt 32 0
%int = OpTypeInt 32 1
%int_n1 = OpConstant %int -1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%int2 = OpTypeVector %int 2
%int_rta = OpTypeRuntimeArray %int
%in_struct = OpTypeStruct %int %int_rta
%ptr_ssbo_in_struct = OpTypePointer StorageBuffer %in_struct
%in_var = OpVariable %ptr_ssbo_in_struct StorageBuffer
%int2_rta = OpTypeRuntimeArray %int2
%out_struct = OpTypeStruct %int2_rta
%ptr_ssbo_out_struct = OpTypePointer StorageBuffer %out_struct
%out_var = OpVariable %ptr_ssbo_out_struct StorageBuffer
%ptr_ssbo_int = OpTypePointer StorageBuffer %int
%array_ptr = OpTypeArray %ptr_ssbo_int %int_2
%ptr_ptr = OpTypePointer Function %array_ptr
%ptr_func_ptr = OpTypePointer Function %ptr_ssbo_int
%ptr_ssbo_n = OpTypePointer StorageBuffer %int
%ptr_ssbo_int2 = OpTypePointer StorageBuffer %int2
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
%var = OpVariable %ptr_ptr Function
%n_gep = OpAccessChain %ptr_ssbo_n %in_var %int_0
%n = OpLoad %int %n_gep
%length = OpArrayLength %uint %in_var 1
%length_div_2 = OpSDiv %int %length %int_2
%mid_gep = OpAccessChain %ptr_ssbo_int %in_var %int_1 %length_div_2
%func_gep_0 = OpAccessChain %ptr_func_ptr %var %int_0
%func_gep_1 = OpAccessChain %ptr_func_ptr %var %int_1
OpStore %func_gep_0 %mid_gep
OpStore %func_gep_1 %mid_gep
%cmp_n = OpSLessThanEqual %bool %n %int_0
OpSelectionMerge %exit None
OpBranchConditional %cmp_n %exit %loop
%loop = OpLabel
%i = OpPhi %int %int_0 %entry %inc_i %continue
%gep_0 = OpLoad %ptr_ssbo_int %func_gep_0
%gep_1 = OpLoad %ptr_ssbo_int %func_gep_1
%inc_i = OpIAdd %int %i %int_1
%diff1 = OpPtrDiff %int %gep_0 %gep_1
%diff2 = OpPtrDiff %int %gep_1 %gep_0
%result = OpCompositeConstruct %int2 %diff1 %diff2
%out_gep = OpAccessChain %ptr_ssbo_int2 %out_var %int_0 %i
OpStore %out_gep %result
OpLoopMerge %loop_exit %continue None
OpBranch %body
%body = OpLabel
%i_mod_3 = OpSMod %int %i %int_3
%cmp_vs_0 = OpIEqual %bool %i_mod_3 %int_0
OpSelectionMerge %if_merge None
OpBranchConditional %cmp_vs_0 %then %else
%then = OpLabel
%then_0_next = OpPtrAccessChain %ptr_ssbo_int %gep_0 %int_n1
%then_1_next = OpPtrAccessChain %ptr_ssbo_int %gep_1 %int_1
OpBranch %if_merge
%else = OpLabel
%else_0_next = OpPtrAccessChain %ptr_ssbo_int %gep_0 %int_1
%else_1_next = OpPtrAccessChain %ptr_ssbo_int %gep_1 %int_n1
OpBranch %if_merge
%if_merge = OpLabel
%next_0 = OpPhi %ptr_ssbo_int %then_0_next %then %else_0_next %else
%next_1 = OpPhi %ptr_ssbo_int %then_1_next %then %else_1_next %else
OpBranch %continue
%continue = OpLabel
OpStore %func_gep_0 %next_0
OpStore %func_gep_1 %next_1
%cmp = OpSGreaterThanEqual %bool %i %n
OpBranchConditional %cmp %loop_exit %loop
%loop_exit = OpLabel
OpBranch %exit
%exit = OpLabel
OpReturn
OpFunctionEnd
[test]
ssbo 0:0 68
ssbo 0:0 subdata uint 0 16
ssbo 0:1 128
compute entrypoint main
compute 1 1 1
probe ssbo int 0:1 0 == 0 0
probe ssbo int 0:1 8 == -2 2
probe ssbo int 0:1 16 == 0 0
probe ssbo int 0:1 24 == 2 -2
probe ssbo int 0:1 32 == 0 0
probe ssbo int 0:1 40 == 2 -2
probe ssbo int 0:1 48 == 4 -4
probe ssbo int 0:1 56 == 2 -2
probe ssbo int 0:1 64 == 4 -4
probe ssbo int 0:1 72 == 6 -6
probe ssbo int 0:1 80 == 4 -4
probe ssbo int 0:1 88 == 6 -6
probe ssbo int 0:1 96 == 8 -8
probe ssbo int 0:1 104 == 6 -6
probe ssbo int 0:1 112 == 8 -8
probe ssbo int 0:1 120 == 10 -10
@@ -0,0 +1,141 @@
[require]
VK_KHR_spirv_1_4
VariablePointerFeatures.variablePointersStorageBuffer
[compute shader spirv]
; Tests use of private variables holding SSBO pointers and pointer comparisons.
; Two iterators are each stored in Private variables: one moves forward, one
; moves backward. In each iteration an int2 result is written that contains two
; diffs. Iterators are then moved forward (or backward respectively) one index.
OpCapability Shader
OpCapability VariablePointersStorageBuffer
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %in_var %out_var %forward_var %backward_var
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %int_rta ArrayStride 4
OpDecorate %in_struct Block
OpMemberDecorate %in_struct 0 Offset 0
OpMemberDecorate %in_struct 1 Offset 4
OpDecorate %in_var DescriptorSet 0
OpDecorate %in_var Binding 0
OpDecorate %int2_rta ArrayStride 8
OpDecorate %out_struct Block
OpMemberDecorate %out_struct 0 Offset 0
OpDecorate %out_var DescriptorSet 0
OpDecorate %out_var Binding 1
OpDecorate %ptr_ssbo_int ArrayStride 4
%void = OpTypeVoid
%bool = OpTypeBool
%int = OpTypeInt 32 1
%int_n1 = OpConstant %int -1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%int2 = OpTypeVector %int 2
%int_rta = OpTypeRuntimeArray %int
%in_struct = OpTypeStruct %int %int_rta
%ptr_ssbo_in_struct = OpTypePointer StorageBuffer %in_struct
%in_var = OpVariable %ptr_ssbo_in_struct StorageBuffer
%int2_rta = OpTypeRuntimeArray %int2
%out_struct = OpTypeStruct %int2_rta
%ptr_ssbo_out_struct = OpTypePointer StorageBuffer %out_struct
%out_var = OpVariable %ptr_ssbo_out_struct StorageBuffer
%ptr_ssbo_int = OpTypePointer StorageBuffer %int
%ptr_ptr = OpTypePointer Private %ptr_ssbo_int
%forward_var = OpVariable %ptr_ptr Private
%backward_var = OpVariable %ptr_ptr Private
%ptr_ssbo_n = OpTypePointer StorageBuffer %int
%ptr_ssbo_int2 = OpTypePointer StorageBuffer %int2
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
%n_gep = OpAccessChain %ptr_ssbo_n %in_var %int_0
%n = OpLoad %int %n_gep
%first_gep = OpAccessChain %ptr_ssbo_int %in_var %int_1 %int_0
OpStore %forward_var %first_gep
%last_gep = OpPtrAccessChain %ptr_ssbo_int %first_gep %n
OpStore %backward_var %last_gep
%cmp_n = OpSLessThanEqual %bool %n %int_0
OpSelectionMerge %exit None
OpBranchConditional %cmp_n %exit %loop
%loop = OpLabel
%i = OpPhi %int %int_0 %entry %inc_i %loop
%forward_gep = OpLoad %ptr_ssbo_int %forward_var
%backward_gep = OpLoad %ptr_ssbo_int %backward_var
%forward_next = OpPtrAccessChain %ptr_ssbo_int %forward_gep %int_1
%backward_next = OpPtrAccessChain %ptr_ssbo_int %backward_gep %int_n1
%inc_i = OpIAdd %int %i %int_1
OpStore %forward_var %forward_next
OpStore %backward_var %backward_next
%diff1 = OpPtrDiff %int %forward_gep %backward_gep
%diff2 = OpPtrDiff %int %backward_gep %forward_gep
%result = OpCompositeConstruct %int2 %diff1 %diff2
%out_gep = OpAccessChain %ptr_ssbo_int2 %out_var %int_0 %i
OpStore %out_gep %result
%cmp = OpSGreaterThanEqual %bool %i %n
OpLoopMerge %loop_exit %loop None
OpBranchConditional %cmp %loop_exit %loop
%loop_exit = OpLabel
OpBranch %exit
%exit = OpLabel
OpReturn
OpFunctionEnd
[test]
ssbo 0:0 132
# Only data for number of iterations matters.
ssbo 0:0 subdata int 0 33
ssbo 0:1 264
compute entrypoint main
compute 1 1 1
probe ssbo ivec2 0:1 0 == -33 33
probe ssbo ivec2 0:1 8 == -31 31
probe ssbo ivec2 0:1 16 == -29 29
probe ssbo ivec2 0:1 24 == -27 27
probe ssbo ivec2 0:1 32 == -25 25
probe ssbo ivec2 0:1 40 == -23 23
probe ssbo ivec2 0:1 48 == -21 21
probe ssbo ivec2 0:1 56 == -19 19
probe ssbo ivec2 0:1 64 == -17 17
probe ssbo ivec2 0:1 72 == -15 15
probe ssbo ivec2 0:1 80 == -13 13
probe ssbo ivec2 0:1 88 == -11 11
probe ssbo ivec2 0:1 96 == -9 9
probe ssbo ivec2 0:1 104 == -7 7
probe ssbo ivec2 0:1 112 == -5 5
probe ssbo ivec2 0:1 120 == -3 3
probe ssbo ivec2 0:1 128 == -1 1
probe ssbo ivec2 0:1 136 == 1 -1
probe ssbo ivec2 0:1 144 == 3 -3
probe ssbo ivec2 0:1 152 == 5 -5
probe ssbo ivec2 0:1 160 == 7 -7
probe ssbo ivec2 0:1 168 == 9 -9
probe ssbo ivec2 0:1 176 == 11 -11
probe ssbo ivec2 0:1 184 == 13 -13
probe ssbo ivec2 0:1 192 == 15 -15
probe ssbo ivec2 0:1 200 == 17 -17
probe ssbo ivec2 0:1 208 == 19 -19
probe ssbo ivec2 0:1 216 == 21 -21
probe ssbo ivec2 0:1 224 == 23 -23
probe ssbo ivec2 0:1 232 == 25 -25
probe ssbo ivec2 0:1 240 == 27 -27
probe ssbo ivec2 0:1 248 == 29 -29
probe ssbo ivec2 0:1 256 == 31 -31
@@ -0,0 +1,126 @@
[require]
VK_KHR_spirv_1_4
VariablePointerFeatures.variablePointersStorageBuffer
VariablePointerFeatures.variablePointers
[compute shader spirv]
; Tests use of private variables holding workgroup pointers and pointer comparisons.
; Two iterators are each stored in Private variables: one moves forward, one
; moves backward. In each iteration an int2 result is written that contains
; two diffs (operands swapped). Iterators are then moved forward (or backward
; respectively) one index.
OpCapability Shader
OpCapability VariablePointers
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %wg_var %out_var %forward_var %backward_var
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %int2_rta ArrayStride 8
OpDecorate %out_struct Block
OpMemberDecorate %out_struct 0 Offset 0
OpDecorate %out_var DescriptorSet 0
OpDecorate %out_var Binding 0
OpDecorate %ptr_wg_int ArrayStride 4
%void = OpTypeVoid
%bool = OpTypeBool
%int = OpTypeInt 32 1
%int_n1 = OpConstant %int -1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%int_32 = OpConstant %int 32
%int2 = OpTypeVector %int 2
%int_array_32 = OpTypeArray %int %int_32
%ptr_wg_array = OpTypePointer Workgroup %int_array_32
%wg_var = OpVariable %ptr_wg_array Workgroup
%int2_rta = OpTypeRuntimeArray %int2
%out_struct = OpTypeStruct %int2_rta
%ptr_ssbo_out_struct = OpTypePointer StorageBuffer %out_struct
%out_var = OpVariable %ptr_ssbo_out_struct StorageBuffer
%ptr_wg_int = OpTypePointer Workgroup %int
%ptr_ptr = OpTypePointer Private %ptr_wg_int
%forward_var = OpVariable %ptr_ptr Private
%backward_var = OpVariable %ptr_ptr Private
%ptr_ssbo_int2 = OpTypePointer StorageBuffer %int2
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
%first_gep = OpAccessChain %ptr_wg_int %wg_var %int_0
OpStore %forward_var %first_gep
%last_gep = OpPtrAccessChain %ptr_wg_int %first_gep %int_32
OpStore %backward_var %last_gep
OpBranch %loop
%loop = OpLabel
%i = OpPhi %int %int_0 %entry %inc_i %loop
%forward_gep = OpLoad %ptr_wg_int %forward_var
%backward_gep = OpLoad %ptr_wg_int %backward_var
%forward_next = OpPtrAccessChain %ptr_wg_int %forward_gep %int_1
%backward_next = OpPtrAccessChain %ptr_wg_int %backward_gep %int_n1
%inc_i = OpIAdd %int %i %int_1
OpStore %forward_var %forward_next
OpStore %backward_var %backward_next
%diff1 = OpPtrDiff %int %forward_gep %backward_gep
%diff2 = OpPtrDiff %int %backward_gep %forward_gep
%result = OpCompositeConstruct %int2 %diff1 %diff2
%out_gep = OpAccessChain %ptr_ssbo_int2 %out_var %int_0 %i
OpStore %out_gep %result
%cmp = OpSGreaterThan %bool %i %int_32
OpLoopMerge %exit %loop None
OpBranchConditional %cmp %exit %loop
%exit = OpLabel
OpReturn
OpFunctionEnd
[test]
ssbo 0:0 264
compute entrypoint main
compute 1 1 1
probe ssbo ivec2 0:0 0 == -32 32
probe ssbo ivec2 0:0 8 == -30 30
probe ssbo ivec2 0:0 16 == -28 28
probe ssbo ivec2 0:0 24 == -26 26
probe ssbo ivec2 0:0 32 == -24 24
probe ssbo ivec2 0:0 40 == -22 22
probe ssbo ivec2 0:0 48 == -20 20
probe ssbo ivec2 0:0 56 == -18 18
probe ssbo ivec2 0:0 64 == -16 16
probe ssbo ivec2 0:0 72 == -14 14
probe ssbo ivec2 0:0 80 == -12 12
probe ssbo ivec2 0:0 88 == -10 10
probe ssbo ivec2 0:0 96 == -8 8
probe ssbo ivec2 0:0 104 == -6 6
probe ssbo ivec2 0:0 112 == -4 4
probe ssbo ivec2 0:0 120 == -2 2
probe ssbo ivec2 0:0 128 == 0 0
probe ssbo ivec2 0:0 136 == 2 -2
probe ssbo ivec2 0:0 144 == 4 -4
probe ssbo ivec2 0:0 152 == 6 -6
probe ssbo ivec2 0:0 160 == 8 -8
probe ssbo ivec2 0:0 168 == 10 -10
probe ssbo ivec2 0:0 176 == 12 -12
probe ssbo ivec2 0:0 184 == 14 -14
probe ssbo ivec2 0:0 192 == 16 -16
probe ssbo ivec2 0:0 200 == 18 -18
probe ssbo ivec2 0:0 208 == 20 -20
probe ssbo ivec2 0:0 216 == 22 -22
probe ssbo ivec2 0:0 224 == 24 -24
probe ssbo ivec2 0:0 232 == 26 -26
probe ssbo ivec2 0:0 240 == 28 -28
probe ssbo ivec2 0:0 248 == 30 -30
probe ssbo ivec2 0:0 256 == 32 -32
@@ -0,0 +1,155 @@
[require]
VK_KHR_spirv_1_4
VariablePointerFeatures.variablePointersStorageBuffer
VariablePointerFeatures.variablePointers
[compute shader spirv]
; Test operates on a Workgroup array (%wg_var) containing an array of 16 arrays of four ints.
; Each invocation writes out the result of OpPtrDiff for elements of the
; outer array to index 16 of the corresponding output variable. Pointers are
; based the gid'th element vs the zero'th element.
; Each invocation loops 4 times and writes out 4 results each for OpPtrDiff.
; The pointers are the lid'th element of gid'th element of the outer array vs
; the iteration count mod 4'th element of the gid'th element of the outer
; array. Results are ordered so each thread writes continguous results.
OpCapability Shader
OpCapability VariablePointers
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main" %wg_var %diff_var %lid_var %gid_var
OpExecutionMode %main LocalSize 16 4 1
OpDecorate %struct_17 Block
OpMemberDecorate %struct_17 0 Offset 0
OpDecorate %runtime_17 ArrayStride 68
OpDecorate %array_17 ArrayStride 4
OpDecorate %diff_var DescriptorSet 0
OpDecorate %diff_var Binding 0
OpDecorate %lid_var BuiltIn LocalInvocationId
OpDecorate %gid_var BuiltIn GlobalInvocationId
%void = OpTypeVoid
%bool = OpTypeBool
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%int_4 = OpConstant %int 4
%int_16 = OpConstant %int 16
%int_17 = OpConstant %int 17
%int_64 = OpConstant %int 64
%int3 = OpTypeVector %int 3
%ptr_input_int3 = OpTypePointer Input %int3
%array_4 = OpTypeArray %int %int_4
%array_array_4 = OpTypeArray %array_4 %int_16
%ptr_array_array_4 = OpTypePointer Workgroup %array_array_4
%ptr_array_4 = OpTypePointer Workgroup %array_4
%ptr_wg_int = OpTypePointer Workgroup %int
%array_17 = OpTypeArray %int %int_17
%runtime_17 = OpTypeRuntimeArray %array_17
%struct_17 = OpTypeStruct %runtime_17
%ptr_struct_17 = OpTypePointer StorageBuffer %struct_17
%ptr_array_17 = OpTypePointer StorageBuffer %array_17
%ptr_int = OpTypePointer StorageBuffer %int
%wg_var = OpVariable %ptr_array_array_4 Workgroup
%diff_var = OpVariable %ptr_struct_17 StorageBuffer
%lid_var = OpVariable %ptr_input_int3 Input
%gid_var = OpVariable %ptr_input_int3 Input
%void_fn = OpTypeFunction %void
%main = OpFunction %void None %void_fn
%entry = OpLabel
%gid = OpLoad %int3 %gid_var
%gid_x = OpCompositeExtract %int %gid 0
%gid_y = OpCompositeExtract %int %gid 1
%lid = OpLoad %int3 %lid_var
%lid_x = OpCompositeExtract %int %lid 0
%lid_y = OpCompositeExtract %int %lid 1
%array_gep_0 = OpAccessChain %ptr_array_4 %wg_var %int_0
%array_gep = OpAccessChain %ptr_array_4 %wg_var %lid_x
%lid_y_is_1 = OpIEqual %bool %lid_y %int_1
OpSelectionMerge %loop None
OpBranchConditional %lid_y_is_1 %then %loop
%then = OpLabel
; Compute results for outer array
%large_diff = OpPtrDiff %int %array_gep %array_gep_0
%large_diff_gep = OpAccessChain %ptr_int %diff_var %int_0 %gid_x %int_16
OpStore %large_diff_gep %large_diff
;
OpBranch %loop
%loop = OpLabel
%i = OpPhi %int %int_0 %entry %int_0 %then %inc_i %loop
%inc_i = OpIAdd %int %i %int_1
%i_cmp = OpIEqual %bool %inc_i %int_4
%lid_offset = OpIMul %int %lid_y %int_4
%out_gep_index = OpIAdd %int %i %lid_offset
; Compute results for inner array
%ref_gep = OpAccessChain %ptr_wg_int %array_gep %lid_y
%cmp_gep = OpAccessChain %ptr_wg_int %array_gep %i
%diff = OpPtrDiff %int %ref_gep %cmp_gep
%diff_gep = OpAccessChain %ptr_int %diff_var %int_0 %gid_x %out_gep_index
OpStore %diff_gep %diff
;
OpLoopMerge %exit %loop None
OpBranchConditional %i_cmp %exit %loop
%exit = OpLabel
OpReturn
OpFunctionEnd
[test]
# 16 x 4 x 2 = 128 work items
# 4 x 4 = 16 bytes per invocation
# 2048 bytes from looping
# 16 x 2 = 32 coarse results (1 per lid)
# 128 bytes
# 2176 total bytes
ssbo 0:0 2176
compute entrypoint main
compute 2 1 1
# diff var
probe ssbo int 0:0 0 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 0
probe ssbo int 0:0 68 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 1
probe ssbo int 0:0 136 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 2
probe ssbo int 0:0 204 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 3
probe ssbo int 0:0 272 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 4
probe ssbo int 0:0 340 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 5
probe ssbo int 0:0 408 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 6
probe ssbo int 0:0 476 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 7
probe ssbo int 0:0 544 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 8
probe ssbo int 0:0 612 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 9
probe ssbo int 0:0 680 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 10
probe ssbo int 0:0 748 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 11
probe ssbo int 0:0 816 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 12
probe ssbo int 0:0 884 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 13
probe ssbo int 0:0 952 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 14
probe ssbo int 0:0 1020 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 15
probe ssbo int 0:0 1088 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 0
probe ssbo int 0:0 1156 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 1
probe ssbo int 0:0 1224 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 2
probe ssbo int 0:0 1292 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 3
probe ssbo int 0:0 1360 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 4
probe ssbo int 0:0 1428 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 5
probe ssbo int 0:0 1496 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 6
probe ssbo int 0:0 1564 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 7
probe ssbo int 0:0 1632 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 8
probe ssbo int 0:0 1700 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 9
probe ssbo int 0:0 1768 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 10
probe ssbo int 0:0 1836 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 11
probe ssbo int 0:0 1904 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 12
probe ssbo int 0:0 1972 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 13
probe ssbo int 0:0 2040 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 14
probe ssbo int 0:0 2108 == 0 -1 -2 -3 1 0 -1 -2 2 1 0 -1 3 2 1 0 15