diff options
| author | 2018-01-11 19:21:20 -0700 | |
|---|---|---|
| committer | 2018-01-12 19:11:03 -0700 | |
| commit | ebf9a784a9f7f4148a669dbb39e7cd50df779a14 (patch) | |
| tree | d585685a1c0a34b903af1d086d62560bf56bb29f /src/citra_qt/debugger/graphics | |
| parent | config: Default CPU core to Unicorn. (diff) | |
| download | yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.gz yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.xz yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.zip | |
Massive removal of unused modules
Diffstat (limited to 'src/citra_qt/debugger/graphics')
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics.cpp | 77 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics.h | 41 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_breakpoint_observer.cpp | 27 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_breakpoint_observer.h | 33 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_breakpoints.cpp | 213 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_breakpoints.h | 46 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_breakpoints_p.h | 36 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_cmdlists.cpp | 259 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_cmdlists.h | 61 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_surface.cpp | 713 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_surface.h | 118 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_tracing.cpp | 177 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_tracing.h | 33 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp | 622 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics/graphics_vertex_shader.h | 88 |
15 files changed, 0 insertions, 2544 deletions
diff --git a/src/citra_qt/debugger/graphics/graphics.cpp b/src/citra_qt/debugger/graphics/graphics.cpp deleted file mode 100644 index 8154363a2..000000000 --- a/src/citra_qt/debugger/graphics/graphics.cpp +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QListView> | ||
| 6 | #include "citra_qt/debugger/graphics/graphics.h" | ||
| 7 | #include "citra_qt/util/util.h" | ||
| 8 | |||
| 9 | GraphicsDebugger g_debugger; | ||
| 10 | |||
| 11 | GPUCommandStreamItemModel::GPUCommandStreamItemModel(QObject* parent) | ||
| 12 | : QAbstractListModel(parent), command_count(0) { | ||
| 13 | connect(this, SIGNAL(GXCommandFinished(int)), this, SLOT(OnGXCommandFinishedInternal(int))); | ||
| 14 | } | ||
| 15 | |||
| 16 | int GPUCommandStreamItemModel::rowCount(const QModelIndex& parent) const { | ||
| 17 | return command_count; | ||
| 18 | } | ||
| 19 | |||
| 20 | QVariant GPUCommandStreamItemModel::data(const QModelIndex& index, int role) const { | ||
| 21 | if (!index.isValid()) | ||
| 22 | return QVariant(); | ||
| 23 | |||
| 24 | int command_index = index.row(); | ||
| 25 | const Service::GSP::Command& command = GetDebugger()->ReadGXCommandHistory(command_index); | ||
| 26 | if (role == Qt::DisplayRole) { | ||
| 27 | std::map<Service::GSP::CommandId, const char*> command_names = { | ||
| 28 | {Service::GSP::CommandId::REQUEST_DMA, "REQUEST_DMA"}, | ||
| 29 | {Service::GSP::CommandId::SUBMIT_GPU_CMDLIST, "SUBMIT_GPU_CMDLIST"}, | ||
| 30 | {Service::GSP::CommandId::SET_MEMORY_FILL, "SET_MEMORY_FILL"}, | ||
| 31 | {Service::GSP::CommandId::SET_DISPLAY_TRANSFER, "SET_DISPLAY_TRANSFER"}, | ||
| 32 | {Service::GSP::CommandId::SET_TEXTURE_COPY, "SET_TEXTURE_COPY"}, | ||
| 33 | {Service::GSP::CommandId::CACHE_FLUSH, "CACHE_FLUSH"}, | ||
| 34 | }; | ||
| 35 | const u32* command_data = reinterpret_cast<const u32*>(&command); | ||
| 36 | QString str = QString("%1 %2 %3 %4 %5 %6 %7 %8 %9") | ||
| 37 | .arg(command_names[command.id]) | ||
| 38 | .arg(command_data[0], 8, 16, QLatin1Char('0')) | ||
| 39 | .arg(command_data[1], 8, 16, QLatin1Char('0')) | ||
| 40 | .arg(command_data[2], 8, 16, QLatin1Char('0')) | ||
| 41 | .arg(command_data[3], 8, 16, QLatin1Char('0')) | ||
| 42 | .arg(command_data[4], 8, 16, QLatin1Char('0')) | ||
| 43 | .arg(command_data[5], 8, 16, QLatin1Char('0')) | ||
| 44 | .arg(command_data[6], 8, 16, QLatin1Char('0')) | ||
| 45 | .arg(command_data[7], 8, 16, QLatin1Char('0')); | ||
| 46 | return QVariant(str); | ||
| 47 | } else { | ||
| 48 | return QVariant(); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | void GPUCommandStreamItemModel::GXCommandProcessed(int total_command_count) { | ||
| 53 | emit GXCommandFinished(total_command_count); | ||
| 54 | } | ||
| 55 | |||
| 56 | void GPUCommandStreamItemModel::OnGXCommandFinishedInternal(int total_command_count) { | ||
| 57 | if (total_command_count == 0) | ||
| 58 | return; | ||
| 59 | |||
| 60 | int prev_command_count = command_count; | ||
| 61 | command_count = total_command_count; | ||
| 62 | emit dataChanged(index(prev_command_count, 0), index(total_command_count - 1, 0)); | ||
| 63 | } | ||
| 64 | |||
| 65 | GPUCommandStreamWidget::GPUCommandStreamWidget(QWidget* parent) | ||
| 66 | : QDockWidget(tr("Graphics Debugger"), parent) { | ||
| 67 | setObjectName("GraphicsDebugger"); | ||
| 68 | |||
| 69 | GPUCommandStreamItemModel* command_model = new GPUCommandStreamItemModel(this); | ||
| 70 | g_debugger.RegisterObserver(command_model); | ||
| 71 | |||
| 72 | QListView* command_list = new QListView; | ||
| 73 | command_list->setModel(command_model); | ||
| 74 | command_list->setFont(GetMonospaceFont()); | ||
| 75 | |||
| 76 | setWidget(command_list); | ||
| 77 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics.h b/src/citra_qt/debugger/graphics/graphics.h deleted file mode 100644 index 8837fb792..000000000 --- a/src/citra_qt/debugger/graphics/graphics.h +++ /dev/null | |||
| @@ -1,41 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QAbstractListModel> | ||
| 8 | #include <QDockWidget> | ||
| 9 | #include "video_core/gpu_debugger.h" | ||
| 10 | |||
| 11 | class GPUCommandStreamItemModel : public QAbstractListModel, | ||
| 12 | public GraphicsDebugger::DebuggerObserver { | ||
| 13 | Q_OBJECT | ||
| 14 | |||
| 15 | public: | ||
| 16 | explicit GPUCommandStreamItemModel(QObject* parent); | ||
| 17 | |||
| 18 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 19 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
| 20 | |||
| 21 | public: | ||
| 22 | void GXCommandProcessed(int total_command_count) override; | ||
| 23 | |||
| 24 | public slots: | ||
| 25 | void OnGXCommandFinishedInternal(int total_command_count); | ||
| 26 | |||
| 27 | signals: | ||
| 28 | void GXCommandFinished(int total_command_count); | ||
| 29 | |||
| 30 | private: | ||
| 31 | int command_count; | ||
| 32 | }; | ||
| 33 | |||
| 34 | class GPUCommandStreamWidget : public QDockWidget { | ||
| 35 | Q_OBJECT | ||
| 36 | |||
| 37 | public: | ||
| 38 | GPUCommandStreamWidget(QWidget* parent = nullptr); | ||
| 39 | |||
| 40 | private: | ||
| 41 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.cpp b/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.cpp deleted file mode 100644 index dc6070dea..000000000 --- a/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.cpp +++ /dev/null | |||
| @@ -1,27 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QMetaType> | ||
| 6 | #include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h" | ||
| 7 | |||
| 8 | BreakPointObserverDock::BreakPointObserverDock(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 9 | const QString& title, QWidget* parent) | ||
| 10 | : QDockWidget(title, parent), BreakPointObserver(debug_context) { | ||
| 11 | qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event"); | ||
| 12 | |||
| 13 | connect(this, SIGNAL(Resumed()), this, SLOT(OnResumed())); | ||
| 14 | |||
| 15 | // NOTE: This signal is emitted from a non-GUI thread, but connect() takes | ||
| 16 | // care of delaying its handling to the GUI thread. | ||
| 17 | connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event, void*)), this, | ||
| 18 | SLOT(OnBreakPointHit(Pica::DebugContext::Event, void*)), Qt::BlockingQueuedConnection); | ||
| 19 | } | ||
| 20 | |||
| 21 | void BreakPointObserverDock::OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) { | ||
| 22 | emit BreakPointHit(event, data); | ||
| 23 | } | ||
| 24 | |||
| 25 | void BreakPointObserverDock::OnPicaResume() { | ||
| 26 | emit Resumed(); | ||
| 27 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.h b/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.h deleted file mode 100644 index e77df4f5b..000000000 --- a/src/citra_qt/debugger/graphics/graphics_breakpoint_observer.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QDockWidget> | ||
| 8 | #include "video_core/debug_utils/debug_utils.h" | ||
| 9 | |||
| 10 | /** | ||
| 11 | * Utility class which forwards calls to OnPicaBreakPointHit and OnPicaResume to public slots. | ||
| 12 | * This is because the Pica breakpoint callbacks are called from a non-GUI thread, while | ||
| 13 | * the widget usually wants to perform reactions in the GUI thread. | ||
| 14 | */ | ||
| 15 | class BreakPointObserverDock : public QDockWidget, | ||
| 16 | protected Pica::DebugContext::BreakPointObserver { | ||
| 17 | Q_OBJECT | ||
| 18 | |||
| 19 | public: | ||
| 20 | BreakPointObserverDock(std::shared_ptr<Pica::DebugContext> debug_context, const QString& title, | ||
| 21 | QWidget* parent = nullptr); | ||
| 22 | |||
| 23 | void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override; | ||
| 24 | void OnPicaResume() override; | ||
| 25 | |||
| 26 | private slots: | ||
| 27 | virtual void OnBreakPointHit(Pica::DebugContext::Event event, void* data) = 0; | ||
| 28 | virtual void OnResumed() = 0; | ||
| 29 | |||
| 30 | signals: | ||
| 31 | void Resumed(); | ||
| 32 | void BreakPointHit(Pica::DebugContext::Event event, void* data); | ||
| 33 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_breakpoints.cpp b/src/citra_qt/debugger/graphics/graphics_breakpoints.cpp deleted file mode 100644 index 030828ba8..000000000 --- a/src/citra_qt/debugger/graphics/graphics_breakpoints.cpp +++ /dev/null | |||
| @@ -1,213 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QLabel> | ||
| 6 | #include <QMetaType> | ||
| 7 | #include <QPushButton> | ||
| 8 | #include <QTreeView> | ||
| 9 | #include <QVBoxLayout> | ||
| 10 | #include "citra_qt/debugger/graphics/graphics_breakpoints.h" | ||
| 11 | #include "citra_qt/debugger/graphics/graphics_breakpoints_p.h" | ||
| 12 | #include "common/assert.h" | ||
| 13 | |||
| 14 | BreakPointModel::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 | int BreakPointModel::columnCount(const QModelIndex& parent) const { | ||
| 20 | return 1; | ||
| 21 | } | ||
| 22 | |||
| 23 | int BreakPointModel::rowCount(const QModelIndex& parent) const { | ||
| 24 | return static_cast<int>(Pica::DebugContext::Event::NumEvents); | ||
| 25 | } | ||
| 26 | |||
| 27 | QVariant BreakPointModel::data(const QModelIndex& index, int role) const { | ||
| 28 | const auto event = static_cast<Pica::DebugContext::Event>(index.row()); | ||
| 29 | |||
| 30 | switch (role) { | ||
| 31 | case Qt::DisplayRole: { | ||
| 32 | if (index.column() == 0) { | ||
| 33 | static const std::map<Pica::DebugContext::Event, QString> map = { | ||
| 34 | {Pica::DebugContext::Event::PicaCommandLoaded, tr("Pica command loaded")}, | ||
| 35 | {Pica::DebugContext::Event::PicaCommandProcessed, tr("Pica command processed")}, | ||
| 36 | {Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch")}, | ||
| 37 | {Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch")}, | ||
| 38 | {Pica::DebugContext::Event::VertexShaderInvocation, tr("Vertex shader invocation")}, | ||
| 39 | {Pica::DebugContext::Event::IncomingDisplayTransfer, | ||
| 40 | tr("Incoming display transfer")}, | ||
| 41 | {Pica::DebugContext::Event::GSPCommandProcessed, tr("GSP command processed")}, | ||
| 42 | {Pica::DebugContext::Event::BufferSwapped, tr("Buffers swapped")}, | ||
| 43 | }; | ||
| 44 | |||
| 45 | DEBUG_ASSERT(map.size() == static_cast<size_t>(Pica::DebugContext::Event::NumEvents)); | ||
| 46 | return (map.find(event) != map.end()) ? map.at(event) : QString(); | ||
| 47 | } | ||
| 48 | |||
| 49 | break; | ||
| 50 | } | ||
| 51 | |||
| 52 | case Qt::CheckStateRole: { | ||
| 53 | if (index.column() == 0) | ||
| 54 | return data(index, Role_IsEnabled).toBool() ? Qt::Checked : Qt::Unchecked; | ||
| 55 | break; | ||
| 56 | } | ||
| 57 | |||
| 58 | case Qt::BackgroundRole: { | ||
| 59 | if (at_breakpoint && index.row() == static_cast<int>(active_breakpoint)) { | ||
| 60 | return QBrush(QColor(0xE0, 0xE0, 0x10)); | ||
| 61 | } | ||
| 62 | break; | ||
| 63 | } | ||
| 64 | |||
| 65 | case Role_IsEnabled: { | ||
| 66 | auto context = context_weak.lock(); | ||
| 67 | return context && context->breakpoints[(int)event].enabled; | ||
| 68 | } | ||
| 69 | |||
| 70 | default: | ||
| 71 | break; | ||
| 72 | } | ||
| 73 | return QVariant(); | ||
| 74 | } | ||
| 75 | |||
| 76 | Qt::ItemFlags BreakPointModel::flags(const QModelIndex& index) const { | ||
| 77 | if (!index.isValid()) | ||
| 78 | return 0; | ||
| 79 | |||
| 80 | Qt::ItemFlags flags = Qt::ItemIsEnabled; | ||
| 81 | if (index.column() == 0) | ||
| 82 | flags |= Qt::ItemIsUserCheckable; | ||
| 83 | return flags; | ||
| 84 | } | ||
| 85 | |||
| 86 | bool BreakPointModel::setData(const QModelIndex& index, const QVariant& value, int role) { | ||
| 87 | const auto event = static_cast<Pica::DebugContext::Event>(index.row()); | ||
| 88 | |||
| 89 | switch (role) { | ||
| 90 | case Qt::CheckStateRole: { | ||
| 91 | if (index.column() != 0) | ||
| 92 | return false; | ||
| 93 | |||
| 94 | auto context = context_weak.lock(); | ||
| 95 | if (!context) | ||
| 96 | return false; | ||
| 97 | |||
| 98 | context->breakpoints[(int)event].enabled = value == Qt::Checked; | ||
| 99 | QModelIndex changed_index = createIndex(index.row(), 0); | ||
| 100 | emit dataChanged(changed_index, changed_index); | ||
| 101 | return true; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | return false; | ||
| 106 | } | ||
| 107 | |||
| 108 | void BreakPointModel::OnBreakPointHit(Pica::DebugContext::Event event) { | ||
| 109 | auto context = context_weak.lock(); | ||
| 110 | if (!context) | ||
| 111 | return; | ||
| 112 | |||
| 113 | active_breakpoint = context->active_breakpoint; | ||
| 114 | at_breakpoint = context->at_breakpoint; | ||
| 115 | emit dataChanged(createIndex(static_cast<int>(event), 0), | ||
| 116 | createIndex(static_cast<int>(event), 0)); | ||
| 117 | } | ||
| 118 | |||
| 119 | void BreakPointModel::OnResumed() { | ||
| 120 | auto context = context_weak.lock(); | ||
| 121 | if (!context) | ||
| 122 | return; | ||
| 123 | |||
| 124 | at_breakpoint = context->at_breakpoint; | ||
| 125 | emit dataChanged(createIndex(static_cast<int>(active_breakpoint), 0), | ||
| 126 | createIndex(static_cast<int>(active_breakpoint), 0)); | ||
| 127 | active_breakpoint = context->active_breakpoint; | ||
| 128 | } | ||
| 129 | |||
| 130 | GraphicsBreakPointsWidget::GraphicsBreakPointsWidget( | ||
| 131 | std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent) | ||
| 132 | : QDockWidget(tr("Pica Breakpoints"), parent), | ||
| 133 | Pica::DebugContext::BreakPointObserver(debug_context) { | ||
| 134 | setObjectName("PicaBreakPointsWidget"); | ||
| 135 | |||
| 136 | status_text = new QLabel(tr("Emulation running")); | ||
| 137 | resume_button = new QPushButton(tr("Resume")); | ||
| 138 | resume_button->setEnabled(false); | ||
| 139 | |||
| 140 | breakpoint_model = new BreakPointModel(debug_context, this); | ||
| 141 | breakpoint_list = new QTreeView; | ||
| 142 | breakpoint_list->setRootIsDecorated(false); | ||
| 143 | breakpoint_list->setHeaderHidden(true); | ||
| 144 | breakpoint_list->setModel(breakpoint_model); | ||
| 145 | |||
| 146 | qRegisterMetaType<Pica::DebugContext::Event>("Pica::DebugContext::Event"); | ||
| 147 | |||
| 148 | connect(breakpoint_list, SIGNAL(doubleClicked(const QModelIndex&)), this, | ||
| 149 | SLOT(OnItemDoubleClicked(const QModelIndex&))); | ||
| 150 | |||
| 151 | connect(resume_button, SIGNAL(clicked()), this, SLOT(OnResumeRequested())); | ||
| 152 | |||
| 153 | connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event, void*)), this, | ||
| 154 | SLOT(OnBreakPointHit(Pica::DebugContext::Event, void*)), Qt::BlockingQueuedConnection); | ||
| 155 | connect(this, SIGNAL(Resumed()), this, SLOT(OnResumed())); | ||
| 156 | |||
| 157 | connect(this, SIGNAL(BreakPointHit(Pica::DebugContext::Event, void*)), breakpoint_model, | ||
| 158 | SLOT(OnBreakPointHit(Pica::DebugContext::Event)), Qt::BlockingQueuedConnection); | ||
| 159 | connect(this, SIGNAL(Resumed()), breakpoint_model, SLOT(OnResumed())); | ||
| 160 | |||
| 161 | connect(this, SIGNAL(BreakPointsChanged(const QModelIndex&, const QModelIndex&)), | ||
| 162 | breakpoint_model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&))); | ||
| 163 | |||
| 164 | QWidget* main_widget = new QWidget; | ||
| 165 | auto main_layout = new QVBoxLayout; | ||
| 166 | { | ||
| 167 | auto sub_layout = new QHBoxLayout; | ||
| 168 | sub_layout->addWidget(status_text); | ||
| 169 | sub_layout->addWidget(resume_button); | ||
| 170 | main_layout->addLayout(sub_layout); | ||
| 171 | } | ||
| 172 | main_layout->addWidget(breakpoint_list); | ||
| 173 | main_widget->setLayout(main_layout); | ||
| 174 | |||
| 175 | setWidget(main_widget); | ||
| 176 | } | ||
| 177 | |||
| 178 | void GraphicsBreakPointsWidget::OnPicaBreakPointHit(Event event, void* data) { | ||
| 179 | // Process in GUI thread | ||
| 180 | emit BreakPointHit(event, data); | ||
| 181 | } | ||
| 182 | |||
| 183 | void GraphicsBreakPointsWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) { | ||
| 184 | status_text->setText(tr("Emulation halted at breakpoint")); | ||
| 185 | resume_button->setEnabled(true); | ||
| 186 | } | ||
| 187 | |||
| 188 | void GraphicsBreakPointsWidget::OnPicaResume() { | ||
| 189 | // Process in GUI thread | ||
| 190 | emit Resumed(); | ||
| 191 | } | ||
| 192 | |||
| 193 | void GraphicsBreakPointsWidget::OnResumed() { | ||
| 194 | status_text->setText(tr("Emulation running")); | ||
| 195 | resume_button->setEnabled(false); | ||
| 196 | } | ||
| 197 | |||
| 198 | void GraphicsBreakPointsWidget::OnResumeRequested() { | ||
| 199 | if (auto context = context_weak.lock()) | ||
| 200 | context->Resume(); | ||
| 201 | } | ||
| 202 | |||
| 203 | void GraphicsBreakPointsWidget::OnItemDoubleClicked(const QModelIndex& index) { | ||
| 204 | if (!index.isValid()) | ||
| 205 | return; | ||
| 206 | |||
| 207 | QModelIndex check_index = breakpoint_list->model()->index(index.row(), 0); | ||
| 208 | QVariant enabled = breakpoint_list->model()->data(check_index, Qt::CheckStateRole); | ||
| 209 | QVariant new_state = Qt::Unchecked; | ||
| 210 | if (enabled == Qt::Unchecked) | ||
| 211 | new_state = Qt::Checked; | ||
| 212 | breakpoint_list->model()->setData(check_index, new_state, Qt::CheckStateRole); | ||
| 213 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_breakpoints.h b/src/citra_qt/debugger/graphics/graphics_breakpoints.h deleted file mode 100644 index bec72a2db..000000000 --- a/src/citra_qt/debugger/graphics/graphics_breakpoints.h +++ /dev/null | |||
| @@ -1,46 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <QDockWidget> | ||
| 9 | #include "video_core/debug_utils/debug_utils.h" | ||
| 10 | |||
| 11 | class QLabel; | ||
| 12 | class QPushButton; | ||
| 13 | class QTreeView; | ||
| 14 | |||
| 15 | class BreakPointModel; | ||
| 16 | |||
| 17 | class GraphicsBreakPointsWidget : public QDockWidget, Pica::DebugContext::BreakPointObserver { | ||
| 18 | Q_OBJECT | ||
| 19 | |||
| 20 | using Event = Pica::DebugContext::Event; | ||
| 21 | |||
| 22 | public: | ||
| 23 | explicit GraphicsBreakPointsWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 24 | QWidget* parent = nullptr); | ||
| 25 | |||
| 26 | void OnPicaBreakPointHit(Pica::DebugContext::Event event, void* data) override; | ||
| 27 | void OnPicaResume() override; | ||
| 28 | |||
| 29 | public slots: | ||
| 30 | void OnBreakPointHit(Pica::DebugContext::Event event, void* data); | ||
| 31 | void OnItemDoubleClicked(const QModelIndex&); | ||
| 32 | void OnResumeRequested(); | ||
| 33 | void OnResumed(); | ||
| 34 | |||
| 35 | signals: | ||
| 36 | void Resumed(); | ||
| 37 | void BreakPointHit(Pica::DebugContext::Event event, void* data); | ||
| 38 | void BreakPointsChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); | ||
| 39 | |||
| 40 | private: | ||
| 41 | QLabel* status_text; | ||
| 42 | QPushButton* resume_button; | ||
| 43 | |||
| 44 | BreakPointModel* breakpoint_model; | ||
| 45 | QTreeView* breakpoint_list; | ||
| 46 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_breakpoints_p.h b/src/citra_qt/debugger/graphics/graphics_breakpoints_p.h deleted file mode 100644 index dc64706bd..000000000 --- a/src/citra_qt/debugger/graphics/graphics_breakpoints_p.h +++ /dev/null | |||
| @@ -1,36 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include <QAbstractListModel> | ||
| 9 | #include "video_core/debug_utils/debug_utils.h" | ||
| 10 | |||
| 11 | class BreakPointModel : public QAbstractListModel { | ||
| 12 | Q_OBJECT | ||
| 13 | |||
| 14 | public: | ||
| 15 | enum { | ||
| 16 | Role_IsEnabled = Qt::UserRole, | ||
| 17 | }; | ||
| 18 | |||
| 19 | BreakPointModel(std::shared_ptr<Pica::DebugContext> context, QObject* parent); | ||
| 20 | |||
| 21 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 22 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 23 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
| 24 | Qt::ItemFlags flags(const QModelIndex& index) const override; | ||
| 25 | |||
| 26 | bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; | ||
| 27 | |||
| 28 | public slots: | ||
| 29 | void OnBreakPointHit(Pica::DebugContext::Event event); | ||
| 30 | void OnResumed(); | ||
| 31 | |||
| 32 | private: | ||
| 33 | std::weak_ptr<Pica::DebugContext> context_weak; | ||
| 34 | bool at_breakpoint; | ||
| 35 | Pica::DebugContext::Event active_breakpoint; | ||
| 36 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp deleted file mode 100644 index ce2b9fa50..000000000 --- a/src/citra_qt/debugger/graphics/graphics_cmdlists.cpp +++ /dev/null | |||
| @@ -1,259 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QApplication> | ||
| 6 | #include <QClipboard> | ||
| 7 | #include <QComboBox> | ||
| 8 | #include <QHeaderView> | ||
| 9 | #include <QLabel> | ||
| 10 | #include <QListView> | ||
| 11 | #include <QMainWindow> | ||
| 12 | #include <QPushButton> | ||
| 13 | #include <QSpinBox> | ||
| 14 | #include <QTreeView> | ||
| 15 | #include <QVBoxLayout> | ||
| 16 | #include "citra_qt/debugger/graphics/graphics_cmdlists.h" | ||
| 17 | #include "citra_qt/util/spinbox.h" | ||
| 18 | #include "citra_qt/util/util.h" | ||
| 19 | #include "common/vector_math.h" | ||
| 20 | #include "core/memory.h" | ||
| 21 | #include "video_core/debug_utils/debug_utils.h" | ||
| 22 | #include "video_core/pica_state.h" | ||
| 23 | #include "video_core/regs.h" | ||
| 24 | #include "video_core/texture/texture_decode.h" | ||
| 25 | |||
| 26 | namespace { | ||
| 27 | QImage LoadTexture(const u8* src, const Pica::Texture::TextureInfo& info) { | ||
| 28 | QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); | ||
| 29 | for (u32 y = 0; y < info.height; ++y) { | ||
| 30 | for (u32 x = 0; x < info.width; ++x) { | ||
| 31 | Math::Vec4<u8> color = Pica::Texture::LookupTexture(src, x, y, info, true); | ||
| 32 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | return decoded_image; | ||
| 37 | } | ||
| 38 | |||
| 39 | class TextureInfoWidget : public QWidget { | ||
| 40 | public: | ||
| 41 | TextureInfoWidget(const u8* src, const Pica::Texture::TextureInfo& info, | ||
| 42 | QWidget* parent = nullptr) | ||
| 43 | : QWidget(parent) { | ||
| 44 | |||
| 45 | QLabel* image_widget = new QLabel; | ||
| 46 | QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info)); | ||
| 47 | image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); | ||
| 48 | image_widget->setPixmap(image_pixmap); | ||
| 49 | |||
| 50 | QVBoxLayout* layout = new QVBoxLayout; | ||
| 51 | layout->addWidget(image_widget); | ||
| 52 | setLayout(layout); | ||
| 53 | } | ||
| 54 | }; | ||
| 55 | } // Anonymous namespace | ||
| 56 | |||
| 57 | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) {} | ||
| 58 | |||
| 59 | int GPUCommandListModel::rowCount(const QModelIndex& parent) const { | ||
| 60 | return static_cast<int>(pica_trace.writes.size()); | ||
| 61 | } | ||
| 62 | |||
| 63 | int GPUCommandListModel::columnCount(const QModelIndex& parent) const { | ||
| 64 | return 4; | ||
| 65 | } | ||
| 66 | |||
| 67 | QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const { | ||
| 68 | if (!index.isValid()) | ||
| 69 | return QVariant(); | ||
| 70 | |||
| 71 | const auto& write = pica_trace.writes[index.row()]; | ||
| 72 | |||
| 73 | if (role == Qt::DisplayRole) { | ||
| 74 | switch (index.column()) { | ||
| 75 | case 0: | ||
| 76 | return QString::fromLatin1(Pica::Regs::GetRegisterName(write.cmd_id)); | ||
| 77 | case 1: | ||
| 78 | return QString("%1").arg(write.cmd_id, 3, 16, QLatin1Char('0')); | ||
| 79 | case 2: | ||
| 80 | return QString("%1").arg(write.mask, 4, 2, QLatin1Char('0')); | ||
| 81 | case 3: | ||
| 82 | return QString("%1").arg(write.value, 8, 16, QLatin1Char('0')); | ||
| 83 | } | ||
| 84 | } else if (role == CommandIdRole) { | ||
| 85 | return QVariant::fromValue<int>(write.cmd_id); | ||
| 86 | } | ||
| 87 | |||
| 88 | return QVariant(); | ||
| 89 | } | ||
| 90 | |||
| 91 | QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const { | ||
| 92 | switch (role) { | ||
| 93 | case Qt::DisplayRole: { | ||
| 94 | switch (section) { | ||
| 95 | case 0: | ||
| 96 | return tr("Command Name"); | ||
| 97 | case 1: | ||
| 98 | return tr("Register"); | ||
| 99 | case 2: | ||
| 100 | return tr("Mask"); | ||
| 101 | case 3: | ||
| 102 | return tr("New Value"); | ||
| 103 | } | ||
| 104 | |||
| 105 | break; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | return QVariant(); | ||
| 110 | } | ||
| 111 | |||
| 112 | void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) { | ||
| 113 | beginResetModel(); | ||
| 114 | |||
| 115 | pica_trace = trace; | ||
| 116 | |||
| 117 | endResetModel(); | ||
| 118 | } | ||
| 119 | |||
| 120 | #define COMMAND_IN_RANGE(cmd_id, reg_name) \ | ||
| 121 | (cmd_id >= PICA_REG_INDEX(reg_name) && \ | ||
| 122 | cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::g_state.regs.reg_name)) / 4) | ||
| 123 | |||
| 124 | void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) { | ||
| 125 | const unsigned int command_id = | ||
| 126 | list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt(); | ||
| 127 | if (COMMAND_IN_RANGE(command_id, texturing.texture0) || | ||
| 128 | COMMAND_IN_RANGE(command_id, texturing.texture1) || | ||
| 129 | COMMAND_IN_RANGE(command_id, texturing.texture2)) { | ||
| 130 | |||
| 131 | unsigned texture_index; | ||
| 132 | if (COMMAND_IN_RANGE(command_id, texturing.texture0)) { | ||
| 133 | texture_index = 0; | ||
| 134 | } else if (COMMAND_IN_RANGE(command_id, texturing.texture1)) { | ||
| 135 | texture_index = 1; | ||
| 136 | } else if (COMMAND_IN_RANGE(command_id, texturing.texture2)) { | ||
| 137 | texture_index = 2; | ||
| 138 | } else { | ||
| 139 | UNREACHABLE_MSG("Unknown texture command"); | ||
| 140 | } | ||
| 141 | |||
| 142 | // TODO: Open a surface debugger | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) { | ||
| 147 | QWidget* new_info_widget = nullptr; | ||
| 148 | |||
| 149 | const unsigned int command_id = | ||
| 150 | list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toUInt(); | ||
| 151 | if (COMMAND_IN_RANGE(command_id, texturing.texture0) || | ||
| 152 | COMMAND_IN_RANGE(command_id, texturing.texture1) || | ||
| 153 | COMMAND_IN_RANGE(command_id, texturing.texture2)) { | ||
| 154 | |||
| 155 | unsigned texture_index; | ||
| 156 | if (COMMAND_IN_RANGE(command_id, texturing.texture0)) { | ||
| 157 | texture_index = 0; | ||
| 158 | } else if (COMMAND_IN_RANGE(command_id, texturing.texture1)) { | ||
| 159 | texture_index = 1; | ||
| 160 | } else { | ||
| 161 | texture_index = 2; | ||
| 162 | } | ||
| 163 | |||
| 164 | const auto texture = Pica::g_state.regs.texturing.GetTextures()[texture_index]; | ||
| 165 | const auto config = texture.config; | ||
| 166 | const auto format = texture.format; | ||
| 167 | |||
| 168 | const auto info = Pica::Texture::TextureInfo::FromPicaRegister(config, format); | ||
| 169 | const u8* src = Memory::GetPhysicalPointer(config.GetPhysicalAddress()); | ||
| 170 | new_info_widget = new TextureInfoWidget(src, info); | ||
| 171 | } | ||
| 172 | if (command_info_widget) { | ||
| 173 | delete command_info_widget; | ||
| 174 | command_info_widget = nullptr; | ||
| 175 | } | ||
| 176 | if (new_info_widget) { | ||
| 177 | widget()->layout()->addWidget(new_info_widget); | ||
| 178 | command_info_widget = new_info_widget; | ||
| 179 | } | ||
| 180 | } | ||
| 181 | #undef COMMAND_IN_RANGE | ||
| 182 | |||
| 183 | GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) | ||
| 184 | : QDockWidget(tr("Pica Command List"), parent) { | ||
| 185 | setObjectName("Pica Command List"); | ||
| 186 | GPUCommandListModel* model = new GPUCommandListModel(this); | ||
| 187 | |||
| 188 | QWidget* main_widget = new QWidget; | ||
| 189 | |||
| 190 | list_widget = new QTreeView; | ||
| 191 | list_widget->setModel(model); | ||
| 192 | list_widget->setFont(GetMonospaceFont()); | ||
| 193 | list_widget->setRootIsDecorated(false); | ||
| 194 | list_widget->setUniformRowHeights(true); | ||
| 195 | |||
| 196 | #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) | ||
| 197 | list_widget->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | ||
| 198 | #else | ||
| 199 | list_widget->header()->setResizeMode(QHeaderView::ResizeToContents); | ||
| 200 | #endif | ||
| 201 | |||
| 202 | connect(list_widget->selectionModel(), | ||
| 203 | SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)), this, | ||
| 204 | SLOT(SetCommandInfo(const QModelIndex&))); | ||
| 205 | connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)), this, | ||
| 206 | SLOT(OnCommandDoubleClicked(const QModelIndex&))); | ||
| 207 | |||
| 208 | toggle_tracing = new QPushButton(tr("Start Tracing")); | ||
| 209 | QPushButton* copy_all = new QPushButton(tr("Copy All")); | ||
| 210 | |||
| 211 | connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); | ||
| 212 | connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), model, | ||
| 213 | SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); | ||
| 214 | |||
| 215 | connect(copy_all, SIGNAL(clicked()), this, SLOT(CopyAllToClipboard())); | ||
| 216 | |||
| 217 | command_info_widget = nullptr; | ||
| 218 | |||
| 219 | QVBoxLayout* main_layout = new QVBoxLayout; | ||
| 220 | main_layout->addWidget(list_widget); | ||
| 221 | { | ||
| 222 | QHBoxLayout* sub_layout = new QHBoxLayout; | ||
| 223 | sub_layout->addWidget(toggle_tracing); | ||
| 224 | sub_layout->addWidget(copy_all); | ||
| 225 | main_layout->addLayout(sub_layout); | ||
| 226 | } | ||
| 227 | main_widget->setLayout(main_layout); | ||
| 228 | |||
| 229 | setWidget(main_widget); | ||
| 230 | } | ||
| 231 | |||
| 232 | void GPUCommandListWidget::OnToggleTracing() { | ||
| 233 | if (!Pica::DebugUtils::IsPicaTracing()) { | ||
| 234 | Pica::DebugUtils::StartPicaTracing(); | ||
| 235 | toggle_tracing->setText(tr("Finish Tracing")); | ||
| 236 | } else { | ||
| 237 | pica_trace = Pica::DebugUtils::FinishPicaTracing(); | ||
| 238 | emit TracingFinished(*pica_trace); | ||
| 239 | toggle_tracing->setText(tr("Start Tracing")); | ||
| 240 | } | ||
| 241 | } | ||
| 242 | |||
| 243 | void GPUCommandListWidget::CopyAllToClipboard() { | ||
| 244 | QClipboard* clipboard = QApplication::clipboard(); | ||
| 245 | QString text; | ||
| 246 | |||
| 247 | QAbstractItemModel* model = static_cast<QAbstractItemModel*>(list_widget->model()); | ||
| 248 | |||
| 249 | for (int row = 0; row < model->rowCount({}); ++row) { | ||
| 250 | for (int col = 0; col < model->columnCount({}); ++col) { | ||
| 251 | QModelIndex index = model->index(row, col); | ||
| 252 | text += model->data(index).value<QString>(); | ||
| 253 | text += '\t'; | ||
| 254 | } | ||
| 255 | text += '\n'; | ||
| 256 | } | ||
| 257 | |||
| 258 | clipboard->setText(text); | ||
| 259 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_cmdlists.h b/src/citra_qt/debugger/graphics/graphics_cmdlists.h deleted file mode 100644 index 8f40b94c5..000000000 --- a/src/citra_qt/debugger/graphics/graphics_cmdlists.h +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QAbstractListModel> | ||
| 8 | #include <QDockWidget> | ||
| 9 | #include "video_core/debug_utils/debug_utils.h" | ||
| 10 | #include "video_core/gpu_debugger.h" | ||
| 11 | |||
| 12 | class QPushButton; | ||
| 13 | class QTreeView; | ||
| 14 | |||
| 15 | class GPUCommandListModel : public QAbstractListModel { | ||
| 16 | Q_OBJECT | ||
| 17 | |||
| 18 | public: | ||
| 19 | enum { | ||
| 20 | CommandIdRole = Qt::UserRole, | ||
| 21 | }; | ||
| 22 | |||
| 23 | explicit GPUCommandListModel(QObject* parent); | ||
| 24 | |||
| 25 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 26 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 27 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
| 28 | QVariant headerData(int section, Qt::Orientation orientation, | ||
| 29 | int role = Qt::DisplayRole) const override; | ||
| 30 | |||
| 31 | public slots: | ||
| 32 | void OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace); | ||
| 33 | |||
| 34 | private: | ||
| 35 | Pica::DebugUtils::PicaTrace pica_trace; | ||
| 36 | }; | ||
| 37 | |||
| 38 | class GPUCommandListWidget : public QDockWidget { | ||
| 39 | Q_OBJECT | ||
| 40 | |||
| 41 | public: | ||
| 42 | explicit GPUCommandListWidget(QWidget* parent = nullptr); | ||
| 43 | |||
| 44 | public slots: | ||
| 45 | void OnToggleTracing(); | ||
| 46 | void OnCommandDoubleClicked(const QModelIndex&); | ||
| 47 | |||
| 48 | void SetCommandInfo(const QModelIndex&); | ||
| 49 | |||
| 50 | void CopyAllToClipboard(); | ||
| 51 | |||
| 52 | signals: | ||
| 53 | void TracingFinished(const Pica::DebugUtils::PicaTrace&); | ||
| 54 | |||
| 55 | private: | ||
| 56 | std::unique_ptr<Pica::DebugUtils::PicaTrace> pica_trace; | ||
| 57 | |||
| 58 | QTreeView* list_widget; | ||
| 59 | QWidget* command_info_widget; | ||
| 60 | QPushButton* toggle_tracing; | ||
| 61 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_surface.cpp b/src/citra_qt/debugger/graphics/graphics_surface.cpp deleted file mode 100644 index c974545ef..000000000 --- a/src/citra_qt/debugger/graphics/graphics_surface.cpp +++ /dev/null | |||
| @@ -1,713 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QBoxLayout> | ||
| 6 | #include <QComboBox> | ||
| 7 | #include <QDebug> | ||
| 8 | #include <QFileDialog> | ||
| 9 | #include <QLabel> | ||
| 10 | #include <QMouseEvent> | ||
| 11 | #include <QPushButton> | ||
| 12 | #include <QScrollArea> | ||
| 13 | #include <QSpinBox> | ||
| 14 | #include "citra_qt/debugger/graphics/graphics_surface.h" | ||
| 15 | #include "citra_qt/util/spinbox.h" | ||
| 16 | #include "common/color.h" | ||
| 17 | #include "core/hw/gpu.h" | ||
| 18 | #include "core/memory.h" | ||
| 19 | #include "video_core/pica_state.h" | ||
| 20 | #include "video_core/regs_framebuffer.h" | ||
| 21 | #include "video_core/regs_texturing.h" | ||
| 22 | #include "video_core/texture/texture_decode.h" | ||
| 23 | #include "video_core/utils.h" | ||
| 24 | |||
| 25 | SurfacePicture::SurfacePicture(QWidget* parent, GraphicsSurfaceWidget* surface_widget_) | ||
| 26 | : QLabel(parent), surface_widget(surface_widget_) {} | ||
| 27 | SurfacePicture::~SurfacePicture() {} | ||
| 28 | |||
| 29 | void SurfacePicture::mousePressEvent(QMouseEvent* event) { | ||
| 30 | // Only do something while the left mouse button is held down | ||
| 31 | if (!(event->buttons() & Qt::LeftButton)) | ||
| 32 | return; | ||
| 33 | |||
| 34 | if (pixmap() == nullptr) | ||
| 35 | return; | ||
| 36 | |||
| 37 | if (surface_widget) | ||
| 38 | surface_widget->Pick(event->x() * pixmap()->width() / width(), | ||
| 39 | event->y() * pixmap()->height() / height()); | ||
| 40 | } | ||
| 41 | |||
| 42 | void SurfacePicture::mouseMoveEvent(QMouseEvent* event) { | ||
| 43 | // We also want to handle the event if the user moves the mouse while holding down the LMB | ||
| 44 | mousePressEvent(event); | ||
| 45 | } | ||
| 46 | |||
| 47 | GraphicsSurfaceWidget::GraphicsSurfaceWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 48 | QWidget* parent) | ||
| 49 | : BreakPointObserverDock(debug_context, tr("Pica Surface Viewer"), parent), | ||
| 50 | surface_source(Source::ColorBuffer) { | ||
| 51 | setObjectName("PicaSurface"); | ||
| 52 | |||
| 53 | surface_source_list = new QComboBox; | ||
| 54 | surface_source_list->addItem(tr("Color Buffer")); | ||
| 55 | surface_source_list->addItem(tr("Depth Buffer")); | ||
| 56 | surface_source_list->addItem(tr("Stencil Buffer")); | ||
| 57 | surface_source_list->addItem(tr("Texture 0")); | ||
| 58 | surface_source_list->addItem(tr("Texture 1")); | ||
| 59 | surface_source_list->addItem(tr("Texture 2")); | ||
| 60 | surface_source_list->addItem(tr("Custom")); | ||
| 61 | surface_source_list->setCurrentIndex(static_cast<int>(surface_source)); | ||
| 62 | |||
| 63 | surface_address_control = new CSpinBox; | ||
| 64 | surface_address_control->SetBase(16); | ||
| 65 | surface_address_control->SetRange(0, 0xFFFFFFFF); | ||
| 66 | surface_address_control->SetPrefix("0x"); | ||
| 67 | |||
| 68 | unsigned max_dimension = 16384; // TODO: Find actual maximum | ||
| 69 | |||
| 70 | surface_width_control = new QSpinBox; | ||
| 71 | surface_width_control->setRange(0, max_dimension); | ||
| 72 | |||
| 73 | surface_height_control = new QSpinBox; | ||
| 74 | surface_height_control->setRange(0, max_dimension); | ||
| 75 | |||
| 76 | surface_picker_x_control = new QSpinBox; | ||
| 77 | surface_picker_x_control->setRange(0, max_dimension - 1); | ||
| 78 | |||
| 79 | surface_picker_y_control = new QSpinBox; | ||
| 80 | surface_picker_y_control->setRange(0, max_dimension - 1); | ||
| 81 | |||
| 82 | surface_format_control = new QComboBox; | ||
| 83 | |||
| 84 | // Color formats sorted by Pica texture format index | ||
| 85 | surface_format_control->addItem(tr("RGBA8")); | ||
| 86 | surface_format_control->addItem(tr("RGB8")); | ||
| 87 | surface_format_control->addItem(tr("RGB5A1")); | ||
| 88 | surface_format_control->addItem(tr("RGB565")); | ||
| 89 | surface_format_control->addItem(tr("RGBA4")); | ||
| 90 | surface_format_control->addItem(tr("IA8")); | ||
| 91 | surface_format_control->addItem(tr("RG8")); | ||
| 92 | surface_format_control->addItem(tr("I8")); | ||
| 93 | surface_format_control->addItem(tr("A8")); | ||
| 94 | surface_format_control->addItem(tr("IA4")); | ||
| 95 | surface_format_control->addItem(tr("I4")); | ||
| 96 | surface_format_control->addItem(tr("A4")); | ||
| 97 | surface_format_control->addItem(tr("ETC1")); | ||
| 98 | surface_format_control->addItem(tr("ETC1A4")); | ||
| 99 | surface_format_control->addItem(tr("D16")); | ||
| 100 | surface_format_control->addItem(tr("D24")); | ||
| 101 | surface_format_control->addItem(tr("D24X8")); | ||
| 102 | surface_format_control->addItem(tr("X24S8")); | ||
| 103 | surface_format_control->addItem(tr("Unknown")); | ||
| 104 | |||
| 105 | surface_info_label = new QLabel(); | ||
| 106 | surface_info_label->setWordWrap(true); | ||
| 107 | |||
| 108 | surface_picture_label = new SurfacePicture(0, this); | ||
| 109 | surface_picture_label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); | ||
| 110 | surface_picture_label->setAlignment(Qt::AlignLeft | Qt::AlignTop); | ||
| 111 | surface_picture_label->setScaledContents(false); | ||
| 112 | |||
| 113 | auto scroll_area = new QScrollArea(); | ||
| 114 | scroll_area->setBackgroundRole(QPalette::Dark); | ||
| 115 | scroll_area->setWidgetResizable(false); | ||
| 116 | scroll_area->setWidget(surface_picture_label); | ||
| 117 | |||
| 118 | save_surface = new QPushButton(QIcon::fromTheme("document-save"), tr("Save")); | ||
| 119 | |||
| 120 | // Connections | ||
| 121 | connect(this, SIGNAL(Update()), this, SLOT(OnUpdate())); | ||
| 122 | connect(surface_source_list, SIGNAL(currentIndexChanged(int)), this, | ||
| 123 | SLOT(OnSurfaceSourceChanged(int))); | ||
| 124 | connect(surface_address_control, SIGNAL(ValueChanged(qint64)), this, | ||
| 125 | SLOT(OnSurfaceAddressChanged(qint64))); | ||
| 126 | connect(surface_width_control, SIGNAL(valueChanged(int)), this, | ||
| 127 | SLOT(OnSurfaceWidthChanged(int))); | ||
| 128 | connect(surface_height_control, SIGNAL(valueChanged(int)), this, | ||
| 129 | SLOT(OnSurfaceHeightChanged(int))); | ||
| 130 | connect(surface_format_control, SIGNAL(currentIndexChanged(int)), this, | ||
| 131 | SLOT(OnSurfaceFormatChanged(int))); | ||
| 132 | connect(surface_picker_x_control, SIGNAL(valueChanged(int)), this, | ||
| 133 | SLOT(OnSurfacePickerXChanged(int))); | ||
| 134 | connect(surface_picker_y_control, SIGNAL(valueChanged(int)), this, | ||
| 135 | SLOT(OnSurfacePickerYChanged(int))); | ||
| 136 | connect(save_surface, SIGNAL(clicked()), this, SLOT(SaveSurface())); | ||
| 137 | |||
| 138 | auto main_widget = new QWidget; | ||
| 139 | auto main_layout = new QVBoxLayout; | ||
| 140 | { | ||
| 141 | auto sub_layout = new QHBoxLayout; | ||
| 142 | sub_layout->addWidget(new QLabel(tr("Source:"))); | ||
| 143 | sub_layout->addWidget(surface_source_list); | ||
| 144 | main_layout->addLayout(sub_layout); | ||
| 145 | } | ||
| 146 | { | ||
| 147 | auto sub_layout = new QHBoxLayout; | ||
| 148 | sub_layout->addWidget(new QLabel(tr("Physical Address:"))); | ||
| 149 | sub_layout->addWidget(surface_address_control); | ||
| 150 | main_layout->addLayout(sub_layout); | ||
| 151 | } | ||
| 152 | { | ||
| 153 | auto sub_layout = new QHBoxLayout; | ||
| 154 | sub_layout->addWidget(new QLabel(tr("Width:"))); | ||
| 155 | sub_layout->addWidget(surface_width_control); | ||
| 156 | main_layout->addLayout(sub_layout); | ||
| 157 | } | ||
| 158 | { | ||
| 159 | auto sub_layout = new QHBoxLayout; | ||
| 160 | sub_layout->addWidget(new QLabel(tr("Height:"))); | ||
| 161 | sub_layout->addWidget(surface_height_control); | ||
| 162 | main_layout->addLayout(sub_layout); | ||
| 163 | } | ||
| 164 | { | ||
| 165 | auto sub_layout = new QHBoxLayout; | ||
| 166 | sub_layout->addWidget(new QLabel(tr("Format:"))); | ||
| 167 | sub_layout->addWidget(surface_format_control); | ||
| 168 | main_layout->addLayout(sub_layout); | ||
| 169 | } | ||
| 170 | main_layout->addWidget(scroll_area); | ||
| 171 | |||
| 172 | auto info_layout = new QHBoxLayout; | ||
| 173 | { | ||
| 174 | auto xy_layout = new QVBoxLayout; | ||
| 175 | { | ||
| 176 | { | ||
| 177 | auto sub_layout = new QHBoxLayout; | ||
| 178 | sub_layout->addWidget(new QLabel(tr("X:"))); | ||
| 179 | sub_layout->addWidget(surface_picker_x_control); | ||
| 180 | xy_layout->addLayout(sub_layout); | ||
| 181 | } | ||
| 182 | { | ||
| 183 | auto sub_layout = new QHBoxLayout; | ||
| 184 | sub_layout->addWidget(new QLabel(tr("Y:"))); | ||
| 185 | sub_layout->addWidget(surface_picker_y_control); | ||
| 186 | xy_layout->addLayout(sub_layout); | ||
| 187 | } | ||
| 188 | } | ||
| 189 | info_layout->addLayout(xy_layout); | ||
| 190 | surface_info_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); | ||
| 191 | info_layout->addWidget(surface_info_label); | ||
| 192 | } | ||
| 193 | main_layout->addLayout(info_layout); | ||
| 194 | |||
| 195 | main_layout->addWidget(save_surface); | ||
| 196 | main_widget->setLayout(main_layout); | ||
| 197 | setWidget(main_widget); | ||
| 198 | |||
| 199 | // Load current data - TODO: Make sure this works when emulation is not running | ||
| 200 | if (debug_context && debug_context->at_breakpoint) { | ||
| 201 | emit Update(); | ||
| 202 | widget()->setEnabled(debug_context->at_breakpoint); | ||
| 203 | } else { | ||
| 204 | widget()->setEnabled(false); | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | void GraphicsSurfaceWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) { | ||
| 209 | emit Update(); | ||
| 210 | widget()->setEnabled(true); | ||
| 211 | } | ||
| 212 | |||
| 213 | void GraphicsSurfaceWidget::OnResumed() { | ||
| 214 | widget()->setEnabled(false); | ||
| 215 | } | ||
| 216 | |||
| 217 | void GraphicsSurfaceWidget::OnSurfaceSourceChanged(int new_value) { | ||
| 218 | surface_source = static_cast<Source>(new_value); | ||
| 219 | emit Update(); | ||
| 220 | } | ||
| 221 | |||
| 222 | void GraphicsSurfaceWidget::OnSurfaceAddressChanged(qint64 new_value) { | ||
| 223 | if (surface_address != new_value) { | ||
| 224 | surface_address = static_cast<unsigned>(new_value); | ||
| 225 | |||
| 226 | surface_source_list->setCurrentIndex(static_cast<int>(Source::Custom)); | ||
| 227 | emit Update(); | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | void GraphicsSurfaceWidget::OnSurfaceWidthChanged(int new_value) { | ||
| 232 | if (surface_width != static_cast<unsigned>(new_value)) { | ||
| 233 | surface_width = static_cast<unsigned>(new_value); | ||
| 234 | |||
| 235 | surface_source_list->setCurrentIndex(static_cast<int>(Source::Custom)); | ||
| 236 | emit Update(); | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | void GraphicsSurfaceWidget::OnSurfaceHeightChanged(int new_value) { | ||
| 241 | if (surface_height != static_cast<unsigned>(new_value)) { | ||
| 242 | surface_height = static_cast<unsigned>(new_value); | ||
| 243 | |||
| 244 | surface_source_list->setCurrentIndex(static_cast<int>(Source::Custom)); | ||
| 245 | emit Update(); | ||
| 246 | } | ||
| 247 | } | ||
| 248 | |||
| 249 | void GraphicsSurfaceWidget::OnSurfaceFormatChanged(int new_value) { | ||
| 250 | if (surface_format != static_cast<Format>(new_value)) { | ||
| 251 | surface_format = static_cast<Format>(new_value); | ||
| 252 | |||
| 253 | surface_source_list->setCurrentIndex(static_cast<int>(Source::Custom)); | ||
| 254 | emit Update(); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | void GraphicsSurfaceWidget::OnSurfacePickerXChanged(int new_value) { | ||
| 259 | if (surface_picker_x != new_value) { | ||
| 260 | surface_picker_x = new_value; | ||
| 261 | Pick(surface_picker_x, surface_picker_y); | ||
| 262 | } | ||
| 263 | } | ||
| 264 | |||
| 265 | void GraphicsSurfaceWidget::OnSurfacePickerYChanged(int new_value) { | ||
| 266 | if (surface_picker_y != new_value) { | ||
| 267 | surface_picker_y = new_value; | ||
| 268 | Pick(surface_picker_x, surface_picker_y); | ||
| 269 | } | ||
| 270 | } | ||
| 271 | |||
| 272 | void GraphicsSurfaceWidget::Pick(int x, int y) { | ||
| 273 | surface_picker_x_control->setValue(x); | ||
| 274 | surface_picker_y_control->setValue(y); | ||
| 275 | |||
| 276 | if (x < 0 || x >= static_cast<int>(surface_width) || y < 0 || | ||
| 277 | y >= static_cast<int>(surface_height)) { | ||
| 278 | surface_info_label->setText(tr("Pixel out of bounds")); | ||
| 279 | surface_info_label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | ||
| 280 | return; | ||
| 281 | } | ||
| 282 | |||
| 283 | u8* buffer = Memory::GetPhysicalPointer(surface_address); | ||
| 284 | if (buffer == nullptr) { | ||
| 285 | surface_info_label->setText(tr("(unable to access pixel data)")); | ||
| 286 | surface_info_label->setAlignment(Qt::AlignCenter); | ||
| 287 | return; | ||
| 288 | } | ||
| 289 | |||
| 290 | unsigned nibbles_per_pixel = GraphicsSurfaceWidget::NibblesPerPixel(surface_format); | ||
| 291 | unsigned stride = nibbles_per_pixel * surface_width / 2; | ||
| 292 | |||
| 293 | unsigned bytes_per_pixel; | ||
| 294 | bool nibble_mode = (nibbles_per_pixel == 1); | ||
| 295 | if (nibble_mode) { | ||
| 296 | // As nibbles are contained in a byte we still need to access one byte per nibble | ||
| 297 | bytes_per_pixel = 1; | ||
| 298 | } else { | ||
| 299 | bytes_per_pixel = nibbles_per_pixel / 2; | ||
| 300 | } | ||
| 301 | |||
| 302 | const u32 coarse_y = y & ~7; | ||
| 303 | u32 offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride; | ||
| 304 | const u8* pixel = buffer + (nibble_mode ? (offset / 2) : offset); | ||
| 305 | |||
| 306 | auto GetText = [offset](Format format, const u8* pixel) { | ||
| 307 | switch (format) { | ||
| 308 | case Format::RGBA8: { | ||
| 309 | auto value = Color::DecodeRGBA8(pixel) / 255.0f; | ||
| 310 | return QString("Red: %1, Green: %2, Blue: %3, Alpha: %4") | ||
| 311 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 312 | .arg(QString::number(value.g(), 'f', 2)) | ||
| 313 | .arg(QString::number(value.b(), 'f', 2)) | ||
| 314 | .arg(QString::number(value.a(), 'f', 2)); | ||
| 315 | } | ||
| 316 | case Format::RGB8: { | ||
| 317 | auto value = Color::DecodeRGB8(pixel) / 255.0f; | ||
| 318 | return QString("Red: %1, Green: %2, Blue: %3") | ||
| 319 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 320 | .arg(QString::number(value.g(), 'f', 2)) | ||
| 321 | .arg(QString::number(value.b(), 'f', 2)); | ||
| 322 | } | ||
| 323 | case Format::RGB5A1: { | ||
| 324 | auto value = Color::DecodeRGB5A1(pixel) / 255.0f; | ||
| 325 | return QString("Red: %1, Green: %2, Blue: %3, Alpha: %4") | ||
| 326 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 327 | .arg(QString::number(value.g(), 'f', 2)) | ||
| 328 | .arg(QString::number(value.b(), 'f', 2)) | ||
| 329 | .arg(QString::number(value.a(), 'f', 2)); | ||
| 330 | } | ||
| 331 | case Format::RGB565: { | ||
| 332 | auto value = Color::DecodeRGB565(pixel) / 255.0f; | ||
| 333 | return QString("Red: %1, Green: %2, Blue: %3") | ||
| 334 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 335 | .arg(QString::number(value.g(), 'f', 2)) | ||
| 336 | .arg(QString::number(value.b(), 'f', 2)); | ||
| 337 | } | ||
| 338 | case Format::RGBA4: { | ||
| 339 | auto value = Color::DecodeRGBA4(pixel) / 255.0f; | ||
| 340 | return QString("Red: %1, Green: %2, Blue: %3, Alpha: %4") | ||
| 341 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 342 | .arg(QString::number(value.g(), 'f', 2)) | ||
| 343 | .arg(QString::number(value.b(), 'f', 2)) | ||
| 344 | .arg(QString::number(value.a(), 'f', 2)); | ||
| 345 | } | ||
| 346 | case Format::IA8: | ||
| 347 | return QString("Index: %1, Alpha: %2").arg(pixel[0]).arg(pixel[1]); | ||
| 348 | case Format::RG8: { | ||
| 349 | auto value = Color::DecodeRG8(pixel) / 255.0f; | ||
| 350 | return QString("Red: %1, Green: %2") | ||
| 351 | .arg(QString::number(value.r(), 'f', 2)) | ||
| 352 | .arg(QString::number(value.g(), 'f', 2)); | ||
| 353 | } | ||
| 354 | case Format::I8: | ||
| 355 | return QString("Index: %1").arg(*pixel); | ||
| 356 | case Format::A8: | ||
| 357 | return QString("Alpha: %1").arg(QString::number(*pixel / 255.0f, 'f', 2)); | ||
| 358 | case Format::IA4: | ||
| 359 | return QString("Index: %1, Alpha: %2").arg(*pixel & 0xF).arg((*pixel & 0xF0) >> 4); | ||
| 360 | case Format::I4: { | ||
| 361 | u8 i = (*pixel >> ((offset % 2) ? 4 : 0)) & 0xF; | ||
| 362 | return QString("Index: %1").arg(i); | ||
| 363 | } | ||
| 364 | case Format::A4: { | ||
| 365 | u8 a = (*pixel >> ((offset % 2) ? 4 : 0)) & 0xF; | ||
| 366 | return QString("Alpha: %1").arg(QString::number(a / 15.0f, 'f', 2)); | ||
| 367 | } | ||
| 368 | case Format::ETC1: | ||
| 369 | case Format::ETC1A4: | ||
| 370 | // TODO: Display block information or channel values? | ||
| 371 | return QString("Compressed data"); | ||
| 372 | case Format::D16: { | ||
| 373 | auto value = Color::DecodeD16(pixel); | ||
| 374 | return QString("Depth: %1").arg(QString::number(value / (float)0xFFFF, 'f', 4)); | ||
| 375 | } | ||
| 376 | case Format::D24: { | ||
| 377 | auto value = Color::DecodeD24(pixel); | ||
| 378 | return QString("Depth: %1").arg(QString::number(value / (float)0xFFFFFF, 'f', 4)); | ||
| 379 | } | ||
| 380 | case Format::D24X8: | ||
| 381 | case Format::X24S8: { | ||
| 382 | auto values = Color::DecodeD24S8(pixel); | ||
| 383 | return QString("Depth: %1, Stencil: %2") | ||
| 384 | .arg(QString::number(values[0] / (float)0xFFFFFF, 'f', 4)) | ||
| 385 | .arg(values[1]); | ||
| 386 | } | ||
| 387 | case Format::Unknown: | ||
| 388 | return QString("Unknown format"); | ||
| 389 | default: | ||
| 390 | return QString("Unhandled format"); | ||
| 391 | } | ||
| 392 | return QString(""); | ||
| 393 | }; | ||
| 394 | |||
| 395 | QString nibbles = ""; | ||
| 396 | for (unsigned i = 0; i < nibbles_per_pixel; i++) { | ||
| 397 | unsigned nibble_index = i; | ||
| 398 | if (nibble_mode) { | ||
| 399 | nibble_index += (offset % 2) ? 0 : 1; | ||
| 400 | } | ||
| 401 | u8 byte = pixel[nibble_index / 2]; | ||
| 402 | u8 nibble = (byte >> ((nibble_index % 2) ? 0 : 4)) & 0xF; | ||
| 403 | nibbles.append(QString::number(nibble, 16).toUpper()); | ||
| 404 | } | ||
| 405 | |||
| 406 | surface_info_label->setText( | ||
| 407 | QString("Raw: 0x%3\n(%4)").arg(nibbles).arg(GetText(surface_format, pixel))); | ||
| 408 | surface_info_label->setAlignment(Qt::AlignLeft | Qt::AlignVCenter); | ||
| 409 | } | ||
| 410 | |||
| 411 | void GraphicsSurfaceWidget::OnUpdate() { | ||
| 412 | QPixmap pixmap; | ||
| 413 | |||
| 414 | switch (surface_source) { | ||
| 415 | case Source::ColorBuffer: { | ||
| 416 | // TODO: Store a reference to the registers in the debug context instead of accessing them | ||
| 417 | // directly... | ||
| 418 | |||
| 419 | const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer; | ||
| 420 | |||
| 421 | surface_address = framebuffer.GetColorBufferPhysicalAddress(); | ||
| 422 | surface_width = framebuffer.GetWidth(); | ||
| 423 | surface_height = framebuffer.GetHeight(); | ||
| 424 | |||
| 425 | switch (framebuffer.color_format) { | ||
| 426 | case Pica::FramebufferRegs::ColorFormat::RGBA8: | ||
| 427 | surface_format = Format::RGBA8; | ||
| 428 | break; | ||
| 429 | |||
| 430 | case Pica::FramebufferRegs::ColorFormat::RGB8: | ||
| 431 | surface_format = Format::RGB8; | ||
| 432 | break; | ||
| 433 | |||
| 434 | case Pica::FramebufferRegs::ColorFormat::RGB5A1: | ||
| 435 | surface_format = Format::RGB5A1; | ||
| 436 | break; | ||
| 437 | |||
| 438 | case Pica::FramebufferRegs::ColorFormat::RGB565: | ||
| 439 | surface_format = Format::RGB565; | ||
| 440 | break; | ||
| 441 | |||
| 442 | case Pica::FramebufferRegs::ColorFormat::RGBA4: | ||
| 443 | surface_format = Format::RGBA4; | ||
| 444 | break; | ||
| 445 | |||
| 446 | default: | ||
| 447 | surface_format = Format::Unknown; | ||
| 448 | break; | ||
| 449 | } | ||
| 450 | |||
| 451 | break; | ||
| 452 | } | ||
| 453 | |||
| 454 | case Source::DepthBuffer: { | ||
| 455 | const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer; | ||
| 456 | |||
| 457 | surface_address = framebuffer.GetDepthBufferPhysicalAddress(); | ||
| 458 | surface_width = framebuffer.GetWidth(); | ||
| 459 | surface_height = framebuffer.GetHeight(); | ||
| 460 | |||
| 461 | switch (framebuffer.depth_format) { | ||
| 462 | case Pica::FramebufferRegs::DepthFormat::D16: | ||
| 463 | surface_format = Format::D16; | ||
| 464 | break; | ||
| 465 | |||
| 466 | case Pica::FramebufferRegs::DepthFormat::D24: | ||
| 467 | surface_format = Format::D24; | ||
| 468 | break; | ||
| 469 | |||
| 470 | case Pica::FramebufferRegs::DepthFormat::D24S8: | ||
| 471 | surface_format = Format::D24X8; | ||
| 472 | break; | ||
| 473 | |||
| 474 | default: | ||
| 475 | surface_format = Format::Unknown; | ||
| 476 | break; | ||
| 477 | } | ||
| 478 | |||
| 479 | break; | ||
| 480 | } | ||
| 481 | |||
| 482 | case Source::StencilBuffer: { | ||
| 483 | const auto& framebuffer = Pica::g_state.regs.framebuffer.framebuffer; | ||
| 484 | |||
| 485 | surface_address = framebuffer.GetDepthBufferPhysicalAddress(); | ||
| 486 | surface_width = framebuffer.GetWidth(); | ||
| 487 | surface_height = framebuffer.GetHeight(); | ||
| 488 | |||
| 489 | switch (framebuffer.depth_format) { | ||
| 490 | case Pica::FramebufferRegs::DepthFormat::D24S8: | ||
| 491 | surface_format = Format::X24S8; | ||
| 492 | break; | ||
| 493 | |||
| 494 | default: | ||
| 495 | surface_format = Format::Unknown; | ||
| 496 | break; | ||
| 497 | } | ||
| 498 | |||
| 499 | break; | ||
| 500 | } | ||
| 501 | |||
| 502 | case Source::Texture0: | ||
| 503 | case Source::Texture1: | ||
| 504 | case Source::Texture2: { | ||
| 505 | unsigned texture_index; | ||
| 506 | if (surface_source == Source::Texture0) | ||
| 507 | texture_index = 0; | ||
| 508 | else if (surface_source == Source::Texture1) | ||
| 509 | texture_index = 1; | ||
| 510 | else if (surface_source == Source::Texture2) | ||
| 511 | texture_index = 2; | ||
| 512 | else { | ||
| 513 | qDebug() << "Unknown texture source " << static_cast<int>(surface_source); | ||
| 514 | break; | ||
| 515 | } | ||
| 516 | |||
| 517 | const auto texture = Pica::g_state.regs.texturing.GetTextures()[texture_index]; | ||
| 518 | auto info = Pica::Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); | ||
| 519 | |||
| 520 | surface_address = info.physical_address; | ||
| 521 | surface_width = info.width; | ||
| 522 | surface_height = info.height; | ||
| 523 | surface_format = static_cast<Format>(info.format); | ||
| 524 | |||
| 525 | if (surface_format > Format::MaxTextureFormat) { | ||
| 526 | qDebug() << "Unknown texture format " << static_cast<int>(info.format); | ||
| 527 | } | ||
| 528 | break; | ||
| 529 | } | ||
| 530 | |||
| 531 | case Source::Custom: { | ||
| 532 | // Keep user-specified values | ||
| 533 | break; | ||
| 534 | } | ||
| 535 | |||
| 536 | default: | ||
| 537 | qDebug() << "Unknown surface source " << static_cast<int>(surface_source); | ||
| 538 | break; | ||
| 539 | } | ||
| 540 | |||
| 541 | surface_address_control->SetValue(surface_address); | ||
| 542 | surface_width_control->setValue(surface_width); | ||
| 543 | surface_height_control->setValue(surface_height); | ||
| 544 | surface_format_control->setCurrentIndex(static_cast<int>(surface_format)); | ||
| 545 | |||
| 546 | // TODO: Implement a good way to visualize alpha components! | ||
| 547 | |||
| 548 | QImage decoded_image(surface_width, surface_height, QImage::Format_ARGB32); | ||
| 549 | u8* buffer = Memory::GetPhysicalPointer(surface_address); | ||
| 550 | |||
| 551 | if (buffer == nullptr) { | ||
| 552 | surface_picture_label->hide(); | ||
| 553 | surface_info_label->setText(tr("(invalid surface address)")); | ||
| 554 | surface_info_label->setAlignment(Qt::AlignCenter); | ||
| 555 | surface_picker_x_control->setEnabled(false); | ||
| 556 | surface_picker_y_control->setEnabled(false); | ||
| 557 | save_surface->setEnabled(false); | ||
| 558 | return; | ||
| 559 | } | ||
| 560 | |||
| 561 | if (surface_format == Format::Unknown) { | ||
| 562 | surface_picture_label->hide(); | ||
| 563 | surface_info_label->setText(tr("(unknown surface format)")); | ||
| 564 | surface_info_label->setAlignment(Qt::AlignCenter); | ||
| 565 | surface_picker_x_control->setEnabled(false); | ||
| 566 | surface_picker_y_control->setEnabled(false); | ||
| 567 | save_surface->setEnabled(false); | ||
| 568 | return; | ||
| 569 | } | ||
| 570 | |||
| 571 | surface_picture_label->show(); | ||
| 572 | |||
| 573 | if (surface_format <= Format::MaxTextureFormat) { | ||
| 574 | // Generate a virtual texture | ||
| 575 | Pica::Texture::TextureInfo info; | ||
| 576 | info.physical_address = surface_address; | ||
| 577 | info.width = surface_width; | ||
| 578 | info.height = surface_height; | ||
| 579 | info.format = static_cast<Pica::TexturingRegs::TextureFormat>(surface_format); | ||
| 580 | info.SetDefaultStride(); | ||
| 581 | |||
| 582 | for (unsigned int y = 0; y < surface_height; ++y) { | ||
| 583 | for (unsigned int x = 0; x < surface_width; ++x) { | ||
| 584 | Math::Vec4<u8> color = Pica::Texture::LookupTexture(buffer, x, y, info, true); | ||
| 585 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | ||
| 586 | } | ||
| 587 | } | ||
| 588 | } else { | ||
| 589 | // We handle depth formats here because DebugUtils only supports TextureFormats | ||
| 590 | |||
| 591 | // TODO(yuriks): Convert to newer tile-based addressing | ||
| 592 | unsigned nibbles_per_pixel = GraphicsSurfaceWidget::NibblesPerPixel(surface_format); | ||
| 593 | unsigned stride = nibbles_per_pixel * surface_width / 2; | ||
| 594 | |||
| 595 | ASSERT_MSG(nibbles_per_pixel >= 2, | ||
| 596 | "Depth decoder only supports formats with at least one byte per pixel"); | ||
| 597 | unsigned bytes_per_pixel = nibbles_per_pixel / 2; | ||
| 598 | |||
| 599 | for (unsigned int y = 0; y < surface_height; ++y) { | ||
| 600 | for (unsigned int x = 0; x < surface_width; ++x) { | ||
| 601 | const u32 coarse_y = y & ~7; | ||
| 602 | u32 offset = VideoCore::GetMortonOffset(x, y, bytes_per_pixel) + coarse_y * stride; | ||
| 603 | const u8* pixel = buffer + offset; | ||
| 604 | Math::Vec4<u8> color = {0, 0, 0, 0}; | ||
| 605 | |||
| 606 | switch (surface_format) { | ||
| 607 | case Format::D16: { | ||
| 608 | u32 data = Color::DecodeD16(pixel); | ||
| 609 | color.r() = data & 0xFF; | ||
| 610 | color.g() = (data >> 8) & 0xFF; | ||
| 611 | break; | ||
| 612 | } | ||
| 613 | case Format::D24: { | ||
| 614 | u32 data = Color::DecodeD24(pixel); | ||
| 615 | color.r() = data & 0xFF; | ||
| 616 | color.g() = (data >> 8) & 0xFF; | ||
| 617 | color.b() = (data >> 16) & 0xFF; | ||
| 618 | break; | ||
| 619 | } | ||
| 620 | case Format::D24X8: { | ||
| 621 | Math::Vec2<u32> data = Color::DecodeD24S8(pixel); | ||
| 622 | color.r() = data.x & 0xFF; | ||
| 623 | color.g() = (data.x >> 8) & 0xFF; | ||
| 624 | color.b() = (data.x >> 16) & 0xFF; | ||
| 625 | break; | ||
| 626 | } | ||
| 627 | case Format::X24S8: { | ||
| 628 | Math::Vec2<u32> data = Color::DecodeD24S8(pixel); | ||
| 629 | color.r() = color.g() = color.b() = data.y; | ||
| 630 | break; | ||
| 631 | } | ||
| 632 | default: | ||
| 633 | qDebug() << "Unknown surface format " << static_cast<int>(surface_format); | ||
| 634 | break; | ||
| 635 | } | ||
| 636 | |||
| 637 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), 255)); | ||
| 638 | } | ||
| 639 | } | ||
| 640 | } | ||
| 641 | |||
| 642 | pixmap = QPixmap::fromImage(decoded_image); | ||
| 643 | surface_picture_label->setPixmap(pixmap); | ||
| 644 | surface_picture_label->resize(pixmap.size()); | ||
| 645 | |||
| 646 | // Update the info with pixel data | ||
| 647 | surface_picker_x_control->setEnabled(true); | ||
| 648 | surface_picker_y_control->setEnabled(true); | ||
| 649 | Pick(surface_picker_x, surface_picker_y); | ||
| 650 | |||
| 651 | // Enable saving the converted pixmap to file | ||
| 652 | save_surface->setEnabled(true); | ||
| 653 | } | ||
| 654 | |||
| 655 | void GraphicsSurfaceWidget::SaveSurface() { | ||
| 656 | QString png_filter = tr("Portable Network Graphic (*.png)"); | ||
| 657 | QString bin_filter = tr("Binary data (*.bin)"); | ||
| 658 | |||
| 659 | QString selectedFilter; | ||
| 660 | QString filename = QFileDialog::getSaveFileName( | ||
| 661 | this, tr("Save Surface"), | ||
| 662 | QString("texture-0x%1.png").arg(QString::number(surface_address, 16)), | ||
| 663 | QString("%1;;%2").arg(png_filter, bin_filter), &selectedFilter); | ||
| 664 | |||
| 665 | if (filename.isEmpty()) { | ||
| 666 | // If the user canceled the dialog, don't save anything. | ||
| 667 | return; | ||
| 668 | } | ||
| 669 | |||
| 670 | if (selectedFilter == png_filter) { | ||
| 671 | const QPixmap* pixmap = surface_picture_label->pixmap(); | ||
| 672 | ASSERT_MSG(pixmap != nullptr, "No pixmap set"); | ||
| 673 | |||
| 674 | QFile file(filename); | ||
| 675 | file.open(QIODevice::WriteOnly); | ||
| 676 | if (pixmap) | ||
| 677 | pixmap->save(&file, "PNG"); | ||
| 678 | } else if (selectedFilter == bin_filter) { | ||
| 679 | const u8* buffer = Memory::GetPhysicalPointer(surface_address); | ||
| 680 | ASSERT_MSG(buffer != nullptr, "Memory not accessible"); | ||
| 681 | |||
| 682 | QFile file(filename); | ||
| 683 | file.open(QIODevice::WriteOnly); | ||
| 684 | int size = surface_width * surface_height * NibblesPerPixel(surface_format) / 2; | ||
| 685 | QByteArray data(reinterpret_cast<const char*>(buffer), size); | ||
| 686 | file.write(data); | ||
| 687 | } else { | ||
| 688 | UNREACHABLE_MSG("Unhandled filter selected"); | ||
| 689 | } | ||
| 690 | } | ||
| 691 | |||
| 692 | unsigned int GraphicsSurfaceWidget::NibblesPerPixel(GraphicsSurfaceWidget::Format format) { | ||
| 693 | if (format <= Format::MaxTextureFormat) { | ||
| 694 | return Pica::TexturingRegs::NibblesPerPixel( | ||
| 695 | static_cast<Pica::TexturingRegs::TextureFormat>(format)); | ||
| 696 | } | ||
| 697 | |||
| 698 | switch (format) { | ||
| 699 | case Format::D24X8: | ||
| 700 | case Format::X24S8: | ||
| 701 | return 4 * 2; | ||
| 702 | case Format::D24: | ||
| 703 | return 3 * 2; | ||
| 704 | case Format::D16: | ||
| 705 | return 2 * 2; | ||
| 706 | default: | ||
| 707 | UNREACHABLE_MSG("GraphicsSurfaceWidget::BytesPerPixel: this should not be reached as this " | ||
| 708 | "function should be given a format which is in " | ||
| 709 | "GraphicsSurfaceWidget::Format. Instead got %i", | ||
| 710 | static_cast<int>(format)); | ||
| 711 | return 0; | ||
| 712 | } | ||
| 713 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_surface.h b/src/citra_qt/debugger/graphics/graphics_surface.h deleted file mode 100644 index 28f5650a7..000000000 --- a/src/citra_qt/debugger/graphics/graphics_surface.h +++ /dev/null | |||
| @@ -1,118 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QLabel> | ||
| 8 | #include <QPushButton> | ||
| 9 | #include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h" | ||
| 10 | |||
| 11 | class QComboBox; | ||
| 12 | class QSpinBox; | ||
| 13 | class CSpinBox; | ||
| 14 | |||
| 15 | class GraphicsSurfaceWidget; | ||
| 16 | |||
| 17 | class SurfacePicture : public QLabel { | ||
| 18 | Q_OBJECT | ||
| 19 | |||
| 20 | public: | ||
| 21 | explicit SurfacePicture(QWidget* parent = nullptr, | ||
| 22 | GraphicsSurfaceWidget* surface_widget = nullptr); | ||
| 23 | ~SurfacePicture(); | ||
| 24 | |||
| 25 | protected slots: | ||
| 26 | virtual void mouseMoveEvent(QMouseEvent* event); | ||
| 27 | virtual void mousePressEvent(QMouseEvent* event); | ||
| 28 | |||
| 29 | private: | ||
| 30 | GraphicsSurfaceWidget* surface_widget; | ||
| 31 | }; | ||
| 32 | |||
| 33 | class GraphicsSurfaceWidget : public BreakPointObserverDock { | ||
| 34 | Q_OBJECT | ||
| 35 | |||
| 36 | using Event = Pica::DebugContext::Event; | ||
| 37 | |||
| 38 | enum class Source { | ||
| 39 | ColorBuffer = 0, | ||
| 40 | DepthBuffer = 1, | ||
| 41 | StencilBuffer = 2, | ||
| 42 | Texture0 = 3, | ||
| 43 | Texture1 = 4, | ||
| 44 | Texture2 = 5, | ||
| 45 | Custom = 6, | ||
| 46 | }; | ||
| 47 | |||
| 48 | enum class Format { | ||
| 49 | // These must match the TextureFormat type! | ||
| 50 | RGBA8 = 0, | ||
| 51 | RGB8 = 1, | ||
| 52 | RGB5A1 = 2, | ||
| 53 | RGB565 = 3, | ||
| 54 | RGBA4 = 4, | ||
| 55 | IA8 = 5, | ||
| 56 | RG8 = 6, ///< @note Also called HILO8 in 3DBrew. | ||
| 57 | I8 = 7, | ||
| 58 | A8 = 8, | ||
| 59 | IA4 = 9, | ||
| 60 | I4 = 10, | ||
| 61 | A4 = 11, | ||
| 62 | ETC1 = 12, // compressed | ||
| 63 | ETC1A4 = 13, | ||
| 64 | MaxTextureFormat = 13, | ||
| 65 | D16 = 14, | ||
| 66 | D24 = 15, | ||
| 67 | D24X8 = 16, | ||
| 68 | X24S8 = 17, | ||
| 69 | Unknown = 18, | ||
| 70 | }; | ||
| 71 | |||
| 72 | static unsigned int NibblesPerPixel(Format format); | ||
| 73 | |||
| 74 | public: | ||
| 75 | explicit GraphicsSurfaceWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 76 | QWidget* parent = nullptr); | ||
| 77 | void Pick(int x, int y); | ||
| 78 | |||
| 79 | public slots: | ||
| 80 | void OnSurfaceSourceChanged(int new_value); | ||
| 81 | void OnSurfaceAddressChanged(qint64 new_value); | ||
| 82 | void OnSurfaceWidthChanged(int new_value); | ||
| 83 | void OnSurfaceHeightChanged(int new_value); | ||
| 84 | void OnSurfaceFormatChanged(int new_value); | ||
| 85 | void OnSurfacePickerXChanged(int new_value); | ||
| 86 | void OnSurfacePickerYChanged(int new_value); | ||
| 87 | void OnUpdate(); | ||
| 88 | |||
| 89 | private slots: | ||
| 90 | void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override; | ||
| 91 | void OnResumed() override; | ||
| 92 | |||
| 93 | void SaveSurface(); | ||
| 94 | |||
| 95 | signals: | ||
| 96 | void Update(); | ||
| 97 | |||
| 98 | private: | ||
| 99 | QComboBox* surface_source_list; | ||
| 100 | CSpinBox* surface_address_control; | ||
| 101 | QSpinBox* surface_width_control; | ||
| 102 | QSpinBox* surface_height_control; | ||
| 103 | QComboBox* surface_format_control; | ||
| 104 | |||
| 105 | SurfacePicture* surface_picture_label; | ||
| 106 | QSpinBox* surface_picker_x_control; | ||
| 107 | QSpinBox* surface_picker_y_control; | ||
| 108 | QLabel* surface_info_label; | ||
| 109 | QPushButton* save_surface; | ||
| 110 | |||
| 111 | Source surface_source; | ||
| 112 | unsigned surface_address; | ||
| 113 | unsigned surface_width; | ||
| 114 | unsigned surface_height; | ||
| 115 | Format surface_format; | ||
| 116 | int surface_picker_x = 0; | ||
| 117 | int surface_picker_y = 0; | ||
| 118 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_tracing.cpp b/src/citra_qt/debugger/graphics/graphics_tracing.cpp deleted file mode 100644 index 40d5bed51..000000000 --- a/src/citra_qt/debugger/graphics/graphics_tracing.cpp +++ /dev/null | |||
| @@ -1,177 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <iterator> | ||
| 8 | #include <memory> | ||
| 9 | #include <QBoxLayout> | ||
| 10 | #include <QComboBox> | ||
| 11 | #include <QFileDialog> | ||
| 12 | #include <QMessageBox> | ||
| 13 | #include <QPushButton> | ||
| 14 | #include <boost/range/algorithm/copy.hpp> | ||
| 15 | #include "citra_qt/debugger/graphics/graphics_tracing.h" | ||
| 16 | #include "common/common_types.h" | ||
| 17 | #include "core/hw/gpu.h" | ||
| 18 | #include "core/hw/lcd.h" | ||
| 19 | #include "core/tracer/recorder.h" | ||
| 20 | #include "nihstro/float24.h" | ||
| 21 | #include "video_core/pica_state.h" | ||
| 22 | |||
| 23 | GraphicsTracingWidget::GraphicsTracingWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 24 | QWidget* parent) | ||
| 25 | : BreakPointObserverDock(debug_context, tr("CiTrace Recorder"), parent) { | ||
| 26 | |||
| 27 | setObjectName("CiTracing"); | ||
| 28 | |||
| 29 | QPushButton* start_recording = new QPushButton(tr("Start Recording")); | ||
| 30 | QPushButton* stop_recording = | ||
| 31 | new QPushButton(QIcon::fromTheme("document-save"), tr("Stop and Save")); | ||
| 32 | QPushButton* abort_recording = new QPushButton(tr("Abort Recording")); | ||
| 33 | |||
| 34 | connect(this, SIGNAL(SetStartTracingButtonEnabled(bool)), start_recording, | ||
| 35 | SLOT(setVisible(bool))); | ||
| 36 | connect(this, SIGNAL(SetStopTracingButtonEnabled(bool)), stop_recording, | ||
| 37 | SLOT(setVisible(bool))); | ||
| 38 | connect(this, SIGNAL(SetAbortTracingButtonEnabled(bool)), abort_recording, | ||
| 39 | SLOT(setVisible(bool))); | ||
| 40 | connect(start_recording, SIGNAL(clicked()), this, SLOT(StartRecording())); | ||
| 41 | connect(stop_recording, SIGNAL(clicked()), this, SLOT(StopRecording())); | ||
| 42 | connect(abort_recording, SIGNAL(clicked()), this, SLOT(AbortRecording())); | ||
| 43 | |||
| 44 | stop_recording->setVisible(false); | ||
| 45 | abort_recording->setVisible(false); | ||
| 46 | |||
| 47 | auto main_widget = new QWidget; | ||
| 48 | auto main_layout = new QVBoxLayout; | ||
| 49 | { | ||
| 50 | auto sub_layout = new QHBoxLayout; | ||
| 51 | sub_layout->addWidget(start_recording); | ||
| 52 | sub_layout->addWidget(stop_recording); | ||
| 53 | sub_layout->addWidget(abort_recording); | ||
| 54 | main_layout->addLayout(sub_layout); | ||
| 55 | } | ||
| 56 | main_widget->setLayout(main_layout); | ||
| 57 | setWidget(main_widget); | ||
| 58 | } | ||
| 59 | |||
| 60 | void GraphicsTracingWidget::StartRecording() { | ||
| 61 | auto context = context_weak.lock(); | ||
| 62 | if (!context) | ||
| 63 | return; | ||
| 64 | |||
| 65 | auto shader_binary = Pica::g_state.vs.program_code; | ||
| 66 | auto swizzle_data = Pica::g_state.vs.swizzle_data; | ||
| 67 | |||
| 68 | // Encode floating point numbers to 24-bit values | ||
| 69 | // TODO: Drop this explicit conversion once we store float24 values bit-correctly internally. | ||
| 70 | std::array<u32, 4 * 16> default_attributes; | ||
| 71 | for (unsigned i = 0; i < 16; ++i) { | ||
| 72 | for (unsigned comp = 0; comp < 3; ++comp) { | ||
| 73 | default_attributes[4 * i + comp] = nihstro::to_float24( | ||
| 74 | Pica::g_state.input_default_attributes.attr[i][comp].ToFloat32()); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | std::array<u32, 4 * 96> vs_float_uniforms; | ||
| 79 | for (unsigned i = 0; i < 96; ++i) | ||
| 80 | for (unsigned comp = 0; comp < 3; ++comp) | ||
| 81 | vs_float_uniforms[4 * i + comp] = | ||
| 82 | nihstro::to_float24(Pica::g_state.vs.uniforms.f[i][comp].ToFloat32()); | ||
| 83 | |||
| 84 | CiTrace::Recorder::InitialState state; | ||
| 85 | std::copy_n((u32*)&GPU::g_regs, sizeof(GPU::g_regs) / sizeof(u32), | ||
| 86 | std::back_inserter(state.gpu_registers)); | ||
| 87 | std::copy_n((u32*)&LCD::g_regs, sizeof(LCD::g_regs) / sizeof(u32), | ||
| 88 | std::back_inserter(state.lcd_registers)); | ||
| 89 | std::copy_n((u32*)&Pica::g_state.regs, sizeof(Pica::g_state.regs) / sizeof(u32), | ||
| 90 | std::back_inserter(state.pica_registers)); | ||
| 91 | boost::copy(default_attributes, std::back_inserter(state.default_attributes)); | ||
| 92 | boost::copy(shader_binary, std::back_inserter(state.vs_program_binary)); | ||
| 93 | boost::copy(swizzle_data, std::back_inserter(state.vs_swizzle_data)); | ||
| 94 | boost::copy(vs_float_uniforms, std::back_inserter(state.vs_float_uniforms)); | ||
| 95 | // boost::copy(TODO: Not implemented, std::back_inserter(state.gs_program_binary)); | ||
| 96 | // boost::copy(TODO: Not implemented, std::back_inserter(state.gs_swizzle_data)); | ||
| 97 | // boost::copy(TODO: Not implemented, std::back_inserter(state.gs_float_uniforms)); | ||
| 98 | |||
| 99 | auto recorder = new CiTrace::Recorder(state); | ||
| 100 | context->recorder = std::shared_ptr<CiTrace::Recorder>(recorder); | ||
| 101 | |||
| 102 | emit SetStartTracingButtonEnabled(false); | ||
| 103 | emit SetStopTracingButtonEnabled(true); | ||
| 104 | emit SetAbortTracingButtonEnabled(true); | ||
| 105 | } | ||
| 106 | |||
| 107 | void GraphicsTracingWidget::StopRecording() { | ||
| 108 | auto context = context_weak.lock(); | ||
| 109 | if (!context) | ||
| 110 | return; | ||
| 111 | |||
| 112 | QString filename = QFileDialog::getSaveFileName(this, tr("Save CiTrace"), "citrace.ctf", | ||
| 113 | tr("CiTrace File (*.ctf)")); | ||
| 114 | |||
| 115 | if (filename.isEmpty()) { | ||
| 116 | // If the user canceled the dialog, keep recording | ||
| 117 | return; | ||
| 118 | } | ||
| 119 | |||
| 120 | context->recorder->Finish(filename.toStdString()); | ||
| 121 | context->recorder = nullptr; | ||
| 122 | |||
| 123 | emit SetStopTracingButtonEnabled(false); | ||
| 124 | emit SetAbortTracingButtonEnabled(false); | ||
| 125 | emit SetStartTracingButtonEnabled(true); | ||
| 126 | } | ||
| 127 | |||
| 128 | void GraphicsTracingWidget::AbortRecording() { | ||
| 129 | auto context = context_weak.lock(); | ||
| 130 | if (!context) | ||
| 131 | return; | ||
| 132 | |||
| 133 | context->recorder = nullptr; | ||
| 134 | |||
| 135 | emit SetStopTracingButtonEnabled(false); | ||
| 136 | emit SetAbortTracingButtonEnabled(false); | ||
| 137 | emit SetStartTracingButtonEnabled(true); | ||
| 138 | } | ||
| 139 | |||
| 140 | void GraphicsTracingWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) { | ||
| 141 | widget()->setEnabled(true); | ||
| 142 | } | ||
| 143 | |||
| 144 | void GraphicsTracingWidget::OnResumed() { | ||
| 145 | widget()->setEnabled(false); | ||
| 146 | } | ||
| 147 | |||
| 148 | void GraphicsTracingWidget::OnEmulationStarting(EmuThread* emu_thread) { | ||
| 149 | // Disable tracing starting/stopping until a GPU breakpoint is reached | ||
| 150 | widget()->setEnabled(false); | ||
| 151 | } | ||
| 152 | |||
| 153 | void GraphicsTracingWidget::OnEmulationStopping() { | ||
| 154 | // TODO: Is it safe to access the context here? | ||
| 155 | |||
| 156 | auto context = context_weak.lock(); | ||
| 157 | if (!context) | ||
| 158 | return; | ||
| 159 | |||
| 160 | if (context->recorder) { | ||
| 161 | auto reply = | ||
| 162 | QMessageBox::question(this, tr("CiTracing still active"), | ||
| 163 | tr("A CiTrace is still being recorded. Do you want to save it? " | ||
| 164 | "If not, all recorded data will be discarded."), | ||
| 165 | QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); | ||
| 166 | |||
| 167 | if (reply == QMessageBox::Yes) { | ||
| 168 | StopRecording(); | ||
| 169 | } else { | ||
| 170 | AbortRecording(); | ||
| 171 | } | ||
| 172 | } | ||
| 173 | |||
| 174 | // If the widget was disabled before, enable it now to allow starting | ||
| 175 | // tracing before starting the next emulation session | ||
| 176 | widget()->setEnabled(true); | ||
| 177 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_tracing.h b/src/citra_qt/debugger/graphics/graphics_tracing.h deleted file mode 100644 index eb1292c29..000000000 --- a/src/citra_qt/debugger/graphics/graphics_tracing.h +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h" | ||
| 8 | |||
| 9 | class EmuThread; | ||
| 10 | |||
| 11 | class GraphicsTracingWidget : public BreakPointObserverDock { | ||
| 12 | Q_OBJECT | ||
| 13 | |||
| 14 | public: | ||
| 15 | explicit GraphicsTracingWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 16 | QWidget* parent = nullptr); | ||
| 17 | |||
| 18 | void OnEmulationStarting(EmuThread* emu_thread); | ||
| 19 | void OnEmulationStopping(); | ||
| 20 | |||
| 21 | private slots: | ||
| 22 | void StartRecording(); | ||
| 23 | void StopRecording(); | ||
| 24 | void AbortRecording(); | ||
| 25 | |||
| 26 | void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override; | ||
| 27 | void OnResumed() override; | ||
| 28 | |||
| 29 | signals: | ||
| 30 | void SetStartTracingButtonEnabled(bool enable); | ||
| 31 | void SetStopTracingButtonEnabled(bool enable); | ||
| 32 | void SetAbortTracingButtonEnabled(bool enable); | ||
| 33 | }; | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp deleted file mode 100644 index 7f4ec0c52..000000000 --- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp +++ /dev/null | |||
| @@ -1,622 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <iomanip> | ||
| 6 | #include <sstream> | ||
| 7 | #include <QBoxLayout> | ||
| 8 | #include <QFileDialog> | ||
| 9 | #include <QFormLayout> | ||
| 10 | #include <QGroupBox> | ||
| 11 | #include <QLabel> | ||
| 12 | #include <QLineEdit> | ||
| 13 | #include <QPushButton> | ||
| 14 | #include <QSignalMapper> | ||
| 15 | #include <QSpinBox> | ||
| 16 | #include <QTreeView> | ||
| 17 | #include "citra_qt/debugger/graphics/graphics_vertex_shader.h" | ||
| 18 | #include "citra_qt/util/util.h" | ||
| 19 | #include "video_core/pica_state.h" | ||
| 20 | #include "video_core/shader/debug_data.h" | ||
| 21 | #include "video_core/shader/shader.h" | ||
| 22 | #include "video_core/shader/shader_interpreter.h" | ||
| 23 | |||
| 24 | using nihstro::OpCode; | ||
| 25 | using nihstro::Instruction; | ||
| 26 | using nihstro::SourceRegister; | ||
| 27 | using nihstro::SwizzlePattern; | ||
| 28 | |||
| 29 | GraphicsVertexShaderModel::GraphicsVertexShaderModel(GraphicsVertexShaderWidget* parent) | ||
| 30 | : QAbstractTableModel(parent), par(parent) {} | ||
| 31 | |||
| 32 | int GraphicsVertexShaderModel::columnCount(const QModelIndex& parent) const { | ||
| 33 | return 3; | ||
| 34 | } | ||
| 35 | |||
| 36 | int GraphicsVertexShaderModel::rowCount(const QModelIndex& parent) const { | ||
| 37 | return static_cast<int>(par->info.code.size()); | ||
| 38 | } | ||
| 39 | |||
| 40 | QVariant GraphicsVertexShaderModel::headerData(int section, Qt::Orientation orientation, | ||
| 41 | int role) const { | ||
| 42 | switch (role) { | ||
| 43 | case Qt::DisplayRole: { | ||
| 44 | if (section == 0) { | ||
| 45 | return tr("Offset"); | ||
| 46 | } else if (section == 1) { | ||
| 47 | return tr("Raw"); | ||
| 48 | } else if (section == 2) { | ||
| 49 | return tr("Disassembly"); | ||
| 50 | } | ||
| 51 | |||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | |||
| 56 | return QVariant(); | ||
| 57 | } | ||
| 58 | |||
| 59 | static std::string SelectorToString(u32 selector) { | ||
| 60 | std::string ret; | ||
| 61 | for (int i = 0; i < 4; ++i) { | ||
| 62 | int component = (selector >> ((3 - i) * 2)) & 3; | ||
| 63 | ret += "xyzw"[component]; | ||
| 64 | } | ||
| 65 | return ret; | ||
| 66 | } | ||
| 67 | |||
| 68 | // e.g. "-c92[a0.x].xyzw" | ||
| 69 | static void print_input(std::ostringstream& output, const SourceRegister& input, bool negate, | ||
| 70 | const std::string& swizzle_mask, bool align = true, | ||
| 71 | const std::string& address_register_name = std::string()) { | ||
| 72 | if (align) | ||
| 73 | output << std::setw(4) << std::right; | ||
| 74 | output << ((negate ? "-" : "") + input.GetName()); | ||
| 75 | |||
| 76 | if (!address_register_name.empty()) | ||
| 77 | output << '[' << address_register_name << ']'; | ||
| 78 | output << '.' << swizzle_mask; | ||
| 79 | }; | ||
| 80 | |||
| 81 | QVariant GraphicsVertexShaderModel::data(const QModelIndex& index, int role) const { | ||
| 82 | switch (role) { | ||
| 83 | case Qt::DisplayRole: { | ||
| 84 | switch (index.column()) { | ||
| 85 | case 0: | ||
| 86 | if (par->info.HasLabel(index.row())) | ||
| 87 | return QString::fromStdString(par->info.GetLabel(index.row())); | ||
| 88 | |||
| 89 | return QString("%1").arg(4 * index.row(), 4, 16, QLatin1Char('0')); | ||
| 90 | |||
| 91 | case 1: | ||
| 92 | return QString("%1").arg(par->info.code[index.row()].hex, 8, 16, QLatin1Char('0')); | ||
| 93 | |||
| 94 | case 2: { | ||
| 95 | std::ostringstream output; | ||
| 96 | output.flags(std::ios::uppercase); | ||
| 97 | |||
| 98 | // To make the code aligning columns of assembly easier to keep track of, this function | ||
| 99 | // keeps track of the start of the start of the previous column, allowing alignment | ||
| 100 | // based on desired field widths. | ||
| 101 | int current_column = 0; | ||
| 102 | auto AlignToColumn = [&](int col_width) { | ||
| 103 | // Prints spaces to the output to pad previous column to size and advances the | ||
| 104 | // column marker. | ||
| 105 | current_column += col_width; | ||
| 106 | int to_add = std::max(1, current_column - (int)output.tellp()); | ||
| 107 | for (int i = 0; i < to_add; ++i) { | ||
| 108 | output << ' '; | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | |||
| 112 | const Instruction instr = par->info.code[index.row()]; | ||
| 113 | const OpCode opcode = instr.opcode; | ||
| 114 | const OpCode::Info opcode_info = opcode.GetInfo(); | ||
| 115 | const u32 operand_desc_id = opcode_info.type == OpCode::Type::MultiplyAdd | ||
| 116 | ? instr.mad.operand_desc_id.Value() | ||
| 117 | : instr.common.operand_desc_id.Value(); | ||
| 118 | const SwizzlePattern swizzle = par->info.swizzle_info[operand_desc_id].pattern; | ||
| 119 | |||
| 120 | // longest known instruction name: "setemit " | ||
| 121 | int kOpcodeColumnWidth = 8; | ||
| 122 | // "rXX.xyzw " | ||
| 123 | int kOutputColumnWidth = 10; | ||
| 124 | // "-rXX.xyzw ", no attempt is made to align indexed inputs | ||
| 125 | int kInputOperandColumnWidth = 11; | ||
| 126 | |||
| 127 | output << opcode_info.name; | ||
| 128 | |||
| 129 | switch (opcode_info.type) { | ||
| 130 | case OpCode::Type::Trivial: | ||
| 131 | // Nothing to do here | ||
| 132 | break; | ||
| 133 | |||
| 134 | case OpCode::Type::Arithmetic: | ||
| 135 | case OpCode::Type::MultiplyAdd: { | ||
| 136 | // Use custom code for special instructions | ||
| 137 | switch (opcode.EffectiveOpCode()) { | ||
| 138 | case OpCode::Id::CMP: { | ||
| 139 | AlignToColumn(kOpcodeColumnWidth); | ||
| 140 | |||
| 141 | // NOTE: CMP always writes both cc components, so we do not consider the dest | ||
| 142 | // mask here. | ||
| 143 | output << " cc.xy"; | ||
| 144 | AlignToColumn(kOutputColumnWidth); | ||
| 145 | |||
| 146 | SourceRegister src1 = instr.common.GetSrc1(false); | ||
| 147 | SourceRegister src2 = instr.common.GetSrc2(false); | ||
| 148 | |||
| 149 | output << ' '; | ||
| 150 | print_input(output, src1, swizzle.negate_src1, | ||
| 151 | swizzle.SelectorToString(false).substr(0, 1), false, | ||
| 152 | instr.common.AddressRegisterName()); | ||
| 153 | output << ' ' << instr.common.compare_op.ToString(instr.common.compare_op.x) | ||
| 154 | << ' '; | ||
| 155 | print_input(output, src2, swizzle.negate_src2, | ||
| 156 | swizzle.SelectorToString(true).substr(0, 1), false); | ||
| 157 | |||
| 158 | output << ", "; | ||
| 159 | |||
| 160 | print_input(output, src1, swizzle.negate_src1, | ||
| 161 | swizzle.SelectorToString(false).substr(1, 1), false, | ||
| 162 | instr.common.AddressRegisterName()); | ||
| 163 | output << ' ' << instr.common.compare_op.ToString(instr.common.compare_op.y) | ||
| 164 | << ' '; | ||
| 165 | print_input(output, src2, swizzle.negate_src2, | ||
| 166 | swizzle.SelectorToString(true).substr(1, 1), false); | ||
| 167 | |||
| 168 | break; | ||
| 169 | } | ||
| 170 | |||
| 171 | case OpCode::Id::MAD: | ||
| 172 | case OpCode::Id::MADI: { | ||
| 173 | AlignToColumn(kOpcodeColumnWidth); | ||
| 174 | |||
| 175 | bool src_is_inverted = 0 != (opcode_info.subtype & OpCode::Info::SrcInversed); | ||
| 176 | SourceRegister src1 = instr.mad.GetSrc1(src_is_inverted); | ||
| 177 | SourceRegister src2 = instr.mad.GetSrc2(src_is_inverted); | ||
| 178 | SourceRegister src3 = instr.mad.GetSrc3(src_is_inverted); | ||
| 179 | |||
| 180 | output << std::setw(3) << std::right << instr.mad.dest.Value().GetName() << '.' | ||
| 181 | << swizzle.DestMaskToString(); | ||
| 182 | AlignToColumn(kOutputColumnWidth); | ||
| 183 | print_input(output, src1, swizzle.negate_src1, | ||
| 184 | SelectorToString(swizzle.src1_selector)); | ||
| 185 | AlignToColumn(kInputOperandColumnWidth); | ||
| 186 | print_input(output, src2, swizzle.negate_src2, | ||
| 187 | SelectorToString(swizzle.src2_selector), true, | ||
| 188 | src_is_inverted ? "" : instr.mad.AddressRegisterName()); | ||
| 189 | AlignToColumn(kInputOperandColumnWidth); | ||
| 190 | print_input(output, src3, swizzle.negate_src3, | ||
| 191 | SelectorToString(swizzle.src3_selector), true, | ||
| 192 | src_is_inverted ? instr.mad.AddressRegisterName() : ""); | ||
| 193 | AlignToColumn(kInputOperandColumnWidth); | ||
| 194 | break; | ||
| 195 | } | ||
| 196 | |||
| 197 | default: { | ||
| 198 | AlignToColumn(kOpcodeColumnWidth); | ||
| 199 | |||
| 200 | bool src_is_inverted = 0 != (opcode_info.subtype & OpCode::Info::SrcInversed); | ||
| 201 | |||
| 202 | if (opcode_info.subtype & OpCode::Info::Dest) { | ||
| 203 | // e.g. "r12.xy__" | ||
| 204 | output << std::setw(3) << std::right << instr.common.dest.Value().GetName() | ||
| 205 | << '.' << swizzle.DestMaskToString(); | ||
| 206 | } else if (opcode_info.subtype == OpCode::Info::MOVA) { | ||
| 207 | output << " a0." << swizzle.DestMaskToString(); | ||
| 208 | } | ||
| 209 | AlignToColumn(kOutputColumnWidth); | ||
| 210 | |||
| 211 | if (opcode_info.subtype & OpCode::Info::Src1) { | ||
| 212 | SourceRegister src1 = instr.common.GetSrc1(src_is_inverted); | ||
| 213 | print_input(output, src1, swizzle.negate_src1, | ||
| 214 | swizzle.SelectorToString(false), true, | ||
| 215 | src_is_inverted ? "" : instr.common.AddressRegisterName()); | ||
| 216 | AlignToColumn(kInputOperandColumnWidth); | ||
| 217 | } | ||
| 218 | |||
| 219 | if (opcode_info.subtype & OpCode::Info::Src2) { | ||
| 220 | SourceRegister src2 = instr.common.GetSrc2(src_is_inverted); | ||
| 221 | print_input(output, src2, swizzle.negate_src2, | ||
| 222 | swizzle.SelectorToString(true), true, | ||
| 223 | src_is_inverted ? instr.common.AddressRegisterName() : ""); | ||
| 224 | AlignToColumn(kInputOperandColumnWidth); | ||
| 225 | } | ||
| 226 | break; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | |||
| 230 | break; | ||
| 231 | } | ||
| 232 | |||
| 233 | case OpCode::Type::Conditional: | ||
| 234 | case OpCode::Type::UniformFlowControl: { | ||
| 235 | output << ' '; | ||
| 236 | |||
| 237 | switch (opcode.EffectiveOpCode()) { | ||
| 238 | case OpCode::Id::LOOP: | ||
| 239 | output << 'i' << instr.flow_control.int_uniform_id << " (end on 0x" | ||
| 240 | << std::setw(4) << std::right << std::setfill('0') << std::hex | ||
| 241 | << (4 * instr.flow_control.dest_offset) << ")"; | ||
| 242 | break; | ||
| 243 | |||
| 244 | default: | ||
| 245 | if (opcode_info.subtype & OpCode::Info::HasCondition) { | ||
| 246 | output << '('; | ||
| 247 | |||
| 248 | if (instr.flow_control.op != instr.flow_control.JustY) { | ||
| 249 | if (!instr.flow_control.refx) | ||
| 250 | output << '!'; | ||
| 251 | output << "cc.x"; | ||
| 252 | } | ||
| 253 | |||
| 254 | if (instr.flow_control.op == instr.flow_control.Or) { | ||
| 255 | output << " || "; | ||
| 256 | } else if (instr.flow_control.op == instr.flow_control.And) { | ||
| 257 | output << " && "; | ||
| 258 | } | ||
| 259 | |||
| 260 | if (instr.flow_control.op != instr.flow_control.JustX) { | ||
| 261 | if (!instr.flow_control.refy) | ||
| 262 | output << '!'; | ||
| 263 | output << "cc.y"; | ||
| 264 | } | ||
| 265 | |||
| 266 | output << ") "; | ||
| 267 | } else if (opcode_info.subtype & OpCode::Info::HasUniformIndex) { | ||
| 268 | if (opcode.EffectiveOpCode() == OpCode::Id::JMPU && | ||
| 269 | (instr.flow_control.num_instructions & 1) == 1) { | ||
| 270 | output << '!'; | ||
| 271 | } | ||
| 272 | output << 'b' << instr.flow_control.bool_uniform_id << ' '; | ||
| 273 | } | ||
| 274 | |||
| 275 | if (opcode_info.subtype & OpCode::Info::HasAlternative) { | ||
| 276 | output << "else jump to 0x" << std::setw(4) << std::right | ||
| 277 | << std::setfill('0') << std::hex | ||
| 278 | << (4 * instr.flow_control.dest_offset); | ||
| 279 | } else if (opcode_info.subtype & OpCode::Info::HasExplicitDest) { | ||
| 280 | output << "jump to 0x" << std::setw(4) << std::right << std::setfill('0') | ||
| 281 | << std::hex << (4 * instr.flow_control.dest_offset); | ||
| 282 | } else { | ||
| 283 | // TODO: Handle other cases | ||
| 284 | output << "(unknown destination)"; | ||
| 285 | } | ||
| 286 | |||
| 287 | if (opcode_info.subtype & OpCode::Info::HasFinishPoint) { | ||
| 288 | output << " (return on 0x" << std::setw(4) << std::right | ||
| 289 | << std::setfill('0') << std::hex | ||
| 290 | << (4 * instr.flow_control.dest_offset + | ||
| 291 | 4 * instr.flow_control.num_instructions) | ||
| 292 | << ')'; | ||
| 293 | } | ||
| 294 | |||
| 295 | break; | ||
| 296 | } | ||
| 297 | break; | ||
| 298 | } | ||
| 299 | |||
| 300 | default: | ||
| 301 | output << " (unknown instruction format)"; | ||
| 302 | break; | ||
| 303 | } | ||
| 304 | |||
| 305 | return QString::fromLatin1(output.str().c_str()); | ||
| 306 | } | ||
| 307 | |||
| 308 | default: | ||
| 309 | break; | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | case Qt::FontRole: | ||
| 314 | return GetMonospaceFont(); | ||
| 315 | |||
| 316 | case Qt::BackgroundRole: { | ||
| 317 | // Highlight current instruction | ||
| 318 | int current_record_index = par->cycle_index->value(); | ||
| 319 | if (current_record_index < static_cast<int>(par->debug_data.records.size())) { | ||
| 320 | const auto& current_record = par->debug_data.records[current_record_index]; | ||
| 321 | if (index.row() == static_cast<int>(current_record.instruction_offset)) { | ||
| 322 | return QColor(255, 255, 63); | ||
| 323 | } | ||
| 324 | } | ||
| 325 | |||
| 326 | // Use a grey background for instructions which have no debug data associated to them | ||
| 327 | for (const auto& record : par->debug_data.records) | ||
| 328 | if (index.row() == static_cast<int>(record.instruction_offset)) | ||
| 329 | return QVariant(); | ||
| 330 | |||
| 331 | return QBrush(QColor(192, 192, 192)); | ||
| 332 | } | ||
| 333 | |||
| 334 | // TODO: Draw arrows for each "reachable" instruction to visualize control flow | ||
| 335 | |||
| 336 | default: | ||
| 337 | break; | ||
| 338 | } | ||
| 339 | |||
| 340 | return QVariant(); | ||
| 341 | } | ||
| 342 | |||
| 343 | void GraphicsVertexShaderWidget::DumpShader() { | ||
| 344 | QString filename = QFileDialog::getSaveFileName( | ||
| 345 | this, tr("Save Shader Dump"), "shader_dump.shbin", tr("Shader Binary (*.shbin)")); | ||
| 346 | |||
| 347 | if (filename.isEmpty()) { | ||
| 348 | // If the user canceled the dialog, don't dump anything. | ||
| 349 | return; | ||
| 350 | } | ||
| 351 | |||
| 352 | auto& setup = Pica::g_state.vs; | ||
| 353 | auto& config = Pica::g_state.regs.vs; | ||
| 354 | |||
| 355 | Pica::DebugUtils::DumpShader(filename.toStdString(), config, setup, | ||
| 356 | Pica::g_state.regs.rasterizer.vs_output_attributes); | ||
| 357 | } | ||
| 358 | |||
| 359 | GraphicsVertexShaderWidget::GraphicsVertexShaderWidget( | ||
| 360 | std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent) | ||
| 361 | : BreakPointObserverDock(debug_context, "Pica Vertex Shader", parent) { | ||
| 362 | setObjectName("PicaVertexShader"); | ||
| 363 | |||
| 364 | // Clear input vertex data so that it contains valid float values in case a debug shader | ||
| 365 | // execution happens before the first Vertex Loaded breakpoint. | ||
| 366 | // TODO: This makes a crash in the interpreter much less likely, but not impossible. The | ||
| 367 | // interpreter should guard against out-of-bounds accesses to ensure crashes in it aren't | ||
| 368 | // possible. | ||
| 369 | std::memset(&input_vertex, 0, sizeof(input_vertex)); | ||
| 370 | |||
| 371 | auto input_data_mapper = new QSignalMapper(this); | ||
| 372 | |||
| 373 | // TODO: Support inputting data in hexadecimal raw format | ||
| 374 | for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) { | ||
| 375 | input_data[i] = new QLineEdit; | ||
| 376 | input_data[i]->setValidator(new QDoubleValidator(input_data[i])); | ||
| 377 | } | ||
| 378 | |||
| 379 | breakpoint_warning = | ||
| 380 | new QLabel(tr("(data only available at vertex shader invocation breakpoints)")); | ||
| 381 | |||
| 382 | // TODO: Add some button for jumping to the shader entry point | ||
| 383 | |||
| 384 | model = new GraphicsVertexShaderModel(this); | ||
| 385 | binary_list = new QTreeView; | ||
| 386 | binary_list->setModel(model); | ||
| 387 | binary_list->setRootIsDecorated(false); | ||
| 388 | binary_list->setAlternatingRowColors(true); | ||
| 389 | |||
| 390 | auto dump_shader = new QPushButton(QIcon::fromTheme("document-save"), tr("Dump")); | ||
| 391 | |||
| 392 | instruction_description = new QLabel; | ||
| 393 | |||
| 394 | cycle_index = new QSpinBox; | ||
| 395 | |||
| 396 | connect(dump_shader, SIGNAL(clicked()), this, SLOT(DumpShader())); | ||
| 397 | |||
| 398 | connect(cycle_index, SIGNAL(valueChanged(int)), this, SLOT(OnCycleIndexChanged(int))); | ||
| 399 | |||
| 400 | for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) { | ||
| 401 | connect(input_data[i], SIGNAL(textEdited(const QString&)), input_data_mapper, SLOT(map())); | ||
| 402 | input_data_mapper->setMapping(input_data[i], i); | ||
| 403 | } | ||
| 404 | connect(input_data_mapper, SIGNAL(mapped(int)), this, SLOT(OnInputAttributeChanged(int))); | ||
| 405 | |||
| 406 | auto main_widget = new QWidget; | ||
| 407 | auto main_layout = new QVBoxLayout; | ||
| 408 | { | ||
| 409 | auto input_data_group = new QGroupBox(tr("Input Data")); | ||
| 410 | |||
| 411 | // For each vertex attribute, add a QHBoxLayout consisting of: | ||
| 412 | // - A QLabel denoting the source attribute index | ||
| 413 | // - Four QLineEdits for showing and manipulating attribute data | ||
| 414 | // - A QLabel denoting the shader input attribute index | ||
| 415 | auto sub_layout = new QVBoxLayout; | ||
| 416 | for (unsigned i = 0; i < 16; ++i) { | ||
| 417 | // Create an HBoxLayout to store the widgets used to specify a particular attribute | ||
| 418 | // and store it in a QWidget to allow for easy hiding and unhiding. | ||
| 419 | auto row_layout = new QHBoxLayout; | ||
| 420 | // Remove unnecessary padding between rows | ||
| 421 | row_layout->setContentsMargins(0, 0, 0, 0); | ||
| 422 | |||
| 423 | row_layout->addWidget(new QLabel(tr("Attribute %1").arg(i, 2))); | ||
| 424 | for (unsigned comp = 0; comp < 4; ++comp) | ||
| 425 | row_layout->addWidget(input_data[4 * i + comp]); | ||
| 426 | |||
| 427 | row_layout->addWidget(input_data_mapping[i] = new QLabel); | ||
| 428 | |||
| 429 | input_data_container[i] = new QWidget; | ||
| 430 | input_data_container[i]->setLayout(row_layout); | ||
| 431 | input_data_container[i]->hide(); | ||
| 432 | |||
| 433 | sub_layout->addWidget(input_data_container[i]); | ||
| 434 | } | ||
| 435 | |||
| 436 | sub_layout->addWidget(breakpoint_warning); | ||
| 437 | breakpoint_warning->hide(); | ||
| 438 | |||
| 439 | input_data_group->setLayout(sub_layout); | ||
| 440 | main_layout->addWidget(input_data_group); | ||
| 441 | } | ||
| 442 | |||
| 443 | // Make program listing expand to fill available space in the dialog | ||
| 444 | binary_list->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | ||
| 445 | main_layout->addWidget(binary_list); | ||
| 446 | |||
| 447 | main_layout->addWidget(dump_shader); | ||
| 448 | { | ||
| 449 | auto sub_layout = new QFormLayout; | ||
| 450 | sub_layout->addRow(tr("Cycle Index:"), cycle_index); | ||
| 451 | |||
| 452 | main_layout->addLayout(sub_layout); | ||
| 453 | } | ||
| 454 | |||
| 455 | // Set a minimum height so that the size of this label doesn't cause the rest of the bottom | ||
| 456 | // part of the UI to keep jumping up and down when cycling through instructions. | ||
| 457 | instruction_description->setMinimumHeight(instruction_description->fontMetrics().lineSpacing() * | ||
| 458 | 6); | ||
| 459 | instruction_description->setAlignment(Qt::AlignLeft | Qt::AlignTop); | ||
| 460 | main_layout->addWidget(instruction_description); | ||
| 461 | |||
| 462 | main_widget->setLayout(main_layout); | ||
| 463 | setWidget(main_widget); | ||
| 464 | |||
| 465 | widget()->setEnabled(false); | ||
| 466 | } | ||
| 467 | |||
| 468 | void GraphicsVertexShaderWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) { | ||
| 469 | if (event == Pica::DebugContext::Event::VertexShaderInvocation) { | ||
| 470 | Reload(true, data); | ||
| 471 | } else { | ||
| 472 | // No vertex data is retrievable => invalidate currently stored vertex data | ||
| 473 | Reload(true, nullptr); | ||
| 474 | } | ||
| 475 | widget()->setEnabled(true); | ||
| 476 | } | ||
| 477 | |||
| 478 | void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_data) { | ||
| 479 | model->beginResetModel(); | ||
| 480 | |||
| 481 | if (replace_vertex_data) { | ||
| 482 | if (vertex_data) { | ||
| 483 | memcpy(&input_vertex, vertex_data, sizeof(input_vertex)); | ||
| 484 | for (unsigned attr = 0; attr < 16; ++attr) { | ||
| 485 | for (unsigned comp = 0; comp < 4; ++comp) { | ||
| 486 | input_data[4 * attr + comp]->setText( | ||
| 487 | QString("%1").arg(input_vertex.attr[attr][comp].ToFloat32())); | ||
| 488 | } | ||
| 489 | } | ||
| 490 | breakpoint_warning->hide(); | ||
| 491 | } else { | ||
| 492 | for (unsigned attr = 0; attr < 16; ++attr) { | ||
| 493 | for (unsigned comp = 0; comp < 4; ++comp) { | ||
| 494 | input_data[4 * attr + comp]->setText(QString("???")); | ||
| 495 | } | ||
| 496 | } | ||
| 497 | breakpoint_warning->show(); | ||
| 498 | } | ||
| 499 | } | ||
| 500 | |||
| 501 | // Reload shader code | ||
| 502 | info.Clear(); | ||
| 503 | |||
| 504 | auto& shader_setup = Pica::g_state.vs; | ||
| 505 | auto& shader_config = Pica::g_state.regs.vs; | ||
| 506 | for (auto instr : shader_setup.program_code) | ||
| 507 | info.code.push_back({instr}); | ||
| 508 | int num_attributes = shader_config.max_input_attribute_index + 1; | ||
| 509 | |||
| 510 | for (auto pattern : shader_setup.swizzle_data) | ||
| 511 | info.swizzle_info.push_back({pattern}); | ||
| 512 | |||
| 513 | u32 entry_point = Pica::g_state.regs.vs.main_offset; | ||
| 514 | info.labels.insert({entry_point, "main"}); | ||
| 515 | |||
| 516 | // Generate debug information | ||
| 517 | Pica::Shader::InterpreterEngine shader_engine; | ||
| 518 | shader_engine.SetupBatch(shader_setup, entry_point); | ||
| 519 | debug_data = shader_engine.ProduceDebugInfo(shader_setup, input_vertex, shader_config); | ||
| 520 | |||
| 521 | // Reload widget state | ||
| 522 | for (int attr = 0; attr < num_attributes; ++attr) { | ||
| 523 | unsigned source_attr = shader_config.GetRegisterForAttribute(attr); | ||
| 524 | input_data_mapping[attr]->setText(QString("-> v%1").arg(source_attr)); | ||
| 525 | input_data_container[attr]->setVisible(true); | ||
| 526 | } | ||
| 527 | // Only show input attributes which are used as input to the shader | ||
| 528 | for (unsigned int attr = num_attributes; attr < 16; ++attr) { | ||
| 529 | input_data_container[attr]->setVisible(false); | ||
| 530 | } | ||
| 531 | |||
| 532 | // Initialize debug info text for current cycle count | ||
| 533 | cycle_index->setMaximum(static_cast<int>(debug_data.records.size() - 1)); | ||
| 534 | OnCycleIndexChanged(cycle_index->value()); | ||
| 535 | |||
| 536 | model->endResetModel(); | ||
| 537 | } | ||
| 538 | |||
| 539 | void GraphicsVertexShaderWidget::OnResumed() { | ||
| 540 | widget()->setEnabled(false); | ||
| 541 | } | ||
| 542 | |||
| 543 | void GraphicsVertexShaderWidget::OnInputAttributeChanged(int index) { | ||
| 544 | float value = input_data[index]->text().toFloat(); | ||
| 545 | input_vertex.attr[index / 4][index % 4] = Pica::float24::FromFloat32(value); | ||
| 546 | // Re-execute shader with updated value | ||
| 547 | Reload(); | ||
| 548 | } | ||
| 549 | |||
| 550 | void GraphicsVertexShaderWidget::OnCycleIndexChanged(int index) { | ||
| 551 | QString text; | ||
| 552 | |||
| 553 | auto& record = debug_data.records[index]; | ||
| 554 | if (record.mask & Pica::Shader::DebugDataRecord::SRC1) | ||
| 555 | text += tr("SRC1: %1, %2, %3, %4\n") | ||
| 556 | .arg(record.src1.x.ToFloat32()) | ||
| 557 | .arg(record.src1.y.ToFloat32()) | ||
| 558 | .arg(record.src1.z.ToFloat32()) | ||
| 559 | .arg(record.src1.w.ToFloat32()); | ||
| 560 | if (record.mask & Pica::Shader::DebugDataRecord::SRC2) | ||
| 561 | text += tr("SRC2: %1, %2, %3, %4\n") | ||
| 562 | .arg(record.src2.x.ToFloat32()) | ||
| 563 | .arg(record.src2.y.ToFloat32()) | ||
| 564 | .arg(record.src2.z.ToFloat32()) | ||
| 565 | .arg(record.src2.w.ToFloat32()); | ||
| 566 | if (record.mask & Pica::Shader::DebugDataRecord::SRC3) | ||
| 567 | text += tr("SRC3: %1, %2, %3, %4\n") | ||
| 568 | .arg(record.src3.x.ToFloat32()) | ||
| 569 | .arg(record.src3.y.ToFloat32()) | ||
| 570 | .arg(record.src3.z.ToFloat32()) | ||
| 571 | .arg(record.src3.w.ToFloat32()); | ||
| 572 | if (record.mask & Pica::Shader::DebugDataRecord::DEST_IN) | ||
| 573 | text += tr("DEST_IN: %1, %2, %3, %4\n") | ||
| 574 | .arg(record.dest_in.x.ToFloat32()) | ||
| 575 | .arg(record.dest_in.y.ToFloat32()) | ||
| 576 | .arg(record.dest_in.z.ToFloat32()) | ||
| 577 | .arg(record.dest_in.w.ToFloat32()); | ||
| 578 | if (record.mask & Pica::Shader::DebugDataRecord::DEST_OUT) | ||
| 579 | text += tr("DEST_OUT: %1, %2, %3, %4\n") | ||
| 580 | .arg(record.dest_out.x.ToFloat32()) | ||
| 581 | .arg(record.dest_out.y.ToFloat32()) | ||
| 582 | .arg(record.dest_out.z.ToFloat32()) | ||
| 583 | .arg(record.dest_out.w.ToFloat32()); | ||
| 584 | |||
| 585 | if (record.mask & Pica::Shader::DebugDataRecord::ADDR_REG_OUT) | ||
| 586 | text += tr("Address Registers: %1, %2\n") | ||
| 587 | .arg(record.address_registers[0]) | ||
| 588 | .arg(record.address_registers[1]); | ||
| 589 | if (record.mask & Pica::Shader::DebugDataRecord::CMP_RESULT) | ||
| 590 | text += tr("Compare Result: %1, %2\n") | ||
| 591 | .arg(record.conditional_code[0] ? "true" : "false") | ||
| 592 | .arg(record.conditional_code[1] ? "true" : "false"); | ||
| 593 | |||
| 594 | if (record.mask & Pica::Shader::DebugDataRecord::COND_BOOL_IN) | ||
| 595 | text += tr("Static Condition: %1\n").arg(record.cond_bool ? "true" : "false"); | ||
| 596 | if (record.mask & Pica::Shader::DebugDataRecord::COND_CMP_IN) | ||
| 597 | text += tr("Dynamic Conditions: %1, %2\n") | ||
| 598 | .arg(record.cond_cmp[0] ? "true" : "false") | ||
| 599 | .arg(record.cond_cmp[1] ? "true" : "false"); | ||
| 600 | if (record.mask & Pica::Shader::DebugDataRecord::LOOP_INT_IN) | ||
| 601 | text += tr("Loop Parameters: %1 (repeats), %2 (initializer), %3 (increment), %4\n") | ||
| 602 | .arg(record.loop_int.x) | ||
| 603 | .arg(record.loop_int.y) | ||
| 604 | .arg(record.loop_int.z) | ||
| 605 | .arg(record.loop_int.w); | ||
| 606 | |||
| 607 | text += | ||
| 608 | tr("Instruction offset: 0x%1").arg(4 * record.instruction_offset, 4, 16, QLatin1Char('0')); | ||
| 609 | if (record.mask & Pica::Shader::DebugDataRecord::NEXT_INSTR) { | ||
| 610 | text += tr(" -> 0x%2").arg(4 * record.next_instruction, 4, 16, QLatin1Char('0')); | ||
| 611 | } else { | ||
| 612 | text += tr(" (last instruction)"); | ||
| 613 | } | ||
| 614 | |||
| 615 | instruction_description->setText(text); | ||
| 616 | |||
| 617 | // Emit model update notification and scroll to current instruction | ||
| 618 | QModelIndex instr_index = model->index(record.instruction_offset, 0); | ||
| 619 | emit model->dataChanged(instr_index, | ||
| 620 | model->index(record.instruction_offset, model->columnCount())); | ||
| 621 | binary_list->scrollTo(instr_index, QAbstractItemView::EnsureVisible); | ||
| 622 | } | ||
diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.h b/src/citra_qt/debugger/graphics/graphics_vertex_shader.h deleted file mode 100644 index c249a2ff8..000000000 --- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.h +++ /dev/null | |||
| @@ -1,88 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <QAbstractTableModel> | ||
| 8 | #include <QTreeView> | ||
| 9 | #include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h" | ||
| 10 | #include "nihstro/parser_shbin.h" | ||
| 11 | #include "video_core/shader/debug_data.h" | ||
| 12 | #include "video_core/shader/shader.h" | ||
| 13 | |||
| 14 | class QLabel; | ||
| 15 | class QSpinBox; | ||
| 16 | |||
| 17 | class GraphicsVertexShaderWidget; | ||
| 18 | |||
| 19 | class GraphicsVertexShaderModel : public QAbstractTableModel { | ||
| 20 | Q_OBJECT | ||
| 21 | |||
| 22 | public: | ||
| 23 | explicit GraphicsVertexShaderModel(GraphicsVertexShaderWidget* parent); | ||
| 24 | |||
| 25 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 26 | int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||
| 27 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||
| 28 | QVariant headerData(int section, Qt::Orientation orientation, | ||
| 29 | int role = Qt::DisplayRole) const override; | ||
| 30 | |||
| 31 | private: | ||
| 32 | GraphicsVertexShaderWidget* par; | ||
| 33 | |||
| 34 | friend class GraphicsVertexShaderWidget; | ||
| 35 | }; | ||
| 36 | |||
| 37 | class GraphicsVertexShaderWidget : public BreakPointObserverDock { | ||
| 38 | Q_OBJECT | ||
| 39 | |||
| 40 | using Event = Pica::DebugContext::Event; | ||
| 41 | |||
| 42 | public: | ||
| 43 | GraphicsVertexShaderWidget(std::shared_ptr<Pica::DebugContext> debug_context, | ||
| 44 | QWidget* parent = nullptr); | ||
| 45 | |||
| 46 | private slots: | ||
| 47 | void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override; | ||
| 48 | void OnResumed() override; | ||
| 49 | |||
| 50 | void OnInputAttributeChanged(int index); | ||
| 51 | |||
| 52 | void OnCycleIndexChanged(int index); | ||
| 53 | |||
| 54 | void DumpShader(); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Reload widget based on the current PICA200 state | ||
| 58 | * @param replace_vertex_data If true, invalidate all current vertex data | ||
| 59 | * @param vertex_data New vertex data to use, as passed to OnBreakPointHit. May be nullptr to | ||
| 60 | * specify that no valid vertex data can be retrieved currently. Only used if | ||
| 61 | * replace_vertex_data is true. | ||
| 62 | */ | ||
| 63 | void Reload(bool replace_vertex_data = false, void* vertex_data = nullptr); | ||
| 64 | |||
| 65 | private: | ||
| 66 | QLabel* instruction_description; | ||
| 67 | QTreeView* binary_list; | ||
| 68 | GraphicsVertexShaderModel* model; | ||
| 69 | |||
| 70 | /// TODO: Move these into a single struct | ||
| 71 | std::array<QLineEdit*, 4 * 16> | ||
| 72 | input_data; // A text box for each of the 4 components of up to 16 vertex attributes | ||
| 73 | std::array<QWidget*, 16> | ||
| 74 | input_data_container; // QWidget containing the QLayout containing each vertex attribute | ||
| 75 | std::array<QLabel*, 16> input_data_mapping; // A QLabel denoting the shader input attribute | ||
| 76 | // which the vertex attribute maps to | ||
| 77 | |||
| 78 | // Text to be shown when input vertex data is not retrievable | ||
| 79 | QLabel* breakpoint_warning; | ||
| 80 | |||
| 81 | QSpinBox* cycle_index; | ||
| 82 | |||
| 83 | nihstro::ShaderInfo info; | ||
| 84 | Pica::Shader::DebugData<true> debug_data; | ||
| 85 | Pica::Shader::AttributeBuffer input_vertex; | ||
| 86 | |||
| 87 | friend class GraphicsVertexShaderModel; | ||
| 88 | }; | ||