Make minmax/histogram aware of custom shaders. Refs #385

* This moves those functions relative to an output instead of the
  renderer, so they pick up the settings etc from the output
  configuration.
This commit is contained in:
baldurk
2016-10-04 14:36:56 +02:00
parent a1c72464fd
commit 0f4d43cd37
6 changed files with 152 additions and 129 deletions
+49 -49
View File
@@ -143,6 +143,11 @@ namespace renderdoc
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern void ReplayOutput_GetCustomShaderTexID(IntPtr real, ref ResourceId texid);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayOutput_GetMinMax(IntPtr real, IntPtr outminval, IntPtr outmaxval);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayOutput_GetHistogram(IntPtr real, float minval, float maxval, bool[] channels, IntPtr outhistogram);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayOutput_PickPixel(IntPtr real, ResourceId texID, bool customShader,
UInt32 x, UInt32 y, UInt32 sliceFace, UInt32 mip, UInt32 sample, IntPtr outval);
@@ -204,6 +209,50 @@ namespace renderdoc
return ret;
}
public bool GetMinMax(out PixelValue minval, out PixelValue maxval)
{
IntPtr mem1 = CustomMarshal.Alloc(typeof(PixelValue));
IntPtr mem2 = CustomMarshal.Alloc(typeof(PixelValue));
bool success = ReplayOutput_GetMinMax(m_Real, mem1, mem2);
if (success)
{
minval = (PixelValue)CustomMarshal.PtrToStructure(mem1, typeof(PixelValue), true);
maxval = (PixelValue)CustomMarshal.PtrToStructure(mem2, typeof(PixelValue), true);
}
else
{
minval = null;
maxval = null;
}
CustomMarshal.Free(mem1);
CustomMarshal.Free(mem2);
return success;
}
public bool GetHistogram(float minval, float maxval,
bool Red, bool Green, bool Blue, bool Alpha,
out UInt32[] histogram)
{
IntPtr mem = CustomMarshal.Alloc(typeof(templated_array));
bool[] channels = new bool[] { Red, Green, Blue, Alpha };
bool success = ReplayOutput_GetHistogram(m_Real, minval, maxval, channels, mem);
histogram = null;
if (success)
histogram = (UInt32[])CustomMarshal.GetTemplatedArray(mem, typeof(UInt32), true);
CustomMarshal.Free(mem);
return success;
}
public PixelValue PickPixel(ResourceId texID, bool customShader, UInt32 x, UInt32 y, UInt32 sliceFace, UInt32 mip, UInt32 sample)
{
IntPtr mem = CustomMarshal.Alloc(typeof(PixelValue));
@@ -313,11 +362,6 @@ namespace renderdoc
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_GetPostVSData(IntPtr real, UInt32 instID, MeshDataStage stage, IntPtr outdata);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_GetMinMax(IntPtr real, ResourceId tex, UInt32 sliceFace, UInt32 mip, UInt32 sample, FormatComponentType typeHint, IntPtr outminval, IntPtr outmaxval);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_GetHistogram(IntPtr real, ResourceId tex, UInt32 sliceFace, UInt32 mip, UInt32 sample, FormatComponentType typeHint, float minval, float maxval, bool[] channels, IntPtr outhistogram);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
private static extern bool ReplayRenderer_GetBufferData(IntPtr real, ResourceId buff, UInt64 offset, UInt64 len, IntPtr outdata);
[DllImport("renderdoc.dll", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
@@ -821,50 +865,6 @@ namespace renderdoc
return ret;
}
public bool GetMinMax(ResourceId tex, UInt32 sliceFace, UInt32 mip, UInt32 sample, FormatComponentType typeHint, out PixelValue minval, out PixelValue maxval)
{
IntPtr mem1 = CustomMarshal.Alloc(typeof(PixelValue));
IntPtr mem2 = CustomMarshal.Alloc(typeof(PixelValue));
bool success = ReplayRenderer_GetMinMax(m_Real, tex, sliceFace, mip, sample, typeHint, mem1, mem2);
if (success)
{
minval = (PixelValue)CustomMarshal.PtrToStructure(mem1, typeof(PixelValue), true);
maxval = (PixelValue)CustomMarshal.PtrToStructure(mem2, typeof(PixelValue), true);
}
else
{
minval = null;
maxval = null;
}
CustomMarshal.Free(mem1);
CustomMarshal.Free(mem2);
return success;
}
public bool GetHistogram(ResourceId tex, UInt32 sliceFace, UInt32 mip, UInt32 sample, FormatComponentType typeHint, float minval, float maxval,
bool Red, bool Green, bool Blue, bool Alpha,
out UInt32[] histogram)
{
IntPtr mem = CustomMarshal.Alloc(typeof(templated_array));
bool[] channels = new bool[] { Red, Green, Blue, Alpha };
bool success = ReplayRenderer_GetHistogram(m_Real, tex, sliceFace, mip, sample, typeHint, minval, maxval, channels, mem);
histogram = null;
if (success)
histogram = (UInt32[])CustomMarshal.GetTemplatedArray(mem, typeof(UInt32), true);
CustomMarshal.Free(mem);
return success;
}
public byte[] GetBufferData(ResourceId buff, UInt64 offset, UInt64 len)
{
IntPtr mem = CustomMarshal.Alloc(typeof(templated_array));
+12 -10
View File
@@ -3331,16 +3331,13 @@ namespace renderdocui.Windows
private void AutoFitRange()
{
// no log loaded or buffer/empty texture currently being viewed - don't autofit
if (!m_Core.LogLoaded || CurrentTexture == null)
if (!m_Core.LogLoaded || CurrentTexture == null || m_Output == null)
return;
m_Core.Renderer.BeginInvoke((ReplayRenderer r) =>
{
PixelValue min, max;
bool success = r.GetMinMax(m_TexDisplay.texid,
m_TexDisplay.sliceFace, m_TexDisplay.mip, m_TexDisplay.sampleIdx,
m_TexDisplay.typeHint,
out min, out max);
bool success = m_Output.GetMinMax(out min, out max);
if (success)
{
@@ -3351,6 +3348,11 @@ namespace renderdocui.Windows
ResourceFormat fmt = CurrentTexture.format;
if (m_TexDisplay.CustomShader != ResourceId.Null)
{
fmt.compType = FormatComponentType.Float;
}
for (int i = 0; i < 4; i++)
{
if (fmt.compType == FormatComponentType.UInt)
@@ -3424,17 +3426,17 @@ namespace renderdocui.Windows
private void RT_UpdateVisualRange(ReplayRenderer r)
{
if (!m_Visualise || CurrentTexture == null) return;
if (!m_Visualise || CurrentTexture == null || m_Output == null) return;
ResourceFormat fmt = CurrentTexture.format;
if (m_TexDisplay.CustomShader != ResourceId.Null)
fmt.compCount = 4;
bool success = true;
uint[] histogram;
success = r.GetHistogram(m_TexDisplay.texid,
m_TexDisplay.sliceFace, m_TexDisplay.mip, m_TexDisplay.sampleIdx,
m_TexDisplay.typeHint,
rangeHistogram.RangeMin, rangeHistogram.RangeMax,
success = m_Output.GetHistogram(rangeHistogram.RangeMin, rangeHistogram.RangeMax,
m_TexDisplay.Red,
m_TexDisplay.Green && fmt.compCount > 1,
m_TexDisplay.Blue && fmt.compCount > 2,