diff options
| author | 2014-12-09 12:14:05 -0500 | |
|---|---|---|
| committer | 2014-12-09 12:14:05 -0500 | |
| commit | 360f68419db55de15a996feb1874d1b0b82c4661 (patch) | |
| tree | 816d9a88deded411908e6d9aa22a648416c41469 /src/citra_qt/debugger/graphics_cmdlists.cpp | |
| parent | Merge pull request #217 from archshift/cmd_buff (diff) | |
| parent | More cleanups. (diff) | |
| download | yuzu-360f68419db55de15a996feb1874d1b0b82c4661.tar.gz yuzu-360f68419db55de15a996feb1874d1b0b82c4661.tar.xz yuzu-360f68419db55de15a996feb1874d1b0b82c4661.zip | |
Merge pull request #218 from neobrain/pica_debugger
Pica debugger improvements
Diffstat (limited to 'src/citra_qt/debugger/graphics_cmdlists.cpp')
| -rw-r--r-- | src/citra_qt/debugger/graphics_cmdlists.cpp | 241 |
1 files changed, 222 insertions, 19 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index 71dd166cd..7f97cf143 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp | |||
| @@ -2,30 +2,171 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <QLabel> | ||
| 5 | #include <QListView> | 6 | #include <QListView> |
| 7 | #include <QMainWindow> | ||
| 6 | #include <QPushButton> | 8 | #include <QPushButton> |
| 7 | #include <QVBoxLayout> | 9 | #include <QVBoxLayout> |
| 8 | #include <QTreeView> | 10 | #include <QTreeView> |
| 11 | #include <QSpinBox> | ||
| 12 | #include <QComboBox> | ||
| 13 | |||
| 14 | #include "video_core/pica.h" | ||
| 15 | #include "video_core/math.h" | ||
| 16 | |||
| 17 | #include "video_core/debug_utils/debug_utils.h" | ||
| 9 | 18 | ||
| 10 | #include "graphics_cmdlists.hxx" | 19 | #include "graphics_cmdlists.hxx" |
| 11 | 20 | ||
| 12 | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) | 21 | #include "util/spinbox.hxx" |
| 13 | { | 22 | |
| 23 | QImage LoadTexture(u8* src, const Pica::DebugUtils::TextureInfo& info) { | ||
| 24 | QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); | ||
| 25 | for (int y = 0; y < info.height; ++y) { | ||
| 26 | for (int x = 0; x < info.width; ++x) { | ||
| 27 | Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info); | ||
| 28 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | return decoded_image; | ||
| 33 | } | ||
| 34 | |||
| 35 | class TextureInfoWidget : public QWidget { | ||
| 36 | public: | ||
| 37 | TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) { | ||
| 38 | QLabel* image_widget = new QLabel; | ||
| 39 | QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info)); | ||
| 40 | image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); | ||
| 41 | image_widget->setPixmap(image_pixmap); | ||
| 42 | |||
| 43 | QVBoxLayout* layout = new QVBoxLayout; | ||
| 44 | layout->addWidget(image_widget); | ||
| 45 | setLayout(layout); | ||
| 46 | } | ||
| 47 | }; | ||
| 48 | |||
| 49 | TextureInfoDockWidget::TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent) | ||
| 50 | : QDockWidget(tr("Texture 0x%1").arg(info.address, 8, 16, QLatin1Char('0'))), | ||
| 51 | info(info) { | ||
| 52 | |||
| 53 | QWidget* main_widget = new QWidget; | ||
| 54 | |||
| 55 | QLabel* image_widget = new QLabel; | ||
| 56 | |||
| 57 | connect(this, SIGNAL(UpdatePixmap(const QPixmap&)), image_widget, SLOT(setPixmap(const QPixmap&))); | ||
| 58 | |||
| 59 | CSpinBox* phys_address_spinbox = new CSpinBox; | ||
| 60 | phys_address_spinbox->SetBase(16); | ||
| 61 | phys_address_spinbox->SetRange(0, 0xFFFFFFFF); | ||
| 62 | phys_address_spinbox->SetPrefix("0x"); | ||
| 63 | phys_address_spinbox->SetValue(info.address); | ||
| 64 | connect(phys_address_spinbox, SIGNAL(ValueChanged(qint64)), this, SLOT(OnAddressChanged(qint64))); | ||
| 65 | |||
| 66 | QComboBox* format_choice = new QComboBox; | ||
| 67 | format_choice->addItem(tr("RGBA8")); | ||
| 68 | format_choice->addItem(tr("RGB8")); | ||
| 69 | format_choice->addItem(tr("RGBA5551")); | ||
| 70 | format_choice->addItem(tr("RGB565")); | ||
| 71 | format_choice->addItem(tr("RGBA4")); | ||
| 72 | format_choice->setCurrentIndex(static_cast<int>(info.format)); | ||
| 73 | connect(format_choice, SIGNAL(currentIndexChanged(int)), this, SLOT(OnFormatChanged(int))); | ||
| 74 | |||
| 75 | QSpinBox* width_spinbox = new QSpinBox; | ||
| 76 | width_spinbox->setMaximum(65535); | ||
| 77 | width_spinbox->setValue(info.width); | ||
| 78 | connect(width_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnWidthChanged(int))); | ||
| 79 | |||
| 80 | QSpinBox* height_spinbox = new QSpinBox; | ||
| 81 | height_spinbox->setMaximum(65535); | ||
| 82 | height_spinbox->setValue(info.height); | ||
| 83 | connect(height_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnHeightChanged(int))); | ||
| 84 | |||
| 85 | QSpinBox* stride_spinbox = new QSpinBox; | ||
| 86 | stride_spinbox->setMaximum(65535 * 4); | ||
| 87 | stride_spinbox->setValue(info.stride); | ||
| 88 | connect(stride_spinbox, SIGNAL(valueChanged(int)), this, SLOT(OnStrideChanged(int))); | ||
| 89 | |||
| 90 | QVBoxLayout* main_layout = new QVBoxLayout; | ||
| 91 | main_layout->addWidget(image_widget); | ||
| 92 | |||
| 93 | { | ||
| 94 | QHBoxLayout* sub_layout = new QHBoxLayout; | ||
| 95 | sub_layout->addWidget(new QLabel(tr("Source Address:"))); | ||
| 96 | sub_layout->addWidget(phys_address_spinbox); | ||
| 97 | main_layout->addLayout(sub_layout); | ||
| 98 | } | ||
| 99 | |||
| 100 | { | ||
| 101 | QHBoxLayout* sub_layout = new QHBoxLayout; | ||
| 102 | sub_layout->addWidget(new QLabel(tr("Format"))); | ||
| 103 | sub_layout->addWidget(format_choice); | ||
| 104 | main_layout->addLayout(sub_layout); | ||
| 105 | } | ||
| 106 | |||
| 107 | { | ||
| 108 | QHBoxLayout* sub_layout = new QHBoxLayout; | ||
| 109 | sub_layout->addWidget(new QLabel(tr("Width:"))); | ||
| 110 | sub_layout->addWidget(width_spinbox); | ||
| 111 | sub_layout->addStretch(); | ||
| 112 | sub_layout->addWidget(new QLabel(tr("Height:"))); | ||
| 113 | sub_layout->addWidget(height_spinbox); | ||
| 114 | sub_layout->addStretch(); | ||
| 115 | sub_layout->addWidget(new QLabel(tr("Stride:"))); | ||
| 116 | sub_layout->addWidget(stride_spinbox); | ||
| 117 | main_layout->addLayout(sub_layout); | ||
| 118 | } | ||
| 119 | |||
| 120 | main_widget->setLayout(main_layout); | ||
| 121 | |||
| 122 | emit UpdatePixmap(ReloadPixmap()); | ||
| 123 | |||
| 124 | setWidget(main_widget); | ||
| 125 | } | ||
| 126 | |||
| 127 | void TextureInfoDockWidget::OnAddressChanged(qint64 value) { | ||
| 128 | info.address = value; | ||
| 129 | emit UpdatePixmap(ReloadPixmap()); | ||
| 130 | } | ||
| 131 | |||
| 132 | void TextureInfoDockWidget::OnFormatChanged(int value) { | ||
| 133 | info.format = static_cast<Pica::Regs::TextureFormat>(value); | ||
| 134 | emit UpdatePixmap(ReloadPixmap()); | ||
| 135 | } | ||
| 136 | |||
| 137 | void TextureInfoDockWidget::OnWidthChanged(int value) { | ||
| 138 | info.width = value; | ||
| 139 | emit UpdatePixmap(ReloadPixmap()); | ||
| 140 | } | ||
| 141 | |||
| 142 | void TextureInfoDockWidget::OnHeightChanged(int value) { | ||
| 143 | info.height = value; | ||
| 144 | emit UpdatePixmap(ReloadPixmap()); | ||
| 145 | } | ||
| 14 | 146 | ||
| 147 | void TextureInfoDockWidget::OnStrideChanged(int value) { | ||
| 148 | info.stride = value; | ||
| 149 | emit UpdatePixmap(ReloadPixmap()); | ||
| 15 | } | 150 | } |
| 16 | 151 | ||
| 17 | int GPUCommandListModel::rowCount(const QModelIndex& parent) const | 152 | QPixmap TextureInfoDockWidget::ReloadPixmap() const { |
| 18 | { | 153 | u8* src = Memory::GetPointer(info.address); |
| 154 | return QPixmap::fromImage(LoadTexture(src, info)); | ||
| 155 | } | ||
| 156 | |||
| 157 | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) { | ||
| 158 | |||
| 159 | } | ||
| 160 | |||
| 161 | int GPUCommandListModel::rowCount(const QModelIndex& parent) const { | ||
| 19 | return pica_trace.writes.size(); | 162 | return pica_trace.writes.size(); |
| 20 | } | 163 | } |
| 21 | 164 | ||
| 22 | int GPUCommandListModel::columnCount(const QModelIndex& parent) const | 165 | int GPUCommandListModel::columnCount(const QModelIndex& parent) const { |
| 23 | { | ||
| 24 | return 2; | 166 | return 2; |
| 25 | } | 167 | } |
| 26 | 168 | ||
| 27 | QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | 169 | QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const { |
| 28 | { | ||
| 29 | if (!index.isValid()) | 170 | if (!index.isValid()) |
| 30 | return QVariant(); | 171 | return QVariant(); |
| 31 | 172 | ||
| @@ -36,21 +177,39 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | |||
| 36 | if (role == Qt::DisplayRole) { | 177 | if (role == Qt::DisplayRole) { |
| 37 | QString content; | 178 | QString content; |
| 38 | if (index.column() == 0) { | 179 | if (index.column() == 0) { |
| 39 | content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str()); | 180 | QString content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str()); |
| 40 | content.append(" "); | 181 | content.append(" "); |
| 182 | return content; | ||
| 41 | } else if (index.column() == 1) { | 183 | } else if (index.column() == 1) { |
| 42 | content.append(QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'))); | 184 | QString content = QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0')); |
| 43 | content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0'))); | 185 | content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0'))); |
| 186 | return content; | ||
| 44 | } | 187 | } |
| 188 | } else if (role == CommandIdRole) { | ||
| 189 | return QVariant::fromValue<int>(cmd.cmd_id.Value()); | ||
| 190 | } | ||
| 45 | 191 | ||
| 46 | return QVariant(content); | 192 | return QVariant(); |
| 193 | } | ||
| 194 | |||
| 195 | QVariant GPUCommandListModel::headerData(int section, Qt::Orientation orientation, int role) const { | ||
| 196 | switch(role) { | ||
| 197 | case Qt::DisplayRole: | ||
| 198 | { | ||
| 199 | if (section == 0) { | ||
| 200 | return tr("Command Name"); | ||
| 201 | } else if (section == 1) { | ||
| 202 | return tr("Data"); | ||
| 203 | } | ||
| 204 | |||
| 205 | break; | ||
| 206 | } | ||
| 47 | } | 207 | } |
| 48 | 208 | ||
| 49 | return QVariant(); | 209 | return QVariant(); |
| 50 | } | 210 | } |
| 51 | 211 | ||
| 52 | void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) | 212 | void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) { |
| 53 | { | ||
| 54 | beginResetModel(); | 213 | beginResetModel(); |
| 55 | 214 | ||
| 56 | pica_trace = trace; | 215 | pica_trace = trace; |
| @@ -58,38 +217,82 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& | |||
| 58 | endResetModel(); | 217 | endResetModel(); |
| 59 | } | 218 | } |
| 60 | 219 | ||
| 220 | #define COMMAND_IN_RANGE(cmd_id, reg_name) \ | ||
| 221 | (cmd_id >= PICA_REG_INDEX(reg_name) && \ | ||
| 222 | cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4) | ||
| 223 | |||
| 224 | void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) { | ||
| 225 | const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); | ||
| 226 | if (COMMAND_IN_RANGE(command_id, texture0)) { | ||
| 227 | auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0, | ||
| 228 | Pica::registers.texture0_format); | ||
| 229 | |||
| 230 | // TODO: Instead, emit a signal here to be caught by the main window widget. | ||
| 231 | auto main_window = static_cast<QMainWindow*>(parent()); | ||
| 232 | main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window)); | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) { | ||
| 237 | QWidget* new_info_widget; | ||
| 238 | |||
| 239 | const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); | ||
| 240 | if (COMMAND_IN_RANGE(command_id, texture0)) { | ||
| 241 | u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress()); | ||
| 242 | auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0, | ||
| 243 | Pica::registers.texture0_format); | ||
| 244 | new_info_widget = new TextureInfoWidget(src, info); | ||
| 245 | } else { | ||
| 246 | new_info_widget = new QWidget; | ||
| 247 | } | ||
| 248 | |||
| 249 | widget()->layout()->removeWidget(command_info_widget); | ||
| 250 | delete command_info_widget; | ||
| 251 | widget()->layout()->addWidget(new_info_widget); | ||
| 252 | command_info_widget = new_info_widget; | ||
| 253 | } | ||
| 254 | #undef COMMAND_IN_RANGE | ||
| 61 | 255 | ||
| 62 | GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) | 256 | GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) { |
| 63 | { | 257 | setObjectName("Pica Command List"); |
| 64 | GPUCommandListModel* model = new GPUCommandListModel(this); | 258 | GPUCommandListModel* model = new GPUCommandListModel(this); |
| 65 | 259 | ||
| 66 | QWidget* main_widget = new QWidget; | 260 | QWidget* main_widget = new QWidget; |
| 67 | 261 | ||
| 68 | QTreeView* list_widget = new QTreeView; | 262 | list_widget = new QTreeView; |
| 69 | list_widget->setModel(model); | 263 | list_widget->setModel(model); |
| 70 | list_widget->setFont(QFont("monospace")); | 264 | list_widget->setFont(QFont("monospace")); |
| 71 | list_widget->setRootIsDecorated(false); | 265 | list_widget->setRootIsDecorated(false); |
| 72 | 266 | ||
| 73 | QPushButton* toggle_tracing = new QPushButton(tr("Start Tracing")); | 267 | connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), |
| 268 | this, SLOT(SetCommandInfo(const QModelIndex&))); | ||
| 269 | connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)), | ||
| 270 | this, SLOT(OnCommandDoubleClicked(const QModelIndex&))); | ||
| 271 | |||
| 272 | toggle_tracing = new QPushButton(tr("Start Tracing")); | ||
| 74 | 273 | ||
| 75 | connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); | 274 | connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); |
| 76 | connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), | 275 | connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), |
| 77 | model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); | 276 | model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); |
| 78 | 277 | ||
| 278 | command_info_widget = new QWidget; | ||
| 279 | |||
| 79 | QVBoxLayout* main_layout = new QVBoxLayout; | 280 | QVBoxLayout* main_layout = new QVBoxLayout; |
| 80 | main_layout->addWidget(list_widget); | 281 | main_layout->addWidget(list_widget); |
| 81 | main_layout->addWidget(toggle_tracing); | 282 | main_layout->addWidget(toggle_tracing); |
| 283 | main_layout->addWidget(command_info_widget); | ||
| 82 | main_widget->setLayout(main_layout); | 284 | main_widget->setLayout(main_layout); |
| 83 | 285 | ||
| 84 | setWidget(main_widget); | 286 | setWidget(main_widget); |
| 85 | } | 287 | } |
| 86 | 288 | ||
| 87 | void GPUCommandListWidget::OnToggleTracing() | 289 | void GPUCommandListWidget::OnToggleTracing() { |
| 88 | { | ||
| 89 | if (!Pica::DebugUtils::IsPicaTracing()) { | 290 | if (!Pica::DebugUtils::IsPicaTracing()) { |
| 90 | Pica::DebugUtils::StartPicaTracing(); | 291 | Pica::DebugUtils::StartPicaTracing(); |
| 292 | toggle_tracing->setText(tr("Finish Tracing")); | ||
| 91 | } else { | 293 | } else { |
| 92 | pica_trace = Pica::DebugUtils::FinishPicaTracing(); | 294 | pica_trace = Pica::DebugUtils::FinishPicaTracing(); |
| 93 | emit TracingFinished(*pica_trace); | 295 | emit TracingFinished(*pica_trace); |
| 296 | toggle_tracing->setText(tr("Start Tracing")); | ||
| 94 | } | 297 | } |
| 95 | } | 298 | } |