From 607060832bc1c1a64178a5e2158face8e69bec25 Mon Sep 17 00:00:00 2001 From: Mike Chow Date: Wed, 4 Aug 2021 13:56:46 -0700 Subject: [PATCH 1/3] Added URP late latching support in camera and per render pass. Use new late latching command buffer commands to mark/unmark URP stereo matrices such as stereo view and projection matrices for use in late latching. --- .../Runtime/ScriptableRenderer.cs | 11 +++++++ .../Runtime/UniversalRenderPipeline.cs | 5 +++- .../Runtime/XR/XRPass.cs | 29 +++++++++++++++++++ .../Runtime/XR/XRSystem.cs | 19 ++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index 7376bc8138f..928bfa3a1b4 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -561,6 +561,11 @@ public void Execute(ScriptableRenderContext context, ref RenderingData rendering ExecuteBlock(RenderPassBlock.MainRenderingTransparent, in renderBlocks, context, ref renderingData); } +#if ENABLE_VR && ENABLE_XR_MODULE + if (cameraData.xr.enabled) + cameraData.xr.canMarkLateLatch = false; +#endif + // Draw Gizmos... DrawGizmos(context, camera, GizmoSubset.PreImageEffects); @@ -729,6 +734,10 @@ void ExecuteRenderPass(ScriptableRenderContext context, ScriptableRenderPass ren CommandBufferPool.Release(cmd); renderPass.Execute(context, ref renderingData); +#if ENABLE_VR && ENABLE_XR_MODULE + if (cameraData.xr.enabled && cameraData.xr.hasMarkedLateLatch) + cameraData.xr.UnmarkLateLatchShaderProperties(cmd, ref cameraData); +#endif } void SetRenderPassAttachments(CommandBuffer cmd, ScriptableRenderPass renderPass, ref CameraData cameraData) @@ -924,6 +933,8 @@ void BeginXRRendering(CommandBuffer cmd, ScriptableRenderContext context, ref Ca #if ENABLE_VR && ENABLE_XR_MODULE if (cameraData.xr.enabled) { + if (cameraData.xr.isLateLatchEnabled) + cameraData.xr.canMarkLateLatch = true; cameraData.xr.StartSinglePass(cmd); cmd.EnableShaderKeyword(ShaderKeywordStrings.UseDrawProcedural); context.ExecuteCommandBuffer(cmd); diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs index 5c6101eb8b1..ffc35fa25f2 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -512,6 +512,7 @@ static void RenderCameraStack(ScriptableRenderContext context, Camera baseCamera { UpdateVolumeFramework(baseCamera, baseCameraAdditionalData); } + m_XRSystem.BeginLateLatching(baseCamera, xrPass); } #endif @@ -528,7 +529,9 @@ static void RenderCameraStack(ScriptableRenderContext context, Camera baseCamera { EndCameraRendering(context, baseCamera); } - +#if ENABLE_VR && ENABLE_XR_MODULE + m_XRSystem.EndLateLatching(baseCamera, xrPass); +#endif if (isStackedRendering) { for (int i = 0; i < cameraStack.Count; ++i) diff --git a/com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs b/com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs index 5f96f040a78..01695b06bab 100644 --- a/com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs +++ b/com.unity.render-pipelines.universal/Runtime/XR/XRPass.cs @@ -81,6 +81,9 @@ class XRPass static RenderTargetIdentifier invalidRT = -1; internal bool renderTargetValid { get => renderTarget != invalidRT; } internal bool renderTargetIsRenderTexture { get; private set; } + internal bool isLateLatchEnabled { get; set; } + internal bool canMarkLateLatch { get; set; } + internal bool hasMarkedLateLatch { get; set; } // Access to view information internal Matrix4x4 GetProjMatrix(int viewIndex = 0) { return views[viewIndex].projMatrix; } @@ -450,8 +453,34 @@ internal void UpdateGPUViewAndProjectionMatrices(CommandBuffer cmd, ref CameraDa stereoProjectionMatrix[i] = GL.GetGPUProjectionMatrix(stereoCameraProjectionMatrix[i], isRenderToTexture); } RenderingUtils.SetStereoViewAndProjectionMatrices(cmd, stereoViewMatrix, stereoProjectionMatrix, stereoCameraProjectionMatrix, true); + if (cameraData.xr.canMarkLateLatch) + MarkLateLatchShaderProperties(cmd, ref cameraData); } } + + internal static readonly int UNITY_STEREO_MATRIX_V = Shader.PropertyToID("unity_StereoMatrixV"); + internal static readonly int UNITY_STEREO_MATRIX_IV = Shader.PropertyToID("unity_StereoMatrixInvV"); + internal static readonly int UNITY_STEREO_MATRIX_VP = Shader.PropertyToID("unity_StereoMatrixVP"); + internal static readonly int UNITY_STEREO_MATRIX_IVP = Shader.PropertyToID("unity_StereoMatrixIVP"); + + internal void MarkLateLatchShaderProperties(CommandBuffer cmd, ref CameraData cameraData) + { + cmd.MarkLateLatchMatrixShaderPropertyID(CameraLateLatchMatrixType.View, UNITY_STEREO_MATRIX_V); + cmd.MarkLateLatchMatrixShaderPropertyID(CameraLateLatchMatrixType.InverseView, UNITY_STEREO_MATRIX_IV); + cmd.MarkLateLatchMatrixShaderPropertyID(CameraLateLatchMatrixType.ViewProjection, UNITY_STEREO_MATRIX_VP); + cmd.MarkLateLatchMatrixShaderPropertyID(CameraLateLatchMatrixType.InverseViewProjection, UNITY_STEREO_MATRIX_IVP); + cmd.SetLateLatchProjectionMatrices(stereoProjectionMatrix); + cameraData.xr.hasMarkedLateLatch = true; + } + + internal void UnmarkLateLatchShaderProperties(CommandBuffer cmd, ref CameraData cameraData) + { + cmd.UnmarkLateLatchMatrix(CameraLateLatchMatrixType.View); + cmd.UnmarkLateLatchMatrix(CameraLateLatchMatrixType.InverseView); + cmd.UnmarkLateLatchMatrix(CameraLateLatchMatrixType.ViewProjection); + cmd.UnmarkLateLatchMatrix(CameraLateLatchMatrixType.InverseViewProjection); + cameraData.xr.hasMarkedLateLatch = false; + } } } diff --git a/com.unity.render-pipelines.universal/Runtime/XR/XRSystem.cs b/com.unity.render-pipelines.universal/Runtime/XR/XRSystem.cs index a1237d17255..e769e3bfdc3 100644 --- a/com.unity.render-pipelines.universal/Runtime/XR/XRSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/XR/XRSystem.cs @@ -134,6 +134,25 @@ internal int GetMaxViews() return maxViews; } + internal void BeginLateLatching(Camera camera, XRPass xrPass) + { + //Only support late latching for multiview use case + if (display != null && xrPass.singlePassEnabled && xrPass.viewCount == 2) + { + display.BeginRecordingIfLateLatched(camera); + xrPass.isLateLatchEnabled = true; + } + } + + internal void EndLateLatching(Camera camera, XRPass xrPass) + { + if (display != null && xrPass.isLateLatchEnabled) + { + display.EndRecordingIfLateLatched(camera); + xrPass.isLateLatchEnabled = false; + } + } + internal List SetupFrame(CameraData cameraData) { Camera camera = cameraData.camera; From 1a5da3396fae7aa3f2ac368ccee81acaf17cf071 Mon Sep 17 00:00:00 2001 From: Mike Chow Date: Wed, 25 Aug 2021 13:27:27 -0700 Subject: [PATCH 2/3] add changelog for late latching. Bump up Unity version to 18f in packages --- com.unity.render-pipelines.core/package.json | 2 +- .../package.json | 2 +- com.unity.render-pipelines.high-definition/package.json | 2 +- com.unity.render-pipelines.universal/CHANGELOG.md | 4 ++++ com.unity.render-pipelines.universal/package.json | 2 +- com.unity.shadergraph/package.json | 2 +- com.unity.visualeffectgraph/package.json | 2 +- 7 files changed, 10 insertions(+), 6 deletions(-) diff --git a/com.unity.render-pipelines.core/package.json b/com.unity.render-pipelines.core/package.json index 700484d65db..0620dcfa01b 100644 --- a/com.unity.render-pipelines.core/package.json +++ b/com.unity.render-pipelines.core/package.json @@ -3,7 +3,7 @@ "description": "SRP Core makes it easier to create or customize a Scriptable Render Pipeline (SRP). SRP Core contains reusable code, including boilerplate code for working with platform-specific graphics APIs, utility functions for common rendering operations, and shader libraries. The code in SRP Core is use by the High Definition Render Pipeline (HDRP) and Universal Render Pipeline (URP). If you are creating a custom SRP from scratch or customizing a prebuilt SRP, using SRP Core will save you time.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "Core RP Library", "dependencies": { "com.unity.ugui": "1.0.0" diff --git a/com.unity.render-pipelines.high-definition-config/package.json b/com.unity.render-pipelines.high-definition-config/package.json index a2b918f07ac..aa603cc9f75 100644 --- a/com.unity.render-pipelines.high-definition-config/package.json +++ b/com.unity.render-pipelines.high-definition-config/package.json @@ -3,7 +3,7 @@ "description": "Configuration files for the High Definition Render Pipeline.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "High Definition RP Config", "dependencies": { "com.unity.render-pipelines.core": "10.7.0" diff --git a/com.unity.render-pipelines.high-definition/package.json b/com.unity.render-pipelines.high-definition/package.json index df010a742b1..ba331ceccff 100644 --- a/com.unity.render-pipelines.high-definition/package.json +++ b/com.unity.render-pipelines.high-definition/package.json @@ -3,7 +3,7 @@ "description": "The High Definition Render Pipeline (HDRP) is a high-fidelity Scriptable Render Pipeline built by Unity to target modern (Compute Shader compatible) platforms. HDRP utilizes Physically-Based Lighting techniques, linear lighting, HDR lighting, and a configurable hybrid Tile/Cluster deferred/Forward lighting architecture and gives you the tools you need to create games, technical demos, animations, and more to a high graphical standard.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "High Definition RP", "dependencies": { "com.unity.render-pipelines.core": "10.7.0", diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 8a57b76f555..21f95ded632 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Version Updated The version number for this package has increased due to a version update of a related graphics package. + +### Added +- XR: Added Late Latching support to reduce VR latency (Quest). + ### Fixed - Fixed terrain hole shadowing [case 1349305] diff --git a/com.unity.render-pipelines.universal/package.json b/com.unity.render-pipelines.universal/package.json index 48eac149f95..346d50d5a4c 100644 --- a/com.unity.render-pipelines.universal/package.json +++ b/com.unity.render-pipelines.universal/package.json @@ -3,7 +3,7 @@ "description": "The Universal Render Pipeline (URP) is a prebuilt Scriptable Render Pipeline, made by Unity. URP provides artist-friendly workflows that let you quickly and easily create optimized graphics across a range of platforms, from mobile to high-end consoles and PCs.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "Universal RP", "dependencies": { "com.unity.mathematics": "1.1.0", diff --git a/com.unity.shadergraph/package.json b/com.unity.shadergraph/package.json index 888aeb76d11..d8029ce073a 100644 --- a/com.unity.shadergraph/package.json +++ b/com.unity.shadergraph/package.json @@ -3,7 +3,7 @@ "description": "The Shader Graph package adds a visual Shader editing tool to Unity. You can use this tool to create Shaders in a visual way instead of writing code. Specific render pipelines can implement specific graph features. Currently, both the High Definition Rendering Pipeline and the Universal Rendering Pipeline support Shader Graph.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "Shader Graph", "dependencies": { "com.unity.render-pipelines.core": "10.7.0", diff --git a/com.unity.visualeffectgraph/package.json b/com.unity.visualeffectgraph/package.json index 360fc9c0603..9399be87029 100644 --- a/com.unity.visualeffectgraph/package.json +++ b/com.unity.visualeffectgraph/package.json @@ -3,7 +3,7 @@ "displayName": "Visual Effect Graph", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "description": "The Visual Effect Graph is a node based visual effect editor. It allows you to author next generation visual effects that Unity simulates directly on the GPU. The Visual Effect Graph is production-ready for the High Definition Render Pipeline and runs on all platforms supported by it. Full support for the Universal Render Pipeline and compatible mobile devices is still in development.", "keywords": [ "vfx", From 2b694b4a9627082c525cb7f171dbf4d094871b72 Mon Sep 17 00:00:00 2001 From: Mike Chow Date: Fri, 27 Aug 2021 14:05:02 -0700 Subject: [PATCH 3/3] Bump up Unity version to 18f along with other packages --- com.unity.render-pipelines.lightweight/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.lightweight/package.json b/com.unity.render-pipelines.lightweight/package.json index 51fe7e41079..8b4872f6dd0 100644 --- a/com.unity.render-pipelines.lightweight/package.json +++ b/com.unity.render-pipelines.lightweight/package.json @@ -3,7 +3,7 @@ "description": "The Lightweight Render Pipeline (LWRP) is a prebuilt Scriptable Render Pipeline, made by Unity. The technology offers graphics that are scalable to mobile platforms, and you can also use it for higher-end consoles and PCs. You’re able to achieve quick rendering at a high quality without needing compute shader technology. LWRP uses simplified, physically based Lighting and Materials. The LWRP uses single-pass forward rendering. Use this pipeline to get optimized real-time performance on several platforms.", "version": "10.7.0", "unity": "2020.3", - "unityRelease": "13f1", + "unityRelease": "18f1", "displayName": "Lightweight RP", "dependencies": { "com.unity.render-pipelines.universal": "10.7.0",