From 35884170eb7e44edd8a7d260aad9cbec685d912c Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 10 Sep 2014 18:25:29 +0100 Subject: [PATCH] In D3D11 support setting friendly names on shaders --- renderdoc/driver/d3d11/d3d11_replay.cpp | 13 ++++++++ renderdoc/replay/d3d11_pipestate.h | 2 ++ renderdocui/Code/CommonPipelineState.cs | 33 +++++++++++++++++++ renderdocui/Interop/D3D11PipelineState.cs | 3 ++ .../PipelineState/D3D11PipelineStateViewer.cs | 2 +- renderdocui/Windows/ShaderViewer.cs | 4 +-- 6 files changed, 54 insertions(+), 3 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_replay.cpp b/renderdoc/driver/d3d11/d3d11_replay.cpp index ddcfbc581..cf2ef15a2 100644 --- a/renderdoc/driver/d3d11/d3d11_replay.cpp +++ b/renderdoc/driver/d3d11/d3d11_replay.cpp @@ -474,6 +474,8 @@ D3D11PipelineState D3D11Replay::MakePipelineState() D3D11PipelineState::ShaderStage *dstArr = &ret.m_VS; const D3D11RenderState::shader *srcArr = &rs->VS; + const char *stageNames[] = { "Vertex", "Hull", "Domain", "Geometry", "Pixel", "Compute" }; + for(size_t i=0; i < 6; i++) { D3D11PipelineState::ShaderStage &dst = dstArr[i]; @@ -486,6 +488,17 @@ D3D11PipelineState D3D11Replay::MakePipelineState() dst.Shader = rm->GetOriginalID(id); dst.ShaderDetails = NULL; + string str = GetDebugName(src.Shader); + dst.customName = true; + + if(str == "" && dst.Shader != ResourceId()) + { + dst.customName = false; + str = StringFormat::Fmt("%hs Shader %llu", stageNames[i], dst.Shader); + } + + dst.ShaderName = widen(str); + // create identity bindpoint mapping create_array_uninit(dst.BindpointMapping.ConstantBlocks, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT); for(int s=0; s < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; s++) diff --git a/renderdoc/replay/d3d11_pipestate.h b/renderdoc/replay/d3d11_pipestate.h index 6fbc56bc0..c6d7725b5 100644 --- a/renderdoc/replay/d3d11_pipestate.h +++ b/renderdoc/replay/d3d11_pipestate.h @@ -71,6 +71,8 @@ struct D3D11PipelineState { ShaderStage() : Shader(), ShaderDetails(NULL) {} ResourceId Shader; + rdctype::wstr ShaderName; + bool32 customName; ShaderReflection *ShaderDetails; ShaderBindpointMapping BindpointMapping; diff --git a/renderdocui/Code/CommonPipelineState.cs b/renderdocui/Code/CommonPipelineState.cs index 1f2df71f5..0330da77e 100644 --- a/renderdocui/Code/CommonPipelineState.cs +++ b/renderdocui/Code/CommonPipelineState.cs @@ -208,6 +208,39 @@ namespace renderdocui.Code return ResourceId.Null; } + public string GetShaderName(ShaderStageType stage) + { + if (LogLoaded) + { + if (IsLogD3D11) + { + switch (stage) + { + case ShaderStageType.Vertex: return m_D3D11.m_VS.ShaderName; + case ShaderStageType.Domain: return m_D3D11.m_DS.ShaderName; + case ShaderStageType.Hull: return m_D3D11.m_HS.ShaderName; + case ShaderStageType.Geometry: return m_D3D11.m_GS.ShaderName; + case ShaderStageType.Pixel: return m_D3D11.m_PS.ShaderName; + case ShaderStageType.Compute: return m_D3D11.m_CS.ShaderName; + } + } + else if (IsLogGL) + { + switch (stage) + { + case ShaderStageType.Vertex: return String.Format("Shader {0}", m_GL.m_VS.Shader); + case ShaderStageType.Tess_Control: return String.Format("Shader {0}", m_GL.m_TCS.Shader); + case ShaderStageType.Tess_Eval: return String.Format("Shader {0}", m_GL.m_TES.Shader); + case ShaderStageType.Geometry: return String.Format("Shader {0}", m_GL.m_GS.Shader); + case ShaderStageType.Fragment: return String.Format("Shader {0}", m_GL.m_FS.Shader); + case ShaderStageType.Compute: return String.Format("Shader {0}", m_GL.m_CS.Shader); + } + } + } + + return ""; + } + public void GetIBuffer(out ResourceId buf, out uint ByteOffset, out ResourceFormat IndexFormat) { if (LogLoaded) diff --git a/renderdocui/Interop/D3D11PipelineState.cs b/renderdocui/Interop/D3D11PipelineState.cs index 619d390ca..d28171912 100644 --- a/renderdocui/Interop/D3D11PipelineState.cs +++ b/renderdocui/Interop/D3D11PipelineState.cs @@ -103,6 +103,9 @@ namespace renderdoc } public ResourceId Shader; + [CustomMarshalAs(CustomUnmanagedType.WideTemplatedString)] + public string ShaderName; + public bool customName; private IntPtr _ptr_ShaderDetails; [CustomMarshalAs(CustomUnmanagedType.Skip)] public ShaderReflection ShaderDetails; diff --git a/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs b/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs index 95255527f..f0ebd5a68 100644 --- a/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs +++ b/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs @@ -192,7 +192,7 @@ namespace renderdocui.Windows.PipelineState if (stage.Shader == ResourceId.Null) shader.Text = "Unbound"; else - shader.Text = "Shader " + stage.Shader.ToString(); + shader.Text = stage.ShaderName; if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc != "" && shaderDetails.DebugInfo.files.Length > 0) shader.Text = shaderDetails.DebugInfo.entryFunc + "()" + " - " + diff --git a/renderdocui/Windows/ShaderViewer.cs b/renderdocui/Windows/ShaderViewer.cs index ded5f0b0e..77e44aac3 100644 --- a/renderdocui/Windows/ShaderViewer.cs +++ b/renderdocui/Windows/ShaderViewer.cs @@ -308,9 +308,9 @@ namespace renderdocui.Windows } if (trace != null) - Text = String.Format("Debug Shader {0} - {1}", m_Core.CurPipelineState.GetShader(stage), debugContext); + Text = String.Format("Debugging {0} - {1}", m_Core.CurPipelineState.GetShaderName(stage), debugContext); else - Text = String.Format("Shader {0}", m_Core.CurPipelineState.GetShader(stage)); + Text = m_Core.CurPipelineState.GetShaderName(stage); var disasm = shader.Disassembly;