diff options
Diffstat (limited to '')
| -rw-r--r-- | src/citra_qt/debugger/graphics_cmdlists.cpp | 173 | ||||
| -rw-r--r-- | src/citra_qt/debugger/graphics_cmdlists.hxx | 24 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.h | 4 | ||||
| -rw-r--r-- | src/video_core/pica.h | 15 |
5 files changed, 209 insertions, 19 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index dcd0ced33..4f58e9a90 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp | |||
| @@ -4,30 +4,39 @@ | |||
| 4 | 4 | ||
| 5 | #include <QLabel> | 5 | #include <QLabel> |
| 6 | #include <QListView> | 6 | #include <QListView> |
| 7 | #include <QMainWindow> | ||
| 7 | #include <QPushButton> | 8 | #include <QPushButton> |
| 8 | #include <QVBoxLayout> | 9 | #include <QVBoxLayout> |
| 9 | #include <QTreeView> | 10 | #include <QTreeView> |
| 10 | 11 | #include <QSpinBox> | |
| 11 | #include "graphics_cmdlists.hxx" | 12 | #include <QComboBox> |
| 12 | 13 | ||
| 13 | #include "video_core/pica.h" | 14 | #include "video_core/pica.h" |
| 14 | #include "video_core/math.h" | 15 | #include "video_core/math.h" |
| 15 | 16 | ||
| 16 | #include "video_core/debug_utils/debug_utils.h" | 17 | #include "video_core/debug_utils/debug_utils.h" |
| 17 | 18 | ||
| 19 | #include "graphics_cmdlists.hxx" | ||
| 20 | |||
| 21 | #include "util/spinbox.hxx" | ||
| 22 | |||
| 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 | |||
| 18 | class TextureInfoWidget : public QWidget { | 35 | class TextureInfoWidget : public QWidget { |
| 19 | public: | 36 | public: |
| 20 | TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) { | 37 | TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) { |
| 21 | QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); | ||
| 22 | for (int y = 0; y < info.height; ++y) { | ||
| 23 | for (int x = 0; x < info.width; ++x) { | ||
| 24 | Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info); | ||
| 25 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | QLabel* image_widget = new QLabel; | 38 | QLabel* image_widget = new QLabel; |
| 30 | QPixmap image_pixmap = QPixmap::fromImage(decoded_image); | 39 | QPixmap image_pixmap = QPixmap::fromImage(LoadTexture(src, info)); |
| 31 | image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); | 40 | image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); |
| 32 | image_widget->setPixmap(image_pixmap); | 41 | image_widget->setPixmap(image_pixmap); |
| 33 | 42 | ||
| @@ -37,6 +46,120 @@ public: | |||
| 37 | } | 46 | } |
| 38 | }; | 47 | }; |
| 39 | 48 | ||
| 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 | { | ||
| 129 | info.address = value; | ||
| 130 | emit UpdatePixmap(ReloadPixmap()); | ||
| 131 | } | ||
| 132 | |||
| 133 | void TextureInfoDockWidget::OnFormatChanged(int value) | ||
| 134 | { | ||
| 135 | info.format = static_cast<Pica::Regs::TextureFormat>(value); | ||
| 136 | emit UpdatePixmap(ReloadPixmap()); | ||
| 137 | } | ||
| 138 | |||
| 139 | void TextureInfoDockWidget::OnWidthChanged(int value) | ||
| 140 | { | ||
| 141 | info.width = value; | ||
| 142 | emit UpdatePixmap(ReloadPixmap()); | ||
| 143 | } | ||
| 144 | |||
| 145 | void TextureInfoDockWidget::OnHeightChanged(int value) | ||
| 146 | { | ||
| 147 | info.height = value; | ||
| 148 | emit UpdatePixmap(ReloadPixmap()); | ||
| 149 | } | ||
| 150 | |||
| 151 | void TextureInfoDockWidget::OnStrideChanged(int value) | ||
| 152 | { | ||
| 153 | info.stride = value; | ||
| 154 | emit UpdatePixmap(ReloadPixmap()); | ||
| 155 | } | ||
| 156 | |||
| 157 | QPixmap TextureInfoDockWidget::ReloadPixmap() const | ||
| 158 | { | ||
| 159 | u8* src = Memory::GetPointer(info.address); | ||
| 160 | return QPixmap::fromImage(LoadTexture(src, info)); | ||
| 161 | } | ||
| 162 | |||
| 40 | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) | 163 | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) |
| 41 | { | 164 | { |
| 42 | 165 | ||
| @@ -106,30 +229,42 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& | |||
| 106 | endResetModel(); | 229 | endResetModel(); |
| 107 | } | 230 | } |
| 108 | 231 | ||
| 232 | #define COMMAND_IN_RANGE(cmd_id, reg_name) \ | ||
| 233 | (cmd_id >= PICA_REG_INDEX(reg_name) && \ | ||
| 234 | cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4) | ||
| 235 | |||
| 236 | void GPUCommandListWidget::OnCommandDoubleClicked(const QModelIndex& index) | ||
| 237 | { | ||
| 238 | |||
| 239 | const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); | ||
| 240 | if (COMMAND_IN_RANGE(command_id, texture0)) { | ||
| 241 | auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0, | ||
| 242 | Pica::registers.texture0_format); | ||
| 243 | QMainWindow* main_window = (QMainWindow*)parent(); | ||
| 244 | main_window->tabifyDockWidget(this, new TextureInfoDockWidget(info, main_window)); | ||
| 245 | } | ||
| 246 | } | ||
| 247 | |||
| 109 | void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) | 248 | void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) |
| 110 | { | 249 | { |
| 111 | QWidget* new_info_widget; | 250 | QWidget* new_info_widget; |
| 112 | 251 | ||
| 113 | #define COMMAND_IN_RANGE(cmd_id, reg_name) (cmd_id >= PICA_REG_INDEX(reg_name) && cmd_id < PICA_REG_INDEX(reg_name) + sizeof(decltype(Pica::registers.reg_name)) / 4) | ||
| 114 | const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); | 252 | const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); |
| 115 | if (COMMAND_IN_RANGE(command_id, texture0)) { | 253 | if (COMMAND_IN_RANGE(command_id, texture0)) { |
| 116 | u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress()); | 254 | u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress()); |
| 117 | Pica::DebugUtils::TextureInfo info; | 255 | auto info = Pica::DebugUtils::TextureInfo::FromPicaRegister(Pica::registers.texture0, |
| 118 | info.width = Pica::registers.texture0.width; | 256 | Pica::registers.texture0_format); |
| 119 | info.height = Pica::registers.texture0.height; | ||
| 120 | info.stride = 3 * Pica::registers.texture0.width; | ||
| 121 | info.format = Pica::registers.texture0_format; | ||
| 122 | new_info_widget = new TextureInfoWidget(src, info); | 257 | new_info_widget = new TextureInfoWidget(src, info); |
| 123 | } else { | 258 | } else { |
| 124 | new_info_widget = new QWidget; | 259 | new_info_widget = new QWidget; |
| 125 | } | 260 | } |
| 126 | #undef COMMAND_IN_RANGE | ||
| 127 | 261 | ||
| 128 | widget()->layout()->removeWidget(command_info_widget); | 262 | widget()->layout()->removeWidget(command_info_widget); |
| 129 | delete command_info_widget; | 263 | delete command_info_widget; |
| 130 | widget()->layout()->addWidget(new_info_widget); | 264 | widget()->layout()->addWidget(new_info_widget); |
| 131 | command_info_widget = new_info_widget; | 265 | command_info_widget = new_info_widget; |
| 132 | } | 266 | } |
| 267 | #undef COMMAND_IN_RANGE | ||
| 133 | 268 | ||
| 134 | GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) | 269 | GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) |
| 135 | { | 270 | { |
| @@ -145,6 +280,8 @@ GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pi | |||
| 145 | 280 | ||
| 146 | connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), | 281 | connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), |
| 147 | this, SLOT(SetCommandInfo(const QModelIndex&))); | 282 | this, SLOT(SetCommandInfo(const QModelIndex&))); |
| 283 | connect(list_widget, SIGNAL(doubleClicked(const QModelIndex&)), | ||
| 284 | this, SLOT(OnCommandDoubleClicked(const QModelIndex&))); | ||
| 148 | 285 | ||
| 149 | 286 | ||
| 150 | toggle_tracing = new QPushButton(tr("Start Tracing")); | 287 | toggle_tracing = new QPushButton(tr("Start Tracing")); |
diff --git a/src/citra_qt/debugger/graphics_cmdlists.hxx b/src/citra_qt/debugger/graphics_cmdlists.hxx index 37fe19053..a459bba64 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.hxx +++ b/src/citra_qt/debugger/graphics_cmdlists.hxx | |||
| @@ -45,6 +45,8 @@ public: | |||
| 45 | 45 | ||
| 46 | public slots: | 46 | public slots: |
| 47 | void OnToggleTracing(); | 47 | void OnToggleTracing(); |
| 48 | void OnCommandDoubleClicked(const QModelIndex&); | ||
| 49 | |||
| 48 | void SetCommandInfo(const QModelIndex&); | 50 | void SetCommandInfo(const QModelIndex&); |
| 49 | 51 | ||
| 50 | signals: | 52 | signals: |
| @@ -57,3 +59,25 @@ private: | |||
| 57 | QWidget* command_info_widget; | 59 | QWidget* command_info_widget; |
| 58 | QPushButton* toggle_tracing; | 60 | QPushButton* toggle_tracing; |
| 59 | }; | 61 | }; |
| 62 | |||
| 63 | class TextureInfoDockWidget : public QDockWidget { | ||
| 64 | Q_OBJECT | ||
| 65 | |||
| 66 | public: | ||
| 67 | TextureInfoDockWidget(const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr); | ||
| 68 | |||
| 69 | signals: | ||
| 70 | void UpdatePixmap(const QPixmap& pixmap); | ||
| 71 | |||
| 72 | private slots: | ||
| 73 | void OnAddressChanged(qint64 value); | ||
| 74 | void OnFormatChanged(int value); | ||
| 75 | void OnWidthChanged(int value); | ||
| 76 | void OnHeightChanged(int value); | ||
| 77 | void OnStrideChanged(int value); | ||
| 78 | |||
| 79 | private: | ||
| 80 | QPixmap ReloadPixmap() const; | ||
| 81 | |||
| 82 | Pica::DebugUtils::TextureInfo info; | ||
| 83 | }; | ||
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 59909c827..31ce09faf 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -382,6 +382,18 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 382 | return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; | 382 | return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | TextureInfo TextureInfo::FromPicaRegister(const Regs::TextureConfig& config, | ||
| 386 | const Regs::TextureFormat& format) | ||
| 387 | { | ||
| 388 | TextureInfo info; | ||
| 389 | info.address = config.GetPhysicalAddress(); | ||
| 390 | info.width = config.width; | ||
| 391 | info.height = config.height; | ||
| 392 | info.format = format; | ||
| 393 | info.stride = Pica::Regs::BytesPerPixel(info.format) * info.width; | ||
| 394 | return info; | ||
| 395 | } | ||
| 396 | |||
| 385 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | 397 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { |
| 386 | // NOTE: Permanently enabling this just trashes hard disks for no reason. | 398 | // NOTE: Permanently enabling this just trashes hard disks for no reason. |
| 387 | // Hence, this is currently disabled. | 399 | // Hence, this is currently disabled. |
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h index bad4c919a..51f14f12f 100644 --- a/src/video_core/debug_utils/debug_utils.h +++ b/src/video_core/debug_utils/debug_utils.h | |||
| @@ -192,10 +192,14 @@ void OnPicaRegWrite(u32 id, u32 value); | |||
| 192 | std::unique_ptr<PicaTrace> FinishPicaTracing(); | 192 | std::unique_ptr<PicaTrace> FinishPicaTracing(); |
| 193 | 193 | ||
| 194 | struct TextureInfo { | 194 | struct TextureInfo { |
| 195 | unsigned int address; | ||
| 195 | int width; | 196 | int width; |
| 196 | int height; | 197 | int height; |
| 197 | int stride; | 198 | int stride; |
| 198 | Pica::Regs::TextureFormat format; | 199 | Pica::Regs::TextureFormat format; |
| 200 | |||
| 201 | static TextureInfo FromPicaRegister(const Pica::Regs::TextureConfig& config, | ||
| 202 | const Pica::Regs::TextureFormat& format); | ||
| 199 | }; | 203 | }; |
| 200 | 204 | ||
| 201 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info); | 205 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info); |
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 10fa73355..c1f35a011 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -130,7 +130,20 @@ struct Regs { | |||
| 130 | // Seems like they are luminance formats and compressed textures. | 130 | // Seems like they are luminance formats and compressed textures. |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | BitField<0, 1, u32> texturing_enable; | 133 | static unsigned BytesPerPixel(TextureFormat format) { |
| 134 | if (format == TextureFormat::RGBA8) | ||
| 135 | return 4; | ||
| 136 | else if (format == TextureFormat::RGB8) | ||
| 137 | return 3; | ||
| 138 | else if (format == TextureFormat::RGBA5551 || | ||
| 139 | format == TextureFormat::RGB565 || | ||
| 140 | format == TextureFormat::RGBA4) | ||
| 141 | return 2; | ||
| 142 | else // placeholder | ||
| 143 | return 1; | ||
| 144 | } | ||
| 145 | |||
| 146 | BitField< 0, 1, u32> texturing_enable; | ||
| 134 | TextureConfig texture0; | 147 | TextureConfig texture0; |
| 135 | INSERT_PADDING_WORDS(0x8); | 148 | INSERT_PADDING_WORDS(0x8); |
| 136 | BitField<0, 4, TextureFormat> texture0_format; | 149 | BitField<0, 4, TextureFormat> texture0_format; |