devtools: pm4 - show reg depth buffer

This commit is contained in:
Vinicius Rangel 2024-10-13 06:45:18 -03:00
parent 87ecb87674
commit 395ac5dda9
No known key found for this signature in database
GPG Key ID: A5B154D904B761D9
6 changed files with 154 additions and 62 deletions

View File

@ -121,14 +121,7 @@ void DebugStateImpl::PushQueueDump(QueueDump dump) {
UNREACHABLE(); UNREACHABLE();
} }
const AmdGpu::PM4ItOpcode opcode = header->opcode; const AmdGpu::PM4ItOpcode opcode = header->opcode;
switch (opcode) { if (Core::Devtools::Widget::IsDrawCall(opcode)) {
case AmdGpu::PM4ItOpcode::DrawIndex2:
case AmdGpu::PM4ItOpcode::DrawIndexOffset2:
case AmdGpu::PM4ItOpcode::DrawIndexAuto:
case AmdGpu::PM4ItOpcode::DrawIndirect:
case AmdGpu::PM4ItOpcode::DrawIndexIndirect:
case AmdGpu::PM4ItOpcode::DispatchDirect:
case AmdGpu::PM4ItOpcode::DispatchIndirect: {
const auto offset = const auto offset =
reinterpret_cast<uintptr_t>(header) - reinterpret_cast<uintptr_t>(initial_data); reinterpret_cast<uintptr_t>(header) - reinterpret_cast<uintptr_t>(initial_data);
const auto addr = dump.base_addr + offset; const auto addr = dump.base_addr + offset;
@ -138,9 +131,6 @@ void DebugStateImpl::PushQueueDump(QueueDump dump) {
fmt::format("#{} h({}) queue {} {} {}", fmt::format("#{} h({}) queue {} {} {}",
frame_dump_list.size() - gnm_frame_dump_request_count, addr, frame_dump_list.size() - gnm_frame_dump_request_count, addr,
magic_enum::enum_name(dump.type), dump.submit_num, dump.num2)); magic_enum::enum_name(dump.type), dump.submit_num, dump.num2));
} break;
default:
break;
} }
data = data.subspan(header->NumWords() + 1); data = data.subspan(header->NumWords() + 1);
} }

View File

