Skip to content

Commit efd7d21

Browse files
committed
Add profiling layer support
1 parent cc96378 commit efd7d21

File tree

5 files changed

+96
-2
lines changed

5 files changed

+96
-2
lines changed

layer_gpu_profile/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ add_library(
4949
layer_device_functions_command_buffer.cpp
5050
layer_device_functions_command_pool.cpp
5151
layer_device_functions_debug.cpp
52+
layer_device_functions_dispatch_data_graph.cpp
5253
layer_device_functions_dispatch.cpp
5354
layer_device_functions_queue.cpp
5455
layer_device_functions_render_pass.cpp

layer_gpu_profile/source/layer_device_functions.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchIndirect<user_tag>(VkCommandBuffer
194194
VkBuffer buffer,
195195
VkDeviceSize offset);
196196

197+
// Commands for data graph
198+
199+
/* See Vulkan API for documentation. */
200+
template<>
201+
VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchDataGraphARM<user_tag>(VkCommandBuffer commandBuffer,
202+
VkDataGraphPipelineSessionARM session,
203+
const VkDataGraphPipelineDispatchInfoARM* pInfo);
204+
197205
// Commands for trace rays
198206

199207
/* See Vulkan API for documentation. */
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* ----------------------------------------------------------------------------
4+
* Copyright (c) 2024-2025 Arm Limited
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to
8+
* deal in the Software without restriction, including without limitation the
9+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10+
* sell copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
* IN THE SOFTWARE.
23+
* ----------------------------------------------------------------------------
24+
*/
25+
26+
#include "device.hpp"
27+
#include "device_utils.hpp"
28+
#include "framework/device_dispatch_table.hpp"
29+
30+
#include <mutex>
31+
32+
extern std::mutex g_vulkanLock;
33+
34+
/**
35+
* @brief Register a compute dispatch with the tracker.
36+
*
37+
* @param layer The layer context for the device.
38+
* @param commandBuffer The command buffer we are recording.
39+
*/
40+
static void registerDispatchDataGraph(Device* layer,
41+
VkCommandBuffer commandBuffer)
42+
{
43+
if (!layer->isFrameOfInterest)
44+
{
45+
return;
46+
}
47+
48+
auto& tracker = layer->getStateTracker();
49+
auto& cb = tracker.getCommandBuffer(commandBuffer);
50+
cb.dispatchDataGraph();
51+
}
52+
53+
/* See Vulkan API for documentation. */
54+
template<>
55+
VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchDataGraphARM<user_tag>(VkCommandBuffer commandBuffer,
56+
VkDataGraphPipelineSessionARM session,
57+
const VkDataGraphPipelineDispatchInfoARM* pInfo)
58+
{
59+
LAYER_TRACE(__func__);
60+
61+
// Hold the lock to access layer-wide global store
62+
std::unique_lock<std::mutex> lock {g_vulkanLock};
63+
auto* layer = Device::retrieve(commandBuffer);
64+
65+
registerDispatchDataGraph(layer, commandBuffer);
66+
67+
// Release the lock to call into the driver
68+
lock.unlock();
69+
layer->driver.vkCmdDispatchDataGraphARM(commandBuffer, session, pInfo);
70+
emitCPUTrap(*layer, commandBuffer);
71+
}

layer_gpu_profile/source/submit_visitor.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void ProfileSubmitVisitor::operator()(
9797
) {
9898
UNUSED(renderPass);
9999

100-
handleCPUTrap("renderpass", debugStack);
100+
handleCPUTrap("render_pass", debugStack);
101101
}
102102

103103
/* See header for documentation */
@@ -123,14 +123,24 @@ void ProfileSubmitVisitor::operator()(
123123
handleCPUTrap("compute", debugStack);
124124
}
125125

126+
/* See header for documentation */
127+
void ProfileSubmitVisitor::operator()(
128+
const Tracker::LCSDispatchDataGraph& dispatch,
129+
const std::vector<std::string>& debugStack
130+
) {
131+
UNUSED(dispatch);
132+
133+
handleCPUTrap("data_graph", debugStack);
134+
}
135+
126136
/* See header for documentation */
127137
void ProfileSubmitVisitor::operator()(
128138
const Tracker::LCSTraceRays& traceRays,
129139
const std::vector<std::string>& debugStack
130140
) {
131141
UNUSED(traceRays);
132142

133-
handleCPUTrap("tracerays", debugStack);
143+
handleCPUTrap("trace_rays", debugStack);
134144
}
135145

136146
/* See header for documentation */

layer_gpu_profile/source/submit_visitor.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class ProfileSubmitVisitor : public Tracker::SubmitCommandWorkloadVisitor
6868
const Tracker::LCSDispatch& dispatch,
6969
const std::vector<std::string>& debugStack) override;
7070

71+
void operator()(
72+
const Tracker::LCSDispatchDataGraph& dispatch,
73+
const std::vector<std::string>& debugStack) override;
74+
7175
void operator()(
7276
const Tracker::LCSTraceRays& traceRays,
7377
const std::vector<std::string>& debugStack) override;

0 commit comments

Comments
 (0)