mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	citra-qt: Add texture viewer to Pica command list.
The texture viewer is enabled when selecting a write command to one of the texture config registers.
This commit is contained in:
		
							parent
							
								
									c63a495de6
								
							
						
					
					
						commit
						fd194d95b0
					
				
					 4 changed files with 116 additions and 22 deletions
				
			
		|  | @ -2,6 +2,7 @@ | |||
| // Licensed under GPLv2
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <QLabel> | ||||
| #include <QListView> | ||||
| #include <QPushButton> | ||||
| #include <QVBoxLayout> | ||||
|  | @ -9,6 +10,33 @@ | |||
| 
 | ||||
| #include "graphics_cmdlists.hxx" | ||||
| 
 | ||||
| #include "video_core/pica.h" | ||||
| #include "video_core/math.h" | ||||
| 
 | ||||
| #include "video_core/debug_utils/debug_utils.h" | ||||
| 
 | ||||
| class TextureInfoWidget : public QWidget { | ||||
| public: | ||||
|     TextureInfoWidget(u8* src, const Pica::DebugUtils::TextureInfo& info, QWidget* parent = nullptr) : QWidget(parent) { | ||||
|         QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); | ||||
|         for (int y = 0; y < info.height; ++y) { | ||||
|             for (int x = 0; x < info.width; ++x) { | ||||
|                 Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info); | ||||
|                 decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | ||||
|             } | ||||
|         } | ||||
| 
 | ||||
|         QLabel* image_widget = new QLabel; | ||||
|         QPixmap image_pixmap = QPixmap::fromImage(decoded_image); | ||||
|         image_pixmap = image_pixmap.scaled(200, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation); | ||||
|         image_widget->setPixmap(image_pixmap); | ||||
| 
 | ||||
|         QVBoxLayout* layout = new QVBoxLayout; | ||||
|         layout->addWidget(image_widget); | ||||
|         setLayout(layout); | ||||
|     } | ||||
| }; | ||||
| 
 | ||||
| GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) | ||||
| { | ||||
| 
 | ||||
|  | @ -44,6 +72,8 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | |||
|         } | ||||
| 
 | ||||
|         return QVariant(content); | ||||
|     } else if (role == CommandIdRole) { | ||||
|         return QVariant::fromValue<int>(cmd.cmd_id.Value()); | ||||
|     } | ||||
| 
 | ||||
|     return QVariant(); | ||||
|  | @ -76,27 +106,59 @@ void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& | |||
|     endResetModel(); | ||||
| } | ||||
| 
 | ||||
| void GPUCommandListWidget::SetCommandInfo(const QModelIndex& index) | ||||
| { | ||||
|     QWidget* new_info_widget; | ||||
| 
 | ||||
| #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) | ||||
|     const int command_id = list_widget->model()->data(index, GPUCommandListModel::CommandIdRole).toInt(); | ||||
|     if (COMMAND_IN_RANGE(command_id, texture0)) { | ||||
|         u8* src = Memory::GetPointer(Pica::registers.texture0.GetPhysicalAddress()); | ||||
|         Pica::DebugUtils::TextureInfo info; | ||||
|         info.width = Pica::registers.texture0.width; | ||||
|         info.height = Pica::registers.texture0.height; | ||||
|         info.stride = 3 * Pica::registers.texture0.width; | ||||
|         info.format = Pica::registers.texture0_format; | ||||
|         new_info_widget = new TextureInfoWidget(src, info); | ||||
|     } else { | ||||
|         new_info_widget = new QWidget; | ||||
|     } | ||||
| #undef COMMAND_IN_RANGE | ||||
| 
 | ||||
|     widget()->layout()->removeWidget(command_info_widget); | ||||
|     delete command_info_widget; | ||||
|     widget()->layout()->addWidget(new_info_widget); | ||||
|     command_info_widget = new_info_widget; | ||||
| } | ||||
| 
 | ||||
| GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) | ||||
| { | ||||
|     setObjectName("Pica Command List"); | ||||
|     GPUCommandListModel* model = new GPUCommandListModel(this); | ||||
| 
 | ||||
|     QWidget* main_widget = new QWidget; | ||||
| 
 | ||||
|     QTreeView* list_widget = new QTreeView; | ||||
|     list_widget = new QTreeView; | ||||
|     list_widget->setModel(model); | ||||
|     list_widget->setFont(QFont("monospace")); | ||||
|     list_widget->setRootIsDecorated(false); | ||||
| 
 | ||||
|     connect(list_widget->selectionModel(), SIGNAL(currentChanged(const QModelIndex&,const QModelIndex&)), | ||||
|             this, SLOT(SetCommandInfo(const QModelIndex&))); | ||||
| 
 | ||||
| 
 | ||||
|     toggle_tracing = new QPushButton(tr("Start Tracing")); | ||||
| 
 | ||||
|     connect(toggle_tracing, SIGNAL(clicked()), this, SLOT(OnToggleTracing())); | ||||
|     connect(this, SIGNAL(TracingFinished(const Pica::DebugUtils::PicaTrace&)), | ||||
|             model, SLOT(OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace&))); | ||||
| 
 | ||||
|     command_info_widget = new QWidget; | ||||
| 
 | ||||
|     QVBoxLayout* main_layout = new QVBoxLayout; | ||||
|     main_layout->addWidget(list_widget); | ||||
|     main_layout->addWidget(toggle_tracing); | ||||
|     main_layout->addWidget(command_info_widget); | ||||
|     main_widget->setLayout(main_layout); | ||||
| 
 | ||||
|     setWidget(main_widget); | ||||
|  |  | |||
|  | @ -11,12 +11,17 @@ | |||
| #include "video_core/debug_utils/debug_utils.h" | ||||
| 
 | ||||
| class QPushButton; | ||||
| class QTreeView; | ||||
| 
 | ||||
| class GPUCommandListModel : public QAbstractListModel | ||||
| { | ||||
|     Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|     enum { | ||||
|         CommandIdRole = Qt::UserRole, | ||||
|     }; | ||||
| 
 | ||||
|     GPUCommandListModel(QObject* parent); | ||||
| 
 | ||||
|     int columnCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
|  | @ -40,6 +45,7 @@ public: | |||
| 
 | ||||
| public slots: | ||||
|     void OnToggleTracing(); | ||||
|     void SetCommandInfo(const QModelIndex&); | ||||
| 
 | ||||
| signals: | ||||
|     void TracingFinished(const Pica::DebugUtils::PicaTrace&); | ||||
|  | @ -47,5 +53,7 @@ signals: | |||
| private: | ||||
|     std::unique_ptr<Pica::DebugUtils::PicaTrace> pica_trace; | ||||
| 
 | ||||
|     QTreeView* list_widget; | ||||
|     QWidget* command_info_widget; | ||||
|     QPushButton* toggle_tracing; | ||||
| }; | ||||
|  |  | |||
|  | @ -2,6 +2,8 @@ | |||
| // Licensed under GPLv2
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include <cassert> | ||||
| 
 | ||||
| #include <algorithm> | ||||
| #include <condition_variable> | ||||
| #include <list> | ||||
|  | @ -17,6 +19,7 @@ | |||
| #include "common/log.h" | ||||
| #include "common/file_util.h" | ||||
| 
 | ||||
| #include "video_core/math.h" | ||||
| #include "video_core/pica.h" | ||||
| 
 | ||||
| #include "debug_utils.h" | ||||
|  | @ -355,6 +358,30 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() | |||
|     return std::move(ret); | ||||
| } | ||||
| 
 | ||||
