Add shader's ID and entry point to the shader reflection struct

* This allows better identification of a shader from its reflection
  bundle. The entry point was already 'optionally' in the debug info
  struct which is no longer a great location for it.
* For APIs where the entry point isn't contractual and it might not be
  listed, instead we just fall back to 'main'. This means that the UI
  or anyone fetching the info can be guaranteed that some sensible entry
  point will be listed.
* Also for the debug info, remove the 'entryFile' index and instead just
  guarantee that as much as possible the entry point will be in the
  first file in the list.
This commit is contained in:
baldurk
2017-07-05 16:27:17 +01:00
parent c2b0c2d7d8
commit bdf2a68c71
26 changed files with 298 additions and 256 deletions
+10
View File
@@ -37,9 +37,14 @@ namespace renderdoc
private void PostMarshal()
{
if (_ptr_Bytecode != IntPtr.Zero)
{
Bytecode = (ShaderReflection)CustomMarshal.PtrToStructure(_ptr_Bytecode, typeof(ShaderReflection), false);
Bytecode.origPtr = _ptr_Bytecode;
}
else
{
Bytecode = null;
}
_ptr_Bytecode = IntPtr.Zero;
}
@@ -95,9 +100,14 @@ namespace renderdoc
private void PostMarshal()
{
if (_ptr_ShaderDetails != IntPtr.Zero)
{
ShaderDetails = (ShaderReflection)CustomMarshal.PtrToStructure(_ptr_ShaderDetails, typeof(ShaderReflection), false);
ShaderDetails.origPtr = _ptr_ShaderDetails;
}
else
{
ShaderDetails = null;
}
_ptr_ShaderDetails = IntPtr.Zero;
}
@@ -166,9 +166,14 @@ namespace renderdoc
private void PostMarshal()
{
if (_ptr_ShaderDetails != IntPtr.Zero)
{
ShaderDetails = (ShaderReflection)CustomMarshal.PtrToStructure(_ptr_ShaderDetails, typeof(ShaderReflection), false);
ShaderDetails.origPtr = _ptr_ShaderDetails;
}
else
{
ShaderDetails = null;
}
_ptr_ShaderDetails = IntPtr.Zero;
}
+5
View File
@@ -89,9 +89,14 @@ namespace renderdoc
private void PostMarshal()
{
if (_ptr_ShaderDetails != IntPtr.Zero)
{
ShaderDetails = (ShaderReflection)CustomMarshal.PtrToStructure(_ptr_ShaderDetails, typeof(ShaderReflection), false);
ShaderDetails.origPtr = _ptr_ShaderDetails;
}
else
{
ShaderDetails = null;
}
_ptr_ShaderDetails = IntPtr.Zero;
}
+8 -5
View File
@@ -377,9 +377,6 @@ namespace renderdoc
[StructLayout(LayoutKind.Sequential)]
public class ShaderDebugChunk
{
[CustomMarshalAs(CustomUnmanagedType.UTF8TemplatedString)]
public string entryFunc;
public UInt32 compileFlags;
public struct DebugFile
@@ -413,13 +410,19 @@ namespace renderdoc
[CustomMarshalAs(CustomUnmanagedType.TemplatedArray)]
public DebugFile[] files;
public Int32 entryFile;
};
[StructLayout(LayoutKind.Sequential)]
public class ShaderReflection
{
public ResourceId ID;
[CustomMarshalAs(CustomUnmanagedType.UTF8TemplatedString)]
public string EntryPoint;
[CustomMarshalAs(CustomUnmanagedType.Skip)]
public IntPtr origPtr;
[CustomMarshalAs(CustomUnmanagedType.CustomClass)]
public ShaderDebugChunk DebugInfo;
@@ -171,9 +171,14 @@ namespace renderdoc
private void PostMarshal()
{
if (_ptr_ShaderDetails != IntPtr.Zero)
{
ShaderDetails = (ShaderReflection)CustomMarshal.PtrToStructure(_ptr_ShaderDetails, typeof(ShaderReflection), false);
ShaderDetails.origPtr = _ptr_ShaderDetails;
}
else
{
ShaderDetails = null;
}
_ptr_ShaderDetails = IntPtr.Zero;
}
@@ -310,18 +310,8 @@ namespace renderdocui.Windows.PipelineState
else
shader.Text = stage.ShaderName;
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
{
string shaderfn = "";
int entryFile = shaderDetails.DebugInfo.entryFile;
if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length)
entryFile = 0;
shaderfn = shaderDetails.DebugInfo.files[entryFile].BaseFilename;
shader.Text = shaderDetails.DebugInfo.entryFunc + "()" + " - " + shaderfn;
}
if (shaderDetails != null && shaderDetails.DebugInfo.files.Length > 0)
shader.Text = shaderDetails.EntryPoint + "()" + " - " + shaderDetails.DebugInfo.files[0].BaseFilename;
int vs = 0;
@@ -768,8 +758,8 @@ namespace renderdocui.Windows.PipelineState
else
iaBytecode.Text = state.m_IA.LayoutName;
if (state.m_IA.Bytecode != null && state.m_IA.Bytecode.DebugInfo != null && state.m_IA.Bytecode.DebugInfo.entryFunc.Length > 0)
iaBytecode.Text += " (" + state.m_IA.Bytecode.DebugInfo.entryFunc + ")";
if (state.m_IA.Bytecode != null && state.m_IA.Bytecode.DebugInfo != null)
iaBytecode.Text += " (" + state.m_IA.Bytecode.EntryPoint + ")";
iaBytecodeMismatch.Text = "";
iaBytecodeMismatch.Visible = false;
@@ -2420,9 +2410,9 @@ namespace renderdocui.Windows.PipelineState
string mainfile = "";
var files = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
if (shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
if (shaderDetails.DebugInfo.files.Length > 0)
{
entryFunc = shaderDetails.DebugInfo.entryFunc;
entryFunc = shaderDetails.EntryPoint;
foreach (var s in shaderDetails.DebugInfo.files)
{
@@ -2432,11 +2422,7 @@ namespace renderdocui.Windows.PipelineState
files.Add(s.FullFilename, s.filetext);
}
int entryFile = shaderDetails.DebugInfo.entryFile;
if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length)
entryFile = 0;
mainfile = shaderDetails.DebugInfo.files[entryFile].FullFilename;
mainfile = shaderDetails.DebugInfo.files[0].FullFilename;
}
else
{
@@ -3334,8 +3320,8 @@ namespace renderdocui.Windows.PipelineState
else
shadername = sh.ShaderName;
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.DebugInfo.entryFunc + "()" + " - " +
if (shaderDetails != null && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.EntryPoint + "()" + " - " +
shaderDetails.DebugInfo.files[0].BaseFilename;
writer.WriteStartElement("p");
@@ -512,18 +512,8 @@ namespace renderdocui.Windows.PipelineState
else
shader.Text = state.PipelineName + " - " + stage.stage.Str(GraphicsAPI.D3D12) + " Shader";
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
{
string shaderfn = "";
int entryFile = shaderDetails.DebugInfo.entryFile;
if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length)
entryFile = 0;
shaderfn = shaderDetails.DebugInfo.files[entryFile].BaseFilename;
shader.Text = shaderDetails.DebugInfo.entryFunc + "()" + " - " + shaderfn;
}
if (shaderDetails != null && shaderDetails.DebugInfo.files.Length > 0)
shader.Text = shaderDetails.EntryPoint + "()" + " - " + shaderDetails.DebugInfo.files[0].BaseFilename;
int vs = 0;
@@ -2047,9 +2037,9 @@ namespace renderdocui.Windows.PipelineState
string mainfile = "";
var files = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
if (shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
if (shaderDetails.DebugInfo.files.Length > 0)
{
entryFunc = shaderDetails.DebugInfo.entryFunc;
entryFunc = shaderDetails.EntryPoint;
foreach (var s in shaderDetails.DebugInfo.files)
{
@@ -2059,11 +2049,7 @@ namespace renderdocui.Windows.PipelineState
files.Add(s.FullFilename, s.filetext);
}
int entryFile = shaderDetails.DebugInfo.entryFile;
if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length)
entryFile = 0;
mainfile = shaderDetails.DebugInfo.files[entryFile].FullFilename;
mainfile = shaderDetails.DebugInfo.files[0].FullFilename;
}
else
{
@@ -2927,8 +2913,8 @@ namespace renderdocui.Windows.PipelineState
else
shadername = sh.stage.Str(GraphicsAPI.D3D12);
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.DebugInfo.entryFunc + "()" + " - " +
if (shaderDetails != null && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.EntryPoint + "()" + " - " +
shaderDetails.DebugInfo.files[0].BaseFilename;
writer.WriteStartElement("p");
@@ -953,23 +953,13 @@ namespace renderdocui.Windows.PipelineState
else
shader.Text = stage.ShaderName;
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0)
if (shaderDetails != null)
{
if (shaderDetails.DebugInfo.files.Length > 0 || shaderDetails.DebugInfo.entryFunc != "main")
shader.Text = shaderDetails.DebugInfo.entryFunc + "()";
if (shaderDetails.DebugInfo.files.Length > 0 || shaderDetails.EntryPoint != "main")
shader.Text = shaderDetails.EntryPoint + "()";
if (shaderDetails.DebugInfo.files.Length > 0)
{
string shaderfn = "";
int entryFile = shaderDetails.DebugInfo.entryFile;
if (entryFile < 0 || entryFile >= shaderDetails.DebugInfo.files.Length)
entryFile = 0;
shaderfn = shaderDetails.DebugInfo.files[entryFile].BaseFilename;
shader.Text += " - " + shaderfn;
}
shader.Text += " - " + shaderDetails.DebugInfo.files[0].BaseFilename;
}
int vs = 0;
@@ -2844,8 +2834,8 @@ namespace renderdocui.Windows.PipelineState
else
shadername = sh.ShaderName;
if (shaderDetails != null && shaderDetails.DebugInfo.entryFunc.Length > 0 && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.DebugInfo.entryFunc + "()" + " - " +
if (shaderDetails != null && shaderDetails.DebugInfo.files.Length > 0)
shadername = shaderDetails.EntryPoint + "()" + " - " +
shaderDetails.DebugInfo.files[0].BaseFilename;
writer.WriteStartElement("p");
+4 -11
View File
@@ -578,12 +578,12 @@ namespace renderdocui.Windows
w.CloseButtonVisible = false;
}
if (shader != null && shader.DebugInfo.entryFunc.Length > 0 && shader.DebugInfo.files.Length > 0)
if (shader != null && shader.DebugInfo.files.Length > 0)
{
if(trace != null)
Text = String.Format("Debug {0}() - {1}", shader.DebugInfo.entryFunc, debugContext);
Text = String.Format("Debug {0}() - {1}", shader.EntryPoint, debugContext);
else
Text = String.Format("{0}()", shader.DebugInfo.entryFunc);
Text = String.Format("{0}()", shader.EntryPoint);
int fileIdx = 0;
@@ -606,15 +606,8 @@ namespace renderdocui.Windows
m_Scintillas.Add(scintilla1);
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))
{
if (sel == null)
sel = w;
}
fileIdx++;
}