Skip to content

Commit 9bef60d

Browse files
committed
Display source variables mapped to OpUndef as <undefined value>
* Undefined values are still 0xccccccccc, since that value can propagate through operations. But source variables mapped directly to an OpUndef are displayed in a more semantically clear way.
1 parent d32454e commit 9bef60d

File tree

4 files changed

+82
-25
lines changed

4 files changed

+82
-25
lines changed

qrenderdoc/Windows/ShaderViewer.cpp

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,8 @@ QString ShaderViewer::getRegNames(const RDTreeWidgetItem *item, uint32_t swizzle
34153415
}
34163416

34173417
const RDTreeWidgetItem *ShaderViewer::evaluateVar(const RDTreeWidgetItem *item, uint32_t swizzle,
3418-
ShaderVariable *var)
3418+
ShaderVariable *var,
3419+
SourceVariableMapping *mappingPtr)
34193420
{
34203421
VariableTag tag = item->tag().value<VariableTag>();
34213422

@@ -3528,13 +3529,16 @@ const RDTreeWidgetItem *ShaderViewer::evaluateVar(const RDTreeWidgetItem *item,
35283529
for(int i = 0; i < item->childCount(); i++)
35293530
{
35303531
ret.members.push_back(ShaderVariable());
3531-
if(!evaluateVar(item->child(i), ~0U, &ret.members.back()))
3532+
if(!evaluateVar(item->child(i), ~0U, &ret.members.back(), NULL))
35323533
return NULL;
35333534
}
35343535

35353536
return item;
35363537
}
35373538

3539+
if(mappingPtr)
3540+
*mappingPtr = mapping;
3541+
35383542
if(mapping.variables.empty())
35393543
return NULL;
35403544

@@ -3575,6 +3579,9 @@ const RDTreeWidgetItem *ShaderViewer::evaluateVar(const RDTreeWidgetItem *item,
35753579
}
35763580
}
35773581

3582+
if(mappingPtr)
3583+
*mappingPtr = mapping;
3584+
35783585
ShaderVariable &ret = *var;
35793586
ret.name = mapping.name;
35803587
ret.flags |= ShaderVariableFlags::RowMajorMatrix;
@@ -3649,14 +3656,15 @@ const RDTreeWidgetItem *ShaderViewer::evaluateVar(const RDTreeWidgetItem *item,
36493656
}
36503657

36513658
const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, const RDTreeWidgetItem *root,
3652-
ShaderVariable *var, uint32_t *swizzlePtr)
3659+
ShaderVariable *var, uint32_t *swizzlePtr,
3660+
SourceVariableMapping *mappingPtr)
36533661
{
36543662
VariableTag tag = root->tag().value<VariableTag>();
36553663

36563664
// if the path is an exact match, return the evaluation directly
36573665
if(tag.absoluteRefPath == path)
36583666
{
3659-
return evaluateVar(root, ~0U, var);
3667+
return evaluateVar(root, ~0U, var, mappingPtr);
36603668
}
36613669

36623670
for(int i = 0; i < root->childCount(); i++)
@@ -3672,7 +3680,7 @@ const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, const R
36723680
// if the path is an exact match, return the evaluation directly
36733681
if(tag.absoluteRefPath == path)
36743682
{
3675-
return evaluateVar(child, ~0U, var);
3683+
return evaluateVar(child, ~0U, var, mappingPtr);
36763684
}
36773685

36783686
// after the common prefix, if the next value is . or [ then this is the next child, so recurse.
@@ -3684,7 +3692,7 @@ const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, const R
36843692
if(common == tag.absoluteRefPath &&
36853693
(path[tag.absoluteRefPath.size()] == '.' || path[tag.absoluteRefPath.size()] == '['))
36863694
{
3687-
return getVarFromPath(path, child, var, swizzlePtr);
3695+
return getVarFromPath(path, child, var, swizzlePtr, mappingPtr);
36883696
}
36893697
}
36903698

@@ -3726,15 +3734,16 @@ const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, const R
37263734
if(swizzlePtr)
37273735
*swizzlePtr = swizzleMask;
37283736

3729-
return evaluateVar(root, swizzleMask, var);
3737+
return evaluateVar(root, swizzleMask, var, mappingPtr);
37303738
}
37313739
}
37323740

37333741
return NULL;
37343742
}
37353743

