Refine command list debugging functionality and its qt interface.
This commit is contained in:
		| @@ -3,18 +3,57 @@ | |||||||
| // Refer to the license.txt file included. | // Refer to the license.txt file included. | ||||||
|  |  | ||||||
| #include "graphics_cmdlists.hxx" | #include "graphics_cmdlists.hxx" | ||||||
| #include <QListView> | #include <QTreeView> | ||||||
|  |  | ||||||
| extern GraphicsDebugger g_debugger; | extern GraphicsDebugger g_debugger; | ||||||
|  |  | ||||||
| GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractListModel(parent), row_count(0) | GPUCommandListModel::GPUCommandListModel(QObject* parent) : QAbstractItemModel(parent) | ||||||
| { | { | ||||||
|  |     root_item = new TreeItem(TreeItem::ROOT, 0, NULL, this); | ||||||
|  |  | ||||||
|     connect(this, SIGNAL(CommandListCalled()), this, SLOT(OnCommandListCalledInternal()), Qt::UniqueConnection); |     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 | int GPUCommandListModel::rowCount(const QModelIndex& parent) const | ||||||
| { | { | ||||||
|     return row_count; |     TreeItem* item; | ||||||
|  |     if (!parent.isValid()) { | ||||||
|  |         item = root_item; | ||||||
|  |     } else { | ||||||
|  |         item = (TreeItem*)parent.internalPointer(); | ||||||
|  |     } | ||||||
|  |     return item->children.size(); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int GPUCommandListModel::columnCount(const QModelIndex& parent) const | ||||||
|  | { | ||||||
|  |     return 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | ||||||
| @@ -22,19 +61,33 @@ QVariant GPUCommandListModel::data(const QModelIndex& index, int role) const | |||||||
|     if (!index.isValid()) |     if (!index.isValid()) | ||||||
|         return QVariant(); |         return QVariant(); | ||||||
|  |  | ||||||
|     int idx = index.row(); |     const TreeItem* item = (const TreeItem*)index.internalPointer(); | ||||||
|     if (role == Qt::DisplayRole) |  | ||||||
|  |     if (item->type == TreeItem::COMMAND_LIST) | ||||||
|     { |     { | ||||||
|         QString content; |         const GraphicsDebugger::PicaCommandList& cmdlist = command_lists[item->index].second; | ||||||
|         const GraphicsDebugger::PicaCommandList& cmdlist = command_list[idx].second; |         u32 address = command_lists[item->index].first; | ||||||
|         for (int i = 0; i < cmdlist.size(); ++i) |  | ||||||
|  |         if (role == Qt::DisplayRole) | ||||||
|         { |         { | ||||||
|             const GraphicsDebugger::PicaCommand& cmd = cmdlist[i]; |             return QVariant(QString("0x%1 bytes at 0x%2").arg(cmdlist.size(), 0, 16).arg(address, 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]; | ||||||
|  |  | ||||||
|  |         if (role == Qt::DisplayRole) { | ||||||
|  |             QString content; | ||||||
|             for (int j = 0; j < cmd.size(); ++j) |             for (int j = 0; j < cmd.size(); ++j) | ||||||
|                 content.append(QString("%1 ").arg(cmd[j], 8, 16, QLatin1Char('0'))); |                 content.append(QString("%1 ").arg(cmd[j], 8, 16, QLatin1Char('0'))); | ||||||
|  |  | ||||||
|  |             return QVariant(content); | ||||||
|         } |         } | ||||||
|         return QVariant(content); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return QVariant(); |     return QVariant(); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -48,8 +101,22 @@ void GPUCommandListModel::OnCommandListCalledInternal() | |||||||
| { | { | ||||||
|     beginResetModel(); |     beginResetModel(); | ||||||
|  |  | ||||||
|     command_list = GetDebugger()->GetCommandLists(); |     command_lists = GetDebugger()->GetCommandLists(); | ||||||
|     row_count = command_list.size(); |  | ||||||
|  |     // 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); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |  | ||||||
|     endResetModel(); |     endResetModel(); | ||||||
| } | } | ||||||
| @@ -59,7 +126,8 @@ GPUCommandListWidget::GPUCommandListWidget(QWidget* parent) : QDockWidget(tr("Pi | |||||||
|     GPUCommandListModel* model = new GPUCommandListModel(this); |     GPUCommandListModel* model = new GPUCommandListModel(this); | ||||||
|     g_debugger.RegisterObserver(model); |     g_debugger.RegisterObserver(model); | ||||||
|  |  | ||||||
|     QListView* list_widget = new QListView; |     QTreeView* tree_widget = new QTreeView; | ||||||
|     list_widget->setModel(model); |     tree_widget->setModel(model); | ||||||
|     setWidget(list_widget); |     tree_widget->setFont(QFont("monospace")); | ||||||
|  |     setWidget(tree_widget); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -4,18 +4,22 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <QAbstractListModel> | #include <QAbstractItemModel> | ||||||
| #include <QDockWidget> | #include <QDockWidget> | ||||||
|  |  | ||||||
| #include "video_core/gpu_debugger.h" | #include "video_core/gpu_debugger.h" | ||||||
|  |  | ||||||
| class GPUCommandListModel : public QAbstractListModel, public GraphicsDebugger::DebuggerObserver | // TODO: Rename class, since it's not actually a list model anymore... | ||||||
|  | class GPUCommandListModel : public QAbstractItemModel, public GraphicsDebugger::DebuggerObserver | ||||||
| { | { | ||||||
|     Q_OBJECT |     Q_OBJECT | ||||||
|  |  | ||||||
| public: | public: | ||||||
|     GPUCommandListModel(QObject* parent); |     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; |     int rowCount(const QModelIndex& parent = QModelIndex()) const override; | ||||||
|     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | ||||||
|  |  | ||||||
| @@ -29,8 +33,24 @@ signals: | |||||||
|     void CommandListCalled(); |     void CommandListCalled(); | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     int row_count; |     struct TreeItem : public QObject | ||||||
|     std::vector<std::pair<u32,GraphicsDebugger::PicaCommandList>> command_list; |     { | ||||||
|  |         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; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| class GPUCommandListWidget : public QDockWidget | class GPUCommandListWidget : public QDockWidget | ||||||
|   | |||||||
| @@ -22,7 +22,8 @@ public: | |||||||
|     { |     { | ||||||
|         Pica::CommandHeader& GetHeader() |         Pica::CommandHeader& GetHeader() | ||||||
|         { |         { | ||||||
|             return *(Pica::CommandHeader*)&(front()); |             u32& val = at(1); | ||||||
|  |             return *(Pica::CommandHeader*)&val; | ||||||
|         } |         } | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| @@ -90,14 +91,20 @@ public: | |||||||
|  |  | ||||||
|     void CommandListCalled(u32 address, u32* command_list, u32 size_in_words) |     void CommandListCalled(u32 address, u32* command_list, u32 size_in_words) | ||||||
|     { |     { | ||||||
|         // TODO: Decoding fun |  | ||||||
|  |  | ||||||
|         // For now, just treating the whole command list as a single command |  | ||||||
|         PicaCommandList cmdlist; |         PicaCommandList cmdlist; | ||||||
|         cmdlist.push_back(PicaCommand()); |         for (u32* parse_pointer = command_list; parse_pointer < command_list + size_in_words;) | ||||||
|         auto& cmd = cmdlist[0]; |         { | ||||||
|         cmd.reserve(size_in_words); |             const Pica::CommandHeader header = static_cast<Pica::CommandHeader>(parse_pointer[1]); | ||||||
|         std::copy(command_list, command_list+size_in_words, std::back_inserter(cmd)); |  | ||||||
|  |             cmdlist.push_back(PicaCommand()); | ||||||
|  |             auto& cmd = cmdlist.back(); | ||||||
|  |  | ||||||
|  |             size_t size = 2 + header.extra_data_length; | ||||||
|  |             cmd.reserve(size); | ||||||
|  |             std::copy(parse_pointer, parse_pointer + size, std::back_inserter(cmd)); | ||||||
|  |  | ||||||
|  |             parse_pointer += size; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         auto obj = std::pair<u32,PicaCommandList>(address, cmdlist); |         auto obj = std::pair<u32,PicaCommandList>(address, cmdlist); | ||||||
|         auto it = std::find(command_lists.begin(), command_lists.end(), obj); |         auto it = std::find(command_lists.begin(), command_lists.end(), obj); | ||||||
|   | |||||||
| @@ -24,6 +24,8 @@ enum class CommandId : u32 | |||||||
| }; | }; | ||||||
|  |  | ||||||
| union CommandHeader { | union CommandHeader { | ||||||
|  |     CommandHeader(u32 h) : hex(h) {} | ||||||
|  |  | ||||||
|     u32 hex; |     u32 hex; | ||||||
|  |  | ||||||
|     BitField< 0, 16, CommandId> cmd_id; |     BitField< 0, 16, CommandId> cmd_id; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user