diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs index 1424b56..1ef2b01 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs @@ -130,12 +130,16 @@ namespace ArmASR _keywords.ApplyKeywords(commandBuffer, _contextDescription.Variant, _contextDescription.Flags, dispatchParams); + AsrResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); + if (_firstExecution) { commandBuffer.SetRenderTarget(_resources.LockStatus[0]); commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.SetRenderTarget(_resources.LockStatus[1]); commandBuffer.ClearRenderTarget(false, true, Color.clear); + commandBuffer.SetRenderTarget(AsrShaderIDs.UavPreparedInputColor); + commandBuffer.ClearRenderTarget(false, true, Color.clear); } int frameIndex = _resourceFrameIndex % 2; @@ -150,7 +154,6 @@ namespace ArmASR if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); - AsrResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -158,6 +161,10 @@ namespace ArmASR const int threadGroupWorkRegionDim = 8; int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; + + bool applyPerfModeOptimizations = _contextDescription.Variant == Asr.Variant.Performance; + bool applyBalancedModeOptimizations = _contextDescription.Variant == Asr.Variant.Balanced; + bool isBalancedOrPerformance = applyBalancedModeOptimizations || applyPerfModeOptimizations; // Clear reconstructed depth for max depth store if (resetAccumulation) @@ -167,6 +174,12 @@ namespace ArmASR commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]); commandBuffer.ClearRenderTarget(false, true, Color.clear); + + if (isBalancedOrPerformance) + { + commandBuffer.SetRenderTarget(_resources.InternalReactive[frameIndex ^ 1]); + commandBuffer.ClearRenderTarget(false, true, Color.clear); + } commandBuffer.SetRenderTarget(_resources.SceneLuminance); commandBuffer.ClearRenderTarget(false, true, Color.clear); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs index 0fc44f2..ba503ee 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs @@ -34,7 +34,7 @@ namespace ArmASR /// internal abstract class AsrPass: IDisposable { - internal const int ShadingChangeMipLevel = 4; // This matches the FFXM_FSR2_SHADING_CHANGE_MIP_LEVEL define // TODO: still relevant? + internal const int ShadingChangeMipLevel = 4; // This matches the FFXM_FSR2_SHADING_CHANGE_MIP_LEVEL define protected readonly Asr.ContextDescription ContextDescription; protected readonly AsrResources Resources; @@ -162,6 +162,8 @@ namespace ArmASR internal class AsrReconstructPreviousDepthPass : AsrPass { + private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[3]; + public AsrReconstructPreviousDepthPass(Asr.ContextDescription contextDescription, AsrResources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) { @@ -175,8 +177,15 @@ namespace ArmASR commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors); commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputExposure, dispatchParams.Exposure); + // TODO UAVs in fragment shaders? That seems like it might be a problem... + commandBuffer.SetGlobalTexture(AsrShaderIDs.UavReconstructedPrevNearestDepth, AsrShaderIDs.UavReconstructedPrevNearestDepth); + + _mrt[0] = AsrShaderIDs.RtDilatedDepth; // fDepth + _mrt[1] = Resources.DilatedMotionVectors[frameIndex]; // fMotionVector + _mrt[2] = AsrShaderIDs.RtLockInputLuma; // fLuma + FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); - BlitFragment(commandBuffer, Resources.DilatedMotionVectors[frameIndex]); + BlitFragment(commandBuffer, _mrt); } } @@ -204,8 +213,8 @@ namespace ArmASR commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvDilatedDepth, AsrShaderIDs.UavDilatedDepth); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); - _mrt[0] = AsrShaderIDs.UavDilatedReactiveMasks; - _mrt[1] = BuiltinRenderTextureType.None; // TODO: Tonemapped + _mrt[0] = AsrShaderIDs.RtDilatedReactiveMasks; // fDilatedReactiveMasks + _mrt[1] = AsrShaderIDs.RtPreparedInputColor; // fTonemapped FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); BlitFragment(commandBuffer, _mrt); @@ -223,6 +232,10 @@ namespace ArmASR protected override void DoScheduleDispatch(CommandBuffer commandBuffer, Asr.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) { commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, AsrShaderIDs.SrvLockInputLuma, AsrShaderIDs.UavLockInputLuma); + + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, AsrShaderIDs.UavNewLocks, AsrShaderIDs.UavNewLocks); + commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, AsrShaderIDs.UavReconstructedPrevNearestDepth, AsrShaderIDs.UavReconstructedPrevNearestDepth); + commandBuffer.SetComputeConstantBufferParam(ComputeShader, AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); @@ -261,19 +274,26 @@ namespace ArmASR commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvSceneLuminanceMips, Resources.SceneLuminance); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvAutoExposure, Resources.AutoExposure); commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]); + commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvInternalTemporalReactive, Resources.InternalReactive[frameIndex ^ 1]); + + // TODO UAVs in fragment shaders? That seems like it might be a problem... + commandBuffer.SetGlobalTexture(AsrShaderIDs.UavNewLocks, AsrShaderIDs.UavNewLocks); if (ContextDescription.Variant == Asr.Variant.Quality) { - _mrt[0] = Resources.InternalUpscaled[frameIndex]; // TODO: ColorAndWeight - _mrt[1] = Resources.LockStatus[frameIndex]; - _mrt[2] = Resources.LumaHistory[frameIndex]; - _mrt[3] = dispatchParams.EnableSharpening ? BuiltinRenderTextureType.None : dispatchParams.Output.RenderTarget; + _mrt[0] = Resources.InternalUpscaled[frameIndex]; // fColorAndWeight + _mrt[1] = Resources.LockStatus[frameIndex]; // fLockStatus + _mrt[2] = Resources.LumaHistory[frameIndex]; // fLumaHistory } else { - // TODO: UpscaledColor, TemporalReactive, LockStatus, Color + _mrt[0] = Resources.InternalUpscaled[frameIndex]; // fUpscaledColor + _mrt[1] = Resources.InternalReactive[frameIndex]; // fTemporalReactive + _mrt[2] = Resources.LockStatus[frameIndex]; // fLockStatus } + _mrt[3] = dispatchParams.EnableSharpening ? BuiltinRenderTextureType.None : dispatchParams.Output.RenderTarget; // fColor + FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); BlitFragment(commandBuffer, _mrt); } @@ -325,6 +345,7 @@ namespace ArmASR commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, AsrShaderIDs.SrvOpaqueOnly, dispatchParams.ColorOpaqueOnly); commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, AsrShaderIDs.SrvInputColor, dispatchParams.ColorPreUpscale); + FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride); FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbGenReactive, _generateReactiveConstants, 0, _generateReactiveConstants.stride); BlitFragment(commandBuffer, dispatchParams.OutReactive.RenderTarget); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrResources.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrResources.cs index 5fedade..c2eeb65 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrResources.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrResources.cs @@ -62,7 +62,7 @@ namespace ArmASR maximumBias[i] = MaximumBias[i] / 2.0f; } - GetFormatRequirements(contextDescription, out bool isBalancedOrPerformance, out bool preparedInputColorNeedsFp16, out GraphicsFormat r8Format, out GraphicsFormat r16Format, out GraphicsFormat rg16Format); + GetFormatRequirements(contextDescription, out bool isBalancedOrPerformance, out _, out _, out GraphicsFormat r16Format, out GraphicsFormat rg16Format); // Resource FSR2_LanczosLutData: FFX_RESOURCE_USAGE_READ_ONLY, FFX_SURFACE_FORMAT_R16_SNORM, FFX_RESOURCE_FLAGS_NONE // R16_SNorm textures are not supported by Unity on most platforms, strangely enough. So instead we use R32_SFloat and upload pre-normalized float data. @@ -130,7 +130,7 @@ namespace ArmASR Vector2Int displaySize = contextDescription.DisplaySize; Vector2Int maxRenderSize = contextDescription.MaxRenderSize; - GetFormatRequirements(contextDescription, out bool isBalancedOrPerformance, out bool preparedInputColorNeedsFp16, out GraphicsFormat r8Format, out GraphicsFormat r16Format, out GraphicsFormat rg16Format); + GetFormatRequirements(contextDescription, out _, out bool preparedInputColorNeedsFp16, out GraphicsFormat r8Format, out _, out _); // FSR2_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE commandBuffer.GetTemporaryRT(AsrShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true); diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_lock.h b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_lock.h index b78afdc..1efc9e1 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_lock.h +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_lock.h @@ -125,7 +125,7 @@ void ComputeLock(FfxInt32x2 iPxLrPos) StoreNewLocks(ComputeHrPosFromLrPos(iPxLrPos), 1.f); } - ClearResourcesForNextFrame(iPxLrPos); + //ClearResourcesForNextFrame(iPxLrPos); } #endif // FFXM_FSR2_LOCK_H