From cff3b036b23251d71265786c72228045386aa041 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 5 Jun 2020 14:04:24 +0200 Subject: [PATCH 1/4] Use a fixed size for xr related fields in cbuffers --- .../Runtime/ShaderConfig.cs | 3 + .../Runtime/Lighting/LightLoop/LightLoop.cs | 16 +++--- .../VolumetricLighting/VolumetricLighting.cs | 4 +- .../ShaderLibrary/ShaderVariablesXR.cs | 56 +++++++++---------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs index 6d773ae079c..dd3ff265869 100644 --- a/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs +++ b/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs @@ -60,6 +60,9 @@ public enum ShaderOptions // Changing a value in this enum Config here require to regenerate the hlsl include and recompile C# and shaders public class ShaderConfig { + public const int k_XRMaxViewsForCBuffer = 2; // REALLY IMPORTANT! This needs to be the maximum possible XrMaxViews for any supported platform! + // this needs to be constant and not vary like XrMaxViews does as it is used to generate the cbuffer declarations + public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering; public static int s_PreExposition = (int)ShaderOptions.PreExposition; public static int s_XrMaxViews = (int)ShaderOptions.XrMaxViews; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs index 84890509e9f..0047970d137 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/LightLoop.cs @@ -217,14 +217,14 @@ public enum TileClusterCategoryDebug : int [GenerateHLSL(needAccessors = false, generateCBuffer = true)] unsafe struct ShaderVariablesLightList { - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float g_mInvScrProjectionArr[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float g_mScrProjectionArr[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float g_mInvProjectionArr[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float g_mProjectionArr[(int)ShaderOptions.XrMaxViews * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float g_mInvScrProjectionArr[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float g_mScrProjectionArr[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float g_mInvProjectionArr[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float g_mProjectionArr[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; public Vector4 g_screenSize; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs index 7c3280d4d4f..6180f149bf1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/VolumetricLighting/VolumetricLighting.cs @@ -43,8 +43,8 @@ public static DensityVolumeEngineData GetNeutralValues() [GenerateHLSL(needAccessors = false, generateCBuffer = true)] unsafe struct ShaderVariablesVolumetric { - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _VBufferCoordToViewDirWS[(int)ShaderOptions.XrMaxViews * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _VBufferCoordToViewDirWS[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; public float _VBufferUnitDepthTexelSpacing; public uint _NumVisibleDensityVolumes; diff --git a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesXR.cs b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesXR.cs index 6898a2fbcc3..a7c25738f1f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesXR.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariablesXR.cs @@ -4,35 +4,35 @@ namespace UnityEngine.Rendering.HighDefinition [GenerateHLSL(needAccessors = false, generateCBuffer = true, constantRegister = (int)ConstantRegister.XR)] unsafe struct ShaderVariablesXR { - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRViewMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRInvViewMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRInvProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRViewProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRInvViewProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRNonJitteredViewProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRPrevViewProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRPrevInvViewProjMatrix[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRPrevViewProjMatrixNoCameraTrans[(int)ShaderOptions.XrMaxViews * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Matrix4x4))] - public fixed float _XRPixelCoordToViewDirWS[(int)ShaderOptions.XrMaxViews * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRViewMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRInvViewMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRInvProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRViewProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRInvViewProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRNonJitteredViewProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRPrevViewProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRPrevInvViewProjMatrix[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRPrevViewProjMatrixNoCameraTrans[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Matrix4x4))] + public fixed float _XRPixelCoordToViewDirWS[ShaderConfig.k_XRMaxViewsForCBuffer * 16]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Vector4))] - public fixed float _XRWorldSpaceCameraPos[(int)ShaderOptions.XrMaxViews * 4]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Vector4))] - public fixed float _XRWorldSpaceCameraPosViewOffset[(int)ShaderOptions.XrMaxViews * 4]; - [HLSLArray((int)ShaderOptions.XrMaxViews, typeof(Vector4))] - public fixed float _XRPrevWorldSpaceCameraPos[(int)ShaderOptions.XrMaxViews * 4]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Vector4))] + public fixed float _XRWorldSpaceCameraPos[ShaderConfig.k_XRMaxViewsForCBuffer * 4]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Vector4))] + public fixed float _XRWorldSpaceCameraPosViewOffset[ShaderConfig.k_XRMaxViewsForCBuffer * 4]; + [HLSLArray(ShaderConfig.k_XRMaxViewsForCBuffer, typeof(Vector4))] + public fixed float _XRPrevWorldSpaceCameraPos[ShaderConfig.k_XRMaxViewsForCBuffer * 4]; } } From 2d8e5e7d2e8610de4d608518682b3b2b17316d58 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Fri, 5 Jun 2020 14:06:11 +0200 Subject: [PATCH 2/4] changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 2a070512c52..0845360e249 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -637,7 +637,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed a vulkan and metal warning in the SSGI compute shader. - Fixed an exception due to the color pyramid not allocated when SSGI is enabled. - Fixed an issue with the first Depth history was incorrectly copied. -- Fixed path traced DoF focusing issue +- Fixed path traced DoF focusing issue. +- Fixed issue with rendering being mostly broken when target platform disables VR. ### Changed - Improve MIP selection for decals on Transparents From 1ddbc6c3419d3351a92faad3d5a2971af636123b Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Mon, 8 Jun 2020 11:12:25 +0200 Subject: [PATCH 3/4] Update local shader config --- .../Runtime/ShaderConfig.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs b/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs index 697159b4b37..22ae4a9b21d 100644 --- a/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs +++ b/TestProjects/HDRP_DXR_Tests/LocalPackages/com.unity.render-pipelines.high-definition-config/Runtime/ShaderConfig.cs @@ -58,6 +58,9 @@ public enum ShaderOptions // Changing a value in this enum Config here require to regenerate the hlsl include and recompile C# and shaders public class ShaderConfig { + public const int k_XRMaxViewsForCBuffer = 2; // REALLY IMPORTANT! This needs to be the maximum possible XrMaxViews for any supported platform! + // this needs to be constant and not vary like XrMaxViews does as it is used to generate the cbuffer declarations + public static int s_CameraRelativeRendering = (int)ShaderOptions.CameraRelativeRendering; public static int s_PreExposition = (int)ShaderOptions.PreExposition; public static int s_XrMaxViews = (int)ShaderOptions.XrMaxViews; From a01eb77f682f3d02277cfabb2a38d66583a1ac98 Mon Sep 17 00:00:00 2001 From: sebastienlagarde Date: Mon, 8 Jun 2020 12:04:53 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 48ec3aa5883..dbc12ca2418 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -648,7 +648,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed path traced DoF focusing issue - Fix an issue with the half resolution Mode (performance) - Fix an issue with the color intensity of emissive for performance rtgi -- Fixed path traced DoF focusing issue. - Fixed issue with rendering being mostly broken when target platform disables VR. ### Changed