Skip to content

Commit 3b9fff0

Browse files
authored
Add VK_ARM_data_graph support (#149)
Add support for VK_ARM_data_graph extension workload modelling.
1 parent 8290b66 commit 3b9fff0

18 files changed

+285
-17
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;

layer_gpu_timeline/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_library(
4747
layer_device_functions_command_buffer.cpp
4848
layer_device_functions_command_pool.cpp
4949
layer_device_functions_debug.cpp
50+
layer_device_functions_dispatch_data_graph.cpp
5051
layer_device_functions_dispatch.cpp
5152
layer_device_functions_draw_call.cpp
5253
layer_device_functions_queue.cpp

layer_gpu_timeline/source/layer_device_functions.hpp

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

282+
// Commands for data graph
283+
284+
/* See Vulkan API for documentation. */
285+
template<>
286+
VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchDataGraphARM<user_tag>(VkCommandBuffer commandBuffer,
287+
VkDataGraphPipelineSessionARM session,
288+
const VkDataGraphPipelineDispatchInfoARM* pInfo);
289+
282290
// Commands for trace rays
283291

284292
/* See Vulkan API for documentation. */
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* SPDX-License-Identifier: MIT
3+
* ----------------------------------------------------------------------------
4+
* Copyright (c) 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+
/* See Vulkan API for documentation. */
35+
template<>
36+
VKAPI_ATTR void VKAPI_CALL layer_vkCmdDispatchDataGraphARM<user_tag>(VkCommandBuffer commandBuffer,
37+
VkDataGraphPipelineSessionARM session,
38+
const VkDataGraphPipelineDispatchInfoARM* pInfo)
39+
{
40+
LAYER_TRACE(__func__);
41+
42+
// Hold the lock to access layer-wide global store
43+
std::unique_lock<std::mutex> lock {g_vulkanLock};
44+
auto* layer = Device::retrieve(commandBuffer);
45+
46+
auto& tracker = layer->getStateTracker();
47+
auto& cb = tracker.getCommandBuffer(commandBuffer);
48+
uint64_t tagID = cb.dispatchDataGraph();
49+
50+
// Release the lock to call into the driver
51+
lock.unlock();
52+
emitStartTag(layer, commandBuffer, tagID);
53+
layer->driver.vkCmdDispatchDataGraphARM(commandBuffer, session, pInfo);
54+
emitEndTag(layer, commandBuffer);
55+
}

layer_gpu_timeline/source/timeline_protobuf_encoder.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ using Dispatch = pp::message<
148148
/* Any user defined debug labels associated with the dispatch */
149149
pp::string_field<"debug_label", 5, pp::repeated>>;
150150

151+
/* A dispatch data graph object submission */
152+
using DispatchDataGraph = pp::message<
153+
/* The unique identifier for this operation */
154+
pp::uint64_field<"tag_id", 1>,
155+
/* Any user defined debug labels associated with the dispatch */
156+
pp::string_field<"debug_label", 2, pp::repeated>>;
157+
151158
/* A trace rays object submission */
152159
using TraceRays = pp::message<
153160
/* The unique identifier for this operation */
@@ -251,7 +258,8 @@ using TimelineRecord =
251258
pp::message_field<"image_transfer", 9, ImageTransfer>,
252259
pp::message_field<"buffer_transfer", 10, BufferTransfer>,
253260
pp::message_field<"acceleration_structure_build", 11, AccelerationStructureBuild>,
254-
pp::message_field<"acceleration_structure_transfer", 12, AccelerationStructureTransfer>>;
261+
pp::message_field<"acceleration_structure_transfer", 12, AccelerationStructureTransfer>,
262+
pp::message_field<"dispatch_data_graph", 13, DispatchDataGraph>>;
255263

256264
namespace
257265
{
@@ -527,6 +535,23 @@ Comms::MessageData serialize(const Tracker::LCSDispatch& dispatch, const std::ve
527535
});
528536
}
529537

538+
/**
539+
* @brief Get the metadata for this workload
540+
*
541+
* @param dispatch The dispatch data graph to serialize
542+
* @param debugLabel The debug label stack for the VkQueue at submit time.
543+
*/
544+
Comms::MessageData serialize(const Tracker::LCSDispatchDataGraph& dispatch, const std::vector<std::string>& debugLabel)
545+
{
546+
using namespace pp;
547+
548+
return packBuffer("dispatch_data_graph"_f,
549+
DispatchDataGraph {
550+
dispatch.getTagID(),
551+
debugLabel,
552+
});
553+
}
554+
530555
/**
531556
* @brief Get the metadata for this workload
532557
*
@@ -702,6 +727,12 @@ void TimelineProtobufEncoder::operator()(const Tracker::LCSDispatch& dispatch,
702727
device.txMessage(serialize(dispatch, debugStack));
703728
}
704729

730+
void TimelineProtobufEncoder::operator()(const Tracker::LCSDispatchDataGraph& dispatch,
731+
const std::vector<std::string>& debugStack)
732+
{
733+
device.txMessage(serialize(dispatch, debugStack));
734+
}
735+
705736
void TimelineProtobufEncoder::operator()(const Tracker::LCSTraceRays& traceRays,
706737
const std::vector<std::string>& debugStack)
707738
{

layer_gpu_timeline/source/timeline_protobuf_encoder.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class TimelineProtobufEncoder : public Tracker::SubmitCommandWorkloadVisitor
112112
const std::vector<std::string>& debugStack,
113113
uint64_t renderPassTagID) override;
114114
void operator()(const Tracker::LCSDispatch& dispatch, const std::vector<std::string>& debugStack) override;
115+
void operator()(const Tracker::LCSDispatchDataGraph& dispatch, const std::vector<std::string>& debugStack) override;
115116
void operator()(const Tracker::LCSTraceRays& traceRays, const std::vector<std::string>& debugStack) override;
116117
void operator()(const Tracker::LCSImageTransfer& imageTransfer,
117118
const std::vector<std::string>& debugStack) override;

0 commit comments

Comments
 (0)