1111 limitations under the License.
1212*/
1313
14- #include " gfxr_vulkan_command_hierarchy.h"
15- #include " dive_strings.h"
14+ #include " dive_core/gfxr_vulkan_command_hierarchy.h"
15+
16+ #include < iostream>
17+
18+ #include " absl/strings/numbers.h"
19+ #include " dive_core/dive_strings.h"
1620
1721namespace Dive
1822{
@@ -49,6 +53,33 @@ void GfxrVulkanCommandHierarchyCreator::ConditionallyAddChild(uint64_t node_inde
4953 }
5054}
5155
56+ // --------------------------------------------------------------------------------------------------
57+ std::string GfxrVulkanCommandHierarchyCreator::GetCurrDrawCallString ()
58+ {
59+ // Early return for zero instance count
60+ if (m_cur_draw_call_info.instance_count == 0 )
61+ {
62+ return " " ;
63+ }
64+
65+ std::ostringstream s;
66+
67+ s << " (" ;
68+
69+ if (m_cur_draw_call_info.index_count > 0 )
70+ {
71+ s << " indexCount:" << m_cur_draw_call_info.index_count << " ," ;
72+ }
73+ else if (m_cur_draw_call_info.vertex_count > 0 )
74+ {
75+ s << " vertexCount:" << m_cur_draw_call_info.vertex_count << " ," ;
76+ }
77+
78+ s << " instanceCount:" << m_cur_draw_call_info.instance_count << " )" ;
79+
80+ return s.str ();
81+ }
82+
5283// --------------------------------------------------------------------------------------------------
5384void GfxrVulkanCommandHierarchyCreator::OnCommand (
5485const DiveAnnotationProcessor::VulkanCommandInfo &vk_cmd_info,
@@ -65,7 +96,7 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
6596 uint64_t cmd_buffer_index = AddNode (NodeType::kGfxrVulkanBeginCommandBufferNode ,
6697 vk_cmd_string_stream.str ());
6798 m_cur_command_buffer_node_index = cmd_buffer_index;
68- GetArgs (vulkan_cmd_args, m_cur_command_buffer_node_index, " " );
99+ GetArgs (vulkan_cmd_args, m_cur_command_buffer_node_index);
69100 AddChild (CommandHierarchy::TopologyType::kAllEventTopology ,
70101 m_cur_submit_node_index,
71102 cmd_buffer_index);
@@ -75,7 +106,7 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
75106 uint64_t cmd_buffer_index = AddNode (NodeType::kGfxrVulkanEndCommandBufferNode ,
76107 vk_cmd_string_stream.str ());
77108
78- GetArgs (vulkan_cmd_args, cmd_buffer_index, " " );
109+ GetArgs (vulkan_cmd_args, cmd_buffer_index);
79110 AddChild (CommandHierarchy::TopologyType::kAllEventTopology ,
80111 m_cur_command_buffer_node_index,
81112 cmd_buffer_index);
@@ -87,7 +118,7 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
87118 uint64_t
88119 begin_debug_utils_label_cmd_index = AddNode (NodeType::kGfxrBeginDebugUtilsLabelCommandNode ,
89120 label_name.c_str ());
90- GetArgs (vulkan_cmd_args, begin_debug_utils_label_cmd_index, " " );
121+ GetArgs (vulkan_cmd_args, begin_debug_utils_label_cmd_index);
91122 ConditionallyAddChild (begin_debug_utils_label_cmd_index);
92123 m_cur_parent_node_index_stack.push (begin_debug_utils_label_cmd_index);
93124 }
@@ -104,10 +135,23 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
104135 else if (vulkan_cmd_name.find (" vkCmdDraw" ) != std::string::npos ||
105136 vulkan_cmd_name.find (" vkCmdDispatch" ) != std::string::npos)
106137 {
138+ m_cur_draw_call_info = {};
139+
107140 uint64_t vk_cmd_index = AddNode (NodeType::kGfxrVulkanDrawCommandNode ,
108141 vk_cmd_string_stream.str ());
109- GetArgs (vulkan_cmd_args, vk_cmd_index, " " );
142+ GetArgs (vulkan_cmd_args, vk_cmd_index);
110143 ConditionallyAddChild (vk_cmd_index);
144+
145+ if (vulkan_cmd_name.find (" vkCmdDraw" ) != std::string::npos)
146+ {
147+ std::string extra_info = GetCurrDrawCallString ();
148+ if (!extra_info.empty ())
149+ {
150+ // Update the draw node description with info obtained from its args
151+ vk_cmd_string_stream << extra_info;
152+ m_command_hierarchy.SetNodeDesc (vk_cmd_index, vk_cmd_string_stream.str ());
153+ }
154+ }
111155 }
112156 else if (vulkan_cmd_name.find (" vkCmdBeginRenderPass" ) != std::string::npos)
113157 {
@@ -119,15 +163,15 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
119163 vk_cmd_string_stream << " , Draw Call Count: " << draw_call_count;
120164 uint64_t vk_cmd_index = AddNode (NodeType::kGfxrVulkanBeginRenderPassCommandNode ,
121165 vk_cmd_string_stream.str ());
122- GetArgs (vulkan_cmd_args, vk_cmd_index, " " );
166+ GetArgs (vulkan_cmd_args, vk_cmd_index);
123167 ConditionallyAddChild (vk_cmd_index);
124168 m_cur_parent_node_index_stack.push (vk_cmd_index);
125169 }
126170 else if (vulkan_cmd_name.find (" vkCmdEndRenderPass" ) != std::string::npos)
127171 {
128172 uint64_t vk_cmd_index = AddNode (NodeType::kGfxrVulkanEndRenderPassCommandNode ,
129173 vk_cmd_string_stream.str ());
130- GetArgs (vulkan_cmd_args, vk_cmd_index, " " );
174+ GetArgs (vulkan_cmd_args, vk_cmd_index);
131175 ConditionallyAddChild (vk_cmd_index);
132176 if (!m_cur_parent_node_index_stack.empty ())
133177 {
@@ -139,7 +183,7 @@ std::vector<uint64_t> &render_pass_draw_call_counts)
139183 {
140184 uint64_t vk_cmd_index = AddNode (NodeType::kGfxrVulkanCommandNode ,
141185 vk_cmd_string_stream.str ());
142- GetArgs (vulkan_cmd_args, vk_cmd_index, " " );
186+ GetArgs (vulkan_cmd_args, vk_cmd_index);
143187 ConditionallyAddChild (vk_cmd_index);
144188 }
145189}
@@ -238,15 +282,12 @@ uint64_t GfxrVulkanCommandHierarchyCreator::AddNode(NodeType type, std::string &
238282 uint64_t local_node_index = m_node_children[CommandHierarchy::kAllEventTopology ].size ();
239283 m_dive_indices_to_local_indices_map[node_index] = local_node_index;
240284 m_node_children[CommandHierarchy::kAllEventTopology ].resize (local_node_index + 1 );
241- m_node_root_node_indices[CommandHierarchy::kAllEventTopology ].resize (local_node_index + 1 );
242285 }
243286 else
244287 {
245288 DIVE_ASSERT (m_node_children[CommandHierarchy::kAllEventTopology ].size () == node_index);
246289 m_node_children[CommandHierarchy::kAllEventTopology ].resize (
247290 m_node_children[CommandHierarchy::kAllEventTopology ].size () + 1 );
248- m_node_root_node_indices[CommandHierarchy::kAllEventTopology ].resize (
249- m_node_root_node_indices[CommandHierarchy::kAllEventTopology ].size () + 1 );
250291 }
251292
252293 return node_index;
@@ -274,9 +315,46 @@ void GfxrVulkanCommandHierarchyCreator::AddChild(CommandHierarchy::TopologyType
274315 }
275316}
276317
318+ bool GfxrVulkanCommandHierarchyCreator::ParseCurDrawCallInfo (std::string_view key,
319+ std::string_view val)
320+ {
321+ if (key == " indexCount" )
322+ {
323+ uint64_t value = 0 ;
324+ if (!absl::SimpleAtoi (val, &value))
325+ {
326+ return false ;
327+ }
328+ m_cur_draw_call_info.index_count = value;
329+ return true ;
330+ }
331+ if (key == " vertexCount" )
332+ {
333+ uint64_t value = 0 ;
334+ if (!absl::SimpleAtoi (val, &value))
335+ {
336+ return false ;
337+ }
338+ m_cur_draw_call_info.vertex_count = value;
339+ return true ;
340+ }
341+ if (key == " instanceCount" )
342+ {
343+ uint64_t value = 0 ;
344+ if (!absl::SimpleAtoi (val, &value))
345+ {
346+ return false ;
347+ }
348+ m_cur_draw_call_info.instance_count = value;
349+ return true ;
350+ }
351+
352+ // key is unrelated to DrawCallDescInfo
353+ return true ;
354+ }
355+
277356void GfxrVulkanCommandHierarchyCreator::GetArgs (const nlohmann::ordered_json &json_args,
278- uint64_t curr_index,
279- const std::string ¤t_path)
357+ uint64_t curr_index)
280358{
281359 // This block processes key-value pairs where keys represent field names
282360 // and values can be objects, arrays, or primitives.
@@ -294,7 +372,7 @@ void GfxrVulkanCommandHierarchyCreator::GetArgs(const nlohmann::ordered_json &js
294372 curr_index,
295373 object_node_index);
296374
297- GetArgs (val, object_node_index, " " );
375+ GetArgs (val, object_node_index);
298376 }
299377 else if (val.is_array ())
300378 {
@@ -311,7 +389,7 @@ void GfxrVulkanCommandHierarchyCreator::GetArgs(const nlohmann::ordered_json &js
311389 if (element.is_object ())
312390 {
313391 // If an array element is an object, recursively process it.
314- GetArgs (element, array_node_index, " " );
392+ GetArgs (element, array_node_index);
315393 }
316394 else if (element.is_array ())
317395 {
@@ -323,7 +401,7 @@ void GfxrVulkanCommandHierarchyCreator::GetArgs(const nlohmann::ordered_json &js
323401 AddChild (CommandHierarchy::TopologyType::kAllEventTopology ,
324402 array_node_index,
325403 nested_array_node_index);
326- GetArgs (element, nested_array_node_index, " " );
404+ GetArgs (element, nested_array_node_index);
327405 }
328406 else
329407 {
@@ -341,12 +419,26 @@ void GfxrVulkanCommandHierarchyCreator::GetArgs(const nlohmann::ordered_json &js
341419 }
342420 else
343421 {
422+ std::ostringstream s;
423+ std::string val_str;
424+
425+ s.str (" " );
426+ s << val;
427+ val_str = s.str ();
428+
429+ s.str (" " );
430+ s << key << " :" << val;
431+
432+ if (!ParseCurDrawCallInfo (key, val_str))
433+ {
434+ std::cerr << " GfxrVulkanCommandHierarchyCreator::GetArgs() "
435+ << " could not parse draw call info from: " << s.str () << std::endl;
436+ }
437+
344438 // If the value is a primitive,
345439 // create a node containing the "key:value" pair.
346- std::ostringstream vk_cmd_arg_string_stream;
347- vk_cmd_arg_string_stream << key << " :" << val;
348- uint64_t vk_cmd_arg_index = AddNode (NodeType::kGfxrVulkanCommandArgNode ,
349- vk_cmd_arg_string_stream.str ());
440+
441+ uint64_t vk_cmd_arg_index = AddNode (NodeType::kGfxrVulkanCommandArgNode , s.str ());
350442 AddChild (CommandHierarchy::TopologyType::kAllEventTopology ,
351443 curr_index,
352444 vk_cmd_arg_index);
@@ -363,7 +455,7 @@ void GfxrVulkanCommandHierarchyCreator::GetArgs(const nlohmann::ordered_json &js
363455 {
364456 // If an array element is an object or another array,
365457 // recursively process it, and associate it with the current parent node.
366- GetArgs (element, curr_index, " " );
458+ GetArgs (element, curr_index);
367459 }
368460 else
369461 {
0 commit comments