37363744
const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, ShaderVariable *var,
3737-
uint32_t *swizzle)
3745+
uint32_t *swizzle,
3746+
SourceVariableMapping *mapping)
37383747
{
37393748
if(!m_Trace || m_States.empty())
37403749
return NULL;
@@ -3765,7 +3774,7 @@ const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, ShaderV
37653774

37663775
if(item->text(0) == root)
37673776
{
3768-
const RDTreeWidgetItem *ret = getVarFromPath(path, item, var, swizzle);
3777+
const RDTreeWidgetItem *ret = getVarFromPath(path, item, var, swizzle, mapping);
37693778
if(ret)
37703779
return ret;
37713780
}
@@ -3781,7 +3790,7 @@ const RDTreeWidgetItem *ShaderViewer::getVarFromPath(const rdcstr &path, ShaderV
37813790
VariableTag tag = item->tag().value<VariableTag>();
37823791

37833792
const RDTreeWidgetItem *ret =
3784-
getVarFromPath(tag.absoluteRefPath + "." + path, child, var, swizzle);
3793+
getVarFromPath(tag.absoluteRefPath + "." + path, child, var, swizzle, mapping);
37853794
if(ret)
37863795
return ret;
37873796
}
@@ -4515,6 +4524,7 @@ void ShaderViewer::markWatchStale(RDTreeWidgetItem *item)
45154524

45164525
bool ShaderViewer::updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTreeWidgetItem *varItem,
45174526
const rdcstr &path, uint32_t swizzle,
4527+
const SourceVariableMapping &mapping,
45184528
const ShaderVariable &var, QChar regcast)
45194529
{
45204530
if(!var.members.empty())
@@ -4577,7 +4587,7 @@ bool ShaderViewer::updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTree
45774587
rdcstr sep = var.members[i].name[0] == '[' ? "" : ".";
45784588

45794589
updateWatchVariable(watchItem->child(idx), varItem->child(i),
4580-
path + sep + var.members[i].name, ~0U, var.members[i], regcast);
4590+
path + sep + var.members[i].name, ~0U, mapping, var.members[i], regcast);
45814591
}
45824592

45834593
// any children that weren't marked as valid are now stale
@@ -4644,7 +4654,8 @@ bool ShaderViewer::updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTree
46444654
QVariant(),
46454655
});
46464656

4647-
updateWatchVariable(item, varItem->child(r), path + ".row" + ToStr(r), ~0U, rowVar, regcast);
4657+
updateWatchVariable(item, varItem->child(r), path + ".row" + ToStr(r), ~0U, mapping, rowVar,
4658+
regcast);
46484659
item->setText(1, getRegNames(varItem, ~0U, r));
46494660
item->setTag(QVariant());
46504661
watchItem->addChild(item);
@@ -4787,8 +4798,16 @@ bool ShaderViewer::updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTree
47874798
val += lit(", ");
47884799
}
47894800

4801+
QString typeString = TypeString(var);
4802+
4803+
if(mapping.type != VarType::Unknown && mapping.undefinedValue)
4804+
{
4805+
typeString = lit("-");
4806+
val = tr("<undefined value>");
4807+
}
4808+
47904809
watchItem->setText(1, getRegNames(varItem, swizzle));
4791-
watchItem->setText(2, TypeString(var));
4810+
watchItem->setText(2, typeString);
47924811

47934812
if(!swatchColor.isValid())
47944813
{
@@ -4844,12 +4863,13 @@ void ShaderViewer::updateWatchVariables()
48444863
if(!match.captured(2).isEmpty())
48454864
regcast = match.captured(2)[1];
48464865

4866+
SourceVariableMapping mapping;
48474867
ShaderVariable var;
48484868
uint32_t swizzle = ~0U;
4849-
const RDTreeWidgetItem *varItem = getVarFromPath(path, &var, &swizzle);
4869+
const RDTreeWidgetItem *varItem = getVarFromPath(path, &var, &swizzle, &mapping);
48504870
if(varItem)
48514871
{
4852-
if(updateWatchVariable(item, varItem, path, swizzle, var, regcast))
4872+
if(updateWatchVariable(item, varItem, path, swizzle, mapping, var, regcast))
48534873
continue;
48544874

48554875
error = tr("Couldn't evaluate watch for '%1'").arg(expr);
@@ -5181,6 +5201,12 @@ RDTreeWidgetItem *ShaderViewer::makeSourceVariableNode(const SourceVariableMappi
51815201
}
51825202
}
51835203

5204+
if(l.undefinedValue)
5205+
{
5206+
typeName = lit("-");
5207+
value = tr("<undefined value>");
5208+
}
5209+
51845210
RDTreeWidgetItem *node = new RDTreeWidgetItem({localName, QString(), typeName, value});
51855211

51865212
for(RDTreeWidgetItem *c : children)
@@ -6099,8 +6125,9 @@ void ShaderViewer::updateVariableTooltip()
60996125
return;
61006126

61016127
ShaderVariable var;
6128+
SourceVariableMapping mapping;
61026129

6103-
if(!getVarFromPath(m_TooltipVarPath, &var))
6130+
if(!getVarFromPath(m_TooltipVarPath, &var, NULL, &mapping))
61046131
return;
61056132

61066133
if(var.type != VarType::Unknown)
@@ -6125,6 +6152,9 @@ void ShaderViewer::updateVariableTooltip()
61256152
tooltip += lit("</pre>");
61266153
}
61276154

