Skip to content

Virtual texturing fullscreen debug [Hold] #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public enum FullScreenDebugMode
DepthOfFieldCoc,
/// <summary>Display Transparency Overdraw.</summary>
TransparencyOverdraw,
/// <summary>Display Virtual Texturing resolver feedback.</summary>
VirtualTexturingFeedback,
/// <summary>Maximum Full Screen Rendering debug mode value (used internally).</summary>
MaxRenderingFullScreenDebug,

Expand All @@ -113,6 +115,11 @@ public enum FullScreenDebugMode
MaxMaterialFullScreenDebug
}

public enum VirtualTexturingFeedbackMode
{
HighlightMips = 0,
HighlightStackConfiguration = 1
}
/// <summary>
/// Class managing debug display in HDRP.
/// </summary>
Expand Down Expand Up @@ -195,6 +202,8 @@ public class DebugData
public uint screenSpaceShadowIndex = 0;
/// <summary>Display ray tracing ray count per frame.</summary>
public bool countRays = false;
/// <summary>Toggle focus on mips vs VT tilesets</summary>
public VirtualTexturingFeedbackMode VTFeedbackMode = VirtualTexturingFeedbackMode.HighlightMips;

/// <summary>Index of the camera to freeze for visibility.</summary>
public int debugCameraToFreeze = 0;
Expand All @@ -216,6 +225,7 @@ public class DebugData
internal int tileClusterDebugByCategoryEnumIndex;
internal int lightVolumeDebugTypeEnumIndex;
internal int renderingFulscreenDebugModeEnumIndex;
internal int vtFeedbackEnumIndex;
internal int terrainTextureEnumIndex;
internal int colorPickerDebugModeEnumIndex;
internal int msaaSampleDebugModeEnumIndex;
Expand Down Expand Up @@ -1376,6 +1386,18 @@ void RegisterRenderingDebug()
});
}

if (data.fullScreenDebugMode == FullScreenDebugMode.VirtualTexturingFeedback)
{
widgetList.Add(new DebugUI.Container
{
children =
{
new DebugUI.EnumField {displayName = "Debug mode ", getter = () => (int)data.VTFeedbackMode, setter = value => data.VTFeedbackMode = (VirtualTexturingFeedbackMode)value, autoEnum = typeof(VirtualTexturingFeedbackMode), getIndex = () => data.vtFeedbackEnumIndex, setIndex = value => data.vtFeedbackEnumIndex = value}
}
})
;
}

