Browse Source

Use RenderTargetIdentifier magic to bind UAV outputs to SRV inputs, making obsolete the monkey patching of shaders.

Also reorganized the SRV/UAV names to match the ordering from the FSR2 source.
mac-autoexp
Nico de Poel 3 years ago
parent
commit
54849cee0f
  1. 4
      Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute
  2. 4
      Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute
  3. 3
      Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute
  4. 38
      Assets/Scripts/Fsr2Pipeline.cs

4
Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute

@ -17,8 +17,4 @@
#define FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE 1
#endif
// Monkey-patch SRV names to match the UAV names from the shaders that output them
#define r_dilated_reactive_masks rw_dilated_reactive_masks
#define r_prepared_input_color rw_prepared_input_color
#include "shaders/ffx_fsr2_accumulate_pass.hlsl"

4
Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute

@ -11,8 +11,4 @@
#define FFX_GPU // Compiling for GPU
#define FFX_HLSL // Compile for plain HLSL
// Monkey-patch SRV names to match the UAV names from the shaders that output them
#define r_reconstructed_previous_nearest_depth rw_reconstructed_previous_nearest_depth
#define r_dilatedDepth rw_dilatedDepth
#include "shaders/ffx_fsr2_depth_clip_pass.hlsl"

3
Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute

@ -11,7 +11,4 @@
#define FFX_GPU // Compiling for GPU
#define FFX_HLSL // Compile for plain HLSL
// Monkey-patch SRV names to match the UAV names from the shaders that output them
#define r_lock_input_luma rw_lock_input_luma
#include "shaders/ffx_fsr2_lock_pass.hlsl"

38
Assets/Scripts/Fsr2Pipeline.cs

@ -28,35 +28,40 @@ namespace FidelityFX
internal static readonly int SrvInputMotionVectors = Shader.PropertyToID("r_input_motion_vectors");
internal static readonly int SrvInputDepth = Shader.PropertyToID("r_input_depth");
internal static readonly int SrvInputExposure = Shader.PropertyToID("r_input_exposure");
internal static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors");
internal static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure");
internal static readonly int SrvReactiveMask = Shader.PropertyToID("r_reactive_mask");
internal static readonly int SrvTransparencyAndCompositionMask = Shader.PropertyToID("r_transparency_and_composition_mask");
internal static readonly int SrvReconstructedPrevNearestDepth = Shader.PropertyToID("r_reconstructed_previous_nearest_depth");
internal static readonly int SrvDilatedMotionVectors = Shader.PropertyToID("r_dilated_motion_vectors");
internal static readonly int SrvPrevDilatedMotionVectors = Shader.PropertyToID("r_previous_dilated_motion_vectors");
internal static readonly int SrvDilatedDepth = Shader.PropertyToID("r_dilatedDepth");
internal static readonly int SrvInternalUpscaled = Shader.PropertyToID("r_internal_upscaled_color");
internal static readonly int SrvLockStatus = Shader.PropertyToID("r_lock_status");
internal static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut");
internal static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut");
internal static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips");
internal static readonly int SrvAutoExposure = Shader.PropertyToID("r_auto_exposure");
internal static readonly int SrvLockInputLuma = Shader.PropertyToID("r_lock_input_luma");
internal static readonly int SrvPreparedInputColor = Shader.PropertyToID("r_prepared_input_color");
internal static readonly int SrvLumaHistory = Shader.PropertyToID("r_luma_history");
internal static readonly int SrvRcasInput = Shader.PropertyToID("r_rcas_input");
internal static readonly int SrvLanczosLut = Shader.PropertyToID("r_lanczos_lut");
internal static readonly int SrvSceneLuminanceMips = Shader.PropertyToID("r_imgMips");
internal static readonly int SrvUpscaleMaximumBiasLut = Shader.PropertyToID("r_upsample_maximum_bias_lut");
internal static readonly int SrvDilatedReactiveMasks = Shader.PropertyToID("r_dilated_reactive_masks");
// Unordered access views, i.e. random read/write bindings
internal static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output");
internal static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change");
internal static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5");
internal static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure");
internal static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic");
internal static readonly int UavReconstructedPrevNearestDepth = Shader.PropertyToID("rw_reconstructed_previous_nearest_depth");
internal static readonly int UavDilatedMotionVectors = Shader.PropertyToID("rw_dilated_motion_vectors");
internal static readonly int UavDilatedDepth = Shader.PropertyToID("rw_dilatedDepth");
internal static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma");
internal static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks");
internal static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color");
internal static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks");
internal static readonly int UavInternalUpscaled = Shader.PropertyToID("rw_internal_upscaled_color");
internal static readonly int UavLockStatus = Shader.PropertyToID("rw_lock_status");
internal static readonly int UavLockInputLuma = Shader.PropertyToID("rw_lock_input_luma");
internal static readonly int UavNewLocks = Shader.PropertyToID("rw_new_locks");
internal static readonly int UavPreparedInputColor = Shader.PropertyToID("rw_prepared_input_color");
internal static readonly int UavLumaHistory = Shader.PropertyToID("rw_luma_history");
internal static readonly int UavUpscaledOutput = Shader.PropertyToID("rw_upscaled_output");
internal static readonly int UavExposureMipLumaChange = Shader.PropertyToID("rw_img_mip_shading_change");
internal static readonly int UavExposureMip5 = Shader.PropertyToID("rw_img_mip_5");
internal static readonly int UavDilatedReactiveMasks = Shader.PropertyToID("rw_dilated_reactive_masks");
internal static readonly int UavAutoExposure = Shader.PropertyToID("rw_auto_exposure");
internal static readonly int UavSpdAtomicCount = Shader.PropertyToID("rw_spd_global_atomic");
internal static readonly int UavAutoReactive = Shader.PropertyToID("rw_output_autoreactive");
// Constant buffer bindings
@ -255,7 +260,9 @@ namespace FidelityFX
if (dispatchParams.Reactive.HasValue)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvReactiveMask, dispatchParams.Reactive.Value);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvReconstructedPrevNearestDepth, UavReconstructedPrevNearestDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvDilatedDepth, UavDilatedDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvTransparencyAndCompositionMask, Resources.DefaultReactive); // Default reactive mask, as we don't support TCR (yet)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]);
@ -275,6 +282,7 @@ namespace FidelityFX
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvLockInputLuma, UavLockInputLuma);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
@ -302,8 +310,10 @@ namespace FidelityFX
if (dispatchParams.Exposure.HasValue)
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInputExposure, dispatchParams.Exposure.Value);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvDilatedReactiveMasks, UavDilatedReactiveMasks);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvLockStatus, Resources.LockStatus[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvPreparedInputColor, UavPreparedInputColor);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvLanczosLut, Resources.LanczosLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvUpscaleMaximumBiasLut, Resources.MaximumBiasLut);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, SrvSceneLuminanceMips, Resources.SceneLuminance);

Loading…
Cancel
Save