mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 05:40:04 +00:00 
			
		
		
		
	Pica/citra-qt: Replace command list view and command list debugging code with something more sophisticated.
This commit is contained in:
		
							parent
							
								
									0465adf206
								
							
						
					
					
						commit
						26ade98411
					
				
					 8 changed files with 142 additions and 194 deletions
				
			
		|  | @ -2,53 +2,21 @@ | |||
| // Licensed under GPLv2
 | ||||
| // Refer to the license.txt file included.
 | ||||
| 
 | ||||
| #include "graphics_cmdlists.hxx" | ||||
| #include <QListView> | ||||
| #include <QPushButton> | ||||
| #include <QVBoxLayout> | ||||
| #include <QTreeView> | ||||
| 
 | ||||
| extern GraphicsDebugger g_debugger; | ||||
| #include "graphics_cmdlists.hxx" | ||||
| 
 | ||||
| GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractItemModel(parent) | ||||
| GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent) | ||||
| { | ||||
|     root_item = new TreeItem(TreeItem::ROOT, 0, NULL, this); | ||||
| 
 | ||||
|     connect(this, SIGNAL(CommandListCalled()), this, SLOT(OnCommandListCalledInternal()), Qt::UniqueConnection); | ||||
| } | ||||
| 
 | ||||
| QModelIndex GPUCommandListModel::index(int row, int column, const QModelIndex& parent) const | ||||
| { | ||||
|     TreeItem* item; | ||||
| 
 | ||||
|     if (!parent.isValid()) { | ||||
|         item = root_item; | ||||
|     } else { | ||||
|         item = (TreeItem*)parent.internalPointer(); | ||||
|     } | ||||
| 
 | ||||
|     return createIndex(row, column, item->children[row]); | ||||
| } | ||||
| 
 | ||||
| QModelIndex GPUCommandListModel::parent(const QModelIndex& child) const | ||||
| { | ||||
|     if (!child.isValid()) | ||||
|         return QModelIndex(); | ||||
| 
 | ||||
|     TreeItem* item = (TreeItem*)child.internalPointer(); | ||||
| 
 | ||||
|     if (item->parent == NULL) | ||||
|         return QModelIndex(); | ||||
| 
 | ||||
|     return createIndex(item->parent->index, 0, item->parent); | ||||
| } | ||||
| 
 | ||||
| int GPUCommandListModel::rowCount(const QModelIndex& parent) const | ||||
| { | ||||
|     TreeItem* item; | ||||
|     if (!parent.isValid()) { | ||||
|         item = root_item; | ||||
|     } else { | ||||
|         item = (TreeItem*)parent.internalPointer(); | ||||
|     } | ||||
|     return item->children.size(); | ||||
|     return pica_trace.writes.size(); | ||||
| } | ||||
| 
 | ||||
| int GPUCommandListModel::columnCount(const QModelIndex& parent) const | ||||
|  | @ -61,79 +29,67 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | |||
|     if (!index.isValid()) | ||||
|         return QVariant(); | ||||
| 
 | ||||
|     const TreeItem* item = (const TreeItem*)index.internalPointer(); | ||||
|     const auto& writes = pica_trace.writes; | ||||
|     const Pica::CommandProcessor::CommandHeader cmd{writes[index.row()].Id()}; | ||||
|     const u32 val{writes[index.row()].Value()}; | ||||
| 
 | ||||
