diff --git a/renderdoc/api/replay/shader_types.h b/renderdoc/api/replay/shader_types.h index f8acb3aa9..90fd74259 100644 --- a/renderdoc/api/replay/shader_types.h +++ b/renderdoc/api/replay/shader_types.h @@ -192,13 +192,15 @@ struct ShaderResource struct ShaderDebugChunk { - ShaderDebugChunk() : compileFlags(0) {} + ShaderDebugChunk() : compileFlags(0), entryFile(0) {} rdctype::str entryFunc; uint32_t compileFlags; rdctype::array< rdctype::pair > files; // + + int32_t entryFile; // index in above array of 'main' file with entry point }; struct ShaderReflection diff --git a/renderdoc/core/replay_proxy.cpp b/renderdoc/core/replay_proxy.cpp index b1d7b229d..bf62e3849 100644 --- a/renderdoc/core/replay_proxy.cpp +++ b/renderdoc/core/replay_proxy.cpp @@ -212,7 +212,7 @@ void Serialiser::Serialise(const char *name, ShaderReflection &el) Serialise("", el.Interfaces); - SIZE_CHECK(ShaderReflection, 68); + SIZE_CHECK(ShaderReflection, 72); } template<> diff --git a/renderdoc/driver/d3d11/d3d11_common.cpp b/renderdoc/driver/d3d11/d3d11_common.cpp index e516e6feb..791a76daa 100644 --- a/renderdoc/driver/d3d11/d3d11_common.cpp +++ b/renderdoc/driver/d3d11/d3d11_common.cpp @@ -888,11 +888,19 @@ ShaderReflection *MakeShaderReflection(DXBC::DXBCFile *dxbc) ret->DebugInfo.entryFunc = dxbc->m_DebugInfo->GetEntryFunction(); ret->DebugInfo.compileFlags = dxbc->m_DebugInfo->GetShaderCompileFlags(); + ret->DebugInfo.entryFile = -1; + create_array_uninit(ret->DebugInfo.files, dxbc->m_DebugInfo->Files.size()); for(size_t i=0; i < dxbc->m_DebugInfo->Files.size(); i++) { ret->DebugInfo.files[i].first = dxbc->m_DebugInfo->Files[i].first; ret->DebugInfo.files[i].second = dxbc->m_DebugInfo->Files[i].second; + + if(ret->DebugInfo.entryFile == -1 && + strstr(ret->DebugInfo.files[i].second.elems, ret->DebugInfo.entryFunc.elems)) + { + ret->DebugInfo.entryFile = (int32_t)i; + } } } diff --git a/renderdoc/driver/gl/gl_shader_refl.cpp b/renderdoc/driver/gl/gl_shader_refl.cpp index c3cea1b4f..85621133a 100644 --- a/renderdoc/driver/gl/gl_shader_refl.cpp +++ b/renderdoc/driver/gl/gl_shader_refl.cpp @@ -749,6 +749,8 @@ void MakeShaderReflection(const GLHookSet &gl, GLenum shadType, GLuint sepProg, refl.DebugInfo.entryFunc = "main"; refl.DebugInfo.compileFlags = 0; + refl.DebugInfo.entryFile = 0; + refl.Disassembly = ""; vector resources; diff --git a/renderdocui/Interop/Shader.cs b/renderdocui/Interop/Shader.cs index b2c0e8444..534c149ad 100644 --- a/renderdocui/Interop/Shader.cs +++ b/renderdocui/Interop/Shader.cs @@ -373,6 +373,8 @@ namespace renderdoc [CustomMarshalAs(CustomUnmanagedType.TemplatedArray)] public DebugFile[] files; + + public Int32 entryFile; }; [StructLayout(LayoutKind.Sequential)] diff --git a/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs b/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs index e9fc9b614..957a76a08 100644 --- a/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs +++ b/renderdocui/Windows/PipelineState/D3D11PipelineStateViewer.cs @@ -225,15 +225,19 @@ namespace renderdocui.Windows.PipelineState { string shaderfn = ""; + int entryFile = shaderDetails.DebugInfo.entryFile; + if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length) + entryFile = 0; + try { - shaderfn = Path.GetFileName(shaderDetails.DebugInfo.files[0].filename); + shaderfn = Path.GetFileName(shaderDetails.DebugInfo.files[entryFile].filename); } catch (ArgumentException) { // invalid path or similar, just try to go from last \ or / onwards - shaderfn = shaderDetails.DebugInfo.files[0].filename; + shaderfn = shaderDetails.DebugInfo.files[entryFile].filename; int idx = shaderfn.LastIndexOfAny(new char[] { '/', '\\' }); if (idx > 0) shaderfn = shaderfn.Substring(idx + 1); @@ -1863,7 +1867,11 @@ namespace renderdocui.Windows.PipelineState foreach (var s in shaderDetails.DebugInfo.files) files.Add(Path.GetFileName(s.filename), s.filetext); - mainfile = Path.GetFileName(shaderDetails.DebugInfo.files[0].filename); + int entryFile = shaderDetails.DebugInfo.entryFile; + if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length) + entryFile = 0; + + mainfile = Path.GetFileName(shaderDetails.DebugInfo.files[entryFile].filename); } else { @@ -1948,7 +1956,7 @@ namespace renderdocui.Windows.PipelineState // Save Callback (ShaderViewer viewer, Dictionary updatedfiles) => { - string compileSource = updatedfiles.First().Value; + string compileSource = updatedfiles[mainfile]; // try and match up #includes against the files that we have. This isn't always // possible as fxc only seems to include the source for files if something in diff --git a/renderdocui/Windows/PipelineState/GLPipelineStateViewer.cs b/renderdocui/Windows/PipelineState/GLPipelineStateViewer.cs index 7ae7c8289..33c777d96 100644 --- a/renderdocui/Windows/PipelineState/GLPipelineStateViewer.cs +++ b/renderdocui/Windows/PipelineState/GLPipelineStateViewer.cs @@ -1867,7 +1867,9 @@ namespace renderdocui.Windows.PipelineState // Save Callback (ShaderViewer viewer, Dictionary updatedfiles) => { - string compileSource = updatedfiles.First().Value; + string compileSource = ""; + foreach (var kv in updatedfiles) + compileSource += kv.Value; // invoke off to the ReplayRenderer to replace the log's shader // with our edited one diff --git a/renderdocui/Windows/ShaderViewer.cs b/renderdocui/Windows/ShaderViewer.cs index 8e8041bd3..32b1018ca 100644 --- a/renderdocui/Windows/ShaderViewer.cs +++ b/renderdocui/Windows/ShaderViewer.cs @@ -521,6 +521,8 @@ namespace renderdocui.Windows else Text = String.Format("{0}()", shader.DebugInfo.entryFunc); + int fileIdx = 0; + DockContent sel = null; foreach (var f in shader.DebugInfo.files) { @@ -540,8 +542,17 @@ namespace renderdocui.Windows m_Scintillas.Add(scintilla1); - if (f.filetext.Contains(shader.DebugInfo.entryFunc)) + if (shader.DebugInfo.entryFile >= 0 && shader.DebugInfo.entryFile < shader.DebugInfo.files.Length) + { + if (fileIdx == shader.DebugInfo.entryFile) + sel = w; + } + else if (f.filetext.Contains(shader.DebugInfo.entryFunc)) + { sel = w; + } + + fileIdx++; } if (trace != null || sel == null)