@ -34,10 +34,10 @@ namespace FidelityFX.FSR2
public class Fsr2Context
public class Fsr2Context
{
{
private const int MaxQueuedFrames = 1 6 ;
private const int MaxQueuedFrames = 1 6 ;
private Fsr2 . ContextDescription _contextDescription ;
private Fsr2 . ContextDescription _contextDescription ;
private CommandBuffer _commandBuffer ;
private CommandBuffer _commandBuffer ;
private Fsr2Pass _computeLuminancePyramidPass ;
private Fsr2Pass _computeLuminancePyramidPass ;
private Fsr2Pass _reconstructPreviousDepthPass ;
private Fsr2Pass _reconstructPreviousDepthPass ;
private Fsr2Pass _depthClipPass ;
private Fsr2Pass _depthClipPass ;
@ -56,7 +56,7 @@ namespace FidelityFX.FSR2
private ComputeBuffer _spdConstantsBuffer ;
private ComputeBuffer _spdConstantsBuffer ;
private readonly Fsr2 . SpdConstants [ ] _spdConstantsArray = { new Fsr2 . SpdConstants ( ) } ;
private readonly Fsr2 . SpdConstants [ ] _spdConstantsArray = { new Fsr2 . SpdConstants ( ) } ;
private ref Fsr2 . SpdConstants SpdConsts = > ref _spdConstantsArray [ 0 ] ;
private ref Fsr2 . SpdConstants SpdConsts = > ref _spdConstantsArray [ 0 ] ;
private ComputeBuffer _rcasConstantsBuffer ;
private ComputeBuffer _rcasConstantsBuffer ;
private readonly Fsr2 . RcasConstants [ ] _rcasConstantsArray = new Fsr2 . RcasConstants [ 1 ] ;
private readonly Fsr2 . RcasConstants [ ] _rcasConstantsArray = new Fsr2 . RcasConstants [ 1 ] ;
private ref Fsr2 . RcasConstants RcasConsts = > ref _rcasConstantsArray [ 0 ] ;
private ref Fsr2 . RcasConstants RcasConsts = > ref _rcasConstantsArray [ 0 ] ;
@ -77,7 +77,7 @@ namespace FidelityFX.FSR2
{
{
_contextDescription = contextDescription ;
_contextDescription = contextDescription ;
_commandBuffer = new CommandBuffer { name = "FSR2" } ;
_commandBuffer = new CommandBuffer { name = "FSR2" } ;
_upscalerConstantsBuffer = CreateConstantBuffer < Fsr2 . UpscalerConstants > ( ) ;
_upscalerConstantsBuffer = CreateConstantBuffer < Fsr2 . UpscalerConstants > ( ) ;
_spdConstantsBuffer = CreateConstantBuffer < Fsr2 . SpdConstants > ( ) ;
_spdConstantsBuffer = CreateConstantBuffer < Fsr2 . SpdConstants > ( ) ;
_rcasConstantsBuffer = CreateConstantBuffer < Fsr2 . RcasConstants > ( ) ;
_rcasConstantsBuffer = CreateConstantBuffer < Fsr2 . RcasConstants > ( ) ;
@ -87,9 +87,9 @@ namespace FidelityFX.FSR2
// Set defaults
// Set defaults
_firstExecution = true ;
_firstExecution = true ;
_resourceFrameIndex = 0 ;
_resourceFrameIndex = 0 ;
UpscalerConsts . displaySize = _contextDescription . DisplaySize ;
UpscalerConsts . displaySize = _contextDescription . DisplaySize ;
_resources . Create ( _contextDescription ) ;
_resources . Create ( _contextDescription ) ;
CreatePasses ( ) ;
CreatePasses ( ) ;
}
}
@ -105,7 +105,7 @@ namespace FidelityFX.FSR2
_generateReactivePass = new Fsr2GenerateReactivePass ( _contextDescription , _resources , _generateReactiveConstantsBuffer ) ;
_generateReactivePass = new Fsr2GenerateReactivePass ( _contextDescription , _resources , _generateReactiveConstantsBuffer ) ;
_tcrAutogeneratePass = new Fsr2TcrAutogeneratePass ( _contextDescription , _resources , _upscalerConstantsBuffer , _tcrAutogenerateConstantsBuffer ) ;
_tcrAutogeneratePass = new Fsr2TcrAutogeneratePass ( _contextDescription , _resources , _upscalerConstantsBuffer , _tcrAutogenerateConstantsBuffer ) ;
}
}
public void Destroy ( )
public void Destroy ( )
{
{
DestroyPass ( ref _tcrAutogeneratePass ) ;
DestroyPass ( ref _tcrAutogeneratePass ) ;
@ -116,9 +116,9 @@ namespace FidelityFX.FSR2
DestroyPass ( ref _depthClipPass ) ;
DestroyPass ( ref _depthClipPass ) ;
DestroyPass ( ref _reconstructPreviousDepthPass ) ;
DestroyPass ( ref _reconstructPreviousDepthPass ) ;
DestroyPass ( ref _computeLuminancePyramidPass ) ;
DestroyPass ( ref _computeLuminancePyramidPass ) ;
_resources . Destroy ( ) ;
_resources . Destroy ( ) ;
DestroyConstantBuffer ( ref _tcrAutogenerateConstantsBuffer ) ;
DestroyConstantBuffer ( ref _tcrAutogenerateConstantsBuffer ) ;
DestroyConstantBuffer ( ref _generateReactiveConstantsBuffer ) ;
DestroyConstantBuffer ( ref _generateReactiveConstantsBuffer ) ;
DestroyConstantBuffer ( ref _rcasConstantsBuffer ) ;
DestroyConstantBuffer ( ref _rcasConstantsBuffer ) ;
@ -138,17 +138,17 @@ namespace FidelityFX.FSR2
Dispatch ( dispatchParams , _commandBuffer ) ;
Dispatch ( dispatchParams , _commandBuffer ) ;
Graphics . ExecuteCommandBuffer ( _commandBuffer ) ;
Graphics . ExecuteCommandBuffer ( _commandBuffer ) ;
}
}
public void Dispatch ( Fsr2 . DispatchDescription dispatchParams , CommandBuffer commandBuffer )
public void Dispatch ( Fsr2 . DispatchDescription dispatchParams , CommandBuffer commandBuffer )
{
{
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDebugChecking ) ! = 0 )
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDebugChecking ) ! = 0 )
{
{
DebugCheckDispatch ( dispatchParams ) ;
DebugCheckDispatch ( dispatchParams ) ;
}
}
if ( dispatchParams . UseTextureArrays )
if ( dispatchParams . UseTextureArrays )
commandBuffer . EnableShaderKeyword ( "UNITY_FSR_TEXTURE2D_X_ARRAY" ) ;
commandBuffer . EnableShaderKeyword ( "UNITY_FSR_TEXTURE2D_X_ARRAY" ) ;
if ( _firstExecution )
if ( _firstExecution )
{
{
commandBuffer . SetRenderTarget ( _resources . LockStatus [ 0 ] ) ;
commandBuffer . SetRenderTarget ( _resources . LockStatus [ 0 ] ) ;
@ -156,7 +156,7 @@ namespace FidelityFX.FSR2
commandBuffer . SetRenderTarget ( _resources . LockStatus [ 1 ] ) ;
commandBuffer . SetRenderTarget ( _resources . LockStatus [ 1 ] ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
}
}
int frameIndex = _resourceFrameIndex % 2 ;
int frameIndex = _resourceFrameIndex % 2 ;
bool resetAccumulation = dispatchParams . Reset | | _firstExecution ;
bool resetAccumulation = dispatchParams . Reset | | _firstExecution ;
_firstExecution = false ;
_firstExecution = false ;
@ -164,7 +164,7 @@ namespace FidelityFX.FSR2
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableAutoExposure ) ! = 0 )
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableAutoExposure ) ! = 0 )
dispatchParams . Exposure = new ResourceView ( _resources . AutoExposure ) ;
dispatchParams . Exposure = new ResourceView ( _resources . AutoExposure ) ;
else if ( ! dispatchParams . Exposure . IsValid )
else if ( ! dispatchParams . Exposure . IsValid )
dispatchParams . Exposure = new ResourceView ( _resources . DefaultExposure ) ;
dispatchParams . Exposure = new ResourceView ( _resources . DefaultExposure ) ;
if ( dispatchParams . EnableAutoReactive )
if ( dispatchParams . EnableAutoReactive )
@ -181,16 +181,16 @@ namespace FidelityFX.FSR2
}
}
else if ( _resources . AutoReactive ! = null )
else if ( _resources . AutoReactive ! = null )
{
{
// Destroy the auto-TCR resources if we don't use the feature
// Destroy the auto-TCR resources if we don't use the feature
_resources . DestroyTcrAutogenResources ( ) ;
_resources . DestroyTcrAutogenResources ( ) ;
}
}
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 ) ;
Fsr2Resources . CreateAliasableResources ( commandBuffer , _contextDescription , dispatchParams ) ;
Fsr2Resources . CreateAliasableResources ( commandBuffer , _contextDescription , dispatchParams ) ;
SetupConstants ( dispatchParams , resetAccumulation ) ;
SetupConstants ( dispatchParams , resetAccumulation ) ;
// Reactive mask bias
// Reactive mask bias
const int threadGroupWorkRegionDim = 8 ;
const int threadGroupWorkRegionDim = 8 ;
int dispatchSrcX = ( UpscalerConsts . renderSize . x + ( threadGroupWorkRegionDim - 1 ) ) / threadGroupWorkRegionDim ;
int dispatchSrcX = ( UpscalerConsts . renderSize . x + ( threadGroupWorkRegionDim - 1 ) ) / threadGroupWorkRegionDim ;
@ -203,7 +203,7 @@ namespace FidelityFX.FSR2
{
{
commandBuffer . SetRenderTarget ( _resources . LockStatus [ frameIndex ^ 1 ] ) ;
commandBuffer . SetRenderTarget ( _resources . LockStatus [ frameIndex ^ 1 ] ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . SetRenderTarget ( _resources . InternalUpscaled [ frameIndex ^ 1 ] ) ;
commandBuffer . SetRenderTarget ( _resources . InternalUpscaled [ frameIndex ^ 1 ] ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
@ -213,7 +213,7 @@ namespace FidelityFX.FSR2
commandBuffer . SetRenderTarget ( _resources . SceneLuminance ) ;
commandBuffer . SetRenderTarget ( _resources . SceneLuminance ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
// Auto exposure always used to track luma changes in locking logic
// Auto exposure always used to track luma changes in locking logic
commandBuffer . SetRenderTarget ( _resources . AutoExposure ) ;
commandBuffer . SetRenderTarget ( _resources . AutoExposure ) ;
commandBuffer . ClearRenderTarget ( false , true , new Color ( 0f , 1f , 0f , 0f ) ) ;
commandBuffer . ClearRenderTarget ( false , true , new Color ( 0f , 1f , 0f , 0f ) ) ;
@ -222,15 +222,15 @@ namespace FidelityFX.FSR2
commandBuffer . SetRenderTarget ( _resources . SpdAtomicCounter ) ;
commandBuffer . SetRenderTarget ( _resources . SpdAtomicCounter ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
commandBuffer . ClearRenderTarget ( false , true , Color . clear ) ;
}
}
// 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 & Fsr2 . InitializationFlags . EnableDepthInverted ) = = Fsr2 . InitializationFlags . EnableDepthInverted ;
bool depthInverted = ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDepthInverted ) = = Fsr2 . InitializationFlags . EnableDepthInverted ;
commandBuffer . SetRenderTarget ( Fsr2ShaderIDs . UavReconstructedPrevNearestDepth ) ;
commandBuffer . SetRenderTarget ( Fsr2ShaderIDs . UavReconstructedPrevNearestDepth ) ;
commandBuffer . ClearRenderTarget ( false , true , depthInverted ? Color . clear : Color . white ) ;
commandBuffer . ClearRenderTarget ( false , true , depthInverted ? Color . clear : Color . white ) ;
// Auto exposure
// Auto exposure
SetupSpdConstants ( dispatchParams , out var dispatchThreadGroupCount ) ;
SetupSpdConstants ( dispatchParams , out var dispatchThreadGroupCount ) ;
// Initialize constant buffers data
// Initialize constant buffers data
commandBuffer . SetBufferData ( _upscalerConstantsBuffer , _upscalerConstantsArray ) ;
commandBuffer . SetBufferData ( _upscalerConstantsBuffer , _upscalerConstantsArray ) ;
commandBuffer . SetBufferData ( _spdConstantsBuffer , _spdConstantsArray ) ;
commandBuffer . SetBufferData ( _spdConstantsBuffer , _spdConstantsArray ) ;
@ -242,7 +242,7 @@ namespace FidelityFX.FSR2
dispatchParams . Reactive = new ResourceView ( _resources . AutoReactive ) ;
dispatchParams . Reactive = new ResourceView ( _resources . AutoReactive ) ;
dispatchParams . TransparencyAndComposition = new ResourceView ( _resources . AutoComposition ) ;
dispatchParams . TransparencyAndComposition = new ResourceView ( _resources . AutoComposition ) ;
}
}
// Compute luminance pyramid
// Compute luminance pyramid
_computeLuminancePyramidPass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchThreadGroupCount . x , dispatchThreadGroupCount . y ) ;
_computeLuminancePyramidPass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchThreadGroupCount . x , dispatchThreadGroupCount . y ) ;
@ -263,18 +263,18 @@ namespace FidelityFX.FSR2
// Compute the constants
// Compute the constants
SetupRcasConstants ( dispatchParams ) ;
SetupRcasConstants ( dispatchParams ) ;
commandBuffer . SetBufferData ( _rcasConstantsBuffer , _rcasConstantsArray ) ;
commandBuffer . SetBufferData ( _rcasConstantsBuffer , _rcasConstantsArray ) ;
// Dispatch RCAS
// Dispatch RCAS
const int threadGroupWorkRegionDimRcas = 1 6 ;
const int threadGroupWorkRegionDimRcas = 1 6 ;
int threadGroupsX = ( Screen . width + threadGroupWorkRegionDimRcas - 1 ) / threadGroupWorkRegionDimRcas ;
int threadGroupsY = ( Screen . height + threadGroupWorkRegionDimRcas - 1 ) / threadGroupWorkRegionDimRcas ;
int threadGroupsX = ( _contextDescription . DisplaySize . x + threadGroupWorkRegionDimRcas - 1 ) / threadGroupWorkRegionDimRcas ;
int threadGroupsY = ( _contextDescription . DisplaySize . y + threadGroupWorkRegionDimRcas - 1 ) / threadGroupWorkRegionDimRcas ;
_sharpenPass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , threadGroupsX , threadGroupsY ) ;
_sharpenPass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , threadGroupsX , threadGroupsY ) ;
}
}
_resourceFrameIndex = ( _resourceFrameIndex + 1 ) % MaxQueuedFrames ;
_resourceFrameIndex = ( _resourceFrameIndex + 1 ) % MaxQueuedFrames ;
Fsr2Resources . DestroyAliasableResources ( commandBuffer ) ;
Fsr2Resources . DestroyAliasableResources ( commandBuffer ) ;
commandBuffer . DisableShaderKeyword ( "UNITY_FSR_TEXTURE2D_X_ARRAY" ) ;
commandBuffer . DisableShaderKeyword ( "UNITY_FSR_TEXTURE2D_X_ARRAY" ) ;
}
}
@ -296,7 +296,7 @@ namespace FidelityFX.FSR2
GenReactiveConsts . binaryValue = dispatchParams . BinaryValue ;
GenReactiveConsts . binaryValue = dispatchParams . BinaryValue ;
GenReactiveConsts . flags = ( uint ) dispatchParams . Flags ;
GenReactiveConsts . flags = ( uint ) dispatchParams . Flags ;
commandBuffer . SetBufferData ( _generateReactiveConstantsBuffer , _generateReactiveConstantsArray ) ;
commandBuffer . SetBufferData ( _generateReactiveConstantsBuffer , _generateReactiveConstantsArray ) ;
( ( Fsr2GenerateReactivePass ) _generateReactivePass ) . ScheduleDispatch ( commandBuffer , dispatchParams , dispatchSrcX , dispatchSrcY ) ;
( ( Fsr2GenerateReactivePass ) _generateReactivePass ) . ScheduleDispatch ( commandBuffer , dispatchParams , dispatchSrcX , dispatchSrcY ) ;
}
}
@ -311,14 +311,14 @@ namespace FidelityFX.FSR2
TcrAutoGenConsts . autoReactiveScale = dispatchParams . AutoReactiveScale ;
TcrAutoGenConsts . autoReactiveScale = dispatchParams . AutoReactiveScale ;
TcrAutoGenConsts . autoReactiveMax = dispatchParams . AutoReactiveMax ;
TcrAutoGenConsts . autoReactiveMax = dispatchParams . AutoReactiveMax ;
commandBuffer . SetBufferData ( _tcrAutogenerateConstantsBuffer , _tcrAutogenerateConstantsArray ) ;
commandBuffer . SetBufferData ( _tcrAutogenerateConstantsBuffer , _tcrAutogenerateConstantsArray ) ;
_tcrAutogeneratePass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchSrcX , dispatchSrcY ) ;
_tcrAutogeneratePass . ScheduleDispatch ( commandBuffer , dispatchParams , frameIndex , dispatchSrcX , dispatchSrcY ) ;
}
}
private void SetupConstants ( Fsr2 . DispatchDescription dispatchParams , bool resetAccumulation )
private void SetupConstants ( Fsr2 . DispatchDescription dispatchParams , bool resetAccumulation )
{
{
ref Fsr2 . UpscalerConstants constants = ref UpscalerConsts ;
ref Fsr2 . UpscalerConstants constants = ref UpscalerConsts ;
constants . jitterOffset = dispatchParams . JitterOffset ;
constants . jitterOffset = dispatchParams . JitterOffset ;
constants . renderSize = dispatchParams . RenderSize ;
constants . renderSize = dispatchParams . RenderSize ;
constants . maxRenderSize = _contextDescription . MaxRenderSize ;
constants . maxRenderSize = _contextDescription . MaxRenderSize ;
@ -332,16 +332,16 @@ namespace FidelityFX.FSR2
// Compute params to enable device depth to view space depth computation in shader
// Compute params to enable device depth to view space depth computation in shader
constants . deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams ( dispatchParams ) ;
constants . deviceToViewDepth = SetupDeviceDepthToViewSpaceDepthParams ( dispatchParams ) ;
// To be updated if resource is larger than the actual image size
// To be updated if resource is larger than the actual image size
constants . downscaleFactor = new Vector2 ( ( float ) constants . renderSize . x / _contextDescription . DisplaySize . x , ( float ) constants . renderSize . y / _contextDescription . DisplaySize . y ) ;
constants . downscaleFactor = new Vector2 ( ( float ) constants . renderSize . x / _contextDescription . DisplaySize . x , ( float ) constants . renderSize . y / _contextDescription . DisplaySize . y ) ;
constants . previousFramePreExposure = constants . preExposure ;
constants . previousFramePreExposure = constants . preExposure ;
constants . preExposure = ( dispatchParams . PreExposure ! = 0 ) ? dispatchParams . PreExposure : 1.0f ;
constants . preExposure = ( dispatchParams . PreExposure ! = 0 ) ? dispatchParams . PreExposure : 1.0f ;
// Motion vector data
// Motion vector data
Vector2Int motionVectorsTargetSize = ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDisplayResolutionMotionVectors ) ! = 0 ? constants . displaySize : constants . renderSize ;
Vector2Int motionVectorsTargetSize = ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDisplayResolutionMotionVectors ) ! = 0 ? constants . displaySize : constants . renderSize ;
constants . motionVectorScale = dispatchParams . MotionVectorScale / motionVectorsTargetSize ;
constants . motionVectorScale = dispatchParams . MotionVectorScale / motionVectorsTargetSize ;
// Compute jitter cancellation
// Compute jitter cancellation
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 )
if ( ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableMotionVectorsJitterCancellation ) ! = 0 )
{
{
@ -362,7 +362,7 @@ namespace FidelityFX.FSR2
else if ( jitterPhaseCountDelta < 0 )
else if ( jitterPhaseCountDelta < 0 )
constants . jitterPhaseCount - - ;
constants . jitterPhaseCount - - ;
}
}
// Convert delta time to seconds and clamp to [0, 1]
// Convert delta time to seconds and clamp to [0, 1]
constants . deltaTime = Mathf . Clamp01 ( dispatchParams . FrameTimeDelta ) ;
constants . deltaTime = Mathf . Clamp01 ( dispatchParams . FrameTimeDelta ) ;
@ -378,7 +378,7 @@ namespace FidelityFX.FSR2
constants . lumaMipDimensions . x = ( int ) ( constants . maxRenderSize . x / mipDiv ) ;
constants . lumaMipDimensions . x = ( int ) ( constants . maxRenderSize . x / mipDiv ) ;
constants . lumaMipDimensions . y = ( int ) ( constants . maxRenderSize . y / mipDiv ) ;
constants . lumaMipDimensions . y = ( int ) ( constants . maxRenderSize . y / mipDiv ) ;
}
}
private Vector4 SetupDeviceDepthToViewSpaceDepthParams ( Fsr2 . DispatchDescription dispatchParams )
private Vector4 SetupDeviceDepthToViewSpaceDepthParams ( Fsr2 . DispatchDescription dispatchParams )
{
{
bool inverted = ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDepthInverted ) ! = 0 ;
bool inverted = ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableDepthInverted ) ! = 0 ;
@ -399,7 +399,7 @@ namespace FidelityFX.FSR2
Vector4 matrixElemC = new Vector4 ( q , - 1.0f - Mathf . Epsilon , q , 0.0f + Mathf . Epsilon ) ;
Vector4 matrixElemC = new Vector4 ( q , - 1.0f - Mathf . Epsilon , q , 0.0f + Mathf . Epsilon ) ;
Vector4 matrixElemE = new Vector4 ( q * min , - min - Mathf . Epsilon , q * min , max ) ;
Vector4 matrixElemE = new Vector4 ( q * min , - min - Mathf . Epsilon , q * min , max ) ;
// Revert x and y coords
// Revert x and y coords
float aspect = ( float ) dispatchParams . RenderSize . x / dispatchParams . RenderSize . y ;
float aspect = ( float ) dispatchParams . RenderSize . x / dispatchParams . RenderSize . y ;
float cotHalfFovY = Mathf . Cos ( 0.5f * dispatchParams . CameraFovAngleVertical ) / Mathf . Sin ( 0.5f * dispatchParams . CameraFovAngleVertical ) ;
float cotHalfFovY = Mathf . Cos ( 0.5f * dispatchParams . CameraFovAngleVertical ) / Mathf . Sin ( 0.5f * dispatchParams . CameraFovAngleVertical ) ;
@ -422,7 +422,7 @@ namespace FidelityFX.FSR2
{
{
RectInt rectInfo = new RectInt ( 0 , 0 , dispatchParams . RenderSize . x , dispatchParams . RenderSize . y ) ;
RectInt rectInfo = new RectInt ( 0 , 0 , dispatchParams . RenderSize . x , dispatchParams . RenderSize . y ) ;
SpdSetup ( rectInfo , out dispatchThreadGroupCount , out var workGroupOffset , out var numWorkGroupsAndMips ) ;
SpdSetup ( rectInfo , out dispatchThreadGroupCount , out var workGroupOffset , out var numWorkGroupsAndMips ) ;
// Downsample
// Downsample
ref Fsr2 . SpdConstants spdConstants = ref SpdConsts ;
ref Fsr2 . SpdConstants spdConstants = ref SpdConsts ;
spdConstants . numWorkGroups = ( uint ) numWorkGroupsAndMips . x ;
spdConstants . numWorkGroups = ( uint ) numWorkGroupsAndMips . x ;
@ -456,22 +456,22 @@ namespace FidelityFX.FSR2
{
{
Debug . LogError ( "Color resource is null" ) ;
Debug . LogError ( "Color resource is null" ) ;
}
}
if ( ! dispatchParams . Depth . IsValid )
if ( ! dispatchParams . Depth . IsValid )
{
{
Debug . LogError ( "Depth resource is null" ) ;
Debug . LogError ( "Depth resource is null" ) ;
}
}
if ( ! dispatchParams . MotionVectors . IsValid )
if ( ! dispatchParams . MotionVectors . IsValid )
{
{
Debug . LogError ( "MotionVectors resource is null" ) ;
Debug . LogError ( "MotionVectors resource is null" ) ;
}
}
if ( ! dispatchParams . Output . IsValid )
if ( ! dispatchParams . Output . IsValid )
{
{
Debug . LogError ( "Output resource is null" ) ;
Debug . LogError ( "Output resource is null" ) ;
}
}
if ( dispatchParams . Exposure . IsValid & & ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableAutoExposure ) ! = 0 )
if ( dispatchParams . Exposure . IsValid & & ( _contextDescription . Flags & Fsr2 . InitializationFlags . EnableAutoExposure ) ! = 0 )
{
{
Debug . LogWarning ( "Exposure resource provided, however auto exposure flag is present" ) ;
Debug . LogWarning ( "Exposure resource provided, however auto exposure flag is present" ) ;
@ -529,7 +529,7 @@ namespace FidelityFX.FSR2
Debug . LogWarning ( "EnableDepthInfinite and EnableDepthInverted present, yet CameraNear != float.MaxValue" ) ;
Debug . LogWarning ( "EnableDepthInfinite and EnableDepthInverted present, yet CameraNear != float.MaxValue" ) ;
}
}
}
}
if ( dispatchParams . CameraFar < 0.075f )
if ( dispatchParams . CameraFar < 0.075f )
{
{
Debug . LogWarning ( "EnableDepthInverted present, CameraFar value is very low which may result in depth separation artefacting" ) ;
Debug . LogWarning ( "EnableDepthInverted present, CameraFar value is very low which may result in depth separation artefacting" ) ;
@ -595,17 +595,17 @@ namespace FidelityFX.FSR2
new Fsr2 . RcasConstants ( 1 0 6 4 2 2 9 6 9 5 u , 9 9 7 6 0 4 2 1 4 u ) ,
new Fsr2 . RcasConstants ( 1 0 6 4 2 2 9 6 9 5 u , 9 9 7 6 0 4 2 1 4 u ) ,
new Fsr2 . RcasConstants ( 1 0 6 5 3 5 3 2 1 6 u , 1 0 0 6 6 4 8 3 2 0 ) ,
new Fsr2 . RcasConstants ( 1 0 6 5 3 5 3 2 1 6 u , 1 0 0 6 6 4 8 3 2 0 ) ,
} ;
} ;
private static ComputeBuffer CreateConstantBuffer < TConstants > ( ) where TConstants : struct
private static ComputeBuffer CreateConstantBuffer < TConstants > ( ) where TConstants : struct
{
{
return new ComputeBuffer ( 1 , Marshal . SizeOf < TConstants > ( ) , ComputeBufferType . Constant ) ;
return new ComputeBuffer ( 1 , Marshal . SizeOf < TConstants > ( ) , ComputeBufferType . Constant ) ;
}
}
private static void DestroyConstantBuffer ( ref ComputeBuffer bufferRef )
private static void DestroyConstantBuffer ( ref ComputeBuffer bufferRef )
{
{
if ( bufferRef = = null )
if ( bufferRef = = null )
return ;
return ;
bufferRef . Release ( ) ;
bufferRef . Release ( ) ;
bufferRef = null ;
bufferRef = null ;
}
}
@ -614,7 +614,7 @@ namespace FidelityFX.FSR2
{
{
if ( pass = = null )
if ( pass = = null )
return ;
return ;
pass . Dispose ( ) ;
pass . Dispose ( ) ;
pass = null ;
pass = null ;
}
}