devtools: refactor DrawRow to templating

This commit is contained in:
Vinicius Rangel 2024-10-14 13:33:54 -03:00
parent 5caee0f4c3
commit a145ed0f07
No known key found for this signature in database
GPG Key ID: A5B154D904B761D9
4 changed files with 83 additions and 82 deletions

View File

@ -81,7 +81,9 @@
#pragma pack(1) #pragma pack(1)
template <std::size_t Position, std::size_t Bits, typename T> template <std::size_t Position, std::size_t Bits, typename T>
struct BitField { struct BitField {
private:
using Type = T;
// UnderlyingType is T for non-enum types and the underlying type of T if // UnderlyingType is T for non-enum types and the underlying type of T if
// T is an enumeration. Note that T is wrapped within an enable_if in the // T is an enumeration. Note that T is wrapped within an enable_if in the
// former case to workaround compile errors which arise when using // former case to workaround compile errors which arise when using
@ -92,7 +94,6 @@ private:
// We store the value as the unsigned type to avoid undefined behaviour on value shifting // We store the value as the unsigned type to avoid undefined behaviour on value shifting
using StorageType = std::make_unsigned_t<UnderlyingType>; using StorageType = std::make_unsigned_t<UnderlyingType>;
public:
/// Constants to allow limited introspection of fields if needed /// Constants to allow limited introspection of fields if needed
static constexpr std::size_t position = Position; static constexpr std::size_t position = Position;
static constexpr std::size_t bits = Bits; static constexpr std::size_t bits = Bits;

View File

@ -4,15 +4,16 @@
#pragma once #pragma once
#include <string> #include <string>
#include <type_traits>
#include <variant> #include <variant>
#include <magic_enum.hpp> #include <magic_enum.hpp>
#include "common/bit_field.h"
#include "common/types.h" #include "common/types.h"
#include "video_core/amdgpu/pm4_opcodes.h" #include "video_core/amdgpu/pm4_opcodes.h"
namespace Core::Devtools::Widget { namespace Core::Devtools::Widget {
/* /*
* Generic PM4 header * Generic PM4 header
*/ */
@ -57,16 +58,24 @@ void DrawRow(const char* text, const char* fmt, Args... args) {
ImGui::TextUnformatted(buf); ImGui::TextUnformatted(buf);
} }
template <typename T, typename V = u32> template <typename T>
void DrawEnumRow(const char* text, T value) { void DrawValueRow(const char* text, T value) {
DrawRow(text, "%X (%s)", V(value), magic_enum::enum_name(value).data()); if constexpr (std::is_enum_v<T>) {
return DrawRow(text, "%X (%s)", value, magic_enum::enum_name(value).data());
} else if constexpr (std::is_integral_v<T>) {
return DrawRow(text, "%X", value);
} else if constexpr (std::is_base_of_v<BitField<T::position, T::bits, typename T::Type>, T>) {
return DrawValueRow(text, value.Value());
} else {
static_assert(false, "Unsupported type");
}
} }
template <typename V, typename... Extra> template <typename V, typename... Extra>
void DrawMultipleRow(const char* text, const char* fmt, V arg, Extra&&... extra_args) { void DrawValueRowList(const char* text, V arg, Extra&&... extra_args) {
DrawRow(text, fmt, arg); DrawValueRow(text, arg);
if constexpr (sizeof...(extra_args) > 0) { if constexpr (sizeof...(extra_args) > 0) {
DrawMultipleRow(std::forward<Extra>(extra_args)...); DrawValueRowList(std::forward<Extra>(extra_args)...);
} }
} }

View File

@ -21,13 +21,13 @@ void RegPopup::DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer) {
// clang-format off // clang-format off
DrawMultipleRow( DrawValueRowList(
"BASE_ADDR", "%X", buffer.base_address, "BASE_ADDR", buffer.base_address,
"PITCH.TILE_MAX", "%X", buffer.pitch.tile_max, "PITCH.TILE_MAX", buffer.pitch.tile_max,
"PITCH.FMASK_TILE_MAX", "%X", buffer.pitch.fmask_tile_max, "PITCH.FMASK_TILE_MAX", buffer.pitch.fmask_tile_max,
"SLICE.TILE_MAX", "%X", buffer.slice.tile_max, "SLICE.TILE_MAX", buffer.slice.tile_max,
"VIEW.SLICE_START", "%X", buffer.view.slice_start, "VIEW.SLICE_START", buffer.view.slice_start,
"VIEW.SLICE_MAX", "%X", buffer.view.slice_max "VIEW.SLICE_MAX", buffer.view.slice_max
); );
TableNextRow(); TableNextRow();
@ -49,31 +49,25 @@ void RegPopup::DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer) {
} }
TableNextRow(); TableNextRow();
DrawMultipleRow( DrawValueRowList(
"CMASK_BASE_EXT", "%X", buffer.cmask_base_address, "CMASK_BASE_EXT", buffer.cmask_base_address,
"FMASK_BASE_EXT", "%X", buffer.fmask_base_address, "FMASK_BASE_EXT", buffer.fmask_base_address,
"FMASK_SLICE.TILE_MAX", "%X", buffer.fmask_slice.tile_max, "FMASK_SLICE.TILE_MAX", buffer.fmask_slice.tile_max,
"CLEAR_WORD0", "%X", buffer.clear_word0, "CLEAR_WORD0", buffer.clear_word0,
"CLEAR_WORD1", "%X", buffer.clear_word1 "CLEAR_WORD1", buffer.clear_word1,
"Pitch()", buffer.Pitch(),
"Height()", buffer.Height(),
"Address()", buffer.Address(),
"CmaskAddress", buffer.CmaskAddress(),
"FmaskAddress", buffer.FmaskAddress(),
"NumSamples()", buffer.NumSamples(),
"NumSlices()", buffer.NumSlices(),
"GetColorSliceSize()", buffer.GetColorSliceSize(),
"GetTilingMode()", buffer.GetTilingMode(),
"IsTiled()", buffer.IsTiled(),
"NumFormat()", buffer.NumFormat()
); );
DrawMultipleRow(
"Pitch()", "%X", buffer.Pitch(),
"Height()", "%X", buffer.Height(),
"Address()", "%X", buffer.Address(),
"CmaskAddress", "%X", buffer.CmaskAddress(),
"FmaskAddress", "%X", buffer.FmaskAddress(),
"NumSamples()", "%X", buffer.NumSamples(),
"NumSlices()", "%X", buffer.NumSlices(),
"GetColorSliceSize()", "%X", buffer.GetColorSliceSize()
);
auto tiling_mode = buffer.GetTilingMode();
auto num_format = buffer.NumFormat();
DrawEnumRow("GetTilingMode()", tiling_mode);
DrawRow("IsTiled()", "%X", buffer.IsTiled());
DrawEnumRow("NumFormat()", num_format);
// clang-format on // clang-format on
EndTable(); EndTable();
@ -89,37 +83,34 @@ void RegPopup::DrawDepthBuffer(const DepthBuffer& depth_data) {
TableNextRow(); TableNextRow();
// clang-format off // clang-format off
DrawEnumRow("Z_INFO.FORMAT", depth_buffer.z_info.format.Value()); DrawValueRowList(
DrawMultipleRow( "Z_INFO.FORMAT", depth_buffer.z_info.format,
"Z_INFO.NUM_SAMPLES", "%X", depth_buffer.z_info.num_samples.Value(), "Z_INFO.NUM_SAMPLES", depth_buffer.z_info.num_samples,
"Z_INFO.TILE_SPLIT", "%X", depth_buffer.z_info.tile_split.Value(), "Z_INFO.TILE_SPLIT", depth_buffer.z_info.tile_split,
"Z_INFO.TILE_MODE_INDEX", "%X", depth_buffer.z_info.tile_mode_index.Value(), "Z_INFO.TILE_MODE_INDEX", depth_buffer.z_info.tile_mode_index,
"Z_INFO.DECOMPRESS_ON_N_ZPLANES", "%X", depth_buffer.z_info.decompress_on_n_zplanes.Value(), "Z_INFO.DECOMPRESS_ON_N_ZPLANES", depth_buffer.z_info.decompress_on_n_zplanes,
"Z_INFO.ALLOW_EXPCLEAR", "%X", depth_buffer.z_info.allow_expclear.Value(), "Z_INFO.ALLOW_EXPCLEAR", depth_buffer.z_info.allow_expclear,
"Z_INFO.READ_SIZE", "%X", depth_buffer.z_info.read_size.Value(), "Z_INFO.READ_SIZE", depth_buffer.z_info.read_size,
"Z_INFO.TILE_SURFACE_EN", "%X", depth_buffer.z_info.tile_surface_en.Value(), "Z_INFO.TILE_SURFACE_EN", depth_buffer.z_info.tile_surface_en,
"Z_INFO.CLEAR_DISALLOWED", "%X", depth_buffer.z_info.clear_disallowed.Value(), "Z_INFO.CLEAR_DISALLOWED", depth_buffer.z_info.clear_disallowed,
"Z_INFO.ZRANGE_PRECISION", "%X", depth_buffer.z_info.zrange_precision.Value() "Z_INFO.ZRANGE_PRECISION", depth_buffer.z_info.zrange_precision,
); "STENCIL_INFO.FORMAT", depth_buffer.stencil_info.format,
"Z_READ_BASE", depth_buffer.z_read_base,
DrawEnumRow("STENCIL_INFO.FORMAT", depth_buffer.stencil_info.format.Value()); "STENCIL_READ_BASE", depth_buffer.stencil_read_base,
"Z_WRITE_BASE", depth_buffer.z_write_base,
DrawMultipleRow( "STENCIL_WRITE_BASE", depth_buffer.stencil_write_base,
"Z_READ_BASE", "%X", depth_buffer.z_read_base, "DEPTH_SIZE.PITCH_TILE_MAX", depth_buffer.depth_size.pitch_tile_max,
"STENCIL_READ_BASE", "%X", depth_buffer.stencil_read_base, "DEPTH_SIZE.HEIGHT_TILE_MAX", depth_buffer.depth_size.height_tile_max,
"Z_WRITE_BASE", "%X", depth_buffer.z_write_base, "DEPTH_SLICE.TILE_MAX", depth_buffer.depth_slice.tile_max,
"STENCIL_WRITE_BASE", "%X", depth_buffer.stencil_write_base, "Pitch()", depth_buffer.Pitch(),
"DEPTH_SIZE.PITCH_TILE_MAX", "%X", depth_buffer.depth_size.pitch_tile_max.Value(), "Height()", depth_buffer.Height(),
"DEPTH_SIZE.HEIGHT_TILE_MAX", "%X", depth_buffer.depth_size.height_tile_max.Value(), "Address()", depth_buffer.Address(),
"DEPTH_SLICE.TILE_MAX", "%X", depth_buffer.depth_slice.tile_max.Value(), "NumSamples()", depth_buffer.NumSamples(),
"Pitch()", "%X", depth_buffer.Pitch(), "NumBits()", depth_buffer.NumBits(),
"Height()", "%X", depth_buffer.Height(), "GetDepthSliceSize()", depth_buffer.GetDepthSliceSize()
"Address()", "%X", depth_buffer.Address(),
"NumSamples()", "%X", depth_buffer.NumSamples(),
"NumBits()", "%X", depth_buffer.NumBits(),
"GetDepthSliceSize()", "%X", depth_buffer.GetDepthSliceSize()
); );
// clang-format on // clang-format on
EndTable(); EndTable();
} }
SeparatorText("Depth control"); SeparatorText("Depth control");
@ -127,19 +118,17 @@ void RegPopup::DrawDepthBuffer(const DepthBuffer& depth_data) {
TableNextRow(); TableNextRow();
// clang-format off // clang-format off
DrawMultipleRow( DrawValueRowList(
"STENCIL_ENABLE", "%X", depth_control.stencil_enable.Value(), "STENCIL_ENABLE", depth_control.stencil_enable,
"DEPTH_ENABLE", "%X", depth_control.depth_enable.Value(), "DEPTH_ENABLE", depth_control.depth_enable,
"DEPTH_WRITE_ENABLE", "%X", depth_control.depth_write_enable.Value(), "DEPTH_WRITE_ENABLE", depth_control.depth_write_enable,
"DEPTH_BOUNDS_ENABLE", "%X", depth_control.depth_bounds_enable.Value() "DEPTH_BOUNDS_ENABLE", depth_control.depth_bounds_enable,
); "DEPTH_FUNC", depth_control.depth_func,
DrawEnumRow("DEPTH_FUNC", depth_control.depth_func.Value()); "BACKFACE_ENABLE", depth_control.backface_enable,
DrawRow("BACKFACE_ENABLE", "%X", depth_control.backface_enable.Value()); "STENCIL_FUNC", depth_control.stencil_ref_func,
DrawEnumRow("STENCIL_FUNC", depth_control.stencil_ref_func.Value()); "STENCIL_FUNC_BF", depth_control.stencil_bf_func,
DrawEnumRow("STENCIL_FUNC_BF", depth_control.stencil_bf_func.Value()); "ENABLE_COLOR_WRITES_ON_DEPTH_FAIL", depth_control.enable_color_writes_on_depth_fail,
DrawMultipleRow( "DISABLE_COLOR_WRITES_ON_DEPTH_PASS", depth_control.disable_color_writes_on_depth_pass
"ENABLE_COLOR_WRITES_ON_DEPTH_FAIL", "%X", depth_control.enable_color_writes_on_depth_fail.Value(),
"DISABLE_COLOR_WRITES_ON_DEPTH_PASS", "%X", depth_control.disable_color_writes_on_depth_pass.Value()
); );
// clang-format on // clang-format on

View File

@ -20,7 +20,9 @@ class RegPopup {
void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer); void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer);
void DrawDepthBuffer(const DepthBuffer& depth_data); static void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer);
static void DrawDepthBuffer(const DepthBuffer& depth_data);
public: public:
bool open = false; bool open = false;