@ -63,21 +63,6 @@ static HdrType GetNext(HdrType this_pm4, uint32_t n) {
return curr_pm4; return curr_pm4;
} }
static bool IsDrawCall(AmdGpu::PM4ItOpcode opcode) {
using AmdGpu::PM4ItOpcode;
switch (opcode) {
case PM4ItOpcode::DispatchDirect:
case PM4ItOpcode::DispatchIndirect:
case PM4ItOpcode::DrawIndex2:
case PM4ItOpcode::DrawIndexAuto:
case PM4ItOpcode::DrawIndexOffset2:
case PM4ItOpcode::DrawIndexIndirect:
return true;
default:
return false;
}
}
void ParsePolygonControl(u32 value, bool begin_table) { void ParsePolygonControl(u32 value, bool begin_table) {
auto const reg = reinterpret_cast<AmdGpu::Liverpool::PolygonControl const&>(value); auto const reg = reinterpret_cast<AmdGpu::Liverpool::PolygonControl const&>(value);
@ -1302,11 +1287,14 @@ void CmdListViewer::Draw() {
if (batch.type == static_cast<AmdGpu::PM4ItOpcode>(0xFF)) { if (batch.type == static_cast<AmdGpu::PM4ItOpcode>(0xFF)) {
snprintf(batch_hdr, sizeof(batch_hdr), "State batch"); snprintf(batch_hdr, sizeof(batch_hdr), "State batch");
} else if (!batch.marker.empty()) { } else if (!batch.marker.empty()) {
snprintf(batch_hdr, sizeof(batch_hdr), "%08llX: batch-%03d | %s", snprintf(batch_hdr, sizeof(batch_hdr), "%08llX: batch-%03d %s | %s",
cmdb_addr + batch.start_addr, batch.id, batch.marker.c_str()); cmdb_addr + batch.start_addr, batch.id,
Gcn::GetOpCodeName(static_cast<u32>(batch.type)),
batch.marker.c_str());
} else { } else {
snprintf(batch_hdr, sizeof(batch_hdr), "%08llX: batch-%03d", snprintf(batch_hdr, sizeof(batch_hdr), "%08llX: batch-%03d %s",
cmdb_addr + batch.start_addr, batch.id); cmdb_addr + batch.start_addr, batch.id,
Gcn::GetOpCodeName(static_cast<u32>(batch.type)));
} }
if (batch.id == batch_bp) { // highlight batch at breakpoint if (batch.id == batch_bp) { // highlight batch at breakpoint

View File

@ -6,6 +6,8 @@
#include <string> #include <string>
#include <variant> #include <variant>
#include <magic_enum.hpp>
#include "common/types.h" #include "common/types.h"
#include "video_core/amdgpu/pm4_opcodes.h" #include "video_core/amdgpu/pm4_opcodes.h"
@ -55,6 +57,11 @@ void DrawRow(const char* text, const char* fmt, Args... args) {
ImGui::TextUnformatted(buf); ImGui::TextUnformatted(buf);
} }
template <typename T, typename V = u32>
void DrawEnumRow(const char* text, T value) {
DrawRow(text, "%X (%s)", V(value), magic_enum::enum_name(value).data());
}
template <typename V, typename... Extra> template <typename V, typename... Extra>
void DrawMultipleRow(const char* text, const char* fmt, V arg, Extra&&... extra_args) { void DrawMultipleRow(const char* text, const char* fmt, V arg, Extra&&... extra_args) {
DrawRow(text, fmt, arg); DrawRow(text, fmt, arg);
@ -74,4 +81,20 @@ static void DoTooltip(const char* str_id, Args&&... args) {
} }
} }
static bool IsDrawCall(AmdGpu::PM4ItOpcode opcode) {
using AmdGpu::PM4ItOpcode;
switch (opcode) {
case PM4ItOpcode::DrawIndex2:
case PM4ItOpcode::DrawIndexOffset2:
case PM4ItOpcode::DrawIndexAuto:
case PM4ItOpcode::DrawIndirect:
case PM4ItOpcode::DrawIndexIndirect:
case PM4ItOpcode::DispatchDirect:
case PM4ItOpcode::DispatchIndirect:
return true;
default:
return false;
}
}
} // namespace Core::Devtools::Widget } // namespace Core::Devtools::Widget

View File

@ -70,9 +70,9 @@ void RegPopup::DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer) {
auto tiling_mode = buffer.GetTilingMode(); auto tiling_mode = buffer.GetTilingMode();
auto num_format = buffer.NumFormat(); auto num_format = buffer.NumFormat();
DrawRow("GetTilingMode()", "%X (%s)", tiling_mode, enum_name(tiling_mode).data()); DrawEnumRow("GetTilingMode()", tiling_mode);
DrawRow("IsTiled()", "%X", buffer.IsTiled()); DrawRow("IsTiled()", "%X", buffer.IsTiled());
DrawRow("NumFormat()", "%X (%s)", num_format, enum_name(num_format).data()); DrawEnumRow("NumFormat()", num_format);
// clang-format on // clang-format on
@ -80,6 +80,73 @@ void RegPopup::DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer) {
} }
} }
void RegPopup::DrawDepthBuffer(const DepthBuffer& depth_data) {
const auto& [depth_buffer, depth_control] = depth_data;
SeparatorText("Depth buffer");
if (BeginTable("DEPTH_BUFFER", 2, ImGuiTableFlags_Borders)) {
TableNextRow();
// clang-format off
DrawEnumRow("Z_INFO.FORMAT", depth_buffer.z_info.format.Value());
DrawMultipleRow(
"Z_INFO.NUM_SAMPLES", "%X", depth_buffer.z_info.num_samples,
"Z_INFO.TILE_SPLIT", "%X", depth_buffer.z_info.tile_split,
"Z_INFO.TILE_MODE_INDEX", "%X", depth_buffer.z_info.tile_mode_index,
"Z_INFO.DECOMPRESS_ON_N_ZPLANES", "%X", depth_buffer.z_info.decompress_on_n_zplanes,
"Z_INFO.ALLOW_EXPCLEAR", "%X", depth_buffer.z_info.allow_expclear,
"Z_INFO.READ_SIZE", "%X", depth_buffer.z_info.read_size,
"Z_INFO.TILE_SURFACE_EN", "%X", depth_buffer.z_info.tile_surface_en,
"Z_INFO.CLEAR_DISALLOWED", "%X", depth_buffer.z_info.clear_disallowed,
"Z_INFO.ZRANGE_PRECISION", "%X", depth_buffer.z_info.zrange_precision
);
DrawEnumRow("STENCIL_INFO.FORMAT", depth_buffer.stencil_info.format.Value());
DrawMultipleRow(
"Z_READ_BASE", "%X", depth_buffer.z_read_base,
"STENCIL_READ_BASE", "%X", depth_buffer.stencil_read_base,
"Z_WRITE_BASE", "%X", depth_buffer.z_write_base,
"STENCIL_WRITE_BASE", "%X", depth_buffer.stencil_write_base,
"DEPTH_SIZE.PITCH_TILE_MAX", "%X", depth_buffer.depth_size.pitch_tile_max,
"DEPTH_SIZE.HEIGHT_TILE_MAX", "%X", depth_buffer.depth_size.height_tile_max,
"DEPTH_SLICE.TILE_MAX", "%X", depth_buffer.depth_slice.tile_max,
"Pitch()", "%X", depth_buffer.Pitch(),
"Height()", "%X", depth_buffer.Height(),
"Address()", "%X", depth_buffer.Address(),
"NumSamples()", "%X", depth_buffer.NumSamples(),
"NumBits()", "%X", depth_buffer.NumBits(),
"GetDepthSliceSize()", "%X", depth_buffer.GetDepthSliceSize()
);
// clang-format on
EndTable();
}
SeparatorText("Depth control");
if (BeginTable("DEPTH_CONTROL", 2, ImGuiTableFlags_Borders)) {
TableNextRow();
// clang-format off
DrawMultipleRow(
"STENCIL_ENABLE", "%X", depth_control.stencil_enable,
"DEPTH_ENABLE", "%X", depth_control.depth_enable,
"DEPTH_WRITE_ENABLE", "%X", depth_control.depth_write_enable,
"DEPTH_BOUNDS_ENABLE", "%X", depth_control.depth_bounds_enable
);
DrawEnumRow("DEPTH_FUNC", depth_control.depth_func.Value());
DrawRow("BACKFACE_ENABLE", "%X", depth_control.backface_enable);
DrawEnumRow("STENCIL_FUNC", depth_control.stencil_ref_func.Value());
DrawEnumRow("STENCIL_FUNC_BF", depth_control.stencil_bf_func.Value());
DrawMultipleRow(
"ENABLE_COLOR_WRITES_ON_DEPTH_FAIL", "%X", depth_control.enable_color_writes_on_depth_fail,
"DISABLE_COLOR_WRITES_ON_DEPTH_PASS", "%X", depth_control.disable_color_writes_on_depth_pass
);
// clang-format on
EndTable();
}
}
RegPopup::RegPopup() { RegPopup::RegPopup() {
static int unique_id = 0; static int unique_id = 0;
id = unique_id++; id = unique_id++;
@ -90,6 +157,12 @@ void RegPopup::SetData(AmdGpu::Liverpool::ColorBuffer color_buffer, u32 batch_id
this->title = fmt::format("Batch #{} CB #{}", batch_id, cb_id); this->title = fmt::format("Batch #{} CB #{}", batch_id, cb_id);
} }
void RegPopup::SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer,
AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id) {
this->data = std::make_tuple(depth_buffer, depth_control);
this->title = fmt::format("Batch #{} Depth", batch_id);
}
void RegPopup::Draw() { void RegPopup::Draw() {
char name[128]; char name[128];
@ -99,6 +172,8 @@ void RegPopup::Draw() {
if (Begin(name, &open, ImGuiWindowFlags_NoSavedSettings)) { if (Begin(name, &open, ImGuiWindowFlags_NoSavedSettings)) {
if (const auto* buffer = std::get_if<AmdGpu::Liverpool::ColorBuffer>(&data)) { if (const auto* buffer = std::get_if<AmdGpu::Liverpool::ColorBuffer>(&data)) {
DrawColorBuffer(*buffer); DrawColorBuffer(*buffer);
} else if (const auto* depth_data = std::get_if<DepthBuffer>(&data)) {
DrawDepthBuffer(*depth_data);
} }
} }
End(); End();

View File

@ -13,11 +13,15 @@ namespace Core::Devtools::Widget {
class RegPopup { class RegPopup {
int id; int id;
std::variant<AmdGpu::Liverpool::ColorBuffer> data; using DepthBuffer = std::tuple<AmdGpu::Liverpool::DepthBuffer, AmdGpu::Liverpool::DepthControl>;
std::variant<AmdGpu::Liverpool::ColorBuffer, DepthBuffer> data;
std::string title{}; std::string title{};
void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer); void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer);
void DrawDepthBuffer(const DepthBuffer& depth_data);
public: public:
bool open = false; bool open = false;
@ -25,6 +29,9 @@ public:
void SetData(AmdGpu::Liverpool::ColorBuffer color_buffer, u32 batch_id, u32 cb_id); void SetData(AmdGpu::Liverpool::ColorBuffer color_buffer, u32 batch_id, u32 cb_id);
void SetData(AmdGpu::Liverpool::DepthBuffer depth_buffer,
AmdGpu::Liverpool::DepthControl depth_control, u32 batch_id);
void Draw(); void Draw();
}; };

View File

@ -107,39 +107,16 @@ void RegView::DrawRegs() {
auto cc_mode = regs.color_control.mode.Value(); auto cc_mode = regs.color_control.mode.Value();
DrawRow("Color control", "%X (%s)", cc_mode, enum_name(cc_mode).data()); DrawRow("Color control", "%X (%s)", cc_mode, enum_name(cc_mode).data());
for (int cb = 0; cb < AmdGpu::Liverpool::NumColorBuffers; ++cb) { const auto open_new_popup = [&](int cb, auto... args) {
PushID(cb); if (GetIO().KeyShift) {
TableNextRow();
TableNextColumn();
const auto& buffer = regs.color_buffers[cb];
const auto open_new_popup = [&] {
auto& pop = extra_reg_popup.emplace_back(); auto& pop = extra_reg_popup.emplace_back();
pop.SetData(buffer, batch_id, cb); pop.SetData(args...);
pop.open = true; pop.open = true;
};
Text("Color buffer %d", cb);
TableNextColumn();
if (!buffer || !regs.color_target_mask.GetMask(cb)) {
TextUnformatted("N/A");
} else if (last_selected_cb == cb && default_reg_popup.open) { } else if (last_selected_cb == cb && default_reg_popup.open) {
if (SmallButton("x")) {
if (GetIO().KeyShift) {
open_new_popup();
} else {
default_reg_popup.open = false; default_reg_popup.open = false;
}
}
} else {
if (SmallButton("->")) {
if (GetIO().KeyShift) {
open_new_popup();
} else { } else {
last_selected_cb = cb; last_selected_cb = cb;
default_reg_popup.SetData(buffer, batch_id, cb); default_reg_popup.SetData(args...);
if (!default_reg_popup.open) { if (!default_reg_popup.open) {
default_reg_popup.open = true; default_reg_popup.open = true;
auto popup_pos = auto popup_pos =
@ -148,12 +125,44 @@ void RegView::DrawRegs() {
default_reg_popup.Draw(); default_reg_popup.Draw();
} }
} }
};
for (int cb = 0; cb < AmdGpu::Liverpool::NumColorBuffers; ++cb) {
PushID(cb);
TableNextRow();
TableNextColumn();
const auto& buffer = regs.color_buffers[cb];
Text("Color buffer %d", cb);
TableNextColumn();
if (!buffer || !regs.color_target_mask.GetMask(cb)) {
TextUnformatted("N/A");
} else {
const char* text = last_selected_cb == cb && default_reg_popup.open ? "x" : "->";
if (SmallButton(text)) {
open_new_popup(cb, buffer, batch_id, cb);
} }
} }
PopID(); PopID();
} }
TableNextRow();
TableNextColumn();
TextUnformatted("Depth buffer");
TableNextColumn();
if (regs.depth_buffer.Address() == 0 || !regs.depth_control.depth_enable) {
TextUnformatted("N/A");
} else {
constexpr auto depth_id = 0xF3;
const char* text = last_selected_cb == depth_id && default_reg_popup.open ? "x" : "->";
if (SmallButton(text)) {
open_new_popup(depth_id, regs.depth_buffer, regs.depth_control, batch_id);
}
}
EndTable(); EndTable();
} }
} }