@ -18,10 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
// THE SOFTWARE.
using System ;
using System.Runtime.InteropServices ;
using UnityEngine ;
using UnityEngine ;
using UnityEngine.Profiling ;
using UnityEngine.Rendering ;
using UnityEngine.Rendering ;
namespace FidelityFX.FSR3
namespace FidelityFX.FSR3
@ -31,53 +28,30 @@ namespace FidelityFX.FSR3
/// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket.
/// This loosely matches the FfxPipelineState struct from the original FSR3 codebase, wrapped in an object-oriented blanket.
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
/// These classes are responsible for loading compute shaders, managing temporary resources, binding resources to shader kernels and dispatching said shaders.
/// </summary>
/// </summary>
internal abstract class Fsr3UpscalerPass : IDisposable
internal abstract class Fsr3UpscalerPass : FfxPassWithFlags < Fsr3Upscaler . InitializationFlags >
{
{
protected readonly Fsr3Upscaler . ContextDescription ContextDescription ;
protected readonly Fsr3UpscalerResources Resources ;
protected readonly Fsr3UpscalerResources Resources ;
protected readonly ComputeBuffer Constants ;
protected readonly ComputeBuffer Constants ;
protected ComputeShader ComputeShader ;
protected int KernelIndex ;
protected CustomSampler Sampler ;
protected Fsr3UpscalerPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
protected Fsr3UpscalerPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( "FSR3 Upscaler" , contextDescription . Flags )
{
{
ContextDescription = contextDescription ;
Resources = resources ;
Resources = resources ;
Constants = constants ;
Constants = constants ;
}
}
public virtual void Dispose ( )
public void ScheduleDispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ = 1 )
{
{
}
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY )
using ( ProfilerSample ( commandBuffer ) )
{
{
commandBuffer . BeginSample ( Sampler ) ;
DoScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchX , dispatchY ) ;
commandBuffer . EndSample ( Sampler ) ;
Dispatch ( commandBuffer , dispatchParams , bufferIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
protected abstract void DoScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frameIndex , int dispatchX , int dispatchY ) ;
protected void InitComputeShader ( string passName , ComputeShader shader )
{
InitComputeShader ( passName , shader , ContextDescription . Flags ) ;
}
}
private void InitComputeShader ( string passName , ComputeShader shader , Fsr3Upscaler . InitializationFlags flags )
{
if ( shader = = null )
{
throw new MissingReferenceException ( $"Shader for FSR3 Upscaler pass '{passName}' could not be loaded! Please ensure it is included in the project correctly." ) ;
}
ComputeShader = shader ;
KernelIndex = ComputeShader . FindKernel ( "CS" ) ;
Sampler = CustomSampler . Create ( passName ) ;
protected abstract void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bufferIndex , int dispatchX , int dispatchY , int dispatchZ ) ;
protected override void SetupShaderKeywords ( )
{
bool useLut = false ;
bool useLut = false ;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+
if ( SystemInfo . computeSubGroupSize = = 6 4 )
if ( SystemInfo . computeSubGroupSize = = 6 4 )
@ -87,50 +61,46 @@ namespace FidelityFX.FSR3
#endif
#endif
// This matches the permutation rules from the CreatePipeline* functions
// This matches the permutation rules from the CreatePipeline* functions
if ( ( f lags & Fsr3Upscaler . InitializationFlags . EnableHighDynamicRange ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT" ) ;
if ( ( f lags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS" ) ;
if ( ( f lags & Fsr3Upscaler . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS" ) ;
if ( ( f lags & Fsr3Upscaler . InitializationFlags . EnableDepthInverted ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH" ) ;
if ( ( F lags & Fsr3Upscaler . InitializationFlags . EnableHighDynamicRange ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT" ) ;
if ( ( F lags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS" ) ;
if ( ( F lags & Fsr3Upscaler . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS" ) ;
if ( ( F lags & Fsr3Upscaler . InitializationFlags . EnableDepthInverted ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH" ) ;
if ( useLut ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE" ) ;
if ( useLut ) ComputeShader . EnableKeyword ( "FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE" ) ;
if ( ( f lags & Fsr3Upscaler . InitializationFlags . EnableFP16Usage ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_HALF" ) ;
if ( ( F lags & Fsr3Upscaler . InitializationFlags . EnableFP16Usage ) ! = 0 ) ComputeShader . EnableKeyword ( "FFX_HALF" ) ;
}
}
}
}
internal class Fsr3UpscalerPrepareInputsPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerPrepareInputsPass : Fsr3UpscalerPass
{
{
public Fsr3UpscalerPrepareInputsPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerPrepareInputsPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Prepare Inputs" , contextDescription . Shaders . prepareInputsPass ) ;
InitComputeShader ( "Prepare Inputs" , contextDescription . Shaders . prepareInputsPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var color = ref dispatchParams . Color ;
ref var depth = ref dispatchParams . Depth ;
ref var motionVectors = ref dispatchParams . MotionVectors ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputDepth , depth . RenderTarget , depth . MipLevel , depth . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputDepth , dispatchParams . Depth ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavCurrentLuma , Resources . Luma [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavCurrentLuma , Resources . Luma [ bu ffe rIndex] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerLumaPyramidPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerLumaPyramidPass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _spdConstants ;
private readonly ComputeBuffer _spdConstants ;
public Fsr3UpscalerLumaPyramidPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
public Fsr3UpscalerLumaPyramidPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
_spdConstants = spdConstants ;
_spdConstants = spdConstants ;
@ -138,32 +108,32 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Luminance Pyramid" , contextDescription . Shaders . lumaPyramidPass ) ;
InitComputeShader ( "Compute Luminance Pyramid" , contextDescription . Shaders . lumaPyramidPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bu ffe rIndex] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepth , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdAtomicCount , Resources . SpdAtomicCounter ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdAtomicCount , Resources . SpdAtomicCounter ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFrameInfo , Resources . FrameInfo ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavFrameInfo , Resources . FrameInfo ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip0 , Resources . SpdMips , 0 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip1 , Resources . SpdMips , 1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip2 , Resources . SpdMips , 2 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip0 , Resources . SpdMips , 0 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip1 , Resources . SpdMips , 1 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip2 , Resources . SpdMips , 2 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . SpdConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . SpdConstants > ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerShadingChangePyramidPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerShadingChangePyramidPass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _spdConstants ;
private readonly ComputeBuffer _spdConstants ;
public Fsr3UpscalerShadingChangePyramidPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
public Fsr3UpscalerShadingChangePyramidPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer spdConstants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
_spdConstants = spdConstants ;
_spdConstants = spdConstants ;
@ -171,110 +141,102 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Compute Shading Change Pyramid" , contextDescription . Shaders . shadingChangePyramidPass ) ;
InitComputeShader ( "Compute Shading Change Pyramid" , contextDescription . Shaders . shadingChangePyramidPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var exposure = ref dispatchParams . Exposure ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frameIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPreviousLuma , Resources . Luma [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bufferIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPreviousLuma , Resources . Luma [ bufferIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdAtomicCount , Resources . SpdAtomicCounter ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdAtomicCount , Resources . SpdAtomicCounter ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip0 , Resources . SpdMips , 0 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip1 , Resources . SpdMips , 1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip2 , Resources . SpdMips , 2 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip0 , Resources . SpdMips , 0 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip1 , Resources . SpdMips , 1 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip2 , Resources . SpdMips , 2 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip3 , Resources . SpdMips , 3 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip4 , Resources . SpdMips , 4 ) ;
commandBuffer . SetComputeTextureMip Param ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavSpdMip5 , Resources . SpdMips , 5 ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . SpdConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . SpdConstants > ( ComputeShader , Fsr3ShaderIDs . CbSpd , _spdConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerShadingChangePass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerShadingChangePass : Fsr3UpscalerPass
{
{
public Fsr3UpscalerShadingChangePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerShadingChangePass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Compute Shading Change" , contextDescription . Shaders . shadingChangePass ) ;
InitComputeShader ( "Compute Shading Change" , contextDescription . Shaders . shadingChangePass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvSpdMips , Resources . SpdMips ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvSpdMips , Resources . SpdMips ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerPrepareReactivityPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerPrepareReactivityPass : Fsr3UpscalerPass
{
{
public Fsr3UpscalerPrepareReactivityPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerPrepareReactivityPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Prepare Reactivity" , contextDescription . Shaders . prepareReactivityPass ) ;
InitComputeShader ( "Prepare Reactivity" , contextDescription . Shaders . prepareReactivityPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var exposure = ref dispatchParams . Exposure ;
ref var reactive = ref dispatchParams . Reactive ;
ref var tac = ref dispatchParams . TransparencyAndComposition ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReconstructedPrevNearestDepth , Resources . ReconstructedPrevNearestDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReactiveMask , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvTransparencyAndCompositionMask , tac . RenderTarget , tac . MipLevel , tac . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvAccumulation , Resources . Accumulation [ frame Index ^ 1 ] ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReactiveMask , dispatchParams . Reactive ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvTransparencyAndCompositionMask , dispatchParams . TransparencyAndComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvAccumulation , Resources . Accumulation [ bu ffe rIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvShadingChange , Fsr3ShaderIDs . UavShadingChange ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvShadingChange , Fsr3ShaderIDs . UavShadingChange ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frame Index ] ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bu ffe rIndex] ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAccumulation , Resources . Accumulation [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAccumulation , Resources . Accumulation [ bu ffe rIndex] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerLumaInstabilityPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerLumaInstabilityPass : Fsr3UpscalerPass
{
{
public Fsr3UpscalerLumaInstabilityPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerLumaInstabilityPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Compute Luminance Instability" , contextDescription . Shaders . lumaInstabilityPass ) ;
InitComputeShader ( "Compute Luminance Instability" , contextDescription . Shaders . lumaInstabilityPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var exposure = ref dispatchParams . Exposure ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFrameInfo , Resources . FrameInfo ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFrameInfo , Resources . FrameInfo ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLumaHistory , Resources . LumaHistory [ frame Index ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLumaHistory , Resources . LumaHistory [ bu ffe rIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepthMip1 , Fsr3ShaderIDs . UavFarthestDepthMip1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepthMip1 , Fsr3ShaderIDs . UavFarthestDepthMip1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bu ffe rIndex] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaHistory , Resources . LumaHistory [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaHistory , Resources . LumaHistory [ bu ffe rIndex] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerAccumulatePass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerAccumulatePass : Fsr3UpscalerPass
{
{
private const string SharpeningKeyword = "FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING" ;
private const string SharpeningKeyword = "FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING" ;
@ -282,7 +244,7 @@ namespace FidelityFX.FSR3
private readonly LocalKeyword _sharpeningKeyword ;
private readonly LocalKeyword _sharpeningKeyword ;
#endif
#endif
public Fsr3UpscalerAccumulatePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerAccumulatePass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Accumulate" , contextDescription . Shaders . accumulatePass ) ;
InitComputeShader ( "Accumulate" , contextDescription . Shaders . accumulatePass ) ;
@ -291,7 +253,7 @@ namespace FidelityFX.FSR3
#endif
#endif
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
#if UNITY_2021_2_OR_NEWER
#if UNITY_2021_2_OR_NEWER
if ( dispatchParams . EnableSharpening )
if ( dispatchParams . EnableSharpening )
@ -305,44 +267,39 @@ namespace FidelityFX.FSR3
commandBuffer . DisableShaderKeyword ( SharpeningKeyword ) ;
commandBuffer . DisableShaderKeyword ( SharpeningKeyword ) ;
#endif
#endif
ref var color = ref dispatchParams . Color ;
ref var exposure = ref dispatchParams . Exposure ;
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
if ( ( ContextDescription . Flags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 )
if ( ( Flags & Fsr3Upscaler . InitializationFlags . EnableDisplayResolutionMotionVectors ) = = 0 )
{
{
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
}
}
else
else
{
{
ref var motionVectors = ref dispatchParams . MotionVectors ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
}
}
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInternalUpscaled , Resources . InternalUpscaled [ frame Index ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInternalUpscaled , Resources . InternalUpscaled [ bu ffe rIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLanczosLut , Resources . LanczosLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLanczosLut , Resources . LanczosLut ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepthMip1 , Fsr3ShaderIDs . UavFarthestDepthMip1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvFarthestDepthMip1 , Fsr3ShaderIDs . UavFarthestDepthMip1 ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvCurrentLuma , Resources . Luma [ bu ffe rIndex] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvLumaInstability , Fsr3ShaderIDs . UavIntermediate ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavInternalUpscaled , Resources . InternalUpscaled [ frame Index ] ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElemen t) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavInternalUpscaled , Resources . InternalUpscaled [ bu ffe rIndex] ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , dispatchParams . Outpu t) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerSharpenPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerSharpenPass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _rcasConstants ;
private readonly ComputeBuffer _rcasConstants ;
public Fsr3UpscalerSharpenPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer rcasConstants )
public Fsr3UpscalerSharpenPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer rcasConstants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
_rcasConstants = rcasConstants ;
_rcasConstants = rcasConstants ;
@ -350,27 +307,25 @@ namespace FidelityFX.FSR3
InitComputeShader ( "RCAS Sharpening" , contextDescription . Shaders . sharpenPass ) ;
InitComputeShader ( "RCAS Sharpening" , contextDescription . Shaders . sharpenPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var exposure = ref dispatchParams . Exposure ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvRcasInput , Resources . InternalUpscaled [ frameIndex ] ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvRcasInput , Resources . InternalUpscaled [ bufferIndex ] ) ;
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , dispatchParams . Output ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbRcas , _rcasConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . RcasConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . RcasConstants > ( ComputeShader , Fsr3ShaderIDs . CbRcas , _rcasConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
internal class Fsr3UpscalerGenerateReactivePass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerGenerateReactivePass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _generateReactiveConstants ;
private readonly ComputeBuffer _generateReactiveConstants ;
public Fsr3UpscalerGenerateReactivePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer generateReactiveConstants )
public Fsr3UpscalerGenerateReactivePass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer generateReactiveConstants )
: base ( contextDescription , resources , null )
: base ( contextDescription , resources , null )
{
{
_generateReactiveConstants = generateReactiveConstants ;
_generateReactiveConstants = generateReactiveConstants ;
@ -378,35 +333,30 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Auto-Generate Reactive Mask" , contextDescription . Shaders . autoGenReactivePass ) ;
InitComputeShader ( "Auto-Generate Reactive Mask" , contextDescription . Shaders . autoGenReactivePass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
}
}
public void ScheduleDispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
public void ScheduleDispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . GenerateReactiveDescription dispatchParams , int dispatchX , int dispatchY )
{
{
commandBuffer . BeginSample ( Sampler ) ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var color = ref dispatchParams . ColorPreUpscale ;
ref var reactive = ref dispatchParams . OutReactive ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , opaqueOnly . RenderTarget , opaqueOnly . MipLevel , opaqueOnly . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
using ( ProfilerSample ( commandBuffer ) )
{
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . ColorPreUpscale ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , dispatchParams . OutReactive ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _generateReactiveConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . GenerateReactiveConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . GenerateReactiveConstants > ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _generateReactiveConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . EndSample ( Sampler ) ;
}
}
}
}
}
internal class Fsr3UpscalerTcrAutogeneratePass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerTcrAutogeneratePass : Fsr3UpscalerPass
{
{
private readonly ComputeBuffer _tcrAutogenerateConstants ;
private readonly ComputeBuffer _tcrAutogenerateConstants ;
public Fsr3UpscalerTcrAutogeneratePass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer tcrAutogenerateConstants )
public Fsr3UpscalerTcrAutogeneratePass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants , ComputeBuffer tcrAutogenerateConstants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
_tcrAutogenerateConstants = tcrAutogenerateConstants ;
@ -414,58 +364,50 @@ namespace FidelityFX.FSR3
InitComputeShader ( "Auto-Generate Transparency & Composition Mask" , contextDescription . Shaders . tcrAutoGenPass ) ;
InitComputeShader ( "Auto-Generate Transparency & Composition Mask" , contextDescription . Shaders . tcrAutoGenPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var color = ref dispatchParams . Color ;
ref var motionVectors = ref dispatchParams . MotionVectors ;
ref var opaqueOnly = ref dispatchParams . ColorOpaqueOnly ;
ref var reactive = ref dispatchParams . Reactive ;
ref var tac = ref dispatchParams . TransparencyAndComposition ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , opaqueOnly . RenderTarget , opaqueOnly . MipLevel , opaqueOnly . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , color . RenderTarget , color . MipLevel , color . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , motionVectors . RenderTarget , motionVectors . MipLevel , motionVectors . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPreAlpha , Resources . PrevPreAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPostAlpha , Resources . PrevPostAlpha [ frameIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReactiveMask , reactive . RenderTarget , reactive . MipLevel , reactive . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvTransparencyAndCompositionMask , tac . RenderTarget , tac . MipLevel , tac . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvOpaqueOnly , dispatchParams . ColorOpaqueOnly ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputColor , dispatchParams . Color ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputMotionVectors , dispatchParams . MotionVectors ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPreAlpha , Resources . PrevPreAlpha [ bufferIndex ^ 1 ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvPrevColorPostAlpha , Resources . PrevPostAlpha [ bufferIndex ^ 1 ] ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvReactiveMask , dispatchParams . Reactive ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvTransparencyAndCompositionMask , dispatchParams . TransparencyAndComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , Resources . AutoReactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoReactive , Resources . AutoReactive ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoComposition , Resources . AutoComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavAutoComposition , Resources . AutoComposition ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPreAlpha , Resources . PrevPreAlpha [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPostAlpha , Resources . PrevPostAlpha [ frame Index ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPreAlpha , Resources . PrevPreAlpha [ bufferIndex ] ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavPrevColorPostAlpha , Resources . PrevPostAlpha [ bufferIndex ] ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _tcrAutogenerateConstants , 0 , Marshal . SizeOf < Fsr3Upscaler . GenerateReactiveConstants2 > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . GenerateReactiveConstants2 > ( ComputeShader , Fsr3ShaderIDs . CbGenReactive , _tcrAutogenerateConstants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
#if UNITY_EDITOR || DEVELOPMENT_BUILD
#if UNITY_EDITOR || DEVELOPMENT_BUILD
internal class Fsr3UpscalerDebugViewPass : Fsr3UpscalerPass
internal sealed class Fsr3UpscalerDebugViewPass : Fsr3UpscalerPass
{
{
public Fsr3UpscalerDebugViewPass ( Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
public Fsr3UpscalerDebugViewPass ( in Fsr3Upscaler . ContextDescription contextDescription , Fsr3UpscalerResources resources , ComputeBuffer constants )
: base ( contextDescription , resources , constants )
: base ( contextDescription , resources , constants )
{
{
InitComputeShader ( "Debug View" , contextDescription . Shaders . debugViewPass ) ;
InitComputeShader ( "Debug View" , contextDescription . Shaders . debugViewPass ) ;
}
}
protected override void DoScheduleD ispatch ( CommandBuffer commandBuffer , Fsr3Upscaler . DispatchDescription dispatchParams , int frame Index , int dispatchX , int dispatchY )
protected override void Dispatch ( CommandBuffer commandBuffer , in Fsr3Upscaler . DispatchDescription dispatchParams , int bu ffe rIndex, int dispatchX , int dispatchY , int dispatchZ )
{
{
ref var exposure = ref dispatchParams . Exposure ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedReactiveMasks , Fsr3ShaderIDs . UavDilatedReactiveMasks ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedMotionVectors , Resources . DilatedVelocity ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvDilatedDepth , Resources . DilatedDepth ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInternalUpscaled , Resources . InternalUpscaled [ frame Index ] ) ;
commandBuffer . SetComputeTextur eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , exposure . RenderTarget , exposure . MipLevel , exposure . SubElement ) ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInternalUpscaled , Resources . InternalUpscaled [ bu ffe rIndex] ) ;
commandBuffer . SetComputeResourc eParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . SrvInputExposure , dispatchParams . Exposure ) ;
ref var output = ref dispatchParams . Output ;
commandBuffer . SetComputeTextureParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , output . RenderTarget , output . MipLevel , output . SubElement ) ;
commandBuffer . SetComputeResourceParam ( ComputeShader , KernelIndex , Fsr3ShaderIDs . UavUpscaledOutput , dispatchParams . Output ) ;
commandBuffer . SetComputeConstantBufferParam ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants , 0 , Marshal . SizeOf < Fsr3Upscaler . UpscalerConstants > ( ) ) ;
commandBuffer . SetComputeConstantBufferParam < Fsr3Upscaler . UpscalerConstants > ( ComputeShader , Fsr3ShaderIDs . CbFsr3Upscaler , Constants ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , 1 ) ;
commandBuffer . DispatchCompute ( ComputeShader , KernelIndex , dispatchX , dispatchY , dispatchZ ) ;
}
}
}
}
#endif
#endif