Browse Source

Allow FSR2 commands to be added to a CommandBuffer passed in externally

mac-autoexp
Nico de Poel 3 years ago
parent
commit
1a0945a283
  1. 51
      Assets/Scripts/Fsr2Context.cs

51
Assets/Scripts/Fsr2Context.cs

@ -100,16 +100,21 @@ namespace FidelityFX
public void Dispatch(Fsr2.DispatchDescription dispatchParams)
{
// TODO: validation & debug checking
_commandBuffer.Clear();
Dispatch(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer);
}
public void Dispatch(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer)
{
// TODO: validation & debug checking
if (_firstExecution)
{
_commandBuffer.SetRenderTarget(_resources.LockStatus[0]);
_commandBuffer.ClearRenderTarget(false, true, Color.clear);
_commandBuffer.SetRenderTarget(_resources.LockStatus[1]);
_commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[0]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
}
int frameIndex = _resourceFrameIndex % 2;
@ -119,7 +124,7 @@ namespace FidelityFX
// TODO: auto-exposure flag
if (dispatchParams.Exposure == null) dispatchParams.Exposure = _resources.DefaultExposure;
if (dispatchParams.Reactive == null) dispatchParams.Reactive = _resources.DefaultReactive;
Fsr2Pipeline.RegisterResources(_commandBuffer, _contextDescription, dispatchParams);
Fsr2Pipeline.RegisterResources(commandBuffer, _contextDescription, dispatchParams);
SetupConstants(dispatchParams, resetAccumulation);
@ -133,18 +138,18 @@ namespace FidelityFX
// Clear reconstructed depth for max depth store.
if (resetAccumulation)
{
_commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]);
_commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.LockStatus[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
_commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]);
_commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.InternalUpscaled[frameIndex ^ 1]);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
_commandBuffer.SetRenderTarget(_resources.SceneLuminance);
_commandBuffer.ClearRenderTarget(false, true, Color.clear);
commandBuffer.SetRenderTarget(_resources.SceneLuminance);
commandBuffer.ClearRenderTarget(false, true, Color.clear);
// Auto exposure always used to track luma changes in locking logic
_commandBuffer.SetRenderTarget(_resources.AutoExposure);
_commandBuffer.ClearRenderTarget(false, true, new Color(-1f, 1e8f, 0f, 0f));
commandBuffer.SetRenderTarget(_resources.AutoExposure);
commandBuffer.ClearRenderTarget(false, true, new Color(-1f, 1e8f, 0f, 0f));
}
// Auto exposure
@ -155,22 +160,22 @@ namespace FidelityFX
_spdConstantsBuffer.SetData(_spdConstantsArray);
// Compute luminance pyramid
_computeLuminancePyramidPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
_computeLuminancePyramidPipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchThreadGroupCount.x, dispatchThreadGroupCount.y);
// Reconstruct previous depth
_reconstructPreviousDepthPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_reconstructPreviousDepthPipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Depth clip
_depthClipPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_depthClipPipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
// Create locks
_lockPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_lockPipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
bool sharpenEnabled = dispatchParams.EnableSharpening;
// Accumulate
var accumulatePipeline = sharpenEnabled ? _accumulateSharpenPipeline : _accumulatePipeline;
accumulatePipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
accumulatePipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchDstX, dispatchDstY);
if (sharpenEnabled)
{
@ -182,14 +187,12 @@ namespace FidelityFX
const int threadGroupWorkRegionDimRcas = 16;
int threadGroupsX = (Screen.width + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
int threadGroupsY = (Screen.height + threadGroupWorkRegionDimRcas - 1) / threadGroupWorkRegionDimRcas;
_rcasPipeline.ScheduleDispatch(_commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
_rcasPipeline.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, threadGroupsX, threadGroupsY);
}
_resourceFrameIndex = (_resourceFrameIndex + 1) % MaxQueuedFrames;
Fsr2Pipeline.UnregisterResources(_commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer);
Fsr2Pipeline.UnregisterResources(commandBuffer);
}
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams)

Loading…
Cancel
Save