diff --git a/.gitignore b/.gitignore index b331511..ebfe867 100644 --- a/.gitignore +++ b/.gitignore @@ -57,4 +57,5 @@ crashlytics-build.properties TJURP_BurstDebugInformation_DoNotShip/ UserSettings/ -**/.DS_Store \ No newline at end of file +**/.DS_Store +out/ \ No newline at end of file diff --git a/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib b/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib index 44b5642..902a340 100755 Binary files a/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib and b/Assets/Plugins/Mac/libGfxPluginNativeRender.dylib differ diff --git a/Assets/Settings/Mobile/Mobile_High.asset b/Assets/Settings/Mobile/Mobile_High.asset index 4a51dd0..89c8ffa 100644 --- a/Assets/Settings/Mobile/Mobile_High.asset +++ b/Assets/Settings/Mobile/Mobile_High.asset @@ -28,7 +28,7 @@ MonoBehaviour: m_SupportsHDR: 1 m_HDRColorBufferPrecision: 0 m_MSAA: 1 - m_RenderScale: 0.8333333 + m_RenderScale: 0.58823526 m_UpscalingFilter: 0 m_FsrOverrideSharpness: 1 m_FsrSharpness: 1 @@ -85,7 +85,7 @@ MonoBehaviour: blueNoise64LTex: {fileID: 2800000, guid: e3d24661c1e055f45a7560c033dbb837, type: 3} bayerMatrixTex: {fileID: 2800000, guid: f9ee4ed84c1d10c49aabb9b210b0fc44, type: 3} m_PrefilteringModeMainLightShadows: 3 - m_PrefilteringModeAdditionalLight: 4 + m_PrefilteringModeAdditionalLight: 2 m_PrefilteringModeAdditionalLightShadows: 0 m_PrefilterXRKeywords: 1 m_PrefilteringModeForwardPlus: 1 @@ -96,12 +96,12 @@ MonoBehaviour: m_PrefilterHDROutput: 1 m_PrefilterSSAODepthNormals: 1 m_PrefilterSSAOSourceDepthLow: 1 - m_PrefilterSSAOSourceDepthMedium: 0 + m_PrefilterSSAOSourceDepthMedium: 1 m_PrefilterSSAOSourceDepthHigh: 1 - m_PrefilterSSAOInterleaved: 0 + m_PrefilterSSAOInterleaved: 1 m_PrefilterSSAOBlueNoise: 1 m_PrefilterSSAOSampleCountLow: 1 - m_PrefilterSSAOSampleCountMedium: 0 + m_PrefilterSSAOSampleCountMedium: 1 m_PrefilterSSAOSampleCountHigh: 1 m_PrefilterDBufferMRT1: 1 m_PrefilterDBufferMRT2: 1 diff --git a/Assets/Settings/Mobile/Mobile_High_Renderer.asset b/Assets/Settings/Mobile/Mobile_High_Renderer.asset index 6c3cdba..d2f9162 100644 --- a/Assets/Settings/Mobile/Mobile_High_Renderer.asset +++ b/Assets/Settings/Mobile/Mobile_High_Renderer.asset @@ -259,4 +259,4 @@ MonoBehaviour: m_Name: MetalFxSpatialUpScale m_EditorClassIdentifier: m_Active: 1 - quality: 2 + quality: 4 diff --git a/NativeRenderPlugin/RenderAPI_Metal.mm b/NativeRenderPlugin/RenderAPI_Metal.mm index 445af39..170e070 100644 --- a/NativeRenderPlugin/RenderAPI_Metal.mm +++ b/NativeRenderPlugin/RenderAPI_Metal.mm @@ -57,7 +57,7 @@ void RenderAPI_Metal::processDeviceEvent(UnityGfxDeviceEventType type, IUnityInt } void RenderAPI_Metal::initSupportFeature() { - if (@available(iOS 16.0, macOS 13.0, *)) + if (@available(iOS 16, macOS 13, *)) { support_features[GraphicsFeature::METAL_FX_SPATIAL_SR] = true; support_features[GraphicsFeature::METAL_FX_TEMPORAL_SR] = true; @@ -66,12 +66,13 @@ void RenderAPI_Metal::initSupportFeature() void RenderAPI_Metal::spatialUpScale(void* data) { - if (@available(iOS 16.0, macOS 13.0, *)) + if (@available(iOS 16, macOS 13, *)) { struct DataPack { void* src; void* dst; + bool qulityChange; }; DataPack* data_pack = static_cast(data); @@ -80,10 +81,10 @@ void RenderAPI_Metal::spatialUpScale(void* data) id _device = metal_graphics->MetalDevice(); id cmd = (id)metal_graphics->CurrentCommandBuffer(); - + // metal_graphics->EndCurrentCommandEncoder(); cmd.label = @"Upscale Command Buffer"; - if (mfx_spatial_scaler == nil) + if (mfx_spatial_scaler == nil || data_pack->qulityChange) { MTLFXSpatialScalerDescriptor* desc = [[MTLFXSpatialScalerDescriptor alloc]init]; desc.inputWidth = [srctex width]; @@ -101,11 +102,23 @@ void RenderAPI_Metal::spatialUpScale(void* data) return; } } - mfx_spatial_scaler.colorTexture = srctex; mfx_spatial_scaler.outputTexture = dsttex; - [mfx_spatial_scaler encodeToCommandBuffer:cmd]; - [cmd commit]; + // if(!cmd) + { + id _commandQueue = [_device newCommandQueue]; + id upscaleCommandBuffer = [_commandQueue commandBuffer]; + upscaleCommandBuffer.label = @"Upscale Command Buffer"; + + [mfx_spatial_scaler encodeToCommandBuffer:upscaleCommandBuffer]; + [upscaleCommandBuffer commit]; + } + // else + { + // [mfx_spatial_scaler encodeToCommandBuffer:cmd]; + // [cmd commit]; + } + } } diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs index f515fba..b87f71d 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/Passes/PostProcessPass.cs @@ -504,10 +504,10 @@ namespace UnityEngine.Rendering.Universal ref var colorDescriptor = ref cameraData.cameraTargetDescriptor; colorDescriptor.width = cameraData.camera.pixelWidth; colorDescriptor.height = cameraData.camera.pixelHeight; - if (asset.SuperResolution == ESuperResolution.XESS13 || asset.SuperResolution == ESuperResolution.GSR2) + //if (asset.SuperResolution == ESuperResolution.XESS13 || asset.SuperResolution == ESuperResolution.GSR2) { colorDescriptor.graphicsFormat = GraphicsFormat.R16G16B16A16_SFloat; - colorDescriptor.enableRandomWrite = true; // compute + colorDescriptor.enableRandomWrite = true; // } renderer.m_ColorBufferSystem.SetCameraSettings(colorDescriptor, FilterMode.Bilinear); diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs index 660bf90..2440d49 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/MetalFx.cs @@ -15,10 +15,13 @@ namespace X.Rendering.Feature SrQuality quality; private ProfilingSampler profiler; + SrQuality lastQuality; + bool updateSrNextFrame = false; struct DataPack { public IntPtr src; public IntPtr dst; + public bool qulityChange; }; IntPtr dataPtr; public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) @@ -39,11 +42,28 @@ namespace X.Rendering.Feature public void DoSR(CommandBuffer cmd, RTHandle source, RTHandle destination, RTHandle motionVector, ref RenderingData renderingData) { + if (source.rt == null || destination.rt == null) + { + return; + } + using var scp = new ProfilingScope(cmd, profiler); DataPack * ptr = (DataPack*) dataPtr.ToPointer(); ptr->src = source.rt.GetNativeTexturePtr(); ptr->dst = destination.rt.GetNativeTexturePtr(); - cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.UpdateXESS1Config, dataPtr); + ptr->qulityChange = updateSrNextFrame; + if(updateSrNextFrame) + { + updateSrNextFrame = false; + } + if (lastQuality != quality) + { + updateSrNextFrame = true; + UniversalRenderPipeline.asset.renderScale = GetRenderScale(); + lastQuality = quality; + } + + cmd.IssuePluginEventAndData(RenderingPlugin.GetRenderEventAndDataFunc(), (int)RenderingPlugin.NativeRenderingEvent.SpatialUpScale, dataPtr); } public float GetRenderScale() diff --git a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs index aa119d5..ad577df 100644 --- a/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs +++ b/Packages/com.unity.render-pipelines.universal@14.0.11/Runtime/SuperRendering/SR/Scripts/XESS.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.InteropServices; -using UnityEditor.VersionControl; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 8ab20e1..23b83af 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -266,6 +266,7 @@ PlayerSettings: - {fileID: 0} - {fileID: 0} - {fileID: 0} + - {fileID: 11400000, guid: 9e7be553448fa2546aea5752021cbcf7, type: 2} metroInputSource: 0 wsaTransparentSwapchain: 0 m_HolographicPauseOnTrackingLoss: 1