6155+
if(mapping.type != VarType::Unknown && mapping.undefinedValue)
6156+
tooltip = tr("%1: <undefined value>").arg(var.name);
6157+
61286158
QToolTip::showText(m_TooltipPos, tooltip);
61296159
return;
61306160
}
@@ -6141,8 +6171,13 @@ void ShaderViewer::updateVariableTooltip()
61416171
}
61426172
else if(!var.members.empty())
61436173
{
6174+
QString tooltip = tr("%1: { ... }").arg(var.name);
6175+
6176+
if(mapping.type != VarType::Unknown && mapping.undefinedValue)
6177+
tooltip = tr("%1: <undefined value>").arg(var.name);
6178+
61446179
// other structs
6145-
QToolTip::showText(m_TooltipPos, lit("{ ... }"));
6180+
QToolTip::showText(m_TooltipPos, tooltip);
61466181
return;
61476182
}
61486183

qrenderdoc/Windows/ShaderViewer.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ private slots:
402402
void updateDebugState();
403403
void markWatchStale(RDTreeWidgetItem *item);
404404
bool updateWatchVariable(RDTreeWidgetItem *watchItem, const RDTreeWidgetItem *varItem,
405-
const rdcstr &path, uint32_t swizzle, const ShaderVariable &var,
406-
QChar regcast);
405+
const rdcstr &path, uint32_t swizzle, const SourceVariableMapping &mapping,
406+
const ShaderVariable &var, QChar regcast);
407407
void updateWatchVariables();
408408

409409
void updateAccessedResources();
@@ -452,9 +452,11 @@ private slots:
452452

453453
QString getRegNames(const RDTreeWidgetItem *item, uint32_t swizzle, uint32_t child = ~0U);
454454
const RDTreeWidgetItem *evaluateVar(const RDTreeWidgetItem *item, uint32_t swizzle,
455-
ShaderVariable *var);
455+
ShaderVariable *var, SourceVariableMapping *mapping);
456456
const RDTreeWidgetItem *getVarFromPath(const rdcstr &path, const RDTreeWidgetItem *root,
457-
ShaderVariable *var, uint32_t *swizzle);
457+
ShaderVariable *var, uint32_t *swizzle,
458+
SourceVariableMapping *mapping);
458459
const RDTreeWidgetItem *getVarFromPath(const rdcstr &path, ShaderVariable *var = NULL,
459-
uint32_t *swizzle = NULL);
460+
uint32_t *swizzle = NULL,
461+
SourceVariableMapping *mapping = NULL);
460462
};

renderdoc/api/replay/shader_types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,13 @@ struct SourceVariableMapping
676676
)");
677677
VarType type = VarType::Unknown;
678678

679+
DOCUMENT(R"(A flag indicating if this mapping indicates an undefined value - the meaning of which
680+
is compiler defined but may mean either uninitialised data, unassigned values, or optimised away values.
681+
682+
:type: bool
683+
)");
684+
bool undefinedValue = false;
685+
679686
DOCUMENT(R"(The number of rows in this variable - 1 for vectors, >1 for matrices.
680687
681688
:type: int

renderdoc/driver/shaders/spirv/spirv_debug_setup.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2626,11 +2626,24 @@ void Debugger::FillDebugSourceVars(rdcarray<InstructionSourceInfo> &instInfo) co
26262626

26272627
if(n->children.empty())
26282628
{
2629-
RDCASSERTNOTEQUAL(n->rows * n->columns, 0);
2630-
for(uint32_t c = 0; c < n->rows * n->columns; ++c)
2629+
ConstIter it = GetID(n->debugVar);
2630+
2631+
if(it.opcode() == Op::Undef)
26312632
{
2633+
sourceVar.rows = sourceVar.columns = 1;
2634+
sourceVar.undefinedValue = true;
2635+
26322636
sourceVar.variables.push_back(DebugVariableReference(
2633-
DebugVariableType::Variable, GetRawName(n->debugVar) + n->debugVarSuffix, c));
2637+
DebugVariableType::Variable, GetRawName(n->debugVar) + n->debugVarSuffix, 0));
2638+
}
2639+
else
2640+
{
2641+
RDCASSERTNOTEQUAL(n->rows * n->columns, 0);
2642+
for(uint32_t c = 0; c < n->rows * n->columns; ++c)
2643+
{
2644+
sourceVar.variables.push_back(DebugVariableReference(
2645+
DebugVariableType::Variable, GetRawName(n->debugVar) + n->debugVarSuffix, c));
2646+
}
26342647
}
26352648
}
26362649
else

0 commit comments

Comments
 (0)