summaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/graphics_cmdlists.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-08-24 17:23:02 +0200
committerGravatar Tony Wasserka2014-12-09 16:37:34 +0100
commit2793619dcef9fb2f97db5f0258ca950e18fe7f13 (patch)
tree47f0b608ca674d7dce921de2e11b10fc1ca9807a /src/citra_qt/debugger/graphics_cmdlists.cpp
parentcitra-qt: Add texture viewer to Pica command list. (diff)
downloadyuzu-2793619dcef9fb2f97db5f0258ca950e18fe7f13.tar.gz
yuzu-2793619dcef9fb2f97db5f0258ca950e18fe7f13.tar.xz
yuzu-2793619dcef9fb2f97db5f0258ca950e18fe7f13.zip
citra_qt: Add enhanced texture debugging widgets.
Double-clicking a texture parameter command in the pica command lists will spawn these as a new tab in the pica command list dock area.
Diffstat (limited to 'src/citra_qt/debugger/graphics_cmdlists.cpp')
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp173
1 files changed, 155 insertions, 18 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index dcd0ced33..4f58e9a90 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -4,30 +4,39 @@
4 4
5#include <QLabel> 5#include <QLabel>
6#include <QListView> 6#include <QListView>
7#include <QMainWindow>
7#include <QPushButton> 8#include <QPushButton>
8#include <QVBoxLayout> 9#include <QVBoxLayout>
9#include <QTreeView> 10#include <QTreeView>
10 11#include <QSpinBox>
11#include "graphics_cmdlists.hxx" 12#include <QComboBox>
12 13
13#include "video_core/pica.h" 14#include "video_core/pica.h"
14#include "video_core/math.h" 15#include "video_core/math.h"
15 16
16#include "video_core/debug_utils/debug_utils.h" 17#include "video_core/debug_utils/debug_utils.h"
17 18
19#include "graphics_cmdlists.hxx"
20
21#include "util/spinbox.hxx"
22
23QImage LoadTexture(u8* src, const Pica::DebugUtils::TextureInfo& info) {
24 QImage decoded_image(info.width, info.height, QImage::Format_ARGB32);
25 for (int y = 0; y < info.height; ++y) {
26 for (int x = 0; x < info.width; ++x) {
27 Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info);
28 decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a()));
29 }
30 }
31
32 return decoded_image;
33}
34
18class TextureInfoWidget : public QWidget { 35class TextureInfoWidget : public QWidget {
19public: 36public:
20 TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) { 37 TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) {
21 QImage decoded_image(info.width, info.height, QImage::Format_ARGB32);
22 for (int y = 0; y < info.height; ++y) {
23 for (int x = 0; x < info.width; ++x) {
24 Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info);
25 decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a()));
26 }
27 }
28
29 QLabel* image_widget = new QLabel; 38 QLabel* image_widget = new QLabel;
30 QPixmap image_pixmap = QPixmap::fromImage(decoded_image); 39 QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info));
31 image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); 40 image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
32 image_widget->setPixmap(image_pixmap); 41 image_widget->setPixmap(image_pixmap);
33 42
@@ -37,6 +46,120 @@ public:
37 } 46 }
38}; 47};
39 48
49TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent)
50 : QDockWidget(tr("Texture 0x%1").arg(info.address, 8, 16, QLatin1Char('0'))),
51 info(info) {
52
53 QWidget* main_widget = new QWidget;
54
55 QLabel* image_widget = new QLabel;
56
57 connect(this, SIGNAL(UpdatePixmap(const QPixmap&)), image_widget, SLOT(setPixmap(const QPixmap&)));
58
59 CSpinBox* phys_address_spinbox = new CSpinBox;
60 phys_address_spinbox->SetBase(16);
61 phys_address_spinbox->SetRange(0, 0xFFFFFFFF);
62 phys_address_spinbox->SetPrefix("0x");
63 phys_address_spinbox->SetValue(info.address);
64 connect(phys_address_spinbox, SIGNAL(ValueChanged(qint64)), this, SLOT(OnAddressChanged(qint64)));
65
66 QComboBox* format_choice = new QComboBox;
67 format_choice->addItem(tr("RGBA8"));
68 format_choice->addItem(tr("RGB8"));
69 format_choice->addItem(tr("RGBA5551"));
70 format_choice->addItem(tr("RGB565"));
71 format_choice->addItem(tr("RGBA4"));
72 format_choice->setCurrentIndex(static_cast<int>(info.format));
73 connect(format_choice, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormatChanged(int)));
74
75 QSpinBox* width_spinbox = new QSpinBox;
76 width_spinbox->setMaximum(65535);
77 width_spinbox->setValue(info.width);
78 connect(width_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnWidthChanged(int)));
79
80 QSpinBox* height_spinbox = new QSpinBox;
81 height_spinbox->setMaximum(65535);
82 height_spinbox->setValue(info.height);
83 connect(height_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnHeightChanged(int)));
84
85 QSpinBox* stride_spinbox = new QSpinBox;
86 stride_spinbox->setMaximum(65535 * 4);
87 stride_spinbox->setValue(info.stride);
88 connect(stride_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnStrideChanged(int)));
89
90 QVBoxLayout* main_layout = new QVBoxLayout;
91 main_layout->addWidget(image_widget);
92
93 {
94 QHBoxLayout* sub_layout = new QHBoxLayout;
95 sub_layout->addWidget(new QLabel(tr("Source Address:")));
96 sub_layout->addWidget(phys_address_spinbox);
97 main_layout->addLayout(sub_layout);
98 }
99
100 {
101 QHBoxLayout* sub_layout = new QHBoxLayout;
102 sub_layout->addWidget(new QLabel(tr("Format")));
103 sub_layout->addWidget(format_choice);
104 main_layout->addLayout(sub_layout);
105 }
106
107 {
108 QHBoxLayout* sub_layout = new QHBoxLayout;
109 sub_layout->addWidget(new QLabel(tr("Width:")));
110 sub_layout->addWidget(width_spinbox);
111 sub_layout->addStretch();
112 sub_layout->addWidget(new QLabel(tr("Height:")));
113 sub_layout->addWidget(height_spinbox);
114 sub_layout->addStretch();
115 sub_layout->addWidget(new QLabel(tr("Stride:")));
116 sub_layout->addWidget(stride_spinbox);
117 main_layout->addLayout(sub_layout);
118 }
119
120 main_widget->setLayout(main_layout);
121
122 emit UpdatePixmap(ReloadPixmap());
123
124 setWidget(main_widget);
125}
126
127void TextureInfoDockWidget::OnAddressChanged(qint64 value)
128{
129 info.address = value;
130 emit UpdatePixmap(ReloadPixmap());
131}
132
133void TextureInfoDockWidget::OnFormatChanged(int value)
134{
135 info.format = static_cast<Pica::Regs::TextureFormat>(value);
136 emit UpdatePixmap(ReloadPixmap());
137}
138
139void TextureInfoDockWidget::OnWidthChanged(int value)
140{
141 info.width = value;
142 emit UpdatePixmap(ReloadPixmap());
143}
144
145void TextureInfoDockWidget::OnHeightChanged(int value)
146{
147 info.height = value;
148 emit UpdatePixmap(ReloadPixmap());
149}
150
151void TextureInfoDockWidget::OnStrideChanged(int value)
152{
153 info.stride = value;
154 emit UpdatePixmap(ReloadPixmap());
155}
156
157QPixmap TextureInfoDockWidget::ReloadPixmap() const
158{
159 u8* src = Memory::GetPointer(info.address);
160 return QPixmap::fromImage(LoadTexture(src, info));
161}
162
40GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) 163GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent)
41{ 164{
42 165
@@ -106,30 +229,42 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&
106 endResetModel(); 229 endResetModel();
107} 230}
108 231
232#define COMMAND_IN_RANGE(cmd_id, reg_name) \
233 (cmd_id >= PICA_REG_INDEX(reg_name) && \
234 cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4)
235
236void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index)
237{
238
239 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
240 if (COMMAND_IN_RANGE(command_id, texture0)) {
241 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0,
242 Pica::registers.texture0_format);
243 QMainWindow* main_window = (QMainWindow*)parent();
244 main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window));
245 }
246}
247
109void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) 248void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index)
110{ 249{
111 QWidget* new_info_widget; 250 QWidget* new_info_widget;
112 251
113#define COMMAND_IN_RANGE(cmd_id, reg_name) (cmd_id >= PICA_REG_INDEX(reg_name) && cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4)
114 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); 252 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
115 if (COMMAND_IN_RANGE(command_id, texture0)) { 253 if (COMMAND_IN_RANGE(command_id, texture0)) {
116 u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress()); 254 u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress());
117 Pica::DebugUtils::TextureInfo info; 255 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0,
118 info.width = Pica::registers.texture0.width; 256 Pica::registers.texture0_format);
119 info.height = Pica::registers.texture0.height;
120 info.stride = 3 * Pica::registers.texture0.width;
121 info.format = Pica::registers.texture0_format;
122 new_info_widget = new TextureInfoWidget(src, info); 257 new_info_widget = new TextureInfoWidget(src, info);
123 } else { 258 } else {
124 new_info_widget = new QWidget; 259 new_info_widget = new QWidget;
125 } 260 }
126#undef COMMAND_IN_RANGE
127 261
128 widget()->layout()->removeWidget(command_info_widget); 262 widget()->layout()->removeWidget(command_info_widget);
129 delete command_info_widget; 263 delete command_info_widget;
130 widget()->layout()->addWidget(new_info_widget); 264 widget()->layout()->addWidget(new_info_widget);
131 command_info_widget = new_info_widget; 265 command_info_widget = new_info_widget;
132} 266}
267#undef COMMAND_IN_RANGE
133 268
134GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) 269GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent)
135{ 270{
@@ -145,6 +280,8 @@ GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pi
145 280
146 connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), 281 connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
147 this, SLOT(SetCommandInfo(const QModelIndex&))); 282 this, SLOT(SetCommandInfo(const QModelIndex&)));
283 connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)),
284 this, SLOT(OnCommandDoubleClicked(const QModelIndex&)));
148 285
149 286
150 toggle_tracing = new QPushButton(tr("Start Tracing")); 287 toggle_tracing = new QPushButton(tr("Start Tracing"));