Don't use StringFormat for SPIR-V GetRawName

This commit is contained in:
baldurk
2022-07-22 16:10:59 +01:00
parent fda5c4819a
commit a967805a24
3 changed files with 74 additions and 29 deletions
@@ -211,7 +211,7 @@ void ThreadState::EnterFunction(const rdcarray<Id> &arguments)
OpVariable decl(it);
ShaderVariable &stackvar = frame->locals[i];
stackvar.name = debugger.GetRawName(decl.result);
stackvar.name = GetRawName(decl.result);
rdcstr sourceName = debugger.GetHumanName(decl.result);
@@ -342,7 +342,7 @@ void ThreadState::SetDst(Id id, const ShaderVariable &val)
m_State->flags |= ShaderEvents::GeneratedNanOrInf;
ids[id] = val;
ids[id].name = debugger.GetRawName(id);
ids[id].name = GetRawName(id);
lastWrite[id] = m_State ? m_State->stepIndex : nextInstruction;
@@ -545,7 +545,7 @@ bool ThreadState::ReferencePointer(Id id)
{
StackFrame *frame = callstack.back();
rdcstr name = debugger.GetRawName(id);
rdcstr name = GetRawName(id);
// see if this is a local variable which is newly referenced, if so add source vars for it
for(size_t i = 0; i < frame->locals.size(); i++)
+3 -3
View File
@@ -329,6 +329,9 @@ struct LocalMapping
rdcarray<uint32_t> indexes;
};
Id ParseRawName(const rdcstr &name);
rdcstr GetRawName(Id id);
class Debugger : public Processor, public ShaderDebugger
{
public:
@@ -354,7 +357,6 @@ public:
bool IsDebugExtInstSet(Id id) const;
bool HasDebugInfo() const { return m_DebugInfo.valid; }
bool InDebugScope(uint32_t inst) const;
rdcstr GetRawName(Id id) const;
rdcstr GetHumanName(Id id);
void AddSourceVars(rdcarray<SourceVariableMapping> &sourceVars, const ShaderVariable &var, Id id);
void AllocateVariable(Id id, Id typeId, ShaderVariable &outVar);
@@ -393,8 +395,6 @@ private:
uint64_t, const rdcstr &)>
callback) const;
static Id ParseRawName(const rdcstr &name);
void MakeSignatureNames(const rdcarray<SPIRVInterfaceAccess> &sigList, rdcarray<rdcstr> &sigNames);
/////////////////////////////////////////////////////////
@@ -114,6 +114,42 @@ static const void *VarElemPointer(const ShaderVariable &var, uint32_t comp)
namespace rdcspv
{
rdcstr GetRawName(Id id)
{
// 32-bit value means at most 10 decimal digits, plus a preceeding _, plus trailing NULL.
char name[12] = {};
char *ptr = name + 10;
uint32_t val = id.value();
do
{
*ptr = char('0' + (val % 10));
ptr--;
val /= 10;
} while(val);
*ptr = '_';
return ptr;
}
Id ParseRawName(const rdcstr &name)
{
if(name[0] != '_')
return Id();
uint32_t val = 0;
for(int i = 1; i < name.count(); i++)
{
if(name[i] < '0' || name[i] > '9')
return Id();
val *= 10;
val += uint32_t(name[i] - '0');
}
return Id::fromWord(val);
}
void AssignValue(ShaderVariable &dst, const ShaderVariable &src)
{
dst.value = src.value;
@@ -2270,29 +2306,6 @@ void Debugger::WriteThroughPointer(const ShaderVariable &ptr, const ShaderVariab
}
}
rdcstr Debugger::GetRawName(Id id) const
{
return StringFormat::Fmt("_%u", id.value());
}
Id Debugger::ParseRawName(const rdcstr &name)
{
if(name[0] != '_')
return Id();
uint32_t val = 0;
for(int i = 1; i < name.count(); i++)
{
if(name[i] < '0' || name[i] > '9')
return Id();
val *= 10;
val += uint32_t(name[i] - '0');
}
return Id::fromWord(val);
}
rdcstr Debugger::GetHumanName(Id id)
{
// see if we have a dynamic name assigned (to disambiguate), if so use that
@@ -3353,3 +3366,35 @@ void Debugger::RegisterOp(Iter it)
}
}; // namespace rdcspv
#if ENABLED(ENABLE_UNIT_TESTS)
#include "catch/catch.hpp"
TEST_CASE("Check SPIRV Id naming", "[tostr]")
{
SECTION("Test GetRawName")
{
CHECK(rdcspv::GetRawName(rdcspv::Id::fromWord(1234)) == "_1234");
CHECK(rdcspv::GetRawName(rdcspv::Id::fromWord(12345)) == "_12345");
CHECK(rdcspv::GetRawName(rdcspv::Id::fromWord(999)) == "_999");
CHECK(rdcspv::GetRawName(rdcspv::Id::fromWord(0xffffffff)) == "_4294967295");
CHECK(rdcspv::GetRawName(rdcspv::Id()) == "_0");
};
SECTION("Test ParseRawName")
{
CHECK(rdcspv::ParseRawName("_1234") == rdcspv::Id::fromWord(1234));
CHECK(rdcspv::ParseRawName("_12345") == rdcspv::Id::fromWord(12345));
CHECK(rdcspv::ParseRawName("_999") == rdcspv::Id::fromWord(999));
CHECK(rdcspv::ParseRawName("_4294967295") == rdcspv::Id::fromWord(0xffffffff));
CHECK(rdcspv::ParseRawName("_0") == rdcspv::Id());
CHECK(rdcspv::ParseRawName("1234") == rdcspv::Id());
CHECK(rdcspv::ParseRawName("999") == rdcspv::Id());
CHECK(rdcspv::ParseRawName("1") == rdcspv::Id());
CHECK(rdcspv::ParseRawName("-1234") == rdcspv::Id());
CHECK(rdcspv::ParseRawName("asdf") == rdcspv::Id());
};
}
#endif