summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/citra_qt/CMakeLists.txt7
-rw-r--r--src/citra_qt/bootmanager.cpp13
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints.cpp261
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints.hxx53
-rw-r--r--src/citra_qt/debugger/graphics_breakpoints_p.hxx38
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.cpp241
-rw-r--r--src/citra_qt/debugger/graphics_cmdlists.hxx37
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.cpp282
-rw-r--r--src/citra_qt/debugger/graphics_framebuffer.hxx92
-rw-r--r--src/citra_qt/main.cpp16
-rw-r--r--src/citra_qt/util/spinbox.cpp303
-rw-r--r--src/citra_qt/util/spinbox.hxx88
-rw-r--r--src/common/common_funcs.h6
-rw-r--r--src/common/log.h3
-rw-r--r--src/video_core/command_processor.cpp13
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp110
-rw-r--r--src/video_core/debug_utils/debug_utils.h146
-rw-r--r--src/video_core/pica.h28
18 files changed, 1688 insertions, 49 deletions
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 98a48a69a..90e5c6aa6 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -8,9 +8,12 @@ set(SRCS
8 debugger/callstack.cpp 8 debugger/callstack.cpp
9 debugger/disassembler.cpp 9 debugger/disassembler.cpp
10 debugger/graphics.cpp 10 debugger/graphics.cpp
11 debugger/graphics_breakpoints.cpp
11 debugger/graphics_cmdlists.cpp 12 debugger/graphics_cmdlists.cpp
13 debugger/graphics_framebuffer.cpp
12 debugger/ramview.cpp 14 debugger/ramview.cpp
13 debugger/registers.cpp 15 debugger/registers.cpp
16 util/spinbox.cpp
14 bootmanager.cpp 17 bootmanager.cpp
15 hotkeys.cpp 18 hotkeys.cpp
16 main.cpp 19 main.cpp
@@ -23,9 +26,13 @@ set(HEADERS
23 debugger/callstack.hxx 26 debugger/callstack.hxx
24 debugger/disassembler.hxx 27 debugger/disassembler.hxx
25 debugger/graphics.hxx 28 debugger/graphics.hxx
29 debugger/graphics_breakpoints.hxx
30 debugger/graphics_breakpoints_p.hxx
26 debugger/graphics_cmdlists.hxx 31 debugger/graphics_cmdlists.hxx
32 debugger/graphics_framebuffer.hxx
27 debugger/ramview.hxx 33 debugger/ramview.hxx
28 debugger/registers.hxx 34 debugger/registers.hxx
35 util/spinbox.hxx
29 bootmanager.hxx 36 bootmanager.hxx
30 hotkeys.hxx 37 hotkeys.hxx
31 main.hxx 38 main.hxx
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 9a29f974b..b53206be6 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -14,6 +14,8 @@
14#include "core/core.h" 14#include "core/core.h"
15#include "core/settings.h" 15#include "core/settings.h"
16 16
17#include "video_core/debug_utils/debug_utils.h"
18
17#include "video_core/video_core.h" 19#include "video_core/video_core.h"
18 20
19#include "citra_qt/version.h" 21#include "citra_qt/version.h"
@@ -65,14 +67,21 @@ void EmuThread::Stop()
65 } 67 }
66 stop_run = true; 68 stop_run = true;
67 69
70 // Release emu threads from any breakpoints, so that this doesn't hang forever.
71 Pica::g_debug_context->ClearBreakpoints();
72
68 //core::g_state = core::SYS_DIE; 73 //core::g_state = core::SYS_DIE;
69 74
70 wait(500); 75 // TODO: Waiting here is just a bad workaround for retarded shutdown logic.
76 wait(1000);
71 if (isRunning()) 77 if (isRunning())
72 { 78 {
73 WARN_LOG(MASTER_LOG, "EmuThread still running, terminating..."); 79 WARN_LOG(MASTER_LOG, "EmuThread still running, terminating...");
74 quit(); 80 quit();
75 wait(1000); 81
82 // TODO: Waiting 50 seconds can be necessary if the logging subsystem has a lot of spam
83 // queued... This should be fixed.
84 wait(50000);
76 if (isRunning()) 85 if (isRunning())
77 { 86 {
78 WARN_LOG(MASTER_LOG, "EmuThread STILL running, something is wrong here..."); 87 WARN_LOG(MASTER_LOG, "EmuThread STILL running, something is wrong here...");
diff --git a/src/citra_qt/debugger/graphics_breakpoints.cpp b/src/citra_qt/debugger/graphics_breakpoints.cpp
new file mode 100644
index 000000000..df5579e15
--- /dev/null
+++ b/src/citra_qt/debugger/graphics_breakpoints.cpp
@@ -0,0 +1,261 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <QMetaType>
6#include <QPushButton>
7#include <QTreeWidget>
8#include <QVBoxLayout>
9#include <QLabel>
10
11#include "graphics_breakpoints.hxx"
12#include "graphics_breakpoints_p.hxx"
13
14BreakPointModel::BreakPointModel(std::shared_ptr<Pica::DebugContext> debug_context, QObject* parent)
15 : QAbstractListModel(parent), context_weak(debug_context),
16 at_breakpoint(debug_context->at_breakpoint),
17 active_breakpoint(debug_context->active_breakpoint)
18{
19
20}
21
22int BreakPointModel::columnCount(const QModelIndex& parent) const
23{
24 return 2;
25}
26
27int BreakPointModel::rowCount(const QModelIndex& parent) const
28{
29 return static_cast<int>(Pica::DebugContext::Event::NumEvents);
30}
31
32QVariant BreakPointModel::data(const QModelIndex& index, int role) const
33{
34 const auto event = static_cast<Pica::DebugContext::Event>(index.row());
35
36 switch (role) {
37 case Qt::DisplayRole:
38 {
39 switch (index.column()) {
40 case 0:
41 {
42 std::map<Pica::DebugContext::Event, QString> map;
43 map.insert({Pica::DebugContext::Event::CommandLoaded, tr("Pica command loaded")});
44 map.insert({Pica::DebugContext::Event::CommandProcessed, tr("Pica command processed")});
45 map.insert({Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch")});
46 map.insert({Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch")});
47
48 _dbg_assert_(GUI, map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents));
49
50 return map[event];
51 }
52
53 case 1:
54 return data(index, Role_IsEnabled).toBool() ? tr("Enabled") : tr("Disabled");
55
56 default:
57 break;
58 }
59
60 break;
61 }
62
63 case Qt::BackgroundRole:
64 {
65 if (at_breakpoint && index.row() == static_cast<int>(active_breakpoint)) {
66 return QBrush(QColor(0xE0, 0xE0, 0x10));
67 }
68 break;
69 }
70
71 case Role_IsEnabled:
72 {
73 auto context = context_weak.lock();
74 return context && context->breakpoints[event].enabled;
75 }
76
77 default:
78 break;
79 }
80 return QVariant();
81}
82
83QVariant BreakPointModel::headerData(int section, Qt::Orientation orientation, int role) const
84{
85 switch(role) {
86 case Qt::DisplayRole:
87 {
88 if (section == 0) {
89 return tr("Event");
90 } else if (section == 1) {
91 return tr("Status");
92 }
93
94 break;
95 }
96 }
97
98 return QVariant();
99}
100
101bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role)
102{
103 const auto event = static_cast<Pica::DebugContext::Event>(index.row());
104
105 switch (role) {
106 case Role_IsEnabled:
107 {
108 auto context = context_weak.lock();
109 if (!context)
110 return false;
111
112 context->breakpoints[event].enabled = value.toBool();
113 QModelIndex changed_index = createIndex(index.row(), 1);
114 emit dataChanged(changed_index, changed_index);
115 return true;
116 }
117 }
118
119 return false;
120}
121
122
123void BreakPointModel::OnBreakPointHit(Pica::DebugContext::Event event)
124{
125 auto context = context_weak.lock();
126 if (!context)
127 return;
128
129 active_breakpoint = context->active_breakpoint;
130 at_breakpoint = context->at_breakpoint;
131 emit dataChanged(createIndex(static_cast<int>(event), 0),
132 createIndex(static_cast<int>(event), 1));
133}
134
135void BreakPointModel::OnResumed()
136{
137 auto context = context_weak.lock();
138 if (!context)
139 return;
140
141 at_breakpoint = context->at_breakpoint;
142 emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0),
143 createIndex(static_cast<int>(active_breakpoint), 1));
144 active_breakpoint = context->active_breakpoint;
145}
146
147
148GraphicsBreakPointsWidget::GraphicsBreakPointsWidget(std::shared_ptr<Pica::DebugContext> debug_context,
149 QWidget* parent)
150 : QDockWidget(tr("Pica Breakpoints"), parent),
151 Pica::DebugContext::BreakPointObserver(debug_context)
152{
153 setObjectName("PicaBreakPointsWidget");
154
155 status_text = new QLabel(tr("Emulation running"));
156 resume_button = new QPushButton(tr("Resume"));
157 resume_button->setEnabled(false);
158
159 breakpoint_model = new BreakPointModel(debug_context, this);
160 breakpoint_list = new QTreeView;
161 breakpoint_list->setModel(breakpoint_model);
162
163 toggle_breakpoint_button = new QPushButton(tr("Enable"));
164 toggle_breakpoint_button->setEnabled(false);
165
166 qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event");
167
168 connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested()));
169
170 connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
171 this, SLOT(OnBreakPointHit(Pica::DebugContext::Event,void*)),
172 Qt::BlockingQueuedConnection);
173 connect(this, SIGNAL(Resumed()), this, SLOT(OnResumed()));
174
175 connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
176 breakpoint_model, SLOT(OnBreakPointHit(Pica::DebugContext::Event)),
177 Qt::BlockingQueuedConnection);
178 connect(this, SIGNAL(Resumed()), breakpoint_model, SLOT(OnResumed()));
179
180 connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&,const QModelIndex&)),
181 breakpoint_model, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)));
182
183 connect(breakpoint_list->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
184 this, SLOT(OnBreakpointSelectionChanged(QModelIndex)));
185
186 connect(toggle_breakpoint_button, SIGNAL(clicked()), this, SLOT(OnToggleBreakpointEnabled()));
187
188 QWidget* main_widget = new QWidget;
189 auto main_layout = new QVBoxLayout;
190 {
191 auto sub_layout = new QHBoxLayout;
192 sub_layout->addWidget(status_text);
193 sub_layout->addWidget(resume_button);
194 main_layout->addLayout(sub_layout);
195 }
196 main_layout->addWidget(breakpoint_list);
197 main_layout->addWidget(toggle_breakpoint_button);
198 main_widget->setLayout(main_layout);
199
200 setWidget(main_widget);
201}
202
203void GraphicsBreakPointsWidget::OnPicaBreakPointHit(Event event, void* data)
204{
205 // Process in GUI thread
206 emit BreakPointHit(event, data);
207}
208
209void GraphicsBreakPointsWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data)
210{
211 status_text->setText(tr("Emulation halted at breakpoint"));
212 resume_button->setEnabled(true);
213}
214
215void GraphicsBreakPointsWidget::OnPicaResume()
216{
217 // Process in GUI thread
218 emit Resumed();
219}
220
221void GraphicsBreakPointsWidget::OnResumed()
222{
223 status_text->setText(tr("Emulation running"));
224 resume_button->setEnabled(false);
225}
226
227void GraphicsBreakPointsWidget::OnResumeRequested()
228{
229 if (auto context = context_weak.lock())
230 context->Resume();
231}
232
233void GraphicsBreakPointsWidget::OnBreakpointSelectionChanged(const QModelIndex& index)
234{
235 if (!index.isValid()) {
236 toggle_breakpoint_button->setEnabled(false);
237 return;
238 }
239
240 toggle_breakpoint_button->setEnabled(true);
241 UpdateToggleBreakpointButton(index);
242}
243
244void GraphicsBreakPointsWidget::OnToggleBreakpointEnabled()
245{
246 QModelIndex index = breakpoint_list->selectionModel()->currentIndex();
247 bool new_state = !(breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool());
248
249 breakpoint_model->setData(index, new_state,
250 BreakPointModel::Role_IsEnabled);
251 UpdateToggleBreakpointButton(index);
252}
253
254void GraphicsBreakPointsWidget::UpdateToggleBreakpointButton(const QModelIndex& index)
255{
256 if (true == breakpoint_model->data(index, BreakPointModel::Role_IsEnabled).toBool()) {
257 toggle_breakpoint_button->setText(tr("Disable"));
258 } else {
259 toggle_breakpoint_button->setText(tr("Enable"));
260 }
261}
diff --git a/src/citra_qt/debugger/graphics_breakpoints.hxx b/src/citra_qt/debugger/graphics_breakpoints.hxx
new file mode 100644
index 000000000..2142c6fa1
--- /dev/null
+++ b/src/citra_qt/debugger/graphics_breakpoints.hxx
@@ -0,0 +1,53 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8
9#include <QAbstractListModel>
10#include <QDockWidget>
11
12#include "video_core/debug_utils/debug_utils.h"
13
14class QLabel;
15class QPushButton;
16class QTreeView;
17
18class BreakPointModel;
19
20class GraphicsBreakPointsWidget : public QDockWidget, Pica::DebugContext::BreakPointObserver {
21 Q_OBJECT
22
23 using Event = Pica::DebugContext::Event;
24
25public:
26 GraphicsBreakPointsWidget(std::shared_ptr<Pica::DebugContext> debug_context,
27 QWidget* parent = nullptr);
28
29 void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override;
30 void OnPicaResume() override;
31
32public slots:
33 void OnBreakPointHit(Pica::DebugContext::Event event, void* data);
34 void OnResumeRequested();
35 void OnResumed();
36 void OnBreakpointSelectionChanged(const QModelIndex&);
37 void OnToggleBreakpointEnabled();
38
39signals:
40 void Resumed();
41 void BreakPointHit(Pica::DebugContext::Event event, void* data);
42 void BreakPointsChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
43
44private:
45 void UpdateToggleBreakpointButton(const QModelIndex& index);
46
47 QLabel* status_text;
48 QPushButton* resume_button;
49 QPushButton* toggle_breakpoint_button;
50
51 BreakPointModel* breakpoint_model;
52 QTreeView* breakpoint_list;
53};
diff --git a/src/citra_qt/debugger/graphics_breakpoints_p.hxx b/src/citra_qt/debugger/graphics_breakpoints_p.hxx
new file mode 100644
index 000000000..bf5daf73d
--- /dev/null
+++ b/src/citra_qt/debugger/graphics_breakpoints_p.hxx
@@ -0,0 +1,38 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <memory>
8
9#include <QAbstractListModel>
10
11#include "video_core/debug_utils/debug_utils.h"
12
13class BreakPointModel : public QAbstractListModel {
14 Q_OBJECT
15
16public:
17 enum {
18 Role_IsEnabled = Qt::UserRole,
19 };
20
21 BreakPointModel(std::shared_ptr<Pica::DebugContext> context, QObject* parent);
22
23 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
24 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
25 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
26 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
27
28 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
29
30public slots:
31 void OnBreakPointHit(Pica::DebugContext::Event event);
32 void OnResumed();
33
34private:
35 std::weak_ptr<Pica::DebugContext> context_weak;
36 bool at_breakpoint;
37 Pica::DebugContext::Event active_breakpoint;
38};
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp
index 71dd166cd..7f97cf143 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.cpp
+++ b/src/citra_qt/debugger/graphics_cmdlists.cpp
@@ -2,30 +2,171 @@
2// Licensed under GPLv2 2// Licensed under GPLv2
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);
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.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 info.address = value;
129 emit UpdatePixmap(ReloadPixmap());
130}
131
132void TextureInfoDockWidget::OnFormatChanged(int value) {
133 info.format = static_cast<Pica::Regs::TextureFormat>(value);
134 emit UpdatePixmap(ReloadPixmap());
135}
136
137void TextureInfoDockWidget::OnWidthChanged(int value) {
138 info.width = value;
139 emit UpdatePixmap(ReloadPixmap());
140}
141
142void TextureInfoDockWidget::OnHeightChanged(int value) {
143 info.height = value;
144 emit UpdatePixmap(ReloadPixmap());
145}
14 146
147void TextureInfoDockWidget::OnStrideChanged(int value) {
148 info.stride = value;
149 emit UpdatePixmap(ReloadPixmap());
15} 150}
16 151
17int GPUCommandListModel::rowCount(const QModelIndex& parent) const 152QPixmap TextureInfoDockWidget::ReloadPixmap() const {
18{ 153 u8* src = Memory::GetPointer(info.address);
154 return QPixmap::fromImage(LoadTexture(src, info));
155}
156
157GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) {
158
159}
160
161int GPUCommandListModel::rowCount(const QModelIndex& parent) const {
19 return pica_trace.writes.size(); 162 return pica_trace.writes.size();
20} 163}
21 164
22int GPUCommandListModel::columnCount(const QModelIndex& parent) const 165int GPUCommandListModel::columnCount(const QModelIndex& parent) const {
23{
24 return 2; 166 return 2;
25} 167}
26 168
27QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const 169QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const {
28{
29 if (!index.isValid()) 170 if (!index.isValid())
30 return QVariant(); 171 return QVariant();
31 172
@@ -36,21 +177,39 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const
36 if (role == Qt::DisplayRole) { 177 if (role == Qt::DisplayRole) {
37 QString content; 178 QString content;
38 if (index.column() == 0) { 179 if (index.column() == 0) {
39 content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str()); 180 QString content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str());
40 content.append(" "); 181 content.append(" ");
182 return content;
41 } else if (index.column() == 1) { 183 } else if (index.column() == 1) {
42 content.append(QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'))); 184 QString content = QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'));
43 content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0'))); 185 content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0')));
186 return content;
44 } 187 }
188 } else if (role == CommandIdRole) {
189 return QVariant::fromValue<int>(cmd.cmd_id.Value());
190 }
45 191
46 return QVariant(content); 192 return QVariant();
193}
194
195QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const {
196 switch(role) {
197 case Qt::DisplayRole:
198 {
199 if (section == 0) {
200 return tr("Command Name");
201 } else if (section == 1) {
202 return tr("Data");
203 }
204
205 break;
206 }
47 } 207 }
48 208
49 return QVariant(); 209 return QVariant();
50} 210}
51 211
52void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) 212void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) {
53{
54 beginResetModel(); 213 beginResetModel();
55 214
56 pica_trace = trace; 215 pica_trace = trace;
@@ -58,38 +217,82 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&
58 endResetModel(); 217 endResetModel();
59} 218}
60 219
220#define COMMAND_IN_RANGE(cmd_id, reg_name) \
221 (cmd_id >= PICA_REG_INDEX(reg_name) && \
222 cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4)
223
224void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) {
225 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
226 if (COMMAND_IN_RANGE(command_id, texture0)) {
227 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0,
228 Pica::registers.texture0_format);
229
230 // TODO: Instead, emit a signal here to be caught by the main window widget.
231 auto main_window = static_cast<QMainWindow*>(parent());
232 main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window));
233 }
234}
235
236void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) {
237 QWidget* new_info_widget;
238
239 const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt();
240 if (COMMAND_IN_RANGE(command_id, texture0)) {
241 u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress());
242 auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0,
243 Pica::registers.texture0_format);
244 new_info_widget = new TextureInfoWidget(src, info);
245 } else {
246 new_info_widget = new QWidget;
247 }
248
249 widget()->layout()->removeWidget(command_info_widget);
250 delete command_info_widget;
251 widget()->layout()->addWidget(new_info_widget);
252 command_info_widget = new_info_widget;
253}
254#undef COMMAND_IN_RANGE
61 255
62GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) 256GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) {
63{ 257 setObjectName("Pica Command List");
64 GPUCommandListModel* model = new GPUCommandListModel(this); 258 GPUCommandListModel* model = new GPUCommandListModel(this);
65 259
66 QWidget* main_widget = new QWidget; 260 QWidget* main_widget = new QWidget;
67 261
68 QTreeView* list_widget = new QTreeView; 262 list_widget = new QTreeView;
69 list_widget->setModel(model); 263 list_widget->setModel(model);
70 list_widget->setFont(QFont("monospace")); 264 list_widget->setFont(QFont("monospace"));
71 list_widget->setRootIsDecorated(false); 265 list_widget->setRootIsDecorated(false);
72 266
73 QPushButton* toggle_tracing = new QPushButton(tr("Start Tracing")); 267 connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)),
268 this, SLOT(SetCommandInfo(const QModelIndex&)));
269 connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)),
270 this, SLOT(OnCommandDoubleClicked(const QModelIndex&)));
271
272 toggle_tracing = new QPushButton(tr("Start Tracing"));
74 273
75 connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); 274 connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing()));
76 connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), 275 connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)),
77 model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); 276 model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&)));
78 277
278 command_info_widget = new QWidget;
279
79 QVBoxLayout* main_layout = new QVBoxLayout; 280 QVBoxLayout* main_layout = new QVBoxLayout;
80 main_layout->addWidget(list_widget); 281 main_layout->addWidget(list_widget);
81 main_layout->addWidget(toggle_tracing); 282 main_layout->addWidget(toggle_tracing);
283 main_layout->addWidget(command_info_widget);
82 main_widget->setLayout(main_layout); 284 main_widget->setLayout(main_layout);
83 285
84 setWidget(main_widget); 286 setWidget(main_widget);
85} 287}
86 288
87void GPUCommandListWidget::OnToggleTracing() 289void GPUCommandListWidget::OnToggleTracing() {
88{
89 if (!Pica::DebugUtils::IsPicaTracing()) { 290 if (!Pica::DebugUtils::IsPicaTracing()) {
90 Pica::DebugUtils::StartPicaTracing(); 291 Pica::DebugUtils::StartPicaTracing();
292 toggle_tracing->setText(tr("Finish Tracing"));
91 } else { 293 } else {
92 pica_trace = Pica::DebugUtils::FinishPicaTracing(); 294 pica_trace = Pica::DebugUtils::FinishPicaTracing();
93 emit TracingFinished(*pica_trace); 295 emit TracingFinished(*pica_trace);
296 toggle_tracing->setText(tr("Start Tracing"));
94 } 297 }
95} 298}
diff --git a/src/citra_qt/debugger/graphics_cmdlists.hxx b/src/citra_qt/debugger/graphics_cmdlists.hxx
index 1523e724f..a459bba64 100644
--- a/src/citra_qt/debugger/graphics_cmdlists.hxx
+++ b/src/citra_qt/debugger/graphics_cmdlists.hxx
@@ -10,16 +10,24 @@
10#include "video_core/gpu_debugger.h" 10#include "video_core/gpu_debugger.h"
11#include "video_core/debug_utils/debug_utils.h" 11#include "video_core/debug_utils/debug_utils.h"
12 12
13class QPushButton;
14class QTreeView;
15
13class GPUCommandListModel : public QAbstractListModel 16class GPUCommandListModel : public QAbstractListModel
14{ 17{
15 Q_OBJECT 18 Q_OBJECT
16 19
17public: 20public:
21 enum {
22 CommandIdRole = Qt::UserRole,
23 };
24
18 GPUCommandListModel(QObject* parent); 25 GPUCommandListModel(QObject* parent);
19 26
20 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 27 int columnCount(const QModelIndex& parent = QModelIndex()) const override;
21 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 28 int rowCount(const QModelIndex& parent = QModelIndex()) const override;
22 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 29 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
30 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
23 31
24public slots: 32public slots:
25 void OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace); 33 void OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace);
@@ -37,10 +45,39 @@ public:
37 45
38public slots: 46public slots:
39 void OnToggleTracing(); 47 void OnToggleTracing();
48 void OnCommandDoubleClicked(const QModelIndex&);
49
50 void SetCommandInfo(const QModelIndex&);
40 51
41signals: 52signals:
42 void TracingFinished(const Pica::DebugUtils::PicaTrace&); 53 void TracingFinished(const Pica::DebugUtils::PicaTrace&);
43 54
44private: 55private:
45 std::unique_ptr<Pica::DebugUtils::PicaTrace> pica_trace; 56 std::unique_ptr<Pica::DebugUtils::PicaTrace> pica_trace;
57
58 QTreeView* list_widget;
59 QWidget* command_info_widget;
60 QPushButton* toggle_tracing;
61};
62
63class TextureInfoDockWidget : public QDockWidget {
64 Q_OBJECT
65
66public:
67 TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr);
68
69signals:
70 void UpdatePixmap(const QPixmap& pixmap);
71
72private slots:
73 void OnAddressChanged(qint64 value);
74 void OnFormatChanged(int value);
75 void OnWidthChanged(int value);
76 void OnHeightChanged(int value);
77 void OnStrideChanged(int value);
78
79private:
80 QPixmap ReloadPixmap() const;
81
82 Pica::DebugUtils::TextureInfo info;
46}; 83};
diff --git a/src/citra_qt/debugger/graphics_framebuffer.cpp b/src/citra_qt/debugger/graphics_framebuffer.cpp
new file mode 100644
index 000000000..ac47f298d
--- /dev/null
+++ b/src/citra_qt/debugger/graphics_framebuffer.cpp
@@ -0,0 +1,282 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <QBoxLayout>
6#include <QComboBox>
7#include <QDebug>
8#include <QLabel>
9#include <QMetaType>
10#include <QPushButton>
11#include <QSpinBox>
12
13#include "video_core/pica.h"
14
15#include "graphics_framebuffer.hxx"
16
17#include "util/spinbox.hxx"
18
19BreakPointObserverDock::BreakPointObserverDock(std::shared_ptr<Pica::DebugContext> debug_context,
20 const QString& title, QWidget* parent)
21 : QDockWidget(title, parent), BreakPointObserver(debug_context)
22{
23 qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event");
24
25 connect(this, SIGNAL(Resumed()), this, SLOT(OnResumed()));
26
27 // NOTE: This signal is emitted from a non-GUI thread, but connect() takes
28 // care of delaying its handling to the GUI thread.
29 connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event,void*)),
30 this, SLOT(OnBreakPointHit(Pica::DebugContext::Event,void*)),
31 Qt::BlockingQueuedConnection);
32}
33
34void BreakPointObserverDock::OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data)
35{
36 emit BreakPointHit(event, data);
37}
38
39void BreakPointObserverDock::OnPicaResume()
40{
41 emit Resumed();
42}
43
44
45GraphicsFramebufferWidget::GraphicsFramebufferWidget(std::shared_ptr<Pica::DebugContext> debug_context,
46 QWidget* parent)
47 : BreakPointObserverDock(debug_context, tr("Pica Framebuffer"), parent),
48 framebuffer_source(Source::PicaTarget)
49{
50 setObjectName("PicaFramebuffer");
51
52 framebuffer_source_list = new QComboBox;
53 framebuffer_source_list->addItem(tr("Active Render Target"));
54 framebuffer_source_list->addItem(tr("Custom"));
55 framebuffer_source_list->setCurrentIndex(static_cast<int>(framebuffer_source));
56
57 framebuffer_address_control = new CSpinBox;
58 framebuffer_address_control->SetBase(16);
59 framebuffer_address_control->SetRange(0, 0xFFFFFFFF);
60 framebuffer_address_control->SetPrefix("0x");
61
62 framebuffer_width_control = new QSpinBox;
63 framebuffer_width_control->setMinimum(1);
64 framebuffer_width_control->setMaximum(std::numeric_limits<int>::max()); // TODO: Find actual maximum
65
66 framebuffer_height_control = new QSpinBox;
67 framebuffer_height_control->setMinimum(1);
68 framebuffer_height_control->setMaximum(std::numeric_limits<int>::max()); // TODO: Find actual maximum
69
70 framebuffer_format_control = new QComboBox;
71 framebuffer_format_control->addItem(tr("RGBA8"));
72 framebuffer_format_control->addItem(tr("RGB8"));
73 framebuffer_format_control->addItem(tr("RGBA5551"));
74 framebuffer_format_control->addItem(tr("RGB565"));
75 framebuffer_format_control->addItem(tr("RGBA4"));
76
77 // TODO: This QLabel should shrink the image to the available space rather than just expanding...
78 framebuffer_picture_label = new QLabel;
79
80 auto enlarge_button = new QPushButton(tr("Enlarge"));
81
82 // Connections
83 connect(this, SIGNAL(Update()), this, SLOT(OnUpdate()));
84 connect(framebuffer_source_list, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFramebufferSourceChanged(int)));
85 connect(framebuffer_address_control, SIGNAL(ValueChanged(qint64)), this, SLOT(OnFramebufferAddressChanged(qint64)));
86 connect(framebuffer_width_control, SIGNAL(valueChanged(int)), this, SLOT(OnFramebufferWidthChanged(int)));
87 connect(framebuffer_height_control, SIGNAL(valueChanged(int)), this, SLOT(OnFramebufferHeightChanged(int)));
88 connect(framebuffer_format_control, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFramebufferFormatChanged(int)));
89
90 auto main_widget = new QWidget;
91 auto main_layout = new QVBoxLayout;
92 {
93 auto sub_layout = new QHBoxLayout;
94 sub_layout->addWidget(new QLabel(tr("Source:")));
95 sub_layout->addWidget(framebuffer_source_list);
96 main_layout->addLayout(sub_layout);
97 }
98 {
99 auto sub_layout = new QHBoxLayout;
100 sub_layout->addWidget(new QLabel(tr("Virtual Address:")));
101 sub_layout->addWidget(framebuffer_address_control);
102 main_layout->addLayout(sub_layout);
103 }
104 {
105 auto sub_layout = new QHBoxLayout;
106 sub_layout->addWidget(new QLabel(tr("Width:")));
107 sub_layout->addWidget(framebuffer_width_control);
108 main_layout->addLayout(sub_layout);
109 }
110 {
111 auto sub_layout = new QHBoxLayout;
112 sub_layout->addWidget(new QLabel(tr("Height:")));
113 sub_layout->addWidget(framebuffer_height_control);
114 main_layout->addLayout(sub_layout);
115 }
116 {
117 auto sub_layout = new QHBoxLayout;
118 sub_layout->addWidget(new QLabel(tr("Format:")));
119 sub_layout->addWidget(framebuffer_format_control);
120 main_layout->addLayout(sub_layout);
121 }
122 main_layout->addWidget(framebuffer_picture_label);
123 main_layout->addWidget(enlarge_button);
124 main_widget->setLayout(main_layout);
125 setWidget(main_widget);
126
127 // Load current data - TODO: Make sure this works when emulation is not running
128 emit Update();
129 widget()->setEnabled(false); // TODO: Only enable if currently at breakpoint
130}
131
132void GraphicsFramebufferWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data)
133{
134 emit Update();
135 widget()->setEnabled(true);
136}
137
138void GraphicsFramebufferWidget::OnResumed()
139{
140 widget()->setEnabled(false);
141}
142
143void GraphicsFramebufferWidget::OnFramebufferSourceChanged(int new_value)
144{
145 framebuffer_source = static_cast<Source>(new_value);
146 emit Update();
147}
148
149void GraphicsFramebufferWidget::OnFramebufferAddressChanged(qint64 new_value)
150{
151 if (framebuffer_address != new_value) {
152 framebuffer_address = static_cast<unsigned>(new_value);
153
154 framebuffer_source_list->setCurrentIndex(static_cast<int>(Source::Custom));
155 emit Update();
156 }
157}
158
159void GraphicsFramebufferWidget::OnFramebufferWidthChanged(int new_value)
160{
161 if (framebuffer_width != new_value) {
162 framebuffer_width = new_value;
163
164 framebuffer_source_list->setCurrentIndex(static_cast<int>(Source::Custom));
165 emit Update();
166 }
167}
168
169void GraphicsFramebufferWidget::OnFramebufferHeightChanged(int new_value)
170{
171 if (framebuffer_height != new_value) {
172 framebuffer_height = new_value;
173
174 framebuffer_source_list->setCurrentIndex(static_cast<int>(Source::Custom));
175 emit Update();
176 }
177}
178
179void GraphicsFramebufferWidget::OnFramebufferFormatChanged(int new_value)
180{
181 if (framebuffer_format != static_cast<Format>(new_value)) {
182 framebuffer_format = static_cast<Format>(new_value);
183
184 framebuffer_source_list->setCurrentIndex(static_cast<int>(Source::Custom));
185 emit Update();
186 }
187}
188
189void GraphicsFramebufferWidget::OnUpdate()
190{
191 QPixmap pixmap;
192
193 switch (framebuffer_source) {
194 case Source::PicaTarget:
195 {
196 // TODO: Store a reference to the registers in the debug context instead of accessing them directly...
197
198 auto framebuffer = Pica::registers.framebuffer;
199 using Framebuffer = decltype(framebuffer);
200
201 framebuffer_address = framebuffer.GetColorBufferAddress();
202 framebuffer_width = framebuffer.GetWidth();
203 framebuffer_height = framebuffer.GetHeight();
204 framebuffer_format = static_cast<Format>(framebuffer.color_format);
205
206 break;
207 }
208
209 case Source::Custom:
210 {
211 // Keep user-specified values
212 break;
213 }
214
215 default:
216 qDebug() << "Unknown framebuffer source " << static_cast<int>(framebuffer_source);
217 break;
218 }
219
220 // TODO: Implement a good way to visualize alpha components!
221 // TODO: Unify this decoding code with the texture decoder
222 switch (framebuffer_format) {
223 case Format::RGBA8:
224 {
225 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
226 u32* color_buffer = (u32*)Memory::GetPointer(framebuffer_address);
227 for (int y = 0; y < framebuffer_height; ++y) {
228 for (int x = 0; x < framebuffer_width; ++x) {
229 u32 value = *(color_buffer + x + y * framebuffer_width);
230
231 decoded_image.setPixel(x, y, qRgba((value >> 16) & 0xFF, (value >> 8) & 0xFF, value & 0xFF, 255/*value >> 24*/));
232 }
233 }
234 pixmap = QPixmap::fromImage(decoded_image);
235 break;
236 }
237
238 case Format::RGB8:
239 {
240 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
241 u8* color_buffer = Memory::GetPointer(framebuffer_address);
242 for (int y = 0; y < framebuffer_height; ++y) {
243 for (int x = 0; x < framebuffer_width; ++x) {
244 u8* pixel_pointer = color_buffer + x * 3 + y * 3 * framebuffer_width;
245
246 decoded_image.setPixel(x, y, qRgba(pixel_pointer[0], pixel_pointer[1], pixel_pointer[2], 255/*value >> 24*/));
247 }
248 }
249 pixmap = QPixmap::fromImage(decoded_image);
250 break;
251 }
252
253 case Format::RGBA5551:
254 {
255 QImage decoded_image(framebuffer_width, framebuffer_height, QImage::Format_ARGB32);
256 u32* color_buffer = (u32*)Memory::GetPointer(framebuffer_address);
257 for (int y = 0; y < framebuffer_height; ++y) {
258 for (int x = 0; x < framebuffer_width; ++x) {
259 u16 value = *(u16*)(((u8*)color_buffer) + x * 2 + y * framebuffer_width * 2);
260 u8 r = (value >> 11) & 0x1F;
261 u8 g = (value >> 6) & 0x1F;
262 u8 b = (value >> 1) & 0x1F;
263 u8 a = value & 1;
264
265 decoded_image.setPixel(x, y, qRgba(r, g, b, 255/*a*/));
266 }
267 }
268 pixmap = QPixmap::fromImage(decoded_image);
269 break;
270 }
271
272 default:
273 qDebug() << "Unknown fb color format " << static_cast<int>(framebuffer_format);
274 break;
275 }
276
277 framebuffer_address_control->SetValue(framebuffer_address);
278 framebuffer_width_control->setValue(framebuffer_width);
279 framebuffer_height_control->setValue(framebuffer_height);
280 framebuffer_format_control->setCurrentIndex(static_cast<int>(framebuffer_format));
281 framebuffer_picture_label->setPixmap(pixmap);
282}
diff --git a/src/citra_qt/debugger/graphics_framebuffer.hxx b/src/citra_qt/debugger/graphics_framebuffer.hxx
new file mode 100644
index 000000000..1151ee7a1
--- /dev/null
+++ b/src/citra_qt/debugger/graphics_framebuffer.hxx
@@ -0,0 +1,92 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <QDockWidget>
8
9#include "video_core/debug_utils/debug_utils.h"
10
11class QComboBox;
12class QLabel;
13class QSpinBox;
14
15class CSpinBox;
16
17// Utility class which forwards calls to OnPicaBreakPointHit and OnPicaResume to public slots.
18// This is because the Pica breakpoint callbacks are called from a non-GUI thread, while
19// the widget usually wants to perform reactions in the GUI thread.
20class BreakPointObserverDock : public QDockWidget, Pica::DebugContext::BreakPointObserver {
21 Q_OBJECT
22
23public:
24 BreakPointObserverDock(std::shared_ptr<Pica::DebugContext> debug_context, const QString& title,
25 QWidget* parent = nullptr);
26
27 void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override;
28 void OnPicaResume() override;
29
30private slots:
31 virtual void OnBreakPointHit(Pica::DebugContext::Event event, void* data) = 0;
32 virtual void OnResumed() = 0;
33
34signals:
35 void Resumed();
36 void BreakPointHit(Pica::DebugContext::Event event, void* data);
37};
38
39class GraphicsFramebufferWidget : public BreakPointObserverDock {
40 Q_OBJECT
41
42 using Event = Pica::DebugContext::Event;
43
44 enum class Source {
45 PicaTarget = 0,
46 Custom = 1,
47
48 // TODO: Add GPU framebuffer sources!
49 };
50
51 enum class Format {
52 RGBA8 = 0,
53 RGB8 = 1,
54 RGBA5551 = 2,
55 RGB565 = 3,
56 RGBA4 = 4,
57 };
58
59public:
60 GraphicsFramebufferWidget(std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent = nullptr);
61
62public slots:
63 void OnFramebufferSourceChanged(int new_value);
64 void OnFramebufferAddressChanged(qint64 new_value);
65 void OnFramebufferWidthChanged(int new_value);
66 void OnFramebufferHeightChanged(int new_value);
67 void OnFramebufferFormatChanged(int new_value);
68 void OnUpdate();
69
70private slots:
71 void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override;
72 void OnResumed() override;
73
74signals:
75 void Update();
76
77private:
78
79 QComboBox* framebuffer_source_list;
80 CSpinBox* framebuffer_address_control;
81 QSpinBox* framebuffer_width_control;
82 QSpinBox* framebuffer_height_control;
83 QComboBox* framebuffer_format_control;
84
85 QLabel* framebuffer_picture_label;
86
87 Source framebuffer_source;
88 unsigned framebuffer_address;
89 unsigned framebuffer_width;
90 unsigned framebuffer_height;
91 Format framebuffer_format;
92};
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 0701decef..b4e3ad964 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -20,7 +20,9 @@
20#include "debugger/callstack.hxx" 20#include "debugger/callstack.hxx"
21#include "debugger/ramview.hxx" 21#include "debugger/ramview.hxx"
22#include "debugger/graphics.hxx" 22#include "debugger/graphics.hxx"
23#include "debugger/graphics_breakpoints.hxx"
23#include "debugger/graphics_cmdlists.hxx" 24#include "debugger/graphics_cmdlists.hxx"
25#include "debugger/graphics_framebuffer.hxx"
24 26
25#include "core/settings.h" 27#include "core/settings.h"
26#include "core/system.h" 28#include "core/system.h"
@@ -36,6 +38,8 @@ GMainWindow::GMainWindow()
36{ 38{
37 LogManager::Init(); 39 LogManager::Init();
38 40
41 Pica::g_debug_context = Pica::DebugContext::Construct();
42
39 Config config; 43 Config config;
40 44
41 if (!Settings::values.enable_log) 45 if (!Settings::values.enable_log)
@@ -67,12 +71,22 @@ GMainWindow::GMainWindow()
67 addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget); 71 addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget);
68 graphicsCommandsWidget->hide(); 72 graphicsCommandsWidget->hide();
69 73
74 auto graphicsBreakpointsWidget = new GraphicsBreakPointsWidget(Pica::g_debug_context, this);
75 addDockWidget(Qt::RightDockWidgetArea, graphicsBreakpointsWidget);
76 graphicsBreakpointsWidget->hide();
77
78 auto graphicsFramebufferWidget = new GraphicsFramebufferWidget(Pica::g_debug_context, this);
79 addDockWidget(Qt::RightDockWidgetArea, graphicsFramebufferWidget);
80 graphicsFramebufferWidget->hide();
81
70 QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging")); 82 QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging"));
71 debug_menu->addAction(disasmWidget->toggleViewAction()); 83 debug_menu->addAction(disasmWidget->toggleViewAction());
72 debug_menu->addAction(registersWidget->toggleViewAction()); 84 debug_menu->addAction(registersWidget->toggleViewAction());
73 debug_menu->addAction(callstackWidget->toggleViewAction()); 85 debug_menu->addAction(callstackWidget->toggleViewAction());
74 debug_menu->addAction(graphicsWidget->toggleViewAction()); 86 debug_menu->addAction(graphicsWidget->toggleViewAction());
75 debug_menu->addAction(graphicsCommandsWidget->toggleViewAction()); 87 debug_menu->addAction(graphicsCommandsWidget->toggleViewAction());
88 debug_menu->addAction(graphicsBreakpointsWidget->toggleViewAction());
89 debug_menu->addAction(graphicsFramebufferWidget->toggleViewAction());
76 90
77 // Set default UI state 91 // Set default UI state
78 // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half 92 // geometry: 55% of the window contents are in the upper screen half, 45% in the lower half
@@ -133,6 +147,8 @@ GMainWindow::~GMainWindow()
133 // will get automatically deleted otherwise 147 // will get automatically deleted otherwise
134 if (render_window->parent() == nullptr) 148 if (render_window->parent() == nullptr)
135 delete render_window; 149 delete render_window;
150
151 Pica::g_debug_context.reset();
136} 152}
137 153
138void GMainWindow::BootGame(std::string filename) 154void GMainWindow::BootGame(std::string filename)
diff --git a/src/citra_qt/util/spinbox.cpp b/src/citra_qt/util/spinbox.cpp
new file mode 100644
index 000000000..80dc67d7d
--- /dev/null
+++ b/src/citra_qt/util/spinbox.cpp
@@ -0,0 +1,303 @@
1// Licensed under GPLv2+
2// Refer to the license.txt file included.
3
4
5// Copyright 2014 Tony Wasserka
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are met:
10//
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// * Neither the name of the owner nor the names of its contributors may
17// be used to endorse or promote products derived from this software
18// without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#include <QLineEdit>
33#include <QRegExpValidator>
34
35#include "common/log.h"
36
37#include "spinbox.hxx"
38
39CSpinBox::CSpinBox(QWidget* parent) : QAbstractSpinBox(parent), base(10), min_value(-100), max_value(100), value(0), num_digits(0)
40{
41 // TODO: Might be nice to not immediately call the slot.
42 // Think of an address that is being replaced by a different one, in which case a lot
43 // invalid intermediate addresses would be read from during editing.
44 connect(lineEdit(), SIGNAL(textEdited(QString)), this, SLOT(OnEditingFinished()));
45
46 UpdateText();
47}
48
49void CSpinBox::SetValue(qint64 val)
50{
51 auto old_value = value;
52 value = std::max(std::min(val, max_value), min_value);
53
54 if (old_value != value) {
55 UpdateText();
56 emit ValueChanged(value);
57 }
58}
59
60void CSpinBox::SetRange(qint64 min, qint64 max)
61{
62 min_value = min;
63 max_value = max;
64
65 SetValue(value);
66 UpdateText();
67}
68
69void CSpinBox::stepBy(int steps)
70{
71 auto new_value = value;
72 // Scale number of steps by the currently selected digit
73 // TODO: Move this code elsewhere and enable it.
74 // TODO: Support for num_digits==0, too
75 // TODO: Support base!=16, too
76 // TODO: Make the cursor not jump back to the end of the line...
77 /*if (base == 16 && num_digits > 0) {
78 int digit = num_digits - (lineEdit()->cursorPosition() - prefix.length()) - 1;
79 digit = std::max(0, std::min(digit, num_digits - 1));
80 steps <<= digit * 4;
81 }*/
82
83 // Increment "new_value" by "steps", and perform annoying overflow checks, too.
84 if (steps < 0 && new_value + steps > new_value) {
85 new_value = std::numeric_limits<qint64>::min();
86 } else if (steps > 0 && new_value + steps < new_value) {
87 new_value = std::numeric_limits<qint64>::max();
88 } else {
89 new_value += steps;
90 }
91
92 SetValue(new_value);
93 UpdateText();
94}
95
96QAbstractSpinBox::StepEnabled CSpinBox::stepEnabled() const
97{
98 StepEnabled ret = StepNone;
99
100 if (value > min_value)
101 ret |= StepDownEnabled;
102
103 if (value < max_value)
104 ret |= StepUpEnabled;
105
106 return ret;
107}
108
109void CSpinBox::SetBase(int base)
110{
111 this->base = base;
112
113 UpdateText();
114}
115
116void CSpinBox::SetNumDigits(int num_digits)
117{
118 this->num_digits = num_digits;
119
120 UpdateText();
121}
122
123void CSpinBox::SetPrefix(const QString& prefix)
124{
125 this->prefix = prefix;
126
127 UpdateText();
128}
129
130void CSpinBox::SetSuffix(const QString& suffix)
131{
132 this->suffix = suffix;
133
134 UpdateText();
135}
136
137static QString StringToInputMask(const QString& input) {
138 QString mask = input;
139
140 // ... replace any special characters by their escaped counterparts ...
141 mask.replace("\\", "\\\\");
142 mask.replace("A", "\\A");
143 mask.replace("a", "\\a");
144 mask.replace("N", "\\N");
145 mask.replace("n", "\\n");
146 mask.replace("X", "\\X");
147 mask.replace("x", "\\x");
148 mask.replace("9", "\\9");
149 mask.replace("0", "\\0");
150 mask.replace("D", "\\D");
151 mask.replace("d", "\\d");
152 mask.replace("#", "\\#");
153 mask.replace("H", "\\H");
154 mask.replace("h", "\\h");
155 mask.replace("B", "\\B");
156 mask.replace("b", "\\b");
157 mask.replace(">", "\\>");
158 mask.replace("<", "\\<");
159 mask.replace("!", "\\!");
160
161 return mask;
162}
163
164void CSpinBox::UpdateText()
165{
166 // If a fixed number of digits is used, we put the line edit in insertion mode by setting an
167 // input mask.
168 QString mask;
169 if (num_digits != 0) {
170 mask += StringToInputMask(prefix);
171
172 // For base 10 and negative range, demand a single sign character
173 if (HasSign())
174 mask += "X"; // identified as "-" or "+" in the validator
175
176 // Uppercase digits greater than 9.
177 mask += ">";
178
179 // The greatest signed 64-bit number has 19 decimal digits.
180 // TODO: Could probably make this more generic with some logarithms.
181 // For reference, unsigned 64-bit can have up to 20 decimal digits.
182 int digits = (num_digits != 0) ? num_digits
183 : (base == 16) ? 16
184 : (base == 10) ? 19
185 : 0xFF; // fallback case...
186
187 // Match num_digits digits
188 // Digits irrelevant to the chosen number base are filtered in the validator
189 mask += QString("H").repeated(std::max(num_digits, 1));
190
191 // Switch off case conversion
192 mask += "!";
193
194 mask += StringToInputMask(suffix);
195 }
196 lineEdit()->setInputMask(mask);
197
198 // Set new text without changing the cursor position. This will cause the cursor to briefly
199 // appear at the end of the line and then to jump back to its original position. That's
200 // a bit ugly, but better than having setText() move the cursor permanently all the time.
201 int cursor_position = lineEdit()->cursorPosition();
202 lineEdit()->setText(TextFromValue());
203 lineEdit()->setCursorPosition(cursor_position);
204}
205
206QString CSpinBox::TextFromValue()
207{
208 return prefix
209 + QString(HasSign() ? ((value < 0) ? "-" : "+") : "")
210 + QString("%1").arg(abs(value), num_digits, base, QLatin1Char('0')).toUpper()
211 + suffix;
212}
213
214qint64 CSpinBox::ValueFromText()
215{
216 unsigned strpos = prefix.length();
217
218 QString num_string = text().mid(strpos, text().length() - strpos - suffix.length());
219 return num_string.toLongLong(nullptr, base);
220}
221
222bool CSpinBox::HasSign() const
223{
224 return base == 10 && min_value < 0;
225}
226
227void CSpinBox::OnEditingFinished()
228{
229 // Only update for valid input
230 QString input = lineEdit()->text();
231 int pos = 0;
232 if (QValidator::Acceptable == validate(input, pos))
233 SetValue(ValueFromText());
234}
235
236QValidator::State CSpinBox::validate(QString& input, int& pos) const
237{
238 if (!prefix.isEmpty() && input.left(prefix.length()) != prefix)
239 return QValidator::Invalid;
240
241 unsigned strpos = prefix.length();
242
243 // Empty "numbers" allowed as intermediate values
244 if (strpos >= input.length() - HasSign() - suffix.length())
245 return QValidator::Intermediate;
246
247 _dbg_assert_(GUI, base <= 10 || base == 16);
248 QString regexp;
249
250 // Demand sign character for negative ranges
251 if (HasSign())
252 regexp += "[+\\-]";
253
254 // Match digits corresponding to the chosen number base.
255 regexp += QString("[0-%1").arg(std::min(base, 9));
256 if (base == 16) {
257 regexp += "a-fA-F";
258 }
259 regexp += "]";
260
261 // Specify number of digits
262 if (num_digits > 0) {
263 regexp += QString("{%1}").arg(num_digits);
264 } else {
265 regexp += "+";
266 }
267
268 // Match string
269 QRegExp num_regexp(regexp);
270 int num_pos = strpos;
271 QString sub_input = input.mid(strpos, input.length() - strpos - suffix.length());
272
273 if (!num_regexp.exactMatch(sub_input) && num_regexp.matchedLength() == 0)
274 return QValidator::Invalid;
275
276 sub_input = sub_input.left(num_regexp.matchedLength());
277 bool ok;
278 qint64 val = sub_input.toLongLong(&ok, base);
279
280 if (!ok)
281 return QValidator::Invalid;
282
283 // Outside boundaries => don't accept
284 if (val < min_value || val > max_value)
285 return QValidator::Invalid;
286
287 // Make sure we are actually at the end of this string...
288 strpos += num_regexp.matchedLength();
289
290 if (!suffix.isEmpty() && input.mid(strpos) != suffix) {
291 return QValidator::Invalid;
292 } else {
293 strpos += suffix.length();
294 }
295
296 if (strpos != input.length())
297 return QValidator::Invalid;
298
299 // At this point we can say for sure that the input is fine. Let's fix it up a bit though
300 input.replace(num_pos, sub_input.length(), sub_input.toUpper());
301
302 return QValidator::Acceptable;
303}
diff --git a/src/citra_qt/util/spinbox.hxx b/src/citra_qt/util/spinbox.hxx
new file mode 100644
index 000000000..68f5b9894
--- /dev/null
+++ b/src/citra_qt/util/spinbox.hxx
@@ -0,0 +1,88 @@
1// Licensed under GPLv2+
2// Refer to the license.txt file included.
3
4
5// Copyright 2014 Tony Wasserka
6// All rights reserved.
7//
8// Redistribution and use in source and binary forms, with or without
9// modification, are permitted provided that the following conditions are met:
10//
11// * Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// * Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// * Neither the name of the owner nor the names of its contributors may
17// be used to endorse or promote products derived from this software
18// without specific prior written permission.
19//
20// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33#pragma once
34
35#include <QAbstractSpinBox>
36#include <QtGlobal>
37
38class QVariant;
39
40/**
41 * A custom spin box widget with enhanced functionality over Qt's QSpinBox
42 */
43class CSpinBox : public QAbstractSpinBox {
44 Q_OBJECT
45
46public:
47 CSpinBox(QWidget* parent = nullptr);
48
49 void stepBy(int steps) override;
50 StepEnabled stepEnabled() const override;
51
52 void SetValue(qint64 val);
53
54 void SetRange(qint64 min, qint64 max);
55
56 void SetBase(int base);
57
58 void SetPrefix(const QString& prefix);
59 void SetSuffix(const QString& suffix);
60
61 void SetNumDigits(int num_digits);
62
63 QValidator::State validate(QString& input, int& pos) const override;
64
65signals:
66 void ValueChanged(qint64 val);
67
68private slots:
69 void OnEditingFinished();
70
71private:
72 void UpdateText();
73
74 bool HasSign() const;
75
76 QString TextFromValue();
77 qint64 ValueFromText();
78
79 qint64 min_value, max_value;
80
81 qint64 value;
82
83 QString prefix, suffix;
84
85 int base;
86
87 int num_digits;
88};
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 1139dc3b8..db041780a 100644
--- a/src/common/common_funcs.h
+++ b/src/common/common_funcs.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common_types.h"
8
7#ifdef _WIN32 9#ifdef _WIN32
8#define SLEEP(x) Sleep(x) 10#define SLEEP(x) Sleep(x)
9#else 11#else
@@ -37,6 +39,8 @@ template<> struct CompileTimeAssert<true> {};
37#include <sys/endian.h> 39#include <sys/endian.h>
38#endif 40#endif
39 41
42#include "common_types.h"
43
40// go to debugger mode 44// go to debugger mode
41 #ifdef GEKKO 45 #ifdef GEKKO
42 #define Crash() 46 #define Crash()
@@ -73,6 +77,8 @@ inline u64 _rotr64(u64 x, unsigned int shift){
73} 77}
74 78
75#else // WIN32 79#else // WIN32
80#include <locale.h>
81
76// Function Cross-Compatibility 82// Function Cross-Compatibility
77 #define strcasecmp _stricmp 83 #define strcasecmp _stricmp
78 #define strncasecmp _strnicmp 84 #define strncasecmp _strnicmp
diff --git a/src/common/log.h b/src/common/log.h
index 14ad98c08..ff0295cb0 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -4,6 +4,9 @@
4 4
5#pragma once 5#pragma once
6 6
7#include "common/common_funcs.h"
8#include "common/msg_handler.h"
9
7#ifndef LOGGING 10#ifndef LOGGING
8#define LOGGING 11#define LOGGING
9#endif 12#endif
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 8a6ba2560..298b04c51 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -34,6 +34,9 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
34 u32 old_value = registers[id]; 34 u32 old_value = registers[id];
35 registers[id] = (old_value & ~mask) | (value & mask); 35 registers[id] = (old_value & ~mask) | (value & mask);
36 36
37 if (g_debug_context)
38 g_debug_context->OnEvent(DebugContext::Event::CommandLoaded, reinterpret_cast<void*>(&id));
39
37 DebugUtils::OnPicaRegWrite(id, registers[id]); 40 DebugUtils::OnPicaRegWrite(id, registers[id]);
38 41
39 switch(id) { 42 switch(id) {
@@ -43,6 +46,9 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
43 { 46 {
44 DebugUtils::DumpTevStageConfig(registers.GetTevStages()); 47 DebugUtils::DumpTevStageConfig(registers.GetTevStages());
45 48
49 if (g_debug_context)
50 g_debug_context->OnEvent(DebugContext::Event::IncomingPrimitiveBatch, nullptr);
51
46 const auto& attribute_config = registers.vertex_attributes; 52 const auto& attribute_config = registers.vertex_attributes;
47 const u8* const base_address = Memory::GetPointer(attribute_config.GetBaseAddress()); 53 const u8* const base_address = Memory::GetPointer(attribute_config.GetBaseAddress());
48 54
@@ -132,6 +138,10 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
132 clipper_primitive_assembler.SubmitVertex(output, Clipper::ProcessTriangle); 138 clipper_primitive_assembler.SubmitVertex(output, Clipper::ProcessTriangle);
133 } 139 }
134 geometry_dumper.Dump(); 140 geometry_dumper.Dump();
141
142 if (g_debug_context)
143 g_debug_context->OnEvent(DebugContext::Event::FinishedPrimitiveBatch, nullptr);
144
135 break; 145 break;
136 } 146 }
137 147
@@ -229,6 +239,9 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
229 default: 239 default:
230 break; 240 break;
231 } 241 }
242
243 if (g_debug_context)
244 g_debug_context->OnEvent(DebugContext::Event::CommandProcessed, reinterpret_cast<void*>(&id));
232} 245}
233 246
234static std::ptrdiff_t ExecuteCommandBlock(const u32* first_command_word) { 247static std::ptrdiff_t ExecuteCommandBlock(const u32* first_command_word) {
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 8a5f11424..71b03f31c 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -3,6 +3,8 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm> 5#include <algorithm>
6#include <condition_variable>
7#include <list>
6#include <map> 8#include <map>
7#include <fstream> 9#include <fstream>
8#include <mutex> 10#include <mutex>
@@ -12,14 +14,56 @@
12#include <png.h> 14#include <png.h>
13#endif 15#endif
14 16
17#include "common/log.h"
15#include "common/file_util.h" 18#include "common/file_util.h"
16 19
20#include "video_core/math.h"
17#include "video_core/pica.h" 21#include "video_core/pica.h"
18 22
19#include "debug_utils.h" 23#include "debug_utils.h"
20 24
21namespace Pica { 25namespace Pica {
22 26
27void DebugContext::OnEvent(Event event, void* data) {
28 if (!breakpoints[event].enabled)
29 return;
30
31 {
32 std::unique_lock<std::mutex> lock(breakpoint_mutex);
33
34 // TODO: Should stop the CPU thread here once we multithread emulation.
35
36 active_breakpoint = event;
37 at_breakpoint = true;
38
39 // Tell all observers that we hit a breakpoint
40 for (auto& breakpoint_observer : breakpoint_observers) {
41 breakpoint_observer->OnPicaBreakPointHit(event, data);
42 }
43
44 // Wait until another thread tells us to Resume()
45 resume_from_breakpoint.wait(lock, [&]{ return !at_breakpoint; });
46 }
47}
48
49void DebugContext::Resume() {
50 {
51 std::unique_lock<std::mutex> lock(breakpoint_mutex);
52
53 // Tell all observers that we are about to resume
54 for (auto& breakpoint_observer : breakpoint_observers) {
55 breakpoint_observer->OnPicaResume();
56 }
57
58 // Resume the waiting thread (i.e. OnEvent())
59 at_breakpoint = false;
60 }
61
62 resume_from_breakpoint.notify_one();
63}
64
65std::shared_ptr<DebugContext> g_debug_context; // TODO: Get rid of this global
66
23namespace DebugUtils { 67namespace DebugUtils {
24 68
25void GeometryDumper::AddTriangle(Vertex& v0, Vertex& v1, Vertex& v2) { 69void GeometryDumper::AddTriangle(Vertex& v0, Vertex& v1, Vertex& v2) {
@@ -312,6 +356,42 @@ std::unique_ptr<PicaTrace> FinishPicaTracing()
312 return std::move(ret); 356 return std::move(ret);
313} 357}
314 358
359const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) {
360 _dbg_assert_(GPU, info.format == Pica::Regs::TextureFormat::RGB8);
361
362 // Cf. rasterizer code for an explanation of this algorithm.
363 int texel_index_within_tile = 0;
364 for (int block_size_index = 0; block_size_index < 3; ++block_size_index) {
365 int sub_tile_width = 1 << block_size_index;
366 int sub_tile_height = 1 << block_size_index;
367
368 int sub_tile_index = (x & sub_tile_width) << block_size_index;
369 sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index);
370 texel_index_within_tile += sub_tile_index;
371 }
372
373 const int block_width = 8;
374 const int block_height = 8;
375
376 int coarse_x = (x / block_width) * block_width;
377 int coarse_y = (y / block_height) * block_height;
378
379 const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3;
380 return { source_ptr[2], source_ptr[1], source_ptr[0], 255 };
381}
382
383TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config,
384 const Regs::TextureFormat& format)
385{
386 TextureInfo info;
387 info.address = config.GetPhysicalAddress();
388 info.width = config.width;
389 info.height = config.height;
390 info.format = format;
391 info.stride = Pica::Regs::BytesPerPixel(info.format) * info.width;
392 return info;
393}
394
315void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { 395void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
316 // NOTE: Permanently enabling this just trashes hard disks for no reason. 396 // NOTE: Permanently enabling this just trashes hard disks for no reason.
317 // Hence, this is currently disabled. 397 // Hence, this is currently disabled.
@@ -377,27 +457,15 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) {
377 buf = new u8[row_stride * texture_config.height]; 457 buf = new u8[row_stride * texture_config.height];
378 for (unsigned y = 0; y < texture_config.height; ++y) { 458 for (unsigned y = 0; y < texture_config.height; ++y) {
379 for (unsigned x = 0; x < texture_config.width; ++x) { 459 for (unsigned x = 0; x < texture_config.width; ++x) {
380 // Cf. rasterizer code for an explanation of this algorithm. 460 TextureInfo info;
381 int texel_index_within_tile = 0; 461 info.width = texture_config.width;
382 for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { 462 info.height = texture_config.height;
383 int sub_tile_width = 1 << block_size_index; 463 info.stride = row_stride;
384 int sub_tile_height = 1 << block_size_index; 464 info.format = registers.texture0_format;
385 465 Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info);
386 int sub_tile_index = (x & sub_tile_width) << block_size_index; 466 buf[3 * x + y * row_stride ] = texture_color.r();
387 sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); 467 buf[3 * x + y * row_stride + 1] = texture_color.g();
388 texel_index_within_tile += sub_tile_index; 468 buf[3 * x + y * row_stride + 2] = texture_color.b();
389 }
390
391 const int block_width = 8;
392 const int block_height = 8;
393
394 int coarse_x = (x / block_width) * block_width;
395 int coarse_y = (y / block_height) * block_height;
396
397 u8* source_ptr = (u8*)data + coarse_x * block_height * 3 + coarse_y * row_stride + texel_index_within_tile * 3;
398 buf[3 * x + y * row_stride ] = source_ptr[2];
399 buf[3 * x + y * row_stride + 1] = source_ptr[1];
400 buf[3 * x + y * row_stride + 2] = source_ptr[0];
401 } 469 }
402 } 470 }
403 471
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
index b1558cfae..51f14f12f 100644
--- a/src/video_core/debug_utils/debug_utils.h
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -5,13 +5,147 @@
5#pragma once 5#pragma once
6 6
7#include <array> 7#include <array>
8#include <condition_variable>
9#include <list>
10#include <map>
8#include <memory> 11#include <memory>
12#include <mutex>
9#include <vector> 13#include <vector>
10 14
15#include "video_core/math.h"
11#include "video_core/pica.h" 16#include "video_core/pica.h"
12 17
13namespace Pica { 18namespace Pica {
14 19
20class DebugContext {
21public:
22 enum class Event {
23 FirstEvent = 0,
24
25 CommandLoaded = FirstEvent,
26 CommandProcessed,
27 IncomingPrimitiveBatch,
28 FinishedPrimitiveBatch,
29
30 NumEvents
31 };
32
33 /**
34 * Inherit from this class to be notified of events registered to some debug context.
35 * Most importantly this is used for our debugger GUI.
36 *
37 * To implement event handling, override the OnPicaBreakPointHit and OnPicaResume methods.
38 * @warning All BreakPointObservers need to be on the same thread to guarantee thread-safe state access
39 * @todo Evaluate an alternative interface, in which there is only one managing observer and multiple child observers running (by design) on the same thread.
40 */
41 class BreakPointObserver {
42 public:
43 /// Constructs the object such that it observes events of the given DebugContext.
44 BreakPointObserver(std::shared_ptr<DebugContext> debug_context) : context_weak(debug_context) {
45 std::unique_lock<std::mutex> lock(debug_context->breakpoint_mutex);
46 debug_context->breakpoint_observers.push_back(this);
47 }
48
49 virtual ~BreakPointObserver() {
50 auto context = context_weak.lock();
51 if (context) {
52 std::unique_lock<std::mutex> lock(context->breakpoint_mutex);
53 context->breakpoint_observers.remove(this);
54
55 // If we are the last observer to be destroyed, tell the debugger context that
56 // it is free to continue. In particular, this is required for a proper Citra
57 // shutdown, when the emulation thread is waiting at a breakpoint.
58 if (context->breakpoint_observers.empty())
59 context->Resume();
60 }
61 }
62
63 /**
64 * Action to perform when a breakpoint was reached.
65 * @param event Type of event which triggered the breakpoint
66 * @param data Optional data pointer (if unused, this is a nullptr)
67 * @note This function will perform nothing unless it is overridden in the child class.
68 */
69 virtual void OnPicaBreakPointHit(Event, void*) {
70 }
71
72 /**
73 * Action to perform when emulation is resumed from a breakpoint.
74 * @note This function will perform nothing unless it is overridden in the child class.
75 */
76 virtual void OnPicaResume() {
77 }
78
79 protected:
80 /**
81 * Weak context pointer. This need not be valid, so when requesting a shared_ptr via
82 * context_weak.lock(), always compare the result against nullptr.
83 */
84 std::weak_ptr<DebugContext> context_weak;
85 };
86
87 /**
88 * Simple structure defining a breakpoint state
89 */
90 struct BreakPoint {
91 bool enabled = false;
92 };
93
94 /**
95 * Static constructor used to create a shared_ptr of a DebugContext.
96 */
97 static std::shared_ptr<DebugContext> Construct() {
98 return std::shared_ptr<DebugContext>(new DebugContext);
99 }
100
101 /**
102 * Used by the emulation core when a given event has happened. If a breakpoint has been set
103 * for this event, OnEvent calls the event handlers of the registered breakpoint observers.
104 * The current thread then is halted until Resume() is called from another thread (or until
105 * emulation is stopped).
106 * @param event Event which has happened
107 * @param data Optional data pointer (pass nullptr if unused). Needs to remain valid until Resume() is called.
108 */
109 void OnEvent(Event event, void* data);
110
111 /**
112 * Resume from the current breakpoint.
113 * @warning Calling this from the same thread that OnEvent was called in will cause a deadlock. Calling from any other thread is safe.
114 */
115 void Resume();
116
117 /**
118 * Delete all set breakpoints and resume emulation.
119 */
120 void ClearBreakpoints() {
121 breakpoints.clear();
122 Resume();
123 }
124
125 // TODO: Evaluate if access to these members should be hidden behind a public interface.
126 std::map<Event, BreakPoint> breakpoints;
127 Event active_breakpoint;
128 bool at_breakpoint = false;
129
130private:
131 /**
132 * Private default constructor to make sure people always construct this through Construct()
133 * instead.
134 */
135 DebugContext() = default;
136
137 /// Mutex protecting current breakpoint state and the observer list.
138 std::mutex breakpoint_mutex;
139
140 /// Used by OnEvent to wait for resumption.
141 std::condition_variable resume_from_breakpoint;
142
143 /// List of registered observers
144 std::list<BreakPointObserver*> breakpoint_observers;
145};
146
147extern std::shared_ptr<DebugContext> g_debug_context; // TODO: Get rid of this global
148
15namespace DebugUtils { 149namespace DebugUtils {
16 150
17// Simple utility class for dumping geometry data to an OBJ file 151// Simple utility class for dumping geometry data to an OBJ file
@@ -57,6 +191,18 @@ bool IsPicaTracing();
57void OnPicaRegWrite(u32 id, u32 value); 191void OnPicaRegWrite(u32 id, u32 value);
58std::unique_ptr<PicaTrace> FinishPicaTracing(); 192std::unique_ptr<PicaTrace> FinishPicaTracing();
59 193
194struct TextureInfo {
195 unsigned int address;
196 int width;
197 int height;
198 int stride;
199 Pica::Regs::TextureFormat format;
200
201 static TextureInfo FromPicaRegister(const Pica::Regs::TextureConfig& config,
202 const Pica::Regs::TextureFormat& format);
203};
204
205const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info);
60void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); 206void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data);
61 207
62void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); 208void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages);
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 5fe15a218..e7ca38978 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -109,7 +109,7 @@ struct Regs {
109 109
110 u32 address; 110 u32 address;
111 111
112 u32 GetPhysicalAddress() { 112 u32 GetPhysicalAddress() const {
113 return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_GSP_VADDR; 113 return DecodeAddressRegister(address) - Memory::FCRAM_PADDR + Memory::HEAP_GSP_VADDR;
114 } 114 }
115 115
@@ -130,7 +130,26 @@ struct Regs {
130 // Seems like they are luminance formats and compressed textures. 130 // Seems like they are luminance formats and compressed textures.
131 }; 131 };
132 132
133 BitField<0, 1, u32> texturing_enable; 133 static unsigned BytesPerPixel(TextureFormat format) {
134 switch (format) {
135 case TextureFormat::RGBA8:
136 return 4;
137
138 case TextureFormat::RGB8:
139 return 3;
140
141 case TextureFormat::RGBA5551:
142 case TextureFormat::RGB565:
143 case TextureFormat::RGBA4:
144 return 2;
145
146 default:
147 // placeholder for yet unknown formats
148 return 1;
149 }
150 }
151
152 BitField< 0, 1, u32> texturing_enable;
134 TextureConfig texture0; 153 TextureConfig texture0;
135 INSERT_PADDING_WORDS(0x8); 154 INSERT_PADDING_WORDS(0x8);
136 BitField<0, 4, TextureFormat> texture0_format; 155 BitField<0, 4, TextureFormat> texture0_format;
@@ -517,10 +536,6 @@ struct Regs {
517 static std::string GetCommandName(int index) { 536 static std::string GetCommandName(int index) {
518 std::map<u32, std::string> map; 537 std::map<u32, std::string> map;
519 538
520 // TODO: MSVC does not support using offsetof() on non-static data members even though this
521 // is technically allowed since C++11. Hence, this functionality is disabled until
522 // MSVC properly supports it.
523 #ifndef _MSC_VER
524 Regs regs; 539 Regs regs;
525 #define ADD_FIELD(name) \ 540 #define ADD_FIELD(name) \
526 do { \ 541 do { \
@@ -557,7 +572,6 @@ struct Regs {
557 ADD_FIELD(vs_swizzle_patterns); 572 ADD_FIELD(vs_swizzle_patterns);
558 573
559 #undef ADD_FIELD 574 #undef ADD_FIELD
560 #endif // _MSC_VER
561 575
562 // Return empty string if no match is found 576 // Return empty string if no match is found
563 return map[index]; 577 return map[index];