| 1 |
// Copyright (c) 2019 Valve Corporation |
| 2 |
// Copyright (c) 2019 LunarG Inc. |
| 3 |
// |
| 4 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
// you may not use this file except in compliance with the License. |
| 6 |
// You may obtain a copy of the License at |
| 7 |
// |
| 8 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
// |
| 10 |
// Unless required by applicable law or agreed to in writing, software |
| 11 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
// See the License for the specific language governing permissions and |
| 14 |
// limitations under the License. |
| 15 |
|
| 16 |
// Bindless Check Instrumentation Tests. |
| 17 |
// Tests ending with V2 use version 2 record format. |
| 18 |
|
| 19 |
#include <string> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
#include "test/opt/assembly_builder.h" |
| 23 |
#include "test/opt/pass_fixture.h" |
| 24 |
#include "test/opt/pass_utils.h" |
| 25 |
|
| 26 |
namespace spvtools { |
| 27 |
namespace opt { |
| 28 |
namespace { |
| 29 |
|
| 30 |
using InstBuffAddrTest = PassTest<::testing::Test>; |
| 31 |
|
| 32 |
TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferStore) { |
| 33 |
// #version 450 |
| 34 |
// #extension GL_EXT_buffer_reference : enable |
| 35 |
// |
| 36 |
// layout(buffer_reference, buffer_reference_align = 16) buffer bufStruct; |
| 37 |
// |
| 38 |
// layout(set = 0, binding = 0) uniform ufoo { |
| 39 |
// bufStruct data; |
| 40 |
// uint offset; |
| 41 |
// } u_info; |
| 42 |
// |
| 43 |
// layout(buffer_reference, std140) buffer bufStruct { |
| 44 |
// layout(offset = 0) int a[2]; |
| 45 |
// layout(offset = 32) int b; |
| 46 |
// }; |
| 47 |
// |
| 48 |
// void main() { |
| 49 |
// u_info.data.b = 0xca7; |
| 50 |
// } |
| 51 |
|
| 52 |
const std::string defs_before = |
| 53 |
R"(OpCapability Shader |
| 54 |
OpCapability PhysicalStorageBufferAddresses |
| 55 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 56 |
%1 = OpExtInstImport "GLSL.std.450" |
| 57 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 58 |
OpEntryPoint GLCompute %main "main" |
| 59 |
OpExecutionMode %main LocalSize 1 1 1 |
| 60 |
OpSource GLSL 450 |
| 61 |
OpSourceExtension "GL_EXT_buffer_reference" |
| 62 |
OpName %main "main" |
| 63 |
OpName %ufoo "ufoo" |
| 64 |
OpMemberName %ufoo 0 "data" |
| 65 |
OpMemberName %ufoo 1 "offset" |
| 66 |
OpName %bufStruct "bufStruct" |
| 67 |
OpMemberName %bufStruct 0 "a" |
| 68 |
OpMemberName %bufStruct 1 "b" |
| 69 |
OpName %u_info "u_info" |
| 70 |
OpMemberDecorate %ufoo 0 Offset 0 |
| 71 |
OpMemberDecorate %ufoo 1 Offset 8 |
| 72 |
OpDecorate %ufoo Block |
| 73 |
OpDecorate %_arr_int_uint_2 ArrayStride 16 |
| 74 |
OpMemberDecorate %bufStruct 0 Offset 0 |
| 75 |
OpMemberDecorate %bufStruct 1 Offset 32 |
| 76 |
OpDecorate %bufStruct Block |
| 77 |
OpDecorate %u_info DescriptorSet 0 |
| 78 |
OpDecorate %u_info Binding 0 |
| 79 |
%void = OpTypeVoid |
| 80 |
%3 = OpTypeFunction %void |
| 81 |
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer |
| 82 |
%uint = OpTypeInt 32 0 |
| 83 |
%ufoo = OpTypeStruct %_ptr_PhysicalStorageBuffer_bufStruct %uint |
| 84 |
%int = OpTypeInt 32 1 |
| 85 |
%uint_2 = OpConstant %uint 2 |
| 86 |
%_arr_int_uint_2 = OpTypeArray %int %uint_2 |
| 87 |
%bufStruct = OpTypeStruct %_arr_int_uint_2 %int |
| 88 |
%_ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer PhysicalStorageBuffer %bufStruct |
| 89 |
%_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo |
| 90 |
%u_info = OpVariable %_ptr_Uniform_ufoo Uniform |
| 91 |
%int_0 = OpConstant %int 0 |
| 92 |
%_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct |
| 93 |
%int_1 = OpConstant %int 1 |
| 94 |
%int_3239 = OpConstant %int 3239 |
| 95 |
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int |
| 96 |
)"; |
| 97 |
|
| 98 |
const std::string defs_after = |
| 99 |
R"(OpCapability Shader |
| 100 |
OpCapability PhysicalStorageBufferAddresses |
| 101 |
OpCapability Int64 |
| 102 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 103 |
OpExtension "SPV_KHR_storage_buffer_storage_class" |
| 104 |
%1 = OpExtInstImport "GLSL.std.450" |
| 105 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 106 |
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID |
| 107 |
OpExecutionMode %main LocalSize 1 1 1 |
| 108 |
OpSource GLSL 450 |
| 109 |
OpSourceExtension "GL_EXT_buffer_reference" |
| 110 |
OpName %main "main" |
| 111 |
OpName %ufoo "ufoo" |
| 112 |
OpMemberName %ufoo 0 "data" |
| 113 |
OpMemberName %ufoo 1 "offset" |
| 114 |
OpName %bufStruct "bufStruct" |
| 115 |
OpMemberName %bufStruct 0 "a" |
| 116 |
OpMemberName %bufStruct 1 "b" |
| 117 |
OpName %u_info "u_info" |
| 118 |
OpMemberDecorate %ufoo 0 Offset 0 |
| 119 |
OpMemberDecorate %ufoo 1 Offset 8 |
| 120 |
OpDecorate %ufoo Block |
| 121 |
OpDecorate %_arr_int_uint_2 ArrayStride 16 |
| 122 |
OpMemberDecorate %bufStruct 0 Offset 0 |
| 123 |
OpMemberDecorate %bufStruct 1 Offset 32 |
| 124 |
OpDecorate %bufStruct Block |
| 125 |
OpDecorate %u_info DescriptorSet 0 |
| 126 |
OpDecorate %u_info Binding 0 |
| 127 |
OpDecorate %_runtimearr_ulong ArrayStride 8 |
| 128 |
OpDecorate %_struct_39 Block |
| 129 |
OpMemberDecorate %_struct_39 0 Offset 0 |
| 130 |
OpDecorate %41 DescriptorSet 7 |
| 131 |
OpDecorate %41 Binding 2 |
| 132 |
OpDecorate %_runtimearr_uint ArrayStride 4 |
| 133 |
OpDecorate %_struct_77 Block |
| 134 |
OpMemberDecorate %_struct_77 0 Offset 0 |
| 135 |
OpMemberDecorate %_struct_77 1 Offset 4 |
| 136 |
OpDecorate %79 DescriptorSet 7 |
| 137 |
OpDecorate %79 Binding 0 |
| 138 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 139 |
%void = OpTypeVoid |
| 140 |
%8 = OpTypeFunction %void |
| 141 |
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer |
| 142 |
%uint = OpTypeInt 32 0 |
| 143 |
%ufoo = OpTypeStruct %_ptr_PhysicalStorageBuffer_bufStruct %uint |
| 144 |
%int = OpTypeInt 32 1 |
| 145 |
%uint_2 = OpConstant %uint 2 |
| 146 |
%_arr_int_uint_2 = OpTypeArray %int %uint_2 |
| 147 |
%bufStruct = OpTypeStruct %_arr_int_uint_2 %int |
| 148 |
%_ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer PhysicalStorageBuffer %bufStruct |
| 149 |
%_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo |
| 150 |
%u_info = OpVariable %_ptr_Uniform_ufoo Uniform |
| 151 |
%int_0 = OpConstant %int 0 |
| 152 |
%_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct |
| 153 |
%int_1 = OpConstant %int 1 |
| 154 |
%int_3239 = OpConstant %int 3239 |
| 155 |
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int |
| 156 |
%ulong = OpTypeInt 64 0 |
| 157 |
%uint_4 = OpConstant %uint 4 |
| 158 |
%bool = OpTypeBool |
| 159 |
%28 = OpTypeFunction %bool %ulong %uint |
| 160 |
%uint_1 = OpConstant %uint 1 |
| 161 |
%_runtimearr_ulong = OpTypeRuntimeArray %ulong |
| 162 |
%_struct_39 = OpTypeStruct %_runtimearr_ulong |
| 163 |
%_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39 |
| 164 |
%41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer |
| 165 |
%_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong |
| 166 |
%uint_0 = OpConstant %uint 0 |
| 167 |
%uint_32 = OpConstant %uint 32 |
| 168 |
%70 = OpTypeFunction %void %uint %uint %uint %uint |
| 169 |
%_runtimearr_uint = OpTypeRuntimeArray %uint |
| 170 |
%_struct_77 = OpTypeStruct %uint %_runtimearr_uint |
| 171 |
%_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77 |
| 172 |
%79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer |
| 173 |
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint |
| 174 |
%uint_10 = OpConstant %uint 10 |
| 175 |
%uint_23 = OpConstant %uint 23 |
| 176 |
%uint_5 = OpConstant %uint 5 |
| 177 |
%uint_3 = OpConstant %uint 3 |
| 178 |
%v3uint = OpTypeVector %uint 3 |
| 179 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 180 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 181 |
%uint_6 = OpConstant %uint 6 |
| 182 |
%uint_7 = OpConstant %uint 7 |
| 183 |
%uint_8 = OpConstant %uint 8 |
| 184 |
%uint_9 = OpConstant %uint 9 |
| 185 |
%uint_48 = OpConstant %uint 48 |
| 186 |
)"; |
| 187 |
|
| 188 |
const std::string func_before = |
| 189 |
R"(%main = OpFunction %void None %3 |
| 190 |
%5 = OpLabel |
| 191 |
%17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 |
| 192 |
%18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17 |
| 193 |
%22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1 |
| 194 |
OpStore %22 %int_3239 Aligned 16 |
| 195 |
OpReturn |
| 196 |
OpFunctionEnd |
| 197 |
)"; |
| 198 |
|
| 199 |
const std::string func_after = |
| 200 |
R"(%main = OpFunction %void None %8 |
| 201 |
%19 = OpLabel |
| 202 |
%20 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0 |
| 203 |
%21 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %20 |
| 204 |
%22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %21 %int_1 |
| 205 |
%24 = OpConvertPtrToU %ulong %22 |
| 206 |
%61 = OpFunctionCall %bool %26 %24 %uint_4 |
| 207 |
OpSelectionMerge %62 None |
| 208 |
OpBranchConditional %61 %63 %64 |
| 209 |
%63 = OpLabel |
| 210 |
OpStore %22 %int_3239 Aligned 16 |
| 211 |
OpBranch %62 |
| 212 |
%64 = OpLabel |
| 213 |
%65 = OpUConvert %uint %24 |
| 214 |
%67 = OpShiftRightLogical %ulong %24 %uint_32 |
| 215 |
%68 = OpUConvert %uint %67 |
| 216 |
%124 = OpFunctionCall %void %69 %uint_48 %uint_2 %65 %68 |
| 217 |
OpBranch %62 |
| 218 |
%62 = OpLabel |
| 219 |
OpReturn |
| 220 |
OpFunctionEnd |
| 221 |
)"; |
| 222 |
|
| 223 |
const std::string new_funcs = |
| 224 |
R"(%26 = OpFunction %bool None %28 |
| 225 |
%29 = OpFunctionParameter %ulong |
| 226 |
%30 = OpFunctionParameter %uint |
| 227 |
%31 = OpLabel |
| 228 |
OpBranch %32 |
| 229 |
%32 = OpLabel |
| 230 |
%34 = OpPhi %uint %uint_1 %31 %35 %33 |
| 231 |
OpLoopMerge %37 %33 None |
| 232 |
OpBranch %33 |
| 233 |
%33 = OpLabel |
| 234 |
%35 = OpIAdd %uint %34 %uint_1 |
| 235 |
%44 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %35 |
| 236 |
%45 = OpLoad %ulong %44 |
| 237 |
%46 = OpUGreaterThan %bool %45 %29 |
| 238 |
OpBranchConditional %46 %37 %32 |
| 239 |
%37 = OpLabel |
| 240 |
%47 = OpISub %uint %35 %uint_1 |
| 241 |
%48 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %47 |
| 242 |
%49 = OpLoad %ulong %48 |
| 243 |
%50 = OpISub %ulong %29 %49 |
| 244 |
%51 = OpUConvert %ulong %30 |
| 245 |
%52 = OpIAdd %ulong %50 %51 |
| 246 |
%53 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %uint_0 |
| 247 |
%54 = OpLoad %ulong %53 |
| 248 |
%55 = OpUConvert %uint %54 |
| 249 |
%56 = OpISub %uint %47 %uint_1 |
| 250 |
%57 = OpIAdd %uint %56 %55 |
| 251 |
%58 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %57 |
| 252 |
%59 = OpLoad %ulong %58 |
| 253 |
%60 = OpULessThanEqual %bool %52 %59 |
| 254 |
OpReturnValue %60 |
| 255 |
OpFunctionEnd |
| 256 |
%69 = OpFunction %void None %70 |
| 257 |
%71 = OpFunctionParameter %uint |
| 258 |
%72 = OpFunctionParameter %uint |
| 259 |
%73 = OpFunctionParameter %uint |
| 260 |
%74 = OpFunctionParameter %uint |
| 261 |
%75 = OpLabel |
| 262 |
%81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0 |
| 263 |
%83 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_10 |
| 264 |
%84 = OpIAdd %uint %83 %uint_10 |
| 265 |
%85 = OpArrayLength %uint %79 1 |
| 266 |
%86 = OpULessThanEqual %bool %84 %85 |
| 267 |
OpSelectionMerge %87 None |
| 268 |
OpBranchConditional %86 %88 %87 |
| 269 |
%88 = OpLabel |
| 270 |
%89 = OpIAdd %uint %83 %uint_0 |
| 271 |
%90 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %89 |
| 272 |
OpStore %90 %uint_10 |
| 273 |
%92 = OpIAdd %uint %83 %uint_1 |
| 274 |
%93 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %92 |
| 275 |
OpStore %93 %uint_23 |
| 276 |
%94 = OpIAdd %uint %83 %uint_2 |
| 277 |
%95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94 |
| 278 |
OpStore %95 %71 |
| 279 |
%98 = OpIAdd %uint %83 %uint_3 |
| 280 |
%99 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %98 |
| 281 |
OpStore %99 %uint_5 |
| 282 |
%103 = OpLoad %v3uint %gl_GlobalInvocationID |
| 283 |
%104 = OpCompositeExtract %uint %103 0 |
| 284 |
%105 = OpCompositeExtract %uint %103 1 |
| 285 |
%106 = OpCompositeExtract %uint %103 2 |
| 286 |
%107 = OpIAdd %uint %83 %uint_4 |
| 287 |
%108 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %107 |
| 288 |
OpStore %108 %104 |
| 289 |
%109 = OpIAdd %uint %83 %uint_5 |
| 290 |
%110 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %109 |
| 291 |
OpStore %110 %105 |
| 292 |
%112 = OpIAdd %uint %83 %uint_6 |
| 293 |
%113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112 |
| 294 |
OpStore %113 %106 |
| 295 |
%115 = OpIAdd %uint %83 %uint_7 |
| 296 |
%116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115 |
| 297 |
OpStore %116 %72 |
| 298 |
%118 = OpIAdd %uint %83 %uint_8 |
| 299 |
%119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118 |
| 300 |
OpStore %119 %73 |
| 301 |
%121 = OpIAdd %uint %83 %uint_9 |
| 302 |
%122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121 |
| 303 |
OpStore %122 %74 |
| 304 |
OpBranch %87 |
| 305 |
%87 = OpLabel |
| 306 |
OpReturn |
| 307 |
OpFunctionEnd |
| 308 |
)"; |
| 309 |
|
| 310 |
// SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 311 |
SinglePassRunAndCheck<InstBuffAddrCheckPass>( |
| 312 |
defs_before + func_before, defs_after + func_after + new_funcs, true, |
| 313 |
true, 7u, 23u); |
| 314 |
} |
| 315 |
|
| 316 |
TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferLoadAndStore) { |
| 317 |
// #version 450 |
| 318 |
// #extension GL_EXT_buffer_reference : enable |
| 319 |
|
| 320 |
// // forward reference |
| 321 |
// layout(buffer_reference) buffer blockType; |
| 322 |
|
| 323 |
// layout(buffer_reference, std430, buffer_reference_align = 16) buffer |
| 324 |
// blockType { |
| 325 |
// int x; |
| 326 |
// blockType next; |
| 327 |
// }; |
| 328 |
|
| 329 |
// layout(std430) buffer rootBlock { |
| 330 |
// blockType root; |
| 331 |
// } r; |
| 332 |
|
| 333 |
// void main() |
| 334 |
// { |
| 335 |
// blockType b = r.root; |
| 336 |
// b = b.next; |
| 337 |
// b.x = 531; |
| 338 |
// } |
| 339 |
|
| 340 |
const std::string defs_before = |
| 341 |
R"(OpCapability Shader |
| 342 |
OpCapability PhysicalStorageBufferAddresses |
| 343 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 344 |
OpExtension "SPV_KHR_storage_buffer_storage_class" |
| 345 |
%1 = OpExtInstImport "GLSL.std.450" |
| 346 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 347 |
OpEntryPoint GLCompute %main "main" |
| 348 |
OpExecutionMode %main LocalSize 1 1 1 |
| 349 |
OpSource GLSL 450 |
| 350 |
OpSourceExtension "GL_EXT_buffer_reference" |
| 351 |
OpName %main "main" |
| 352 |
OpName %blockType "blockType" |
| 353 |
OpMemberName %blockType 0 "x" |
| 354 |
OpMemberName %blockType 1 "next" |
| 355 |
OpName %rootBlock "rootBlock" |
| 356 |
OpMemberName %rootBlock 0 "root" |
| 357 |
OpName %r "r" |
| 358 |
OpMemberDecorate %blockType 0 Offset 0 |
| 359 |
OpMemberDecorate %blockType 1 Offset 8 |
| 360 |
OpDecorate %blockType Block |
| 361 |
OpMemberDecorate %rootBlock 0 Offset 0 |
| 362 |
OpDecorate %rootBlock Block |
| 363 |
OpDecorate %r DescriptorSet 0 |
| 364 |
OpDecorate %r Binding 0 |
| 365 |
%void = OpTypeVoid |
| 366 |
%3 = OpTypeFunction %void |
| 367 |
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer |
| 368 |
%int = OpTypeInt 32 1 |
| 369 |
%blockType = OpTypeStruct %int %_ptr_PhysicalStorageBuffer_blockType |
| 370 |
%_ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %blockType |
| 371 |
%rootBlock = OpTypeStruct %_ptr_PhysicalStorageBuffer_blockType |
| 372 |
%_ptr_StorageBuffer_rootBlock = OpTypePointer StorageBuffer %rootBlock |
| 373 |
%r = OpVariable %_ptr_StorageBuffer_rootBlock StorageBuffer |
| 374 |
%int_0 = OpConstant %int 0 |
| 375 |
%_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer StorageBuffer %_ptr_PhysicalStorageBuffer_blockType |
| 376 |
%int_1 = OpConstant %int 1 |
| 377 |
%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType |
| 378 |
%int_531 = OpConstant %int 531 |
| 379 |
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int |
| 380 |
)"; |
| 381 |
|
| 382 |
const std::string defs_after = |
| 383 |
R"(OpCapability Shader |
| 384 |
OpCapability PhysicalStorageBufferAddresses |
| 385 |
OpCapability Int64 |
| 386 |
OpExtension "SPV_EXT_physical_storage_buffer" |
| 387 |
OpExtension "SPV_KHR_storage_buffer_storage_class" |
| 388 |
%1 = OpExtInstImport "GLSL.std.450" |
| 389 |
OpMemoryModel PhysicalStorageBuffer64 GLSL450 |
| 390 |
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID |
| 391 |
OpExecutionMode %main LocalSize 1 1 1 |
| 392 |
OpSource GLSL 450 |
| 393 |
OpSourceExtension "GL_EXT_buffer_reference" |
| 394 |
OpName %main "main" |
| 395 |
OpName %blockType "blockType" |
| 396 |
OpMemberName %blockType 0 "x" |
| 397 |
OpMemberName %blockType 1 "next" |
| 398 |
OpName %rootBlock "rootBlock" |
| 399 |
OpMemberName %rootBlock 0 "root" |
| 400 |
OpName %r "r" |
| 401 |
OpMemberDecorate %blockType 0 Offset 0 |
| 402 |
OpMemberDecorate %blockType 1 Offset 8 |
| 403 |
OpDecorate %blockType Block |
| 404 |
OpMemberDecorate %rootBlock 0 Offset 0 |
| 405 |
OpDecorate %rootBlock Block |
| 406 |
OpDecorate %r DescriptorSet 0 |
| 407 |
OpDecorate %r Binding 0 |
| 408 |
OpDecorate %_runtimearr_ulong ArrayStride 8 |
| 409 |
OpDecorate %_struct_45 Block |
| 410 |
OpMemberDecorate %_struct_45 0 Offset 0 |
| 411 |
OpDecorate %47 DescriptorSet 7 |
| 412 |
OpDecorate %47 Binding 2 |
| 413 |
OpDecorate %_runtimearr_uint ArrayStride 4 |
| 414 |
OpDecorate %_struct_84 Block |
| 415 |
OpMemberDecorate %_struct_84 0 Offset 0 |
| 416 |
OpMemberDecorate %_struct_84 1 Offset 4 |
| 417 |
OpDecorate %86 DescriptorSet 7 |
| 418 |
OpDecorate %86 Binding 0 |
| 419 |
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId |
| 420 |
%void = OpTypeVoid |
| 421 |
%3 = OpTypeFunction %void |
| 422 |
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer |
| 423 |
%int = OpTypeInt 32 1 |
| 424 |
%blockType = OpTypeStruct %int %_ptr_PhysicalStorageBuffer_blockType |
| 425 |
%_ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %blockType |
| 426 |
%rootBlock = OpTypeStruct %_ptr_PhysicalStorageBuffer_blockType |
| 427 |
%_ptr_StorageBuffer_rootBlock = OpTypePointer StorageBuffer %rootBlock |
| 428 |
%r = OpVariable %_ptr_StorageBuffer_rootBlock StorageBuffer |
| 429 |
%int_0 = OpConstant %int 0 |
| 430 |
%_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer StorageBuffer %_ptr_PhysicalStorageBuffer_blockType |
| 431 |
%int_1 = OpConstant %int 1 |
| 432 |
%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType |
| 433 |
%int_531 = OpConstant %int 531 |
| 434 |
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int |
| 435 |
%uint = OpTypeInt 32 0 |
| 436 |
%uint_2 = OpConstant %uint 2 |
| 437 |
%ulong = OpTypeInt 64 0 |
| 438 |
%uint_8 = OpConstant %uint 8 |
| 439 |
%bool = OpTypeBool |
| 440 |
%34 = OpTypeFunction %bool %ulong %uint |
| 441 |
%uint_1 = OpConstant %uint 1 |
| 442 |
%_runtimearr_ulong = OpTypeRuntimeArray %ulong |
| 443 |
%_struct_45 = OpTypeStruct %_runtimearr_ulong |
| 444 |
%_ptr_StorageBuffer__struct_45 = OpTypePointer StorageBuffer %_struct_45 |
| 445 |
%47 = OpVariable %_ptr_StorageBuffer__struct_45 StorageBuffer |
| 446 |
%_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong |
| 447 |
%uint_0 = OpConstant %uint 0 |
| 448 |
%uint_32 = OpConstant %uint 32 |
| 449 |
%77 = OpTypeFunction %void %uint %uint %uint %uint |
| 450 |
%_runtimearr_uint = OpTypeRuntimeArray %uint |
| 451 |
%_struct_84 = OpTypeStruct %uint %_runtimearr_uint |
| 452 |
%_ptr_StorageBuffer__struct_84 = OpTypePointer StorageBuffer %_struct_84 |
| 453 |
%86 = OpVariable %_ptr_StorageBuffer__struct_84 StorageBuffer |
| 454 |
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint |
| 455 |
%uint_10 = OpConstant %uint 10 |
| 456 |
%uint_4 = OpConstant %uint 4 |
| 457 |
%uint_23 = OpConstant %uint 23 |
| 458 |
%uint_5 = OpConstant %uint 5 |
| 459 |
%uint_3 = OpConstant %uint 3 |
| 460 |
%v3uint = OpTypeVector %uint 3 |
| 461 |
%_ptr_Input_v3uint = OpTypePointer Input %v3uint |
| 462 |
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input |
| 463 |
%uint_6 = OpConstant %uint 6 |
| 464 |
%uint_7 = OpConstant %uint 7 |
| 465 |
%uint_9 = OpConstant %uint 9 |
| 466 |
%uint_44 = OpConstant %uint 44 |
| 467 |
%132 = OpConstantNull %ulong |
| 468 |
%uint_46 = OpConstant %uint 46 |
| 469 |
)"; |
| 470 |
|
| 471 |
const std::string func_before = |
| 472 |
R"(%main = OpFunction %void None %3 |
| 473 |
%5 = OpLabel |
| 474 |
%16 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0 |
| 475 |
%17 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %16 |
| 476 |
%21 = OpAccessChain %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType %17 %int_1 |
| 477 |
%22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 |
| 478 |
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0 |
| 479 |
OpStore %26 %int_531 Aligned 16 |
| 480 |
OpReturn |
| 481 |
OpFunctionEnd |
| 482 |
)"; |
| 483 |
|
| 484 |
const std::string func_after = |
| 485 |
R"(%main = OpFunction %void None %3 |
| 486 |
%5 = OpLabel |
| 487 |
%16 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0 |
| 488 |
%17 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %16 |
| 489 |
%21 = OpAccessChain %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType %17 %int_1 |
| 490 |
%30 = OpConvertPtrToU %ulong %21 |
| 491 |
%67 = OpFunctionCall %bool %32 %30 %uint_8 |
| 492 |
OpSelectionMerge %68 None |
| 493 |
OpBranchConditional %67 %69 %70 |
| 494 |
%69 = OpLabel |
| 495 |
%71 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8 |
| 496 |
OpBranch %68 |
| 497 |
%70 = OpLabel |
| 498 |
%72 = OpUConvert %uint %30 |
| 499 |
%74 = OpShiftRightLogical %ulong %30 %uint_32 |
| 500 |
%75 = OpUConvert %uint %74 |
| 501 |
%131 = OpFunctionCall %void %76 %uint_44 %uint_2 %72 %75 |
| 502 |
%133 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType %132 |
| 503 |
OpBranch %68 |
| 504 |
%68 = OpLabel |
| 505 |
%134 = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 %133 %70 |
| 506 |
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %134 %int_0 |
| 507 |
%135 = OpConvertPtrToU %ulong %26 |
| 508 |
%136 = OpFunctionCall %bool %32 %135 %uint_4 |
| 509 |
OpSelectionMerge %137 None |
| 510 |
OpBranchConditional %136 %138 %139 |
| 511 |
%138 = OpLabel |
| 512 |
OpStore %26 %int_531 Aligned 16 |
| 513 |
OpBranch %137 |
| 514 |
%139 = OpLabel |
| 515 |
%140 = OpUConvert %uint %135 |
| 516 |
%141 = OpShiftRightLogical %ulong %135 %uint_32 |
| 517 |
%142 = OpUConvert %uint %141 |
| 518 |
%144 = OpFunctionCall %void %76 %uint_46 %uint_2 %140 %142 |
| 519 |
OpBranch %137 |
| 520 |
%137 = OpLabel |
| 521 |
OpReturn |
| 522 |
OpFunctionEnd |
| 523 |
)"; |
| 524 |
|
| 525 |
const std::string new_funcs = |
| 526 |
R"(%32 = OpFunction %bool None %34 |
| 527 |
%35 = OpFunctionParameter %ulong |
| 528 |
%36 = OpFunctionParameter %uint |
| 529 |
%37 = OpLabel |
| 530 |
OpBranch %38 |
| 531 |
%38 = OpLabel |
| 532 |
%40 = OpPhi %uint %uint_1 %37 %41 %39 |
| 533 |
OpLoopMerge %43 %39 None |
| 534 |
OpBranch %39 |
| 535 |
%39 = OpLabel |
| 536 |
%41 = OpIAdd %uint %40 %uint_1 |
| 537 |
%50 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %41 |
| 538 |
%51 = OpLoad %ulong %50 |
| 539 |
%52 = OpUGreaterThan %bool %51 %35 |
| 540 |
OpBranchConditional %52 %43 %38 |
| 541 |
%43 = OpLabel |
| 542 |
%53 = OpISub %uint %41 %uint_1 |
| 543 |
%54 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %53 |
| 544 |
%55 = OpLoad %ulong %54 |
| 545 |
%56 = OpISub %ulong %35 %55 |
| 546 |
%57 = OpUConvert %ulong %36 |
| 547 |
%58 = OpIAdd %ulong %56 %57 |
| 548 |
%59 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %uint_0 |
| 549 |
%60 = OpLoad %ulong %59 |
| 550 |
%61 = OpUConvert %uint %60 |
| 551 |
%62 = OpISub %uint %53 %uint_1 |
| 552 |
%63 = OpIAdd %uint %62 %61 |
| 553 |
%64 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %63 |
| 554 |
%65 = OpLoad %ulong %64 |
| 555 |
%66 = OpULessThanEqual %bool %58 %65 |
| 556 |
OpReturnValue %66 |
| 557 |
OpFunctionEnd |
| 558 |
%76 = OpFunction %void None %77 |
| 559 |
%78 = OpFunctionParameter %uint |
| 560 |
%79 = OpFunctionParameter %uint |
| 561 |
%80 = OpFunctionParameter %uint |
| 562 |
%81 = OpFunctionParameter %uint |
| 563 |
%82 = OpLabel |
| 564 |
%88 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_0 |
| 565 |
%91 = OpAtomicIAdd %uint %88 %uint_4 %uint_0 %uint_10 |
| 566 |
%92 = OpIAdd %uint %91 %uint_10 |
| 567 |
%93 = OpArrayLength %uint %86 1 |
| 568 |
%94 = OpULessThanEqual %bool %92 %93 |
| 569 |
OpSelectionMerge %95 None |
| 570 |
OpBranchConditional %94 %96 %95 |
| 571 |
%96 = OpLabel |
| 572 |
%97 = OpIAdd %uint %91 %uint_0 |
| 573 |
%98 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %97 |
| 574 |
OpStore %98 %uint_10 |
| 575 |
%100 = OpIAdd %uint %91 %uint_1 |
| 576 |
%101 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %100 |
| 577 |
OpStore %101 %uint_23 |
| 578 |
%102 = OpIAdd %uint %91 %uint_2 |
| 579 |
%103 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %102 |
| 580 |
OpStore %103 %78 |
| 581 |
%106 = OpIAdd %uint %91 %uint_3 |
| 582 |
%107 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %106 |
| 583 |
OpStore %107 %uint_5 |
| 584 |
%111 = OpLoad %v3uint %gl_GlobalInvocationID |
| 585 |
%112 = OpCompositeExtract %uint %111 0 |
| 586 |
%113 = OpCompositeExtract %uint %111 1 |
| 587 |
%114 = OpCompositeExtract %uint %111 2 |
| 588 |
%115 = OpIAdd %uint %91 %uint_4 |
| 589 |
%116 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %115 |
| 590 |
OpStore %116 %112 |
| 591 |
%117 = OpIAdd %uint %91 %uint_5 |
| 592 |
%118 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %117 |
| 593 |
OpStore %118 %113 |
| 594 |
%120 = OpIAdd %uint %91 %uint_6 |
| 595 |
%121 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %120 |
| 596 |
OpStore %121 %114 |
| 597 |
%123 = OpIAdd %uint %91 %uint_7 |
| 598 |
%124 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %123 |
| 599 |
OpStore %124 %79 |
| 600 |
%125 = OpIAdd %uint %91 %uint_8 |
| 601 |
%126 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %125 |
| 602 |
OpStore %126 %80 |
| 603 |
%128 = OpIAdd %uint %91 %uint_9 |
| 604 |
%129 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %128 |
| 605 |
OpStore %129 %81 |
| 606 |
OpBranch %95 |
| 607 |
%95 = OpLabel |
| 608 |
OpReturn |
| 609 |
OpFunctionEnd |
| 610 |
)"; |
| 611 |
|
| 612 |
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS); |
| 613 |
SinglePassRunAndCheck<InstBuffAddrCheckPass>( |
| 614 |
defs_before + func_before, defs_after + func_after + new_funcs, true, |
| 615 |
true, 7u, 23u); |
| 616 |
} |
| 617 |
|
| 618 |
} // namespace |
| 619 |
} // namespace opt |
| 620 |
} // namespace spvtools |