|     if (item->type == TreeItem::COMMAND_LIST) | ||||
|     { | ||||
|         const GraphicsDebugger::PicaCommandList& cmdlist = command_lists[item->index].second; | ||||
|         u32 address = command_lists[item->index].first; | ||||
| 
 | ||||
|         if (role == Qt::DisplayRole && index.column() == 0) | ||||
|         { | ||||
|             return QVariant(QString("0x%1 bytes at 0x%2").arg(cmdlist.size(), 0, 16).arg(address, 8, 16, QLatin1Char('0'))); | ||||
|     if (role == Qt::DisplayRole) { | ||||
|         QString content; | ||||
|         if (index.column() == 0) { | ||||
|             content = QString::fromLatin1(Pica::Regs::GetCommandName(cmd.cmd_id).c_str()); | ||||
|             content.append(" "); | ||||
|         } else if (index.column() == 1) { | ||||
|             content.append(QString("%1 ").arg(cmd.hex, 8, 16, QLatin1Char('0'))); | ||||
|             content.append(QString("%1 ").arg(val, 8, 16, QLatin1Char('0'))); | ||||
|         } | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         // index refers to a specific command
 | ||||
|         const GraphicsDebugger::PicaCommandList& cmdlist = command_lists[item->parent->index].second; | ||||
|         const GraphicsDebugger::PicaCommand& cmd = cmdlist[item->index]; | ||||
|         const Pica::CommandProcessor::CommandHeader& header = cmd.GetHeader(); | ||||
| 
 | ||||
|         if (role == Qt::DisplayRole) { | ||||
|             QString content; | ||||
|             if (index.column() == 0) { | ||||
|                 content = QString::fromLatin1(Pica::Regs::GetCommandName(header.cmd_id).c_str()); | ||||
|                 content.append(" "); | ||||
|             } else if (index.column() == 1) { | ||||
|                 for (int j = 0; j < cmd.size(); ++j) | ||||
|                     content.append(QString("%1 ").arg(cmd[j], 8, 16, QLatin1Char('0'))); | ||||
|             } | ||||
| 
 | ||||
|             return QVariant(content); | ||||
|         } | ||||
|         return QVariant(content); | ||||
|     } | ||||
| 
 | ||||
|     return QVariant(); | ||||
| } | ||||
| 
 | ||||
| void GPUCommandListModel::OnCommandListCalled(const GraphicsDebugger::PicaCommandList& lst, bool is_new) | ||||
| { | ||||
|     emit CommandListCalled(); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void GPUCommandListModel::OnCommandListCalledInternal() | ||||
| void GPUCommandListModel::OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace) | ||||
| { | ||||
|     beginResetModel(); | ||||
| 
 | ||||
|     command_lists = GetDebugger()->GetCommandLists(); | ||||
| 
 | ||||
|     // delete root item and rebuild tree
 | ||||
|     delete root_item; | ||||
|     root_item = new TreeItem(TreeItem::ROOT, 0, NULL, this); | ||||
| 
 | ||||
|     for (int command_list_idx = 0; command_list_idx < command_lists.size(); ++command_list_idx) { | ||||
|         TreeItem* command_list_item = new TreeItem(TreeItem::COMMAND_LIST, command_list_idx, root_item, root_item); | ||||
|         root_item->children.push_back(command_list_item); | ||||
| 
 | ||||
|         const GraphicsDebugger::PicaCommandList& command_list = command_lists[command_list_idx].second; | ||||
|         for (int command_idx = 0; command_idx < command_list.size(); ++command_idx) { | ||||
|             TreeItem* command_item = new TreeItem(TreeItem::COMMAND, command_idx, command_list_item, command_list_item); | ||||
|             command_list_item->children.push_back(command_item); | ||||
|         } | ||||
|     } | ||||
|     pica_trace = trace; | ||||
| 
 | ||||
|     endResetModel(); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pica Command List"), parent) | ||||
| { | ||||
|     GPUCommandListModel* model = new GPUCommandListModel(this); | ||||
|     g_debugger.RegisterObserver(model); | ||||
| 
 | ||||
|     QTreeView* tree_widget = new QTreeView; | ||||
|     tree_widget->setModel(model); | ||||
|     tree_widget->setFont(QFont("monospace")); | ||||
|     setWidget(tree_widget); | ||||
|     QWidget* main_widget = new QWidget; | ||||
| 
 | ||||
|     QTreeView* list_widget = new QTreeView; | ||||
|     list_widget->setModel(model); | ||||
|     list_widget->setFont(QFont("monospace")); | ||||
|     list_widget->setRootIsDecorated(false); | ||||
| 
 | ||||
|     QPushButton* 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&))); | ||||
| 
 | ||||
|     QVBoxLayout* main_layout = new QVBoxLayout; | ||||
|     main_layout->addWidget(list_widget); | ||||
|     main_layout->addWidget(toggle_tracing); | ||||
|     main_widget->setLayout(main_layout); | ||||
| 
 | ||||
|     setWidget(main_widget); | ||||
| } | ||||
| 
 | ||||
