Skip to content

Commit

Permalink
Show IB packets as children of INDIRECT_BUFFER packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Shan-Min Chao committed Oct 31, 2023
1 parent 992e6c5 commit d26a62b
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 231 deletions.
76 changes: 42 additions & 34 deletions dive_core/command_hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,12 @@ uint8_t CommandHierarchy::GetPacketNodeOpcode(uint64_t node_index) const
}

//--------------------------------------------------------------------------------------------------
bool CommandHierarchy::GetPacketNodeIsCe(uint64_t node_index) const
uint8_t CommandHierarchy::GetPacketNodeIbLevel(uint64_t node_index) const
{
DIVE_ASSERT(node_index < m_nodes.m_aux_info.size());
DIVE_ASSERT(m_nodes.m_node_type[node_index] == Dive::NodeType::kPacketNode);
const AuxInfo &info = m_nodes.m_aux_info[node_index];
return info.packet_node.m_is_ce_packet;
return info.packet_node.m_ib_level;
}
//--------------------------------------------------------------------------------------------------
bool CommandHierarchy::GetRegFieldNodeIsCe(uint64_t node_index) const
Expand Down Expand Up @@ -480,14 +480,14 @@ CommandHierarchy::AuxInfo CommandHierarchy::AuxInfo::IbNode(uint32_t ib_index,
//--------------------------------------------------------------------------------------------------
CommandHierarchy::AuxInfo CommandHierarchy::AuxInfo::PacketNode(uint64_t addr,
uint8_t opcode,
bool is_ce_packet)
uint8_t ib_level)
{
// Addresses should only be 48-bits
DIVE_ASSERT(addr == (addr & 0x0000FFFFFFFFFFFF));
AuxInfo info(0);
info.packet_node.m_addr = (addr & 0x0000FFFFFFFFFFFF);
info.packet_node.m_opcode = opcode;
info.packet_node.m_is_ce_packet = is_ce_packet;
info.packet_node.m_ib_level = ib_level;
return info;
}

Expand Down Expand Up @@ -554,9 +554,6 @@ bool CommandHierarchyCreator::CreateTrees(CommandHierarchy *command_hierarchy_p
}

m_num_events = 0;
m_cur_submit_node_index = UINT64_MAX;
m_dcb_ib_stack.clear();
m_ccb_ib_stack.clear();
m_flatten_chain_nodes = flatten_chain_nodes;

for (uint32_t submit_index = 0; submit_index < capture_data.GetNumSubmits(); ++submit_index)
Expand Down Expand Up @@ -675,9 +672,6 @@ bool CommandHierarchyCreator::CreateTrees(CommandHierarchy *command_hierarchy_pt
}

m_num_events = 0;
m_cur_submit_node_index = UINT64_MAX;
m_dcb_ib_stack.clear();
m_ccb_ib_stack.clear();
m_flatten_chain_nodes = false;

uint32_t submit_index = 0;
Expand Down Expand Up @@ -773,20 +767,20 @@ bool CommandHierarchyCreator::OnIbStart(uint32_t submit_index,
!ib_info.m_skip);
uint64_t ib_node_index = AddNode(NodeType::kIbNode, ib_string_stream.str(), aux_info);

// Determine parent node and update m_cur_non_chain_#cb_ib_node_index
// Determine parent node
uint64_t parent_node_index = m_cur_submit_node_index;
if (!m_dcb_ib_stack.empty())
if (!m_ib_stack.empty())
{
parent_node_index = m_dcb_ib_stack.back();
parent_node_index = m_ib_stack.back();
}

