tests: Make InstrumentPass tests use SinglePassRunAndMatch<> and stateful pattern matching (#4897)

Using SinglePassRunAndMatch<> instead of SinglePassRunAndCheck<>
makes tests more concise and makes it possible to use pattern
matching features.

Using Effcee stateful pattern matching to make it less repetitive
to check for generated functions and global variables.

This approach isn't worth
it for DebugPrintf functions because the generated code will change
depending on how many parameters are passed to every debugPrintfEXT()
call.
This commit is contained in:
jeremyg-lunarg 2022-08-23 12:28:00 -06:00 committed by GitHub
parent b41e3e1311
commit a98f05d02f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2431 additions and 6553 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
// Copyright (c) 2019 Valve Corporation
// Copyright (c) 2019 LunarG Inc.
// Copyright (c) 2019-2022 Valve Corporation
// Copyright (c) 2019-2022 LunarG Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -27,6 +27,148 @@ namespace spvtools {
namespace opt {
namespace {
static const std::string kOutputDecorations = R"(
; CHECK: OpDecorate [[output_buffer_type:%_struct_\w+]] Block
; CHECK: OpMemberDecorate [[output_buffer_type]] 0 Offset 0
; CHECK: OpMemberDecorate [[output_buffer_type]] 1 Offset 4
; CHECK: OpDecorate [[output_buffer_var:%\w+]] DescriptorSet 7
; CHECK: OpDecorate [[output_buffer_var]] Binding 0
)";
static const std::string kOutputGlobals = R"(
; CHECK: [[output_buffer_type]] = OpTypeStruct %uint %_runtimearr_uint
; CHECK: [[output_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[output_buffer_type]]
; CHECK: [[output_buffer_var]] = OpVariable [[output_ptr_type]] StorageBuffer
)";
static const std::string kStreamWrite4Begin = R"(
; CHECK: {{%\w+}} = OpFunction %void None {{%\w+}}
; CHECK: [[param_1:%\w+]] = OpFunctionParameter %uint
; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
; CHECK: [[param_3:%\w+]] = OpFunctionParameter %uint
; CHECK: [[param_4:%\w+]] = OpFunctionParameter %uint
; CHECK: {{%\w+}} = OpLabel
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_0
; CHECK: {{%\w+}} = OpAtomicIAdd %uint {{%\w+}} %uint_4 %uint_0 %uint_10
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_10
; CHECK: {{%\w+}} = OpArrayLength %uint [[output_buffer_var]] 1
; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}}
; CHECK: OpSelectionMerge {{%\w+}} None
; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpLabel
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_0
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} %uint_10
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} %uint_23
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_2
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} [[param_1]]
)";
static const std::string kStreamWrite4End = R"(
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_7
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} [[param_2]]
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_8
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} [[param_3]]
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_9
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} [[param_4]]
; CHECK: OpBranch {{%\w+}}
; CHECK: {{%\w+}} = OpLabel
; CHECK: OpReturn
; CHECK: OpFunctionEnd
)";
// clang-format off
static const std::string kStreamWrite4Frag = kStreamWrite4Begin + R"(
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} %uint_4
; CHECK: {{%\w+}} = OpLoad %v4float %gl_FragCoord
; CHECK: {{%\w+}} = OpBitcast %v4uint {{%\w+}}
; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} {{%\w+}}
)" + kStreamWrite4End;
static const std::string kStreamWrite4Compute = kStreamWrite4Begin + R"(
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_3
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} %uint_5
; CHECK: {{%\w+}} = OpLoad %v3uint %gl_GlobalInvocationID
; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 0
; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 1
; CHECK: {{%\w+}} = OpCompositeExtract %uint {{%\w+}} 2
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_4
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_5
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_6
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_uint [[output_buffer_var]] %uint_1 {{%\w+}}
; CHECK: OpStore {{%\w+}} {{%\w+}}
)" + kStreamWrite4End;
// clang-format on
static const std::string kInputDecorations = R"(
; CHECK: OpDecorate [[input_buffer_type:%_struct_\w+]] Block
; CHECK: OpMemberDecorate [[input_buffer_type]] 0 Offset 0
; CHECK: OpDecorate [[input_buffer_var:%\w+]] DescriptorSet 7
; CHECK: OpDecorate [[input_buffer_var]] Binding 2
)";
static const std::string kInputGlobals = R"(
; CHECK: [[input_buffer_type]] = OpTypeStruct %_runtimearr_ulong
; CHECK: [[input_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[input_buffer_type]]
; CHECK: [[input_buffer_var]] = OpVariable [[input_ptr_type]] StorageBuffer
)";
static const std::string kSearchAndTest = R"(
; CHECK: {{%\w+}} = OpFunction %bool None {{%\w+}}
; CHECK: [[param_1:%\w+]] = OpFunctionParameter %ulong
; CHECK: [[param_2:%\w+]] = OpFunctionParameter %uint
; CHECK: {{%\w+}} = OpLabel
; CHECK: OpBranch {{%\w+}}
; CHECK: {{%\w+}} = OpLabel
; CHECK: {{%\w+}} = OpPhi %uint %uint_1 {{%\w+}} {{%\w+}} {{%\w+}}
; CHECK: OpLoopMerge {{%\w+}} {{%\w+}} None
; CHECK: OpBranch {{%\w+}}
; CHECK: {{%\w+}} = OpLabel
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} %uint_1
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}}
; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}}
; CHECK: {{%\w+}} = OpUGreaterThan %bool {{%\w+}} [[param_1]]
; CHECK: OpBranchConditional {{%\w+}} {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpLabel
; CHECK: {{%\w+}} = OpISub %uint {{%\w+}} %uint_1
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}}
; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}}
; CHECK: {{%\w+}} = OpISub %ulong [[param_1]] {{%\w+}}
; CHECK: {{%\w+}} = OpUConvert %ulong [[param_2]]
; CHECK: {{%\w+}} = OpIAdd %ulong {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 %uint_0
; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}}
; CHECK: {{%\w+}} = OpUConvert %uint {{%\w+}}
; CHECK: {{%\w+}} = OpISub %uint {{%\w+}} %uint_1
; CHECK: {{%\w+}} = OpIAdd %uint {{%\w+}} {{%\w+}}
; CHECK: {{%\w+}} = OpAccessChain %_ptr_StorageBuffer_ulong [[input_buffer_var]] %uint_0 {{%\w+}}
; CHECK: {{%\w+}} = OpLoad %ulong {{%\w+}}
; CHECK: {{%\w+}} = OpULessThanEqual %bool {{%\w+}} {{%\w+}}
; CHECK: OpReturnValue {{%\w+}}
; CHECK: OpFunctionEnd
)";
// clang-format on
using InstBuffAddrTest = PassTest<::testing::Test>;
TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferStore) {
@ -49,13 +191,16 @@ TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferStore) {
// u_info.data.b = 0xca7;
// }
const std::string defs_before =
R"(OpCapability Shader
const std::string defs = R"(
OpCapability Shader
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability Int64
OpExtension "SPV_EXT_physical_storage_buffer"
; CHECK: OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %main "main"
; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 450
OpSourceExtension "GL_EXT_buffer_reference"
@ -67,6 +212,10 @@ OpName %bufStruct "bufStruct"
OpMemberName %bufStruct 0 "a"
OpMemberName %bufStruct 1 "b"
OpName %u_info "u_info"
)";
// clang-format off
const std::string decorates = R"(
OpMemberDecorate %ufoo 0 Offset 0
OpMemberDecorate %ufoo 1 Offset 8
OpDecorate %ufoo Block
@ -76,6 +225,14 @@ OpMemberDecorate %bufStruct 1 Offset 32
OpDecorate %bufStruct Block
OpDecorate %u_info DescriptorSet 0
OpDecorate %u_info Binding 0
; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8
)" + kInputDecorations + R"(
; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
)" + kOutputDecorations + R"(
; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
)";
const std::string globals = R"(
%void = OpTypeVoid
%3 = OpTypeFunction %void
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer
@ -93,224 +250,71 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer
%int_1 = OpConstant %int 1
%int_3239 = OpConstant %int 3239
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
; CHECK: %ulong = OpTypeInt 64 0
; CHECK: %uint_4 = OpConstant %uint 4
; CHECK: %bool = OpTypeBool
; CHECK: %28 = OpTypeFunction %bool %ulong %uint
; CHECK: %uint_1 = OpConstant %uint 1
; CHECK: %_runtimearr_ulong = OpTypeRuntimeArray %ulong
)" + kInputGlobals + R"(
; CHECK: %_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong
; CHECK: %uint_0 = OpConstant %uint 0
; CHECK: %uint_32 = OpConstant %uint 32
; CHECK: %70 = OpTypeFunction %void %uint %uint %uint %uint
; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
)" + kOutputGlobals + R"(
; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
; CHECK: %uint_10 = OpConstant %uint 10
; CHECK: %uint_23 = OpConstant %uint 23
; CHECK: %uint_5 = OpConstant %uint 5
; CHECK: %uint_3 = OpConstant %uint 3
; CHECK: %v3uint = OpTypeVector %uint 3
; CHECK: %_ptr_Input_v3uint = OpTypePointer Input %v3uint
; CHECK: %gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
; CHECK: %uint_6 = OpConstant %uint 6
; CHECK: %uint_7 = OpConstant %uint 7
; CHECK: %uint_8 = OpConstant %uint 8
; CHECK: %uint_9 = OpConstant %uint 9
; CHECK: %uint_48 = OpConstant %uint 48
)";
// clang-format off
const std::string defs_after =
R"(OpCapability Shader
OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpExtension "SPV_EXT_physical_storage_buffer"
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 450
OpSourceExtension "GL_EXT_buffer_reference"
OpName %main "main"
OpName %ufoo "ufoo"
OpMemberName %ufoo 0 "data"
OpMemberName %ufoo 1 "offset"
OpName %bufStruct "bufStruct"
OpMemberName %bufStruct 0 "a"
OpMemberName %bufStruct 1 "b"
OpName %u_info "u_info"
OpMemberDecorate %ufoo 0 Offset 0
OpMemberDecorate %ufoo 1 Offset 8
OpDecorate %ufoo Block
OpDecorate %_arr_int_uint_2 ArrayStride 16
OpMemberDecorate %bufStruct 0 Offset 0
OpMemberDecorate %bufStruct 1 Offset 32
OpDecorate %bufStruct Block
OpDecorate %u_info DescriptorSet 0
OpDecorate %u_info Binding 0
OpDecorate %_runtimearr_ulong ArrayStride 8
OpDecorate %_struct_39 Block
OpMemberDecorate %_struct_39 0 Offset 0
OpDecorate %41 DescriptorSet 7
OpDecorate %41 Binding 2
OpDecorate %_runtimearr_uint ArrayStride 4
OpDecorate %_struct_77 Block
OpMemberDecorate %_struct_77 0 Offset 0
OpMemberDecorate %_struct_77 1 Offset 4
OpDecorate %79 DescriptorSet 7
OpDecorate %79 Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
%void = OpTypeVoid
%8 = OpTypeFunction %void
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_bufStruct PhysicalStorageBuffer
%uint = OpTypeInt 32 0
%ufoo = OpTypeStruct %_ptr_PhysicalStorageBuffer_bufStruct %uint
%int = OpTypeInt 32 1
%uint_2 = OpConstant %uint 2
%_arr_int_uint_2 = OpTypeArray %int %uint_2
%bufStruct = OpTypeStruct %_arr_int_uint_2 %int
%_ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer PhysicalStorageBuffer %bufStruct
%_ptr_Uniform_ufoo = OpTypePointer Uniform %ufoo
%u_info = OpVariable %_ptr_Uniform_ufoo Uniform
%int_0 = OpConstant %int 0
%_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct = OpTypePointer Uniform %_ptr_PhysicalStorageBuffer_bufStruct
%int_1 = OpConstant %int 1
%int_3239 = OpConstant %int 3239
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
%ulong = OpTypeInt 64 0
%uint_4 = OpConstant %uint 4
%bool = OpTypeBool
%28 = OpTypeFunction %bool %ulong %uint
%uint_1 = OpConstant %uint 1
%_runtimearr_ulong = OpTypeRuntimeArray %ulong
%_struct_39 = OpTypeStruct %_runtimearr_ulong
%_ptr_StorageBuffer__struct_39 = OpTypePointer StorageBuffer %_struct_39
%41 = OpVariable %_ptr_StorageBuffer__struct_39 StorageBuffer
%_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong
%uint_0 = OpConstant %uint 0
%uint_32 = OpConstant %uint 32
%70 = OpTypeFunction %void %uint %uint %uint %uint
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_77 = OpTypeStruct %uint %_runtimearr_uint
%_ptr_StorageBuffer__struct_77 = OpTypePointer StorageBuffer %_struct_77
%79 = OpVariable %_ptr_StorageBuffer__struct_77 StorageBuffer
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_10 = OpConstant %uint 10
%uint_23 = OpConstant %uint 23
%uint_5 = OpConstant %uint 5
%uint_3 = OpConstant %uint 3
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_6 = OpConstant %uint 6
%uint_7 = OpConstant %uint 7
%uint_8 = OpConstant %uint 8
%uint_9 = OpConstant %uint 9
%uint_48 = OpConstant %uint 48
)";
const std::string func_before =
R"(%main = OpFunction %void None %3
const std::string main_func = R"(
%main = OpFunction %void None %3
%5 = OpLabel
%17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
%18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17
%22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1
; CHECK-NOT: %17 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
; CHECK-NOT: %18 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %17
; CHECK-NOT: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %18 %int_1
; CHECK: %20 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
; CHECK: %21 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %20
; CHECK: %22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %21 %int_1
; CHECK: %24 = OpConvertPtrToU %ulong %22
; CHECK: %61 = OpFunctionCall %bool %26 %24 %uint_4
; CHECK: OpSelectionMerge %62 None
; CHECK: OpBranchConditional %61 %63 %64
; CHECK: %63 = OpLabel
OpStore %22 %int_3239 Aligned 16
; CHECK: OpStore %22 %int_3239 Aligned 16
; CHECK: OpBranch %62
; CHECK: %64 = OpLabel
; CHECK: %65 = OpUConvert %uint %24
; CHECK: %67 = OpShiftRightLogical %ulong %24 %uint_32
; CHECK: %68 = OpUConvert %uint %67
; CHECK: %124 = OpFunctionCall %void %69 %uint_48 %uint_2 %65 %68
; CHECK: OpBranch %62
; CHECK: %62 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string func_after =
R"(%main = OpFunction %void None %8
%19 = OpLabel
%20 = OpAccessChain %_ptr_Uniform__ptr_PhysicalStorageBuffer_bufStruct %u_info %int_0
%21 = OpLoad %_ptr_PhysicalStorageBuffer_bufStruct %20
%22 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %21 %int_1
%24 = OpConvertPtrToU %ulong %22
%61 = OpFunctionCall %bool %26 %24 %uint_4
OpSelectionMerge %62 None
OpBranchConditional %61 %63 %64
%63 = OpLabel
OpStore %22 %int_3239 Aligned 16
OpBranch %62
%64 = OpLabel
%65 = OpUConvert %uint %24
%67 = OpShiftRightLogical %ulong %24 %uint_32
%68 = OpUConvert %uint %67
%124 = OpFunctionCall %void %69 %uint_48 %uint_2 %65 %68
OpBranch %62
%62 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string new_funcs =
R"(%26 = OpFunction %bool None %28
%29 = OpFunctionParameter %ulong
%30 = OpFunctionParameter %uint
%31 = OpLabel
OpBranch %32
%32 = OpLabel
%34 = OpPhi %uint %uint_1 %31 %35 %33
OpLoopMerge %37 %33 None
OpBranch %33
%33 = OpLabel
%35 = OpIAdd %uint %34 %uint_1
%44 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %35
%45 = OpLoad %ulong %44
%46 = OpUGreaterThan %bool %45 %29
OpBranchConditional %46 %37 %32
%37 = OpLabel
%47 = OpISub %uint %35 %uint_1
%48 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %47
%49 = OpLoad %ulong %48
%50 = OpISub %ulong %29 %49
%51 = OpUConvert %ulong %30
%52 = OpIAdd %ulong %50 %51
%53 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %uint_0
%54 = OpLoad %ulong %53
%55 = OpUConvert %uint %54
%56 = OpISub %uint %47 %uint_1
%57 = OpIAdd %uint %56 %55
%58 = OpAccessChain %_ptr_StorageBuffer_ulong %41 %uint_0 %57
%59 = OpLoad %ulong %58
%60 = OpULessThanEqual %bool %52 %59
OpReturnValue %60
OpFunctionEnd
%69 = OpFunction %void None %70
%71 = OpFunctionParameter %uint
%72 = OpFunctionParameter %uint
%73 = OpFunctionParameter %uint
%74 = OpFunctionParameter %uint
%75 = OpLabel
%81 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_0
%83 = OpAtomicIAdd %uint %81 %uint_4 %uint_0 %uint_10
%84 = OpIAdd %uint %83 %uint_10
%85 = OpArrayLength %uint %79 1
%86 = OpULessThanEqual %bool %84 %85
OpSelectionMerge %87 None
OpBranchConditional %86 %88 %87
%88 = OpLabel
%89 = OpIAdd %uint %83 %uint_0
%90 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %89
OpStore %90 %uint_10
%92 = OpIAdd %uint %83 %uint_1
%93 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %92
OpStore %93 %uint_23
%94 = OpIAdd %uint %83 %uint_2
%95 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %94
OpStore %95 %71
%98 = OpIAdd %uint %83 %uint_3
%99 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %98
OpStore %99 %uint_5
%103 = OpLoad %v3uint %gl_GlobalInvocationID
%104 = OpCompositeExtract %uint %103 0
%105 = OpCompositeExtract %uint %103 1
%106 = OpCompositeExtract %uint %103 2
%107 = OpIAdd %uint %83 %uint_4
%108 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %107
OpStore %108 %104
%109 = OpIAdd %uint %83 %uint_5
%110 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %109
OpStore %110 %105
%112 = OpIAdd %uint %83 %uint_6
%113 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %112
OpStore %113 %106
%115 = OpIAdd %uint %83 %uint_7
%116 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %115
OpStore %116 %72
%118 = OpIAdd %uint %83 %uint_8
%119 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %118
OpStore %119 %73
%121 = OpIAdd %uint %83 %uint_9
%122 = OpAccessChain %_ptr_StorageBuffer_uint %79 %uint_1 %121
OpStore %122 %74
OpBranch %87
%87 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string output_funcs = kSearchAndTest + kStreamWrite4Compute;
// SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndCheck<InstBuffAddrCheckPass>(
defs_before + func_before, defs_after + func_after + new_funcs, true,
true, 7u, 23u);
SinglePassRunAndMatch<InstBuffAddrCheckPass>(
defs + decorates + globals + main_func + output_funcs, true, 7u, 23u);
}
TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferLoadAndStore) {
@ -337,9 +341,10 @@ TEST_F(InstBuffAddrTest, InstPhysicalStorageBufferLoadAndStore) {
// b.x = 531;
// }
const std::string defs_before =
R"(OpCapability Shader
const std::string defs = R"(
OpCapability Shader
OpCapability PhysicalStorageBufferAddresses
; CHECK: OpCapability Int64
OpExtension "SPV_EXT_physical_storage_buffer"
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
@ -349,12 +354,17 @@ OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 450
OpSourceExtension "GL_EXT_buffer_reference"
OpName %main "main"
; CHECK: OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpName %blockType "blockType"
OpMemberName %blockType 0 "x"
OpMemberName %blockType 1 "next"
OpName %rootBlock "rootBlock"
OpMemberName %rootBlock 0 "root"
OpName %r "r"
)";
// clang-format off
const std::string decorates = R"(
OpMemberDecorate %blockType 0 Offset 0
OpMemberDecorate %blockType 1 Offset 8
OpDecorate %blockType Block
@ -362,6 +372,15 @@ OpMemberDecorate %rootBlock 0 Offset 0
OpDecorate %rootBlock Block
OpDecorate %r DescriptorSet 0
OpDecorate %r Binding 0
; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8
)" + kInputDecorations + R"(
; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
)" + kOutputDecorations + R"(
; CHECK: OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
)";
// clang-format on
const std::string globals = R"(
%void = OpTypeVoid
%3 = OpTypeFunction %void
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
@ -377,99 +396,10 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType
%int_531 = OpConstant %int 531
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
)";
)" + kInputGlobals + kOutputGlobals;
const std::string defs_after =
R"(OpCapability Shader
OpCapability PhysicalStorageBufferAddresses
OpCapability Int64
OpExtension "SPV_EXT_physical_storage_buffer"
OpExtension "SPV_KHR_storage_buffer_storage_class"
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %main "main" %gl_GlobalInvocationID
OpExecutionMode %main LocalSize 1 1 1
OpSource GLSL 450
OpSourceExtension "GL_EXT_buffer_reference"
OpName %main "main"
OpName %blockType "blockType"
OpMemberName %blockType 0 "x"
OpMemberName %blockType 1 "next"
OpName %rootBlock "rootBlock"
OpMemberName %rootBlock 0 "root"
OpName %r "r"
OpMemberDecorate %blockType 0 Offset 0
OpMemberDecorate %blockType 1 Offset 8
OpDecorate %blockType Block
OpMemberDecorate %rootBlock 0 Offset 0
OpDecorate %rootBlock Block
OpDecorate %r DescriptorSet 0
OpDecorate %r Binding 0
OpDecorate %_runtimearr_ulong ArrayStride 8
OpDecorate %_struct_45 Block
OpMemberDecorate %_struct_45 0 Offset 0
OpDecorate %47 DescriptorSet 7
OpDecorate %47 Binding 2
OpDecorate %_runtimearr_uint ArrayStride 4
OpDecorate %_struct_84 Block
OpMemberDecorate %_struct_84 0 Offset 0
OpMemberDecorate %_struct_84 1 Offset 4
OpDecorate %86 DescriptorSet 7
OpDecorate %86 Binding 0
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
%void = OpTypeVoid
%3 = OpTypeFunction %void
OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
%int = OpTypeInt 32 1
%blockType = OpTypeStruct %int %_ptr_PhysicalStorageBuffer_blockType
%_ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %blockType
%rootBlock = OpTypeStruct %_ptr_PhysicalStorageBuffer_blockType
%_ptr_StorageBuffer_rootBlock = OpTypePointer StorageBuffer %rootBlock
%r = OpVariable %_ptr_StorageBuffer_rootBlock StorageBuffer
%int_0 = OpConstant %int 0
%_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer StorageBuffer %_ptr_PhysicalStorageBuffer_blockType
%int_1 = OpConstant %int 1
%_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType = OpTypePointer PhysicalStorageBuffer %_ptr_PhysicalStorageBuffer_blockType
%int_531 = OpConstant %int 531
%_ptr_PhysicalStorageBuffer_int = OpTypePointer PhysicalStorageBuffer %int
%uint = OpTypeInt 32 0
%uint_2 = OpConstant %uint 2
%ulong = OpTypeInt 64 0
%uint_8 = OpConstant %uint 8
%bool = OpTypeBool
%34 = OpTypeFunction %bool %ulong %uint
%uint_1 = OpConstant %uint 1
%_runtimearr_ulong = OpTypeRuntimeArray %ulong
%_struct_45 = OpTypeStruct %_runtimearr_ulong
%_ptr_StorageBuffer__struct_45 = OpTypePointer StorageBuffer %_struct_45
%47 = OpVariable %_ptr_StorageBuffer__struct_45 StorageBuffer
%_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong
%uint_0 = OpConstant %uint 0
%uint_32 = OpConstant %uint 32
%77 = OpTypeFunction %void %uint %uint %uint %uint
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_84 = OpTypeStruct %uint %_runtimearr_uint
%_ptr_StorageBuffer__struct_84 = OpTypePointer StorageBuffer %_struct_84
%86 = OpVariable %_ptr_StorageBuffer__struct_84 StorageBuffer
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_10 = OpConstant %uint 10
%uint_4 = OpConstant %uint 4
%uint_23 = OpConstant %uint 23
%uint_5 = OpConstant %uint 5
%uint_3 = OpConstant %uint 3
%v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%uint_6 = OpConstant %uint 6
%uint_7 = OpConstant %uint 7
%uint_9 = OpConstant %uint 9
%uint_44 = OpConstant %uint 44
%132 = OpConstantNull %ulong
%uint_46 = OpConstant %uint 46
)";
const std::string func_before =
R"(%main = OpFunction %void None %3
const std::string main_func = R"(
%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0
%17 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %16
@ -477,142 +407,48 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_blockType PhysicalStorageBuffer
%22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0
OpStore %26 %int_531 Aligned 16
; CHECK-NOT: %22 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8
; CHECK-NOT: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %22 %int_0
; CHECK: %30 = OpConvertPtrToU %ulong %21
; CHECK: %67 = OpFunctionCall %bool %32 %30 %uint_8
; CHECK: OpSelectionMerge %68 None
; CHECK: OpBranchConditional %67 %69 %70
; CHECK: %69 = OpLabel
; CHECK: %71 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8
; CHECK: OpBranch %68
; CHECK: %70 = OpLabel
; CHECK: %72 = OpUConvert %uint %30
; CHECK: %74 = OpShiftRightLogical %ulong %30 %uint_32
; CHECK: %75 = OpUConvert %uint %74
; CHECK: %131 = OpFunctionCall %void %76 %uint_44 %uint_2 %72 %75
; CHECK: %133 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType %132
; CHECK: OpBranch %68
; CHECK: %68 = OpLabel
; CHECK: %134 = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 %133 %70
; CHECK: %26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %134 %int_0
; CHECK: %135 = OpConvertPtrToU %ulong %26
; CHECK: %136 = OpFunctionCall %bool %32 %135 %uint_4
; CHECK: OpSelectionMerge %137 None
; CHECK: OpBranchConditional %136 %138 %139
; CHECK: %138 = OpLabel
; CHECK: OpStore %26 %int_531 Aligned 16
; CHECK: OpBranch %137
; CHECK: %139 = OpLabel
; CHECK: %140 = OpUConvert %uint %135
; CHECK: %141 = OpShiftRightLogical %ulong %135 %uint_32
; CHECK: %142 = OpUConvert %uint %141
; CHECK: %144 = OpFunctionCall %void %76 %uint_46 %uint_2 %140 %142
; CHECK: OpBranch %137
; CHECK: %137 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string func_after =
R"(%main = OpFunction %void None %3
%5 = OpLabel
%16 = OpAccessChain %_ptr_StorageBuffer__ptr_PhysicalStorageBuffer_blockType %r %int_0
%17 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %16
%21 = OpAccessChain %_ptr_PhysicalStorageBuffer__ptr_PhysicalStorageBuffer_blockType %17 %int_1
%30 = OpConvertPtrToU %ulong %21
%67 = OpFunctionCall %bool %32 %30 %uint_8
OpSelectionMerge %68 None
OpBranchConditional %67 %69 %70
%69 = OpLabel
%71 = OpLoad %_ptr_PhysicalStorageBuffer_blockType %21 Aligned 8
OpBranch %68
%70 = OpLabel
%72 = OpUConvert %uint %30
%74 = OpShiftRightLogical %ulong %30 %uint_32
%75 = OpUConvert %uint %74
%131 = OpFunctionCall %void %76 %uint_44 %uint_2 %72 %75
%133 = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_blockType %132
OpBranch %68
%68 = OpLabel
%134 = OpPhi %_ptr_PhysicalStorageBuffer_blockType %71 %69 %133 %70
%26 = OpAccessChain %_ptr_PhysicalStorageBuffer_int %134 %int_0
%135 = OpConvertPtrToU %ulong %26
%136 = OpFunctionCall %bool %32 %135 %uint_4
OpSelectionMerge %137 None
OpBranchConditional %136 %138 %139
%138 = OpLabel
OpStore %26 %int_531 Aligned 16
OpBranch %137
%139 = OpLabel
%140 = OpUConvert %uint %135
%141 = OpShiftRightLogical %ulong %135 %uint_32
%142 = OpUConvert %uint %141
%144 = OpFunctionCall %void %76 %uint_46 %uint_2 %140 %142
OpBranch %137
%137 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string new_funcs =
R"(%32 = OpFunction %bool None %34
%35 = OpFunctionParameter %ulong
%36 = OpFunctionParameter %uint
%37 = OpLabel
OpBranch %38
%38 = OpLabel
%40 = OpPhi %uint %uint_1 %37 %41 %39
OpLoopMerge %43 %39 None
OpBranch %39
%39 = OpLabel
%41 = OpIAdd %uint %40 %uint_1
%50 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %41
%51 = OpLoad %ulong %50
%52 = OpUGreaterThan %bool %51 %35
OpBranchConditional %52 %43 %38
%43 = OpLabel
%53 = OpISub %uint %41 %uint_1
%54 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %53
%55 = OpLoad %ulong %54
%56 = OpISub %ulong %35 %55
%57 = OpUConvert %ulong %36
%58 = OpIAdd %ulong %56 %57
%59 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %uint_0
%60 = OpLoad %ulong %59
%61 = OpUConvert %uint %60
%62 = OpISub %uint %53 %uint_1
%63 = OpIAdd %uint %62 %61
%64 = OpAccessChain %_ptr_StorageBuffer_ulong %47 %uint_0 %63
%65 = OpLoad %ulong %64
%66 = OpULessThanEqual %bool %58 %65
OpReturnValue %66
OpFunctionEnd
%76 = OpFunction %void None %77
%78 = OpFunctionParameter %uint
%79 = OpFunctionParameter %uint
%80 = OpFunctionParameter %uint
%81 = OpFunctionParameter %uint
%82 = OpLabel
%88 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_0
%91 = OpAtomicIAdd %uint %88 %uint_4 %uint_0 %uint_10
%92 = OpIAdd %uint %91 %uint_10
%93 = OpArrayLength %uint %86 1
%94 = OpULessThanEqual %bool %92 %93
OpSelectionMerge %95 None
OpBranchConditional %94 %96 %95
%96 = OpLabel
%97 = OpIAdd %uint %91 %uint_0
%98 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %97
OpStore %98 %uint_10
%100 = OpIAdd %uint %91 %uint_1
%101 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %100
OpStore %101 %uint_23
%102 = OpIAdd %uint %91 %uint_2
%103 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %102
OpStore %103 %78
%106 = OpIAdd %uint %91 %uint_3
%107 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %106
OpStore %107 %uint_5
%111 = OpLoad %v3uint %gl_GlobalInvocationID
%112 = OpCompositeExtract %uint %111 0
%113 = OpCompositeExtract %uint %111 1
%114 = OpCompositeExtract %uint %111 2
%115 = OpIAdd %uint %91 %uint_4
%116 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %115
OpStore %116 %112
%117 = OpIAdd %uint %91 %uint_5
%118 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %117
OpStore %118 %113
%120 = OpIAdd %uint %91 %uint_6
%121 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %120
OpStore %121 %114
%123 = OpIAdd %uint %91 %uint_7
%124 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %123
OpStore %124 %79
%125 = OpIAdd %uint %91 %uint_8
%126 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %125
OpStore %126 %80
%128 = OpIAdd %uint %91 %uint_9
%129 = OpAccessChain %_ptr_StorageBuffer_uint %86 %uint_1 %128
OpStore %129 %81
OpBranch %95
%95 = OpLabel
OpReturn
OpFunctionEnd
)";
const std::string output_funcs = kSearchAndTest + kStreamWrite4Compute;
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndCheck<InstBuffAddrCheckPass>(
defs_before + func_before, defs_after + func_after + new_funcs, true,
true, 7u, 23u);
SinglePassRunAndMatch<InstBuffAddrCheckPass>(
defs + decorates + globals + main_func + output_funcs, true, 7u, 23u);
}
TEST_F(InstBuffAddrTest, StructLoad) {
@ -657,27 +493,19 @@ OpName %TestBuffer "TestBuffer"
OpMemberName %TestBuffer 0 "test"
)";
const std::string decorates =
R"(
// clang-format off
const std::string decorates = R"(
OpMemberDecorate %Test_0 0 Offset 0
OpMemberDecorate %TestBuffer 0 Offset 0
OpDecorate %TestBuffer Block
; CHECK: OpDecorate %_runtimearr_ulong ArrayStride 8
; CHECK: OpDecorate %_struct_58 Block
; CHECK: OpMemberDecorate %_struct_58 0 Offset 0
; CHECK: OpDecorate %60 DescriptorSet 7
; CHECK: OpDecorate %60 Binding 2
)" + kInputDecorations + R"(
; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
; CHECK: OpDecorate %_struct_97 Block
; CHECK: OpMemberDecorate %_struct_97 0 Offset 0
; CHECK: OpMemberDecorate %_struct_97 1 Offset 4
; CHECK: OpDecorate %99 DescriptorSet 7
; CHECK: OpDecorate %99 Binding 0
)" + kOutputDecorations + R"(
; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
)";
const std::string globals =
R"(
const std::string globals = R"(
%void = OpTypeVoid
%3 = OpTypeFunction %void
%ulong = OpTypeInt 64 0
@ -692,15 +520,14 @@ OpTypeForwardPointer %_ptr_PhysicalStorageBuffer_TestBuffer PhysicalStorageBuffe
%_ptr_PhysicalStorageBuffer_Test_0 = OpTypePointer PhysicalStorageBuffer %Test_0
%ulong_18446744073172680704 = OpConstant %ulong 18446744073172680704
; CHECK: %47 = OpTypeFunction %bool %ulong %uint
; CHECK: %_struct_58 = OpTypeStruct %_runtimearr_ulong
; CHECK: %60 = OpVariable %_ptr_StorageBuffer__struct_58 StorageBuffer
)" + kInputGlobals + R"(
; CHECK: %90 = OpTypeFunction %void %uint %uint %uint %uint
; CHECK: %_struct_97 = OpTypeStruct %uint %_runtimearr_uint
; CHECK: %99 = OpVariable %_ptr_StorageBuffer__struct_97 StorageBuffer
)" + kOutputGlobals + R"(
; CHECK: %143 = OpConstantNull %Test_0
)";
// clang-format on
const std::string main =
const std::string main_func =
R"(
%main = OpFunction %void None %3
%5 = OpLabel
@ -730,95 +557,12 @@ OpReturn
OpFunctionEnd
)";
const std::string output_funcs =
R"(
; CHECK: %45 = OpFunction %bool None %47
; CHECK: %48 = OpFunctionParameter %ulong
; CHECK: %49 = OpFunctionParameter %uint
; CHECK: %50 = OpLabel
; CHECK: OpBranch %51
; CHECK: %51 = OpLabel
; CHECK: %53 = OpPhi %uint %uint_1 %50 %54 %52
; CHECK: OpLoopMerge %56 %52 None
; CHECK: OpBranch %52
; CHECK: %52 = OpLabel
; CHECK: %54 = OpIAdd %uint %53 %uint_1
; CHECK: %63 = OpAccessChain %_ptr_StorageBuffer_ulong %60 %uint_0 %54
; CHECK: %64 = OpLoad %ulong %63
; CHECK: %65 = OpUGreaterThan %bool %64 %48
; CHECK: OpBranchConditional %65 %56 %51
; CHECK: %56 = OpLabel
; CHECK: %66 = OpISub %uint %54 %uint_1
; CHECK: %67 = OpAccessChain %_ptr_StorageBuffer_ulong %60 %uint_0 %66
; CHECK: %68 = OpLoad %ulong %67
; CHECK: %69 = OpISub %ulong %48 %68
; CHECK: %70 = OpUConvert %ulong %49
; CHECK: %71 = OpIAdd %ulong %69 %70
; CHECK: %72 = OpAccessChain %_ptr_StorageBuffer_ulong %60 %uint_0 %uint_0
; CHECK: %73 = OpLoad %ulong %72
; CHECK: %74 = OpUConvert %uint %73
; CHECK: %75 = OpISub %uint %66 %uint_1
; CHECK: %76 = OpIAdd %uint %75 %74
; CHECK: %77 = OpAccessChain %_ptr_StorageBuffer_ulong %60 %uint_0 %76
; CHECK: %78 = OpLoad %ulong %77
; CHECK: %79 = OpULessThanEqual %bool %71 %78
; CHECK: OpReturnValue %79
; CHECK: OpFunctionEnd
; CHECK: %89 = OpFunction %void None %90
; CHECK: %91 = OpFunctionParameter %uint
; CHECK: %92 = OpFunctionParameter %uint
; CHECK: %93 = OpFunctionParameter %uint
; CHECK: %94 = OpFunctionParameter %uint
; CHECK: %95 = OpLabel
; CHECK: %101 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_0
; CHECK: %103 = OpAtomicIAdd %uint %101 %uint_4 %uint_0 %uint_10
; CHECK: %104 = OpIAdd %uint %103 %uint_10
; CHECK: %105 = OpArrayLength %uint %99 1
; CHECK: %106 = OpULessThanEqual %bool %104 %105
; CHECK: OpSelectionMerge %107 None
; CHECK: OpBranchConditional %106 %108 %107
; CHECK: %108 = OpLabel
; CHECK: %109 = OpIAdd %uint %103 %uint_0
; CHECK: %110 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %109
; CHECK: OpStore %110 %uint_10
; CHECK: %112 = OpIAdd %uint %103 %uint_1
; CHECK: %113 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %112
; CHECK: OpStore %113 %uint_23
; CHECK: %114 = OpIAdd %uint %103 %uint_2
; CHECK: %115 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %114
; CHECK: OpStore %115 %91
; CHECK: %117 = OpIAdd %uint %103 %uint_3
; CHECK: %118 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %117
; CHECK: OpStore %118 %uint_4
; CHECK: %122 = OpLoad %v4float %gl_FragCoord
; CHECK: %124 = OpBitcast %v4uint %122
; CHECK: %125 = OpCompositeExtract %uint %124 0
; CHECK: %126 = OpIAdd %uint %103 %uint_4
; CHECK: %127 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %126
; CHECK: OpStore %127 %125
; CHECK: %128 = OpCompositeExtract %uint %124 1
; CHECK: %130 = OpIAdd %uint %103 %uint_5
; CHECK: %131 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %130
; CHECK: OpStore %131 %128
; CHECK: %133 = OpIAdd %uint %103 %uint_7
; CHECK: %134 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %133
; CHECK: OpStore %134 %92
; CHECK: %136 = OpIAdd %uint %103 %uint_8
; CHECK: %137 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %136
; CHECK: OpStore %137 %93
; CHECK: %139 = OpIAdd %uint %103 %uint_9
; CHECK: %140 = OpAccessChain %_ptr_StorageBuffer_uint %99 %uint_1 %139
; CHECK: OpStore %140 %94
; CHECK: OpBranch %107
; CHECK: %107 = OpLabel
; CHECK: OpReturn
; CHECK: OpFunctionEnd
)";
const std::string output_funcs = kSearchAndTest + kStreamWrite4Frag;
SetTargetEnv(SPV_ENV_VULKAN_1_2);
SetAssembleOptions(SPV_TEXT_TO_BINARY_OPTION_PRESERVE_NUMERIC_IDS);
SinglePassRunAndMatch<InstBuffAddrCheckPass>(
defs + decorates + globals + main + output_funcs, true);
defs + decorates + globals + main_func + output_funcs, true);
}
} // namespace