| const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { | ||||
|     assert(info.format == Pica::Regs::TextureFormat::RGB8); | ||||
| 
 | ||||
|     // Cf. rasterizer code for an explanation of this algorithm.
 | ||||
|     int texel_index_within_tile = 0; | ||||
|     for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | ||||
|         int sub_tile_width = 1 << block_size_index; | ||||
|         int sub_tile_height = 1 << block_size_index; | ||||
| 
 | ||||
|         int sub_tile_index = (x & sub_tile_width) << block_size_index; | ||||
|         sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); | ||||
|         texel_index_within_tile += sub_tile_index; | ||||
|     } | ||||
| 
 | ||||
|     const int block_width = 8; | ||||
|     const int block_height = 8; | ||||
| 
 | ||||
|     int coarse_x = (x / block_width) * block_width; | ||||
|     int coarse_y = (y / block_height) * block_height; | ||||
| 
 | ||||
|     const u8* source_ptr = source + coarse_x * block_height * 3 + coarse_y * info.stride + texel_index_within_tile * 3; | ||||
|     return { source_ptr[2], source_ptr[1], source_ptr[0], 255 }; | ||||
| } | ||||
| 
 | ||||
| void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | ||||
|     // NOTE: Permanently enabling this just trashes hard disks for no reason.
 | ||||
|     //       Hence, this is currently disabled.
 | ||||
|  | @ -420,27 +447,15 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | |||
|     buf = new u8[row_stride * texture_config.height]; | ||||
|     for (unsigned y = 0; y < texture_config.height; ++y) { | ||||
|         for (unsigned x = 0; x < texture_config.width; ++x) { | ||||
|             // Cf. rasterizer code for an explanation of this algorithm.
 | ||||
|             int texel_index_within_tile = 0; | ||||
|             for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | ||||
|                 int sub_tile_width = 1 << block_size_index; | ||||
|                 int sub_tile_height = 1 << block_size_index; | ||||
| 
 | ||||
|                 int sub_tile_index = (x & sub_tile_width) << block_size_index; | ||||
|                 sub_tile_index += 2 * ((y & sub_tile_height) << block_size_index); | ||||
|                 texel_index_within_tile += sub_tile_index; | ||||
|             } | ||||
| 
 | ||||
|             const int block_width = 8; | ||||
|             const int block_height = 8; | ||||
| 
 | ||||
|             int coarse_x = (x / block_width) * block_width; | ||||
|             int coarse_y = (y / block_height) * block_height; | ||||
| 
 | ||||
|             u8* source_ptr = (u8*)data + coarse_x * block_height * 3 + coarse_y * row_stride + texel_index_within_tile * 3; | ||||
|             buf[3 * x + y * row_stride    ] = source_ptr[2]; | ||||
|             buf[3 * x + y * row_stride + 1] = source_ptr[1]; | ||||
|             buf[3 * x + y * row_stride + 2] = source_ptr[0]; | ||||
|             TextureInfo info; | ||||
|             info.width = texture_config.width; | ||||
|             info.height = texture_config.height; | ||||
|             info.stride = row_stride; | ||||
|             info.format = registers.texture0_format; | ||||
|             Math::Vec4<u8> texture_color = LookupTexture(data, x, y, info); | ||||
|             buf[3 * x + y * row_stride    ] = texture_color.r(); | ||||
|             buf[3 * x + y * row_stride + 1] = texture_color.g(); | ||||
|             buf[3 * x + y * row_stride + 2] = texture_color.b(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ | |||
| #include <mutex> | ||||
| #include <vector> | ||||
| 
 | ||||
| #include "video_core/math.h" | ||||
| #include "video_core/pica.h" | ||||
| 
 | ||||
| namespace Pica { | ||||
|  | @ -190,6 +191,14 @@ bool IsPicaTracing(); | |||
| void OnPicaRegWrite(u32 id, u32 value); | ||||
| std::unique_ptr<PicaTrace> FinishPicaTracing(); | ||||
| 
 | ||||
| struct TextureInfo { | ||||
|     int width; | ||||
|     int height; | ||||
|     int stride; | ||||
|     Pica::Regs::TextureFormat format; | ||||
| }; | ||||
| 
 | ||||
| const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info); | ||||
| void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); | ||||
| 
 | ||||
| void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue