Skip to content

Commit

Permalink
RD DXIL Disassembly : don't show "unknown" cbuffer member data
Browse files Browse the repository at this point in the history
Fallback to show the cbuffer load i.e.

_dx.types.CBufRet.i32 _50 = cbuffer1.Load(byte_offset = 80);
  • Loading branch information
Zorro666 committed May 28, 2024
1 parent 322722f commit 666c248
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions renderdoc/driver/shaders/dxbc/dxbc_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ struct CBuffer
} descriptor;

rdcarray<CBufferVariable> variables;
bool hasReflectionData;
};

struct Reflection
Expand Down
49 changes: 34 additions & 15 deletions renderdoc/driver/shaders/dxil/dxil_disassemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2836,8 +2836,6 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
{
for(size_t j = 0; j < entryPoint->cbuffers.size(); ++j)
{
if(needBlankLine)
DisassemblyAddNewLine();
EntryPointInterface::CBuffer &cbuffer = entryPoint->cbuffers[j];
if(reflection)
{
Expand All @@ -2852,6 +2850,8 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
}
}
}
if(needBlankLine)
DisassemblyAddNewLine();
m_Disassembly += "cbuffer " + cbuffer.name;
if(cbuffer.regCount > 1)
{
Expand All @@ -2862,7 +2862,8 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
}
m_Disassembly +=
" : register(b" + ToStr(cbuffer.regBase) + ", space" + ToStr(cbuffer.space) + ")";
if(cbuffer.cbufferRefl)
// Ignore cbuffer's which don't have reflection data
if(cbuffer.cbufferRefl && cbuffer.cbufferRefl->hasReflectionData)
{
if(!cbuffer.cbufferRefl->variables.empty())
{
Expand All @@ -2883,10 +2884,15 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
}
m_Disassembly += "};";
DisassemblyAddNewLine();
needBlankLine = true;
}
}
needBlankLine = true;
else
{
DisassemblyAddNewLine();
}
}
needBlankLine = true;
}

if(!entryPoint->samplers.empty())
Expand Down Expand Up @@ -3312,17 +3318,30 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
regIndex = regIndex / 16;
// uint32_t alignment = getival<uint32_t>(inst.args[3]);
}
const Type *retType = inst.type;
uint32_t bytesPerElement = 4;
if(retType)
const EntryPointInterface::CBuffer &cbuffer =
entryPoint->cbuffers[resRef->resourceIndex];
if(cbuffer.cbufferRefl && cbuffer.cbufferRefl->hasReflectionData)
{
const Type *retType = inst.type;
uint32_t bytesPerElement = 4;
if(retType)
{
RDCASSERT(retType->type == Type::TypeKind::Struct);
const Type *baseType = retType->members[0];
RDCASSERT(baseType->type == Type::TypeKind::Scalar);
bytesPerElement = baseType->bitWidth / 8;
}
lineStr += MakeCBufferRegisterStr(regIndex, bytesPerElement, cbuffer);
commentStr += " cbuffer = " + cbuffer.name;
commentStr += ", byte_offset = " + ToStr(regIndex * 16);
}
else
{
RDCASSERT(retType->type == Type::TypeKind::Struct);
const Type *baseType = retType->members[0];
RDCASSERT(baseType->type == Type::TypeKind::Scalar);
bytesPerElement = baseType->bitWidth / 8;
lineStr += cbuffer.name;
lineStr += ".Load4(";
lineStr += "byte_offset = " + ToStr(regIndex * 16);
lineStr += ")";
}
lineStr += MakeCBufferRegisterStr(regIndex, bytesPerElement,
entryPoint->cbuffers[resRef->resourceIndex]);
}
}
else
Expand Down Expand Up @@ -3886,7 +3905,7 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
}
switch(inst.op)
{
case Operation::Trunc: commentStr = "truncate ";
case Operation::Trunc: commentStr += "truncate ";
case Operation::ZExt: commentStr += "zero extend "; break;
case Operation::SExt: commentStr += "signed extend "; break;
case Operation::UToF: commentStr += "unsigned "; break;
Expand Down Expand Up @@ -4263,7 +4282,7 @@ void Program::MakeRDDisassemblyString(const DXBC::Reflection *reflection)
case Operation::SGreater:
case Operation::SGreaterEqual:
case Operation::SLess:
case Operation::SLessEqual: commentStr = "signed ";
case Operation::SLessEqual: commentStr += "signed ";
default: break;
}
lineStr += "(";
Expand Down
6 changes: 6 additions & 0 deletions renderdoc/driver/shaders/dxil/dxil_reflect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1627,9 +1627,13 @@ DXBC::Reflection *Program::GetReflection()

bind.descriptor.type = CBuffer::Descriptor::TYPE_CBUFFER;
bind.descriptor.byteSize = getival<uint32_t>(r->children[(size_t)ResField::CBufferByteSize]);
bind.hasReflectionData = true;

if(bind.name.empty())
{
bind.hasReflectionData = false;
bind.name = StringFormat::Fmt("cbuffer%u", bind.identifier);
}

const Type *cbufType = r->children[(size_t)ResField::VarDecl]->type;

Expand All @@ -1645,6 +1649,8 @@ DXBC::Reflection *Program::GetReflection()
}
else
{
bind.hasReflectionData = false;

CBufferVariable var;

var.name = "unknown";
Expand Down

0 comments on commit 666c248

Please sign in to comment.