View File

@ -1,5 +1,5 @@
// Copyright (c) 2020 Valve Corporation
// Copyright (c) 2020 LunarG Inc.
// Copyright (c) 2020-2022 Valve Corporation
// Copyright (c) 2020-2022 LunarG Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -26,6 +26,20 @@ namespace spvtools {
namespace opt {
namespace {
static const std::string kOutputDecorations = R"(
; CHECK: OpDecorate [[output_buffer_type:%_struct_\w+]] Block
; CHECK: OpMemberDecorate [[output_buffer_type]] 0 Offset 0
; CHECK: OpMemberDecorate [[output_buffer_type]] 1 Offset 4
; CHECK: OpDecorate [[output_buffer_var:%\w+]] DescriptorSet 7
; CHECK: OpDecorate [[output_buffer_var]] Binding 3
)";
static const std::string kOutputGlobals = R"(
; CHECK: [[output_buffer_type]] = OpTypeStruct %uint %_runtimearr_uint
; CHECK: [[output_ptr_type:%\w+]] = OpTypePointer StorageBuffer [[output_buffer_type]]
; CHECK: [[output_buffer_var]] = OpVariable [[output_ptr_type]] StorageBuffer
)";
using InstDebugPrintfTest = PassTest<::testing::Test>;
TEST_F(InstDebugPrintfTest, V4Float32) {
@ -65,6 +79,7 @@ OpExecutionMode %2 OriginUpperLeft
%5 = OpString "Color is %vn"
)";
// clang-format off
const std::string decorates =
R"(OpDecorate %6 DescriptorSet 0
OpDecorate %6 Binding 1
@ -73,11 +88,7 @@ OpDecorate %7 Binding 0
OpDecorate %3 Location 0
OpDecorate %4 Location 0
; CHECK: OpDecorate %_runtimearr_uint ArrayStride 4
; CHECK: OpDecorate %_struct_47 Block
; CHECK: OpMemberDecorate %_struct_47 0 Offset 0
; CHECK: OpMemberDecorate %_struct_47 1 Offset 4
; CHECK: OpDecorate %49 DescriptorSet 7
; CHECK: OpDecorate %49 Binding 3
)" + kOutputDecorations + R"(
; CHECK: OpDecorate %gl_FragCoord BuiltIn FragCoord
)";
@ -101,15 +112,14 @@ OpDecorate %4 Location 0
; CHECK: %uint = OpTypeInt 32 0
; CHECK: %38 = OpTypeFunction %void %uint %uint %uint %uint %uint %uint
; CHECK: %_runtimearr_uint = OpTypeRuntimeArray %uint
; CHECK: %_struct_47 = OpTypeStruct %uint %_runtimearr_uint
; CHECK: %_ptr_StorageBuffer__struct_47 = OpTypePointer StorageBuffer %_struct_47
; CHECK: %49 = OpVariable %_ptr_StorageBuffer__struct_47 StorageBuffer
)" + kOutputGlobals + R"(
; CHECK: %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
; CHECK: %bool = OpTypeBool
; CHECK: %_ptr_Input_v4float = OpTypePointer Input %v4float
; CHECK: %gl_FragCoord = OpVariable %_ptr_Input_v4float Input
; CHECK: %v4uint = OpTypeVector %uint 4
)";
// clang-format on
const std::string main =
R"(%2 = OpFunction %void None %9