if (m_flatten_chain_nodes && type == IbType::kChain)
{
// If flatten enabled, then add to the nearest non-chain node parent
// Find first previous non-CHAIN parent
for (size_t i = m_dcb_ib_stack.size() - 1; i != SIZE_MAX; i--)
for (size_t i = m_ib_stack.size() - 1; i != SIZE_MAX; i--)
{
uint64_t index = m_dcb_ib_stack[i];
uint64_t index = m_ib_stack[i];
IbType cur_type = m_command_hierarchy_ptr->GetIbNodeType(index);
if (cur_type != IbType::kChain)
{
Expand All @@ -799,8 +793,10 @@ bool CommandHierarchyCreator::OnIbStart(uint32_t submit_index,
AddChild(CommandHierarchy::kEngineTopology, parent_node_index, ib_node_index);
AddChild(CommandHierarchy::kSubmitTopology, parent_node_index, ib_node_index);

m_dcb_ib_stack.push_back(ib_node_index);

m_ib_stack.push_back(ib_node_index);
if (m_cur_ib_packet_node_index != UINT64_MAX)
m_cur_shared_node_parent_index = m_cur_ib_packet_node_index;
m_cur_ib_level = ib_info.m_ib_level;
m_cmd_begin_packet_node_indices.clear();
m_cmd_begin_event_node_indices.clear();
return true;
Expand All @@ -811,23 +807,28 @@ bool CommandHierarchyCreator::OnIbEnd(uint32_t submit_index,
uint32_t ib_index,
const IndirectBufferInfo &ib_info)
{
DIVE_ASSERT(!m_dcb_ib_stack.empty());
DIVE_ASSERT(!m_ib_stack.empty());

// Note: This callback is only called for the last CHAIN of a series of daisy-CHAIN IBs,
// because the emulator does not keep track of IBs in an internal stack. So start by
// popping all consecutive CHAIN IBs
IbType type;
type = m_command_hierarchy_ptr->GetIbNodeType(m_dcb_ib_stack.back());
while (!m_dcb_ib_stack.empty() && type == IbType::kChain)
type = m_command_hierarchy_ptr->GetIbNodeType(m_ib_stack.back());
while (!m_ib_stack.empty() && type == IbType::kChain)
{
m_dcb_ib_stack.pop_back();
type = m_command_hierarchy_ptr->GetIbNodeType(m_dcb_ib_stack.back());
m_ib_stack.pop_back();
type = m_command_hierarchy_ptr->GetIbNodeType(m_ib_stack.back());
}

m_dcb_ib_stack.pop_back();
m_ib_stack.pop_back();
OnVulkanMarkerEnd();
m_cmd_begin_packet_node_indices.clear();
m_cmd_begin_event_node_indices.clear();
m_cur_ib_level = ib_info.m_ib_level;

// Reset back to submit node being the parent (as opposed to, possibly, the indirect_buffer
// packet)
m_cur_shared_node_parent_index = m_cur_submit_node_index;
return true;
}

Expand All @@ -850,12 +851,14 @@ bool CommandHierarchyCreator::OnPacket(const IMemoryManager &mem_manager,
false,
type,
header);
AddSharedChild(CommandHierarchy::kEngineTopology, m_cur_submit_node_index, packet_node_index);
AddSharedChild(CommandHierarchy::kSubmitTopology, m_cur_submit_node_index, packet_node_index);
AddSharedChild(CommandHierarchy::kAllEventTopology, m_cur_submit_node_index, packet_node_index);
AddSharedChild(CommandHierarchy::kRgpTopology, m_cur_submit_node_index, packet_node_index);
AddSharedChild(CommandHierarchy::kEngineTopology, m_dcb_ib_stack.back(), packet_node_index);
AddSharedChild(CommandHierarchy::kSubmitTopology, m_dcb_ib_stack.back(), packet_node_index);

uint64_t parent_index = m_cur_shared_node_parent_index;
AddSharedChild(CommandHierarchy::kEngineTopology, parent_index, packet_node_index);
AddSharedChild(CommandHierarchy::kSubmitTopology, parent_index, packet_node_index);
AddSharedChild(CommandHierarchy::kAllEventTopology, parent_index, packet_node_index);
AddSharedChild(CommandHierarchy::kRgpTopology, parent_index, packet_node_index);
AddSharedChild(CommandHierarchy::kEngineTopology, m_ib_stack.back(), packet_node_index);
AddSharedChild(CommandHierarchy::kSubmitTopology, m_ib_stack.back(), packet_node_index);

uint32_t opcode = UINT32_MAX;
if (type == Pm4Type::kType7)
Expand Down Expand Up @@ -950,6 +953,11 @@ bool CommandHierarchyCreator::OnPacket(const IMemoryManager &mem_manager,
AddChild(CommandHierarchy::kRgpTopology, parent_node_index, event_node_index);
m_node_parent_info[CommandHierarchy::kRgpTopology][event_node_index] = parent_node_index;
}
else if ((opcode == CP_INDIRECT_BUFFER_PFE || opcode == CP_INDIRECT_BUFFER_PFD ||
opcode == CP_INDIRECT_BUFFER_CHAIN || opcode == CP_COND_INDIRECT_BUFFER_PFE))
{
m_cur_ib_packet_node_index = packet_node_index;
}
// vulkan call NOP packages. Currently contains call parameters(except parameters in array),
// each call is in one NOP packet.
else if (opcode == CP_NOP)
Expand Down Expand Up @@ -1044,7 +1052,10 @@ void CommandHierarchyCreator::OnSubmitStart(uint32_t submit_index, const SubmitI
AddChild(CommandHierarchy::kAllEventTopology, Topology::kRootNodeIndex, submit_node_index);
AddChild(CommandHierarchy::kRgpTopology, Topology::kRootNodeIndex, submit_node_index);
m_cur_submit_node_index = submit_node_index;
m_cur_shared_node_parent_index = m_cur_submit_node_index;
m_cur_engine_index = submit_info.GetEngineIndex();
m_cur_ib_packet_node_index = UINT64_MAX;
m_ib_stack.clear();
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -1136,9 +1147,6 @@ void CommandHierarchyCreator::OnSubmitEnd(uint32_t submit_index, const SubmitInf
AddChild(CommandHierarchy::kRgpTopology, Topology::kRootNodeIndex, present_node_index);
}
}
m_cur_submit_node_index = UINT64_MAX;
m_ccb_ib_stack.clear();
m_dcb_ib_stack.clear();
}

//--------------------------------------------------------------------------------------------------
Expand All @@ -1161,7 +1169,7 @@ uint64_t CommandHierarchyCreator::AddPacketNode(const IMemoryManager &mem_manage
CommandHierarchy::AuxInfo aux_info = CommandHierarchy::AuxInfo::PacketNode(va_addr,
type7_header
.opcode,
is_ce_packet);
m_cur_ib_level);

uint64_t packet_node_index = AddNode(NodeType::kPacketNode,
packet_string_stream.str(),
Expand Down Expand Up @@ -1294,7 +1302,7 @@ uint64_t CommandHierarchyCreator::AddPacketNode(const IMemoryManager &mem_manage

CommandHierarchy::AuxInfo aux_info = CommandHierarchy::AuxInfo::PacketNode(va_addr,
UINT8_MAX,
is_ce_packet);
m_cur_ib_level);

uint64_t packet_node_index = AddNode(NodeType::kPacketNode,
packet_string_stream.str(),
Expand Down
22 changes: 13 additions & 9 deletions dive_core/command_hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class CommandHierarchy
uint32_t GetEventNodeId(uint64_t node_index) const;
uint64_t GetPacketNodeAddr(uint64_t node_index) const;
uint8_t GetPacketNodeOpcode(uint64_t node_index) const;
bool GetPacketNodeIsCe(uint64_t node_index) const;
uint8_t GetPacketNodeIbLevel(uint64_t node_index) const;
bool GetRegFieldNodeIsCe(uint64_t node_index) const;
SyncType GetSyncNodeSyncType(uint64_t node_index) const;
SyncInfo GetSyncNodeSyncInfo(uint64_t node_index) const;
Expand Down Expand Up @@ -280,8 +280,8 @@ class CommandHierarchy
{
uint64_t m_addr : 48;
uint64_t m_opcode : 8;
uint64_t m_is_ce_packet : 1;
uint64_t m_reserved : 7;
uint64_t m_ib_level : 3;
uint64_t m_reserved : 5;
} packet_node;

struct
Expand All @@ -303,7 +303,7 @@ class CommandHierarchy
IbType ib_type,
uint32_t size_in_dwords,
bool fully_captured);
static AuxInfo PacketNode(uint64_t addr, uint8_t opcode, bool is_ce_packet);
static AuxInfo PacketNode(uint64_t addr, uint8_t opcode, uint8_t ib_level);
static AuxInfo RegFieldNode(bool is_ce_packet);
static AuxInfo EventNode(uint32_t event_id);
static AuxInfo MarkerNode(MarkerType type, uint32_t id = 0);
Expand Down Expand Up @@ -393,6 +393,7 @@ class CommandHierarchyCreator : public IEmulateCallbacks

void OnSubmitStart(uint32_t submit_index, const SubmitInfo &submit_info);
void OnSubmitEnd(uint32_t submit_index, const SubmitInfo &submit_info);
void PreSubmitReset();
uint64_t AddPacketNode(const IMemoryManager &mem_manager,
uint32_t submit_index,
uint64_t va_addr,
Expand Down Expand Up @@ -538,13 +539,16 @@ class CommandHierarchyCreator : public IEmulateCallbacks
// VkBeginCommandBuffer.

std::vector<uint64_t> m_internal_marker_stack; // Current internal marker begin/end stack
std::vector<uint64_t> m_dcb_ib_stack; // Tracks current DCB IB stack
std::vector<uint64_t> m_ccb_ib_stack; // Tracks current CCB IB stack
std::vector<uint64_t> m_ib_stack; // Tracks current IB stack
std::vector<uint64_t> m_renderpass_stack; // render pass marker begin/end stack

uint32_t m_num_events; // Number of events so far
Packets m_packets; // Packets added since last event
uint64_t m_cur_submit_node_index; // Current submit node being processed
uint32_t m_num_events; // Number of events so far
Packets m_packets; // Packets added since last event

uint64_t m_cur_shared_node_parent_index; // The current parent of any shared node being added
uint64_t m_cur_submit_node_index; // Current submit node being processed
uint64_t m_cur_ib_packet_node_index; // Current ib packet node being processed
uint8_t m_cur_ib_level;

// Flattening is the process of forcing chain ib nodes to only ever be child to non-chain ib
// nodes, even when daisy chaining across multiple chain ib nodes. This makes the topology
Expand Down
5 changes: 4 additions & 1 deletion dive_core/common/emulate_pm4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ bool EmulatePM4::AdvanceToQueuedIB(const IMemoryManager &mem_manager,
IndirectBufferInfo call_chain_ib_info;
call_chain_ib_info.m_va_addr = cur_ib_level->m_cur_va;
call_chain_ib_info.m_size_in_dwords = cur_ib_level->m_cur_ib_size_in_dwords;
call_chain_ib_info.m_ib_level = (uint8_t)emu_state->m_top_of_stack;
call_chain_ib_info.m_skip = cur_ib_level->m_cur_ib_skip;
if (!callbacks.OnIbStart(emu_state->m_submit_index,
emu_state->m_ib_index,
Expand Down Expand Up @@ -993,16 +994,18 @@ bool EmulatePM4::AdvanceOutOfIB(EmulateState *emu_state, IEmulateCallbacks &call
{
EmulateState::IbStack *cur_ib_level = emu_state->GetCurIb();

emu_state->m_top_of_stack = (EmulateState::IbLevel)(emu_state->m_top_of_stack - 1);

IndirectBufferInfo ib_info;
ib_info.m_va_addr = cur_ib_level->m_cur_va;
ib_info.m_size_in_dwords = cur_ib_level->m_cur_ib_size_in_dwords;
ib_info.m_ib_level = (uint8_t)emu_state->m_top_of_stack;
ib_info.m_skip = cur_ib_level->m_cur_ib_skip;

// End-Ib Callback
if (!callbacks.OnIbEnd(emu_state->m_submit_index, emu_state->m_ib_index, ib_info))
return false;

emu_state->m_top_of_stack = (EmulateState::IbLevel)(emu_state->m_top_of_stack - 1);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions dive_core/common/emulate_pm4.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct IndirectBufferInfo
{
uint64_t m_va_addr;
uint32_t m_size_in_dwords;
uint8_t m_ib_level;

// Set to true to avoid emulating this IB, probably because it was not captured
bool m_skip;
Expand Down
Loading

0 comments on commit d26a62b

Please sign in to comment.