graphics.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <QListView>
  5. #include "citra_qt/debugger/graphics.h"
  6. #include "citra_qt/util/util.h"
  7. extern GraphicsDebugger g_debugger;
  8. GPUCommandStreamItemModel::GPUCommandStreamItemModel(QObject* parent)
  9. : QAbstractListModel(parent), command_count(0) {
  10. connect(this, SIGNAL(GXCommandFinished(int)), this, SLOT(OnGXCommandFinishedInternal(int)));
  11. }
  12. int GPUCommandStreamItemModel::rowCount(const QModelIndex& parent) const {
  13. return command_count;
  14. }
  15. QVariant GPUCommandStreamItemModel::data(const QModelIndex& index, int role) const {
  16. if (!index.isValid())
  17. return QVariant();
  18. int command_index = index.row();
  19. const Service::GSP::Command& command = GetDebugger()->ReadGXCommandHistory(command_index);
  20. if (role == Qt::DisplayRole) {
  21. std::map<Service::GSP::CommandId, const char*> command_names = {
  22. {Service::GSP::CommandId::REQUEST_DMA, "REQUEST_DMA"},
  23. {Service::GSP::CommandId::SUBMIT_GPU_CMDLIST, "SUBMIT_GPU_CMDLIST"},
  24. {Service::GSP::CommandId::SET_MEMORY_FILL, "SET_MEMORY_FILL"},
  25. {Service::GSP::CommandId::SET_DISPLAY_TRANSFER, "SET_DISPLAY_TRANSFER"},
  26. {Service::GSP::CommandId::SET_TEXTURE_COPY, "SET_TEXTURE_COPY"},
  27. {Service::GSP::CommandId::CACHE_FLUSH, "CACHE_FLUSH"},
  28. };
  29. const u32* command_data = reinterpret_cast<const u32*>(&command);
  30. QString str = QString("%1 %2 %3 %4 %5 %6 %7 %8 %9")
  31. .arg(command_names[command.id])
  32. .arg(command_data[0], 8, 16, QLatin1Char('0'))
  33. .arg(command_data[1], 8, 16, QLatin1Char('0'))
  34. .arg(command_data[2], 8, 16, QLatin1Char('0'))
  35. .arg(command_data[3], 8, 16, QLatin1Char('0'))
  36. .arg(command_data[4], 8, 16, QLatin1Char('0'))
  37. .arg(command_data[5], 8, 16, QLatin1Char('0'))
  38. .arg(command_data[6], 8, 16, QLatin1Char('0'))
  39. .arg(command_data[7], 8, 16, QLatin1Char('0'));
  40. return QVariant(str);
  41. } else {
  42. return QVariant();
  43. }
  44. }
  45. void GPUCommandStreamItemModel::GXCommandProcessed(int total_command_count) {
  46. emit GXCommandFinished(total_command_count);
  47. }
  48. void GPUCommandStreamItemModel::OnGXCommandFinishedInternal(int total_command_count) {
  49. if (total_command_count == 0)
  50. return;
  51. int prev_command_count = command_count;
  52. command_count = total_command_count;
  53. emit dataChanged(index(prev_command_count, 0), index(total_command_count - 1, 0));
  54. }
  55. GPUCommandStreamWidget::GPUCommandStreamWidget(QWidget* parent)
  56. : QDockWidget(tr("Graphics Debugger"), parent) {
  57. setObjectName("GraphicsDebugger");
  58. GPUCommandStreamItemModel* command_model = new GPUCommandStreamItemModel(this);
  59. g_debugger.RegisterObserver(command_model);
  60. QListView* command_list = new QListView;
  61. command_list->setModel(command_model);
  62. command_list->setFont(GetMonospaceFont());
  63. setWidget(command_list);
  64. }