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