From 95224dc86f72970d302a454f5b520af0fa625452 Mon Sep 17 00:00:00 2001 From: robin-demoor <60922742+robin-demoor@users.noreply.github.com> Date: Fri, 3 Apr 2020 11:46:26 +0200 Subject: [PATCH 1/3] Virtual texturing full screen debug (#6534) * FullScreenDebug mip focus, tileset focus --- .../Runtime/Debug/DebugDisplay.cs | 22 ++++++ .../Runtime/Debug/DebugDisplay.cs.hlsl | 13 ++-- .../Runtime/Debug/DebugFullScreen.shader | 68 +++++++++++++++++++ .../Runtime/Debug/DebugVTBlit.shader | 66 ++++++++++++++++++ .../Runtime/Debug/DebugVTBlit.shader.meta | 9 +++ .../RenderPipeline/HDRenderPipeline.cs | 32 +++++++++ .../RenderPipeline/HDStringConstants.cs | 3 + 7 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader create mode 100644 com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs index 9f5f83e7ae1..f80d7bcdd90 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs @@ -61,6 +61,8 @@ public enum FullScreenDebugMode DepthOfFieldCoc, /// Display Transparency Overdraw. TransparencyOverdraw, + /// Display Virtual Texturing resolver feedback. + VirtualTexturingFeedback, /// Maximum Full Screen Rendering debug mode value (used internally). MaxRenderingFullScreenDebug, @@ -75,6 +77,11 @@ public enum FullScreenDebugMode MaxMaterialFullScreenDebug } + public enum VirtualTexturingFeedbackMode + { + HighlightMips = 0, + HighlightStackConfiguration = 1 + } /// /// Class managing debug display in HDRP. /// @@ -157,6 +164,8 @@ public class DebugData public uint screenSpaceShadowIndex = 0; /// Display ray tracing ray count per frame. public bool countRays = false; + /// Toggle focus on mips vs VT tilesets + public VirtualTexturingFeedbackMode VTFeedbackMode = VirtualTexturingFeedbackMode.HighlightMips; /// Index of the camera to freeze for visibility. public int debugCameraToFreeze = 0; @@ -178,6 +187,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; @@ -1338,6 +1348,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; } }, diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl index 4349a804e4a..1aa8e498c60 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs.hlsl @@ -29,11 +29,10 @@ #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) #endif diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader index 749276a6073..6b9d7b5d5c4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugFullScreen.shader @@ -29,6 +29,7 @@ Shader "Hidden/HDRP/DebugFullScreen" CBUFFER_START (UnityDebug) float _FullScreenDebugMode; float _TransparencyOverdrawMaxPixelCost; + float _VTFocusMips; CBUFFER_END TEXTURE2D_X(_DebugFullScreenTexture); @@ -56,6 +57,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) { @@ -310,6 +328,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); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader new file mode 100644 index 00000000000..4559fdd77cb --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader @@ -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 + } + } +} diff --git a/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta new file mode 100644 index 00000000000..7ea74d22c6f --- /dev/null +++ b/com.unity.render-pipelines.high-definition/Runtime/Debug/DebugVTBlit.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: de1f42f132e4e9948bd09358ef124d46 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index d8435fcc947..45c8d9d4bee 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -263,6 +263,7 @@ internal int GetMaxScreenSpaceShadows() // Debugging MaterialPropertyBlock m_SharedPropertyBlock = new MaterialPropertyBlock(); DebugDisplaySettings m_DebugDisplaySettings = new DebugDisplaySettings(); + Material m_VTDebugBlit; /// /// Debug display settings. /// @@ -1213,6 +1214,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 + //Set VTDebug mode based on useTexArray + m_VTDebugBlit = new Material(Shader.Find("Hidden/DebugVTBlit")); + if (m_VTDebugBlit) + { + if (TextureXR.useTexArray) m_VTDebugBlit.EnableKeyword("USE_TEXARRAY"); + else m_VTDebugBlit.DisableKeyword("USE_TEXARRAY"); + } +#endif } struct RenderRequest @@ -2417,6 +2428,14 @@ void Callback(CommandBuffer c, HDCamera cam) #if ENABLE_VIRTUALTEXTURES m_VtBufferManager.Resolve(cmd, m_GbufferManager.GetVTFeedbackBuffer(), hdCamera.actualWidth, hdCamera.actualHeight); 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. @@ -4258,6 +4277,19 @@ 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(); + shader.SetTexture("_MainTex", textureID); + cmd.SetGlobalTexture("_MainTex", textureID); + cmd.Blit(textureID, m_DebugFullScreenTempBuffer, shader,0); + } + } + + void PushFullScreenDebugTextureMip(HDCamera hdCamera, CommandBuffer cmd, RTHandle texture, int lodCount, Vector4 scaleBias, FullScreenDebugMode debugMode) { if (debugMode == m_CurrentDebugDisplaySettings.data.fullScreenDebugMode) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs index 3a2fb788f62..db8f0d527db 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStringConstants.cs @@ -595,6 +595,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"); From 8f747f485235e361b9e9532b9f3be11c596eeaa3 Mon Sep 17 00:00:00 2001 From: robin-demoor Date: Thu, 16 Apr 2020 10:32:05 +0200 Subject: [PATCH 2/3] Removed redundant shader variable set --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 8964e780227..c39fd51ed23 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -4321,7 +4321,6 @@ void PushFullScreenDebugTexture(CommandBuffer cmd, RTHandle textureID, FullScree { m_FullScreenDebugPushed = true; var stringsz = shader.GetTexturePropertyNames(); - shader.SetTexture("_MainTex", textureID); cmd.SetGlobalTexture("_MainTex", textureID); cmd.Blit(textureID, m_DebugFullScreenTempBuffer, shader,0); } From 09e821b13dbb24b5a2629c5e16d852f4cf5d8eb3 Mon Sep 17 00:00:00 2001 From: robin-demoor Date: Thu, 16 Apr 2020 12:48:15 +0200 Subject: [PATCH 3/3] Material leak fix --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index c39fd51ed23..784aaf735f6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1193,9 +1193,9 @@ 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 +#if UNITY_EDITOR && ENABLE_VIRTUALTEXTURES //Set VTDebug mode based on useTexArray - m_VTDebugBlit = new Material(Shader.Find("Hidden/DebugVTBlit")); + if (!m_VTDebugBlit) m_VTDebugBlit = new Material(Shader.Find("Hidden/DebugVTBlit")); if (m_VTDebugBlit) { if (TextureXR.useTexArray) m_VTDebugBlit.EnableKeyword("USE_TEXARRAY");