|
|
|
@ -2,6 +2,7 @@ |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using UnityEngine; |
|
|
|
using UnityEngine.Rendering; |
|
|
|
|
|
|
|
namespace FidelityFX |
|
|
|
{ |
|
|
|
@ -10,6 +11,7 @@ namespace FidelityFX |
|
|
|
private const int MaxQueuedFrames = 16; |
|
|
|
|
|
|
|
private Fsr2.ContextDescription _contextDescription; |
|
|
|
private CommandBuffer _commandBuffer; |
|
|
|
|
|
|
|
private ComputeShader _prepareInputColorShader; |
|
|
|
private ComputeShader _depthClipShader; |
|
|
|
@ -44,6 +46,7 @@ namespace FidelityFX |
|
|
|
public void Create(Fsr2.ContextDescription contextDescription) |
|
|
|
{ |
|
|
|
_contextDescription = contextDescription; |
|
|
|
_commandBuffer = new CommandBuffer { name = "FSR2" }; |
|
|
|
|
|
|
|
_fsr2ConstantsBuffer = CreateConstantBuffer<Fsr2Constants>(); |
|
|
|
_spdConstantsBuffer = CreateConstantBuffer<SpdConstants>(); |
|
|
|
@ -88,6 +91,12 @@ namespace FidelityFX |
|
|
|
|
|
|
|
public void Dispatch(Fsr2.DispatchDescription dispatchParams) |
|
|
|
{ |
|
|
|
_commandBuffer.Clear(); |
|
|
|
|
|
|
|
// TODO: Should probably use a CommandBuffer here, to queue up all of the commands and dispatch them in one go
|
|
|
|
// Use SetRandomWriteTarget to declare UAVs
|
|
|
|
// Use ClearRandomWriteTargets to clear all UAVs at once
|
|
|
|
|
|
|
|
if (_firstExecution) |
|
|
|
{ |
|
|
|
// TODO: clear values
|
|
|
|
@ -112,6 +121,7 @@ namespace FidelityFX |
|
|
|
if (resetAccumulation) |
|
|
|
{ |
|
|
|
// TODO: clear reconstructed depth for max depth store
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Auto exposure
|
|
|
|
@ -133,15 +143,17 @@ namespace FidelityFX |
|
|
|
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; |
|
|
|
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas; |
|
|
|
|
|
|
|
_rcasShader.Dispatch(rcasKernel, threadGroupsX, threadGroupsY, 1); |
|
|
|
_commandBuffer.DispatchCompute(_rcasShader, rcasKernel, threadGroupsX, threadGroupsY, 1); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
Graphics.Blit(dispatchParams.Input, dispatchParams.Output); |
|
|
|
_commandBuffer.Blit(dispatchParams.Input, dispatchParams.Output); |
|
|
|
} |
|
|
|
|
|
|
|
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames; |
|
|
|
|
|
|
|
Graphics.ExecuteCommandBuffer(_commandBuffer); |
|
|
|
|
|
|
|
// TODO Unregister resources: release temp RT's
|
|
|
|
} |
|
|
|
|
|
|
|
@ -313,6 +325,9 @@ namespace FidelityFX |
|
|
|
DestroyComputeShader(ref _prepareInputColorShader); |
|
|
|
DestroyComputeShader(ref _rcasShader); |
|
|
|
DestroyComputeShader(ref _computeLuminancePyramidShader); |
|
|
|
|
|
|
|
_commandBuffer.Dispose(); |
|
|
|
_commandBuffer = null; |
|
|
|
} |
|
|
|
|
|
|
|
[Serializable, StructLayout(LayoutKind.Sequential)] |
|
|
|
|