#version 460 compatibility
#define COMP 1
#define GLOBAL_DATA_MODIFIER buffer
#extension GL_KHR_shader_subgroup_ballot : enable
// This file is generated by options.main.kts. Do not edit this file manually.
#define TITLE_VERSION 3//[0 1 2 3 4 5]
#define SETTING_SHADOW_MAP_RESOLUTION 2048//[1024 2048 3072 4096]
const float shadowDistance = 512.0;//[64.0 128.0 192.0 256.0 384.0 512.0]
const float sunPathRotation = -20.0;//[-90.0 -89.0 -88.0 -87.0 -86.0 -85.0 -84.0 -83.0 -82.0 -81.0 -80.0 -79.0 -78.0 -77.0 -76.0 -75.0 -74.0 -73.0 -72.0 -71.0 -70.0 -69.0 -68.0 -67.0 -66.0 -65.0 -64.0 -63.0 -62.0 -61.0 -60.0 -59.0 -58.0 -57.0 -56.0 -55.0 -54.0 -53.0 -52.0 -51.0 -50.0 -49.0 -48.0 -47.0 -46.0 -45.0 -44.0 -43.0 -42.0 -41.0 -40.0 -39.0 -38.0 -37.0 -36.0 -35.0 -34.0 -33.0 -32.0 -31.0 -30.0 -29.0 -28.0 -27.0 -26.0 -25.0 -24.0 -23.0 -22.0 -21.0 -20.0 -19.0 -18.0 -17.0 -16.0 -15.0 -14.0 -13.0 -12.0 -11.0 -10.0 -9.0 -8.0 -7.0 -6.0 -5.0 -4.0 -3.0 -2.0 -1.0 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0 20.0 21.0 22.0 23.0 24.0 25.0 26.0 27.0 28.0 29.0 30.0 31.0 32.0 33.0 34.0 35.0 36.0 37.0 38.0 39.0 40.0 41.0 42.0 43.0 44.0 45.0 46.0 47.0 48.0 49.0 50.0 51.0 52.0 53.0 54.0 55.0 56.0 57.0 58.0 59.0 60.0 61.0 62.0 63.0 64.0 65.0 66.0 67.0 68.0 69.0 70.0 71.0 72.0 73.0 74.0 75.0 76.0 77.0 78.0 79.0 80.0 81.0 82.0 83.0 84.0 85.0 86.0 87.0 88.0 89.0 90.0]
#define SETTING_MATERIAL_COLOR_SPACE 1//[0 1 2 3 4 5 6 7 8]
#define SETTING_MATERIAL_TRANSFER_FUNC 3//[0 1 2 3 4 5 6 7]
#define SETTING_WORKING_COLOR_SPACE 8//[0 1 2 3 4 5 6 7 8]
#define SETTING_DRT_WORKING_COLOR_SPACE 1//[0 1 2 3 4 5 6 7 8]
//#define SETTING_ASSUME_NVIDIA_GPU
#ifdef SETTING_ASSUME_NVIDIA_GPU
#endif
//#define SETTING_DEBUG_AE
#ifdef SETTING_DEBUG_AE
#endif
#if SETTING_SHADOW_MAP_RESOLUTION == 1024
#define SHADOW_MAP_SIZE_D16 64
const int shadowMapResolution = 1024;
#elif SETTING_SHADOW_MAP_RESOLUTION == 2048
#define SHADOW_MAP_SIZE_D16 128
const int shadowMapResolution = 2048;
#elif SETTING_SHADOW_MAP_RESOLUTION == 3072
#define SHADOW_MAP_SIZE_D16 192
const int shadowMapResolution = 3072;
#elif SETTING_SHADOW_MAP_RESOLUTION == 4096
#define SHADOW_MAP_SIZE_D16 256
const int shadowMapResolution = 4096;
#endif
uniform float near;
uniform float far;
uniform mat4 gbufferPreviousModelView;
uniform mat4 textureMatrix = mat4(1.0);
#ifdef DISTANT_HORIZONS
uniform float dhNearPlane;
uniform float dhFarPlane;
float farPlane = max(dhFarPlane, far);
float nearPlane = min(dhNearPlane, near);
#else
float farPlane = far;
float nearPlane = near;
#endif
uniform int uval_mainImageSizeIX;
uniform int uval_mainImageSizeIY;
ivec2 uval_mainImageSizeI = ivec2(uval_mainImageSizeIX, uval_mainImageSizeIY);
#ifndef GLOBAL_DATA_MODIFIER
#define GLOBAL_DATA_MODIFIER restrict readonly buffer
#endif
struct AEData {
    vec4 lastScreenAvgLum;
    vec4 screenAvgLum;
    vec4 expValues;
    vec2 hsPercents;
    uint shadowCount;
    uint highlightCount;
    uint weightSum;
    #ifdef SETTING_DEBUG_AE
    uint lumHistogram[256];
    uint lumHistogramMaxBinCount;
    float finalAvgLum;
    #endif
};
struct CameraData {
    uint frustumPlaneCount;
    vec4 frustumPlanes[6];
};
mat4 gbufferPrevModelView = gbufferPreviousModelView;
layout(std430, binding = 0) GLOBAL_DATA_MODIFIER GlobalData {
    uvec4 global_dispatchSize1;
    uvec4 global_dispatchSize2;
    uvec4 global_dispatchSize3;
    uvec4 global_dispatchSize4;
    mat4 gbufferPrevModelViewInverse;
    mat4 global_shadowRotationMatrix;
    mat4 global_shadowRotationMatrixInverse;
    mat4 global_taaJitterMat;
    mat4 global_camProj;
    mat4 global_camProjInverse;
    mat4 global_prevCamProj;
    mat4 global_prevCamProjInverse;
    mat4 global_shadowProjPrev;
    mat4 global_shadowProjInversePrev;
    mat4 global_shadowProj;
    mat4 global_shadowProjInverse;
    mat4 global_shadowView;
    mat4 global_shadowViewInverse;
    mat4 global_sceneToShadowNDC;
    mat4 global_shadowViewToShadowNDC;
    mat4 global_shadowNDCToScene;
    vec3 global_prevCameraDelta;
    vec2 global_prevTaaJitter;
    vec2 global_taaJitter;
    CameraData global_cameraData;
    vec2 global_mipmapSizes[16];
    vec2 global_mipmapSizesRcp[16];
    ivec4 global_mipmapTiles3[16];
    ivec2 global_mipmapSizesI[16];
    ivec2 global_mipmapSizePrefixesPadded[16];
    ivec2 global_mipmapSizePrefixes[16];
    ivec4 global_hizTiles[16];
    ivec4 global_mipmapTileCeil[16];
    ivec4 global_mipmapTileCeilPadded[16];
    ivec3 global_shadowAABBMinPrev;
    ivec3 global_shadowAABBMaxPrev;
    ivec3 global_shadowAABBMin;
    ivec3 global_shadowAABBMax;
    vec3 global_shadowAABBMinHistory;
    vec3 global_shadowAABBMaxHistory;
    ivec3 global_shadowAABBMinNew;
    ivec3 global_shadowAABBMaxNew;
    float global_focusDistance;
    int global_lastWorldTime;
    float global_historyResetFactor;
    vec4 global_motionFactor;
    vec4 global_taaResetFactor;
    float global_turbidity;
    AEData global_aeData;
    uint global_atomicCounters[16];
};
layout(std430, binding = 1) GLOBAL_DATA_MODIFIER IndirectComputeData {
    uint indirectComputeData[];
};
const vec2 SHADOW_MAP_SIZE = vec2(float(shadowMapResolution), 1.0 / float(shadowMapResolution));
uniform sampler2D colortex0;
uniform sampler2D usam_rgba8;
#define saturate(x) clamp(x, 0.0, 1.0)
ivec2 _textile_texelToTexel(ivec2 texelPos, ivec2 tileOffset, ivec2 tileSize) {
    return clamp(texelPos, ivec2(0), tileSize - 1) + tileOffset;
}
vec2 _textile_uvToUV(vec2 uv, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(uv * tileSizeF, vec2(0.5), tileSizeF - 0.5) + tileOffsetF;
    return saturate(textureTexelPos * atlastSizeRcp);
}
vec2 _textile_uvToGatherUV(vec2 uv, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(uv * tileSizeF, vec2(1.0), tileSizeF - 1.0) + tileOffsetF;
    return saturate(textureTexelPos * atlastSizeRcp);
}
vec2 _textile_texelToGatherUV(vec2 texelPos, vec2 tileOffsetF, vec2 tileSizeF, vec2 atlastSizeRcp) {
    vec2 textureTexelPos = clamp(texelPos, vec2(1.0), tileSizeF - 1.0) + tileOffsetF;
    return saturate(textureTexelPos * atlastSizeRcp);
}
#undef saturate
#define _shadesmith_RGBA8_2_OFFSET (uval_mainImageSizeI * ivec2(1, 0))
#define _shadesmith_RGBA8_2_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA8_2_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA8_2_OFFSET, _shadesmith_RGBA8_2_SIZE)
#define transient_exposureWeights_fetch(x) texelFetch(usam_rgba8, _shadesmith_RGBA8_2_TEXEL_TO_TEXEL(x), 0)
#define _shadesmith_RGBA32UI_3_OFFSET (uval_mainImageSizeI * ivec2(1, 1))
#define _shadesmith_RGBA32UI_3_SIZE uval_mainImageSizeI
#define _shadesmith_RGBA32UI_3_TEXEL_TO_TEXEL(texelPos) _textile_texelToTexel(texelPos, _shadesmith_RGBA32UI_3_OFFSET, _shadesmith_RGBA32UI_3_SIZE)
#define transient_mainMipTemp_load(x) imageLoad(uimg_rgba32ui, _shadesmith_RGBA32UI_3_TEXEL_TO_TEXEL(x))
#define transient_mainMipTemp_store(x, v) imageStore(uimg_rgba32ui, _shadesmith_RGBA32UI_3_TEXEL_TO_TEXEL(x), v)
#if defined MC_GL_AMD_gpu_shader_half_float
#extension GL_AMD_gpu_shader_half_float : enable
#elif defined MC_GL_NV_gpu_shader5 || defined SETTING_ASSUME_NVIDIA_GPU
#extension GL_NV_gpu_shader5 : enable
#else
#define NO_HALF a
#define hf
#define float16_t float
#define f16vec2 vec2
#define f16vec3 vec3
#define f16vec4 vec4
#define f16mat2 mat2
#define f16mat3 mat3
#define f16mat4 mat4
#endif
#define COLORS2_COLORSPACES_CIE_XYZ 0
#define COLORS2_COLORSPACES_SRGB 1
#define COLORS2_COLORSPACES_REC709 2
#define COLORS2_COLORSPACES_REC2020 3
#define COLORS2_COLORSPACES_DCI_P3 4
#define COLORS2_COLORSPACES_ADOBE_RGB_1998 5
#define COLORS2_COLORSPACES_ACES_AP0 6
#define COLORS2_COLORSPACES_ACES_AP1 7
#define COLORS2_COLORSPACES_COLOR_MCSPACEFACE 8
#define _colors2_colorspaces_convert(a, b, x) colors2_colorspaces_ ## a ## _to_ ## b ##(x)
#define colors2_colorspaces_convert(a, b, x) _colors2_colorspaces_convert(a, b, x)
#define _colors2_colorspaces_luma(a, x) colors2_colorspaces_ ## a ## _luma(x)
#define colors2_colorspaces_luma(a, x) _colors2_colorspaces_luma(a, x)
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_CIE_XYZ = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_SRGB = mat3(
    3.2406, -1.5372, -0.4986,
    -0.9689, 1.8758, 0.0415,
    0.0557, -0.204, 1.057
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_REC709 = mat3(
    3.2409699419, -1.5373831776, -0.4986107603,
    -0.9692436363, 1.8759675015, 0.0415550574,
    0.0556300797, -0.2039769589, 1.0569715142
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_REC2020 = mat3(
    1.716651188, -0.3556707838, -0.2533662814,
    -0.6666843518, 1.6164812366, 0.0157685458,
    0.0176398574, -0.0427706133, 0.9421031212
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_DCI_P3 = mat3(
    2.7253940305, -1.0180030062, -0.4401631952,
    -0.7951680258, 1.6897320548, 0.0226471906,
    0.0412418914, -0.0876390192, 1.1009293786
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ADOBE_RGB_1998 = mat3(
    2.04159, -0.56501, -0.34473,
    -0.96924, 1.87597, 0.04156,
    0.01344, -0.11836, 1.01517
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP0 = mat3(
    1.0498110175, 0.0, -9.74845e-05,
    -0.4959030231, 1.3733130458, 0.0982400361,
    0.0, 0.0, 0.9912520182
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP1 = mat3(
    1.6410233797, -0.3248032942, -0.2364246952,
    -0.6636628587, 1.6153315917, 0.0167563477,
    0.0117218943, -0.008284442, 0.9883948585
);
const mat3 _colors2_colorspaces_mat_CIE_XYZ_to_COLOR_MCSPACEFACE = mat3(
    1.8036169276, -0.4552904521, -0.2378028419,
    -0.8777214976, 1.7861935367, 0.044102742,
    -0.0076302897, 0.0213060993, 0.9055290952
);
const mat3 _colors2_colorspaces_mat_SRGB_to_CIE_XYZ = mat3(
    0.4124, 0.3576, 0.1805,
    0.2126, 0.7152, 0.0722,
    0.0193, 0.1192, 0.9505
);
const mat3 _colors2_colorspaces_mat_SRGB_to_SRGB = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_SRGB_to_REC709 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_SRGB_to_REC2020 = mat3(
    0.6274413721, 0.3292974595, 0.0433514584,
    0.0690276171, 0.9195806669, 0.0113614226,
    0.0163642351, 0.0880171625, 0.8955649727
);
const mat3 _colors2_colorspaces_mat_SRGB_to_DCI_P3 = mat3(
    0.8686602648, 0.1289247846, 0.0025580657,
    0.034463766, 0.9618535095, 0.0036450448,
    0.0167452803, 0.071043109, 0.9121578398
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ADOBE_RGB_1998 = mat3(
    0.715177301, 0.284885616, 4.7408e-05,
    -8.1246e-05, 1.000047472, -6e-09,
    -2.7899e-05, 0.041163336, 0.958799413
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ACES_AP0 = mat3(
    0.439643004, 0.3830054714, 0.1773993089,
    0.0897157319, 0.8134750538, 0.0967822524,
    0.0175127205, 0.1115514385, 0.870882793
);
const mat3 _colors2_colorspaces_mat_SRGB_to_ACES_AP1 = mat3(
    0.6131324224, 0.3395380158, 0.047416696,
    0.0701243808, 0.9163940113, 0.013451524,
    0.0205876575, 0.1095745716, 0.869785404
);
const mat3 _colors2_colorspaces_mat_SRGB_to_COLOR_MCSPACEFACE = mat3(
    0.6424391956, 0.2910124185, 0.066641612,
    0.01862347, 0.9688787528, 0.0124565459,
    0.0188551746, 0.1204306855, 0.8606615207
);
const mat3 _colors2_colorspaces_mat_REC709_to_CIE_XYZ = mat3(
    0.4123907993, 0.3575843394, 0.1804807884,
    0.2126390059, 0.7151686788, 0.0721923154,
    0.0193308187, 0.1191947798, 0.9505321522
);
const mat3 _colors2_colorspaces_mat_REC709_to_SRGB = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC709_to_REC709 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC709_to_REC2020 = mat3(
    0.6274038959, 0.3292830384, 0.0433130657,
    0.0690972894, 0.9195403951, 0.0113623156,
    0.0163914389, 0.0880133079, 0.8955952532
);
const mat3 _colors2_colorspaces_mat_REC709_to_DCI_P3 = mat3(
    0.8685797397, 0.1289191385, 0.0025011218,
    0.0345404103, 0.9618113864, 0.0036482034,
    0.016771429, 0.0710399978, 0.9121885732
);
const mat3 _colors2_colorspaces_mat_REC709_to_ADOBE_RGB_1998 = mat3(
    0.715125854, 0.2848731398, 1.4438e-06,
    2.1264e-06, 1.0000036763, 5.5347e-06,
    -1.3532e-06, 0.0411615333, 0.9588327043
);
const mat3 _colors2_colorspaces_mat_REC709_to_ACES_AP0 = mat3(
    0.4396329819, 0.3829886982, 0.17737832,
    0.0897764429, 0.8134394287, 0.0967841283,
    0.0175411704, 0.1115465533, 0.8709122763
);
const mat3 _colors2_colorspaces_mat_REC709_to_ACES_AP1 = mat3(
    0.6130974024, 0.3395231462, 0.0473794514,
    0.0701937225, 0.9163538791, 0.0134523985,
    0.0206155929, 0.1095697729, 0.8698146342
);
const mat3 _colors2_colorspaces_mat_REC709_to_COLOR_MCSPACEFACE = mat3(
    0.6423975126, 0.290999674, 0.0666028135,
    0.0187025778, 0.968836322, 0.0124611002,
    0.0188839772, 0.1204254114, 0.8606906114
);
const mat3 _colors2_colorspaces_mat_REC2020_to_CIE_XYZ = mat3(
    0.6369580483, 0.1446169036, 0.1688809752,
    0.262700212, 0.6779980715, 0.0593017165,
    0.0, 0.028072693, 1.0609850577
);
const mat3 _colors2_colorspaces_mat_REC2020_to_SRGB = mat3(
    1.6603034854, -0.5875701425, -0.0728900602,
    -0.1243755953, 1.1328344814, -0.0083597372,
    -0.01811228, -0.1005836085, 1.1187703262
);
const mat3 _colors2_colorspaces_mat_REC2020_to_REC709 = mat3(
    1.6604910021, -0.5876411388, -0.0728498633,
    -0.1245504745, 1.1328998971, -0.0083494226,
    -0.0181507634, -0.100578898, 1.1187296614
);
const mat3 _colors2_colorspaces_mat_REC2020_to_REC2020 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_REC2020_to_DCI_P3 = mat3(
    1.4261665053, -0.3646122688, -0.0615542365,
    -0.0625062418, 1.0689717224, -0.0064654806,
    0.0024438227, -0.0211212969, 1.0186774743
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ADOBE_RGB_1998 = mat3(
    1.151978935, -0.0975047657, -0.0544737317,
    -0.124547502, 1.1329022557, -0.0083434163,
    -0.0225324809, -0.0498056448, 1.0723310102
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ACES_AP0 = mat3(
    0.6790856347, 0.1577009146, 0.1632134507,
    0.0460020031, 0.859054673, 0.094943324,
    -0.0005739432, 0.0284677684, 0.9721061748
);
const mat3 _colors2_colorspaces_mat_REC2020_to_ACES_AP1 = mat3(
    0.9748949779, 0.0195991086, 0.0055059134,
    0.0021795628, 0.9955354689, 0.0022849683,
    0.0047972397, 0.0245320166, 0.9706707437
);
const mat3 _colors2_colorspaces_mat_REC2020_to_COLOR_MCSPACEFACE = mat3(
    1.02924225, -0.0545245427, 0.0252822927,
    -0.08983974, 1.0853508417, 0.0044888983,
    0.0007354405, 0.0387656211, 0.9604989385
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ = mat3(
    0.4451698156, 0.2771344092, 0.1722826698,
    0.2094916779, 0.7215952542, 0.0689130679,
    -0.0, 0.0470605601, 0.9073553944
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_SRGB = mat3(
    1.1573859234, -0.1549414014, -0.0026012394,
    -0.041378309, 1.0455482025, -0.0040707446,
    -0.0180228775, -0.0785725929, 1.0966699081
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_REC709 = mat3(
    1.1575164062, -0.1549623781, -0.0025540281,
    -0.0415000715, 1.0455679231, -0.0040678515,
    -0.018050039, -0.0785782727, 1.0966283116
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_REC2020 = mat3(
    0.7117832307, 0.2436603169, 0.0445564524,
    0.0416151636, 0.9498416297, 0.0085432067,
    -0.0008447284, 0.0191095072, 0.9817352212
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_DCI_P3 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ADOBE_RGB_1998 = mat3(
    0.8159476268, 0.1870365007, -0.0029836898,
    -0.0414978627, 1.0455710024, -0.0040618024,
    -0.0190167405, -0.0323060291, 1.0513156541
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ACES_AP0 = mat3(
    0.4897866453, 0.3183760433, 0.1918373114,
    0.0684129538, 0.8289890733, 0.1025979728,
    -4.4998e-05, 0.0454764943, 0.9545685037
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_ACES_AP1 = mat3(
    0.6947248661, 0.2562644839, 0.04901065,
    0.0429788175, 0.9461757697, 0.0108454127,
    0.0036155455, 0.0430194671, 0.9533649873
);
const mat3 _colors2_colorspaces_mat_DCI_P3_to_COLOR_MCSPACEFACE = mat3(
    0.7303069694, 0.1994789445, 0.0702140861,
    -0.0187831594, 1.0091068134, 0.009676346,
    0.0013253512, 0.0553550597, 0.9433195891
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ = mat3(
    0.57667, 0.18556, 0.18823,
    0.29734, 0.62736, 0.07529,
    0.02703, 0.07069, 0.99134
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_SRGB = mat3(
    1.398208596, -0.39829809, -3.9774e-05,
    0.000136554, 0.999946439, -6.455e-06,
    3.3869e-05, -0.042926418, 1.042971631
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC709 = mat3(
    1.3983671735, -0.3983451225, 5.4016e-06,
    -1.03176e-05, 0.9999916496, -3.9459e-06,
    -3.709e-07, -0.042926951, 1.0429319656
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC2020 = mat3(
    0.8773375991, 0.0774977091, 0.0451746704,
    0.0966138895, 0.8915203988, 0.011846867,
    0.0229200098, 0.0430379497, 0.9340446591
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_DCI_P3 = mat3(
    1.2145920645, -0.2171838064, 0.0026126829,
    0.0482902509, 0.9478877447, 0.0038012193,
    0.0234515446, 0.0252011134, 0.9513504319
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ADOBE_RGB_1998 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP0 = mat3(
    0.614764313, 0.2002455356, 0.1849943834,
    0.1255320021, 0.7735159805, 0.1009365364,
    0.024527523, 0.0671725736, 0.9083019068
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP1 = mat3(
    0.857331761, 0.0932620958, 0.0494155164,
    0.0981471377, 0.8878074297, 0.0140266997,
    0.0288267153, 0.0640182469, 0.9071571651
);
const mat3 _colors2_colorspaces_mat_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE = mat3(
    0.8983045668, 0.0322422724, 0.0694645249,
    0.0261430701, 0.9608432342, 0.0129923579,
    0.0264051721, 0.0759552419, 0.897641378
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ = mat3(
    0.9525523959, 0.0, 9.36786e-05,
    0.3439664498, 0.7281660966, -0.0721325464,
    0.0, 0.0, 1.0088251844
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_SRGB = mat3(
    2.5214008886, -1.1339957494, -0.3875618568,
    -0.2762140616, 1.3725955663, -0.0962823557,
    -0.0153202001, -0.1529925618, 1.1683871996
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_REC709 = mat3(
    2.5216861866, -1.1341309882, -0.3875551986,
    -0.2764799141, 1.3727190876, -0.0962391734,
    -0.015378065, -0.1529753359, 1.1683534009
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_REC2020 = mat3(
    1.4904095205, -0.2661709193, -0.2242386013,
    -0.0801674998, 1.1821671211, -0.1019996212,
    0.0032276312, -0.0347764757, 1.0315488446
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_DCI_P3 = mat3(
    2.1546035168, -0.8084960464, -0.3461074707,
    -0.1788775564, 1.280565414, -0.1016878576,
    0.0086234533, -0.0610453898, 1.0524219365
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ADOBE_RGB_1998 = mat3(
    1.7245612643, -0.4199958158, -0.304565011,
    -0.2764756536, 1.3727208758, -0.0962338848,
    -0.0261287411, -0.0901729979, 1.1162946235
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP0 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP1 = mat3(
    1.4514393161, -0.2365107469, -0.2149285693,
    -0.0765537733, 1.1762296998, -0.0996759265,
    0.0083161484, -0.0060324498, 0.9977163014
);
const mat3 _colors2_colorspaces_mat_ACES_AP0_to_COLOR_MCSPACEFACE = mat3(
    1.5384451464, -0.3392907066, -0.19915444,
    -0.2208933788, 1.3068226981, -0.0859293193,
    0.0010885009, 0.0122289218, 0.9866825774
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ = mat3(
    0.6624541811, 0.1340042065, 0.156187687,
    0.2722287168, 0.6740817658, 0.0536895174,
    -0.0055746495, 0.0040607335, 1.0103391003
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_SRGB = mat3(
    1.7048586763, -0.6217160219, -0.0832993717,
    -0.1300768242, 1.1407357748, -0.0105598017,
    -0.0239640729, -0.1289755083, 1.1530140189
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_REC709 = mat3(
    1.7050509927, -0.6217921207, -0.083258872,
    -0.1302564175, 1.1408047366, -0.0105483191,
    -0.0240033568, -0.1289689761, 1.1529723329
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_REC2020 = mat3(
    1.0258247477, -0.0200531908, -0.0057715568,
    -0.0022343695, 1.0045865019, -0.0023521324,
    -0.0050133515, -0.0252900718, 1.0303034233
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_DCI_P3 = mat3(
    1.464120167, -0.3933270416, -0.0707931253,
    -0.0664765138, 1.0752915253, -0.0088150114,
    -0.0025528617, -0.0470296027, 1.0495824644
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ADOBE_RGB_1998 = mat3(
    1.182219458, -0.1196751803, -0.06254384,
    -0.1302534036, 1.1408068945, -0.0105421535,
    -0.0283790646, -0.0767015586, 1.1050735076
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP0 = mat3(
    0.6954522414, 0.1406786965, 0.1638690622,
    0.0447945634, 0.8596711184, 0.0955343182,
    -0.0055258826, 0.0040252103, 1.0015006723
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP1 = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
const mat3 _colors2_colorspaces_mat_ACES_AP1_to_COLOR_MCSPACEFACE = mat3(
    1.0558172503, -0.0760536019, 0.0202363516,
    -0.0946074079, 1.0920168543, 0.0025905536,
    -0.0041475025, 0.0146375846, 0.9895099179
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ = mat3(
    0.6326705035, 0.1593748231, 0.1583847254,
    0.3109383344, 0.6385030652, 0.0505586004,
    -0.0019849432, -0.0136803265, 1.1044717614
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_SRGB = mat3(
    1.5732175875, -0.4582177853, -0.1151565195,
    -0.0298175917, 1.0427085222, -0.0127917816,
    -0.0302889016, -0.1358492065, 1.1662125458
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC709 = mat3(
    1.5733946999, -0.4582756388, -0.1151190611,
    -0.0299830237, 1.0427599524, -0.0127769286,
    -0.0303259165, -0.1358452479, 1.1661711645
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC2020 = mat3(
    0.975967555, 0.0499553701, -0.0259229251,
    0.0808021347, 0.9256507776, -0.0064529123,
    -0.004008449, -0.0373974036, 1.0414058526
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_DCI_P3 = mat3(
    1.3626775245, -0.2639569859, -0.0987205386,
    0.0253970497, 0.9866137758, -0.0120108255,
    -0.0034048709, -0.0575247555, 1.0609296265
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998 = mat3(
    1.1166338266, -0.030670652, -0.0859627369,
    -0.0299799561, 1.0427620595, -0.0127707659,
    -0.0303137568, -0.0873306478, 1.1176372892
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP0 = mat3(
    0.6748538843, 0.1737961892, 0.1513499266,
    0.1139293384, 0.7939320393, 0.0921386223,
    -0.0021565314, -0.0100317066, 1.012188238
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP1 = mat3(
    0.9530274476, 0.0666372627, -0.0196647103,
    0.0825594145, 0.9215416099, -0.0041010244,
    0.0027733055, -0.0133528374, 1.010579532
);
const mat3 _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE = mat3(
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0
);
#define colors2_colorspaces_SRGB_luma(x) dot(x, _colors2_colorspaces_mat_SRGB_to_CIE_XYZ[1])
#define colors2_colorspaces_1_luma(x) colors2_colorspaces_SRGB_luma(x)
#define colors2_colorspaces_REC709_luma(x) dot(x, _colors2_colorspaces_mat_REC709_to_CIE_XYZ[1])
#define colors2_colorspaces_2_luma(x) colors2_colorspaces_REC709_luma(x)
#define colors2_colorspaces_REC2020_luma(x) dot(x, _colors2_colorspaces_mat_REC2020_to_CIE_XYZ[1])
#define colors2_colorspaces_3_luma(x) colors2_colorspaces_REC2020_luma(x)
#define colors2_colorspaces_DCI_P3_luma(x) dot(x, _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ[1])
#define colors2_colorspaces_4_luma(x) colors2_colorspaces_DCI_P3_luma(x)
#define colors2_colorspaces_ADOBE_RGB_1998_luma(x) dot(x, _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ[1])
#define colors2_colorspaces_5_luma(x) colors2_colorspaces_ADOBE_RGB_1998_luma(x)
#define colors2_colorspaces_ACES_AP0_luma(x) dot(x, _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ[1])
#define colors2_colorspaces_6_luma(x) colors2_colorspaces_ACES_AP0_luma(x)
#define colors2_colorspaces_ACES_AP1_luma(x) dot(x, _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ[1])
#define colors2_colorspaces_7_luma(x) colors2_colorspaces_ACES_AP1_luma(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_luma(x) dot(x, _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ[1])
#define colors2_colorspaces_8_luma(x) colors2_colorspaces_COLOR_MCSPACEFACE_luma(x)
#define colors2_colorspaces_CIE_XYZ_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_CIE_XYZ)
#define colors2_colorspaces_0_to_0(x) colors2_colorspaces_CIE_XYZ_to_CIE_XYZ(x)
#define colors2_colorspaces_CIE_XYZ_to_SRGB(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_SRGB)
#define colors2_colorspaces_0_to_1(x) colors2_colorspaces_CIE_XYZ_to_SRGB(x)
#define colors2_colorspaces_CIE_XYZ_to_REC709(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_REC709)
#define colors2_colorspaces_0_to_2(x) colors2_colorspaces_CIE_XYZ_to_REC709(x)
#define colors2_colorspaces_CIE_XYZ_to_REC2020(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_REC2020)
#define colors2_colorspaces_0_to_3(x) colors2_colorspaces_CIE_XYZ_to_REC2020(x)
#define colors2_colorspaces_CIE_XYZ_to_DCI_P3(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_DCI_P3)
#define colors2_colorspaces_0_to_4(x) colors2_colorspaces_CIE_XYZ_to_DCI_P3(x)
#define colors2_colorspaces_CIE_XYZ_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ADOBE_RGB_1998)
#define colors2_colorspaces_0_to_5(x) colors2_colorspaces_CIE_XYZ_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_CIE_XYZ_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP0)
#define colors2_colorspaces_0_to_6(x) colors2_colorspaces_CIE_XYZ_to_ACES_AP0(x)
#define colors2_colorspaces_CIE_XYZ_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_ACES_AP1)
#define colors2_colorspaces_0_to_7(x) colors2_colorspaces_CIE_XYZ_to_ACES_AP1(x)
#define colors2_colorspaces_CIE_XYZ_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_CIE_XYZ_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_0_to_8(x) colors2_colorspaces_CIE_XYZ_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_SRGB_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_SRGB_to_CIE_XYZ)
#define colors2_colorspaces_1_to_0(x) colors2_colorspaces_SRGB_to_CIE_XYZ(x)
#define colors2_colorspaces_SRGB_to_SRGB(x) (x * _colors2_colorspaces_mat_SRGB_to_SRGB)
#define colors2_colorspaces_1_to_1(x) colors2_colorspaces_SRGB_to_SRGB(x)
#define colors2_colorspaces_SRGB_to_REC709(x) (x * _colors2_colorspaces_mat_SRGB_to_REC709)
#define colors2_colorspaces_1_to_2(x) colors2_colorspaces_SRGB_to_REC709(x)
#define colors2_colorspaces_SRGB_to_REC2020(x) (x * _colors2_colorspaces_mat_SRGB_to_REC2020)
#define colors2_colorspaces_1_to_3(x) colors2_colorspaces_SRGB_to_REC2020(x)
#define colors2_colorspaces_SRGB_to_DCI_P3(x) (x * _colors2_colorspaces_mat_SRGB_to_DCI_P3)
#define colors2_colorspaces_1_to_4(x) colors2_colorspaces_SRGB_to_DCI_P3(x)
#define colors2_colorspaces_SRGB_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_SRGB_to_ADOBE_RGB_1998)
#define colors2_colorspaces_1_to_5(x) colors2_colorspaces_SRGB_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_SRGB_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_SRGB_to_ACES_AP0)
#define colors2_colorspaces_1_to_6(x) colors2_colorspaces_SRGB_to_ACES_AP0(x)
#define colors2_colorspaces_SRGB_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_SRGB_to_ACES_AP1)
#define colors2_colorspaces_1_to_7(x) colors2_colorspaces_SRGB_to_ACES_AP1(x)
#define colors2_colorspaces_SRGB_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_SRGB_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_1_to_8(x) colors2_colorspaces_SRGB_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_REC709_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_REC709_to_CIE_XYZ)
#define colors2_colorspaces_2_to_0(x) colors2_colorspaces_REC709_to_CIE_XYZ(x)
#define colors2_colorspaces_REC709_to_SRGB(x) (x * _colors2_colorspaces_mat_REC709_to_SRGB)
#define colors2_colorspaces_2_to_1(x) colors2_colorspaces_REC709_to_SRGB(x)
#define colors2_colorspaces_REC709_to_REC709(x) (x * _colors2_colorspaces_mat_REC709_to_REC709)
#define colors2_colorspaces_2_to_2(x) colors2_colorspaces_REC709_to_REC709(x)
#define colors2_colorspaces_REC709_to_REC2020(x) (x * _colors2_colorspaces_mat_REC709_to_REC2020)
#define colors2_colorspaces_2_to_3(x) colors2_colorspaces_REC709_to_REC2020(x)
#define colors2_colorspaces_REC709_to_DCI_P3(x) (x * _colors2_colorspaces_mat_REC709_to_DCI_P3)
#define colors2_colorspaces_2_to_4(x) colors2_colorspaces_REC709_to_DCI_P3(x)
#define colors2_colorspaces_REC709_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_REC709_to_ADOBE_RGB_1998)
#define colors2_colorspaces_2_to_5(x) colors2_colorspaces_REC709_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_REC709_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_REC709_to_ACES_AP0)
#define colors2_colorspaces_2_to_6(x) colors2_colorspaces_REC709_to_ACES_AP0(x)
#define colors2_colorspaces_REC709_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_REC709_to_ACES_AP1)
#define colors2_colorspaces_2_to_7(x) colors2_colorspaces_REC709_to_ACES_AP1(x)
#define colors2_colorspaces_REC709_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_REC709_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_2_to_8(x) colors2_colorspaces_REC709_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_REC2020_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_REC2020_to_CIE_XYZ)
#define colors2_colorspaces_3_to_0(x) colors2_colorspaces_REC2020_to_CIE_XYZ(x)
#define colors2_colorspaces_REC2020_to_SRGB(x) (x * _colors2_colorspaces_mat_REC2020_to_SRGB)
#define colors2_colorspaces_3_to_1(x) colors2_colorspaces_REC2020_to_SRGB(x)
#define colors2_colorspaces_REC2020_to_REC709(x) (x * _colors2_colorspaces_mat_REC2020_to_REC709)
#define colors2_colorspaces_3_to_2(x) colors2_colorspaces_REC2020_to_REC709(x)
#define colors2_colorspaces_REC2020_to_REC2020(x) (x * _colors2_colorspaces_mat_REC2020_to_REC2020)
#define colors2_colorspaces_3_to_3(x) colors2_colorspaces_REC2020_to_REC2020(x)
#define colors2_colorspaces_REC2020_to_DCI_P3(x) (x * _colors2_colorspaces_mat_REC2020_to_DCI_P3)
#define colors2_colorspaces_3_to_4(x) colors2_colorspaces_REC2020_to_DCI_P3(x)
#define colors2_colorspaces_REC2020_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_REC2020_to_ADOBE_RGB_1998)
#define colors2_colorspaces_3_to_5(x) colors2_colorspaces_REC2020_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_REC2020_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_REC2020_to_ACES_AP0)
#define colors2_colorspaces_3_to_6(x) colors2_colorspaces_REC2020_to_ACES_AP0(x)
#define colors2_colorspaces_REC2020_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_REC2020_to_ACES_AP1)
#define colors2_colorspaces_3_to_7(x) colors2_colorspaces_REC2020_to_ACES_AP1(x)
#define colors2_colorspaces_REC2020_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_REC2020_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_3_to_8(x) colors2_colorspaces_REC2020_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_DCI_P3_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_DCI_P3_to_CIE_XYZ)
#define colors2_colorspaces_4_to_0(x) colors2_colorspaces_DCI_P3_to_CIE_XYZ(x)
#define colors2_colorspaces_DCI_P3_to_SRGB(x) (x * _colors2_colorspaces_mat_DCI_P3_to_SRGB)
#define colors2_colorspaces_4_to_1(x) colors2_colorspaces_DCI_P3_to_SRGB(x)
#define colors2_colorspaces_DCI_P3_to_REC709(x) (x * _colors2_colorspaces_mat_DCI_P3_to_REC709)
#define colors2_colorspaces_4_to_2(x) colors2_colorspaces_DCI_P3_to_REC709(x)
#define colors2_colorspaces_DCI_P3_to_REC2020(x) (x * _colors2_colorspaces_mat_DCI_P3_to_REC2020)
#define colors2_colorspaces_4_to_3(x) colors2_colorspaces_DCI_P3_to_REC2020(x)
#define colors2_colorspaces_DCI_P3_to_DCI_P3(x) (x * _colors2_colorspaces_mat_DCI_P3_to_DCI_P3)
#define colors2_colorspaces_4_to_4(x) colors2_colorspaces_DCI_P3_to_DCI_P3(x)
#define colors2_colorspaces_DCI_P3_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ADOBE_RGB_1998)
#define colors2_colorspaces_4_to_5(x) colors2_colorspaces_DCI_P3_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_DCI_P3_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ACES_AP0)
#define colors2_colorspaces_4_to_6(x) colors2_colorspaces_DCI_P3_to_ACES_AP0(x)
#define colors2_colorspaces_DCI_P3_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_DCI_P3_to_ACES_AP1)
#define colors2_colorspaces_4_to_7(x) colors2_colorspaces_DCI_P3_to_ACES_AP1(x)
#define colors2_colorspaces_DCI_P3_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_DCI_P3_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_4_to_8(x) colors2_colorspaces_DCI_P3_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_CIE_XYZ)
#define colors2_colorspaces_5_to_0(x) colors2_colorspaces_ADOBE_RGB_1998_to_CIE_XYZ(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_SRGB(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_SRGB)
#define colors2_colorspaces_5_to_1(x) colors2_colorspaces_ADOBE_RGB_1998_to_SRGB(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_REC709(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC709)
#define colors2_colorspaces_5_to_2(x) colors2_colorspaces_ADOBE_RGB_1998_to_REC709(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_REC2020(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_REC2020)
#define colors2_colorspaces_5_to_3(x) colors2_colorspaces_ADOBE_RGB_1998_to_REC2020(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_DCI_P3)
#define colors2_colorspaces_5_to_4(x) colors2_colorspaces_ADOBE_RGB_1998_to_DCI_P3(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ADOBE_RGB_1998)
#define colors2_colorspaces_5_to_5(x) colors2_colorspaces_ADOBE_RGB_1998_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP0)
#define colors2_colorspaces_5_to_6(x) colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP0(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_ACES_AP1)
#define colors2_colorspaces_5_to_7(x) colors2_colorspaces_ADOBE_RGB_1998_to_ACES_AP1(x)
#define colors2_colorspaces_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_5_to_8(x) colors2_colorspaces_ADOBE_RGB_1998_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ACES_AP0_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_CIE_XYZ)
#define colors2_colorspaces_6_to_0(x) colors2_colorspaces_ACES_AP0_to_CIE_XYZ(x)
#define colors2_colorspaces_ACES_AP0_to_SRGB(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_SRGB)
#define colors2_colorspaces_6_to_1(x) colors2_colorspaces_ACES_AP0_to_SRGB(x)
#define colors2_colorspaces_ACES_AP0_to_REC709(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_REC709)
#define colors2_colorspaces_6_to_2(x) colors2_colorspaces_ACES_AP0_to_REC709(x)
#define colors2_colorspaces_ACES_AP0_to_REC2020(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_REC2020)
#define colors2_colorspaces_6_to_3(x) colors2_colorspaces_ACES_AP0_to_REC2020(x)
#define colors2_colorspaces_ACES_AP0_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_DCI_P3)
#define colors2_colorspaces_6_to_4(x) colors2_colorspaces_ACES_AP0_to_DCI_P3(x)
#define colors2_colorspaces_ACES_AP0_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ADOBE_RGB_1998)
#define colors2_colorspaces_6_to_5(x) colors2_colorspaces_ACES_AP0_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ACES_AP0_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP0)
#define colors2_colorspaces_6_to_6(x) colors2_colorspaces_ACES_AP0_to_ACES_AP0(x)
#define colors2_colorspaces_ACES_AP0_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_ACES_AP1)
#define colors2_colorspaces_6_to_7(x) colors2_colorspaces_ACES_AP0_to_ACES_AP1(x)
#define colors2_colorspaces_ACES_AP0_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ACES_AP0_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_6_to_8(x) colors2_colorspaces_ACES_AP0_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_ACES_AP1_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_CIE_XYZ)
#define colors2_colorspaces_7_to_0(x) colors2_colorspaces_ACES_AP1_to_CIE_XYZ(x)
#define colors2_colorspaces_ACES_AP1_to_SRGB(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_SRGB)
#define colors2_colorspaces_7_to_1(x) colors2_colorspaces_ACES_AP1_to_SRGB(x)
#define colors2_colorspaces_ACES_AP1_to_REC709(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_REC709)
#define colors2_colorspaces_7_to_2(x) colors2_colorspaces_ACES_AP1_to_REC709(x)
#define colors2_colorspaces_ACES_AP1_to_REC2020(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_REC2020)
#define colors2_colorspaces_7_to_3(x) colors2_colorspaces_ACES_AP1_to_REC2020(x)
#define colors2_colorspaces_ACES_AP1_to_DCI_P3(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_DCI_P3)
#define colors2_colorspaces_7_to_4(x) colors2_colorspaces_ACES_AP1_to_DCI_P3(x)
#define colors2_colorspaces_ACES_AP1_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ADOBE_RGB_1998)
#define colors2_colorspaces_7_to_5(x) colors2_colorspaces_ACES_AP1_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_ACES_AP1_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP0)
#define colors2_colorspaces_7_to_6(x) colors2_colorspaces_ACES_AP1_to_ACES_AP0(x)
#define colors2_colorspaces_ACES_AP1_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_ACES_AP1)
#define colors2_colorspaces_7_to_7(x) colors2_colorspaces_ACES_AP1_to_ACES_AP1(x)
#define colors2_colorspaces_ACES_AP1_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_ACES_AP1_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_7_to_8(x) colors2_colorspaces_ACES_AP1_to_COLOR_MCSPACEFACE(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_CIE_XYZ(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_CIE_XYZ)
#define colors2_colorspaces_8_to_0(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_CIE_XYZ(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_SRGB(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_SRGB)
#define colors2_colorspaces_8_to_1(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_SRGB(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_REC709(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC709)
#define colors2_colorspaces_8_to_2(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_REC709(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_REC2020(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_REC2020)
#define colors2_colorspaces_8_to_3(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_REC2020(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_DCI_P3(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_DCI_P3)
#define colors2_colorspaces_8_to_4(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_DCI_P3(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998)
#define colors2_colorspaces_8_to_5(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ADOBE_RGB_1998(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP0(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP0)
#define colors2_colorspaces_8_to_6(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP0(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP1(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_ACES_AP1)
#define colors2_colorspaces_8_to_7(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_ACES_AP1(x)
#define colors2_colorspaces_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE(x) (x * _colors2_colorspaces_mat_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE)
#define colors2_colorspaces_8_to_8(x) colors2_colorspaces_COLOR_MCSPACEFACE_to_COLOR_MCSPACEFACE(x)
/*
    References:
        [WIK25a] Wikipedia. "Rec. 601". 2025.
            https:
        [WIK25b] Wikipedia. "Rec. 709". 2025.
            https:
        [WIK25c] Wikipedia. "sRGB". 2025.
            https:
        [ITU25] ITU, "Recommendation BT.2100", 2025.
            https:
            
    Note:
        EOTF: Electro-Optical Transfer Function (decoding gamma, non-linear to linear)
        OETF: Opto-Electronic Transfer Function (encoding gamma, linear to non-linear)
*/
/*
    References:
        [WHY23] Whyte, Killian. "Soft Clamp Function". 2023.
            https:

        You can find full license texts in /licenses
*/
#define PI 3.14159265358979323846
#define PI_2 (2.0 * PI)
#define PI_HALF (0.5 * PI)
#define PI_QUARTER (0.25 * PI)
#define RCP_PI (1.0 / PI)
#define RCP_PI_2 (1.0 / PI_2)
#define RCP_PI_HALF (1.0 / PI_HALF)
#define GOLDEN_RATIO 1.618033988749
#define GOLDEN_ANGLE 2.39996322972865332
#define SPHERE_SOLID_ANGLE (4.0 * PI)
#define FLT_MAX uintBitsToFloat(0x7F7FFFFF)
#define FLT_MIN uintBitsToFloat(0x00800000)
#define FLT_TRUE_MIN uintBitsToFloat(0x00000001)
#define FLT_POS_INF uintBitsToFloat(0x7F800000)
#define FLT_NEG_INF uintBitsToFloat(0xFF800000)
#define FP16_MAX 65504.0
#define INT32_MAX 2147483647
#define INT32_MIN -2147483648
#define rcp(x) (1.0 / (x))
#define saturate(x) clamp(x, 0.0, 1.0)
#ifndef NO_HALF
#endif
float safeRcp(float x) {
    return x <= 0.0 ? 0.0 : rcp(x);
}
vec2 safeRcp(vec2 x) {
    return mix(vec2(0.0), rcp(x), greaterThan(x, vec2(0.0)));
}
#define COLORS2_TF_IDENTITY 0
#define COLORS2_TF_REC601 1
#define COLORS2_TF_REC709 2
#define COLORS2_TF_SRGB   3
#define COLORS2_TF_EXP22  4
#define COLORS2_TF_EXP24  5
#define COLORS2_TF_PQ     6
#define COLORS2_TF_HLG    7
#define _colors2_oetf(a, x) colors2_oetf_## a ##(x)
#define colors2_oetf(a, x) _colors2_oetf(a, x)
#define _colors2_eotf(a, x) colors2_eotf_## a ##(x)
#define colors2_eotf(a, x) _colors2_eotf(a, x)
float colors2_oetf_identity(float c) {
    return c;
}
vec3 colors2_oetf_identity(vec3 c) {
    return c;
}
float colors2_eotf_identity(float c) {
    return c;
}
vec3 colors2_eotf_identity(vec3 c) {
    return c;
}
float colors2_oetf_Rec601(float c) {
    float lower = 4.5 * c;
    float higher = pow(c, 0.45) * 1.099 - 0.099;
    return mix(lower, higher, c >= 0.018);
}
vec3 colors2_oetf_Rec601(vec3 c) {
    vec3 lower = 4.5 * c;
    vec3 higher = pow(c, vec3(0.45)) * 1.099 - 0.099;
    return mix(lower, higher, greaterThanEqual(c, vec3(0.018)));
}
float colors2_eotf_Rec601(float c) {
    float lower = c / 4.5;
    float higher = pow((c + 0.099) / 1.099, 1.0 / 0.45);
    return mix(lower, higher, c >= 0.081);
}
vec3 colors2_eotf_Rec601(vec3 c) {
    vec3 lower = c / 4.5;
    vec3 higher = pow((c + 0.099) / 1.099, vec3(1.0 / 0.45));
    return mix(lower, higher, greaterThanEqual(c, vec3(0.081)));
}
float colors2_oetf_Rec709(float c) {
    return colors2_oetf_Rec601(c);
}
vec3 colors2_oetf_Rec709(vec3 c) {
    return colors2_oetf_Rec601(c);
}
float colors2_eotf_Rec709(float c) {
    return colors2_eotf_Rec601(c);
}
vec3 colors2_eotf_Rec709(vec3 c) {
    return colors2_eotf_Rec601(c);
}
float colors2_oetf_sRGB(float c) {
    float lower = 12.92 * c;
    float higher = pow(c, 1.0 / 2.4) * 1.055 - 0.055;
    return mix(lower, higher, c > 0.0031308);
}
vec3 colors2_oetf_sRGB(vec3 c) {
    vec3 lower = 12.92 * c;
    vec3 higher = pow(c, vec3(1.0 / 2.4)) * 1.055 - 0.055;
    return mix(lower, higher, greaterThan(c, vec3(0.0031308)));
}
float colors2_eotf_sRGB(float c) {
    float lower = c / 12.92;
    float higher = pow((c + 0.055) / 1.055, 2.4);
    return mix(lower, higher, c > 0.04045);
}
vec3 colors2_eotf_sRGB(vec3 c) {
    vec3 lower = c / 12.92;
    vec3 higher = pow((c + 0.055) / 1.055, vec3(2.4));
    return mix(lower, higher, greaterThan(c, vec3(0.04045)));
}
float colors2_oetf_Exp22(float c) {
    return pow(c, 1.0 / 2.2);
}
vec3 colors2_oetf_Exp22(vec3 c) {
    return pow(c, vec3(1.0 / 2.2));
}
float colors2_eotf_Exp22(float c) {
    return pow(c, 2.2);
}
vec3 colors2_eotf_Exp22(vec3 c) {
    return pow(c, vec3(2.2));
}
float colors2_oetf_Exp24(float c) {
    return pow(c, 1.0 / 2.4);
}
vec3 colors2_oetf_Exp24(vec3 c) {
    return pow(c, vec3(1.0 / 2.4));
}
float colors2_eotf_Exp24(float c) {
    return pow(c, 2.4);
}
vec3 colors2_eotf_Exp24(vec3 c) {
    return pow(c, vec3(2.4));
}
const float _PQ_M1 = 2610.0 / 16384.0;
const float _PQ_M2 = 2523.0 / 4096.0 * 128.0;
const float _PQ_C1 = 3424.0 / 4096.0;
const float _PQ_C2 = 2413.0 / 4096.0 * 32.0;
const float _PQ_C3 = 2392.0 / 4096.0 * 32.0;
const float _PQ_PEAK = 10000.0;
float colors2_oetf_PQ(float c) {
    float y = c / _PQ_PEAK;
    float yPow = pow(y, _PQ_M1);
    float numerator = _PQ_C1 + _PQ_C2 * yPow;
    float denominator = 1.0 + _PQ_C3 * yPow;
    return pow(numerator / denominator, _PQ_M2);
}
vec3 colors2_oetf_PQ(vec3 c) {
    vec3 y = c / _PQ_PEAK;
    vec3 yPow = pow(y, vec3(_PQ_M1));
    vec3 numerator = vec3(_PQ_C1) + vec3(_PQ_C2) * yPow;
    vec3 denominator = vec3(1.0) + vec3(_PQ_C3) * yPow;
    return pow(numerator / denominator, vec3(_PQ_M2));
}
float colors2_eotf_PQ(float c) {
    float ePow = pow(c, 1.0 / _PQ_M2);
    float numerator = max(ePow - _PQ_C1, 0.0);
    float denominator = _PQ_C2 - _PQ_C3 * ePow;
    float y = pow(numerator / denominator, 1.0 / _PQ_M1);
    return y * _PQ_PEAK;
}
vec3 colors2_eotf_PQ(vec3 c) {
    vec3 ePow = pow(c, vec3(1.0 / _PQ_M2));
    vec3 numerator = max(ePow - vec3(_PQ_C1), 0.0);
    vec3 denominator = _PQ_C2 - _PQ_C3 * ePow;
    vec3 y = pow(numerator / denominator, vec3(1.0 / _PQ_M1));
    return y * _PQ_PEAK;
}
const float _HLG_A = 0.17883277;
const float _HLG_B = 1.0 - 4.0 * _HLG_A;
const float _HLG_C = 0.5 - _HLG_A * log(4.0 * _HLG_A);
float colors2_oetf_HLG(float c) {
    float lower = sqrt(3.0 * c);
    float higher = _HLG_A * log(12.0 * c - _HLG_B) + _HLG_C;
    return mix(lower, higher, c > 1.0 / 12.0);
}
vec3 colors2_oetf_HLG(vec3 c) {
    vec3 lower = sqrt(3.0 * c);
    vec3 higher = _HLG_A * log(12.0 * c - _HLG_B) + _HLG_C;
    return mix(lower, higher, greaterThan(c, vec3(1.0 / 12.0)));
}
float colors2_eotf_HLG(float c) {
    float lower = c * c / 3.0;
    float higher = (exp((c - _HLG_C) / _HLG_A) + _HLG_B) / 12.0;
    return mix(lower, higher, c > 0.5);
}
vec3 colors2_eotf_HLG(vec3 c) {
    vec3 lower = c * c / 3.0;
    vec3 higher = (exp((c - vec3(_HLG_C)) / vec3(_HLG_A)) + vec3(_HLG_B)) / 12.0;
    return mix(lower, higher, greaterThan(c, vec3(0.5)));
}
float colors2_oetf_0(float c) { return colors2_eotf_identity(c); }
vec3 colors2_oetf_0(vec3 c) { return colors2_eotf_identity(c); }
float colors2_eotf_0(float c) { return colors2_oetf_identity(c); }
vec3 colors2_eotf_0(vec3 c) { return colors2_oetf_identity(c); }
float colors2_oetf_1(float c) { return colors2_oetf_Rec601(c); }
vec3 colors2_oetf_1(vec3 c) { return colors2_oetf_Rec601(c); }
float colors2_eotf_1(float c) { return colors2_eotf_Rec601(c); }
vec3 colors2_eotf_1(vec3 c) { return colors2_eotf_Rec601(c); }
float colors2_oetf_2(float c) { return colors2_oetf_Rec709(c); }
vec3 colors2_oetf_2(vec3 c) { return colors2_oetf_Rec709(c); }
float colors2_eotf_2(float c) { return colors2_eotf_Rec709(c); }
vec3 colors2_eotf_2(vec3 c) { return colors2_eotf_Rec709(c); }
float colors2_oetf_3(float c) { return colors2_oetf_sRGB(c); }
vec3 colors2_oetf_3(vec3 c) { return colors2_oetf_sRGB(c); }
float colors2_eotf_3(float c) { return colors2_eotf_sRGB(c); }
vec3 colors2_eotf_3(vec3 c) { return colors2_eotf_sRGB(c); }
float colors2_oetf_4(float c) { return colors2_oetf_Exp22(c); }
vec3 colors2_oetf_4(vec3 c) { return colors2_oetf_Exp22(c); }
float colors2_eotf_4(float c) { return colors2_eotf_Exp22(c); }
vec3 colors2_eotf_4(vec3 c) { return colors2_eotf_Exp22(c); }
float colors2_oetf_5(float c) { return colors2_oetf_Exp24(c); }
vec3 colors2_oetf_5(vec3 c) { return colors2_oetf_Exp24(c); }
float colors2_eotf_5(float c) { return colors2_eotf_Exp24(c); }
vec3 colors2_eotf_5(vec3 c) { return colors2_eotf_Exp24(c); }
float colors2_oetf_6(float c) { return colors2_oetf_PQ(c); }
vec3 colors2_oetf_6(vec3 c) { return colors2_oetf_PQ(c); }
float colors2_eotf_6(float c) { return colors2_eotf_PQ(c); }
vec3 colors2_eotf_6(vec3 c) { return colors2_eotf_PQ(c); }
float colors2_oetf_7(float c) { return colors2_oetf_HLG(c); }
vec3 colors2_oetf_7(vec3 c) { return colors2_oetf_HLG(c); }
float colors2_eotf_7(float c) { return colors2_eotf_HLG(c); }
vec3 colors2_eotf_7(vec3 c) { return colors2_eotf_HLG(c); }
#define COLORS2_MATERIAL_COLORSPACE SETTING_MATERIAL_COLOR_SPACE
#define COLORS2_MATERIAL_TF SETTING_MATERIAL_TRANSFER_FUNC
#define COLORS2_CONSTANTS_COLORSPACE COLORS2_COLORSPACES_ACES_AP0
#define COLORS2_CONSTANTS_TF COLORS2_TF_IDENTITY
#define COLORS2_WORKING_COLORSPACE SETTING_WORKING_COLOR_SPACE
#define COLORS2_DRT_WORKING_COLORSPACE SETTING_DRT_WORKING_COLOR_SPACE
#define COLORS2_OUTPUT_COLORSPACE COLORS2_COLORSPACES_SRGB
#define COLORS2_OUTPUT_TF COLORS2_TF_SRGB
#define colors2_material_toWorkSpace(x) colors2_colorspaces_convert(COLORS2_MATERIAL_COLORSPACE, COLORS2_WORKING_COLORSPACE, colors2_eotf(COLORS2_MATERIAL_TF, x))
#define colors2_constants_toWorkSpace(x) colors2_colorspaces_convert(COLORS2_CONSTANTS_COLORSPACE, COLORS2_WORKING_COLORSPACE, x)
#define SPD_CHANNELS 4
#define SPD_OP 3
#define FFX_GLSL 1
#define FFX_GPU 1
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#ifndef FFX_COMMON_TYPES_H
#define FFX_COMMON_TYPES_H a
#define FFX_PARAMETER_IN        in
#define FFX_PARAMETER_OUT       out
#define FFX_PARAMETER_INOUT     inout
#define FfxFloat32Mat4 mat4
#define FfxFloat32Mat3 mat3
#define FfxBoolean   bool
#define FfxFloat32   float
#define FfxFloat32x2 vec2
#define FfxFloat32x3 vec3
#define FfxFloat32x4 vec4
#define FfxUInt32    uint
#define FfxUInt32x2  uvec2
#define FfxUInt32x3  uvec3
#define FfxUInt32x4  uvec4
#define FfxInt32     int
#define FfxInt32x2   ivec2
#define FfxInt32x3   ivec3
#define FfxInt32x4   ivec4
#define FfxFloat32x4x4 mat4
#define FfxFloat32x3x4 mat4x3
#define FfxFloat32x3x3 mat3
#define FfxFloat32x2x2 mat2
#if FFX_HALF
#define FfxFloat16   float16_t
#define FfxFloat16x2 f16vec2
#define FfxFloat16x3 f16vec3
#define FfxFloat16x4 f16vec4
#define FfxUInt16    uint16_t
#define FfxUInt16x2  u16vec2
#define FfxUInt16x3  u16vec3
#define FfxUInt16x4  u16vec4
#define FfxInt16     int16_t
#define FfxInt16x2   i16vec2
#define FfxInt16x3   i16vec3
#define FfxInt16x4   i16vec4
#endif 
#if FFX_HALF
#if FFX_HLSL_SM >= 62
#define FFX_MIN16_SCALAR( TypeName, BaseComponentType )           typedef BaseComponentType##16_t TypeName;
#define FFX_MIN16_VECTOR( TypeName, BaseComponentType, COL )      typedef vector<BaseComponentType##16_t, COL> TypeName;
#define FFX_MIN16_MATRIX( TypeName, BaseComponentType, ROW, COL ) typedef matrix<BaseComponentType##16_t, ROW, COL> TypeName;
#define FFX_16BIT_SCALAR( TypeName, BaseComponentType )           typedef BaseComponentType##16_t TypeName;
#define FFX_16BIT_VECTOR( TypeName, BaseComponentType, COL )      typedef vector<BaseComponentType##16_t, COL> TypeName;
#define FFX_16BIT_MATRIX( TypeName, BaseComponentType, ROW, COL ) typedef matrix<BaseComponentType##16_t, ROW, COL> TypeName;
#else 
#define FFX_MIN16_SCALAR( TypeName, BaseComponentType )           typedef min16##BaseComponentType TypeName;
#define FFX_MIN16_VECTOR( TypeName, BaseComponentType, COL )      typedef vector<min16##BaseComponentType, COL> TypeName;
#define FFX_MIN16_MATRIX( TypeName, BaseComponentType, ROW, COL ) typedef matrix<min16##BaseComponentType, ROW, COL> TypeName;
#define FFX_16BIT_SCALAR( TypeName, BaseComponentType )           FFX_MIN16_SCALAR( TypeName, BaseComponentType );
#define FFX_16BIT_VECTOR( TypeName, BaseComponentType, COL )      FFX_MIN16_VECTOR( TypeName, BaseComponentType, COL );
#define FFX_16BIT_MATRIX( TypeName, BaseComponentType, ROW, COL ) FFX_MIN16_MATRIX( TypeName, BaseComponentType, ROW, COL );
#endif 
#else 
#define FFX_MIN16_SCALAR( TypeName, BaseComponentType )           typedef BaseComponentType TypeName;
#define FFX_MIN16_VECTOR( TypeName, BaseComponentType, COL )      typedef vector<BaseComponentType, COL> TypeName;
#define FFX_MIN16_MATRIX( TypeName, BaseComponentType, ROW, COL ) typedef matrix<BaseComponentType, ROW, COL> TypeName;
#define FFX_16BIT_SCALAR( TypeName, BaseComponentType )           typedef BaseComponentType TypeName;
#define FFX_16BIT_VECTOR( TypeName, BaseComponentType, COL )      typedef vector<BaseComponentType, COL> TypeName;
#define FFX_16BIT_MATRIX( TypeName, BaseComponentType, ROW, COL ) typedef matrix<BaseComponentType, ROW, COL> TypeName;
#endif 
#if FFX_HALF
#define  FFX_MIN16_F  float16_t
#define  FFX_MIN16_F2 f16vec2
#define  FFX_MIN16_F3 f16vec3
#define  FFX_MIN16_F4 f16vec4
#define  FFX_MIN16_I  int16_t
#define  FFX_MIN16_I2 i16vec2
#define  FFX_MIN16_I3 i16vec3
#define  FFX_MIN16_I4 i16vec4
#define  FFX_MIN16_U  uint16_t
#define  FFX_MIN16_U2 u16vec2
#define  FFX_MIN16_U3 u16vec3
#define  FFX_MIN16_U4 u16vec4
#define FFX_16BIT_F  float16_t
#define FFX_16BIT_F2 f16vec2
#define FFX_16BIT_F3 f16vec3
#define FFX_16BIT_F4 f16vec4
#define FFX_16BIT_I  int16_t
#define FFX_16BIT_I2 i16vec2
#define FFX_16BIT_I3 i16vec3
#define FFX_16BIT_I4 i16vec4
#define FFX_16BIT_U  uint16_t
#define FFX_16BIT_U2 u16vec2
#define FFX_16BIT_U3 u16vec3
#define FFX_16BIT_U4 u16vec4
#else 
#define  FFX_MIN16_F  float
#define  FFX_MIN16_F2 vec2
#define  FFX_MIN16_F3 vec3
#define  FFX_MIN16_F4 vec4
#define  FFX_MIN16_I  int
#define  FFX_MIN16_I2 ivec2
#define  FFX_MIN16_I3 ivec3
#define  FFX_MIN16_I4 ivec4
#define  FFX_MIN16_U  uint
#define  FFX_MIN16_U2 uvec2
#define  FFX_MIN16_U3 uvec3
#define  FFX_MIN16_U4 uvec4
#define FFX_16BIT_F  float
#define FFX_16BIT_F2 vec2
#define FFX_16BIT_F3 vec3
#define FFX_16BIT_F4 vec4
#define FFX_16BIT_I  int
#define FFX_16BIT_I2 ivec2
#define FFX_16BIT_I3 ivec3
#define FFX_16BIT_I4 ivec4
#define FFX_16BIT_U  uint
#define FFX_16BIT_U2 uvec2
#define FFX_16BIT_U3 uvec3
#define FFX_16BIT_U4 uvec4
#endif 
#endif 
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#define FFX_SELECT(cond, arg1, arg2) cond ? arg1 : arg2
#define FFX_GROUPSHARED shared
#define FFX_GROUP_MEMORY_BARRIER groupMemoryBarrier(); barrier()
#define FFX_ATOMIC_ADD(x, y) atomicAdd(x, y)
#define FFX_ATOMIC_ADD_RETURN(x, y, r) r = atomicAdd(x, y)
#define FFX_ATOMIC_OR(x, y) atomicOr(x, y)
#define FFX_ATOMIC_MIN(x, y) atomicMin(x, y)
#define FFX_ATOMIC_MAX(x, y) atomicMax(x, y)
#define FFX_STATIC
#define FFX_UNROLL
#define FFX_GREATER_THAN(x, y) greaterThan(x, y)
#define FFX_GREATER_THAN_EQUAL(x, y) greaterThanEqual(x, y)
#define FFX_LESS_THAN(x, y) lessThan(x, y)
#define FFX_LESS_THAN_EQUAL(x, y) lessThanEqual(x, y)
#define FFX_EQUAL(x, y) equal(x, y)
#define FFX_NOT_EQUAL(x, y) notEqual(x, y)
#define FFX_MATRIX_MULTIPLY(a, b) (a * b)
#define FFX_TRANSFORM_VECTOR(a, b) (a * b)
#define FFX_MODULO(a, b) (mod(a, b))
#define FFX_BROADCAST_FLOAT32(x)   FfxFloat32(x)
#define FFX_BROADCAST_FLOAT32X2(x) FfxFloat32x2(FfxFloat32(x))
#define FFX_BROADCAST_FLOAT32X3(x) FfxFloat32x3(FfxFloat32(x))
#define FFX_BROADCAST_FLOAT32X4(x) FfxFloat32x4(FfxFloat32(x))
#define FFX_BROADCAST_UINT32(x)   FfxUInt32(x)
#define FFX_BROADCAST_UINT32X2(x) FfxUInt32x2(FfxUInt32(x))
#define FFX_BROADCAST_UINT32X3(x) FfxUInt32x3(FfxUInt32(x))
#define FFX_BROADCAST_UINT32X4(x) FfxUInt32x4(FfxUInt32(x))
#define FFX_BROADCAST_INT32(x)   FfxInt32(x)
#define FFX_BROADCAST_INT32X2(x) FfxInt32x2(FfxInt32(x))
#define FFX_BROADCAST_INT32X3(x) FfxInt32x3(FfxInt32(x))
#define FFX_BROADCAST_INT32X4(x) FfxInt32x4(FfxInt32(x))
#define FFX_BROADCAST_MIN_FLOAT16(x)   FFX_MIN16_F(x)
#define FFX_BROADCAST_MIN_FLOAT16X2(x) FFX_MIN16_F2(FFX_MIN16_F(x))
#define FFX_BROADCAST_MIN_FLOAT16X3(x) FFX_MIN16_F3(FFX_MIN16_F(x))
#define FFX_BROADCAST_MIN_FLOAT16X4(x) FFX_MIN16_F4(FFX_MIN16_F(x))
#define FFX_BROADCAST_MIN_UINT16(x)   FFX_MIN16_U(x)
#define FFX_BROADCAST_MIN_UINT16X2(x) FFX_MIN16_U2(FFX_MIN16_U(x))
#define FFX_BROADCAST_MIN_UINT16X3(x) FFX_MIN16_U3(FFX_MIN16_U(x))
#define FFX_BROADCAST_MIN_UINT16X4(x) FFX_MIN16_U4(FFX_MIN16_U(x))
#define FFX_BROADCAST_MIN_INT16(x)   FFX_MIN16_I(x)
#define FFX_BROADCAST_MIN_INT16X2(x) FFX_MIN16_I2(FFX_MIN16_I(x))
#define FFX_BROADCAST_MIN_INT16X3(x) FFX_MIN16_I3(FFX_MIN16_I(x))
#define FFX_BROADCAST_MIN_INT16X4(x) FFX_MIN16_I4(FFX_MIN16_I(x))
#if !defined(FFX_SKIP_EXT)
#if FFX_HALF
    #extension GL_EXT_shader_16bit_storage : require
#endif 
#if defined(FFX_LONG)
    #extension GL_ARB_gpu_shader_int64 : require
    #extension GL_NV_shader_atomic_int64 : require
#endif 
#if defined(FFX_WAVE)
    #extension GL_KHR_shader_subgroup_arithmetic : require
    #extension GL_KHR_shader_subgroup_ballot : require
    #extension GL_KHR_shader_subgroup_quad : require
    #extension GL_KHR_shader_subgroup_shuffle : require
#endif 
#endif 
FfxFloat32 ffxSqrt(FfxFloat32 x);
FfxFloat32x2 ffxSqrt(FfxFloat32x2 x);
FfxFloat32x3 ffxSqrt(FfxFloat32x3 x);
FfxFloat32x4 ffxSqrt(FfxFloat32x4 x);
FfxFloat32 ffxAsFloat(FfxUInt32 x)
{
    return uintBitsToFloat(x);
}
FfxFloat32x2 ffxAsFloat(FfxUInt32x2 x)
{
    return uintBitsToFloat(x);
}
FfxFloat32x3 ffxAsFloat(FfxUInt32x3 x)
{
    return uintBitsToFloat(x);
}
FfxFloat32x4 ffxAsFloat(FfxUInt32x4 x)
{
    return uintBitsToFloat(x);
}
FfxUInt32 ffxBitfieldExtract(FfxUInt32 src, FfxUInt32 off, FfxUInt32 bits)
{
    return bitfieldExtract(src, FfxInt32(off), FfxInt32(bits));
}
FfxUInt32 ffxBitfieldInsertMask(FfxUInt32 src, FfxUInt32 ins, FfxUInt32 bits)
{
    return bitfieldInsert(src, ins, 0, FfxInt32(bits));
}
#if FFX_HALF
#define FFX_UINT32_TO_FLOAT16X2(x) unpackFloat2x16(FfxUInt32(x))
FfxFloat16x4 ffxUint32x2ToFloat16x4(FfxUInt32x2 x)
{
    return FfxFloat16x4(unpackFloat2x16(x.x), unpackFloat2x16(x.y));
}
#define FFX_UINT32X2_TO_FLOAT16X4(x) ffxUint32x2ToFloat16x4(FfxUInt32x2(x))
#define FFX_UINT32_TO_UINT16X2(x) unpackUint2x16(FfxUInt32(x))
#define FFX_UINT32X2_TO_UINT16X4(x) unpackUint4x16(pack64(FfxUInt32x2(x)))
#define FFX_FLOAT16X2_TO_UINT32(x) packFloat2x16(FfxFloat16x2(x))
FfxUInt32x2 ffxFloat16x4ToUint32x2(FfxFloat16x4 x)
{
    return FfxUInt32x2(packFloat2x16(x.xy), packFloat2x16(x.zw));
}
#define FFX_FLOAT16X4_TO_UINT32X2(x) ffxFloat16x4ToUint32x2(FfxFloat16x4(x))
#define FFX_UINT16X2_TO_UINT32(x) packUint2x16(FfxUInt16x2(x))
#define FFX_UINT16X4_TO_UINT32X2(x) unpack32(packUint4x16(FfxUInt16x4(x)))
#define FFX_TO_UINT16(x) halfBitsToUint16(FfxFloat16(x))
#define FFX_TO_UINT16X2(x) halfBitsToUint16(FfxFloat16x2(x))
#define FFX_TO_UINT16X3(x) halfBitsToUint16(FfxFloat16x3(x))
#define FFX_TO_UINT16X4(x) halfBitsToUint16(FfxFloat16x4(x))
#define FFX_TO_FLOAT16(x) uint16BitsToHalf(FfxUInt16(x))
#define FFX_TO_FLOAT16X2(x) uint16BitsToHalf(FfxUInt16x2(x))
#define FFX_TO_FLOAT16X3(x) uint16BitsToHalf(FfxUInt16x3(x))
#define FFX_TO_FLOAT16X4(x) uint16BitsToHalf(FfxUInt16x4(x))
#define FFX_BROADCAST_FLOAT16(a)   FfxFloat16(a)
#define FFX_BROADCAST_FLOAT16X2(a) FfxFloat16x2(FfxFloat16(a))
#define FFX_BROADCAST_FLOAT16X3(a) FfxFloat16x3(FfxFloat16(a))
#define FFX_BROADCAST_FLOAT16X4(a) FfxFloat16x4(FfxFloat16(a))
#define FFX_BROADCAST_INT16(a)   FfxInt16(a)
#define FFX_BROADCAST_INT16X2(a) FfxInt16x2(FfxInt16(a))
#define FFX_BROADCAST_INT16X3(a) FfxInt16x3(FfxInt16(a))
#define FFX_BROADCAST_INT16X4(a) FfxInt16x4(FfxInt16(a))
#define FFX_BROADCAST_UINT16(a)   FfxUInt16(a)
#define FFX_BROADCAST_UINT16X2(a) FfxUInt16x2(FfxUInt16(a))
#define FFX_BROADCAST_UINT16X3(a) FfxUInt16x3(FfxUInt16(a))
#define FFX_BROADCAST_UINT16X4(a) FfxUInt16x4(FfxUInt16(a))
#endif 
#if defined(FFX_WAVE)
#if defined(FFX_WAVE_ALL_TRUE)
#endif
#if FFX_HALF
#endif 
#endif 
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#define FFX_TRUE (true)
#define FFX_FALSE (false)
#define FFX_POSITIVE_INFINITY_FLOAT ffxAsFloat(0x7f800000u)
#define FFX_NEGATIVE_INFINITY_FLOAT ffxAsFloat(0xff800000u)
#define FFX_PI  (3.14159)
FFX_STATIC const FfxFloat32 FFX_FP16_MIN = 6.10e-05f;
FFX_STATIC const FfxFloat32 FFX_FP16_MAX = 65504.0f;
FFX_STATIC const FfxFloat32 FFX_TONEMAP_EPSILON = 1.0f / FFX_FP16_MAX;
#define FFX_HAS_FLAG(v, f) ((v & f) == f)
FfxFloat32 ffxMin(FfxFloat32 x, FfxFloat32 y)
{
    return min(x, y);
}
FfxFloat32x2 ffxMin(FfxFloat32x2 x, FfxFloat32x2 y)
{
    return min(x, y);
}
FfxFloat32x3 ffxMin(FfxFloat32x3 x, FfxFloat32x3 y)
{
    return min(x, y);
}
FfxFloat32x4 ffxMin(FfxFloat32x4 x, FfxFloat32x4 y)
{
    return min(x, y);
}
FfxInt32 ffxMin(FfxInt32 x, FfxInt32 y)
{
    return min(x, y);
}
FfxInt32x2 ffxMin(FfxInt32x2 x, FfxInt32x2 y)
{
    return min(x, y);
}
FfxInt32x3 ffxMin(FfxInt32x3 x, FfxInt32x3 y)
{
    return min(x, y);
}
FfxInt32x4 ffxMin(FfxInt32x4 x, FfxInt32x4 y)
{
    return min(x, y);
}
FfxUInt32 ffxMin(FfxUInt32 x, FfxUInt32 y)
{
    return min(x, y);
}
FfxUInt32x2 ffxMin(FfxUInt32x2 x, FfxUInt32x2 y)
{
    return min(x, y);
}
FfxUInt32x3 ffxMin(FfxUInt32x3 x, FfxUInt32x3 y)
{
    return min(x, y);
}
FfxUInt32x4 ffxMin(FfxUInt32x4 x, FfxUInt32x4 y)
{
    return min(x, y);
}
FfxFloat32 ffxMax(FfxFloat32 x, FfxFloat32 y)
{
    return max(x, y);
}
FfxFloat32x2 ffxMax(FfxFloat32x2 x, FfxFloat32x2 y)
{
    return max(x, y);
}
FfxFloat32x3 ffxMax(FfxFloat32x3 x, FfxFloat32x3 y)
{
    return max(x, y);
}
FfxFloat32x4 ffxMax(FfxFloat32x4 x, FfxFloat32x4 y)
{
    return max(x, y);
}
FfxInt32 ffxMax(FfxInt32 x, FfxInt32 y)
{
    return max(x, y);
}
FfxInt32x2 ffxMax(FfxInt32x2 x, FfxInt32x2 y)
{
    return max(x, y);
}
FfxInt32x3 ffxMax(FfxInt32x3 x, FfxInt32x3 y)
{
    return max(x, y);
}
FfxInt32x4 ffxMax(FfxInt32x4 x, FfxInt32x4 y)
{
    return max(x, y);
}
FfxUInt32 ffxMax(FfxUInt32 x, FfxUInt32 y)
{
    return max(x, y);
}
FfxUInt32x2 ffxMax(FfxUInt32x2 x, FfxUInt32x2 y)
{
    return max(x, y);
}
FfxUInt32x3 ffxMax(FfxUInt32x3 x, FfxUInt32x3 y)
{
    return max(x, y);
}
FfxUInt32x4 ffxMax(FfxUInt32x4 x, FfxUInt32x4 y)
{
    return max(x, y);
}
FfxFloat32 ffxSqrt(FfxFloat32 x)
{
    return sqrt(x);
}
FfxFloat32x2 ffxSqrt(FfxFloat32x2 x)
{
    return sqrt(x);
}
FfxFloat32x3 ffxSqrt(FfxFloat32x3 x)
{
    return sqrt(x);
}
FfxFloat32x4 ffxSqrt(FfxFloat32x4 x)
{
    return sqrt(x);
}
FfxUInt32x2 ffxRemapForWaveReduction(FfxUInt32 a)
{
    return FfxUInt32x2(ffxBitfieldInsertMask(ffxBitfieldExtract(a, 2u, 3u), a, 1u), ffxBitfieldInsertMask(ffxBitfieldExtract(a, 3u, 3u), ffxBitfieldExtract(a, 1u, 2u), 2u));
}
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#if FFX_HALF
#if FFX_HLSL_SM >= 62
#define FFX_POSITIVE_INFINITY_HALF FFX_TO_FLOAT16((uint16_t)0x7c00u)
#define FFX_NEGATIVE_INFINITY_HALF FFX_TO_FLOAT16((uint16_t)0xfc00u)
#else
#define FFX_POSITIVE_INFINITY_HALF FFX_TO_FLOAT16(0x7c00u)
#define FFX_NEGATIVE_INFINITY_HALF FFX_TO_FLOAT16(0xfc00u)
#endif 
FfxFloat16 ffxMin(FfxFloat16 x, FfxFloat16 y)
{
    return min(x, y);
}
FfxFloat16x2 ffxMin(FfxFloat16x2 x, FfxFloat16x2 y)
{
    return min(x, y);
}
FfxFloat16x3 ffxMin(FfxFloat16x3 x, FfxFloat16x3 y)
{
    return min(x, y);
}
FfxFloat16x4 ffxMin(FfxFloat16x4 x, FfxFloat16x4 y)
{
    return min(x, y);
}
FfxInt16 ffxMin(FfxInt16 x, FfxInt16 y)
{
    return min(x, y);
}
FfxInt16x2 ffxMin(FfxInt16x2 x, FfxInt16x2 y)
{
    return min(x, y);
}
FfxInt16x3 ffxMin(FfxInt16x3 x, FfxInt16x3 y)
{
    return min(x, y);
}
FfxInt16x4 ffxMin(FfxInt16x4 x, FfxInt16x4 y)
{
    return min(x, y);
}
FfxUInt16 ffxMin(FfxUInt16 x, FfxUInt16 y)
{
    return min(x, y);
}
FfxUInt16x2 ffxMin(FfxUInt16x2 x, FfxUInt16x2 y)
{
    return min(x, y);
}
FfxUInt16x3 ffxMin(FfxUInt16x3 x, FfxUInt16x3 y)
{
    return min(x, y);
}
FfxUInt16x4 ffxMin(FfxUInt16x4 x, FfxUInt16x4 y)
{
    return min(x, y);
}
FfxFloat16 ffxMax(FfxFloat16 x, FfxFloat16 y)
{
    return max(x, y);
}
FfxFloat16x2 ffxMax(FfxFloat16x2 x, FfxFloat16x2 y)
{
    return max(x, y);
}
FfxFloat16x3 ffxMax(FfxFloat16x3 x, FfxFloat16x3 y)
{
    return max(x, y);
}
FfxFloat16x4 ffxMax(FfxFloat16x4 x, FfxFloat16x4 y)
{
    return max(x, y);
}
FfxInt16 ffxMax(FfxInt16 x, FfxInt16 y)
{
    return max(x, y);
}
FfxInt16x2 ffxMax(FfxInt16x2 x, FfxInt16x2 y)
{
    return max(x, y);
}
FfxInt16x3 ffxMax(FfxInt16x3 x, FfxInt16x3 y)
{
    return max(x, y);
}
FfxInt16x4 ffxMax(FfxInt16x4 x, FfxInt16x4 y)
{
    return max(x, y);
}
FfxUInt16 ffxMax(FfxUInt16 x, FfxUInt16 y)
{
    return max(x, y);
}
FfxUInt16x2 ffxMax(FfxUInt16x2 x, FfxUInt16x2 y)
{
    return max(x, y);
}
FfxUInt16x3 ffxMax(FfxUInt16x3 x, FfxUInt16x3 y)
{
    return max(x, y);
}
FfxUInt16x4 ffxMax(FfxUInt16x4 x, FfxUInt16x4 y)
{
    return max(x, y);
}
FfxFloat16 ffxSqrt(FfxFloat16 x)
{
    return sqrt(x);
}
FfxFloat16x2 ffxSqrt(FfxFloat16x2 x)
{
    return sqrt(x);
}
FfxFloat16x3 ffxSqrt(FfxFloat16x3 x)
{
    return sqrt(x);
}
FfxFloat16x4 ffxSqrt(FfxFloat16x4 x)
{
    return sqrt(x);
}
#endif  
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#if SPD_CHANNELS == 1
#define SPD_DATA_TYPE float
#define SPD_DATA_CAST_TO_4(x) vec4(x, 0.0, 0.0, 0.0)
#define SPD_DATA_CAST_FROM_4(v) v.x
#elif SPD_CHANNELS == 2
#define SPD_DATA_TYPE vec2
#define SPD_DATA_CAST_TO_4(x) vec4(x, 0.0, 0.0)
#define SPD_DATA_CAST_FROM_4(v) v.xy
#elif SPD_CHANNELS == 3
#define SPD_DATA_TYPE vec3
#define SPD_DATA_CAST_TO_4(x) vec4(x, 0.0)
#define SPD_DATA_CAST_FROM_4(v) v.xyz
#elif SPD_CHANNELS == 4
#define SPD_DATA_TYPE vec4
#define SPD_DATA_CAST_TO_4(x) x
#define SPD_DATA_CAST_FROM_4(v) v
#endif
SPD_DATA_TYPE spd_loadInput(ivec2 texelPos, uint slice);
SPD_DATA_TYPE spd_loadOutput(ivec2 texelPos, uint level, uint slice);
void spd_storeOutput(ivec2 texelPos, uint level, uint slice, SPD_DATA_TYPE value);
uint spd_mipCount();
void spd_init();
vec4 spd_reduce4(vec4 v0, vec4 v1, vec4 v2, vec4 v3);
#ifdef SPD_OP
vec4 spd_reduce4(vec4 v0, vec4 v1, vec4 v2, vec4 v3) {
    #if SPD_OP == 0
    return ffxMin(ffxMin(v0, v1), ffxMin(v2, v3));
    #elif SPD_OP == 1
    return ffxMax(ffxMax(v0, v1), ffxMax(v2, v3));
    #elif SPD_OP == 2
    return (v0 + v1 + v2 + v3) * 0.25;
    #else
    return v0 + v1 + v2 + v3;
    #endif
}
#endif
shared uint shared_counter;
void SpdIncreaseAtomicCounter(uint slice) {
    shared_counter = atomicAdd(global_atomicCounters[slice], 1u);
}
uint SpdGetAtomicCounter() {
    return shared_counter;
}
void SpdResetAtomicCounter(uint slice) {
    global_atomicCounters[slice] = 0u;
}
#if SPD_HALF
#else
shared SPD_DATA_TYPE shared_intermediate[16][16];
vec4 SpdLoadSourceImage(ivec2 tex, uint slice) {
    return SPD_DATA_CAST_TO_4(spd_loadInput(tex, slice));
}
vec4 SpdLoad(ivec2 tex, uint slice) {
    return SPD_DATA_CAST_TO_4(spd_loadOutput(tex, 6, slice));
}
void SpdStore(FfxInt32x2 pix, vec4 outValue, uint mip, uint slice) {
    spd_storeOutput(pix, mip + 1, slice, SPD_DATA_CAST_FROM_4(outValue));
}
vec4 SpdLoadIntermediate(uint x, uint y) {
    return SPD_DATA_CAST_TO_4(shared_intermediate[x][y]);
}
void SpdStoreIntermediate(uint x, uint y, vec4 value) {
    shared_intermediate[x][y] = SPD_DATA_CAST_FROM_4(value);
}
vec4 SpdReduce4(vec4 v0, vec4 v1, vec4 v2, vec4 v3) {
    return spd_reduce4(v0, v1, v2, v3);
}
#endif
/*
    This file is part of the FidelityFX SDK.

    Copyright (C) 2024 Advanced Micro Devices, Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files(the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions :

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
*/
#if defined(FFX_GPU)
#if defined(FFX_SPD_PACKED_ONLY)
FfxFloat32x4 SpdLoadSourceImage(FfxInt32x2 p, FfxUInt32 slice)
{
    return FfxFloat32x4(0.0, 0.0, 0.0, 0.0);
}
FfxFloat32x4 SpdLoad(FfxInt32x2 p, FfxUInt32 slice)
{
    return FfxFloat32x4(0.0, 0.0, 0.0, 0.0);
}
void SpdStore(FfxInt32x2 p, FfxFloat32x4 value, FfxUInt32 mip, FfxUInt32 slice)
{
}
FfxFloat32x4 SpdLoadIntermediate(FfxUInt32 x, FfxUInt32 y)
{
    return FfxFloat32x4(0.0, 0.0, 0.0, 0.0);
}
void SpdStoreIntermediate(FfxUInt32 x, FfxUInt32 y, FfxFloat32x4 value)
{
}
FfxFloat32x4 SpdReduce4(FfxFloat32x4 v0, FfxFloat32x4 v1, FfxFloat32x4 v2, FfxFloat32x4 v3)
{
    return FfxFloat32x4(0.0, 0.0, 0.0, 0.0);
}
#endif 
#if defined(FFX_GLSL) && !defined(FFX_SPD_NO_WAVE_OPERATIONS)
#extension GL_KHR_shader_subgroup_quad:require
#endif
void ffxSpdWorkgroupShuffleBarrier()
{
    FFX_GROUP_MEMORY_BARRIER;
}
bool SpdExitWorkgroup(FfxUInt32 numWorkGroups, FfxUInt32 localInvocationIndex, FfxUInt32 slice)
{
    if (localInvocationIndex == 0)
    {
        SpdIncreaseAtomicCounter(slice);
    }
    ffxSpdWorkgroupShuffleBarrier();
    return (SpdGetAtomicCounter() != (numWorkGroups - 1));
}
FfxFloat32x4 SpdReduceQuad(FfxFloat32x4 v)
{
#if defined(FFX_GLSL) && !defined(FFX_SPD_NO_WAVE_OPERATIONS)
    FfxFloat32x4 v0 = v;
    FfxFloat32x4 v1 = subgroupQuadSwapHorizontal(v);
    FfxFloat32x4 v2 = subgroupQuadSwapVertical(v);
    FfxFloat32x4 v3 = subgroupQuadSwapDiagonal(v);
    return SpdReduce4(v0, v1, v2, v3);
#elif defined(FFX_HLSL) && !defined(FFX_SPD_NO_WAVE_OPERATIONS)
    FfxFloat32x4 v0 = v;
    FfxFloat32x4 v1 = QuadReadAcrossX(v);
    FfxFloat32x4 v2 = QuadReadAcrossY(v);
    FfxFloat32x4 v3 = QuadReadAcrossDiagonal(v);
    return SpdReduce4(v0, v1, v2, v3);
/*
    
    
    
    
    FfxFloat32x4 v0 = v;
    FfxFloat32x4 v1;
    v1.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    FfxFloat32x4 v2;
    v2.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    FfxFloat32x4 v3;
    v3.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    return SpdReduce4(v0, v1, v2, v3);
    */
#endif
    return v;
}
FfxFloat32x4 SpdReduceIntermediate(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3)
{
    FfxFloat32x4 v0 = SpdLoadIntermediate(i0.x, i0.y);
    FfxFloat32x4 v1 = SpdLoadIntermediate(i1.x, i1.y);
    FfxFloat32x4 v2 = SpdLoadIntermediate(i2.x, i2.y);
    FfxFloat32x4 v3 = SpdLoadIntermediate(i3.x, i3.y);
    return SpdReduce4(v0, v1, v2, v3);
}
FfxFloat32x4 SpdReduceLoad4(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3, FfxUInt32 slice)
{
    FfxFloat32x4 v0 = SpdLoad(FfxInt32x2(i0), slice);
    FfxFloat32x4 v1 = SpdLoad(FfxInt32x2(i1), slice);
    FfxFloat32x4 v2 = SpdLoad(FfxInt32x2(i2), slice);
    FfxFloat32x4 v3 = SpdLoad(FfxInt32x2(i3), slice);
    return SpdReduce4(v0, v1, v2, v3);
}
FfxFloat32x4 SpdReduceLoad4(FfxUInt32x2 base, FfxUInt32 slice)
{
    return SpdReduceLoad4(FfxUInt32x2(base + FfxUInt32x2(0, 0)), FfxUInt32x2(base + FfxUInt32x2(0, 1)), FfxUInt32x2(base + FfxUInt32x2(1, 0)), FfxUInt32x2(base + FfxUInt32x2(1, 1)), slice);
}
FfxFloat32x4 SpdReduceLoadSourceImage4(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3, FfxUInt32 slice)
{
    FfxFloat32x4 v0 = SpdLoadSourceImage(FfxInt32x2(i0), slice);
    FfxFloat32x4 v1 = SpdLoadSourceImage(FfxInt32x2(i1), slice);
    FfxFloat32x4 v2 = SpdLoadSourceImage(FfxInt32x2(i2), slice);
    FfxFloat32x4 v3 = SpdLoadSourceImage(FfxInt32x2(i3), slice);
    return SpdReduce4(v0, v1, v2, v3);
}
FfxFloat32x4 SpdReduceLoadSourceImage(FfxUInt32x2 base, FfxUInt32 slice)
{
#if defined(SPD_LINEAR_SAMPLER)
    return SpdLoadSourceImage(FfxInt32x2(base), slice);
#else
    return SpdReduceLoadSourceImage4(FfxUInt32x2(base + FfxUInt32x2(0, 0)), FfxUInt32x2(base + FfxUInt32x2(0, 1)), FfxUInt32x2(base + FfxUInt32x2(1, 0)), FfxUInt32x2(base + FfxUInt32x2(1, 1)), slice);
#endif
}
void SpdDownsampleMips_0_1_Intrinsics(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
    FfxFloat32x4 v[4];
    FfxInt32x2 tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2);
    FfxInt32x2 pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y);
    v[0] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[0], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y);
    v[1] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[1], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y + 16);
    v[2] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[2], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y + 16);
    v[3] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[3], 0, slice);
    if (mip <= 1)
        return;
    v[0] = SpdReduceQuad(v[0]);
    v[1] = SpdReduceQuad(v[1]);
    v[2] = SpdReduceQuad(v[2]);
    v[3] = SpdReduceQuad(v[3]);
    if ((localInvocationIndex % 4) == 0)
    {
        SpdStore(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2, y / 2), v[0], 1, slice);
        SpdStoreIntermediate(x / 2, y / 2, v[0]);
        SpdStore(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2 + 8, y / 2), v[1], 1, slice);
        SpdStoreIntermediate(x / 2 + 8, y / 2, v[1]);
        SpdStore(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2, y / 2 + 8), v[2], 1, slice);
        SpdStoreIntermediate(x / 2, y / 2 + 8, v[2]);
        SpdStore(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2 + 8, y / 2 + 8), v[3], 1, slice);
        SpdStoreIntermediate(x / 2 + 8, y / 2 + 8, v[3]);
    }
}
void SpdDownsampleMips_0_1_LDS(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
    FfxFloat32x4 v[4];
    FfxInt32x2 tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2);
    FfxInt32x2 pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y);
    v[0] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[0], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y);
    v[1] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[1], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y + 16);
    v[2] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[2], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y + 16);
    v[3] = SpdReduceLoadSourceImage(tex, slice);
    SpdStore(pix, v[3], 0, slice);
    if (mip <= 1)
        return;
    for (FfxUInt32 i = 0; i < 4; i++)
    {
        SpdStoreIntermediate(x, y, v[i]);
        ffxSpdWorkgroupShuffleBarrier();
        if (localInvocationIndex < 64)
        {
            v[i] = SpdReduceIntermediate(FfxUInt32x2(x * 2 + 0, y * 2 + 0), FfxUInt32x2(x * 2 + 1, y * 2 + 0), FfxUInt32x2(x * 2 + 0, y * 2 + 1), FfxUInt32x2(x * 2 + 1, y * 2 + 1));
            SpdStore(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1, slice);
        }
        ffxSpdWorkgroupShuffleBarrier();
    }
    if (localInvocationIndex < 64)
    {
        SpdStoreIntermediate(x + 0, y + 0, v[0]);
        SpdStoreIntermediate(x + 8, y + 0, v[1]);
        SpdStoreIntermediate(x + 0, y + 8, v[2]);
        SpdStoreIntermediate(x + 8, y + 8, v[3]);
    }
}
void SpdDownsampleMips_0_1(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    SpdDownsampleMips_0_1_LDS(x, y, workGroupID, localInvocationIndex, mip, slice);
#else
    SpdDownsampleMips_0_1_Intrinsics(x, y, workGroupID, localInvocationIndex, mip, slice);
#endif
}
void SpdDownsampleMip_2(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 64)
    {
        FfxFloat32x4 v = SpdReduceIntermediate(FfxUInt32x2(x * 2 + 0, y * 2 + 0), FfxUInt32x2(x * 2 + 1, y * 2 + 0), FfxUInt32x2(x * 2 + 0, y * 2 + 1), FfxUInt32x2(x * 2 + 1, y * 2 + 1));
        SpdStore(FfxInt32x2(workGroupID.xy * 8) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediate(x * 2 + y % 2, y * 2, v);
    }
#else
    FfxFloat32x4 v = SpdLoadIntermediate(x, y);
    v = SpdReduceQuad(v);
    if (localInvocationIndex % 4 == 0)
    {
        SpdStore(FfxInt32x2(workGroupID.xy * 8) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
        SpdStoreIntermediate(x + (y / 2) % 2, y, v);
    }
#endif
}
void SpdDownsampleMip_3(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 16)
    {
        FfxFloat32x4 v =
            SpdReduceIntermediate(FfxUInt32x2(x * 4 + 0 + 0, y * 4 + 0), FfxUInt32x2(x * 4 + 2 + 0, y * 4 + 0), FfxUInt32x2(x * 4 + 0 + 1, y * 4 + 2), FfxUInt32x2(x * 4 + 2 + 1, y * 4 + 2));
        SpdStore(FfxInt32x2(workGroupID.xy * 4) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediate(x * 4 + y, y * 4, v);
    }
#else
    if (localInvocationIndex < 64)
    {
        FfxFloat32x4 v = SpdLoadIntermediate(x * 2 + y % 2, y * 2);
        v = SpdReduceQuad(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStore(FfxInt32x2(workGroupID.xy * 4) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
            SpdStoreIntermediate(x * 2 + y / 2, y * 2, v);
        }
    }
#endif
}
void SpdDownsampleMip_4(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 4)
    {
        FfxFloat32x4 v = SpdReduceIntermediate(FfxUInt32x2(x * 8 + 0 + 0 + y * 2, y * 8 + 0),
                                         FfxUInt32x2(x * 8 + 4 + 0 + y * 2, y * 8 + 0),
                                         FfxUInt32x2(x * 8 + 0 + 1 + y * 2, y * 8 + 4),
                                         FfxUInt32x2(x * 8 + 4 + 1 + y * 2, y * 8 + 4));
        SpdStore(FfxInt32x2(workGroupID.xy * 2) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediate(x + y * 2, 0, v);
    }
#else
    if (localInvocationIndex < 16)
    {
        FfxFloat32x4 v = SpdLoadIntermediate(x * 4 + y, y * 4);
        v = SpdReduceQuad(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStore(FfxInt32x2(workGroupID.xy * 2) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
            SpdStoreIntermediate(x / 2 + y, 0, v);
        }
    }
#endif
}
void SpdDownsampleMip_5(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 1)
    {
        FfxFloat32x4 v = SpdReduceIntermediate(FfxUInt32x2(0, 0), FfxUInt32x2(1, 0), FfxUInt32x2(2, 0), FfxUInt32x2(3, 0));
        SpdStore(FfxInt32x2(workGroupID.xy), v, mip, slice);
    }
#else
    if (localInvocationIndex < 4)
    {
        FfxFloat32x4 v = SpdLoadIntermediate(localInvocationIndex, 0);
        v = SpdReduceQuad(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStore(FfxInt32x2(workGroupID.xy), v, mip, slice);
        }
    }
#endif
}
void SpdDownsampleMips_6_7(FfxUInt32 x, FfxUInt32 y, FfxUInt32 mips, FfxUInt32 slice)
{
    FfxInt32x2 tex = FfxInt32x2(x * 4 + 0, y * 4 + 0);
    FfxInt32x2 pix = FfxInt32x2(x * 2 + 0, y * 2 + 0);
    FfxFloat32x4 v0 = SpdReduceLoad4(tex, slice);
    SpdStore(pix, v0, 6, slice);
    tex = FfxInt32x2(x * 4 + 2, y * 4 + 0);
    pix = FfxInt32x2(x * 2 + 1, y * 2 + 0);
    FfxFloat32x4 v1 = SpdReduceLoad4(tex, slice);
    SpdStore(pix, v1, 6, slice);
    tex = FfxInt32x2(x * 4 + 0, y * 4 + 2);
    pix = FfxInt32x2(x * 2 + 0, y * 2 + 1);
    FfxFloat32x4 v2 = SpdReduceLoad4(tex, slice);
    SpdStore(pix, v2, 6, slice);
    tex = FfxInt32x2(x * 4 + 2, y * 4 + 2);
    pix = FfxInt32x2(x * 2 + 1, y * 2 + 1);
    FfxFloat32x4 v3 = SpdReduceLoad4(tex, slice);
    SpdStore(pix, v3, 6, slice);
    if (mips <= 7)
        return;
    FfxFloat32x4 v = SpdReduce4(v0, v1, v2, v3);
    SpdStore(FfxInt32x2(x, y), v, 7, slice);
    SpdStoreIntermediate(x, y, v);
}
void SpdDownsampleNextFour(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 baseMip, FfxUInt32 mips, FfxUInt32 slice)
{
    if (mips <= baseMip)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_2(x, y, workGroupID, localInvocationIndex, baseMip, slice);
    if (mips <= baseMip + 1)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_3(x, y, workGroupID, localInvocationIndex, baseMip + 1, slice);
    if (mips <= baseMip + 2)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_4(x, y, workGroupID, localInvocationIndex, baseMip + 2, slice);
    if (mips <= baseMip + 3)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_5(workGroupID, localInvocationIndex, baseMip + 3, slice);
}
void SpdDownsample(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 numWorkGroups, FfxUInt32 slice)
{
    FfxUInt32x2 sub_xy = ffxRemapForWaveReduction(localInvocationIndex % 64);
    FfxUInt32 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2);
    FfxUInt32 y = sub_xy.y + 8 * ((localInvocationIndex >> 7));
    SpdDownsampleMips_0_1(x, y, workGroupID, localInvocationIndex, mips, slice);
    SpdDownsampleNextFour(x, y, workGroupID, localInvocationIndex, 2, mips, slice);
    if (mips <= 6)
        return;
    if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex, slice))
        return;
    SpdResetAtomicCounter(slice);
    SpdDownsampleMips_6_7(x, y, mips, slice);
    SpdDownsampleNextFour(x, y, FfxUInt32x2(0, 0), localInvocationIndex, 8, mips, slice);
}
void SpdDownsample(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 numWorkGroups, FfxUInt32 slice, FfxUInt32x2 workGroupOffset)
{
    SpdDownsample(workGroupID + workGroupOffset, localInvocationIndex, mips, numWorkGroups, slice);
}
#if FFX_HALF
#if defined(FFX_GLSL)
#extension GL_EXT_shader_subgroup_extended_types_float16:require
#endif
FfxFloat16x4 SpdReduceQuadH(FfxFloat16x4 v)
{
#if defined(FFX_GLSL) && !defined(FFX_SPD_NO_WAVE_OPERATIONS)
    FfxFloat16x4 v0 = v;
    FfxFloat16x4 v1 = subgroupQuadSwapHorizontal(v);
    FfxFloat16x4 v2 = subgroupQuadSwapVertical(v);
    FfxFloat16x4 v3 = subgroupQuadSwapDiagonal(v);
    return SpdReduce4H(v0, v1, v2, v3);
#elif defined(FFX_HLSL) && !defined(FFX_SPD_NO_WAVE_OPERATIONS)
    FfxFloat16x4 v0 = v;
    FfxFloat16x4 v1 = QuadReadAcrossX(v);
    FfxFloat16x4 v2 = QuadReadAcrossY(v);
    FfxFloat16x4 v3 = QuadReadAcrossDiagonal(v);
    return SpdReduce4H(v0, v1, v2, v3);
/*
    
    
    
    
    FfxFloat16x4 v0 = v;
    FfxFloat16x4 v1;
    v1.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    v1.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
    FfxFloat16x4 v2;
    v2.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    v2.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
    FfxFloat16x4 v3;
    v3.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
    return SpdReduce4H(v0, v1, v2, v3);
    */
#endif
    return FfxFloat16x4(0.0, 0.0, 0.0, 0.0);
}
FfxFloat16x4 SpdReduceIntermediateH(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3)
{
    FfxFloat16x4 v0 = SpdLoadIntermediateH(i0.x, i0.y);
    FfxFloat16x4 v1 = SpdLoadIntermediateH(i1.x, i1.y);
    FfxFloat16x4 v2 = SpdLoadIntermediateH(i2.x, i2.y);
    FfxFloat16x4 v3 = SpdLoadIntermediateH(i3.x, i3.y);
    return SpdReduce4H(v0, v1, v2, v3);
}
FfxFloat16x4 SpdReduceLoad4H(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3, FfxUInt32 slice)
{
    FfxFloat16x4 v0 = SpdLoadH(FfxInt32x2(i0), slice);
    FfxFloat16x4 v1 = SpdLoadH(FfxInt32x2(i1), slice);
    FfxFloat16x4 v2 = SpdLoadH(FfxInt32x2(i2), slice);
    FfxFloat16x4 v3 = SpdLoadH(FfxInt32x2(i3), slice);
    return SpdReduce4H(v0, v1, v2, v3);
}
FfxFloat16x4 SpdReduceLoad4H(FfxUInt32x2 base, FfxUInt32 slice)
{
    return SpdReduceLoad4H(FfxUInt32x2(base + FfxUInt32x2(0, 0)), FfxUInt32x2(base + FfxUInt32x2(0, 1)), FfxUInt32x2(base + FfxUInt32x2(1, 0)), FfxUInt32x2(base + FfxUInt32x2(1, 1)), slice);
}
FfxFloat16x4 SpdReduceLoadSourceImage4H(FfxUInt32x2 i0, FfxUInt32x2 i1, FfxUInt32x2 i2, FfxUInt32x2 i3, FfxUInt32 slice)
{
    FfxFloat16x4 v0 = SpdLoadSourceImageH(FfxInt32x2(i0), slice);
    FfxFloat16x4 v1 = SpdLoadSourceImageH(FfxInt32x2(i1), slice);
    FfxFloat16x4 v2 = SpdLoadSourceImageH(FfxInt32x2(i2), slice);
    FfxFloat16x4 v3 = SpdLoadSourceImageH(FfxInt32x2(i3), slice);
    return SpdReduce4H(v0, v1, v2, v3);
}
FfxFloat16x4 SpdReduceLoadSourceImageH(FfxUInt32x2 base, FfxUInt32 slice)
{
#if defined(SPD_LINEAR_SAMPLER)
    return SpdLoadSourceImageH(FfxInt32x2(base), slice);
#else
    return SpdReduceLoadSourceImage4H(FfxUInt32x2(base + FfxUInt32x2(0, 0)), FfxUInt32x2(base + FfxUInt32x2(0, 1)), FfxUInt32x2(base + FfxUInt32x2(1, 0)), FfxUInt32x2(base + FfxUInt32x2(1, 1)), slice);
#endif
}
void SpdDownsampleMips_0_1_IntrinsicsH(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 slice)
{
    FfxFloat16x4 v[4];
    FfxInt32x2 tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2);
    FfxInt32x2 pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y);
    v[0] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[0], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y);
    v[1] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[1], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y + 16);
    v[2] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[2], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y + 16);
    v[3] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[3], 0, slice);
    if (mips <= 1)
        return;
    v[0] = SpdReduceQuadH(v[0]);
    v[1] = SpdReduceQuadH(v[1]);
    v[2] = SpdReduceQuadH(v[2]);
    v[3] = SpdReduceQuadH(v[3]);
    if ((localInvocationIndex % 4) == 0)
    {
        SpdStoreH(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2, y / 2), v[0], 1, slice);
        SpdStoreIntermediateH(x / 2, y / 2, v[0]);
        SpdStoreH(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2 + 8, y / 2), v[1], 1, slice);
        SpdStoreIntermediateH(x / 2 + 8, y / 2, v[1]);
        SpdStoreH(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2, y / 2 + 8), v[2], 1, slice);
        SpdStoreIntermediateH(x / 2, y / 2 + 8, v[2]);
        SpdStoreH(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x / 2 + 8, y / 2 + 8), v[3], 1, slice);
        SpdStoreIntermediateH(x / 2 + 8, y / 2 + 8, v[3]);
    }
}
void SpdDownsampleMips_0_1_LDSH(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 slice)
{
    FfxFloat16x4 v[4];
    FfxInt32x2 tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2);
    FfxInt32x2 pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y);
    v[0] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[0], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y);
    v[1] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[1], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x, y + 16);
    v[2] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[2], 0, slice);
    tex = FfxInt32x2(workGroupID.xy * 64) + FfxInt32x2(x * 2 + 32, y * 2 + 32);
    pix = FfxInt32x2(workGroupID.xy * 32) + FfxInt32x2(x + 16, y + 16);
    v[3] = SpdReduceLoadSourceImageH(tex, slice);
    SpdStoreH(pix, v[3], 0, slice);
    if (mips <= 1)
        return;
    for (FfxInt32 i = 0; i < 4; i++)
    {
        SpdStoreIntermediateH(x, y, v[i]);
        ffxSpdWorkgroupShuffleBarrier();
        if (localInvocationIndex < 64)
        {
            v[i] = SpdReduceIntermediateH(FfxUInt32x2(x * 2 + 0, y * 2 + 0), FfxUInt32x2(x * 2 + 1, y * 2 + 0), FfxUInt32x2(x * 2 + 0, y * 2 + 1), FfxUInt32x2(x * 2 + 1, y * 2 + 1));
            SpdStoreH(FfxInt32x2(workGroupID.xy * 16) + FfxInt32x2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1, slice);
        }
        ffxSpdWorkgroupShuffleBarrier();
    }
    if (localInvocationIndex < 64)
    {
        SpdStoreIntermediateH(x + 0, y + 0, v[0]);
        SpdStoreIntermediateH(x + 8, y + 0, v[1]);
        SpdStoreIntermediateH(x + 0, y + 8, v[2]);
        SpdStoreIntermediateH(x + 8, y + 8, v[3]);
    }
}
void SpdDownsampleMips_0_1H(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    SpdDownsampleMips_0_1_LDSH(x, y, workGroupID, localInvocationIndex, mips, slice);
#else
    SpdDownsampleMips_0_1_IntrinsicsH(x, y, workGroupID, localInvocationIndex, mips, slice);
#endif
}
void SpdDownsampleMip_2H(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 64)
    {
        FfxFloat16x4 v = SpdReduceIntermediateH(FfxUInt32x2(x * 2 + 0, y * 2 + 0), FfxUInt32x2(x * 2 + 1, y * 2 + 0), FfxUInt32x2(x * 2 + 0, y * 2 + 1), FfxUInt32x2(x * 2 + 1, y * 2 + 1));
        SpdStoreH(FfxInt32x2(workGroupID.xy * 8) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediateH(x * 2 + y % 2, y * 2, v);
    }
#else
    FfxFloat16x4 v = SpdLoadIntermediateH(x, y);
    v = SpdReduceQuadH(v);
    if (localInvocationIndex % 4 == 0)
    {
        SpdStoreH(FfxInt32x2(workGroupID.xy * 8) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
        SpdStoreIntermediateH(x + (y / 2) % 2, y, v);
    }
#endif
}
void SpdDownsampleMip_3H(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 16)
    {
        FfxFloat16x4 v =
            SpdReduceIntermediateH(FfxUInt32x2(x * 4 + 0 + 0, y * 4 + 0), FfxUInt32x2(x * 4 + 2 + 0, y * 4 + 0), FfxUInt32x2(x * 4 + 0 + 1, y * 4 + 2), FfxUInt32x2(x * 4 + 2 + 1, y * 4 + 2));
        SpdStoreH(FfxInt32x2(workGroupID.xy * 4) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediateH(x * 4 + y, y * 4, v);
    }
#else
    if (localInvocationIndex < 64)
    {
        FfxFloat16x4 v = SpdLoadIntermediateH(x * 2 + y % 2, y * 2);
        v = SpdReduceQuadH(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStoreH(FfxInt32x2(workGroupID.xy * 4) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
            SpdStoreIntermediateH(x * 2 + y / 2, y * 2, v);
        }
    }
#endif
}
void SpdDownsampleMip_4H(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 4)
    {
        FfxFloat16x4 v = SpdReduceIntermediateH(FfxUInt32x2(x * 8 + 0 + 0 + y * 2, y * 8 + 0),
                                       FfxUInt32x2(x * 8 + 4 + 0 + y * 2, y * 8 + 0),
                                       FfxUInt32x2(x * 8 + 0 + 1 + y * 2, y * 8 + 4),
                                       FfxUInt32x2(x * 8 + 4 + 1 + y * 2, y * 8 + 4));
        SpdStoreH(FfxInt32x2(workGroupID.xy * 2) + FfxInt32x2(x, y), v, mip, slice);
        SpdStoreIntermediateH(x + y * 2, 0, v);
    }
#else
    if (localInvocationIndex < 16)
    {
        FfxFloat16x4 v = SpdLoadIntermediateH(x * 4 + y, y * 4);
        v = SpdReduceQuadH(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStoreH(FfxInt32x2(workGroupID.xy * 2) + FfxInt32x2(x / 2, y / 2), v, mip, slice);
            SpdStoreIntermediateH(x / 2 + y, 0, v);
        }
    }
#endif
}
void SpdDownsampleMip_5H(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mip, FfxUInt32 slice)
{
#if defined(FFX_SPD_NO_WAVE_OPERATIONS)
    if (localInvocationIndex < 1)
    {
        FfxFloat16x4 v = SpdReduceIntermediateH(FfxUInt32x2(0, 0), FfxUInt32x2(1, 0), FfxUInt32x2(2, 0), FfxUInt32x2(3, 0));
        SpdStoreH(FfxInt32x2(workGroupID.xy), v, mip, slice);
    }
#else
    if (localInvocationIndex < 4)
    {
        FfxFloat16x4 v = SpdLoadIntermediateH(localInvocationIndex, 0);
        v = SpdReduceQuadH(v);
        if (localInvocationIndex % 4 == 0)
        {
            SpdStoreH(FfxInt32x2(workGroupID.xy), v, mip, slice);
        }
    }
#endif
}
void SpdDownsampleMips_6_7H(FfxUInt32 x, FfxUInt32 y, FfxUInt32 mips, FfxUInt32 slice)
{
    FfxInt32x2 tex = FfxInt32x2(x * 4 + 0, y * 4 + 0);
    FfxInt32x2 pix = FfxInt32x2(x * 2 + 0, y * 2 + 0);
    FfxFloat16x4 v0 = SpdReduceLoad4H(tex, slice);
    SpdStoreH(pix, v0, 6, slice);
    tex = FfxInt32x2(x * 4 + 2, y * 4 + 0);
    pix = FfxInt32x2(x * 2 + 1, y * 2 + 0);
    FfxFloat16x4 v1 = SpdReduceLoad4H(tex, slice);
    SpdStoreH(pix, v1, 6, slice);
    tex = FfxInt32x2(x * 4 + 0, y * 4 + 2);
    pix = FfxInt32x2(x * 2 + 0, y * 2 + 1);
    FfxFloat16x4 v2 = SpdReduceLoad4H(tex, slice);
    SpdStoreH(pix, v2, 6, slice);
    tex = FfxInt32x2(x * 4 + 2, y * 4 + 2);
    pix = FfxInt32x2(x * 2 + 1, y * 2 + 1);
    FfxFloat16x4 v3 = SpdReduceLoad4H(tex, slice);
    SpdStoreH(pix, v3, 6, slice);
    if (mips < 8)
        return;
    FfxFloat16x4 v = SpdReduce4H(v0, v1, v2, v3);
    SpdStoreH(FfxInt32x2(x, y), v, 7, slice);
    SpdStoreIntermediateH(x, y, v);
}
void SpdDownsampleNextFourH(FfxUInt32 x, FfxUInt32 y, FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 baseMip, FfxUInt32 mips, FfxUInt32 slice)
{
    if (mips <= baseMip)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_2H(x, y, workGroupID, localInvocationIndex, baseMip, slice);
    if (mips <= baseMip + 1)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_3H(x, y, workGroupID, localInvocationIndex, baseMip + 1, slice);
    if (mips <= baseMip + 2)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_4H(x, y, workGroupID, localInvocationIndex, baseMip + 2, slice);
    if (mips <= baseMip + 3)
        return;
    ffxSpdWorkgroupShuffleBarrier();
    SpdDownsampleMip_5H(workGroupID, localInvocationIndex, baseMip + 3, slice);
}
void SpdDownsampleH(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 numWorkGroups, FfxUInt32 slice)
{
    FfxUInt32x2 sub_xy = ffxRemapForWaveReduction(localInvocationIndex % 64);
    FfxUInt32 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2);
    FfxUInt32 y = sub_xy.y + 8 * ((localInvocationIndex >> 7));
    SpdDownsampleMips_0_1H(x, y, workGroupID, localInvocationIndex, mips, slice);
    SpdDownsampleNextFourH(x, y, workGroupID, localInvocationIndex, 2, mips, slice);
    if (mips < 7)
        return;
    if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex, slice))
        return;
    SpdResetAtomicCounter(slice);
    SpdDownsampleMips_6_7H(x, y, mips, slice);
    SpdDownsampleNextFourH(x, y, FfxUInt32x2(0, 0), localInvocationIndex, 8, mips, slice);
}
void SpdDownsampleH(FfxUInt32x2 workGroupID, FfxUInt32 localInvocationIndex, FfxUInt32 mips, FfxUInt32 numWorkGroups, FfxUInt32 slice, FfxUInt32x2 workGroupOffset)
{
    SpdDownsampleH(workGroupID + workGroupOffset, localInvocationIndex, mips, numWorkGroups, slice);
}
#endif 
#endif 
layout(local_size_x = 16, local_size_y = 16) in;
void main() {
    spd_init();
    uint totalNumWorkGroups = gl_NumWorkGroups.x * gl_NumWorkGroups.y;
    #if SPD_HALF
    SpdDownsampleH(gl_WorkGroupID.xy, gl_LocalInvocationIndex, spd_mipCount(), totalNumWorkGroups, gl_WorkGroupID.z);
    #else
    SpdDownsample(gl_WorkGroupID.xy, gl_LocalInvocationIndex, spd_mipCount(), totalNumWorkGroups, gl_WorkGroupID.z);
    #endif
}
layout(rgba32ui) uniform coherent uimage2D uimg_rgba32ui;
const vec2 workGroupsRender = vec2(0.25, 0.25);
shared ivec2 shared_mipTile6;
vec4 spd_loadInput(ivec2 texelPos, uint slice) {
    vec4 result = vec4(0.0);
    if (all(lessThan(texelPos, uval_mainImageSizeI))) {
        vec4 weightData = transient_exposureWeights_fetch(texelPos);
        float weight = weightData.x * weightData.y;
        vec3 color = texelFetch(colortex0, texelPos, 0).rgb;
        result = vec4(color * weight, weight);
    }
    return result;
}
vec4 spd_loadOutput(ivec2 texelPos, uint level, uint slice) {
    vec4 result = vec4(0.0);
    if (all(lessThan(texelPos, shared_mipTile6))) {
        result = uintBitsToFloat(transient_mainMipTemp_load(texelPos));
    }
    return result;
}
void spd_storeOutput(ivec2 texelPos, uint level, uint slice, vec4 value) {
    if (level == 6u) {
        if (all(lessThan(texelPos, shared_mipTile6))) {
            transient_mainMipTemp_store(texelPos, floatBitsToUint(value));
        }
    }
    if (level == 12u) {
        vec3 finalColor = value.rgb * safeRcp(value.a);
        float luma = colors2_colorspaces_luma(COLORS2_OUTPUT_COLORSPACE, finalColor);
        global_aeData.screenAvgLum = vec4(finalColor, luma);
    }
}
uint spd_mipCount() {
    return 12u;
}
void spd_init() {
    if (gl_LocalInvocationIndex < 1u) {
        shared_mipTile6 = global_mipmapTileCeil[6u].zw;
    }
    barrier();
}