Browse Source

Updated fragment shader passes to provide their output render targets to the Blit function, including multi-render targets

asr-console
Nico de Poel 11 months ago
parent
commit
a0eeda1e84
  1. 63
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs

63
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs

@ -21,6 +21,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
@ -99,25 +100,33 @@ namespace ArmASR
_sampler = CustomSampler.Create(passName);
}
protected void BlitFragment(CommandBuffer commandBuffer, params RenderTargetIdentifier[] renderTargets)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void BlitFragment(CommandBuffer commandBuffer, RenderTargetIdentifier renderTarget)
{
commandBuffer.SetRenderTarget(renderTarget);
BlitFragment(commandBuffer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void BlitFragment(CommandBuffer commandBuffer, RenderTargetIdentifier[] renderTargets)
{
if (renderTargets == null || renderTargets.Length == 0)
commandBuffer.SetRenderTarget(BuiltinRenderTextureType.None);
else if (renderTargets.Length == 1)
commandBuffer.SetRenderTarget(renderTargets[0]);
else
commandBuffer.SetRenderTarget(renderTargets, BuiltinRenderTextureType.None);
BlitFragment(commandBuffer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void BlitFragment(CommandBuffer commandBuffer)
{
commandBuffer.DrawProcedural(Matrix4x4.identity, FragmentMaterial, FragmentPass, MeshTopology.Triangles, 3, 1, FragmentProperties);
}
[Conditional("ENABLE_PROFILER")]
[Conditional("ENABLE_PROFILER"), MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void BeginSample(CommandBuffer cmd)
{
cmd.BeginSample(_sampler);
}
[Conditional("ENABLE_PROFILER")]
[Conditional("ENABLE_PROFILER"), MethodImpl(MethodImplOptions.AggressiveInlining)]
protected void EndSample(CommandBuffer cmd)
{
cmd.EndSample(_sampler);
@ -167,16 +176,15 @@ namespace ArmASR
commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputMotionVectors, dispatchParams.MotionVectors);
commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputExposure, dispatchParams.Exposure);
// TODO: this actually needs to be the render target
commandBuffer.SetGlobalTexture(AsrShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride);
BlitFragment(commandBuffer);
BlitFragment(commandBuffer, Resources.DilatedMotionVectors[frameIndex]);
}
}
internal class AsrDepthClipPass : AsrPass
{
private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[2];
public AsrDepthClipPass(Asr.ContextDescription contextDescription, AsrResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
@ -197,8 +205,11 @@ 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
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride);
BlitFragment(commandBuffer);
BlitFragment(commandBuffer, _mrt);
}
}
@ -221,6 +232,8 @@ namespace ArmASR
internal class AsrAccumulatePass : AsrPass
{
private readonly RenderTargetIdentifier[] _mrt = new RenderTargetIdentifier[4];
public AsrAccumulatePass(Asr.ContextDescription contextDescription, AsrResources resources, ComputeBuffer constants)
: base(contextDescription, resources, constants)
{
@ -250,16 +263,14 @@ namespace ArmASR
commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvAutoExposure, Resources.AutoExposure);
commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvLumaHistory, Resources.LumaHistory[frameIndex ^ 1]);
// TODO: these need to be multi-render targets (and also vary depending on the ASR preset used)
commandBuffer.SetGlobalTexture(AsrShaderIDs.UavInternalUpscaled, Resources.InternalUpscaled[frameIndex]);
commandBuffer.SetGlobalTexture(AsrShaderIDs.UavLockStatus, Resources.LockStatus[frameIndex]);
commandBuffer.SetGlobalTexture(AsrShaderIDs.UavLumaHistory, Resources.LumaHistory[frameIndex]);
// TODO: this actually needs to be the render target
commandBuffer.SetGlobalResource(AsrShaderIDs.UavUpscaledOutput, dispatchParams.Output);
// TODO: these need to vary depending on the ASR preset used (below is for Quality preset)
_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;
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride);
BlitFragment(commandBuffer);
BlitFragment(commandBuffer, _mrt);
}
}
@ -280,12 +291,9 @@ namespace ArmASR
commandBuffer.SetGlobalResource(AsrShaderIDs.SrvInputExposure, dispatchParams.Exposure);
commandBuffer.SetGlobalTexture(AsrShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]);
// TODO: this actually needs to be the render target
commandBuffer.SetGlobalResource(AsrShaderIDs.UavUpscaledOutput, dispatchParams.Output);
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbFsr2, Constants, 0, Constants.stride);
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbRcas, _rcasConstants, 0, _rcasConstants.stride);
BlitFragment(commandBuffer);
BlitFragment(commandBuffer, dispatchParams.Output.RenderTarget);
}
}
@ -312,11 +320,8 @@ namespace ArmASR
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, AsrShaderIDs.SrvOpaqueOnly, dispatchParams.ColorOpaqueOnly);
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, AsrShaderIDs.SrvInputColor, dispatchParams.ColorPreUpscale);
// TODO: this actually needs to be the render target
commandBuffer.SetComputeResourceParam(ComputeShader, KernelIndex, AsrShaderIDs.UavAutoReactive, dispatchParams.OutReactive);
FragmentProperties.SetConstantBuffer(AsrShaderIDs.CbGenReactive, _generateReactiveConstants, 0, _generateReactiveConstants.stride);
BlitFragment(commandBuffer);
BlitFragment(commandBuffer, dispatchParams.OutReactive.RenderTarget);
EndSample(commandBuffer);
}

Loading…
Cancel
Save