| void GPUCommandListWidget::OnToggleTracing() | ||||
| { | ||||
|     if (!Pica::DebugUtils::IsPicaTracing()) { | ||||
|         Pica::DebugUtils::StartPicaTracing(); | ||||
|     } else { | ||||
|         pica_trace = Pica::DebugUtils::FinishPicaTracing(); | ||||
|         emit TracingFinished(*pica_trace); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -4,53 +4,28 @@ | |||
| 
 | ||||
| #pragma once | ||||
| 
 | ||||
| #include <QAbstractItemModel> | ||||
| #include <QAbstractListModel> | ||||
| #include <QDockWidget> | ||||
| 
 | ||||
| #include "video_core/gpu_debugger.h" | ||||
| #include "video_core/debug_utils/debug_utils.h" | ||||
| 
 | ||||
| // TODO: Rename class, since it's not actually a list model anymore...
 | ||||
| class GPUCommandListModel : public QAbstractItemModel, public GraphicsDebugger::DebuggerObserver | ||||
| class GPUCommandListModel : public QAbstractListModel | ||||
| { | ||||
|     Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|     GPUCommandListModel(QObject* parent); | ||||
| 
 | ||||
|     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const; | ||||
|     QModelIndex parent(const QModelIndex& child) const; | ||||
|     int columnCount(const QModelIndex& parent = QModelIndex()) const; | ||||
|     int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||||
|     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||||
| 
 | ||||
| public: | ||||
|     void OnCommandListCalled(const GraphicsDebugger::PicaCommandList& lst, bool is_new) override; | ||||
| 
 | ||||
| public slots: | ||||
|     void OnCommandListCalledInternal(); | ||||
| 
 | ||||
| signals: | ||||
|     void CommandListCalled(); | ||||
|     void OnPicaTraceFinished(const Pica::DebugUtils::PicaTrace& trace); | ||||
| 
 | ||||
| private: | ||||
|     struct TreeItem : public QObject | ||||
|     { | ||||
|         enum Type { | ||||
|             ROOT, | ||||
|             COMMAND_LIST, | ||||
|             COMMAND | ||||
|         }; | ||||
| 
 | ||||
|         TreeItem(Type type, int index, TreeItem* item_parent, QObject* parent) : QObject(parent), type(type), index(index), parent(item_parent) {} | ||||
| 
 | ||||
|         Type type; | ||||
|         int index; | ||||
|         std::vector<TreeItem*> children; | ||||
|         TreeItem* parent; | ||||
|     }; | ||||
| 
 | ||||
|     std::vector<std::pair<u32,GraphicsDebugger::PicaCommandList>> command_lists; | ||||
|     TreeItem* root_item; | ||||
|     Pica::DebugUtils::PicaTrace pica_trace; | ||||
| }; | ||||
| 
 | ||||
| class GPUCommandListWidget : public QDockWidget | ||||
|  | @ -60,5 +35,12 @@ class GPUCommandListWidget : public QDockWidget | |||
| public: | ||||
|     GPUCommandListWidget(QWidget* parent = 0); | ||||
| 
 | ||||
| public slots: | ||||
|     void OnToggleTracing(); | ||||
| 
 | ||||
| signals: | ||||
|     void TracingFinished(const Pica::DebugUtils::PicaTrace&); | ||||
| 
 | ||||
| private: | ||||
|     std::unique_ptr<Pica::DebugUtils::PicaTrace> pica_trace; | ||||
| }; | ||||
|  |  | |||
|  | @ -52,11 +52,11 @@ GMainWindow::GMainWindow() | |||
| 
 | ||||
|     graphicsWidget = new GPUCommandStreamWidget(this); | ||||
|     addDockWidget(Qt::RightDockWidgetArea, graphicsWidget); | ||||
|     callstackWidget->hide(); | ||||
|     graphicsWidget ->hide(); | ||||
| 
 | ||||
|     graphicsCommandsWidget = new GPUCommandListWidget(this); | ||||
|     addDockWidget(Qt::RightDockWidgetArea, graphicsCommandsWidget); | ||||
|     callstackWidget->hide(); | ||||
|     graphicsCommandsWidget->hide(); | ||||
| 
 | ||||
|     QMenu* debug_menu = ui.menu_View->addMenu(tr("Debugging")); | ||||
|     debug_menu->addAction(disasmWidget->toggleViewAction()); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue