Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjodinchr committed Jan 7, 2024
1 parent 6fddff1 commit b263c74
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,15 @@ jobs:
-DCMAKE_CXX_COMPILER="$(which clang++)" \
-DCMAKE_BUILD_TYPE=Release
cmake --build build_release
- name: Tests
run: |
$(pwd)/build_release/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example.spvasm
$(pwd)/build_release/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example-with-counter.spvasm | grep "my_counter"
$(pwd)/third_party/perfetto/out/linux_clang_release/traced &
$(pwd)/third_party/perfetto/out/linux_clang_release/perfetto -c $(pwd)/tests/perfetto_config --txt -o trace &
sleep 1
LD_LIBRARY_PATH=$(pwd)/build_release/layer:${LD_LIBRARY_PATH} VK_ADD_LAYER_PATH="$(pwd)/manifest/" VK_LOADER_LAYERS_ENABLE="VK_LAYER_SHADER_PROFILER" $(pwd)/build_release/runner/vulkan-shader-profiler-runner -i $(pwd)/tests/example.spvasm
pkill -x perfetto
while [[ -n $(pgrep -x perfetto) ]]; do sleep 0.2; done
$(pwd)/build_release/extractor/vulkan-shader-profiler-extractor -i trace -o trace.spvasm -d 0
diff trace.spvasm $(pwd)/tests/expected.spvasm
91 changes: 91 additions & 0 deletions tests/example-with-counter.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
; SPIR-V
; Version: 1.6
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 57
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "NonSemantic.ClspvReflection.5"
%49 = OpExtInstImport "NonSemantic.VkspReflection.1"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %2 "test_simple" %gl_GlobalInvocationID %4 %5 %6

; Debug Information
OpSource OpenCL_C 120
%7 = OpString "test_simple"
%8 = OpString " kernel"
%9 = OpString "out"
%10 = OpString "uint*"

; Annotations
OpMemberDecorate %_struct_11 0 Offset 0
OpMemberDecorate %_struct_11 1 Offset 16
OpDecorate %_struct_11 Block
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
OpDecorate %_runtimearr_uint ArrayStride 4
OpMemberDecorate %_struct_14 0 Offset 0
OpDecorate %_struct_14 Block
OpDecorate %5 DescriptorSet 0
OpDecorate %5 Binding 0
OpDecorate %15 SpecId 0
OpDecorate %16 SpecId 1
OpDecorate %17 SpecId 2

; Types, variables and constants
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%_struct_11 = OpTypeStruct %v3uint %v3uint
%_ptr_PushConstant__struct_11 = OpTypePointer PushConstant %_struct_11
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%15 = OpSpecConstant %uint 1
%16 = OpSpecConstant %uint 1
%17 = OpSpecConstant %uint 1
%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %15 %16 %17
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_14 = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer__struct_14 = OpTypePointer StorageBuffer %_struct_14
%void = OpTypeVoid
%25 = OpTypeFunction %void
%_ptr_Input_uint = OpTypePointer Input %uint
%uint_0 = OpConstant %uint 0
%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
%uint_1 = OpConstant %uint 1
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_4507 = OpConstant %uint 4507
%uint_4515 = OpConstant %uint 4515
%uint_12 = OpConstant %uint 12
%uint_16 = OpConstant %uint 16
%uint_2 = OpConstant %uint 2
%6 = OpVariable %_ptr_PushConstant__struct_11 PushConstant
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%4 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize
%5 = OpVariable %_ptr_StorageBuffer__struct_14 StorageBuffer
%50 = OpExtInst %void %49 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1
%51 = OpExtInst %void %49 PushConstants 16 12 "000000000000000000000000" 32
%52 = OpExtInst %void %49 PushConstants 0 12 "000000000000000000000000" 32
%53 = OpExtInst %void %49 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0
%54 = OpExtInst %void %49 SpecializationMapEntry 0 0 4
%55 = OpExtInst %void %49 SpecializationMapEntry 1 4 4
%56 = OpExtInst %void %49 SpecializationMapEntry 2 8 4

; Function 2
%2 = OpFunction %void None %25
%36 = OpLabel
%37 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
%38 = OpLoad %uint %37
%39 = OpAccessChain %_ptr_PushConstant_uint %6 %uint_1 %uint_0
%40 = OpLoad %uint %39
%counter = OpExtInst %void %49 StartCounter "my_counter"
%41 = OpIAdd %uint %40 %38
%unused = OpExtInst %void %49 StopCounter %counter
%42 = OpAccessChain %_ptr_StorageBuffer_uint %5 %uint_0 %41
OpStore %42 %41
OpReturn
OpFunctionEnd
%43 = OpExtInst %void %1 PushConstantGlobalOffset %uint_0 %uint_12
%44 = OpExtInst %void %1 PushConstantRegionOffset %uint_16 %uint_12
%45 = OpExtInst %void %1 Kernel %2 %7 %uint_1 %uint_0 %8
%46 = OpExtInst %void %1 ArgumentInfo %9 %10 %uint_4507 %uint_4515 %uint_0
%47 = OpExtInst %void %1 ArgumentStorageBuffer %45 %uint_0 %uint_0 %uint_0 %46
%48 = OpExtInst %void %1 SpecConstantWorkgroupSize %uint_0 %uint_1 %uint_2
89 changes: 89 additions & 0 deletions tests/example.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
; SPIR-V
; Version: 1.6
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 57
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "NonSemantic.ClspvReflection.5"
%49 = OpExtInstImport "NonSemantic.VkspReflection.1"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %2 "test_simple" %gl_GlobalInvocationID %4 %5 %6

; Debug Information
OpSource OpenCL_C 120
%7 = OpString "test_simple"
%8 = OpString " kernel"
%9 = OpString "out"
%10 = OpString "uint*"

; Annotations
OpMemberDecorate %_struct_11 0 Offset 0
OpMemberDecorate %_struct_11 1 Offset 16
OpDecorate %_struct_11 Block
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
OpDecorate %_runtimearr_uint ArrayStride 4
OpMemberDecorate %_struct_14 0 Offset 0
OpDecorate %_struct_14 Block
OpDecorate %5 DescriptorSet 0
OpDecorate %5 Binding 0
OpDecorate %15 SpecId 0
OpDecorate %16 SpecId 1
OpDecorate %17 SpecId 2

; Types, variables and constants
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%_struct_11 = OpTypeStruct %v3uint %v3uint
%_ptr_PushConstant__struct_11 = OpTypePointer PushConstant %_struct_11
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%15 = OpSpecConstant %uint 1
%16 = OpSpecConstant %uint 1
%17 = OpSpecConstant %uint 1
%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %15 %16 %17
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_14 = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer__struct_14 = OpTypePointer StorageBuffer %_struct_14
%void = OpTypeVoid
%25 = OpTypeFunction %void
%_ptr_Input_uint = OpTypePointer Input %uint
%uint_0 = OpConstant %uint 0
%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
%uint_1 = OpConstant %uint 1
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_4507 = OpConstant %uint 4507
%uint_4515 = OpConstant %uint 4515
%uint_12 = OpConstant %uint 12
%uint_16 = OpConstant %uint 16
%uint_2 = OpConstant %uint 2
%6 = OpVariable %_ptr_PushConstant__struct_11 PushConstant
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%4 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize
%5 = OpVariable %_ptr_StorageBuffer__struct_14 StorageBuffer
%50 = OpExtInst %void %49 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_EXT_descriptor_indexing" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1
%51 = OpExtInst %void %49 PushConstants 16 12 "000000000000000000000000" 32
%52 = OpExtInst %void %49 PushConstants 0 12 "000000000000000000000000" 32
%53 = OpExtInst %void %49 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0
%54 = OpExtInst %void %49 SpecializationMapEntry 0 0 4
%55 = OpExtInst %void %49 SpecializationMapEntry 1 4 4
%56 = OpExtInst %void %49 SpecializationMapEntry 2 8 4

; Function 2
%2 = OpFunction %void None %25
%36 = OpLabel
%37 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
%38 = OpLoad %uint %37
%39 = OpAccessChain %_ptr_PushConstant_uint %6 %uint_1 %uint_0
%40 = OpLoad %uint %39
%41 = OpIAdd %uint %40 %38
%42 = OpAccessChain %_ptr_StorageBuffer_uint %5 %uint_0 %41
OpStore %42 %41
OpReturn
OpFunctionEnd
%43 = OpExtInst %void %1 PushConstantGlobalOffset %uint_0 %uint_12
%44 = OpExtInst %void %1 PushConstantRegionOffset %uint_16 %uint_12
%45 = OpExtInst %void %1 Kernel %2 %7 %uint_1 %uint_0 %8
%46 = OpExtInst %void %1 ArgumentInfo %9 %10 %uint_4507 %uint_4515 %uint_0
%47 = OpExtInst %void %1 ArgumentStorageBuffer %45 %uint_0 %uint_0 %uint_0 %46
%48 = OpExtInst %void %1 SpecConstantWorkgroupSize %uint_0 %uint_1 %uint_2
112 changes: 112 additions & 0 deletions tests/expected.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
; SPIR-V
; Version: 1.6
; Generator: Khronos SPIR-V Tools Assembler; 0
; Bound: 70
; Schema: 0
OpCapability Shader
OpCapability ShaderClockKHR
OpCapability Int64
OpCapability Int64Atomics
OpExtension "SPV_KHR_shader_clock"
OpExtension "SPV_KHR_storage_buffer_storage_class"
%62 = OpExtInstImport "NonSemantic.VkspReflection.1"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %1 "test_simple" %gl_GlobalInvocationID %3 %4 %5 %6 %7

; Debug Information
OpSource OpenCL_C 120
%8 = OpString "test_simple"
%9 = OpString " kernel"
%10 = OpString "out"
%11 = OpString "uint*"

; Annotations
OpMemberDecorate %_struct_12 0 Offset 0
OpMemberDecorate %_struct_12 1 Offset 16
OpDecorate %_struct_12 Block
OpDecorate %gl_GlobalInvocationID BuiltIn GlobalInvocationId
OpDecorate %gl_WorkGroupSize BuiltIn WorkgroupSize
OpDecorate %_runtimearr_uint ArrayStride 4
OpMemberDecorate %_struct_15 0 Offset 0
OpDecorate %_struct_15 Block
OpDecorate %4 DescriptorSet 0
OpDecorate %4 Binding 0
OpDecorate %16 SpecId 0
OpDecorate %17 SpecId 1
OpDecorate %18 SpecId 2
OpDecorate %_runtimearr_ulong ArrayStride 8
OpMemberDecorate %_struct_20 0 Offset 0
OpDecorate %_struct_20 Block
OpDecorate %6 DescriptorSet 0
OpDecorate %6 Binding 1

; Types, variables and constants
%uint = OpTypeInt 32 0
%v3uint = OpTypeVector %uint 3
%_struct_12 = OpTypeStruct %v3uint %v3uint
%_ptr_PushConstant__struct_12 = OpTypePointer PushConstant %_struct_12
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%16 = OpSpecConstant %uint 1
%17 = OpSpecConstant %uint 1
%18 = OpSpecConstant %uint 1
%gl_WorkGroupSize = OpSpecConstantComposite %v3uint %16 %17 %18
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_15 = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer__struct_15 = OpTypePointer StorageBuffer %_struct_15
%void = OpTypeVoid
%28 = OpTypeFunction %void
%_ptr_Input_uint = OpTypePointer Input %uint
%uint_0 = OpConstant %uint 0
%_ptr_PushConstant_uint = OpTypePointer PushConstant %uint
%uint_1 = OpConstant %uint 1
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_4507 = OpConstant %uint 4507
%uint_4515 = OpConstant %uint 4515
%uint_12 = OpConstant %uint 12
%uint_16 = OpConstant %uint 16
%uint_2 = OpConstant %uint 2
%5 = OpVariable %_ptr_PushConstant__struct_12 PushConstant
%gl_GlobalInvocationID = OpVariable %_ptr_Input_v3uint Input
%3 = OpVariable %_ptr_Private_v3uint Private %gl_WorkGroupSize
%4 = OpVariable %_ptr_StorageBuffer__struct_15 StorageBuffer
%ulong = OpTypeInt 64 0
%_runtimearr_ulong = OpTypeRuntimeArray %ulong
%_struct_20 = OpTypeStruct %_runtimearr_ulong
%_ptr_StorageBuffer__struct_20 = OpTypePointer StorageBuffer %_struct_20
%_ptr_StorageBuffer_ulong = OpTypePointer StorageBuffer %ulong
%_arr_ulong_uint_0 = OpTypeArray %ulong %uint_0
%_ptr_Private__arr_ulong_uint_0 = OpTypePointer Private %_arr_ulong_uint_0
%_ptr_Private_ulong = OpTypePointer Private %ulong
%uint_3 = OpConstant %uint 3
%uint_8 = OpConstant %uint 8
%7 = OpVariable %_ptr_Private__arr_ulong_uint_0 Private
%6 = OpVariable %_ptr_StorageBuffer__struct_20 StorageBuffer
%ulong_0 = OpConstant %ulong 0
%63 = OpExtInst %void %62 Configuration ".VK_KHR_8bit_storage.VK_KHR_16bit_storage.VK_KHR_buffer_device_address.VK_KHR_driver_properties.VK_KHR_shader_float16_int8.VK_KHR_shader_float_controls.VK_KHR_shader_non_semantic_info.VK_KHR_storage_buffer_storage_class.VK_KHR_uniform_buffer_standard_layout.VK_KHR_variable_pointers.VK_KHR_vulkan_memory_model.VK_EXT_calibrated_timestamps.VK_KHR_shader_clock" 12 "020000000100000001000000" "vksp_s0" "test_simple" 128 1 1
%64 = OpExtInst %void %62 PushConstants 0 28 "00000000000000000000000000000000000000000000000000000000" 32
%65 = OpExtInst %void %62 DescriptorSetBuffer 0 0 7 0 0 0 1024 63 1024 0 1024 0 0
%66 = OpExtInst %void %62 DescriptorSetBuffer 0 1 7 0 0 0 16 34 16 0 16 0 0
%67 = OpExtInst %void %62 SpecializationMapEntry 0 0 4
%68 = OpExtInst %void %62 SpecializationMapEntry 1 4 4
%69 = OpExtInst %void %62 SpecializationMapEntry 2 8 4

; Function 1
%1 = OpFunction %void None %28
%48 = OpLabel
%49 = OpReadClockKHR %ulong %uint_3
%50 = OpAccessChain %_ptr_Input_uint %gl_GlobalInvocationID %uint_0
%51 = OpLoad %uint %50
%52 = OpAccessChain %_ptr_PushConstant_uint %5 %uint_1 %uint_0
%53 = OpLoad %uint %52
%54 = OpIAdd %uint %53 %51
%55 = OpAccessChain %_ptr_StorageBuffer_uint %4 %uint_0 %54
OpStore %55 %54
%56 = OpReadClockKHR %ulong %uint_3
%57 = OpISub %ulong %56 %49
%58 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_0
%59 = OpAtomicIIncrement %ulong %58 %uint_1 %uint_8
%60 = OpAccessChain %_ptr_StorageBuffer_ulong %6 %uint_0 %uint_1
%61 = OpAtomicIAdd %ulong %60 %uint_1 %uint_8 %57
OpReturn
OpFunctionEnd
18 changes: 18 additions & 0 deletions tests/perfetto_config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

buffers {
size_kb: 524288
fill_policy: DISCARD
}

data_sources {
config {
name: "track_event"
track_event_config {
disable_incremental_timestamps: true
disabled_categories: "toplevel"
#enabled_tags: "slow"
}
}
}


0 comments on commit b263c74

Please sign in to comment.