Path: blob/master/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock.h
9898 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#ifndef FFX_FSR2_LOCK_H22#define FFX_FSR2_LOCK_H2324void ClearResourcesForNextFrame(in FfxInt32x2 iPxHrPos)25{26if (all(FFX_LESS_THAN(iPxHrPos, FfxInt32x2(RenderSize()))))27{28#if FFX_FSR2_OPTION_INVERTED_DEPTH29const FfxUInt32 farZ = 0x0;30#else31const FfxUInt32 farZ = 0x3f800000;32#endif33SetReconstructedDepth(iPxHrPos, farZ);34}35}3637FfxBoolean ComputeThinFeatureConfidence(FfxInt32x2 pos)38{39const FfxInt32 RADIUS = 1;4041FfxFloat32 fNucleus = LoadLockInputLuma(pos);4243FfxFloat32 similar_threshold = 1.05f;44FfxFloat32 dissimilarLumaMin = FSR2_FLT_MAX;45FfxFloat32 dissimilarLumaMax = 0;4647/*480 1 2493 4 5506 7 851*/5253#define SETBIT(x) (1U << x)5455FfxUInt32 mask = SETBIT(4); //flag fNucleus as similar5657const FfxUInt32 uNumRejectionMasks = 4;58const FfxUInt32 uRejectionMasks[uNumRejectionMasks] = {59SETBIT(0) | SETBIT(1) | SETBIT(3) | SETBIT(4), //Upper left60SETBIT(1) | SETBIT(2) | SETBIT(4) | SETBIT(5), //Upper right61SETBIT(3) | SETBIT(4) | SETBIT(6) | SETBIT(7), //Lower left62SETBIT(4) | SETBIT(5) | SETBIT(7) | SETBIT(8), //Lower right63};6465FfxInt32 idx = 0;66FFX_UNROLL67for (FfxInt32 y = -RADIUS; y <= RADIUS; y++) {68FFX_UNROLL69for (FfxInt32 x = -RADIUS; x <= RADIUS; x++, idx++) {70if (x == 0 && y == 0) continue;7172FfxInt32x2 samplePos = ClampLoad(pos, FfxInt32x2(x, y), FfxInt32x2(RenderSize()));7374FfxFloat32 sampleLuma = LoadLockInputLuma(samplePos);75FfxFloat32 difference = ffxMax(sampleLuma, fNucleus) / ffxMin(sampleLuma, fNucleus);7677if (difference > 0 && (difference < similar_threshold)) {78mask |= SETBIT(idx);79} else {80dissimilarLumaMin = ffxMin(dissimilarLumaMin, sampleLuma);81dissimilarLumaMax = ffxMax(dissimilarLumaMax, sampleLuma);82}83}84}8586FfxBoolean isRidge = fNucleus > dissimilarLumaMax || fNucleus < dissimilarLumaMin;8788if (FFX_FALSE == isRidge) {8990return false;91}9293FFX_UNROLL94for (FfxInt32 i = 0; i < 4; i++) {9596if ((mask & uRejectionMasks[i]) == uRejectionMasks[i]) {97return false;98}99}100101return true;102}103104void ComputeLock(FfxInt32x2 iPxLrPos)105{106if (ComputeThinFeatureConfidence(iPxLrPos))107{108StoreNewLocks(ComputeHrPosFromLrPos(iPxLrPos), 1.f);109}110111ClearResourcesForNextFrame(iPxLrPos);112}113114#endif // FFX_FSR2_LOCK_H115116117