From 16f529bce875ee00549728c463c4692ef66ce6b5 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 21 Feb 2023 13:29:31 +0100 Subject: [PATCH] Made shading change mip level into a reusable const value, and fixed mip sizes for exposure RTs. Actually tested the output of the luminance pyramid shader now and it seems to be working. --- Assets/Scripts/Fsr2Context.cs | 6 ++---- Assets/Scripts/Fsr2Pipeline.cs | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs index d034653..bab4943 100644 --- a/Assets/Scripts/Fsr2Context.cs +++ b/Assets/Scripts/Fsr2Context.cs @@ -160,7 +160,7 @@ namespace FidelityFX bool resetAccumulation = dispatchParams.Reset || _firstExecution; _firstExecution = false; - // TODO Register resources: ... + Fsr2Pipeline.RegisterResources(_commandBuffer, dispatchParams); SetupConstants(dispatchParams, resetAccumulation); @@ -184,8 +184,6 @@ namespace FidelityFX _fsr2ConstantsBuffer.SetData(_fsr2ConstantsArray); _spdConstantsBuffer.SetData(_spdConstantsArray); - Fsr2Pipeline.RegisterResources(_commandBuffer, dispatchParams); - // Compute luminance pyramid _computeLuminancePyramidPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y); @@ -288,7 +286,7 @@ namespace FidelityFX constants.frameIndex++; // Shading change usage of the SPD mip levels - constants.lumaMipLevelToUse = 4; // NOTE: this is derived from a bunch of auto-generated constant values in the FSR2 code + constants.lumaMipLevelToUse = Fsr2Pipeline.ShadingChangeMipLevel; float mipDiv = 2 << constants.lumaMipLevelToUse; constants.lumaMipDimensions.x = (int)(constants.maxRenderSize.x / mipDiv); diff --git a/Assets/Scripts/Fsr2Pipeline.cs b/Assets/Scripts/Fsr2Pipeline.cs index 8c1818b..cb11716 100644 --- a/Assets/Scripts/Fsr2Pipeline.cs +++ b/Assets/Scripts/Fsr2Pipeline.cs @@ -8,6 +8,8 @@ namespace FidelityFX { internal abstract class Fsr2Pipeline: IDisposable { + internal const int ShadingChangeMipLevel = 4; // Corresponds to FFX_FSR2_SHADING_CHANGE_MIP_LEVEL define + private readonly Fsr2Callbacks _callbacks; protected readonly ComputeBuffer Constants; @@ -57,8 +59,8 @@ namespace FidelityFX commandBuffer.GetTemporaryRT(UavSpdAtomicCount, 1, 1, 0, FilterMode.Point, GraphicsFormat.R32_UInt, 1, true); // Resource FSR2_ExposureMips: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R16_FLOAT, FFX_RESOURCE_FLAGS_ALIASABLE, has mipmap chain - commandBuffer.GetTemporaryRT(UavExposureMipLumaChange, dispatchParams.RenderSize.x >> 4, dispatchParams.RenderSize.y >> 4, 0, FilterMode.Point, GraphicsFormat.R16_SFloat, 1, true); - commandBuffer.GetTemporaryRT(UavExposureMip5, dispatchParams.RenderSize.x >> 5, dispatchParams.RenderSize.y >> 5, 0, FilterMode.Point, GraphicsFormat.R16_SFloat, 1, true); + commandBuffer.GetTemporaryRT(UavExposureMipLumaChange, dispatchParams.RenderSize.x >> (ShadingChangeMipLevel + 1), dispatchParams.RenderSize.y >> (ShadingChangeMipLevel + 1), 0, FilterMode.Point, GraphicsFormat.R16_SFloat, 1, true); + commandBuffer.GetTemporaryRT(UavExposureMip5, dispatchParams.RenderSize.x >> 6, dispatchParams.RenderSize.y >> 6, 0, FilterMode.Point, GraphicsFormat.R16_SFloat, 1, true); } public static void UnregisterResources(CommandBuffer commandBuffer)