diff --git a/renderdoc/driver/d3d11/shaders/dxbc_debug.cpp b/renderdoc/driver/d3d11/shaders/dxbc_debug.cpp index e391468de..f8cf40b85 100644 --- a/renderdoc/driver/d3d11/shaders/dxbc_debug.cpp +++ b/renderdoc/driver/d3d11/shaders/dxbc_debug.cpp @@ -506,6 +506,8 @@ ShaderVariable sub(const ShaderVariable &a, const ShaderVariable &b, const VarTy void State::Init() { + vector indexTempSizes; + for(size_t i=0; i < dxbc->m_Declarations.size(); i++) { if(dxbc->m_Declarations[i].declaration == OPCODE_DCL_TEMPS) @@ -523,17 +525,32 @@ void State::Init() } if(dxbc->m_Declarations[i].declaration == OPCODE_DCL_INDEXABLE_TEMP) { - if(indexableTemps.size() <= dxbc->m_Declarations[i].tempReg) - indexableTemps.resize(dxbc->m_Declarations[i].tempReg+1); + uint32_t reg = dxbc->m_Declarations[i].tempReg; + uint32_t size = dxbc->m_Declarations[i].numTemps; + if(reg >= indexTempSizes.size()) + indexTempSizes.resize(reg+1); - indexableTemps[dxbc->m_Declarations[i].tempReg].resize(dxbc->m_Declarations[i].numTemps); - for(uint32_t t=0; t < dxbc->m_Declarations[i].numTemps; t++) + indexTempSizes[reg] = size; + } + } + + if(indexTempSizes.size()) + { + create_array_uninit(indexableTemps, indexTempSizes.size()); + + for(int32_t i=0; i < (int32_t)indexTempSizes.size(); i++) + { + if(indexTempSizes[i] > 0) { - char buf[64] = {0}; + create_array_uninit(indexableTemps[i], indexTempSizes[i]); + for(uint32_t t=0; t < indexTempSizes[i]; t++) + { + char buf[64] = {0}; - StringFormat::snprintf(buf, 63, "x%u[%u]", dxbc->m_Declarations[i].tempReg, t); + StringFormat::snprintf(buf, 63, "x%u[%u]", i, t); - indexableTemps[dxbc->m_Declarations[i].tempReg][t] = ShaderVariable(buf, 0l, 0l, 0l, 0l); + indexableTemps[i][t] = ShaderVariable(buf, 0l, 0l, 0l, 0l); + } } } } @@ -582,11 +599,11 @@ void State::SetDst(const ASMOperand &dstoper, const ASMOperation &op, const Shad if(dstoper.indices.size() == 2) { - RDCASSERT(indices[0] < (uint32_t)indexableTemps.size()); - if(indices[0] < (uint32_t)indexableTemps.size()) + RDCASSERT(indices[0] < (uint32_t)indexableTemps.count); + if(indices[0] < (uint32_t)indexableTemps.count) { - RDCASSERT(indices[1] < (uint32_t)indexableTemps[ indices[0] ].size()); - if(indices[1] < (uint32_t)indexableTemps[ indices[0] ].size()) + RDCASSERT(indices[1] < (uint32_t)indexableTemps[ indices[0] ].count); + if(indices[1] < (uint32_t)indexableTemps[ indices[0] ].count) { v = &indexableTemps[ indices[0] ][ indices[1] ]; } @@ -761,14 +778,14 @@ ShaderVariable State::GetSrc(const ASMOperand &oper, const ASMOperation &op) con case TYPE_INDEXABLE_TEMP: { RDCASSERT(oper.indices.size() == 2); - + if(oper.indices.size() == 2) { - RDCASSERT(indices[0] < (uint32_t)indexableTemps.size()); - if(indices[0] < (uint32_t)indexableTemps.size()) + RDCASSERT(indices[0] < (uint32_t)indexableTemps.count); + if(indices[0] < (uint32_t)indexableTemps.count) { - RDCASSERT(indices[1] < (uint32_t)indexableTemps[ indices[0] ].size()); - if(indices[1] < (uint32_t)indexableTemps[ indices[0] ].size()) + RDCASSERT(indices[1] < (uint32_t)indexableTemps[ indices[0] ].count); + if(indices[1] < (uint32_t)indexableTemps[ indices[0] ].count) { v = s = indexableTemps[ indices[0] ][ indices[1] ]; } diff --git a/renderdoc/driver/d3d11/shaders/dxbc_debug.h b/renderdoc/driver/d3d11/shaders/dxbc_debug.h index 11c1bf93d..c604c18c5 100644 --- a/renderdoc/driver/d3d11/shaders/dxbc_debug.h +++ b/renderdoc/driver/d3d11/shaders/dxbc_debug.h @@ -141,8 +141,6 @@ class State : public ShaderDebugState VarType OperationType(const DXBC::OpcodeType &op) const; - vector< vector > indexableTemps; - DXBC::DXBCFile *dxbc; const ShaderDebugTrace *trace; WrappedID3D11Device *device; diff --git a/renderdoc/replay/shader_types.h b/renderdoc/replay/shader_types.h index 2eafe706f..797938af6 100644 --- a/renderdoc/replay/shader_types.h +++ b/renderdoc/replay/shader_types.h @@ -92,6 +92,8 @@ struct ShaderDebugState { rdctype::array registers; rdctype::array outputs; + + rdctype::array< rdctype::array > indexableTemps; uint32_t nextInstruction; }; diff --git a/renderdocui/Interop/Shader.cs b/renderdocui/Interop/Shader.cs index dd8698fb3..ac04550a6 100644 --- a/renderdocui/Interop/Shader.cs +++ b/renderdocui/Interop/Shader.cs @@ -177,6 +177,15 @@ namespace renderdoc [CustomMarshalAs(CustomUnmanagedType.TemplatedArray)] public ShaderVariable[] outputs; + [StructLayout(LayoutKind.Sequential)] + public struct IndexableTempArray + { + [CustomMarshalAs(CustomUnmanagedType.TemplatedArray)] + public ShaderVariable[] temps; + }; + [CustomMarshalAs(CustomUnmanagedType.TemplatedArray)] + public IndexableTempArray[] indexableTemps; + public UInt32 nextInstruction; }; diff --git a/renderdocui/Windows/ShaderViewer.cs b/renderdocui/Windows/ShaderViewer.cs index ad92d0c62..0f16f3c11 100644 --- a/renderdocui/Windows/ShaderViewer.cs +++ b/renderdocui/Windows/ShaderViewer.cs @@ -785,6 +785,13 @@ namespace renderdocui.Windows for (int i = 0; i < state.registers.Length; i++) variableRegs.Nodes.Add("a"); + for (int i = 0; i < state.indexableTemps.Length; i++) + { + var node = variableRegs.Nodes.Add(new object[] { String.Format("x{0}", i), "indexable array", "" }); + for (int t = 0; t < state.indexableTemps[i].temps.Length; t++) + node.Nodes.Add("a"); + } + for (int i = 0; i < state.outputs.Length; i++) variableRegs.Nodes.Add("a"); } @@ -798,6 +805,16 @@ namespace renderdocui.Windows variableRegs.Nodes[v++].SetData(new object[] { state.registers[i].name, "register", StringRep(state.registers[i], false) }); } + for (int i = 0; i < state.indexableTemps.Length; i++) + { + var node = variableRegs.Nodes[v++]; + + for (int t = 0; t < state.indexableTemps[i].temps.Length; t++) + { + node.Nodes[t].SetData(new object[] { state.indexableTemps[i].temps[t].name, "register", StringRep(state.indexableTemps[i].temps[t], false) }); + } + } + for (int i = 0; i < state.outputs.Length; i++) { variableRegs.Nodes[v++].SetData(new object[] { state.outputs[i].name, "register", StringRep(state.outputs[i], false) }); @@ -818,6 +835,14 @@ namespace renderdocui.Windows var match = Regex.Match(reg, regexp); + // try indexable temps + if (!match.Success) + { + regexp = "^(x[0-9]+)\\[([0-9]+)\\](\\.[xyzwrgba]+)?(,[xfiudb])?$"; + + match = Regex.Match(reg, regexp); + } + if (match.Success) { var regtype = match.Groups[1].Value; @@ -836,15 +861,34 @@ namespace renderdocui.Windows ShaderVariable[] vars = null; if (regtype == "r") + { vars = state.registers; + } else if (regtype == "v") + { vars = m_Trace.inputs; + } else if (regtype == "o") + { vars = state.outputs; + } + else if (regtype[0] == 'x') + { + string tempArrayIndexStr = regtype.Substring(1); + int tempArrayIndex = -1; + + if (int.TryParse(tempArrayIndexStr, out tempArrayIndex)) + { + if (tempArrayIndex >= 0 && tempArrayIndex < state.indexableTemps.Length) + { + vars = state.indexableTemps[tempArrayIndex].temps; + } + } + } int regindex = -1; - if (int.TryParse(regidx, out regindex)) + if (vars != null && int.TryParse(regidx, out regindex)) { if (regindex >= 0 && regindex < vars.Length) {