Path: blob/master/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_hlsl.h
9899 views
// This file is part of the FidelityFX SDK.1//2// Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.3//4// Permission is hereby granted, free of charge, to any person obtaining a copy5// of this software and associated documentation files (the "Software"), to deal6// in the Software without restriction, including without limitation the rights7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell8// copies of the Software, and to permit persons to whom the Software is9// furnished to do so, subject to the following conditions:10// The above copyright notice and this permission notice shall be included in11// all copies or substantial portions of the Software.12//13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN19// THE SOFTWARE.2021#include "ffx_fsr2_resources.h"2223#if defined(FFX_GPU)24#ifdef __hlsl_dx_compiler25#pragma dxc diagnostic push26#pragma dxc diagnostic ignored "-Wambig-lit-shift"27#endif //__hlsl_dx_compiler28#include "ffx_core.h"29#ifdef __hlsl_dx_compiler30#pragma dxc diagnostic pop31#endif //__hlsl_dx_compiler32#endif // #if defined(FFX_GPU)3334#if defined(FFX_GPU)35#ifndef FFX_FSR2_PREFER_WAVE6436#define FFX_FSR2_PREFER_WAVE6437#endif // #if defined(FFX_GPU)3839#if defined(FFX_GPU)40#pragma warning(disable: 3205) // conversion from larger type to smaller41#endif // #if defined(FFX_GPU)4243#define DECLARE_SRV_REGISTER(regIndex) t##regIndex44#define DECLARE_UAV_REGISTER(regIndex) u##regIndex45#define DECLARE_CB_REGISTER(regIndex) b##regIndex46#define FFX_FSR2_DECLARE_SRV(regIndex) register(DECLARE_SRV_REGISTER(regIndex))47#define FFX_FSR2_DECLARE_UAV(regIndex) register(DECLARE_UAV_REGISTER(regIndex))48#define FFX_FSR2_DECLARE_CB(regIndex) register(DECLARE_CB_REGISTER(regIndex))4950#if defined(FSR2_BIND_CB_FSR2) || defined(FFX_INTERNAL)51cbuffer cbFSR2 : FFX_FSR2_DECLARE_CB(FSR2_BIND_CB_FSR2)52{53FfxInt32x2 iRenderSize;54FfxInt32x2 iMaxRenderSize;55FfxInt32x2 iDisplaySize;56FfxInt32x2 iInputColorResourceDimensions;57FfxInt32x2 iLumaMipDimensions;58FfxInt32 iLumaMipLevelToUse;59FfxInt32 iFrameIndex;6061FfxFloat32x4 fDeviceToViewDepth;62FfxFloat32x2 fJitter;63FfxFloat32x2 fMotionVectorScale;64FfxFloat32x2 fDownscaleFactor;65FfxFloat32x2 fMotionVectorJitterCancellation;66FfxFloat32 fPreExposure;67FfxFloat32 fPreviousFramePreExposure;68FfxFloat32 fTanHalfFOV;69FfxFloat32 fJitterSequenceLength;70FfxFloat32 fDeltaTime;71FfxFloat32 fDynamicResChangeFactor;72FfxFloat32 fViewSpaceToMetersFactor;73};7475#define FFX_FSR2_CONSTANT_BUFFER_1_SIZE (sizeof(cbFSR2) / 4) // Number of 32-bit values. This must be kept in sync with the cbFSR2 size.76#endif7778#if defined(FFX_GPU)79#define FFX_FSR2_ROOTSIG_STRINGIFY(p) FFX_FSR2_ROOTSIG_STR(p)80#define FFX_FSR2_ROOTSIG_STR(p) #p81#define FFX_FSR2_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_RESOURCE_IDENTIFIER_COUNT) ")), " \82"DescriptorTable(SRV(t0, numDescriptors = " FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_RESOURCE_IDENTIFIER_COUNT) ")), " \83"RootConstants(num32BitConstants=" FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_CONSTANT_BUFFER_1_SIZE) ", b0), " \84"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, " \85"addressU = TEXTURE_ADDRESS_CLAMP, " \86"addressV = TEXTURE_ADDRESS_CLAMP, " \87"addressW = TEXTURE_ADDRESS_CLAMP, " \88"comparisonFunc = COMPARISON_NEVER, " \89"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \90"StaticSampler(s1, filter = FILTER_MIN_MAG_MIP_LINEAR, " \91"addressU = TEXTURE_ADDRESS_CLAMP, " \92"addressV = TEXTURE_ADDRESS_CLAMP, " \93"addressW = TEXTURE_ADDRESS_CLAMP, " \94"comparisonFunc = COMPARISON_NEVER, " \95"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]9697#define FFX_FSR2_CONSTANT_BUFFER_2_SIZE 6 // Number of 32-bit values. This must be kept in sync with max( cbRCAS , cbSPD) size.9899#define FFX_FSR2_CB2_ROOTSIG [RootSignature( "DescriptorTable(UAV(u0, numDescriptors = " FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_RESOURCE_IDENTIFIER_COUNT) ")), " \100"DescriptorTable(SRV(t0, numDescriptors = " FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_RESOURCE_IDENTIFIER_COUNT) ")), " \101"RootConstants(num32BitConstants=" FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_CONSTANT_BUFFER_1_SIZE) ", b0), " \102"RootConstants(num32BitConstants=" FFX_FSR2_ROOTSIG_STRINGIFY(FFX_FSR2_CONSTANT_BUFFER_2_SIZE) ", b1), " \103"StaticSampler(s0, filter = FILTER_MIN_MAG_MIP_POINT, " \104"addressU = TEXTURE_ADDRESS_CLAMP, " \105"addressV = TEXTURE_ADDRESS_CLAMP, " \106"addressW = TEXTURE_ADDRESS_CLAMP, " \107"comparisonFunc = COMPARISON_NEVER, " \108"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK), " \109"StaticSampler(s1, filter = FILTER_MIN_MAG_MIP_LINEAR, " \110"addressU = TEXTURE_ADDRESS_CLAMP, " \111"addressV = TEXTURE_ADDRESS_CLAMP, " \112"addressW = TEXTURE_ADDRESS_CLAMP, " \113"comparisonFunc = COMPARISON_NEVER, " \114"borderColor = STATIC_BORDER_COLOR_TRANSPARENT_BLACK)" )]115#if defined(FFX_FSR2_EMBED_ROOTSIG)116#define FFX_FSR2_EMBED_ROOTSIG_CONTENT FFX_FSR2_ROOTSIG117#define FFX_FSR2_EMBED_CB2_ROOTSIG_CONTENT FFX_FSR2_CB2_ROOTSIG118#else119#define FFX_FSR2_EMBED_ROOTSIG_CONTENT120#define FFX_FSR2_EMBED_CB2_ROOTSIG_CONTENT121#endif // #if FFX_FSR2_EMBED_ROOTSIG122#endif // #if defined(FFX_GPU)123124/* Define getter functions in the order they are defined in the CB! */125FfxInt32x2 RenderSize()126{127return iRenderSize;128}129130FfxInt32x2 MaxRenderSize()131{132return iMaxRenderSize;133}134135FfxInt32x2 DisplaySize()136{137return iDisplaySize;138}139140FfxInt32x2 InputColorResourceDimensions()141{142return iInputColorResourceDimensions;143}144145FfxInt32x2 LumaMipDimensions()146{147return iLumaMipDimensions;148}149150FfxInt32 LumaMipLevelToUse()151{152return iLumaMipLevelToUse;153}154155FfxInt32 FrameIndex()156{157return iFrameIndex;158}159160FfxFloat32x2 Jitter()161{162return fJitter;163}164165FfxFloat32x4 DeviceToViewSpaceTransformFactors()166{167return fDeviceToViewDepth;168}169170FfxFloat32x2 MotionVectorScale()171{172return fMotionVectorScale;173}174175FfxFloat32x2 DownscaleFactor()176{177return fDownscaleFactor;178}179180FfxFloat32x2 MotionVectorJitterCancellation()181{182return fMotionVectorJitterCancellation;183}184185FfxFloat32 PreExposure()186{187return fPreExposure;188}189190FfxFloat32 PreviousFramePreExposure()191{192return fPreviousFramePreExposure;193}194195FfxFloat32 TanHalfFoV()196{197return fTanHalfFOV;198}199200FfxFloat32 JitterSequenceLength()201{202return fJitterSequenceLength;203}204205FfxFloat32 DeltaTime()206{207return fDeltaTime;208}209210FfxFloat32 DynamicResChangeFactor()211{212return fDynamicResChangeFactor;213}214215FfxFloat32 ViewSpaceToMetersFactor()216{217return fViewSpaceToMetersFactor;218}219220221SamplerState s_PointClamp : register(s0);222SamplerState s_LinearClamp : register(s1);223224// SRVs225#if defined(FFX_INTERNAL)226Texture2D<FfxFloat32x4> r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_OPAQUE_ONLY);227Texture2D<FfxFloat32x4> r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_COLOR);228Texture2D<FfxFloat32x4> r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS);229Texture2D<FfxFloat32> r_input_depth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_DEPTH);230Texture2D<FfxFloat32x2> r_input_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_EXPOSURE);231Texture2D<FfxFloat32x2> r_auto_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE);232Texture2D<FfxFloat32> r_reactive_mask : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_REACTIVE_MASK);233Texture2D<FfxFloat32> r_transparency_and_composition_mask : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_TRANSPARENCY_AND_COMPOSITION_MASK);234Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_RECONSTRUCTED_PREVIOUS_NEAREST_DEPTH);235Texture2D<FfxFloat32x2> r_dilated_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_MOTION_VECTORS);236Texture2D<FfxFloat32x2> r_previous_dilated_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREVIOUS_DILATED_MOTION_VECTORS);237Texture2D<FfxFloat32> r_dilatedDepth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_DEPTH);238Texture2D<FfxFloat32x4> r_internal_upscaled_color : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR);239Texture2D<unorm FfxFloat32x2> r_lock_status : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_LOCK_STATUS);240Texture2D<FfxFloat32> r_lock_input_luma : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_LOCK_INPUT_LUMA);241Texture2D<unorm FfxFloat32> r_new_locks : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_NEW_LOCKS);242Texture2D<FfxFloat32x4> r_prepared_input_color : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREPARED_INPUT_COLOR);243Texture2D<FfxFloat32x4> r_luma_history : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_LUMA_HISTORY);244Texture2D<FfxFloat32x4> r_rcas_input : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_RCAS_INPUT);245Texture2D<FfxFloat32> r_lanczos_lut : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_LANCZOS_LUT);246Texture2D<FfxFloat32> r_imgMips : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_SCENE_LUMINANCE);247Texture2D<FfxFloat32> r_upsample_maximum_bias_lut : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTITIER_UPSAMPLE_MAXIMUM_BIAS_LUT);248Texture2D<unorm FfxFloat32x2> r_dilated_reactive_masks : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_REACTIVE_MASKS);249Texture2D<float3> r_input_prev_color_pre_alpha : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_PRE_ALPHA_COLOR);250Texture2D<float3> r_input_prev_color_post_alpha : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_POST_ALPHA_COLOR);251252Texture2D<FfxFloat32x4> r_debug_out : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_DEBUG_OUTPUT);253254// UAV declarations255RWTexture2D<FfxUInt32> rw_reconstructed_previous_nearest_depth : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_RECONSTRUCTED_PREVIOUS_NEAREST_DEPTH);256RWTexture2D<FfxFloat32x2> rw_dilated_motion_vectors : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_MOTION_VECTORS);257RWTexture2D<FfxFloat32> rw_dilatedDepth : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_DEPTH);258RWTexture2D<FfxFloat32x4> rw_internal_upscaled_color : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_INTERNAL_UPSCALED_COLOR);259RWTexture2D<unorm FfxFloat32x2> rw_lock_status : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_LOCK_STATUS);260RWTexture2D<FfxFloat32> rw_lock_input_luma : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_LOCK_INPUT_LUMA);261RWTexture2D<unorm FfxFloat32> rw_new_locks : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_NEW_LOCKS);262RWTexture2D<FfxFloat32x4> rw_prepared_input_color : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_PREPARED_INPUT_COLOR);263RWTexture2D<FfxFloat32x4> rw_luma_history : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_LUMA_HISTORY);264RWTexture2D<FfxFloat32x4> rw_upscaled_output : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_UPSCALED_OUTPUT);265266globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_shading_change : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_SHADING_CHANGE);267globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_5 : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_SCENE_LUMINANCE_MIPMAP_5);268RWTexture2D<unorm FfxFloat32x2> rw_dilated_reactive_masks : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_DILATED_REACTIVE_MASKS);269RWTexture2D<FfxFloat32x2> rw_auto_exposure : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE);270globallycoherent RWTexture2D<FfxUInt32> rw_spd_global_atomic : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_SPD_ATOMIC_COUNT);271RWTexture2D<FfxFloat32x4> rw_debug_out : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_DEBUG_OUTPUT);272273RWTexture2D<float> rw_output_autoreactive : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTOREACTIVE);274RWTexture2D<float> rw_output_autocomposition : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTOCOMPOSITION);275RWTexture2D<float3> rw_output_prev_color_pre_alpha : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_PRE_ALPHA_COLOR);276RWTexture2D<float3> rw_output_prev_color_post_alpha : FFX_FSR2_DECLARE_UAV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_POST_ALPHA_COLOR);277278#else // #if defined(FFX_INTERNAL)279#if defined FSR2_BIND_SRV_INPUT_COLOR280Texture2D<FfxFloat32x4> r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR);281#endif282#if defined FSR2_BIND_SRV_INPUT_OPAQUE_ONLY283Texture2D<FfxFloat32x4> r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);284#endif285#if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS286Texture2D<FfxFloat32x4> r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS);287#endif288#if defined FSR2_BIND_SRV_INPUT_DEPTH289Texture2D<FfxFloat32> r_input_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH);290#endif291#if defined FSR2_BIND_SRV_INPUT_EXPOSURE292Texture2D<FfxFloat32x2> r_input_exposure : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_EXPOSURE);293#endif294#if defined FSR2_BIND_SRV_AUTO_EXPOSURE295Texture2D<FfxFloat32x2> r_auto_exposure : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_AUTO_EXPOSURE);296#endif297#if defined FSR2_BIND_SRV_REACTIVE_MASK298Texture2D<FfxFloat32> r_reactive_mask : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_REACTIVE_MASK);299#endif300#if defined FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK301Texture2D<FfxFloat32> r_transparency_and_composition_mask : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);302#endif303#if defined FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH304Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH);305#endif306#if defined FSR2_BIND_SRV_DILATED_MOTION_VECTORS307Texture2D<FfxFloat32x2> r_dilated_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_DILATED_MOTION_VECTORS);308#endif309#if defined FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS310Texture2D<FfxFloat32x2> r_previous_dilated_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS);311#endif312#if defined FSR2_BIND_SRV_DILATED_DEPTH313Texture2D<FfxFloat32> r_dilatedDepth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_DILATED_DEPTH);314#endif315#if defined FSR2_BIND_SRV_INTERNAL_UPSCALED316Texture2D<FfxFloat32x4> r_internal_upscaled_color : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INTERNAL_UPSCALED);317#endif318#if defined FSR2_BIND_SRV_LOCK_STATUS319Texture2D<unorm FfxFloat32x2> r_lock_status : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_LOCK_STATUS);320#endif321#if defined FSR2_BIND_SRV_LOCK_INPUT_LUMA322Texture2D<FfxFloat32> r_lock_input_luma : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_LOCK_INPUT_LUMA);323#endif324#if defined FSR2_BIND_SRV_NEW_LOCKS325Texture2D<unorm FfxFloat32> r_new_locks : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_NEW_LOCKS);326#endif327#if defined FSR2_BIND_SRV_PREPARED_INPUT_COLOR328Texture2D<FfxFloat32x4> r_prepared_input_color : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_PREPARED_INPUT_COLOR);329#endif330#if defined FSR2_BIND_SRV_LUMA_HISTORY331Texture2D<unorm FfxFloat32x4> r_luma_history : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_LUMA_HISTORY);332#endif333#if defined FSR2_BIND_SRV_RCAS_INPUT334Texture2D<FfxFloat32x4> r_rcas_input : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_RCAS_INPUT);335#endif336#if defined FSR2_BIND_SRV_LANCZOS_LUT337Texture2D<FfxFloat32> r_lanczos_lut : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_LANCZOS_LUT);338#endif339#if defined FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS340Texture2D<FfxFloat32> r_imgMips : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS);341#endif342#if defined FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT343Texture2D<FfxFloat32> r_upsample_maximum_bias_lut : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT);344#endif345#if defined FSR2_BIND_SRV_DILATED_REACTIVE_MASKS346Texture2D<unorm FfxFloat32x2> r_dilated_reactive_masks : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS);347#endif348349#if defined FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR350Texture2D<float3> r_input_prev_color_pre_alpha : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_PRE_ALPHA_COLOR);351#endif352#if defined FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR353Texture2D<float3> r_input_prev_color_post_alpha : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_PREV_POST_ALPHA_COLOR);354#endif355356// UAV declarations357#if defined FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH358RWTexture2D<FfxUInt32> rw_reconstructed_previous_nearest_depth : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH);359#endif360#if defined FSR2_BIND_UAV_DILATED_MOTION_VECTORS361RWTexture2D<FfxFloat32x2> rw_dilated_motion_vectors : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_DILATED_MOTION_VECTORS);362#endif363#if defined FSR2_BIND_UAV_DILATED_DEPTH364RWTexture2D<FfxFloat32> rw_dilatedDepth : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_DILATED_DEPTH);365#endif366#if defined FSR2_BIND_UAV_INTERNAL_UPSCALED367RWTexture2D<FfxFloat32x4> rw_internal_upscaled_color : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_INTERNAL_UPSCALED);368#endif369#if defined FSR2_BIND_UAV_LOCK_STATUS370RWTexture2D<unorm FfxFloat32x2> rw_lock_status : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LOCK_STATUS);371#endif372#if defined FSR2_BIND_UAV_LOCK_INPUT_LUMA373RWTexture2D<FfxFloat32> rw_lock_input_luma : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LOCK_INPUT_LUMA);374#endif375#if defined FSR2_BIND_UAV_NEW_LOCKS376RWTexture2D<unorm FfxFloat32> rw_new_locks : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_NEW_LOCKS);377#endif378#if defined FSR2_BIND_UAV_PREPARED_INPUT_COLOR379RWTexture2D<FfxFloat32x4> rw_prepared_input_color : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_PREPARED_INPUT_COLOR);380#endif381#if defined FSR2_BIND_UAV_LUMA_HISTORY382RWTexture2D<FfxFloat32x4> rw_luma_history : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LUMA_HISTORY);383#endif384#if defined FSR2_BIND_UAV_UPSCALED_OUTPUT385RWTexture2D<FfxFloat32x4> rw_upscaled_output : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_UPSCALED_OUTPUT);386#endif387#if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE388globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_shading_change : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE);389#endif390#if defined FSR2_BIND_UAV_EXPOSURE_MIP_5391globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_5 : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE_MIP_5);392#endif393#if defined FSR2_BIND_UAV_DILATED_REACTIVE_MASKS394RWTexture2D<unorm FfxFloat32x2> rw_dilated_reactive_masks : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_DILATED_REACTIVE_MASKS);395#endif396#if defined FSR2_BIND_UAV_EXPOSURE397RWTexture2D<FfxFloat32x2> rw_exposure : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE);398#endif399#if defined FSR2_BIND_UAV_AUTO_EXPOSURE400RWTexture2D<FfxFloat32x2> rw_auto_exposure : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_AUTO_EXPOSURE);401#endif402#if defined FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC403globallycoherent RWTexture2D<FfxUInt32> rw_spd_global_atomic : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC);404#endif405406#if defined FSR2_BIND_UAV_AUTOREACTIVE407RWTexture2D<float> rw_output_autoreactive : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_AUTOREACTIVE);408#endif409#if defined FSR2_BIND_UAV_AUTOCOMPOSITION410RWTexture2D<float> rw_output_autocomposition : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_AUTOCOMPOSITION);411#endif412#if defined FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR413RWTexture2D<float3> rw_output_prev_color_pre_alpha : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR);414#endif415#if defined FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR416RWTexture2D<float3> rw_output_prev_color_post_alpha : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR);417#endif418#endif // #if defined(FFX_INTERNAL)419420#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS) || defined(FFX_INTERNAL)421FfxFloat32 LoadMipLuma(FfxUInt32x2 iPxPos, FfxUInt32 mipLevel)422{423return r_imgMips.mips[mipLevel][iPxPos];424}425#endif426427#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS) || defined(FFX_INTERNAL)428FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxUInt32 mipLevel)429{430return r_imgMips.SampleLevel(s_LinearClamp, fUV, mipLevel);431}432#endif433434#if defined(FSR2_BIND_SRV_INPUT_DEPTH) || defined(FFX_INTERNAL)435FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos)436{437return r_input_depth[iPxPos];438}439#endif440441#if defined(FSR2_BIND_SRV_INPUT_DEPTH) || defined(FFX_INTERNAL)442FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)443{444return r_input_depth.SampleLevel(s_LinearClamp, fUV, 0).x;445}446#endif447448#if defined(FSR2_BIND_SRV_REACTIVE_MASK) || defined(FFX_INTERNAL)449FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)450{451return r_reactive_mask[iPxPos];452}453#endif454455#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK) || defined(FFX_INTERNAL)456FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)457{458return r_transparency_and_composition_mask[iPxPos];459}460#endif461462#if defined(FSR2_BIND_SRV_INPUT_COLOR) || defined(FFX_INTERNAL)463FfxFloat32x3 LoadInputColor(FfxUInt32x2 iPxPos)464{465return r_input_color_jittered[iPxPos].rgb;466}467#endif468469#if defined(FSR2_BIND_SRV_INPUT_COLOR) || defined(FFX_INTERNAL)470FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)471{472return r_input_color_jittered.SampleLevel(s_LinearClamp, fUV, 0).rgb;473}474#endif475476#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR) || defined(FFX_INTERNAL)477FfxFloat32x3 LoadPreparedInputColor(FfxUInt32x2 iPxPos)478{479return r_prepared_input_color[iPxPos].xyz;480}481#endif482483#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS) || defined(FFX_INTERNAL)484FfxFloat32x2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos)485{486FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[iPxDilatedMotionVectorPos].xy;487488FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();489490#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS491fUvMotionVector -= MotionVectorJitterCancellation();492#endif493494return fUvMotionVector;495}496#endif497498#if defined(FSR2_BIND_SRV_INTERNAL_UPSCALED) || defined(FFX_INTERNAL)499FfxFloat32x4 LoadHistory(FfxUInt32x2 iPxHistory)500{501return r_internal_upscaled_color[iPxHistory];502}503#endif504505#if defined(FSR2_BIND_UAV_LUMA_HISTORY) || defined(FFX_INTERNAL)506void StoreLumaHistory(FfxUInt32x2 iPxPos, FfxFloat32x4 fLumaHistory)507{508rw_luma_history[iPxPos] = fLumaHistory;509}510#endif511512#if defined(FSR2_BIND_SRV_LUMA_HISTORY) || defined(FFX_INTERNAL)513FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV)514{515return r_luma_history.SampleLevel(s_LinearClamp, fUV, 0);516}517#endif518519#if defined(FFX_INTERNAL)520FfxFloat32x4 SampleDebug(FfxFloat32x2 fUV)521{522return r_debug_out.SampleLevel(s_LinearClamp, fUV, 0).w;523}524#endif525526#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED) || defined(FFX_INTERNAL)527void StoreReprojectedHistory(FfxUInt32x2 iPxHistory, FfxFloat32x4 fHistory)528{529rw_internal_upscaled_color[iPxHistory] = fHistory;530}531#endif532533#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED) || defined(FFX_INTERNAL)534void StoreInternalColorAndWeight(FfxUInt32x2 iPxPos, FfxFloat32x4 fColorAndWeight)535{536rw_internal_upscaled_color[iPxPos] = fColorAndWeight;537}538#endif539540#if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT) || defined(FFX_INTERNAL)541void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)542{543rw_upscaled_output[iPxPos] = FfxFloat32x4(fColor, 1.f);544}545#endif546547//LOCK_LIFETIME_REMAINING == 0548//Should make LockInitialLifetime() return a const 1.0f later549#if defined(FSR2_BIND_SRV_LOCK_STATUS) || defined(FFX_INTERNAL)550FfxFloat32x2 LoadLockStatus(FfxUInt32x2 iPxPos)551{552return r_lock_status[iPxPos];553}554#endif555556#if defined(FSR2_BIND_UAV_LOCK_STATUS) || defined(FFX_INTERNAL)557void StoreLockStatus(FfxUInt32x2 iPxPos, FfxFloat32x2 fLockStatus)558{559rw_lock_status[iPxPos] = fLockStatus;560}561#endif562563#if defined(FSR2_BIND_SRV_LOCK_INPUT_LUMA) || defined(FFX_INTERNAL)564FfxFloat32 LoadLockInputLuma(FfxUInt32x2 iPxPos)565{566return r_lock_input_luma[iPxPos];567}568#endif569570#if defined(FSR2_BIND_UAV_LOCK_INPUT_LUMA) || defined(FFX_INTERNAL)571void StoreLockInputLuma(FfxUInt32x2 iPxPos, FfxFloat32 fLuma)572{573rw_lock_input_luma[iPxPos] = fLuma;574}575#endif576577#if defined(FSR2_BIND_SRV_NEW_LOCKS) || defined(FFX_INTERNAL)578FfxFloat32 LoadNewLocks(FfxUInt32x2 iPxPos)579{580return r_new_locks[iPxPos];581}582#endif583584#if defined(FSR2_BIND_UAV_NEW_LOCKS) || defined(FFX_INTERNAL)585FfxFloat32 LoadRwNewLocks(FfxUInt32x2 iPxPos)586{587return rw_new_locks[iPxPos];588}589#endif590591#if defined(FSR2_BIND_UAV_NEW_LOCKS) || defined(FFX_INTERNAL)592void StoreNewLocks(FfxUInt32x2 iPxPos, FfxFloat32 newLock)593{594rw_new_locks[iPxPos] = newLock;595}596#endif597598#if defined(FSR2_BIND_UAV_PREPARED_INPUT_COLOR) || defined(FFX_INTERNAL)599void StorePreparedInputColor(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x4 fTonemapped)600{601rw_prepared_input_color[iPxPos] = fTonemapped;602}603#endif604605#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR) || defined(FFX_INTERNAL)606FfxFloat32 SampleDepthClip(FfxFloat32x2 fUV)607{608return r_prepared_input_color.SampleLevel(s_LinearClamp, fUV, 0).w;609}610#endif611612#if defined(FSR2_BIND_SRV_LOCK_STATUS) || defined(FFX_INTERNAL)613FfxFloat32x2 SampleLockStatus(FfxFloat32x2 fUV)614{615FfxFloat32x2 fLockStatus = r_lock_status.SampleLevel(s_LinearClamp, fUV, 0);616return fLockStatus;617}618#endif619620#if defined(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH) || defined(FFX_INTERNAL)621FfxFloat32 LoadReconstructedPrevDepth(FfxUInt32x2 iPxPos)622{623return asfloat(r_reconstructed_previous_nearest_depth[iPxPos]);624}625#endif626627#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH) || defined(FFX_INTERNAL)628void StoreReconstructedDepth(FfxUInt32x2 iPxSample, FfxFloat32 fDepth)629{630FfxUInt32 uDepth = asuint(fDepth);631632#if FFX_FSR2_OPTION_INVERTED_DEPTH633InterlockedMax(rw_reconstructed_previous_nearest_depth[iPxSample], uDepth);634#else635InterlockedMin(rw_reconstructed_previous_nearest_depth[iPxSample], uDepth); // min for standard, max for inverted depth636#endif637}638#endif639640#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH) || defined(FFX_INTERNAL)641void SetReconstructedDepth(FfxUInt32x2 iPxSample, const FfxUInt32 uValue)642{643rw_reconstructed_previous_nearest_depth[iPxSample] = uValue;644}645#endif646647#if defined(FSR2_BIND_UAV_DILATED_DEPTH) || defined(FFX_INTERNAL)648void StoreDilatedDepth(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32 fDepth)649{650rw_dilatedDepth[iPxPos] = fDepth;651}652#endif653654#if defined(FSR2_BIND_UAV_DILATED_MOTION_VECTORS) || defined(FFX_INTERNAL)655void StoreDilatedMotionVector(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fMotionVector)656{657rw_dilated_motion_vectors[iPxPos] = fMotionVector;658}659#endif660661#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS) || defined(FFX_INTERNAL)662FfxFloat32x2 LoadDilatedMotionVector(FfxUInt32x2 iPxInput)663{664return r_dilated_motion_vectors[iPxInput].xy;665}666#endif667668#if defined(FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS) || defined(FFX_INTERNAL)669FfxFloat32x2 LoadPreviousDilatedMotionVector(FfxUInt32x2 iPxInput)670{671return r_previous_dilated_motion_vectors[iPxInput].xy;672}673674FfxFloat32x2 SamplePreviousDilatedMotionVector(FfxFloat32x2 uv)675{676return r_previous_dilated_motion_vectors.SampleLevel(s_LinearClamp, uv, 0).xy;677}678#endif679680#if defined(FSR2_BIND_SRV_DILATED_DEPTH) || defined(FFX_INTERNAL)681FfxFloat32 LoadDilatedDepth(FfxUInt32x2 iPxInput)682{683return r_dilatedDepth[iPxInput];684}685#endif686687#if defined(FSR2_BIND_SRV_INPUT_EXPOSURE) || defined(FFX_INTERNAL)688FfxFloat32 Exposure()689{690FfxFloat32 exposure = r_input_exposure[FfxUInt32x2(0, 0)].x;691692if (exposure == 0.0f) {693exposure = 1.0f;694}695696return exposure;697}698#endif699700#if defined(FSR2_BIND_SRV_AUTO_EXPOSURE) || defined(FFX_INTERNAL)701FfxFloat32 AutoExposure()702{703FfxFloat32 exposure = r_auto_exposure[FfxUInt32x2(0, 0)].x;704705if (exposure == 0.0f) {706exposure = 1.0f;707}708709return exposure;710}711#endif712713FfxFloat32 SampleLanczos2Weight(FfxFloat32 x)714{715#if defined(FSR2_BIND_SRV_LANCZOS_LUT) || defined(FFX_INTERNAL)716return r_lanczos_lut.SampleLevel(s_LinearClamp, FfxFloat32x2(x / 2, 0.5f), 0);717#else718return 0.f;719#endif720}721722#if defined(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT) || defined(FFX_INTERNAL)723FfxFloat32 SampleUpsampleMaximumBias(FfxFloat32x2 uv)724{725// Stored as a SNORM, so make sure to multiply by 2 to retrieve the actual expected range.726return FfxFloat32(2.0) * r_upsample_maximum_bias_lut.SampleLevel(s_LinearClamp, abs(uv) * 2.0, 0);727}728#endif729730#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS) || defined(FFX_INTERNAL)731FfxFloat32x2 SampleDilatedReactiveMasks(FfxFloat32x2 fUV)732{733return r_dilated_reactive_masks.SampleLevel(s_LinearClamp, fUV, 0);734}735#endif736737#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS) || defined(FFX_INTERNAL)738FfxFloat32x2 LoadDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos)739{740return r_dilated_reactive_masks[iPxPos];741}742#endif743744#if defined(FSR2_BIND_UAV_DILATED_REACTIVE_MASKS) || defined(FFX_INTERNAL)745void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fDilatedReactiveMasks)746{747rw_dilated_reactive_masks[iPxPos] = fDilatedReactiveMasks;748}749#endif750751#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY) || defined(FFX_INTERNAL)752FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)753{754return r_input_opaque_only[iPxPos].xyz;755}756#endif757758#if defined(FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR) || defined(FFX_INTERNAL)759FfxFloat32x3 LoadPrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)760{761return r_input_prev_color_pre_alpha[iPxPos];762}763#endif764765#if defined(FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR) || defined(FFX_INTERNAL)766FfxFloat32x3 LoadPrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)767{768return r_input_prev_color_post_alpha[iPxPos];769}770#endif771772#if defined(FSR2_BIND_UAV_AUTOREACTIVE) || defined(FFX_INTERNAL)773#if defined(FSR2_BIND_UAV_AUTOCOMPOSITION) || defined(FFX_INTERNAL)774void StoreAutoReactive(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F2 fReactive)775{776rw_output_autoreactive[iPxPos] = fReactive.x;777778rw_output_autocomposition[iPxPos] = fReactive.y;779}780#endif781#endif782783#if defined(FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR) || defined(FFX_INTERNAL)784void StorePrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)785{786rw_output_prev_color_pre_alpha[iPxPos] = color;787788}789#endif790791#if defined(FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR) || defined(FFX_INTERNAL)792void StorePrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)793{794rw_output_prev_color_post_alpha[iPxPos] = color;795}796#endif797798#endif // #if defined(FFX_GPU)799800801