Browse Source

Changed atomic counter from a temporary RT to a permanent one, and set it to 0 only on the first frame. Potential fix for auto-exposure on MacOS.

mac-autoexp
Nico de Poel 3 years ago
parent
commit
63d6fd3203
  1. 8
      Assets/Scripts/Core/Fsr2Context.cs
  2. 5
      Assets/Scripts/Core/Fsr2Pipeline.cs
  3. 5
      Assets/Scripts/Core/Fsr2Resources.cs

8
Assets/Scripts/Core/Fsr2Context.cs

@ -150,6 +150,10 @@ namespace FidelityFX
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[1]); commandBuffer.SetRenderTarget(_resources.LockStatus[1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear); commandBuffer.ClearRenderTarget(false, true, Color.clear);
// Reset atomic counter to 0
commandBuffer.SetRenderTarget(_resources.SpdAtomicCounter);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
} }
int frameIndex = _resourceFrameIndex % 2; int frameIndex = _resourceFrameIndex % 2;
@ -207,10 +211,6 @@ namespace FidelityFX
commandBuffer.ClearRenderTarget(false, true, new Color(-1f, 1e8f, 0f, 0f)); commandBuffer.ClearRenderTarget(false, true, new Color(-1f, 1e8f, 0f, 0f));
} }
// Reset atomic counter to 0
commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavSpdAtomicCount);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
// Auto exposure // Auto exposure
SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount); SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount);

5
Assets/Scripts/Core/Fsr2Pipeline.cs

@ -66,9 +66,6 @@ namespace FidelityFX
// Set up shared aliasable resources, i.e. temporary render textures // Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between passes // These do not need to persist between frames, but they do need to be available between passes
// Resource FSR2_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavSpdAtomicCount, 1, 1, 0, default, GraphicsFormat.R32_UInt, 1, true);
// FSR2_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE // FSR2_ReconstructedPrevNearestDepth: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true); commandBuffer.GetTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth, maxRenderSize.x, maxRenderSize.y, 0, default, GraphicsFormat.R32_UInt, 1, true);
@ -91,7 +88,6 @@ namespace FidelityFX
public static void UnregisterResources(CommandBuffer commandBuffer) public static void UnregisterResources(CommandBuffer commandBuffer)
{ {
// Release all of the aliasable resources used this frame // Release all of the aliasable resources used this frame
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavSpdAtomicCount);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth); commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavDilatedDepth);
commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma); commandBuffer.ReleaseTemporaryRT(Fsr2ShaderIDs.UavLockInputLuma);
@ -175,6 +171,7 @@ namespace FidelityFX
if (dispatchParams.Color.HasValue) if (dispatchParams.Color.HasValue)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, dispatchParams.Color.Value, 0, RenderTextureSubElement.Color);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavSpdAtomicCount, Resources.SpdAtomicCounter);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMipLumaChange, Resources.SceneLuminance, ShadingChangeMipLevel);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure); commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure);

5
Assets/Scripts/Core/Fsr2Resources.cs

@ -34,6 +34,7 @@ namespace FidelityFX
public Texture2D DefaultReactive; public Texture2D DefaultReactive;
public Texture2D LanczosLut; public Texture2D LanczosLut;
public Texture2D MaximumBiasLut; public Texture2D MaximumBiasLut;
public RenderTexture SpdAtomicCounter;
public RenderTexture AutoExposure; public RenderTexture AutoExposure;
public RenderTexture SceneLuminance; public RenderTexture SceneLuminance;
public RenderTexture AutoReactive; public RenderTexture AutoReactive;
@ -84,6 +85,10 @@ namespace FidelityFX
DefaultReactive.SetPixel(0, 0, Color.clear); DefaultReactive.SetPixel(0, 0, Color.clear);
DefaultReactive.Apply(); DefaultReactive.Apply();
// Resource FSR2_SpdAtomicCounter: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32_UINT, FFX_RESOURCE_FLAGS_ALIASABLE
SpdAtomicCounter = new RenderTexture(1, 1, 0, GraphicsFormat.R32_UInt) { name = "FSR2_SpdAtomicCounter", enableRandomWrite = true };
SpdAtomicCounter.Create();
// Resource FSR2_AutoExposure: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE // Resource FSR2_AutoExposure: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R32G32_FLOAT, FFX_RESOURCE_FLAGS_NONE
AutoExposure = new RenderTexture(1, 1, 0, GraphicsFormat.R32G32_SFloat) { name = "FSR2_AutoExposure", enableRandomWrite = true }; AutoExposure = new RenderTexture(1, 1, 0, GraphicsFormat.R32G32_SFloat) { name = "FSR2_AutoExposure", enableRandomWrite = true };
AutoExposure.Create(); AutoExposure.Create();

Loading…
Cancel
Save