Implement private variable storage

This commit is contained in:
baldurk
2020-04-16 18:41:58 +01:00
parent 2556614eb5
commit 60258bd57b
2 changed files with 44 additions and 2 deletions
@@ -177,6 +177,9 @@ struct ThreadState
// thread-local inputs/outputs. This array does not change over the course of debugging
rdcarray<ShaderVariable> inputs, outputs;
// thread-local private variables
rdcarray<ShaderVariable> privates;
// every ID's variable, if a pointer it may be pointing at a ShaderVariable stored elsewhere
DenseIdMap<ShaderVariable> ids;
@@ -412,7 +412,7 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
MakeSignatureNames(patchData.inputs, inputSigNames);
MakeSignatureNames(patchData.outputs, outputSigNames);
rdcarray<Id> inputIDs, outputIDs, cbufferIDs, readOnlyIDs, readWriteIDs, samplerIDs;
rdcarray<Id> inputIDs, outputIDs, cbufferIDs, readOnlyIDs, readWriteIDs, samplerIDs, privateIDs;
// allocate storage for globals with opaque storage classes, and prepare to set up pointers to
// them for the global variables themselves
@@ -622,6 +622,26 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
globalSourceVars.push_back(sourceVar);
}
else if(v.storage == StorageClass::Private)
{
// private variables are allocated as globals the same as outputs
ShaderVariable var;
var.name = GetRawName(v.id);
rdcstr sourceName = GetHumanName(v.id);
const DataType &type = dataTypes[v.type];
// global variables should all be pointers into opaque storage
RDCASSERT(type.type == DataType::PointerType);
// fill the interface variable
AllocateVariable(decorations[v.id], decorations[v.id], DebugVariableType::Variable,
sourceName, decorations[v.id].location, dataTypes[type.InnerType()], var);
active.privates.push_back(var);
privateIDs.push_back(v.id);
}
else
{
RDCERR("Unhandled type of global variable: %s", ToStr(v.storage).c_str());
@@ -629,6 +649,7 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
}
std::sort(outputIDs.begin(), outputIDs.end());
std::sort(privateIDs.begin(), privateIDs.end());
for(uint32_t i = 0; i < workgroupSize; i++)
{
@@ -638,6 +659,7 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
lane.nextInstruction = active.nextInstruction;
lane.inputs = active.inputs;
lane.outputs = active.outputs;
lane.privates = active.privates;
lane.ids = active.ids;
// mark as inactive/helper lane
lane.helperInvocation = true;
@@ -656,10 +678,13 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
lane.ids[readWriteIDs[i]] = MakePointerVariable(readWriteIDs[i], &global.readWriteResources[i]);
for(size_t i = 0; i < global.samplers.size(); i++)
lane.ids[samplerIDs[i]] = MakePointerVariable(samplerIDs[i], &global.samplers[i]);
for(size_t i = 0; i < lane.privates.size(); i++)
lane.ids[privateIDs[i]] = MakePointerVariable(privateIDs[i], &lane.privates[i]);
}
// only outputs are considered mutable
// only outputs and privates are considered mutable
liveGlobals.append(outputIDs);
liveGlobals.append(privateIDs);
for(size_t i = 0; i < globalSourceVars.size();)
{
@@ -691,6 +716,20 @@ ShaderDebugTrace *Debugger::BeginDebug(DebugAPIWrapper *apiWrapper, const Shader
}
}
for(size_t o = 0; o < privateIDs.size(); o++)
{
rdcstr varName = GetRawName(privateIDs[o]);
for(size_t i = 0; i < globalSourceVars.size(); i++)
{
if(!globalSourceVars[i].variables.empty() && globalSourceVars[i].variables[0].name == varName)
{
ret->sourceVars.push_back(globalSourceVars[i]);
break;
}
}
}
ret->lineInfo.resize(instructionOffsets.size());
for(size_t i = 0; i < instructionOffsets.size(); i++)
{