#ifdef __clang__
#pragma clang diagnostic ignored "-Wunused-variable"
#endif
FFX_STATIC void ffxFsrPopulateEasuConstants(
FFX_PARAMETER_INOUT FfxUInt32x4 con0,
FFX_PARAMETER_INOUT FfxUInt32x4 con1,
FFX_PARAMETER_INOUT FfxUInt32x4 con2,
FFX_PARAMETER_INOUT FfxUInt32x4 con3,
FFX_PARAMETER_IN FfxFloat32 inputViewportInPixelsX,
FFX_PARAMETER_IN FfxFloat32 inputViewportInPixelsY,
FFX_PARAMETER_IN FfxFloat32 inputSizeInPixelsX,
FFX_PARAMETER_IN FfxFloat32 inputSizeInPixelsY,
FFX_PARAMETER_IN FfxFloat32 outputSizeInPixelsX,
FFX_PARAMETER_IN FfxFloat32 outputSizeInPixelsY)
{ … }
FFX_STATIC void ffxFsrPopulateEasuConstantsOffset(
FFX_PARAMETER_INOUT FfxUInt32x4 con0,
FFX_PARAMETER_INOUT FfxUInt32x4 con1,
FFX_PARAMETER_INOUT FfxUInt32x4 con2,
FFX_PARAMETER_INOUT FfxUInt32x4 con3,
FFX_PARAMETER_IN FfxFloat32 inputViewportInPixelsX,
FFX_PARAMETER_IN FfxFloat32 inputViewportInPixelsY,
FFX_PARAMETER_IN FfxFloat32 inputSizeInPixelsX,
FFX_PARAMETER_IN FfxFloat32 inputSizeInPixelsY,
FFX_PARAMETER_IN FfxFloat32 outputSizeInPixelsX,
FFX_PARAMETER_IN FfxFloat32 outputSizeInPixelsY,
FFX_PARAMETER_IN FfxFloat32 inputOffsetInPixelsX,
FFX_PARAMETER_IN FfxFloat32 inputOffsetInPixelsY)
{ … }
#if defined(FFX_GPU) && defined(FFX_FSR_EASU_FLOAT)
FfxFloat32x4 FsrEasuRF(FfxFloat32x2 p);
FfxFloat32x4 FsrEasuGF(FfxFloat32x2 p);
FfxFloat32x4 FsrEasuBF(FfxFloat32x2 p);
void fsrEasuTapFloat(
FFX_PARAMETER_INOUT FfxFloat32x3 accumulatedColor,
FFX_PARAMETER_INOUT FfxFloat32 accumulatedWeight,
FFX_PARAMETER_IN FfxFloat32x2 pixelOffset,
FFX_PARAMETER_IN FfxFloat32x2 gradientDirection,
FFX_PARAMETER_IN FfxFloat32x2 length,
FFX_PARAMETER_IN FfxFloat32 negativeLobeStrength,
FFX_PARAMETER_IN FfxFloat32 clippingPoint,
FFX_PARAMETER_IN FfxFloat32x3 color)
{
FfxFloat32x2 rotatedOffset;
rotatedOffset.x = (pixelOffset.x * (gradientDirection.x)) + (pixelOffset.y * gradientDirection.y);
rotatedOffset.y = (pixelOffset.x * (-gradientDirection.y)) + (pixelOffset.y * gradientDirection.x);
rotatedOffset *= length;
FfxFloat32 distanceSquared = rotatedOffset.x * rotatedOffset.x + rotatedOffset.y * rotatedOffset.y;
distanceSquared = ffxMin(distanceSquared, clippingPoint);
FfxFloat32 weightB = FfxFloat32(2.0 / 5.0) * distanceSquared + FfxFloat32(-1.0);
FfxFloat32 weightA = negativeLobeStrength * distanceSquared + FfxFloat32(-1.0);
weightB *= weightB;
weightA *= weightA;
weightB = FfxFloat32(25.0 / 16.0) * weightB + FfxFloat32(-(25.0 / 16.0 - 1.0));
FfxFloat32 weight = weightB * weightA;
accumulatedColor += color * weight;
accumulatedWeight += weight;
}
void fsrEasuSetFloat(
FFX_PARAMETER_INOUT FfxFloat32x2 direction,
FFX_PARAMETER_INOUT FfxFloat32 length,
FFX_PARAMETER_IN FfxFloat32x2 pp,
FFX_PARAMETER_IN FfxBoolean biS,
FFX_PARAMETER_IN FfxBoolean biT,
FFX_PARAMETER_IN FfxBoolean biU,
FFX_PARAMETER_IN FfxBoolean biV,
FFX_PARAMETER_IN FfxFloat32 lA,
FFX_PARAMETER_IN FfxFloat32 lB,
FFX_PARAMETER_IN FfxFloat32 lC,
FFX_PARAMETER_IN FfxFloat32 lD,
FFX_PARAMETER_IN FfxFloat32 lE)
{
FfxFloat32 weight = FfxFloat32(0.0);
if (biS)
weight = (FfxFloat32(1.0) - pp.x) * (FfxFloat32(1.0) - pp.y);
if (biT)
weight = pp.x * (FfxFloat32(1.0) - pp.y);
if (biU)
weight = (FfxFloat32(1.0) - pp.x) * pp.y;
if (biV)
weight = pp.x * pp.y;
FfxFloat32 dc = lD - lC;
FfxFloat32 cb = lC - lB;
FfxFloat32 lengthX = max(abs(dc), abs(cb));
lengthX = ffxApproximateReciprocal(lengthX);
FfxFloat32 directionX = lD - lB;
direction.x += directionX * weight;
lengthX = ffxSaturate(abs(directionX) * lengthX);
lengthX *= lengthX;
length += lengthX * weight;
FfxFloat32 ec = lE - lC;
FfxFloat32 ca = lC - lA;
FfxFloat32 lengthY = max(abs(ec), abs(ca));
lengthY = ffxApproximateReciprocal(lengthY);
FfxFloat32 directionY = lE - lA;
direction.y += directionY * weight;
lengthY = ffxSaturate(abs(directionY) * lengthY);
lengthY *= lengthY;
length += lengthY * weight;
}
void ffxFsrEasuFloat(
FFX_PARAMETER_OUT FfxFloat32x3 pix,
FFX_PARAMETER_IN FfxUInt32x2 ip,
FFX_PARAMETER_IN FfxUInt32x4 con0,
FFX_PARAMETER_IN FfxUInt32x4 con1,
FFX_PARAMETER_IN FfxUInt32x4 con2,
FFX_PARAMETER_IN FfxUInt32x4 con3)
{
FfxFloat32x2 pp = FfxFloat32x2(ip) * ffxAsFloat(con0.xy) + ffxAsFloat(con0.zw);
FfxFloat32x2 fp = floor(pp);
pp -= fp;
FfxFloat32x2 p0 = fp * ffxAsFloat(con1.xy) + ffxAsFloat(con1.zw);
FfxFloat32x2 p1 = p0 + ffxAsFloat(con2.xy);
FfxFloat32x2 p2 = p0 + ffxAsFloat(con2.zw);
FfxFloat32x2 p3 = p0 + ffxAsFloat(con3.xy);
FfxFloat32x4 bczzR = FsrEasuRF(p0);
FfxFloat32x4 bczzG = FsrEasuGF(p0);
FfxFloat32x4 bczzB = FsrEasuBF(p0);
FfxFloat32x4 ijfeR = FsrEasuRF(p1);
FfxFloat32x4 ijfeG = FsrEasuGF(p1);
FfxFloat32x4 ijfeB = FsrEasuBF(p1);
FfxFloat32x4 klhgR = FsrEasuRF(p2);
FfxFloat32x4 klhgG = FsrEasuGF(p2);
FfxFloat32x4 klhgB = FsrEasuBF(p2);
FfxFloat32x4 zzonR = FsrEasuRF(p3);
FfxFloat32x4 zzonG = FsrEasuGF(p3);
FfxFloat32x4 zzonB = FsrEasuBF(p3);
FfxFloat32x4 bczzL = bczzB * ffxBroadcast4(0.5) + (bczzR * ffxBroadcast4(0.5) + bczzG);
FfxFloat32x4 ijfeL = ijfeB * ffxBroadcast4(0.5) + (ijfeR * ffxBroadcast4(0.5) + ijfeG);
FfxFloat32x4 klhgL = klhgB * ffxBroadcast4(0.5) + (klhgR * ffxBroadcast4(0.5) + klhgG);
FfxFloat32x4 zzonL = zzonB * ffxBroadcast4(0.5) + (zzonR * ffxBroadcast4(0.5) + zzonG);
FfxFloat32 bL = bczzL.x;
FfxFloat32 cL = bczzL.y;
FfxFloat32 iL = ijfeL.x;
FfxFloat32 jL = ijfeL.y;
FfxFloat32 fL = ijfeL.z;
FfxFloat32 eL = ijfeL.w;
FfxFloat32 kL = klhgL.x;
FfxFloat32 lL = klhgL.y;
FfxFloat32 hL = klhgL.z;
FfxFloat32 gL = klhgL.w;
FfxFloat32 oL = zzonL.z;
FfxFloat32 nL = zzonL.w;
FfxFloat32x2 dir = ffxBroadcast2(0.0);
FfxFloat32 len = FfxFloat32(0.0);
fsrEasuSetFloat(dir, len, pp, FFX_TRUE, FFX_FALSE, FFX_FALSE, FFX_FALSE, bL, eL, fL, gL, jL);
fsrEasuSetFloat(dir, len, pp, FFX_FALSE, FFX_TRUE, FFX_FALSE, FFX_FALSE, cL, fL, gL, hL, kL);
fsrEasuSetFloat(dir, len, pp, FFX_FALSE, FFX_FALSE, FFX_TRUE, FFX_FALSE, fL, iL, jL, kL, nL);
fsrEasuSetFloat(dir, len, pp, FFX_FALSE, FFX_FALSE, FFX_FALSE, FFX_TRUE, gL, jL, kL, lL, oL);
FfxFloat32x2 dir2 = dir * dir;
FfxFloat32 dirR = dir2.x + dir2.y;
FfxUInt32 zro = dirR < FfxFloat32(1.0 / 32768.0);
dirR = ffxApproximateReciprocalSquareRoot(dirR);
dirR = zro ? FfxFloat32(1.0) : dirR;
dir.x = zro ? FfxFloat32(1.0) : dir.x;
dir *= ffxBroadcast2(dirR);
len = len * FfxFloat32(0.5);
len *= len;
FfxFloat32 stretch = (dir.x * dir.x + dir.y * dir.y) * ffxApproximateReciprocal(max(abs(dir.x), abs(dir.y)));
FfxFloat32x2 len2 = FfxFloat32x2(FfxFloat32(1.0) + (stretch - FfxFloat32(1.0)) * len, FfxFloat32(1.0) + FfxFloat32(-0.5) * len);
FfxFloat32 lob = FfxFloat32(0.5) + FfxFloat32((1.0 / 4.0 - 0.04) - 0.5) * len;
FfxFloat32 clp = ffxApproximateReciprocal(lob);
FfxFloat32x3 min4 =
ffxMin(ffxMin3(FfxFloat32x3(ijfeR.z, ijfeG.z, ijfeB.z), FfxFloat32x3(klhgR.w, klhgG.w, klhgB.w), FfxFloat32x3(ijfeR.y, ijfeG.y, ijfeB.y)),
FfxFloat32x3(klhgR.x, klhgG.x, klhgB.x));
FfxFloat32x3 max4 =
max(ffxMax3(FfxFloat32x3(ijfeR.z, ijfeG.z, ijfeB.z), FfxFloat32x3(klhgR.w, klhgG.w, klhgB.w), FfxFloat32x3(ijfeR.y, ijfeG.y, ijfeB.y)), FfxFloat32x3(klhgR.x, klhgG.x, klhgB.x));
FfxFloat32x3 aC = ffxBroadcast3(0.0);
FfxFloat32 aW = FfxFloat32(0.0);
fsrEasuTapFloat(aC, aW, FfxFloat32x2(0.0, -1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(bczzR.x, bczzG.x, bczzB.x));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(1.0, -1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(bczzR.y, bczzG.y, bczzB.y));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(-1.0, 1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(ijfeR.x, ijfeG.x, ijfeB.x));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(0.0, 1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(ijfeR.y, ijfeG.y, ijfeB.y));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(0.0, 0.0) - pp, dir, len2, lob, clp, FfxFloat32x3(ijfeR.z, ijfeG.z, ijfeB.z));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(-1.0, 0.0) - pp, dir, len2, lob, clp, FfxFloat32x3(ijfeR.w, ijfeG.w, ijfeB.w));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(1.0, 1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(klhgR.x, klhgG.x, klhgB.x));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(2.0, 1.0) - pp, dir, len2, lob, clp, FfxFloat32x3(klhgR.y, klhgG.y, klhgB.y));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(2.0, 0.0) - pp, dir, len2, lob, clp, FfxFloat32x3(klhgR.z, klhgG.z, klhgB.z));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(1.0, 0.0) - pp, dir, len2, lob, clp, FfxFloat32x3(klhgR.w, klhgG.w, klhgB.w));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(1.0, 2.0) - pp, dir, len2, lob, clp, FfxFloat32x3(zzonR.z, zzonG.z, zzonB.z));
fsrEasuTapFloat(aC, aW, FfxFloat32x2(0.0, 2.0) - pp, dir, len2, lob, clp, FfxFloat32x3(zzonR.w, zzonG.w, zzonB.w));
pix = ffxMin(max4, max(min4, aC * ffxBroadcast3(rcp(aW))));
}
#endif
#if defined(FFX_GPU) && FFX_HALF == 1 && defined(FFX_FSR_EASU_HALF)
FfxFloat16x4 FsrEasuRH(FfxFloat32x2 p);
FfxFloat16x4 FsrEasuGH(FfxFloat32x2 p);
FfxFloat16x4 FsrEasuBH(FfxFloat32x2 p);
void FsrEasuTapH(
FFX_PARAMETER_INOUT FfxFloat16x2 aCR,
FFX_PARAMETER_INOUT FfxFloat16x2 aCG,
FFX_PARAMETER_INOUT FfxFloat16x2 aCB,
FFX_PARAMETER_INOUT FfxFloat16x2 aW,
FFX_PARAMETER_IN FfxFloat16x2 offX,
FFX_PARAMETER_IN FfxFloat16x2 offY,
FFX_PARAMETER_IN FfxFloat16x2 dir,
FFX_PARAMETER_IN FfxFloat16x2 len,
FFX_PARAMETER_IN FfxFloat16 lob,
FFX_PARAMETER_IN FfxFloat16 clp,
FFX_PARAMETER_IN FfxFloat16x2 cR,
FFX_PARAMETER_IN FfxFloat16x2 cG,
FFX_PARAMETER_IN FfxFloat16x2 cB)
{
FfxFloat16x2 vX, vY;
vX = offX * dir.xx + offY * dir.yy;
vY = offX * (-dir.yy) + offY * dir.xx;
vX *= len.x;
vY *= len.y;
FfxFloat16x2 d2 = vX * vX + vY * vY;
d2 = min(d2, FFX_BROADCAST_FLOAT16X2(clp));
FfxFloat16x2 wB = FFX_BROADCAST_FLOAT16X2(2.0 / 5.0) * d2 + FFX_BROADCAST_FLOAT16X2(-1.0);
FfxFloat16x2 wA = FFX_BROADCAST_FLOAT16X2(lob) * d2 + FFX_BROADCAST_FLOAT16X2(-1.0);
wB *= wB;
wA *= wA;
wB = FFX_BROADCAST_FLOAT16X2(25.0 / 16.0) * wB + FFX_BROADCAST_FLOAT16X2(-(25.0 / 16.0 - 1.0));
FfxFloat16x2 w = wB * wA;
aCR += cR * w;
aCG += cG * w;
aCB += cB * w;
aW += w;
}
void FsrEasuSetH(
FFX_PARAMETER_INOUT FfxFloat16x2 dirPX,
FFX_PARAMETER_INOUT FfxFloat16x2 dirPY,
FFX_PARAMETER_INOUT FfxFloat16x2 lenP,
FFX_PARAMETER_IN FfxFloat16x2 pp,
FFX_PARAMETER_IN FfxBoolean biST,
FFX_PARAMETER_IN FfxBoolean biUV,
FFX_PARAMETER_IN FfxFloat16x2 lA,
FFX_PARAMETER_IN FfxFloat16x2 lB,
FFX_PARAMETER_IN FfxFloat16x2 lC,
FFX_PARAMETER_IN FfxFloat16x2 lD,
FFX_PARAMETER_IN FfxFloat16x2 lE)
{
FfxFloat16x2 w = FFX_BROADCAST_FLOAT16X2(0.0);
if (biST)
w = (FfxFloat16x2(1.0, 0.0) + FfxFloat16x2(-pp.x, pp.x)) * FFX_BROADCAST_FLOAT16X2(FFX_BROADCAST_FLOAT16(1.0) - pp.y);
if (biUV)
w = (FfxFloat16x2(1.0, 0.0) + FfxFloat16x2(-pp.x, pp.x)) * FFX_BROADCAST_FLOAT16X2(pp.y);
FfxFloat16x2 dc = lD - lC;
FfxFloat16x2 cb = lC - lB;
FfxFloat16x2 lenX = max(abs(dc), abs(cb));
lenX = ffxReciprocalHalf(lenX);
FfxFloat16x2 dirX = lD - lB;
dirPX += dirX * w;
lenX = ffxSaturate(abs(dirX) * lenX);
lenX *= lenX;
lenP += lenX * w;
FfxFloat16x2 ec = lE - lC;
FfxFloat16x2 ca = lC - lA;
FfxFloat16x2 lenY = max(abs(ec), abs(ca));
lenY = ffxReciprocalHalf(lenY);
FfxFloat16x2 dirY = lE - lA;
dirPY += dirY * w;
lenY = ffxSaturate(abs(dirY) * lenY);
lenY *= lenY;
lenP += lenY * w;
}
void FsrEasuH(
FFX_PARAMETER_OUT FfxFloat16x3 pix,
FFX_PARAMETER_IN FfxUInt32x2 ip,
FFX_PARAMETER_IN FfxUInt32x4 con0,
FFX_PARAMETER_IN FfxUInt32x4 con1,
FFX_PARAMETER_IN FfxUInt32x4 con2,
FFX_PARAMETER_IN FfxUInt32x4 con3)
{
FfxFloat32x2 pp = FfxFloat32x2(ip) * ffxAsFloat(con0.xy) + ffxAsFloat(con0.zw);
FfxFloat32x2 fp = floor(pp);
pp -= fp;
FfxFloat16x2 ppp = FfxFloat16x2(pp);
FfxFloat32x2 p0 = fp * ffxAsFloat(con1.xy) + ffxAsFloat(con1.zw);
FfxFloat32x2 p1 = p0 + ffxAsFloat(con2.xy);
FfxFloat32x2 p2 = p0 + ffxAsFloat(con2.zw);
FfxFloat32x2 p3 = p0 + ffxAsFloat(con3.xy);
FfxFloat16x4 bczzR = FsrEasuRH(p0);
FfxFloat16x4 bczzG = FsrEasuGH(p0);
FfxFloat16x4 bczzB = FsrEasuBH(p0);
FfxFloat16x4 ijfeR = FsrEasuRH(p1);
FfxFloat16x4 ijfeG = FsrEasuGH(p1);
FfxFloat16x4 ijfeB = FsrEasuBH(p1);
FfxFloat16x4 klhgR = FsrEasuRH(p2);
FfxFloat16x4 klhgG = FsrEasuGH(p2);
FfxFloat16x4 klhgB = FsrEasuBH(p2);
FfxFloat16x4 zzonR = FsrEasuRH(p3);
FfxFloat16x4 zzonG = FsrEasuGH(p3);
FfxFloat16x4 zzonB = FsrEasuBH(p3);
FfxFloat16x4 bczzL = bczzB * FFX_BROADCAST_FLOAT16X4(0.5) + (bczzR * FFX_BROADCAST_FLOAT16X4(0.5) + bczzG);
FfxFloat16x4 ijfeL = ijfeB * FFX_BROADCAST_FLOAT16X4(0.5) + (ijfeR * FFX_BROADCAST_FLOAT16X4(0.5) + ijfeG);
FfxFloat16x4 klhgL = klhgB * FFX_BROADCAST_FLOAT16X4(0.5) + (klhgR * FFX_BROADCAST_FLOAT16X4(0.5) + klhgG);
FfxFloat16x4 zzonL = zzonB * FFX_BROADCAST_FLOAT16X4(0.5) + (zzonR * FFX_BROADCAST_FLOAT16X4(0.5) + zzonG);
FfxFloat16 bL = bczzL.x;
FfxFloat16 cL = bczzL.y;
FfxFloat16 iL = ijfeL.x;
FfxFloat16 jL = ijfeL.y;
FfxFloat16 fL = ijfeL.z;
FfxFloat16 eL = ijfeL.w;
FfxFloat16 kL = klhgL.x;
FfxFloat16 lL = klhgL.y;
FfxFloat16 hL = klhgL.z;
FfxFloat16 gL = klhgL.w;
FfxFloat16 oL = zzonL.z;
FfxFloat16 nL = zzonL.w;
FfxFloat16x2 dirPX = FFX_BROADCAST_FLOAT16X2(0.0);
FfxFloat16x2 dirPY = FFX_BROADCAST_FLOAT16X2(0.0);
FfxFloat16x2 lenP = FFX_BROADCAST_FLOAT16X2(0.0);
FsrEasuSetH(dirPX,
dirPY,
lenP,
ppp,
FfxUInt32(true),
FfxUInt32(false),
FfxFloat16x2(bL, cL),
FfxFloat16x2(eL, fL),
FfxFloat16x2(fL, gL),
FfxFloat16x2(gL, hL),
FfxFloat16x2(jL, kL));
FsrEasuSetH(dirPX,
dirPY,
lenP,
ppp,
FfxUInt32(false),
FfxUInt32(true),
FfxFloat16x2(fL, gL),
FfxFloat16x2(iL, jL),
FfxFloat16x2(jL, kL),
FfxFloat16x2(kL, lL),
FfxFloat16x2(nL, oL));
FfxFloat16x2 dir = FfxFloat16x2(dirPX.r + dirPX.g, dirPY.r + dirPY.g);
FfxFloat16 len = lenP.r + lenP.g;
FfxFloat16x2 dir2 = dir * dir;
FfxFloat16 dirR = dir2.x + dir2.y;
FfxBoolean zro = FfxBoolean(dirR < FFX_BROADCAST_FLOAT16(1.0 / 32768.0));
dirR = ffxApproximateReciprocalSquareRootHalf(dirR);
dirR = (zro > 0) ? FFX_BROADCAST_FLOAT16(1.0) : dirR;
dir.x = (zro > 0) ? FFX_BROADCAST_FLOAT16(1.0) : dir.x;
dir *= FFX_BROADCAST_FLOAT16X2(dirR);
len = len * FFX_BROADCAST_FLOAT16(0.5);
len *= len;
FfxFloat16 stretch = (dir.x * dir.x + dir.y * dir.y) * ffxApproximateReciprocalHalf(max(abs(dir.x), abs(dir.y)));
FfxFloat16x2 len2 =
FfxFloat16x2(FFX_BROADCAST_FLOAT16(1.0) + (stretch - FFX_BROADCAST_FLOAT16(1.0)) * len, FFX_BROADCAST_FLOAT16(1.0) + FFX_BROADCAST_FLOAT16(-0.5) * len);
FfxFloat16 lob = FFX_BROADCAST_FLOAT16(0.5) + FFX_BROADCAST_FLOAT16((1.0 / 4.0 - 0.04) - 0.5) * len;
FfxFloat16 clp = ffxApproximateReciprocalHalf(lob);
FfxFloat16x2 bothR =
max(max(FfxFloat16x2(-ijfeR.z, ijfeR.z), FfxFloat16x2(-klhgR.w, klhgR.w)), max(FfxFloat16x2(-ijfeR.y, ijfeR.y), FfxFloat16x2(-klhgR.x, klhgR.x)));
FfxFloat16x2 bothG =
max(max(FfxFloat16x2(-ijfeG.z, ijfeG.z), FfxFloat16x2(-klhgG.w, klhgG.w)), max(FfxFloat16x2(-ijfeG.y, ijfeG.y), FfxFloat16x2(-klhgG.x, klhgG.x)));
FfxFloat16x2 bothB =
max(max(FfxFloat16x2(-ijfeB.z, ijfeB.z), FfxFloat16x2(-klhgB.w, klhgB.w)), max(FfxFloat16x2(-ijfeB.y, ijfeB.y), FfxFloat16x2(-klhgB.x, klhgB.x)));
FfxFloat16x2 pR = FFX_BROADCAST_FLOAT16X2(0.0);
FfxFloat16x2 pG = FFX_BROADCAST_FLOAT16X2(0.0);
FfxFloat16x2 pB = FFX_BROADCAST_FLOAT16X2(0.0);
FfxFloat16x2 pW = FFX_BROADCAST_FLOAT16X2(0.0);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(0.0, 1.0) - ppp.xx, FfxFloat16x2(-1.0, -1.0) - ppp.yy, dir, len2, lob, clp, bczzR.xy, bczzG.xy, bczzB.xy);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(-1.0, 0.0) - ppp.xx, FfxFloat16x2(1.0, 1.0) - ppp.yy, dir, len2, lob, clp, ijfeR.xy, ijfeG.xy, ijfeB.xy);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(0.0, -1.0) - ppp.xx, FfxFloat16x2(0.0, 0.0) - ppp.yy, dir, len2, lob, clp, ijfeR.zw, ijfeG.zw, ijfeB.zw);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(1.0, 2.0) - ppp.xx, FfxFloat16x2(1.0, 1.0) - ppp.yy, dir, len2, lob, clp, klhgR.xy, klhgG.xy, klhgB.xy);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(2.0, 1.0) - ppp.xx, FfxFloat16x2(0.0, 0.0) - ppp.yy, dir, len2, lob, clp, klhgR.zw, klhgG.zw, klhgB.zw);
FsrEasuTapH(pR, pG, pB, pW, FfxFloat16x2(1.0, 0.0) - ppp.xx, FfxFloat16x2(2.0, 2.0) - ppp.yy, dir, len2, lob, clp, zzonR.zw, zzonG.zw, zzonB.zw);
FfxFloat16x3 aC = FfxFloat16x3(pR.x + pR.y, pG.x + pG.y, pB.x + pB.y);
FfxFloat16 aW = pW.x + pW.y;
pix = min(FfxFloat16x3(bothR.y, bothG.y, bothB.y), max(-FfxFloat16x3(bothR.x, bothG.x, bothB.x), aC * FFX_BROADCAST_FLOAT16X3(ffxReciprocalHalf(aW))));
}
#endif
#define FSR_RCAS_LIMIT …
FFX_STATIC void FsrRcasCon(FfxUInt32x4 con,
FfxFloat32 sharpness)
{ … }
#if defined(FFX_GPU)&&defined(FSR_RCAS_F)
FfxFloat32x4 FsrRcasLoadF(FfxInt32x2 p);
void FsrRcasInputF(inout FfxFloat32 r,inout FfxFloat32 g,inout FfxFloat32 b);
void FsrRcasF(out FfxFloat32 pixR,
out FfxFloat32 pixG,
out FfxFloat32 pixB,
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
out FfxFloat32 pixA,
#endif
FfxUInt32x2 ip,
FfxUInt32x4 con)
{
FfxInt32x2 sp = FfxInt32x2(ip);
FfxFloat32x3 b = FsrRcasLoadF(sp + FfxInt32x2(0, -1)).rgb;
FfxFloat32x3 d = FsrRcasLoadF(sp + FfxInt32x2(-1, 0)).rgb;
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
FfxFloat32x4 ee = FsrRcasLoadF(sp);
FfxFloat32x3 e = ee.rgb;
pixA = ee.a;
#else
FfxFloat32x3 e = FsrRcasLoadF(sp).rgb;
#endif
FfxFloat32x3 f = FsrRcasLoadF(sp + FfxInt32x2(1, 0)).rgb;
FfxFloat32x3 h = FsrRcasLoadF(sp + FfxInt32x2(0, 1)).rgb;
FfxFloat32 bR = b.r;
FfxFloat32 bG = b.g;
FfxFloat32 bB = b.b;
FfxFloat32 dR = d.r;
FfxFloat32 dG = d.g;
FfxFloat32 dB = d.b;
FfxFloat32 eR = e.r;
FfxFloat32 eG = e.g;
FfxFloat32 eB = e.b;
FfxFloat32 fR = f.r;
FfxFloat32 fG = f.g;
FfxFloat32 fB = f.b;
FfxFloat32 hR = h.r;
FfxFloat32 hG = h.g;
FfxFloat32 hB = h.b;
FsrRcasInputF(bR, bG, bB);
FsrRcasInputF(dR, dG, dB);
FsrRcasInputF(eR, eG, eB);
FsrRcasInputF(fR, fG, fB);
FsrRcasInputF(hR, hG, hB);
FfxFloat32 bL = bB * FfxFloat32(0.5) + (bR * FfxFloat32(0.5) + bG);
FfxFloat32 dL = dB * FfxFloat32(0.5) + (dR * FfxFloat32(0.5) + dG);
FfxFloat32 eL = eB * FfxFloat32(0.5) + (eR * FfxFloat32(0.5) + eG);
FfxFloat32 fL = fB * FfxFloat32(0.5) + (fR * FfxFloat32(0.5) + fG);
FfxFloat32 hL = hB * FfxFloat32(0.5) + (hR * FfxFloat32(0.5) + hG);
FfxFloat32 nz = FfxFloat32(0.25) * bL + FfxFloat32(0.25) * dL + FfxFloat32(0.25) * fL + FfxFloat32(0.25) * hL - eL;
nz = ffxSaturate(abs(nz) * ffxApproximateReciprocalMedium(ffxMax3(ffxMax3(bL, dL, eL), fL, hL) - ffxMin3(ffxMin3(bL, dL, eL), fL, hL)));
nz = FfxFloat32(-0.5) * nz + FfxFloat32(1.0);
FfxFloat32 mn4R = ffxMin(ffxMin3(bR, dR, fR), hR);
FfxFloat32 mn4G = ffxMin(ffxMin3(bG, dG, fG), hG);
FfxFloat32 mn4B = ffxMin(ffxMin3(bB, dB, fB), hB);
FfxFloat32 mx4R = max(ffxMax3(bR, dR, fR), hR);
FfxFloat32 mx4G = max(ffxMax3(bG, dG, fG), hG);
FfxFloat32 mx4B = max(ffxMax3(bB, dB, fB), hB);
FfxFloat32x2 peakC = FfxFloat32x2(1.0, -1.0 * 4.0);
FfxFloat32 hitMinR = mn4R * rcp(FfxFloat32(4.0) * mx4R);
FfxFloat32 hitMinG = mn4G * rcp(FfxFloat32(4.0) * mx4G);
FfxFloat32 hitMinB = mn4B * rcp(FfxFloat32(4.0) * mx4B);
FfxFloat32 hitMaxR = (peakC.x - mx4R) * rcp(FfxFloat32(4.0) * mn4R + peakC.y);
FfxFloat32 hitMaxG = (peakC.x - mx4G) * rcp(FfxFloat32(4.0) * mn4G + peakC.y);
FfxFloat32 hitMaxB = (peakC.x - mx4B) * rcp(FfxFloat32(4.0) * mn4B + peakC.y);
FfxFloat32 lobeR = max(-hitMinR, hitMaxR);
FfxFloat32 lobeG = max(-hitMinG, hitMaxG);
FfxFloat32 lobeB = max(-hitMinB, hitMaxB);
FfxFloat32 lobe = max(FfxFloat32(-FSR_RCAS_LIMIT), ffxMin(ffxMax3(lobeR, lobeG, lobeB), FfxFloat32(0.0))) * ffxAsFloat
(con.x);
#ifdef FSR_RCAS_DENOISE
lobe *= nz;
#endif
FfxFloat32 rcpL = ffxApproximateReciprocalMedium(FfxFloat32(4.0) * lobe + FfxFloat32(1.0));
pixR = (lobe * bR + lobe * dR + lobe * hR + lobe * fR + eR) * rcpL;
pixG = (lobe * bG + lobe * dG + lobe * hG + lobe * fG + eG) * rcpL;
pixB = (lobe * bB + lobe * dB + lobe * hB + lobe * fB + eB) * rcpL;
return;
}
#endif
#if defined(FFX_GPU) && FFX_HALF == 1 && defined(FSR_RCAS_H)
FfxFloat16x4 FsrRcasLoadH(FfxInt16x2 p);
void FsrRcasInputH(inout FfxFloat16 r,inout FfxFloat16 g,inout FfxFloat16 b);
void FsrRcasH(
out FfxFloat16 pixR,
out FfxFloat16 pixG,
out FfxFloat16 pixB,
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
out FfxFloat16 pixA,
#endif
FfxUInt32x2 ip,
FfxUInt32x4 con){
FfxInt16x2 sp=FfxInt16x2(ip);
FfxFloat16x3 b=FsrRcasLoadH(sp+FfxInt16x2( 0,-1)).rgb;
FfxFloat16x3 d=FsrRcasLoadH(sp+FfxInt16x2(-1, 0)).rgb;
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
FfxFloat16x4 ee=FsrRcasLoadH(sp);
FfxFloat16x3 e=ee.rgb;pixA=ee.a;
#else
FfxFloat16x3 e=FsrRcasLoadH(sp).rgb;
#endif
FfxFloat16x3 f=FsrRcasLoadH(sp+FfxInt16x2( 1, 0)).rgb;
FfxFloat16x3 h=FsrRcasLoadH(sp+FfxInt16x2( 0, 1)).rgb;
FfxFloat16 bR=b.r;
FfxFloat16 bG=b.g;
FfxFloat16 bB=b.b;
FfxFloat16 dR=d.r;
FfxFloat16 dG=d.g;
FfxFloat16 dB=d.b;
FfxFloat16 eR=e.r;
FfxFloat16 eG=e.g;
FfxFloat16 eB=e.b;
FfxFloat16 fR=f.r;
FfxFloat16 fG=f.g;
FfxFloat16 fB=f.b;
FfxFloat16 hR=h.r;
FfxFloat16 hG=h.g;
FfxFloat16 hB=h.b;
FsrRcasInputH(bR,bG,bB);
FsrRcasInputH(dR,dG,dB);
FsrRcasInputH(eR,eG,eB);
FsrRcasInputH(fR,fG,fB);
FsrRcasInputH(hR,hG,hB);
FfxFloat16 bL=bB*FFX_BROADCAST_FLOAT16(0.5)+(bR*FFX_BROADCAST_FLOAT16(0.5)+bG);
FfxFloat16 dL=dB*FFX_BROADCAST_FLOAT16(0.5)+(dR*FFX_BROADCAST_FLOAT16(0.5)+dG);
FfxFloat16 eL=eB*FFX_BROADCAST_FLOAT16(0.5)+(eR*FFX_BROADCAST_FLOAT16(0.5)+eG);
FfxFloat16 fL=fB*FFX_BROADCAST_FLOAT16(0.5)+(fR*FFX_BROADCAST_FLOAT16(0.5)+fG);
FfxFloat16 hL=hB*FFX_BROADCAST_FLOAT16(0.5)+(hR*FFX_BROADCAST_FLOAT16(0.5)+hG);
FfxFloat16 nz=FFX_BROADCAST_FLOAT16(0.25)*bL+FFX_BROADCAST_FLOAT16(0.25)*dL+FFX_BROADCAST_FLOAT16(0.25)*fL+FFX_BROADCAST_FLOAT16(0.25)*hL-eL;
nz=ffxSaturate(abs(nz)*ffxApproximateReciprocalMediumHalf(ffxMax3Half(ffxMax3Half(bL,dL,eL),fL,hL)-ffxMin3Half(ffxMin3Half(bL,dL,eL),fL,hL)));
nz=FFX_BROADCAST_FLOAT16(-0.5)*nz+FFX_BROADCAST_FLOAT16(1.0);
FfxFloat16 mn4R=min(ffxMin3Half(bR,dR,fR),hR);
FfxFloat16 mn4G=min(ffxMin3Half(bG,dG,fG),hG);
FfxFloat16 mn4B=min(ffxMin3Half(bB,dB,fB),hB);
FfxFloat16 mx4R=max(ffxMax3Half(bR,dR,fR),hR);
FfxFloat16 mx4G=max(ffxMax3Half(bG,dG,fG),hG);
FfxFloat16 mx4B=max(ffxMax3Half(bB,dB,fB),hB);
FfxFloat16x2 peakC=FfxFloat16x2(1.0,-1.0*4.0);
FfxFloat16 hitMinR=mn4R*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mx4R);
FfxFloat16 hitMinG=mn4G*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mx4G);
FfxFloat16 hitMinB=mn4B*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mx4B);
FfxFloat16 hitMaxR=(peakC.x-mx4R)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mn4R+peakC.y);
FfxFloat16 hitMaxG=(peakC.x-mx4G)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mn4G+peakC.y);
FfxFloat16 hitMaxB=(peakC.x-mx4B)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16(4.0)*mn4B+peakC.y);
FfxFloat16 lobeR=max(-hitMinR,hitMaxR);
FfxFloat16 lobeG=max(-hitMinG,hitMaxG);
FfxFloat16 lobeB=max(-hitMinB,hitMaxB);
FfxFloat16 lobe=max(FFX_BROADCAST_FLOAT16(-FSR_RCAS_LIMIT),min(ffxMax3Half(lobeR,lobeG,lobeB),FFX_BROADCAST_FLOAT16(0.0)))*FFX_UINT32_TO_FLOAT16X2(con.y).x;
#ifdef FSR_RCAS_DENOISE
lobe*=nz;
#endif
FfxFloat16 rcpL=ffxApproximateReciprocalMediumHalf(FFX_BROADCAST_FLOAT16(4.0)*lobe+FFX_BROADCAST_FLOAT16(1.0));
pixR=(lobe*bR+lobe*dR+lobe*hR+lobe*fR+eR)*rcpL;
pixG=(lobe*bG+lobe*dG+lobe*hG+lobe*fG+eG)*rcpL;
pixB=(lobe*bB+lobe*dB+lobe*hB+lobe*fB+eB)*rcpL;
}
#endif
#if defined(FFX_GPU)&& FFX_HALF == 1 && defined(FSR_RCAS_HX2)
FfxFloat16x4 FsrRcasLoadHx2(FfxInt16x2 p);
void FsrRcasInputHx2(inout FfxFloat16x2 r,inout FfxFloat16x2 g,inout FfxFloat16x2 b);
void FsrRcasDepackHx2(out FfxFloat16x4 pix0,out FfxFloat16x4 pix1,FfxFloat16x2 pixR,FfxFloat16x2 pixG,FfxFloat16x2 pixB){
#ifdef FFX_HLSL
pix0.a=pix1.a=0.0;
#endif
pix0.rgb=FfxFloat16x3(pixR.x,pixG.x,pixB.x);
pix1.rgb=FfxFloat16x3(pixR.y,pixG.y,pixB.y);}
void FsrRcasHx2(
out FfxFloat16x2 pixR,
out FfxFloat16x2 pixG,
out FfxFloat16x2 pixB,
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
out FfxFloat16x2 pixA,
#endif
FfxUInt32x2 ip,
FfxUInt32x4 con){
FfxInt16x2 sp0=FfxInt16x2(ip);
FfxFloat16x3 b0=FsrRcasLoadHx2(sp0+FfxInt16x2( 0,-1)).rgb;
FfxFloat16x3 d0=FsrRcasLoadHx2(sp0+FfxInt16x2(-1, 0)).rgb;
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
FfxFloat16x4 ee0=FsrRcasLoadHx2(sp0);
FfxFloat16x3 e0=ee0.rgb;pixA.r=ee0.a;
#else
FfxFloat16x3 e0=FsrRcasLoadHx2(sp0).rgb;
#endif
FfxFloat16x3 f0=FsrRcasLoadHx2(sp0+FfxInt16x2( 1, 0)).rgb;
FfxFloat16x3 h0=FsrRcasLoadHx2(sp0+FfxInt16x2( 0, 1)).rgb;
FfxInt16x2 sp1=sp0+FfxInt16x2(8,0);
FfxFloat16x3 b1=FsrRcasLoadHx2(sp1+FfxInt16x2( 0,-1)).rgb;
FfxFloat16x3 d1=FsrRcasLoadHx2(sp1+FfxInt16x2(-1, 0)).rgb;
#ifdef FSR_RCAS_PASSTHROUGH_ALPHA
FfxFloat16x4 ee1=FsrRcasLoadHx2(sp1);
FfxFloat16x3 e1=ee1.rgb;pixA.g=ee1.a;
#else
FfxFloat16x3 e1=FsrRcasLoadHx2(sp1).rgb;
#endif
FfxFloat16x3 f1=FsrRcasLoadHx2(sp1+FfxInt16x2( 1, 0)).rgb;
FfxFloat16x3 h1=FsrRcasLoadHx2(sp1+FfxInt16x2( 0, 1)).rgb;
FfxFloat16x2 bR=FfxFloat16x2(b0.r,b1.r);
FfxFloat16x2 bG=FfxFloat16x2(b0.g,b1.g);
FfxFloat16x2 bB=FfxFloat16x2(b0.b,b1.b);
FfxFloat16x2 dR=FfxFloat16x2(d0.r,d1.r);
FfxFloat16x2 dG=FfxFloat16x2(d0.g,d1.g);
FfxFloat16x2 dB=FfxFloat16x2(d0.b,d1.b);
FfxFloat16x2 eR=FfxFloat16x2(e0.r,e1.r);
FfxFloat16x2 eG=FfxFloat16x2(e0.g,e1.g);
FfxFloat16x2 eB=FfxFloat16x2(e0.b,e1.b);
FfxFloat16x2 fR=FfxFloat16x2(f0.r,f1.r);
FfxFloat16x2 fG=FfxFloat16x2(f0.g,f1.g);
FfxFloat16x2 fB=FfxFloat16x2(f0.b,f1.b);
FfxFloat16x2 hR=FfxFloat16x2(h0.r,h1.r);
FfxFloat16x2 hG=FfxFloat16x2(h0.g,h1.g);
FfxFloat16x2 hB=FfxFloat16x2(h0.b,h1.b);
FsrRcasInputHx2(bR,bG,bB);
FsrRcasInputHx2(dR,dG,dB);
FsrRcasInputHx2(eR,eG,eB);
FsrRcasInputHx2(fR,fG,fB);
FsrRcasInputHx2(hR,hG,hB);
FfxFloat16x2 bL=bB*FFX_BROADCAST_FLOAT16X2(0.5)+(bR*FFX_BROADCAST_FLOAT16X2(0.5)+bG);
FfxFloat16x2 dL=dB*FFX_BROADCAST_FLOAT16X2(0.5)+(dR*FFX_BROADCAST_FLOAT16X2(0.5)+dG);
FfxFloat16x2 eL=eB*FFX_BROADCAST_FLOAT16X2(0.5)+(eR*FFX_BROADCAST_FLOAT16X2(0.5)+eG);
FfxFloat16x2 fL=fB*FFX_BROADCAST_FLOAT16X2(0.5)+(fR*FFX_BROADCAST_FLOAT16X2(0.5)+fG);
FfxFloat16x2 hL=hB*FFX_BROADCAST_FLOAT16X2(0.5)+(hR*FFX_BROADCAST_FLOAT16X2(0.5)+hG);
FfxFloat16x2 nz=FFX_BROADCAST_FLOAT16X2(0.25)*bL+FFX_BROADCAST_FLOAT16X2(0.25)*dL+FFX_BROADCAST_FLOAT16X2(0.25)*fL+FFX_BROADCAST_FLOAT16X2(0.25)*hL-eL;
nz=ffxSaturate(abs(nz)*ffxApproximateReciprocalMediumHalf(ffxMax3Half(ffxMax3Half(bL,dL,eL),fL,hL)-ffxMin3Half(ffxMin3Half(bL,dL,eL),fL,hL)));
nz=FFX_BROADCAST_FLOAT16X2(-0.5)*nz+FFX_BROADCAST_FLOAT16X2(1.0);
FfxFloat16x2 mn4R=min(ffxMin3Half(bR,dR,fR),hR);
FfxFloat16x2 mn4G=min(ffxMin3Half(bG,dG,fG),hG);
FfxFloat16x2 mn4B=min(ffxMin3Half(bB,dB,fB),hB);
FfxFloat16x2 mx4R=max(ffxMax3Half(bR,dR,fR),hR);
FfxFloat16x2 mx4G=max(ffxMax3Half(bG,dG,fG),hG);
FfxFloat16x2 mx4B=max(ffxMax3Half(bB,dB,fB),hB);
FfxFloat16x2 peakC=FfxFloat16x2(1.0,-1.0*4.0);
FfxFloat16x2 hitMinR=mn4R*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mx4R);
FfxFloat16x2 hitMinG=mn4G*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mx4G);
FfxFloat16x2 hitMinB=mn4B*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mx4B);
FfxFloat16x2 hitMaxR=(peakC.x-mx4R)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mn4R+peakC.y);
FfxFloat16x2 hitMaxG=(peakC.x-mx4G)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mn4G+peakC.y);
FfxFloat16x2 hitMaxB=(peakC.x-mx4B)*ffxReciprocalHalf(FFX_BROADCAST_FLOAT16X2(4.0)*mn4B+peakC.y);
FfxFloat16x2 lobeR=max(-hitMinR,hitMaxR);
FfxFloat16x2 lobeG=max(-hitMinG,hitMaxG);
FfxFloat16x2 lobeB=max(-hitMinB,hitMaxB);
FfxFloat16x2 lobe=max(FFX_BROADCAST_FLOAT16X2(-FSR_RCAS_LIMIT),min(ffxMax3Half(lobeR,lobeG,lobeB),FFX_BROADCAST_FLOAT16X2(0.0)))*FFX_BROADCAST_FLOAT16X2(FFX_UINT32_TO_FLOAT16X2(con.y).x);
#ifdef FSR_RCAS_DENOISE
lobe*=nz;
#endif
FfxFloat16x2 rcpL=ffxApproximateReciprocalMediumHalf(FFX_BROADCAST_FLOAT16X2(4.0)*lobe+FFX_BROADCAST_FLOAT16X2(1.0));
pixR=(lobe*bR+lobe*dR+lobe*hR+lobe*fR+eR)*rcpL;
pixG=(lobe*bG+lobe*dG+lobe*hG+lobe*fG+eG)*rcpL;
pixB=(lobe*bB+lobe*dB+lobe*hB+lobe*fB+eB)*rcpL;}
#endif
#if defined(FFX_GPU)
void FsrLfgaF(inout FfxFloat32x3 c, FfxFloat32x3 t, FfxFloat32 a)
{
c += (t * ffxBroadcast3(a)) * ffxMin(ffxBroadcast3(1.0) - c, c);
}
#endif
#if defined(FFX_GPU)&& FFX_HALF == 1
void FsrLfgaH(inout FfxFloat16x3 c, FfxFloat16x3 t, FfxFloat16 a)
{
c += (t * FFX_BROADCAST_FLOAT16X3(a)) * min(FFX_BROADCAST_FLOAT16X3(1.0) - c, c);
}
void FsrLfgaHx2(inout FfxFloat16x2 cR,inout FfxFloat16x2 cG,inout FfxFloat16x2 cB,FfxFloat16x2 tR,FfxFloat16x2 tG,FfxFloat16x2 tB,FfxFloat16 a){
cR+=(tR*FFX_BROADCAST_FLOAT16X2(a))*min(FFX_BROADCAST_FLOAT16X2(1.0)-cR,cR);cG+=(tG*FFX_BROADCAST_FLOAT16X2(a))*min(FFX_BROADCAST_FLOAT16X2(1.0)-cG,cG);cB+=(tB*FFX_BROADCAST_FLOAT16X2(a))*min(FFX_BROADCAST_FLOAT16X2(1.0)-cB,cB);}
#endif
#if defined(FFX_GPU)
void FsrSrtmF(inout FfxFloat32x3 c)
{
c *= ffxBroadcast3(rcp(ffxMax3(c.r, c.g, c.b) + FfxFloat32(1.0)));
}
void FsrSrtmInvF(inout FfxFloat32x3 c){c*=ffxBroadcast3(rcp(max(FfxFloat32(1.0/32768.0),FfxFloat32(1.0)-ffxMax3(c.r,c.g,c.b))));}
#endif
#if defined(FFX_GPU )&& FFX_HALF == 1
void FsrSrtmH(inout FfxFloat16x3 c)
{
c *= FFX_BROADCAST_FLOAT16X3(ffxReciprocalHalf(ffxMax3Half(c.r, c.g, c.b) + FFX_BROADCAST_FLOAT16(1.0)));
}
void FsrSrtmInvH(inout FfxFloat16x3 c)
{
c *= FFX_BROADCAST_FLOAT16X3(ffxReciprocalHalf(max(FFX_BROADCAST_FLOAT16(1.0 / 32768.0), FFX_BROADCAST_FLOAT16(1.0) - ffxMax3Half(c.r, c.g, c.b))));
}
void FsrSrtmHx2(inout FfxFloat16x2 cR, inout FfxFloat16x2 cG, inout FfxFloat16x2 cB)
{
FfxFloat16x2 rcp = ffxReciprocalHalf(ffxMax3Half(cR, cG, cB) + FFX_BROADCAST_FLOAT16X2(1.0));
cR *= rcp;
cG *= rcp;
cB *= rcp;
}
void FsrSrtmInvHx2(inout FfxFloat16x2 cR,inout FfxFloat16x2 cG,inout FfxFloat16x2 cB)
{
FfxFloat16x2 rcp=ffxReciprocalHalf(max(FFX_BROADCAST_FLOAT16X2(1.0/32768.0),FFX_BROADCAST_FLOAT16X2(1.0)-ffxMax3Half(cR,cG,cB)));
cR*=rcp;
cG*=rcp;
cB*=rcp;
}
#endif
#if defined(FFX_GPU)
FfxFloat32 FsrTepdDitF(FfxUInt32x2 p, FfxUInt32 f)
{
FfxFloat32 x = FfxFloat32(p.x + f);
FfxFloat32 y = FfxFloat32(p.y);
FfxFloat32 a = FfxFloat32((1.0 + ffxSqrt(5.0f)) / 2.0);
FfxFloat32 b = FfxFloat32(1.0 / 3.69);
x = x * a + (y * b);
return ffxFract(x);
}
void FsrTepdC8F(inout FfxFloat32x3 c, FfxFloat32 dit)
{
FfxFloat32x3 n = ffxSqrt(c);
n = floor(n * ffxBroadcast3(255.0)) * ffxBroadcast3(1.0 / 255.0);
FfxFloat32x3 a = n * n;
FfxFloat32x3 b = n + ffxBroadcast3(1.0 / 255.0);
b = b * b;
FfxFloat32x3 r = (c - b) * ffxApproximateReciprocalMedium(a - b);
c = ffxSaturate(n + ffxIsGreaterThanZero(ffxBroadcast3(dit) - r) * ffxBroadcast3(1.0 / 255.0));
}
void FsrTepdC10F(inout FfxFloat32x3 c, FfxFloat32 dit)
{
FfxFloat32x3 n = ffxSqrt(c);
n = floor(n * ffxBroadcast3(1023.0)) * ffxBroadcast3(1.0 / 1023.0);
FfxFloat32x3 a = n * n;
FfxFloat32x3 b = n + ffxBroadcast3(1.0 / 1023.0);
b = b * b;
FfxFloat32x3 r = (c - b) * ffxApproximateReciprocalMedium(a - b);
c = ffxSaturate(n + ffxIsGreaterThanZero(ffxBroadcast3(dit) - r) * ffxBroadcast3(1.0 / 1023.0));
}
#endif
#if defined(FFX_GPU)&& FFX_HALF == 1
FfxFloat16 FsrTepdDitH(FfxUInt32x2 p, FfxUInt32 f)
{
FfxFloat32 x = FfxFloat32(p.x + f);
FfxFloat32 y = FfxFloat32(p.y);
FfxFloat32 a = FfxFloat32((1.0 + ffxSqrt(5.0f)) / 2.0);
FfxFloat32 b = FfxFloat32(1.0 / 3.69);
x = x * a + (y * b);
return FfxFloat16(ffxFract(x));
}
void FsrTepdC8H(inout FfxFloat16x3 c, FfxFloat16 dit)
{
FfxFloat16x3 n = sqrt(c);
n = floor(n * FFX_BROADCAST_FLOAT16X3(255.0)) * FFX_BROADCAST_FLOAT16X3(1.0 / 255.0);
FfxFloat16x3 a = n * n;
FfxFloat16x3 b = n + FFX_BROADCAST_FLOAT16X3(1.0 / 255.0);
b = b * b;
FfxFloat16x3 r = (c - b) * ffxApproximateReciprocalMediumHalf(a - b);
c = ffxSaturate(n + ffxIsGreaterThanZeroHalf(FFX_BROADCAST_FLOAT16X3(dit) - r) * FFX_BROADCAST_FLOAT16X3(1.0 / 255.0));
}
void FsrTepdC10H(inout FfxFloat16x3 c, FfxFloat16 dit)
{
FfxFloat16x3 n = sqrt(c);
n = floor(n * FFX_BROADCAST_FLOAT16X3(1023.0)) * FFX_BROADCAST_FLOAT16X3(1.0 / 1023.0);
FfxFloat16x3 a = n * n;
FfxFloat16x3 b = n + FFX_BROADCAST_FLOAT16X3(1.0 / 1023.0);
b = b * b;
FfxFloat16x3 r = (c - b) * ffxApproximateReciprocalMediumHalf(a - b);
c = ffxSaturate(n + ffxIsGreaterThanZeroHalf(FFX_BROADCAST_FLOAT16X3(dit) - r) * FFX_BROADCAST_FLOAT16X3(1.0 / 1023.0));
}
FfxFloat16x2 FsrTepdDitHx2(FfxUInt32x2 p, FfxUInt32 f)
{
FfxFloat32x2 x;
x.x = FfxFloat32(p.x + f);
x.y = x.x + FfxFloat32(8.0);
FfxFloat32 y = FfxFloat32(p.y);
FfxFloat32 a = FfxFloat32((1.0 + ffxSqrt(5.0f)) / 2.0);
FfxFloat32 b = FfxFloat32(1.0 / 3.69);
x = x * ffxBroadcast2(a) + ffxBroadcast2(y * b);
return FfxFloat16x2(ffxFract(x));
}
void FsrTepdC8Hx2(inout FfxFloat16x2 cR, inout FfxFloat16x2 cG, inout FfxFloat16x2 cB, FfxFloat16x2 dit)
{
FfxFloat16x2 nR = sqrt(cR);
FfxFloat16x2 nG = sqrt(cG);
FfxFloat16x2 nB = sqrt(cB);
nR = floor(nR * FFX_BROADCAST_FLOAT16X2(255.0)) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
nG = floor(nG * FFX_BROADCAST_FLOAT16X2(255.0)) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
nB = floor(nB * FFX_BROADCAST_FLOAT16X2(255.0)) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
FfxFloat16x2 aR = nR * nR;
FfxFloat16x2 aG = nG * nG;
FfxFloat16x2 aB = nB * nB;
FfxFloat16x2 bR = nR + FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
bR = bR * bR;
FfxFloat16x2 bG = nG + FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
bG = bG * bG;
FfxFloat16x2 bB = nB + FFX_BROADCAST_FLOAT16X2(1.0 / 255.0);
bB = bB * bB;
FfxFloat16x2 rR = (cR - bR) * ffxApproximateReciprocalMediumHalf(aR - bR);
FfxFloat16x2 rG = (cG - bG) * ffxApproximateReciprocalMediumHalf(aG - bG);
FfxFloat16x2 rB = (cB - bB) * ffxApproximateReciprocalMediumHalf(aB - bB);
cR = ffxSaturate(nR + ffxIsGreaterThanZeroHalf(dit - rR) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0));
cG = ffxSaturate(nG + ffxIsGreaterThanZeroHalf(dit - rG) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0));
cB = ffxSaturate(nB + ffxIsGreaterThanZeroHalf(dit - rB) * FFX_BROADCAST_FLOAT16X2(1.0 / 255.0));
}
void FsrTepdC10Hx2(inout FfxFloat16x2 cR,inout FfxFloat16x2 cG,inout FfxFloat16x2 cB,FfxFloat16x2 dit){
FfxFloat16x2 nR=sqrt(cR);
FfxFloat16x2 nG=sqrt(cG);
FfxFloat16x2 nB=sqrt(cB);
nR=floor(nR*FFX_BROADCAST_FLOAT16X2(1023.0))*FFX_BROADCAST_FLOAT16X2(1.0/1023.0);
nG=floor(nG*FFX_BROADCAST_FLOAT16X2(1023.0))*FFX_BROADCAST_FLOAT16X2(1.0/1023.0);
nB=floor(nB*FFX_BROADCAST_FLOAT16X2(1023.0))*FFX_BROADCAST_FLOAT16X2(1.0/1023.0);
FfxFloat16x2 aR=nR*nR;
FfxFloat16x2 aG=nG*nG;
FfxFloat16x2 aB=nB*nB;
FfxFloat16x2 bR=nR+FFX_BROADCAST_FLOAT16X2(1.0/1023.0);bR=bR*bR;
FfxFloat16x2 bG=nG+FFX_BROADCAST_FLOAT16X2(1.0/1023.0);bG=bG*bG;
FfxFloat16x2 bB=nB+FFX_BROADCAST_FLOAT16X2(1.0/1023.0);bB=bB*bB;
FfxFloat16x2 rR=(cR-bR)*ffxApproximateReciprocalMediumHalf(aR-bR);
FfxFloat16x2 rG=(cG-bG)*ffxApproximateReciprocalMediumHalf(aG-bG);
FfxFloat16x2 rB=(cB-bB)*ffxApproximateReciprocalMediumHalf(aB-bB);
cR=ffxSaturate(nR+ffxIsGreaterThanZeroHalf(dit-rR)*FFX_BROADCAST_FLOAT16X2(1.0/1023.0));
cG=ffxSaturate(nG+ffxIsGreaterThanZeroHalf(dit-rG)*FFX_BROADCAST_FLOAT16X2(1.0/1023.0));
cB = ffxSaturate(nB + ffxIsGreaterThanZeroHalf(dit - rB) * FFX_BROADCAST_FLOAT16X2(1.0 / 1023.0));
}
#endif