widgetList.AddRange(new DebugUI.Widget[]
{
new DebugUI.EnumField { displayName = "MipMaps", getter = () => (int)data.mipMapDebugSettings.debugMipMapMode, setter = value => SetMipMapMode((DebugMipMapMode)value), autoEnum = typeof(DebugMipMapMode), onValueChanged = RefreshRenderingDebug, getIndex = () => data.mipMapsEnumIndex, setIndex = value => { data.ResetExclusiveEnumIndices(); data.mipMapsEnumIndex = value; } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
#define FULLSCREENDEBUGMODE_COLOR_LOG (19)
#define FULLSCREENDEBUGMODE_DEPTH_OF_FIELD_COC (20)
#define FULLSCREENDEBUGMODE_TRANSPARENCY_OVERDRAW (21)
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (22)
#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (23)
#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (24)
#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (25)
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (26)
#define FULLSCREENDEBUGMODE_VIRTUAL_TEXTURING_FEEDBACK (22)
#define FULLSCREENDEBUGMODE_MAX_RENDERING_FULL_SCREEN_DEBUG (23)
#define FULLSCREENDEBUGMODE_MIN_MATERIAL_FULL_SCREEN_DEBUG (24)
#define FULLSCREENDEBUGMODE_VALIDATE_DIFFUSE_COLOR (25)
#define FULLSCREENDEBUGMODE_VALIDATE_SPECULAR_COLOR (26)
#define FULLSCREENDEBUGMODE_MAX_MATERIAL_FULL_SCREEN_DEBUG (27)


// Generated from UnityEngine.Rendering.HighDefinition.ShaderVariablesDebugDisplay
// PackingRules = Exact
Expand Down Expand Up @@ -66,5 +68,4 @@ CBUFFER_START(ShaderVariablesDebugDisplay)
float3 _DebugDisplayPad0;
CBUFFER_END


#endif
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Shader "Hidden/HDRP/DebugFullScreen"
CBUFFER_START (UnityDebug)
float _FullScreenDebugMode;
float _TransparencyOverdrawMaxPixelCost;
float _VTFocusMips;
uint _DebugContactShadowLightIndex;
int _DebugDepthPyramidMip;
CBUFFER_END
Expand Down Expand Up @@ -58,6 +59,23 @@ Shader "Hidden/HDRP/DebugFullScreen"
return output;
}

static float4 VTDebugColors[] = {
float4(1.0f, 1.0f, 1.0f, 1.0f),
float4(1.0f, 1.0f, 0.0f, 1.0f),
float4(0.0f, 1.0f, 1.0f, 1.0f),
float4(0.0f, 1.0f, 0.0f, 1.0f),
float4(1.0f, 0.0f, 1.0f, 1.0f),
float4(1.0f, 0.0f, 0.0f, 1.0f),
float4(0.0f, 0.0f, 1.0f, 1.0f),
float4(0.5f, 0.5f, 0.5f, 1.0f),
float4(0.5f, 0.5f, 0.0f, 1.0f),
float4(0.0f, 0.5f, 0.5f, 1.0f),
float4(0.0f, 0.5f, 0.0f, 1.0f),
float4(0.5f, 0.0f, 0.5f, 1.0f),
float4(0.5f, 0.0f, 0.0f, 1.0f),
float4(0.0f, 0.0f, 0.5f, 1.0f)
};

// Motion vector debug utilities
float DistanceToLine(float2 p, float2 p1, float2 p2)
{
Expand Down Expand Up @@ -317,6 +335,56 @@ Shader "Hidden/HDRP/DebugFullScreen"
return color;
}

if (_FullScreenDebugMode == FULLSCREENDEBUGMODE_VIRTUAL_TEXTURING_FEEDBACK)
{
float4 color = SAMPLE_TEXTURE2D_X(_DebugFullScreenTexture, s_point_clamp_sampler, input.texcoord);
if (color.r == 0 && color.g == 0 && color.b == 0 && color.a == 0) return float4(0, 0, 0, 0);

float4 swiz;
swiz = color;
swiz *= 255.0f;

float tileX = color.r;
float tileY = color.g;
float level = color.b;
float tex = color.a;

float h = 0;
if (_VTFocusMips == 1)
{
if (tex < 8.0f) h = ((uint)tex % 8) * 45.0f;
else if (tex < 16.0f) h = ((uint) tex % 8) * 45.0f + 22.5f;
else if (tex < 32.0f) h = ((uint) tex % 8) * 45.0f + 11.25f;

h /= 360.0f;

float s = 1.0f;
float v = 1.0f;
v = ((uint)tileY % 5) / 10.0f + 0.25f;
s = ((uint)tileX % 5) / 10.0f + 0.25f;
s = 1.0f - s;

return float4(HsvToRgb(float3(h, s, v)), 1.0f);
}
else
{
float3 hsv = RgbToHsv(VTDebugColors[level].rgb);
//dont adjust hue/saturation when trying to show white or grey (on mips 0 and 7)
if (level == 0 || level == 7)
{
hsv.z = ((uint)tileY % 5) / 5.0f + 1.0f - (((uint)tileX % 5) / 5.0f);
hsv.z /= 2.0f;
hsv.x = 0.0f;
hsv.y = 0.0f;
}
else
{
hsv.y = ((uint)tileY % 5) / 10.0f + 0.5f;
hsv.z = 1.0f - (((uint)tileX % 5) / 10.0f + 0.5f);
}
return float4(HsvToRgb(hsv), 1.0f);
}
}
return float4(0.0, 0.0, 0.0, 0.0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Shader "Hidden/DebugVTBlit"
{

SubShader
{
// No culling or depth
Cull Off ZWrite Off ZTest Always

Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_local __ USE_TEXARRAY

#include "UnityCG.cginc"

struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};

struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};

v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}

#ifdef USE_TEXARRAY
UNITY_DECLARE_TEX2DARRAY(_MainTex);
#else
sampler2D _MainTex;
#endif

fixed4 frag(v2f i) : SV_Target
{
#ifdef USE_TEXARRAY
fixed4 col = UNITY_SAMPLE_TEX2DARRAY(_MainTex,float3(i.uv,0.0f));
#else
fixed4 col = tex2D(_MainTex, i.uv);
#endif

float4 swiz;
swiz = col;
swiz *= 255.0f;

float tileX = swiz.x + fmod(swiz.y, 8.0f) * 256.0f;
float tileY = floor(swiz.y / 8.0f) + fmod(swiz.z, 64.0f) * 32.0f;
float level = floor((swiz.z) / 64.0f) + fmod(swiz.w, 4.0f) * 4.0f;
float tex = floor(swiz.w / 4.0f);

return float4(tileX,tileY,level,tex);
}
ENDCG
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ internal int GetMaxScreenSpaceShadows()
// Debugging
MaterialPropertyBlock m_SharedPropertyBlock = new MaterialPropertyBlock();
DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings();
Material m_VTDebugBlit;
/// <summary>
/// Debug display settings.
/// </summary>
Expand Down Expand Up @@ -1229,6 +1230,16 @@ void ConfigureKeywords(bool enableBakeShadowMask, HDCamera hdCamera, CommandBuff

// Raise or remove the depth msaa flag based on the frame setting
CoreUtils.SetKeyword(cmd, "WRITE_MSAA_DEPTH", hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA));

#if UNITY_EDITOR && ENABLE_VIRTUALTEXTURES
//Set VTDebug mode based on useTexArray
if (!m_VTDebugBlit) m_VTDebugBlit = new Material(Shader.Find("Hidden/DebugVTBlit"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
2 remark here.
Is there any reasons to keep this debug mode editor only? All our debug mode are available at runtime and it is useful for users to see it on device (like no PS4 screen for exampl)e.

Second, we don't inspect shader directly Shader.Find("Hidden/DebugVTBlit")); in HDRP we always put system shader in an hdrp resource asset \com.unity.render-pipelines.high-definition\Runtime\RenderPipeline\RenderPipelineResources.cs and then access it like this.
This is to not pollute other render pipeline with our thing (like URP).

if (m_VTDebugBlit)
{
if (TextureXR.useTexArray) m_VTDebugBlit.EnableKeyword("USE_TEXARRAY");
else m_VTDebugBlit.DisableKeyword("USE_TEXARRAY");
}
#endif
}

struct RenderRequest
Expand Down Expand Up @@ -2534,6 +2545,14 @@ void Callback(CommandBuffer c, HDCamera cam)
#if ENABLE_VIRTUALTEXTURES
m_VtBufferManager.Resolve(cmd, m_GbufferManager.GetVTFeedbackBuffer(), hdCamera);
VirtualTexturing.System.Update();
#if UNITY_EDITOR
if(m_VTDebugBlit != null)
{
PushFullScreenDebugTexture(cmd, GetVTFeedbackBufferForForward(hdCamera), FullScreenDebugMode.VirtualTexturingFeedback, m_VTDebugBlit);
m_DebugFullScreenPropertyBlock.SetFloat(HDShaderIDs._VTFocusMips, (int)m_DebugDisplaySettings.data.VTFeedbackMode);
}

#endif
#endif

// At this point, m_CameraColorBuffer has been filled by either debug views are regular rendering so we can push it here.
Expand Down Expand Up @@ -4379,6 +4398,17 @@ internal void PushFullScreenDebugTexture(HDCamera hdCamera, CommandBuffer cmd, R
}
}

void PushFullScreenDebugTexture(CommandBuffer cmd, RTHandle textureID, FullScreenDebugMode debugMode, Material shader)
{
if(debugMode == m_CurrentDebugDisplaySettings.data.fullScreenDebugMode)
{
m_FullScreenDebugPushed = true;
var stringsz = shader.GetTexturePropertyNames();
cmd.SetGlobalTexture("_MainTex", textureID);
cmd.Blit(textureID, m_DebugFullScreenTempBuffer, shader,0);
}
}

void PushFullScreenDebugTextureMip(HDCamera hdCamera, CommandBuffer cmd, RTHandle texture, int lodCount, FullScreenDebugMode debugMode)
{
if (debugMode == m_CurrentDebugDisplaySettings.data.fullScreenDebugMode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ static class HDShaderIDs
public static readonly int _HorizonZenithShiftPower = Shader.PropertyToID("_HorizonZenithShiftPower");
public static readonly int _HorizonZenithShiftScale = Shader.PropertyToID("_HorizonZenithShiftScale");

//Virtual Texturing debug
public static readonly int _VTFocusMips = Shader.PropertyToID("_VTFocusMips");

// Raytracing variables
public static readonly int _RaytracingRayBias = Shader.PropertyToID("_RaytracingRayBias");
public static readonly int _RayTracingLayerMask = Shader.PropertyToID("_RayTracingLayerMask");
Expand Down