Path: blob/master/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
9900 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.20#include "ffx_fsr2_resources.h"2122#if defined(FFX_GPU)23#include "ffx_core.h"24#endif // #if defined(FFX_GPU)2526#if defined(FFX_GPU)27#ifndef FFX_FSR2_PREFER_WAVE6428#define FFX_FSR2_PREFER_WAVE6429#endif // #if defined(FFX_GPU)3031#if defined(FSR2_BIND_CB_FSR2)32layout (set = 1, binding = FSR2_BIND_CB_FSR2, std140) uniform cbFSR2_t33{34FfxInt32x2 iRenderSize;35FfxInt32x2 iMaxRenderSize;36FfxInt32x2 iDisplaySize;37FfxInt32x2 iInputColorResourceDimensions;38FfxInt32x2 iLumaMipDimensions;39FfxInt32 iLumaMipLevelToUse;40FfxInt32 iFrameIndex;4142FfxFloat32x4 fDeviceToViewDepth;43FfxFloat32x2 fJitter;44FfxFloat32x2 fMotionVectorScale;45FfxFloat32x2 fDownscaleFactor;46FfxFloat32x2 fMotionVectorJitterCancellation;47FfxFloat32 fPreExposure;48FfxFloat32 fPreviousFramePreExposure;49FfxFloat32 fTanHalfFOV;50FfxFloat32 fJitterSequenceLength;51FfxFloat32 fDeltaTime;52FfxFloat32 fDynamicResChangeFactor;53FfxFloat32 fViewSpaceToMetersFactor;5455FfxFloat32 fPad;56mat4 mReprojectionMatrix;57} cbFSR2;58#endif5960FfxInt32x2 RenderSize()61{62return cbFSR2.iRenderSize;63}6465FfxInt32x2 MaxRenderSize()66{67return cbFSR2.iMaxRenderSize;68}6970FfxInt32x2 DisplaySize()71{72return cbFSR2.iDisplaySize;73}7475FfxInt32x2 InputColorResourceDimensions()76{77return cbFSR2.iInputColorResourceDimensions;78}7980FfxInt32x2 LumaMipDimensions()81{82return cbFSR2.iLumaMipDimensions;83}8485FfxInt32 LumaMipLevelToUse()86{87return cbFSR2.iLumaMipLevelToUse;88}8990FfxInt32 FrameIndex()91{92return cbFSR2.iFrameIndex;93}9495FfxFloat32x4 DeviceToViewSpaceTransformFactors()96{97return cbFSR2.fDeviceToViewDepth;98}99100FfxFloat32x2 Jitter()101{102return cbFSR2.fJitter;103}104105FfxFloat32x2 MotionVectorScale()106{107return cbFSR2.fMotionVectorScale;108}109110FfxFloat32x2 DownscaleFactor()111{112return cbFSR2.fDownscaleFactor;113}114115FfxFloat32x2 MotionVectorJitterCancellation()116{117return cbFSR2.fMotionVectorJitterCancellation;118}119120FfxFloat32 PreExposure()121{122return cbFSR2.fPreExposure;123}124125FfxFloat32 PreviousFramePreExposure()126{127return cbFSR2.fPreviousFramePreExposure;128}129130FfxFloat32 TanHalfFoV()131{132return cbFSR2.fTanHalfFOV;133}134135FfxFloat32 JitterSequenceLength()136{137return cbFSR2.fJitterSequenceLength;138}139140FfxFloat32 DeltaTime()141{142return cbFSR2.fDeltaTime;143}144145FfxFloat32 DynamicResChangeFactor()146{147return cbFSR2.fDynamicResChangeFactor;148}149150FfxFloat32 ViewSpaceToMetersFactor()151{152return cbFSR2.fViewSpaceToMetersFactor;153}154155layout (set = 0, binding = 0) uniform sampler s_PointClamp;156layout (set = 0, binding = 1) uniform sampler s_LinearClamp;157158// SRVs159#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)160layout (set = 1, binding = FSR2_BIND_SRV_INPUT_OPAQUE_ONLY) uniform texture2D r_input_opaque_only;161#endif162#if defined(FSR2_BIND_SRV_INPUT_COLOR)163layout (set = 1, binding = FSR2_BIND_SRV_INPUT_COLOR) uniform texture2D r_input_color_jittered;164#endif165#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)166layout (set = 1, binding = FSR2_BIND_SRV_INPUT_MOTION_VECTORS) uniform texture2D r_input_motion_vectors;167#endif168#if defined(FSR2_BIND_SRV_INPUT_DEPTH)169layout (set = 1, binding = FSR2_BIND_SRV_INPUT_DEPTH) uniform texture2D r_input_depth;170#endif171#if defined(FSR2_BIND_SRV_INPUT_EXPOSURE)172layout (set = 1, binding = FSR2_BIND_SRV_INPUT_EXPOSURE) uniform texture2D r_input_exposure;173#endif174#if defined(FSR2_BIND_SRV_AUTO_EXPOSURE)175layout(set = 1, binding = FSR2_BIND_SRV_AUTO_EXPOSURE) uniform texture2D r_auto_exposure;176#endif177#if defined(FSR2_BIND_SRV_REACTIVE_MASK)178layout (set = 1, binding = FSR2_BIND_SRV_REACTIVE_MASK) uniform texture2D r_reactive_mask;179#endif180#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)181layout (set = 1, binding = FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK) uniform texture2D r_transparency_and_composition_mask;182#endif183#if defined(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)184layout (set = 1, binding = FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH) uniform utexture2D r_reconstructed_previous_nearest_depth;185#endif186#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)187layout (set = 1, binding = FSR2_BIND_SRV_DILATED_MOTION_VECTORS) uniform texture2D r_dilated_motion_vectors;188#endif189#if defined (FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS)190layout(set = 1, binding = FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS) uniform texture2D r_previous_dilated_motion_vectors;191#endif192#if defined(FSR2_BIND_SRV_DILATED_DEPTH)193layout (set = 1, binding = FSR2_BIND_SRV_DILATED_DEPTH) uniform texture2D r_dilatedDepth;194#endif195#if defined(FSR2_BIND_SRV_INTERNAL_UPSCALED)196layout (set = 1, binding = FSR2_BIND_SRV_INTERNAL_UPSCALED) uniform texture2D r_internal_upscaled_color;197#endif198#if defined(FSR2_BIND_SRV_LOCK_STATUS)199layout (set = 1, binding = FSR2_BIND_SRV_LOCK_STATUS) uniform texture2D r_lock_status;200#endif201#if defined(FSR2_BIND_SRV_LOCK_INPUT_LUMA)202layout (set = 1, binding = FSR2_BIND_SRV_LOCK_INPUT_LUMA) uniform texture2D r_lock_input_luma;203#endif204#if defined(FSR2_BIND_SRV_NEW_LOCKS)205layout(set = 1, binding = FSR2_BIND_SRV_NEW_LOCKS) uniform texture2D r_new_locks;206#endif207#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)208layout (set = 1, binding = FSR2_BIND_SRV_PREPARED_INPUT_COLOR) uniform texture2D r_prepared_input_color;209#endif210#if defined(FSR2_BIND_SRV_LUMA_HISTORY)211layout (set = 1, binding = FSR2_BIND_SRV_LUMA_HISTORY) uniform texture2D r_luma_history;212#endif213#if defined(FSR2_BIND_SRV_RCAS_INPUT)214layout (set = 1, binding = FSR2_BIND_SRV_RCAS_INPUT) uniform texture2D r_rcas_input;215#endif216#if defined(FSR2_BIND_SRV_LANCZOS_LUT)217layout (set = 1, binding = FSR2_BIND_SRV_LANCZOS_LUT) uniform texture2D r_lanczos_lut;218#endif219#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)220layout (set = 1, binding = FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS) uniform texture2D r_imgMips;221#endif222#if defined(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT)223layout (set = 1, binding = FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT) uniform texture2D r_upsample_maximum_bias_lut;224#endif225#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)226layout (set = 1, binding = FSR2_BIND_SRV_DILATED_REACTIVE_MASKS) uniform texture2D r_dilated_reactive_masks;227#endif228#if defined(FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR)229layout(set = 1, binding = FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR) uniform texture2D r_input_prev_color_pre_alpha;230#endif231#if defined(FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR)232layout(set = 1, binding = FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR) uniform texture2D r_input_prev_color_post_alpha;233#endif234235// UAV236#if defined FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH237layout (set = 1, binding = FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH, r32ui) uniform uimage2D rw_reconstructed_previous_nearest_depth;238#endif239#if defined FSR2_BIND_UAV_DILATED_MOTION_VECTORS240layout (set = 1, binding = FSR2_BIND_UAV_DILATED_MOTION_VECTORS, rg16f) writeonly uniform image2D rw_dilated_motion_vectors;241#endif242#if defined FSR2_BIND_UAV_DILATED_DEPTH243layout (set = 1, binding = FSR2_BIND_UAV_DILATED_DEPTH, r16f) writeonly uniform image2D rw_dilatedDepth;244#endif245#if defined FSR2_BIND_UAV_INTERNAL_UPSCALED246layout (set = 1, binding = FSR2_BIND_UAV_INTERNAL_UPSCALED, rgba16f) writeonly uniform image2D rw_internal_upscaled_color;247#endif248#if defined FSR2_BIND_UAV_LOCK_STATUS249layout (set = 1, binding = FSR2_BIND_UAV_LOCK_STATUS, rg16f) uniform image2D rw_lock_status;250#endif251#if defined(FSR2_BIND_UAV_LOCK_INPUT_LUMA)252layout(set = 1, binding = FSR2_BIND_UAV_LOCK_INPUT_LUMA, r16f) writeonly uniform image2D rw_lock_input_luma;253#endif254#if defined FSR2_BIND_UAV_NEW_LOCKS255layout(set = 1, binding = FSR2_BIND_UAV_NEW_LOCKS, r8) uniform image2D rw_new_locks;256#endif257#if defined FSR2_BIND_UAV_PREPARED_INPUT_COLOR258layout (set = 1, binding = FSR2_BIND_UAV_PREPARED_INPUT_COLOR, rgba16) writeonly uniform image2D rw_prepared_input_color;259#endif260#if defined FSR2_BIND_UAV_LUMA_HISTORY261layout (set = 1, binding = FSR2_BIND_UAV_LUMA_HISTORY, rgba8) uniform image2D rw_luma_history;262#endif263#if defined FSR2_BIND_UAV_UPSCALED_OUTPUT264layout (set = 1, binding = FSR2_BIND_UAV_UPSCALED_OUTPUT /* app controlled format */) writeonly uniform image2D rw_upscaled_output;265#endif266#if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE267layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE, r16f) coherent uniform image2D rw_img_mip_shading_change;268#endif269#if defined FSR2_BIND_UAV_EXPOSURE_MIP_5270layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE_MIP_5, r16f) coherent uniform image2D rw_img_mip_5;271#endif272#if defined FSR2_BIND_UAV_DILATED_REACTIVE_MASKS273layout (set = 1, binding = FSR2_BIND_UAV_DILATED_REACTIVE_MASKS, rg8) writeonly uniform image2D rw_dilated_reactive_masks;274#endif275#if defined FSR2_BIND_UAV_EXPOSURE276layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE, rg32f) uniform image2D rw_exposure;277#endif278#if defined FSR2_BIND_UAV_AUTO_EXPOSURE279layout(set = 1, binding = FSR2_BIND_UAV_AUTO_EXPOSURE, rg32f) uniform image2D rw_auto_exposure;280#endif281#if defined FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC282layout (set = 1, binding = FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC, r32ui) coherent uniform uimage2D rw_spd_global_atomic;283#endif284285#if defined FSR2_BIND_UAV_AUTOREACTIVE286layout(set = 1, binding = FSR2_BIND_UAV_AUTOREACTIVE, r32f) uniform image2D rw_output_autoreactive;287#endif288#if defined FSR2_BIND_UAV_AUTOCOMPOSITION289layout(set = 1, binding = FSR2_BIND_UAV_AUTOCOMPOSITION, r32f) uniform image2D rw_output_autocomposition;290#endif291#if defined FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR292layout(set = 1, binding = FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_pre_alpha;293#endif294#if defined FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR295layout(set = 1, binding = FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_post_alpha;296#endif297298#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)299FfxFloat32 LoadMipLuma(FfxInt32x2 iPxPos, FfxInt32 mipLevel)300{301return texelFetch(r_imgMips, iPxPos, FfxInt32(mipLevel)).r;302}303#endif304305#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)306FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxInt32 mipLevel)307{308return textureLod(sampler2D(r_imgMips, s_LinearClamp), fUV, FfxFloat32(mipLevel)).r;309}310#endif311312#if defined(FSR2_BIND_SRV_INPUT_DEPTH)313FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)314{315return texelFetch(r_input_depth, iPxPos, 0).r;316}317#endif318319#if defined(FSR2_BIND_SRV_REACTIVE_MASK)320FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)321{322#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP323return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f);324#else325return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r;326#endif327}328#endif329330#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)331FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)332{333return texelFetch(r_transparency_and_composition_mask, FfxInt32x2(iPxPos), 0).r;334}335#endif336337#if defined(FSR2_BIND_SRV_INPUT_COLOR)338FfxFloat32x3 LoadInputColor(FfxInt32x2 iPxPos)339{340return texelFetch(r_input_color_jittered, iPxPos, 0).rgb;341}342#endif343344#if defined(FSR2_BIND_SRV_INPUT_COLOR)345FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)346{347return textureLod(sampler2D(r_input_color_jittered, s_LinearClamp), fUV, 0.0f).rgb;348}349#endif350351#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)352FfxFloat32x3 LoadPreparedInputColor(FfxInt32x2 iPxPos)353{354return texelFetch(r_prepared_input_color, iPxPos, 0).xyz;355}356#endif357358#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)359FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)360{361FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;362363#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS364bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f)));365if (bInvalidMotionVector)366{367FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos);368FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize();369fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix);370}371#endif372373FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();374375#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS376fUvMotionVector -= MotionVectorJitterCancellation();377#endif378379return fUvMotionVector;380}381#endif382383#if defined(FSR2_BIND_SRV_INTERNAL_UPSCALED)384FfxFloat32x4 LoadHistory(FfxInt32x2 iPxHistory)385{386return texelFetch(r_internal_upscaled_color, iPxHistory, 0);387}388#endif389390#if defined(FSR2_BIND_UAV_LUMA_HISTORY)391void StoreLumaHistory(FfxInt32x2 iPxPos, FfxFloat32x4 fLumaHistory)392{393imageStore(rw_luma_history, FfxInt32x2(iPxPos), fLumaHistory);394}395#endif396397#if defined(FSR2_BIND_SRV_LUMA_HISTORY)398FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV)399{400return textureLod(sampler2D(r_luma_history, s_LinearClamp), fUV, 0.0f);401}402#endif403404#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED)405void StoreReprojectedHistory(FfxInt32x2 iPxHistory, FfxFloat32x4 fHistory)406{407imageStore(rw_internal_upscaled_color, iPxHistory, fHistory);408}409#endif410411#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED)412void StoreInternalColorAndWeight(FfxInt32x2 iPxPos, FfxFloat32x4 fColorAndWeight)413{414imageStore(rw_internal_upscaled_color, FfxInt32x2(iPxPos), fColorAndWeight);415}416#endif417418#if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT)419void StoreUpscaledOutput(FfxInt32x2 iPxPos, FfxFloat32x3 fColor)420{421imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));422}423#endif424425#if defined(FSR2_BIND_SRV_LOCK_STATUS)426FfxFloat32x2 LoadLockStatus(FfxInt32x2 iPxPos)427{428FfxFloat32x2 fLockStatus = texelFetch(r_lock_status, iPxPos, 0).rg;429430return fLockStatus;431}432#endif433434#if defined(FSR2_BIND_UAV_LOCK_STATUS)435void StoreLockStatus(FfxInt32x2 iPxPos, FfxFloat32x2 fLockstatus)436{437imageStore(rw_lock_status, iPxPos, vec4(fLockstatus, 0.0f, 0.0f));438}439#endif440441#if defined(FSR2_BIND_SRV_LOCK_INPUT_LUMA)442FfxFloat32 LoadLockInputLuma(FfxInt32x2 iPxPos)443{444return texelFetch(r_lock_input_luma, iPxPos, 0).r;445}446#endif447448#if defined(FSR2_BIND_UAV_LOCK_INPUT_LUMA)449void StoreLockInputLuma(FfxInt32x2 iPxPos, FfxFloat32 fLuma)450{451imageStore(rw_lock_input_luma, iPxPos, vec4(fLuma, 0, 0, 0));452}453#endif454455#if defined(FSR2_BIND_SRV_NEW_LOCKS)456FfxFloat32 LoadNewLocks(FfxInt32x2 iPxPos)457{458return texelFetch(r_new_locks, iPxPos, 0).r;459}460#endif461462#if defined(FSR2_BIND_UAV_NEW_LOCKS)463FfxFloat32 LoadRwNewLocks(FfxInt32x2 iPxPos)464{465return imageLoad(rw_new_locks, iPxPos).r;466}467#endif468469#if defined(FSR2_BIND_UAV_NEW_LOCKS)470void StoreNewLocks(FfxInt32x2 iPxPos, FfxFloat32 newLock)471{472imageStore(rw_new_locks, iPxPos, vec4(newLock, 0, 0, 0));473}474#endif475476#if defined(FSR2_BIND_UAV_PREPARED_INPUT_COLOR)477void StorePreparedInputColor(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x4 fTonemapped)478{479imageStore(rw_prepared_input_color, iPxPos, fTonemapped);480}481#endif482483#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)484FfxFloat32 SampleDepthClip(FfxFloat32x2 fUV)485{486return textureLod(sampler2D(r_prepared_input_color, s_LinearClamp), fUV, 0.0f).w;487}488#endif489490#if defined(FSR2_BIND_SRV_LOCK_STATUS)491FfxFloat32x2 SampleLockStatus(FfxFloat32x2 fUV)492{493FfxFloat32x2 fLockStatus = textureLod(sampler2D(r_lock_status, s_LinearClamp), fUV, 0.0f).rg;494return fLockStatus;495}496#endif497498#if defined(FSR2_BIND_SRV_DEPTH)499FfxFloat32 LoadSceneDepth(FfxInt32x2 iPxInput)500{501return texelFetch(r_input_depth, iPxInput, 0).r;502}503#endif504505#if defined(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)506FfxFloat32 LoadReconstructedPrevDepth(FfxInt32x2 iPxPos)507{508return uintBitsToFloat(texelFetch(r_reconstructed_previous_nearest_depth, iPxPos, 0).r);509}510#endif511512#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)513void StoreReconstructedDepth(FfxInt32x2 iPxSample, FfxFloat32 fDepth)514{515FfxUInt32 uDepth = floatBitsToUint(fDepth);516517#if FFX_FSR2_OPTION_INVERTED_DEPTH518imageAtomicMax(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth);519#else520imageAtomicMin(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth); // min for standard, max for inverted depth521#endif522}523#endif524525#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)526void SetReconstructedDepth(FfxInt32x2 iPxSample, FfxUInt32 uValue)527{528imageStore(rw_reconstructed_previous_nearest_depth, iPxSample, uvec4(uValue, 0, 0, 0));529}530#endif531532#if defined(FSR2_BIND_UAV_DILATED_DEPTH)533void StoreDilatedDepth(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32 fDepth)534{535//FfxUInt32 uDepth = f32tof16(fDepth);536imageStore(rw_dilatedDepth, iPxPos, vec4(fDepth, 0.0f, 0.0f, 0.0f));537}538#endif539540#if defined(FSR2_BIND_UAV_DILATED_MOTION_VECTORS)541void StoreDilatedMotionVector(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fMotionVector)542{543imageStore(rw_dilated_motion_vectors, iPxPos, vec4(fMotionVector, 0.0f, 0.0f));544}545#endif546547#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)548FfxFloat32x2 LoadDilatedMotionVector(FfxInt32x2 iPxInput)549{550return texelFetch(r_dilated_motion_vectors, iPxInput, 0).rg;551}552#endif553554#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)555FfxFloat32x2 SampleDilatedMotionVector(FfxFloat32x2 fUV)556{557return textureLod(sampler2D(r_dilated_motion_vectors, s_LinearClamp), fUV, 0.0f).rg;558}559#endif560561#if defined(FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS)562FfxFloat32x2 LoadPreviousDilatedMotionVector(FfxInt32x2 iPxInput)563{564return texelFetch(r_previous_dilated_motion_vectors, iPxInput, 0).rg;565}566567FfxFloat32x2 SamplePreviousDilatedMotionVector(FfxFloat32x2 fUV)568{569return textureLod(sampler2D(r_previous_dilated_motion_vectors, s_LinearClamp), fUV, 0.0f).xy;570}571#endif572573#if defined(FSR2_BIND_SRV_DILATED_DEPTH)574FfxFloat32 LoadDilatedDepth(FfxInt32x2 iPxInput)575{576return texelFetch(r_dilatedDepth, iPxInput, 0).r;577}578#endif579580#if defined(FSR2_BIND_SRV_INPUT_EXPOSURE)581FfxFloat32 Exposure()582{583FfxFloat32 exposure = texelFetch(r_input_exposure, FfxInt32x2(0, 0), 0).x;584585if (exposure == 0.0f) {586exposure = 1.0f;587}588589return exposure;590}591#endif592593#if defined(FSR2_BIND_SRV_AUTO_EXPOSURE)594FfxFloat32 AutoExposure()595{596FfxFloat32 exposure = texelFetch(r_auto_exposure, FfxInt32x2(0, 0), 0).x;597598if (exposure == 0.0f) {599exposure = 1.0f;600}601602return exposure;603}604#endif605606FfxFloat32 SampleLanczos2Weight(FfxFloat32 x)607{608#if defined(FSR2_BIND_SRV_LANCZOS_LUT)609return textureLod(sampler2D(r_lanczos_lut, s_LinearClamp), FfxFloat32x2(x / 2.0f, 0.5f), 0.0f).x;610#else611return 0.f;612#endif613}614615#if defined(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT)616FfxFloat32 SampleUpsampleMaximumBias(FfxFloat32x2 uv)617{618// Stored as a SNORM, so make sure to multiply by 2 to retrieve the actual expected range.619return FfxFloat32(2.0f) * FfxFloat32(textureLod(sampler2D(r_upsample_maximum_bias_lut, s_LinearClamp), abs(uv) * 2.0f, 0.0f).r);620}621#endif622623#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)624FfxFloat32x2 SampleDilatedReactiveMasks(FfxFloat32x2 fUV)625{626return textureLod(sampler2D(r_dilated_reactive_masks, s_LinearClamp), fUV, 0.0f).rg;627}628#endif629630#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)631FfxFloat32x2 LoadDilatedReactiveMasks(FFX_PARAMETER_IN FfxInt32x2 iPxPos)632{633return texelFetch(r_dilated_reactive_masks, iPxPos, 0).rg;634}635#endif636637#if defined(FSR2_BIND_UAV_DILATED_REACTIVE_MASKS)638void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fDilatedReactiveMasks)639{640imageStore(rw_dilated_reactive_masks, iPxPos, vec4(fDilatedReactiveMasks, 0.0f, 0.0f));641}642#endif643644#if defined(FFX_INTERNAL)645FfxFloat32x4 SampleDebug(FfxFloat32x2 fUV)646{647return textureLod(sampler2D(r_debug_out, s_LinearClamp), fUV, 0.0f).rgba;648}649#endif650651#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)652FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)653{654return texelFetch(r_input_opaque_only, iPxPos, 0).xyz;655}656#endif657658#if defined(FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR)659FfxFloat32x3 LoadPrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)660{661return texelFetch(r_input_prev_color_pre_alpha, iPxPos, 0).xyz;662}663#endif664665#if defined(FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR)666FfxFloat32x3 LoadPrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)667{668return texelFetch(r_input_prev_color_post_alpha, iPxPos, 0).xyz;669}670#endif671672#if defined(FSR2_BIND_UAV_AUTOREACTIVE)673#if defined(FSR2_BIND_UAV_AUTOCOMPOSITION)674void StoreAutoReactive(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F2 fReactive)675{676imageStore(rw_output_autoreactive, iPxPos, vec4(FfxFloat32(fReactive.x), 0.0f, 0.0f, 0.0f));677678imageStore(rw_output_autocomposition, iPxPos, vec4(FfxFloat32(fReactive.y), 0.0f, 0.0f, 0.0f));679}680#endif681#endif682683#if defined(FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR)684void StorePrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)685{686imageStore(rw_output_prev_color_pre_alpha, iPxPos, vec4(color, 0.0f));687}688#endif689690#if defined(FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR)691void StorePrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)692{693imageStore(rw_output_prev_color_post_alpha, iPxPos, vec4(color, 0.0f));694}695#endif696697#endif // #if defined(FFX_GPU)698699700