diff --git a/com.unity.render-pipelines.core/package.json b/com.unity.render-pipelines.core/package.json index f099f977265..5a7c5b719dd 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": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "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 6e79848860e..1e6bf6d9555 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": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "displayName": "High Definition RP Config", "dependencies": { "com.unity.render-pipelines.core": "12.0.0" diff --git a/com.unity.render-pipelines.high-definition/package.json b/com.unity.render-pipelines.high-definition/package.json index a6f763c3f0f..e8e2d4d448a 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": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "displayName": "High Definition RP", "dependencies": { "com.unity.modules.video": "1.0.0", diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 5812f2b6981..f75694a67fa 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -37,6 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added Lights 2D to the Light Explorer window. - Two new URP specific scene templates, Basic which has a camera and directional light, then Standard which has the addition of a global volume with basic post effects setup. - Added Render Settings Converter to the Render Pipeline Converter, this tool creates and assigns URP Assets based off rendering settings of a Builtin project. +- XR: Added Late Latching support to reduce VR latency (Quest). ### Changed - Moved fog evaluation from vertex shader to pixel shader. This improves rendering of fog for big triangles and fog quality. This can change the look of the fog slightly. diff --git a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs index 390e06b324b..6775c7c8022 100644 --- a/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs +++ b/com.unity.render-pipelines.universal/Runtime/ScriptableRenderer.cs @@ -725,6 +725,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... if (drawGizmos) { @@ -963,6 +968,11 @@ void ExecuteRenderPass(ScriptableRenderContext context, ScriptableRenderPass ren ExecuteNativeRenderPass(context, renderPass, cameraData, ref renderingData); else 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) @@ -1199,6 +1209,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 21055bb6f2f..ee9ea4065fd 100644 --- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs +++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs @@ -543,6 +543,8 @@ static void RenderCameraStack(ScriptableRenderContext context, Camera baseCamera // Helper function for updating cameraData with xrPass Data m_XRSystem.UpdateCameraData(ref baseCameraData, baseCameraData.xr); + + m_XRSystem.BeginLateLatching(baseCamera, xrPass); } #endif @@ -560,6 +562,10 @@ 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 6636ead9367..1b451e894b4 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; } @@ -452,8 +455,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 94eaffb648a..8b566bc918b 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(Camera camera, bool enableXRRendering) { bool xrEnabled = RefreshXrSdk(); diff --git a/com.unity.render-pipelines.universal/package.json b/com.unity.render-pipelines.universal/package.json index c08a7bec62d..29ada9ed20c 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": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "displayName": "Universal RP", "dependencies": { "com.unity.mathematics": "1.2.1", diff --git a/com.unity.shadergraph/package.json b/com.unity.shadergraph/package.json index 8b6be429af4..12d1fdc9bae 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": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "displayName": "Shader Graph", "dependencies": { "com.unity.render-pipelines.core": "12.0.0", diff --git a/com.unity.visualeffectgraph/package.json b/com.unity.visualeffectgraph/package.json index 1981dfc0445..28162876685 100644 --- a/com.unity.visualeffectgraph/package.json +++ b/com.unity.visualeffectgraph/package.json @@ -3,7 +3,7 @@ "displayName": "Visual Effect Graph", "version": "12.0.0", "unity": "2021.2", - "unityRelease": "0a19", + "unityRelease": "0a21", "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",