|
|
@ -39,18 +39,18 @@ namespace FidelityFX.FSR3 |
|
|
private Fsr3Upscaler.ContextDescription _contextDescription; |
|
|
private Fsr3Upscaler.ContextDescription _contextDescription; |
|
|
private CommandBuffer _commandBuffer; |
|
|
private CommandBuffer _commandBuffer; |
|
|
|
|
|
|
|
|
private Fsr3UpscalerPass _prepareInputsPass; |
|
|
|
|
|
private Fsr3UpscalerPass _lumaPyramidPass; |
|
|
|
|
|
private Fsr3UpscalerPass _shadingChangePyramidPass; |
|
|
|
|
|
private Fsr3UpscalerPass _shadingChangePass; |
|
|
|
|
|
private Fsr3UpscalerPass _prepareReactivityPass; |
|
|
|
|
|
private Fsr3UpscalerPass _lumaInstabilityPass; |
|
|
|
|
|
private Fsr3UpscalerPass _accumulatePass; |
|
|
|
|
|
private Fsr3UpscalerPass _sharpenPass; |
|
|
|
|
|
private Fsr3UpscalerPass _generateReactivePass; |
|
|
|
|
|
private Fsr3UpscalerPass _tcrAutogeneratePass; |
|
|
|
|
|
|
|
|
private Fsr3UpscalerPrepareInputsPass _prepareInputsPass; |
|
|
|
|
|
private Fsr3UpscalerLumaPyramidPass _lumaPyramidPass; |
|
|
|
|
|
private Fsr3UpscalerShadingChangePyramidPass _shadingChangePyramidPass; |
|
|
|
|
|
private Fsr3UpscalerShadingChangePass _shadingChangePass; |
|
|
|
|
|
private Fsr3UpscalerPrepareReactivityPass _prepareReactivityPass; |
|
|
|
|
|
private Fsr3UpscalerLumaInstabilityPass _lumaInstabilityPass; |
|
|
|
|
|
private Fsr3UpscalerAccumulatePass _accumulatePass; |
|
|
|
|
|
private Fsr3UpscalerSharpenPass _sharpenPass; |
|
|
|
|
|
private Fsr3UpscalerGenerateReactivePass _generateReactivePass; |
|
|
|
|
|
private Fsr3UpscalerTcrAutogeneratePass _tcrAutogeneratePass; |
|
|
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
|
|
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
|
|
private Fsr3UpscalerPass _debugViewPass; |
|
|
|
|
|
|
|
|
private Fsr3UpscalerDebugViewPass _debugViewPass; |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); |
|
|
private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); |
|
|
@ -69,7 +69,7 @@ namespace FidelityFX.FSR3 |
|
|
|
|
|
|
|
|
private readonly CustomSampler _sampler = CustomSampler.Create("FSR3 Upscaler"); |
|
|
private readonly CustomSampler _sampler = CustomSampler.Create("FSR3 Upscaler"); |
|
|
|
|
|
|
|
|
public void Create(Fsr3Upscaler.ContextDescription contextDescription) |
|
|
|
|
|
|
|
|
public void Create(in Fsr3Upscaler.ContextDescription contextDescription) |
|
|
{ |
|
|
{ |
|
|
_contextDescription = contextDescription; |
|
|
_contextDescription = contextDescription; |
|
|
_commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" }; |
|
|
_commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" }; |
|
|
@ -138,7 +138,7 @@ namespace FidelityFX.FSR3 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Dispatch(Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
|
|
|
|
|
|
public void Dispatch(in Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
{ |
|
|
{ |
|
|
_commandBuffer.Clear(); |
|
|
_commandBuffer.Clear(); |
|
|
Dispatch(dispatchParams, _commandBuffer); |
|
|
Dispatch(dispatchParams, _commandBuffer); |
|
|
@ -199,7 +199,7 @@ namespace FidelityFX.FSR3 |
|
|
|
|
|
|
|
|
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); |
|
|
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); |
|
|
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); |
|
|
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); |
|
|
Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); |
|
|
|
|
|
|
|
|
Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription); |
|
|
|
|
|
|
|
|
SetupConstants(dispatchParams, resetAccumulation); |
|
|
SetupConstants(dispatchParams, resetAccumulation); |
|
|
|
|
|
|
|
|
@ -233,7 +233,7 @@ namespace FidelityFX.FSR3 |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
|
|
|
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
|
|
|
bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) == Fsr3Upscaler.InitializationFlags.EnableDepthInverted; |
|
|
|
|
|
|
|
|
bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0; |
|
|
commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth); |
|
|
commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth); |
|
|
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); |
|
|
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); |
|
|
|
|
|
|
|
|
@ -289,14 +289,14 @@ namespace FidelityFX.FSR3 |
|
|
commandBuffer.EndSample(_sampler); |
|
|
commandBuffer.EndSample(_sampler); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams) |
|
|
|
|
|
|
|
|
public void GenerateReactiveMask(in Fsr3Upscaler.GenerateReactiveDescription dispatchParams) |
|
|
{ |
|
|
{ |
|
|
_commandBuffer.Clear(); |
|
|
_commandBuffer.Clear(); |
|
|
GenerateReactiveMask(dispatchParams, _commandBuffer); |
|
|
GenerateReactiveMask(dispatchParams, _commandBuffer); |
|
|
Graphics.ExecuteCommandBuffer(_commandBuffer); |
|
|
Graphics.ExecuteCommandBuffer(_commandBuffer); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) |
|
|
|
|
|
|
|
|
public void GenerateReactiveMask(in Fsr3Upscaler.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer) |
|
|
{ |
|
|
{ |
|
|
const int threadGroupWorkRegionDim = 8; |
|
|
const int threadGroupWorkRegionDim = 8; |
|
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
|
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
|
|
@ -309,10 +309,10 @@ namespace FidelityFX.FSR3 |
|
|
genReactiveConsts.flags = (uint)dispatchParams.Flags; |
|
|
genReactiveConsts.flags = (uint)dispatchParams.Flags; |
|
|
_generateReactiveConstants.UpdateBufferData(commandBuffer); |
|
|
_generateReactiveConstants.UpdateBufferData(commandBuffer); |
|
|
|
|
|
|
|
|
((Fsr3UpscalerGenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY); |
|
|
|
|
|
|
|
|
_generateReactivePass.ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void GenerateTransparencyCompositionReactive(Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex) |
|
|
|
|
|
|
|
|
private void GenerateTransparencyCompositionReactive(in Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int bufferIndex) |
|
|
{ |
|
|
{ |
|
|
const int threadGroupWorkRegionDim = 8; |
|
|
const int threadGroupWorkRegionDim = 8; |
|
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
|
|
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; |
|
|
@ -325,10 +325,10 @@ namespace FidelityFX.FSR3 |
|
|
tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax; |
|
|
tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax; |
|
|
_tcrAutogenerateConstants.UpdateBufferData(commandBuffer); |
|
|
_tcrAutogenerateConstants.UpdateBufferData(commandBuffer); |
|
|
|
|
|
|
|
|
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY); |
|
|
|
|
|
|
|
|
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, bufferIndex, dispatchSrcX, dispatchSrcY); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation) |
|
|
|
|
|
|
|
|
private void SetupConstants(in Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation) |
|
|
{ |
|
|
{ |
|
|
ref Fsr3Upscaler.UpscalerConstants constants = ref _upscalerConstants.Value; |
|
|
ref Fsr3Upscaler.UpscalerConstants constants = ref _upscalerConstants.Value; |
|
|
|
|
|
|
|
|
@ -408,13 +408,13 @@ namespace FidelityFX.FSR3 |
|
|
constants.frameIndex += 1.0f; |
|
|
constants.frameIndex += 1.0f; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SetupRcasConstants(Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
|
|
|
|
|
|
private void SetupRcasConstants(in Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
{ |
|
|
{ |
|
|
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); |
|
|
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); |
|
|
_rcasConstants.Value = RcasConfigs[sharpnessIndex]; |
|
|
_rcasConstants.Value = RcasConfigs[sharpnessIndex]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void SetupSpdConstants(Fsr3Upscaler.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount) |
|
|
|
|
|
|
|
|
private void SetupSpdConstants(in Fsr3Upscaler.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount) |
|
|
{ |
|
|
{ |
|
|
// Downsample
|
|
|
// Downsample
|
|
|
ref Fsr3Upscaler.SpdConstants spdConstants = ref _spdConstants.Value; |
|
|
ref Fsr3Upscaler.SpdConstants spdConstants = ref _spdConstants.Value; |
|
|
@ -423,7 +423,7 @@ namespace FidelityFX.FSR3 |
|
|
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y; |
|
|
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void DebugCheckDispatch(Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
|
|
|
|
|
|
private void DebugCheckDispatch(in Fsr3Upscaler.DispatchDescription dispatchParams) |
|
|
{ |
|
|
{ |
|
|
if (!dispatchParams.Color.IsValid) |
|
|
if (!dispatchParams.Color.IsValid) |
|
|
{ |
|
|
{ |
|
|
|