graphics_vertex_shader.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "citra_qt/debugger/graphics_vertex_shader.h"
  5. #include <iomanip>
  6. #include <sstream>
  7. #include <QBoxLayout>
  8. #include <QFileDialog>
  9. #include <QFormLayout>
  10. #include <QGroupBox>
  11. #include <QLabel>
  12. #include <QLineEdit>
  13. #include <QPushButton>
  14. #include <QSignalMapper>
  15. #include <QSpinBox>
  16. #include <QTreeView>
  17. #include "citra_qt/util/util.h"
  18. #include "video_core/pica.h"
  19. #include "video_core/pica_state.h"
  20. #include "video_core/shader/shader.h"
  21. using nihstro::OpCode;
  22. using nihstro::Instruction;
  23. using nihstro::SourceRegister;
  24. using nihstro::SwizzlePattern;
  25. GraphicsVertexShaderModel::GraphicsVertexShaderModel(GraphicsVertexShaderWidget* parent)
  26. : QAbstractTableModel(parent), par(parent) {}
  27. int GraphicsVertexShaderModel::columnCount(const QModelIndex& parent) const {
  28. return 3;
  29. }
  30. int GraphicsVertexShaderModel::rowCount(const QModelIndex& parent) const {
  31. return static_cast<int>(par->info.code.size());
  32. }
  33. QVariant GraphicsVertexShaderModel::headerData(int section, Qt::Orientation orientation,
  34. int role) const {
  35. switch (role) {
  36. case Qt::DisplayRole: {
  37. if (section == 0) {
  38. return tr("Offset");
  39. } else if (section == 1) {
  40. return tr("Raw");
  41. } else if (section == 2) {
  42. return tr("Disassembly");
  43. }
  44. break;
  45. }
  46. }
  47. return QVariant();
  48. }
  49. static std::string SelectorToString(u32 selector) {
  50. std::string ret;
  51. for (int i = 0; i < 4; ++i) {
  52. int component = (selector >> ((3 - i) * 2)) & 3;
  53. ret += "xyzw"[component];
  54. }
  55. return ret;
  56. }
  57. // e.g. "-c92[a0.x].xyzw"
  58. static void print_input(std::ostringstream& output, const SourceRegister& input, bool negate,
  59. const std::string& swizzle_mask, bool align = true,
  60. const std::string& address_register_name = std::string()) {
  61. if (align)
  62. output << std::setw(4) << std::right;
  63. output << ((negate ? "-" : "") + input.GetName());
  64. if (!address_register_name.empty())
  65. output << '[' << address_register_name << ']';
  66. output << '.' << swizzle_mask;
  67. };
  68. QVariant GraphicsVertexShaderModel::data(const QModelIndex& index, int role) const {
  69. switch (role) {
  70. case Qt::DisplayRole: {
  71. switch (index.column()) {
  72. case 0:
  73. if (par->info.HasLabel(index.row()))
  74. return QString::fromStdString(par->info.GetLabel(index.row()));
  75. return QString("%1").arg(4 * index.row(), 4, 16, QLatin1Char('0'));
  76. case 1:
  77. return QString("%1").arg(par->info.code[index.row()].hex, 8, 16, QLatin1Char('0'));
  78. case 2: {
  79. std::ostringstream output;
  80. output.flags(std::ios::uppercase);
  81. // To make the code aligning columns of assembly easier to keep track of, this function
  82. // keeps track of the start of the start of the previous column, allowing alignment
  83. // based on desired field widths.
  84. int current_column = 0;
  85. auto AlignToColumn = [&](int col_width) {
  86. // Prints spaces to the output to pad previous column to size and advances the
  87. // column marker.
  88. current_column += col_width;
  89. int to_add = std::max(1, current_column - (int)output.tellp());
  90. for (int i = 0; i < to_add; ++i) {
  91. output << ' ';
  92. }
  93. };
  94. const Instruction instr = par->info.code[index.row()];
  95. const OpCode opcode = instr.opcode;
  96. const OpCode::Info opcode_info = opcode.GetInfo();
  97. const u32 operand_desc_id = opcode_info.type == OpCode::Type::MultiplyAdd
  98. ? instr.mad.operand_desc_id.Value()
  99. : instr.common.operand_desc_id.Value();
  100. const SwizzlePattern swizzle = par->info.swizzle_info[operand_desc_id].pattern;
  101. // longest known instruction name: "setemit "
  102. int kOpcodeColumnWidth = 8;
  103. // "rXX.xyzw "
  104. int kOutputColumnWidth = 10;
  105. // "-rXX.xyzw ", no attempt is made to align indexed inputs
  106. int kInputOperandColumnWidth = 11;
  107. output << opcode_info.name;
  108. switch (opcode_info.type) {
  109. case OpCode::Type::Trivial:
  110. // Nothing to do here
  111. break;
  112. case OpCode::Type::Arithmetic:
  113. case OpCode::Type::MultiplyAdd: {
  114. // Use custom code for special instructions
  115. switch (opcode.EffectiveOpCode()) {
  116. case OpCode::Id::CMP: {
  117. AlignToColumn(kOpcodeColumnWidth);
  118. // NOTE: CMP always writes both cc components, so we do not consider the dest
  119. // mask here.
  120. output << " cc.xy";
  121. AlignToColumn(kOutputColumnWidth);
  122. SourceRegister src1 = instr.common.GetSrc1(false);
  123. SourceRegister src2 = instr.common.GetSrc2(false);
  124. output << ' ';
  125. print_input(output, src1, swizzle.negate_src1,
  126. swizzle.SelectorToString(false).substr(0, 1), false,
  127. instr.common.AddressRegisterName());
  128. output << ' ' << instr.common.compare_op.ToString(instr.common.compare_op.x)
  129. << ' ';
  130. print_input(output, src2, swizzle.negate_src2,
  131. swizzle.SelectorToString(true).substr(0, 1), false);
  132. output << ", ";
  133. print_input(output, src1, swizzle.negate_src1,
  134. swizzle.SelectorToString(false).substr(1, 1), false,
  135. instr.common.AddressRegisterName());
  136. output << ' ' << instr.common.compare_op.ToString(instr.common.compare_op.y)
  137. << ' ';
  138. print_input(output, src2, swizzle.negate_src2,
  139. swizzle.SelectorToString(true).substr(1, 1), false);
  140. break;
  141. }
  142. case OpCode::Id::MAD:
  143. case OpCode::Id::MADI: {
  144. AlignToColumn(kOpcodeColumnWidth);
  145. bool src_is_inverted = 0 != (opcode_info.subtype & OpCode::Info::SrcInversed);
  146. SourceRegister src1 = instr.mad.GetSrc1(src_is_inverted);
  147. SourceRegister src2 = instr.mad.GetSrc2(src_is_inverted);
  148. SourceRegister src3 = instr.mad.GetSrc3(src_is_inverted);
  149. output << std::setw(3) << std::right << instr.mad.dest.Value().GetName() << '.'
  150. << swizzle.DestMaskToString();
  151. AlignToColumn(kOutputColumnWidth);
  152. print_input(output, src1, swizzle.negate_src1,
  153. SelectorToString(swizzle.src1_selector));
  154. AlignToColumn(kInputOperandColumnWidth);
  155. if (src_is_inverted) {
  156. print_input(output, src2, swizzle.negate_src2,
  157. SelectorToString(swizzle.src2_selector));
  158. } else {
  159. print_input(output, src2, swizzle.negate_src2,
  160. SelectorToString(swizzle.src2_selector), true,
  161. instr.mad.AddressRegisterName());
  162. }
  163. AlignToColumn(kInputOperandColumnWidth);
  164. if (src_is_inverted) {
  165. print_input(output, src3, swizzle.negate_src3,
  166. SelectorToString(swizzle.src3_selector), true,
  167. instr.mad.AddressRegisterName());
  168. } else {
  169. print_input(output, src3, swizzle.negate_src3,
  170. SelectorToString(swizzle.src3_selector));
  171. }
  172. AlignToColumn(kInputOperandColumnWidth);
  173. break;
  174. }
  175. default: {
  176. AlignToColumn(kOpcodeColumnWidth);
  177. bool src_is_inverted = 0 != (opcode_info.subtype & OpCode::Info::SrcInversed);
  178. if (opcode_info.subtype & OpCode::Info::Dest) {
  179. // e.g. "r12.xy__"
  180. output << std::setw(3) << std::right << instr.common.dest.Value().GetName()
  181. << '.' << swizzle.DestMaskToString();
  182. } else if (opcode_info.subtype == OpCode::Info::MOVA) {
  183. output << " a0." << swizzle.DestMaskToString();
  184. }
  185. AlignToColumn(kOutputColumnWidth);
  186. if (opcode_info.subtype & OpCode::Info::Src1) {
  187. SourceRegister src1 = instr.common.GetSrc1(src_is_inverted);
  188. print_input(output, src1, swizzle.negate_src1,
  189. swizzle.SelectorToString(false), true,
  190. instr.common.AddressRegisterName());
  191. AlignToColumn(kInputOperandColumnWidth);
  192. }
  193. // TODO: In some cases, the Address Register is used as an index for SRC2
  194. // instead of SRC1
  195. if (opcode_info.subtype & OpCode::Info::Src2) {
  196. SourceRegister src2 = instr.common.GetSrc2(src_is_inverted);
  197. print_input(output, src2, swizzle.negate_src2,
  198. swizzle.SelectorToString(true));
  199. AlignToColumn(kInputOperandColumnWidth);
  200. }
  201. break;
  202. }
  203. }
  204. break;
  205. }
  206. case OpCode::Type::Conditional:
  207. case OpCode::Type::UniformFlowControl: {
  208. output << ' ';
  209. switch (opcode.EffectiveOpCode()) {
  210. case OpCode::Id::LOOP:
  211. output << "(unknown instruction format)";
  212. break;
  213. default:
  214. if (opcode_info.subtype & OpCode::Info::HasCondition) {
  215. output << '(';
  216. if (instr.flow_control.op != instr.flow_control.JustY) {
  217. if (instr.flow_control.refx)
  218. output << '!';
  219. output << "cc.x";
  220. }
  221. if (instr.flow_control.op == instr.flow_control.Or) {
  222. output << " || ";
  223. } else if (instr.flow_control.op == instr.flow_control.And) {
  224. output << " && ";
  225. }
  226. if (instr.flow_control.op != instr.flow_control.JustX) {
  227. if (instr.flow_control.refy)
  228. output << '!';
  229. output << "cc.y";
  230. }
  231. output << ") ";
  232. } else if (opcode_info.subtype & OpCode::Info::HasUniformIndex) {
  233. output << 'b' << instr.flow_control.bool_uniform_id << ' ';
  234. }
  235. u32 target_addr = instr.flow_control.dest_offset;
  236. u32 target_addr_else = instr.flow_control.dest_offset;
  237. if (opcode_info.subtype & OpCode::Info::HasAlternative) {
  238. output << "else jump to 0x" << std::setw(4) << std::right
  239. << std::setfill('0') << std::hex
  240. << (4 * instr.flow_control.dest_offset);
  241. } else if (opcode_info.subtype & OpCode::Info::HasExplicitDest) {
  242. output << "jump to 0x" << std::setw(4) << std::right << std::setfill('0')
  243. << std::hex << (4 * instr.flow_control.dest_offset);
  244. } else {
  245. // TODO: Handle other cases
  246. output << "(unknown destination)";
  247. }
  248. if (opcode_info.subtype & OpCode::Info::HasFinishPoint) {
  249. output << " (return on 0x" << std::setw(4) << std::right
  250. << std::setfill('0') << std::hex
  251. << (4 * instr.flow_control.dest_offset +
  252. 4 * instr.flow_control.num_instructions)
  253. << ')';
  254. }
  255. break;
  256. }
  257. break;
  258. }
  259. default:
  260. output << " (unknown instruction format)";
  261. break;
  262. }
  263. return QString::fromLatin1(output.str().c_str());
  264. }
  265. default:
  266. break;
  267. }
  268. }
  269. case Qt::FontRole:
  270. return GetMonospaceFont();
  271. case Qt::BackgroundRole: {
  272. // Highlight current instruction
  273. int current_record_index = par->cycle_index->value();
  274. if (current_record_index < static_cast<int>(par->debug_data.records.size())) {
  275. const auto& current_record = par->debug_data.records[current_record_index];
  276. if (index.row() == static_cast<int>(current_record.instruction_offset)) {
  277. return QColor(255, 255, 63);
  278. }
  279. }
  280. // Use a grey background for instructions which have no debug data associated to them
  281. for (const auto& record : par->debug_data.records)
  282. if (index.row() == static_cast<int>(record.instruction_offset))
  283. return QVariant();
  284. return QBrush(QColor(192, 192, 192));
  285. }
  286. // TODO: Draw arrows for each "reachable" instruction to visualize control flow
  287. default:
  288. break;
  289. }
  290. return QVariant();
  291. }
  292. void GraphicsVertexShaderWidget::DumpShader() {
  293. QString filename = QFileDialog::getSaveFileName(
  294. this, tr("Save Shader Dump"), "shader_dump.shbin", tr("Shader Binary (*.shbin)"));
  295. if (filename.isEmpty()) {
  296. // If the user canceled the dialog, don't dump anything.
  297. return;
  298. }
  299. auto& setup = Pica::g_state.vs;
  300. auto& config = Pica::g_state.regs.vs;
  301. Pica::DebugUtils::DumpShader(filename.toStdString(), config, setup,
  302. Pica::g_state.regs.vs_output_attributes);
  303. }
  304. GraphicsVertexShaderWidget::GraphicsVertexShaderWidget(
  305. std::shared_ptr<Pica::DebugContext> debug_context, QWidget* parent)
  306. : BreakPointObserverDock(debug_context, "Pica Vertex Shader", parent) {
  307. setObjectName("PicaVertexShader");
  308. // Clear input vertex data so that it contains valid float values in case a debug shader
  309. // execution happens before the first Vertex Loaded breakpoint.
  310. // TODO: This makes a crash in the interpreter much less likely, but not impossible. The
  311. // interpreter should guard against out-of-bounds accesses to ensure crashes in it aren't
  312. // possible.
  313. std::memset(&input_vertex, 0, sizeof(input_vertex));
  314. auto input_data_mapper = new QSignalMapper(this);
  315. // TODO: Support inputting data in hexadecimal raw format
  316. for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) {
  317. input_data[i] = new QLineEdit;
  318. input_data[i]->setValidator(new QDoubleValidator(input_data[i]));
  319. }
  320. breakpoint_warning =
  321. new QLabel(tr("(data only available at vertex shader invocation breakpoints)"));
  322. // TODO: Add some button for jumping to the shader entry point
  323. model = new GraphicsVertexShaderModel(this);
  324. binary_list = new QTreeView;
  325. binary_list->setModel(model);
  326. binary_list->setRootIsDecorated(false);
  327. binary_list->setAlternatingRowColors(true);
  328. auto dump_shader = new QPushButton(QIcon::fromTheme("document-save"), tr("Dump"));
  329. instruction_description = new QLabel;
  330. cycle_index = new QSpinBox;
  331. connect(dump_shader, SIGNAL(clicked()), this, SLOT(DumpShader()));
  332. connect(cycle_index, SIGNAL(valueChanged(int)), this, SLOT(OnCycleIndexChanged(int)));
  333. for (unsigned i = 0; i < ARRAY_SIZE(input_data); ++i) {
  334. connect(input_data[i], SIGNAL(textEdited(const QString&)), input_data_mapper, SLOT(map()));
  335. input_data_mapper->setMapping(input_data[i], i);
  336. }
  337. connect(input_data_mapper, SIGNAL(mapped(int)), this, SLOT(OnInputAttributeChanged(int)));
  338. auto main_widget = new QWidget;
  339. auto main_layout = new QVBoxLayout;
  340. {
  341. auto input_data_group = new QGroupBox(tr("Input Data"));
  342. // For each vertex attribute, add a QHBoxLayout consisting of:
  343. // - A QLabel denoting the source attribute index
  344. // - Four QLineEdits for showing and manipulating attribute data
  345. // - A QLabel denoting the shader input attribute index
  346. auto sub_layout = new QVBoxLayout;
  347. for (unsigned i = 0; i < 16; ++i) {
  348. // Create an HBoxLayout to store the widgets used to specify a particular attribute
  349. // and store it in a QWidget to allow for easy hiding and unhiding.
  350. auto row_layout = new QHBoxLayout;
  351. // Remove unecessary padding between rows
  352. row_layout->setContentsMargins(0, 0, 0, 0);
  353. row_layout->addWidget(new QLabel(tr("Attribute %1").arg(i, 2)));
  354. for (unsigned comp = 0; comp < 4; ++comp)
  355. row_layout->addWidget(input_data[4 * i + comp]);
  356. row_layout->addWidget(input_data_mapping[i] = new QLabel);
  357. input_data_container[i] = new QWidget;
  358. input_data_container[i]->setLayout(row_layout);
  359. input_data_container[i]->hide();
  360. sub_layout->addWidget(input_data_container[i]);
  361. }
  362. sub_layout->addWidget(breakpoint_warning);
  363. breakpoint_warning->hide();
  364. input_data_group->setLayout(sub_layout);
  365. main_layout->addWidget(input_data_group);
  366. }
  367. // Make program listing expand to fill available space in the dialog
  368. binary_list->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
  369. main_layout->addWidget(binary_list);
  370. main_layout->addWidget(dump_shader);
  371. {
  372. auto sub_layout = new QFormLayout;
  373. sub_layout->addRow(tr("Cycle Index:"), cycle_index);
  374. main_layout->addLayout(sub_layout);
  375. }
  376. // Set a minimum height so that the size of this label doesn't cause the rest of the bottom
  377. // part of the UI to keep jumping up and down when cycling through instructions.
  378. instruction_description->setMinimumHeight(instruction_description->fontMetrics().lineSpacing() *
  379. 6);
  380. instruction_description->setAlignment(Qt::AlignLeft | Qt::AlignTop);
  381. main_layout->addWidget(instruction_description);
  382. main_widget->setLayout(main_layout);
  383. setWidget(main_widget);
  384. widget()->setEnabled(false);
  385. }
  386. void GraphicsVertexShaderWidget::OnBreakPointHit(Pica::DebugContext::Event event, void* data) {
  387. auto input = static_cast<Pica::Shader::InputVertex*>(data);
  388. if (event == Pica::DebugContext::Event::VertexShaderInvocation) {
  389. Reload(true, data);
  390. } else {
  391. // No vertex data is retrievable => invalidate currently stored vertex data
  392. Reload(true, nullptr);
  393. }
  394. widget()->setEnabled(true);
  395. }
  396. void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_data) {
  397. model->beginResetModel();
  398. if (replace_vertex_data) {
  399. if (vertex_data) {
  400. memcpy(&input_vertex, vertex_data, sizeof(input_vertex));
  401. for (unsigned attr = 0; attr < 16; ++attr) {
  402. for (unsigned comp = 0; comp < 4; ++comp) {
  403. input_data[4 * attr + comp]->setText(
  404. QString("%1").arg(input_vertex.attr[attr][comp].ToFloat32()));
  405. }
  406. }
  407. breakpoint_warning->hide();
  408. } else {
  409. for (unsigned attr = 0; attr < 16; ++attr) {
  410. for (unsigned comp = 0; comp < 4; ++comp) {
  411. input_data[4 * attr + comp]->setText(QString("???"));
  412. }
  413. }
  414. breakpoint_warning->show();
  415. }
  416. }
  417. // Reload shader code
  418. info.Clear();
  419. auto& shader_setup = Pica::g_state.vs;
  420. auto& shader_config = Pica::g_state.regs.vs;
  421. for (auto instr : shader_setup.program_code)
  422. info.code.push_back({instr});
  423. int num_attributes = Pica::g_state.regs.vertex_attributes.GetNumTotalAttributes();
  424. for (auto pattern : shader_setup.swizzle_data)
  425. info.swizzle_info.push_back({pattern});
  426. u32 entry_point = Pica::g_state.regs.vs.main_offset;
  427. info.labels.insert({entry_point, "main"});
  428. // Generate debug information
  429. debug_data = Pica::g_state.vs.ProduceDebugInfo(input_vertex, num_attributes, shader_config,
  430. shader_setup);
  431. // Reload widget state
  432. for (int attr = 0; attr < num_attributes; ++attr) {
  433. unsigned source_attr = shader_config.input_register_map.GetRegisterForAttribute(attr);
  434. input_data_mapping[attr]->setText(QString("-> v%1").arg(source_attr));
  435. input_data_container[attr]->setVisible(true);
  436. }
  437. // Only show input attributes which are used as input to the shader
  438. for (unsigned int attr = num_attributes; attr < 16; ++attr) {
  439. input_data_container[attr]->setVisible(false);
  440. }
  441. // Initialize debug info text for current cycle count
  442. cycle_index->setMaximum(static_cast<int>(debug_data.records.size() - 1));
  443. OnCycleIndexChanged(cycle_index->value());
  444. model->endResetModel();
  445. }
  446. void GraphicsVertexShaderWidget::OnResumed() {
  447. widget()->setEnabled(false);
  448. }
  449. void GraphicsVertexShaderWidget::OnInputAttributeChanged(int index) {
  450. float value = input_data[index]->text().toFloat();
  451. input_vertex.attr[index / 4][index % 4] = Pica::float24::FromFloat32(value);
  452. // Re-execute shader with updated value
  453. Reload();
  454. }
  455. void GraphicsVertexShaderWidget::OnCycleIndexChanged(int index) {
  456. QString text;
  457. auto& record = debug_data.records[index];
  458. if (record.mask & Pica::Shader::DebugDataRecord::SRC1)
  459. text += tr("SRC1: %1, %2, %3, %4\n")
  460. .arg(record.src1.x.ToFloat32())
  461. .arg(record.src1.y.ToFloat32())
  462. .arg(record.src1.z.ToFloat32())
  463. .arg(record.src1.w.ToFloat32());
  464. if (record.mask & Pica::Shader::DebugDataRecord::SRC2)
  465. text += tr("SRC2: %1, %2, %3, %4\n")
  466. .arg(record.src2.x.ToFloat32())
  467. .arg(record.src2.y.ToFloat32())
  468. .arg(record.src2.z.ToFloat32())
  469. .arg(record.src2.w.ToFloat32());
  470. if (record.mask & Pica::Shader::DebugDataRecord::SRC3)
  471. text += tr("SRC3: %1, %2, %3, %4\n")
  472. .arg(record.src3.x.ToFloat32())
  473. .arg(record.src3.y.ToFloat32())
  474. .arg(record.src3.z.ToFloat32())
  475. .arg(record.src3.w.ToFloat32());
  476. if (record.mask & Pica::Shader::DebugDataRecord::DEST_IN)
  477. text += tr("DEST_IN: %1, %2, %3, %4\n")
  478. .arg(record.dest_in.x.ToFloat32())
  479. .arg(record.dest_in.y.ToFloat32())
  480. .arg(record.dest_in.z.ToFloat32())
  481. .arg(record.dest_in.w.ToFloat32());
  482. if (record.mask & Pica::Shader::DebugDataRecord::DEST_OUT)
  483. text += tr("DEST_OUT: %1, %2, %3, %4\n")
  484. .arg(record.dest_out.x.ToFloat32())
  485. .arg(record.dest_out.y.ToFloat32())
  486. .arg(record.dest_out.z.ToFloat32())
  487. .arg(record.dest_out.w.ToFloat32());
  488. if (record.mask & Pica::Shader::DebugDataRecord::ADDR_REG_OUT)
  489. text += tr("Addres Registers: %1, %2\n")
  490. .arg(record.address_registers[0])
  491. .arg(record.address_registers[1]);
  492. if (record.mask & Pica::Shader::DebugDataRecord::CMP_RESULT)
  493. text += tr("Compare Result: %1, %2\n")
  494. .arg(record.conditional_code[0] ? "true" : "false")
  495. .arg(record.conditional_code[1] ? "true" : "false");
  496. if (record.mask & Pica::Shader::DebugDataRecord::COND_BOOL_IN)
  497. text += tr("Static Condition: %1\n").arg(record.cond_bool ? "true" : "false");
  498. if (record.mask & Pica::Shader::DebugDataRecord::COND_CMP_IN)
  499. text += tr("Dynamic Conditions: %1, %2\n")
  500. .arg(record.cond_cmp[0] ? "true" : "false")
  501. .arg(record.cond_cmp[1] ? "true" : "false");
  502. if (record.mask & Pica::Shader::DebugDataRecord::LOOP_INT_IN)
  503. text += tr("Loop Parameters: %1 (repeats), %2 (initializer), %3 (increment), %4\n")
  504. .arg(record.loop_int.x)
  505. .arg(record.loop_int.y)
  506. .arg(record.loop_int.z)
  507. .arg(record.loop_int.w);
  508. text +=
  509. tr("Instruction offset: 0x%1").arg(4 * record.instruction_offset, 4, 16, QLatin1Char('0'));
  510. if (record.mask & Pica::Shader::DebugDataRecord::NEXT_INSTR) {
  511. text += tr(" -> 0x%2").arg(4 * record.next_instruction, 4, 16, QLatin1Char('0'));
  512. } else {
  513. text += tr(" (last instruction)");
  514. }
  515. instruction_description->setText(text);
  516. // Emit model update notification and scroll to current instruction
  517. QModelIndex instr_index = model->index(record.instruction_offset, 0);
  518. emit model->dataChanged(instr_index,
  519. model->index(record.instruction_offset, model->columnCount()));
  520. binary_list->scrollTo(instr_index, QAbstractItemView::EnsureVisible);
  521. }