summaryrefslogtreecommitdiff
path: root/src/citra_qt/debugger/graphics_cmdlists.cpp
diff options
context:
space:
mode:
authorGravatar darkf2014-12-29 19:47:41 -0800
committerGravatar darkf2014-12-29 19:47:41 -0800
commit8ba9ac0f74abb0408a26207a76a0c1808bad8de0 (patch)
treef1c7c3393fa726435b5b90bf335567c93e528ef1 /src/citra_qt/debugger/graphics_cmdlists.cpp
parentAdd comment regarding __WIN32__ in SkyEye code (diff)
parentMerge pull request #367 from bunnei/usat_ssat (diff)
downloadyuzu-8ba9ac0f74abb0408a26207a76a0c1808bad8de0.tar.gz
yuzu-8ba9ac0f74abb0408a26207a76a0c1808bad8de0.tar.xz
yuzu-8ba9ac0f74abb0408a26207a76a0c1808bad8de0.zip
Fix merge conflicts
Diffstat (limited to 'src/citra_qt/debugger/graphics_cmdlists.cpp')
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp275
1 files changed, 255 insertions, 20 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 71dd166cd..753cc25da 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -1,31 +1,179 @@
1// Copyright 2014 Citra Emulator Project 1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <QLabel>
5#include <QListView> 6#include <QListView>
7#include <QMainWindow>
6#include <QPushButton> 8#include <QPushButton>
7#include <QVBoxLayout> 9#include <QVBoxLayout>
8#include <QTreeView> 10#include <QTreeView>
11#include <QSpinBox>
12#include <QComboBox>
13
14#include "video_core/pica.h"
15#include "video_core/math.h"
16
17#include "video_core/debug_utils/debug_utils.h"
9 18
10#include "graphics_cmdlists.hxx" 19#include "graphics_cmdlists.hxx"
11 20
12GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) 21#include "util/spinbox.hxx"
13{ 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, true);
28 decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a()));
29 }
30 }
31
32 return decoded_image;
33}
34
35class TextureInfoWidget : public QWidget {
36public:
37 TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) {
38 QLabel* image_widget = new QLabel;
39 QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info));
40 image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
41 image_widget->setPixmap(image_pixmap);
42
43 QVBoxLayout* layout = new QVBoxLayout;
44 layout->addWidget(image_widget);
45 setLayout(layout);
46 }
47};
48
49TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent)
50 : QDockWidget(tr("Texture 0x%1").arg(info.physical_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.physical_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->addItem(tr("IA8"));
73 format_choice->addItem(tr("UNK6"));
74 format_choice->addItem(tr("I8"));
75 format_choice->addItem(tr("A8"));
76 format_choice->addItem(tr("IA4"));
77 format_choice->addItem(tr("UNK10"));
78 format_choice->addItem(tr("A4"));
79 format_choice->setCurrentIndex(static_cast<int>(info.format));
80 connect(format_choice, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormatChanged(int)));
81
82 QSpinBox* width_spinbox = new QSpinBox;
83 width_spinbox->setMaximum(65535);
84 width_spinbox->setValue(info.width);
85 connect(width_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnWidthChanged(int)));
86
87 QSpinBox* height_spinbox = new QSpinBox;
88 height_spinbox->setMaximum(65535);
89 height_spinbox->setValue(info.height);
90 connect(height_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnHeightChanged(int)));
91
92 QSpinBox* stride_spinbox = new QSpinBox;
93 stride_spinbox->setMaximum(65535 * 4);
94 stride_spinbox->setValue(info.stride);
95 connect(stride_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnStrideChanged(int)));
96
97 QVBoxLayout* main_layout = new QVBoxLayout;
98 main_layout->addWidget(image_widget);
99
100 {
101 QHBoxLayout* sub_layout = new QHBoxLayout;
102 sub_layout->addWidget(new QLabel(tr("Source Address:")));
103 sub_layout->addWidget(phys_address_spinbox);
104 main_layout->addLayout(sub_layout);
105 }
106
107 {
108 QHBoxLayout* sub_layout = new QHBoxLayout;
109 sub_layout->addWidget(new QLabel(tr("Format")));
110 sub_layout->addWidget(format_choice);
111 main_layout->addLayout(sub_layout);
112 }
113
114 {
115 QHBoxLayout* sub_layout = new QHBoxLayout;
116 sub_layout->addWidget(new QLabel(tr("Width:")));
117 sub_layout->addWidget(width_spinbox);
118 sub_layout->addStretch();
119 sub_layout->addWidget(new QLabel(tr("Height:")));
120 sub_layout->addWidget(height_spinbox);
121 sub_layout->addStretch();
122 sub_layout->addWidget(new QLabel(tr("Stride:")));
123 sub_layout->addWidget(stride_spinbox);
124 main_layout->addLayout(sub_layout);
125 }
126
127 main_widget->setLayout(main_layout);
128
129 emit UpdatePixmap(ReloadPixmap());
130
131 setWidget(main_widget);
132}
133
134void TextureInfoDockWidget::OnAddressChanged(qint64 value) {
135 info.physical_address = value;
136 emit UpdatePixmap(ReloadPixmap());
137}
14 138
139void TextureInfoDockWidget::OnFormatChanged(int value) {
140 info.format = static_cast<Pica::Regs::TextureFormat>(value);
141 emit UpdatePixmap(ReloadPixmap());
15} 142}
16 143
17int GPUCommandListModel::rowCount(const QModelIndex& parent) const 144void TextureInfoDockWidget::OnWidthChanged(int value) {
18{ 145 info.width = value;
146 emit UpdatePixmap(ReloadPixmap());
147}
148
149void TextureInfoDockWidget::OnHeightChanged(int value) {
150 info.height = value;
151 emit UpdatePixmap(ReloadPixmap());
152}
153
154void TextureInfoDockWidget::OnStrideChanged(int value) {
155 info.stride = value;
156 emit UpdatePixmap(ReloadPixmap());
157}
158
159QPixmap TextureInfoDockWidget::ReloadPixmap() const {
160 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(info.physical_address));
161 return QPixmap::fromImage(LoadTexture(src, info));
162}
163
164GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) {
165
166}
167
168int GPUCommandListModel::rowCount(const QModelIndex& parent) const {
19 return pica_trace.writes.size(); 169 return pica_trace.writes.size();
20} 170}
21 171
22int GPUCommandListModel::columnCount(const QModelIndex& parent) const 172int GPUCommandListModel::columnCount(const QModelIndex& parent) const {
23{
24 return 2; 173 return 2;
25} 174}
26 175
27QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const 176QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const {
28{
29 if (!index.isValid()) 177 if (!index.isValid())
30 return QVariant(); 178 return QVariant();
31 179
@@ -36,21 +184,39 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
36 if (role == Qt::DisplayRole) { 184 if (role == Qt::DisplayRole) {
37 QString content; 185 QString content;
38 if (index.column() == 0) { 186 if (index.column() == 0) {
39 content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str()); 187 QString content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str());
40 content.append(" "); 188 content.append(" ");
189 return content;
41 } else if (index.column() == 1) { 190 } else if (index.column() == 1) {
42 content.append(QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'))); 191 QString content = QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'));
43 content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0'))); 192 content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0')));
193 return content;
44 } 194 }
195 } else if (role == CommandIdRole) {
196 return QVariant::fromValue<int>(cmd.cmd_id.Value());
197 }
45 198
46 return QVariant(content); 199 return QVariant();
200}
201
202QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const {
203 switch(role) {
204 case Qt::DisplayRole:
205 {
206 if (section == 0) {
207 return tr("Command Name");
208 } else if (section == 1) {
209 return tr("Data");
210 }
211
212 break;
213 }
47 } 214 }
48 215
49 return QVariant(); 216 return QVariant();
50} 217}
51 218
52void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) 219void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) {
53{
54 beginResetModel(); 220 beginResetModel();
55 221
56 pica_trace = trace; 222 pica_trace = trace;
@@ -58,38 +224,107 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&
58 endResetModel(); 224 endResetModel();
59} 225}
60 226
227#define COMMAND_IN_RANGE(cmd_id, reg_name) \
228 (cmd_id >= PICA_REG_INDEX(reg_name) && \
229 cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4)
61 230
62GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) 231void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
63{ 232 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
233 if (COMMAND_IN_RANGE(command_id, texture0) ||
234 COMMAND_IN_RANGE(command_id, texture1) ||
235 COMMAND_IN_RANGE(command_id, texture2)) {
236
237 unsigned index;
238 if (COMMAND_IN_RANGE(command_id, texture0)) {
239 index = 0;
240 } else if (COMMAND_IN_RANGE(command_id, texture1)) {
241 index = 1;
242 } else {
243 index = 2;
244 }
245 auto config = Pica::registers.GetTextures()[index].config;
246 auto format = Pica::registers.GetTextures()[index].format;
247 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
248
249 // TODO: Instead, emit a signal here to be caught by the main window widget.
250 auto main_window = static_cast<QMainWindow*>(parent());
251 main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window));
252 }
253}
254
255void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
256 QWidget* new_info_widget;
257
258 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
259 if (COMMAND_IN_RANGE(command_id, texture0) ||
260 COMMAND_IN_RANGE(command_id, texture1) ||
261 COMMAND_IN_RANGE(command_id, texture2)) {
262
263 unsigned index;
264 if (COMMAND_IN_RANGE(command_id, texture0)) {
265 index = 0;
266 } else if (COMMAND_IN_RANGE(command_id, texture1)) {
267 index = 1;
268 } else {
269 index = 2;
270 }
271 auto config = Pica::registers.GetTextures()[index].config;
272 auto format = Pica::registers.GetTextures()[index].format;
273
274 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(config, format);
275 u8* src = Memory::GetPointer(Pica::PAddrToVAddr(config.GetPhysicalAddress()));
276 new_info_widget = new TextureInfoWidget(src, info);
277 } else {
278 new_info_widget = new QWidget;
279 }
280
281 widget()->layout()->removeWidget(command_info_widget);
282 delete command_info_widget;
283 widget()->layout()->addWidget(new_info_widget);
284 command_info_widget = new_info_widget;
285}
286#undef COMMAND_IN_RANGE
287
288GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) {
289 setObjectName("Pica Command List");
64 GPUCommandListModel* model = new GPUCommandListModel(this); 290 GPUCommandListModel* model = new GPUCommandListModel(this);
65 291
66 QWidget* main_widget = new QWidget; 292 QWidget* main_widget = new QWidget;
67 293
68 QTreeView* list_widget = new QTreeView; 294 list_widget = new QTreeView;
69 list_widget->setModel(model); 295 list_widget->setModel(model);
70 list_widget->setFont(QFont("monospace")); 296 list_widget->setFont(QFont("monospace"));
71 list_widget->setRootIsDecorated(false); 297 list_widget->setRootIsDecorated(false);
72 298
73 QPushButton* toggle_tracing = new QPushButton(tr("Start Tracing")); 299 connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
300 this, SLOT(SetCommandInfo(const QModelIndex&)));
301 connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)),
302 this, SLOT(OnCommandDoubleClicked(const QModelIndex&)));
303
304 toggle_tracing = new QPushButton(tr("Start Tracing"));
74 305
75 connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); 306 connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing()));
76 connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), 307 connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)),
77 model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); 308 model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&)));
78 309
310 command_info_widget = new QWidget;
311
79 QVBoxLayout* main_layout = new QVBoxLayout; 312 QVBoxLayout* main_layout = new QVBoxLayout;
80 main_layout->addWidget(list_widget); 313 main_layout->addWidget(list_widget);
81 main_layout->addWidget(toggle_tracing); 314 main_layout->addWidget(toggle_tracing);
315 main_layout->addWidget(command_info_widget);
82 main_widget->setLayout(main_layout); 316 main_widget->setLayout(main_layout);
83 317
84 setWidget(main_widget); 318 setWidget(main_widget);
85} 319}
86 320
87void GPUCommandListWidget::OnToggleTracing() 321void GPUCommandListWidget::OnToggleTracing() {
88{
89 if (!Pica::DebugUtils::IsPicaTracing()) { 322 if (!Pica::DebugUtils::IsPicaTracing()) {
90 Pica::DebugUtils::StartPicaTracing(); 323 Pica::DebugUtils::StartPicaTracing();
324 toggle_tracing->setText(tr("Finish Tracing"));
91 } else { 325 } else {
92 pica_trace = Pica::DebugUtils::FinishPicaTracing(); 326 pica_trace = Pica::DebugUtils::FinishPicaTracing();
93 emit TracingFinished(*pica_trace); 327 emit TracingFinished(*pica_trace);
328 toggle_tracing->setText(tr("Start Tracing"));
94 } 329 }
95} 330}