diff --git a/EffectCommon/EffectCommon.vcxproj b/EffectCommon/EffectCommon.vcxproj index 88b97e312..93609194f 100644 --- a/EffectCommon/EffectCommon.vcxproj +++ b/EffectCommon/EffectCommon.vcxproj @@ -1,4 +1,4 @@ - + diff --git a/EffectCommon/EffectCommon.vcxproj.filters b/EffectCommon/EffectCommon.vcxproj.filters index b007fd99d..dac07c98c 100644 --- a/EffectCommon/EffectCommon.vcxproj.filters +++ b/EffectCommon/EffectCommon.vcxproj.filters @@ -42,6 +42,9 @@ 着色器 + + 着色器 + diff --git a/EffectCommon/common.hlsli b/EffectCommon/common.hlsli index a873c54fd..2c9aa2712 100644 --- a/EffectCommon/common.hlsli +++ b/EffectCommon/common.hlsli @@ -98,9 +98,17 @@ static float2 maxCoord7; #define SampleInputCur(index) (SampleInput(index, Coord(index).xy)) #define SampleInputOff(index, pos) (SampleInput(index, Coord(index).xy + (pos) * Coord(index).zw)) -// ѭʹ +// LOD #define SampleInputLod(index, pos) (InputTexture##index.SampleLevel(InputSampler##index, (pos), 0)) +// Gather +#define GatherInputRed(index, pos) (InputTexture##index.GatherRed(InputSampler##index, (pos), 0)) +#define GatherInputGreen(index, pos) (InputTexture##index.GatherGreen(InputSampler##index, (pos), 0)) +#define GatherInputBlue(index, pos) (InputTexture##index.GatherBlue(InputSampler##index, (pos), 0)) + +// Load +#define LoadInput(index, pos) (InputTexture##index.Load(pos)) + #ifndef MAGPIE_NO_CHECK #define GetCheckedPos(index, pos) (clamp((pos), 0, maxCoord##index)) #define GetCheckedOffPos(index, pos) (GetCheckedPos(index, Coord(index).xy + (pos) * Coord(index).zw)) @@ -110,6 +118,8 @@ static float2 maxCoord7; #endif +#define MAGPIE_ENTRY(name) D2D_PS_ENTRY(name) + // Ҫ main Ŀͷ void InitMagpieSampleInput() { diff --git a/MODULE_Common/DllMain.cpp b/MODULE_Common/DllMain.cpp index 56102502e..b4c433d2f 100644 --- a/MODULE_Common/DllMain.cpp +++ b/MODULE_Common/DllMain.cpp @@ -7,6 +7,7 @@ #include "MitchellNetravaliScaleEffect.h" #include "PixelScaleEffect.h" #include "ContrastAdaptiveSharpenEffect.h" +#include "FSREffect.h" #pragma comment(lib, "dxguid.lib") @@ -357,6 +358,56 @@ API_DECLSPEC HRESULT CreateContrastAdaptiveSharpenEffect( return S_OK; } +API_DECLSPEC HRESULT CreateFSREffect( + ID2D1Factory1* d2dFactory, + ID2D1DeviceContext* d2dDC, + const nlohmann::json& props, + float fillScale, + std::pair& scale, + ComPtr& effect +) { + bool isRegistered; + HRESULT hr = EffectUtils::IsEffectRegistered(d2dFactory, CLSID_MAGPIE_FSR_EFFECT, isRegistered); + if (FAILED(hr)) { + return hr; + } + + if (!isRegistered) { + hr = FSREffect::Register(d2dFactory); + if (FAILED(hr)) { + return hr; + } + } + + ComPtr result; + hr = d2dDC->CreateEffect(CLSID_MAGPIE_FSR_EFFECT, &result); + if (FAILED(hr)) { + return hr; + } + + std::pair scaleResult(1.0f, 1.0f); + // scale 属性 + auto it = props.find("scale"); + if (it != props.end()) { + hr = EffectUtils::ReadScaleProp(*it, fillScale, scale, scaleResult); + if (FAILED(hr)) { + return hr; + } + + hr = result->SetValue( + FSREffect::PROP_SCALE, + D2D1_VECTOR_2F{ scaleResult.first, scaleResult.second } + ); + if (FAILED(hr)) { + return hr; + } + } + + effect = std::move(result); + scale.first *= scaleResult.first; + scale.second *= scaleResult.second; + return S_OK; +} API_DECLSPEC HRESULT CreateEffect( ID2D1Factory1* d2dFactory, @@ -380,7 +431,9 @@ API_DECLSPEC HRESULT CreateEffect( return CreateMitchellEffect(d2dFactory, d2dDC, props, fillScale, scale, effect); } else if (e == "pixelScale") { return CreatePixelScaleEffect(d2dFactory, d2dDC, props, effect, scale); - } else { + } else if (e == "FSR") { + return CreateFSREffect(d2dFactory, d2dDC, props, fillScale, scale, effect); + } else { return E_INVALIDARG; } } diff --git a/MODULE_Common/EffectDefines.h b/MODULE_Common/EffectDefines.h index 2b114622b..4e4ffb8e9 100644 --- a/MODULE_Common/EffectDefines.h +++ b/MODULE_Common/EffectDefines.h @@ -31,6 +31,13 @@ DEFINE_GUID(GUID_MAGPIE_PIXEL_SCALE_SHADER, DEFINE_GUID(GUID_MAGPIE_CONTRAST_ADAPTIVE_SHARPEN_SHADER, 0x3e7f23c3, 0x185f, 0x4ac6, 0xb6, 0xb8, 0xd5, 0x18, 0x7e, 0x69, 0xca, 0x4f); +// {6B5C18BA-B415-4EDC-9A1C-7D4876E94633} +DEFINE_GUID(GUID_MAGPIE_FFX_EASU_SHADER, + 0x6b5c18ba, 0xb415, 0x4edc, 0x9a, 0x1c, 0x7d, 0x48, 0x76, 0xe9, 0x46, 0x33); +// {16C7F163-CBCC-4764-8AF8-07FC113747FA} +DEFINE_GUID(GUID_MAGPIE_FFX_RCAS_SHADER, + 0x16c7f163, 0xcbcc, 0x4764, 0x8a, 0xf8, 0x7, 0xfc, 0x11, 0x37, 0x47, 0xfa); + // {FF65D2D6-4359-429D-B30A-F3F65B5AF20D} @@ -58,6 +65,9 @@ DEFINE_GUID(CLSID_MAGPIE_LANCZOS_SCALE_EFFECT, DEFINE_GUID(CLSID_MAGPIE_PIXEL_SCALE_EFFECT, 0xed9318d, 0xd624, 0x4582, 0x9c, 0xe2, 0x39, 0x9b, 0x79, 0x42, 0x8a, 0xb4); +// {0C748324-87A8-4A9E-AF73-38309CF9CF2C} +DEFINE_GUID(CLSID_MAGPIE_FSR_EFFECT, + 0xc748324, 0x87a8, 0x4a9e, 0xaf, 0x73, 0x38, 0x30, 0x9c, 0xf9, 0xcf, 0x2c); constexpr auto MAGPIE_ADAPTIVE_SHARPEN_PASS1_SHADER = L"shaders/AdaptiveSharpenPass1Shader.cso"; @@ -68,3 +78,6 @@ constexpr auto MAGPIE_LANCZOS6_SCALE_SHADER = L"shaders/Lanczos6ScaleShader.cso" constexpr auto MAGPIE_JINC2_SCALE_SHADER = L"shaders/Jinc2ScaleShader.cso"; constexpr auto MAGPIE_MITCHELL_NETRAVALI_SCALE_SHADER = L"shaders/MitchellNetravaliScaleShader.cso"; constexpr auto MAGPIE_PIXEL_SCALE_SHADER = L"shaders/PixelScaleShader.cso"; + +constexpr auto MAGPIE_FFX_EASU_SHADER = L"shaders/FfxEasuShader.cso"; +constexpr auto MAGPIE_FFX_RCAS_SHADER = L"shaders/FfxRcasShader.cso"; diff --git a/MODULE_Common/FSREffect.h b/MODULE_Common/FSREffect.h new file mode 100644 index 000000000..55f9c04a2 --- /dev/null +++ b/MODULE_Common/FSREffect.h @@ -0,0 +1,109 @@ +#pragma once +#include "pch.h" +#include +#include "EffectDefines.h" +#include "FfxEasuTransform.h" +#include "FfxRcasTransform.h" + + +class FSREffect : public EffectBase { +public: + IFACEMETHODIMP Initialize( + _In_ ID2D1EffectContext* pEffectContext, + _In_ ID2D1TransformGraph* pTransformGraph + ) { + HRESULT hr = FfxEasuTransform::Create(pEffectContext, &_easuTransform); + if (FAILED(hr)) { + return hr; + } + hr = FfxRcasTransform::Create(pEffectContext, &_rcasTransform); + if (FAILED(hr)) { + return hr; + } + + hr = pTransformGraph->AddNode(_easuTransform.Get()); + if (FAILED(hr)) { + return hr; + } + hr = pTransformGraph->AddNode(_rcasTransform.Get()); + if (FAILED(hr)) { + return hr; + } + + hr = pTransformGraph->ConnectToEffectInput(0, _easuTransform.Get(), 0); + if (FAILED(hr)) { + return hr; + } + hr = pTransformGraph->ConnectNode(_easuTransform.Get(), _rcasTransform.Get(), 0); + if (FAILED(hr)) { + return hr; + } + hr = pTransformGraph->SetOutputNode(_rcasTransform.Get()); + if (FAILED(hr)) { + return hr; + } + + return S_OK; + } + + HRESULT SetScale(D2D_VECTOR_2F value) { + if (value.x <= 0 || value.y <= 0) { + return E_INVALIDARG; + } + + _easuTransform->SetScale(value); + return S_OK; + } + + D2D_VECTOR_2F GetScale() const { + return _easuTransform->GetScale(); + } + + enum PROPS { + PROP_SCALE = 0, + }; + + static HRESULT Register(_In_ ID2D1Factory1* pFactory) { + const D2D1_PROPERTY_BINDING bindings[] = + { + D2D1_VALUE_TYPE_BINDING(L"Scale", &SetScale, &GetScale) + }; + + HRESULT hr = pFactory->RegisterEffectFromString(CLSID_MAGPIE_FSR_EFFECT, XML( + + + + + + + + + + + + + + + + + ), bindings, ARRAYSIZE(bindings), CreateEffect); + + return hr; + } + + static HRESULT CALLBACK CreateEffect(_Outptr_ IUnknown** ppEffectImpl) { + *ppEffectImpl = static_cast(new FSREffect()); + + if (*ppEffectImpl == nullptr) { + return E_OUTOFMEMORY; + } + + return S_OK; + } + +private: + FSREffect() {} + + ComPtr _easuTransform = nullptr; + ComPtr _rcasTransform = nullptr; +}; diff --git a/MODULE_Common/FfxEasuShader.hlsl b/MODULE_Common/FfxEasuShader.hlsl new file mode 100644 index 000000000..8ca096b67 --- /dev/null +++ b/MODULE_Common/FfxEasuShader.hlsl @@ -0,0 +1,45 @@ +cbuffer constants : register(b0) { + int2 srcSize : packoffset(c0.x); + int2 destSize : packoffset(c0.z); +}; + +#define MAGPIE_INPUT_COUNT 1 +#include "common.hlsli" + + +#define A_GPU 1 +#define A_HLSL 1 +#include "ffx_a.hlsli" +#define FSR_EASU_F 1 + +AF4 FsrEasuRF(AF2 p) { + return GatherInputRed(0, p * srcSize * Coord(0).zw); +} +AF4 FsrEasuGF(AF2 p) { + return GatherInputGreen(0, p * srcSize * Coord(0).zw); +} +AF4 FsrEasuBF(AF2 p) { + return GatherInputBlue(0, p * srcSize * Coord(0).zw); +} + + +#include "ffx_fsr1.hlsli" + + +MAGPIE_ENTRY(main) { + float2 rcpSrc = rcp(srcSize); + float2 rcpDest = rcp(destSize); + float2 scale = srcSize * rcpDest; + + float3 c; + FsrEasuF( + c, + Coord(0).xy / Coord(0).zw, + asuint(float4(scale, 0.5 * scale - 0.5)), + asuint(float4(rcpSrc.xy, rcpSrc.x, -rcpSrc.y)), + asuint(float4(-rcpSrc.x, 2 * rcpSrc.y, rcpSrc.x, 2 * rcpSrc.y)), + asuint(float4(0, 4 * rcpSrc.y, 0, 0)) + ); + + return float4(c, 1.0f); +} \ No newline at end of file diff --git a/MODULE_Common/FfxEasuTransform.h b/MODULE_Common/FfxEasuTransform.h new file mode 100644 index 000000000..38adbb193 --- /dev/null +++ b/MODULE_Common/FfxEasuTransform.h @@ -0,0 +1,41 @@ +#pragma once +#include "pch.h" +#include +#include "EffectDefines.h" + + +class FfxEasuTransform : public SimpleScaleTransform { +private: + FfxEasuTransform() : SimpleScaleTransform(GUID_MAGPIE_FFX_EASU_SHADER) {} +public: + static HRESULT Create(_In_ ID2D1EffectContext* d2dEC, _Outptr_ FfxEasuTransform** ppOutput) { + if (!ppOutput) { + return E_INVALIDARG; + } + + HRESULT hr = LoadShader(d2dEC, MAGPIE_FFX_EASU_SHADER, GUID_MAGPIE_FFX_EASU_SHADER); + if (FAILED(hr)) { + return hr; + } + + *ppOutput = new FfxEasuTransform(); + return hr; + } + +protected: + void _SetShaderContantBuffer(const SIZE& srcSize, const SIZE& destSize) override { + struct { + INT32 srcWidth; + INT32 srcHeight; + INT32 destWidth; + INT32 destHeight; + } shaderConstants{ + srcSize.cx, + srcSize.cy, + destSize.cx, + destSize.cy + }; + + _drawInfo->SetPixelShaderConstantBuffer((BYTE*)&shaderConstants, sizeof(shaderConstants)); + } +}; diff --git a/MODULE_Common/FfxRcasShader.hlsl b/MODULE_Common/FfxRcasShader.hlsl new file mode 100644 index 000000000..ae526019b --- /dev/null +++ b/MODULE_Common/FfxRcasShader.hlsl @@ -0,0 +1,31 @@ +cbuffer constants : register(b0) { + uint2 srcSize : packoffset(c0.x); + float sharpness : packoffset(c0.z); +}; + +#define MAGPIE_INPUT_COUNT 1 +#define MAGPIE_NO_CHECK +#include "common.hlsli" + + +#define A_GPU +#define A_HLSL +#include "ffx_a.hlsli" +#define FSR_RCAS_F + +AF4 FsrRcasLoadF(ASU2 p) { return LoadInput(0, int3(ASU2(p), 0)); } +void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {} + + +#include "ffx_fsr1.hlsli" + + +MAGPIE_ENTRY(main) { + float s = AExp2F1(-sharpness); + varAF2(hSharp) = initAF2(s, s); + + float3 c; + FsrRcasF(c.r, c.g, c.b, Coord(0).xy / Coord(0).zw, float4(AU1_AF1(s), AU1_AH2_AF2(hSharp), 0, 0)); + + return float4(c, 1.0f); +} \ No newline at end of file diff --git a/MODULE_Common/FfxRcasTransform.h b/MODULE_Common/FfxRcasTransform.h new file mode 100644 index 000000000..d5de54a28 --- /dev/null +++ b/MODULE_Common/FfxRcasTransform.h @@ -0,0 +1,54 @@ +#pragma once +#include "pch.h" +#include +#include "EffectDefines.h" + + + +class FfxRcasTransform : public SimpleDrawTransform<1> { +private: + FfxRcasTransform() : SimpleDrawTransform<1>(GUID_MAGPIE_FFX_RCAS_SHADER) {} +public: + static HRESULT Create(_In_ ID2D1EffectContext* d2dEC, _Outptr_ FfxRcasTransform** ppOutput) { + *ppOutput = nullptr; + + HRESULT hr = LoadShader( + d2dEC, + MAGPIE_FFX_RCAS_SHADER, + GUID_MAGPIE_FFX_RCAS_SHADER + ); + if (FAILED(hr)) { + return hr; + } + + *ppOutput = new FfxRcasTransform(); + + return S_OK; + } + + void SetSharpness(float value) { + assert(value >= 0); + _sharpness = value; + } + + float GetSharpness() { + return _sharpness; + } +protected: + void _SetShaderContantBuffer(const SIZE& srcSize) override { + struct { + UINT32 srcWidth; + UINT32 srcHeight; + FLOAT sharpness; + } shaderConstants{ + (UINT32)srcSize.cx, + (UINT32)srcSize.cy, + _sharpness + }; + + _drawInfo->SetPixelShaderConstantBuffer((BYTE*)&shaderConstants, sizeof(shaderConstants)); + } + +private: + float _sharpness = 0.0f; +}; diff --git a/MODULE_Common/MODULE_Common.vcxproj b/MODULE_Common/MODULE_Common.vcxproj index aab215145..2bbfec01b 100644 --- a/MODULE_Common/MODULE_Common.vcxproj +++ b/MODULE_Common/MODULE_Common.vcxproj @@ -1,4 +1,4 @@ - + @@ -193,6 +193,9 @@ + + + @@ -214,6 +217,8 @@ + + @@ -225,6 +230,18 @@ Pixel Pixel + + Pixel + Pixel + Pixel + Pixel + + + Pixel + Pixel + Pixel + Pixel + diff --git a/MODULE_Common/MODULE_Common.vcxproj.filters b/MODULE_Common/MODULE_Common.vcxproj.filters index a4cdd0a70..63ee63401 100644 --- a/MODULE_Common/MODULE_Common.vcxproj.filters +++ b/MODULE_Common/MODULE_Common.vcxproj.filters @@ -57,6 +57,15 @@ 头文件 + + 头文件 + + + 头文件 + + + 头文件 + @@ -88,11 +97,23 @@ 着色器 + + 着色器 + + + 着色器 + 着色器 + + 着色器 + + + 着色器 + \ No newline at end of file diff --git a/MODULE_Common/ffx_a.hlsli b/MODULE_Common/ffx_a.hlsli new file mode 100644 index 000000000..482e93a96 --- /dev/null +++ b/MODULE_Common/ffx_a.hlsli @@ -0,0 +1,1506 @@ +//============================================================================================================================== +// +// [A] SHADER PORTABILITY 1.20210629 +// +//============================================================================================================================== +// FidelityFX Super Resolution Sample +// +// Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +// 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. +//------------------------------------------------------------------------------------------------------------------------------ +// MIT LICENSE +// =========== +// Copyright (c) 2014 Michal Drobot (for concepts used in "FLOAT APPROXIMATIONS"). +// ----------- +// 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. +//------------------------------------------------------------------------------------------------------------------------------ +// ABOUT +// ===== +// Common central point for high-level shading language and C portability for various shader headers. +//------------------------------------------------------------------------------------------------------------------------------ +// DEFINES +// ======= +// A_CPU ..... Include the CPU related code. +// A_GPU ..... Include the GPU related code. +// A_GLSL .... Using GLSL. +// A_HLSL .... Using HLSL. +// A_HLSL_6_2 Using HLSL 6.2 with new 'uint16_t' and related types (requires '-enable-16bit-types'). +// A_NO_16_BIT_CAST Don't use instructions that are not availabe in SPIR-V (needed for running A_HLSL_6_2 on Vulkan) +// A_GCC ..... Using a GCC compatible compiler (else assume MSVC compatible compiler by default). +// ======= +// A_BYTE .... Support 8-bit integer. +// A_HALF .... Support 16-bit integer and floating point. +// A_LONG .... Support 64-bit integer. +// A_DUBL .... Support 64-bit floating point. +// ======= +// A_WAVE .... Support wave-wide operations. +//------------------------------------------------------------------------------------------------------------------------------ +// To get #include "ffx_a.h" working in GLSL use '#extension GL_GOOGLE_include_directive:require'. +//------------------------------------------------------------------------------------------------------------------------------ +// SIMPLIFIED TYPE SYSTEM +// ====================== +// - All ints will be unsigned with exception of when signed is required. +// - Type naming simplified and shortened "A<#components>", +// - H = 16-bit float (half) +// - F = 32-bit float (float) +// - D = 64-bit float (double) +// - P = 1-bit integer (predicate, not using bool because 'B' is used for byte) +// - B = 8-bit integer (byte) +// - W = 16-bit integer (word) +// - U = 32-bit integer (unsigned) +// - L = 64-bit integer (long) +// - Using "AS<#components>" for signed when required. +//------------------------------------------------------------------------------------------------------------------------------ +// TODO +// ==== +// - Make sure 'ALerp*(a,b,m)' does 'b*m+(-a*m+a)' (2 ops). +//------------------------------------------------------------------------------------------------------------------------------ +// CHANGE LOG +// ========== +// 20200914 - Expanded wave ops and prx code. +// 20200713 - Added [ZOL] section, fixed serious bugs in sRGB and Rec.709 color conversion code, etc. +//============================================================================================================================== +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// COMMON +//============================================================================================================================== +#define A_2PI 6.28318530718 + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// +// HLSL +// +// +//============================================================================================================================== +#if defined(A_HLSL) && defined(A_GPU) + +#define AP1 bool +#define AP2 bool2 +#define AP3 bool3 +#define AP4 bool4 +//------------------------------------------------------------------------------------------------------------------------------ +#define AF1 float +#define AF2 float2 +#define AF3 float3 +#define AF4 float4 +//------------------------------------------------------------------------------------------------------------------------------ +#define AU1 uint +#define AU2 uint2 +#define AU3 uint3 +#define AU4 uint4 +//------------------------------------------------------------------------------------------------------------------------------ +#define ASU1 int +#define ASU2 int2 +#define ASU3 int3 +#define ASU4 int4 + +//============================================================================================================================== +#define AF1_AU1(x) asfloat(AU1(x)) +#define AF2_AU2(x) asfloat(AU2(x)) +#define AF3_AU3(x) asfloat(AU3(x)) +#define AF4_AU4(x) asfloat(AU4(x)) +//------------------------------------------------------------------------------------------------------------------------------ +#define AU1_AF1(x) asuint(AF1(x)) +#define AU2_AF2(x) asuint(AF2(x)) +#define AU3_AF3(x) asuint(AF3(x)) +#define AU4_AF4(x) asuint(AF4(x)) +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AU1_AH1_AF1_x(AF1 a) { return f32tof16(a); } +#define AU1_AH1_AF1(a) AU1_AH1_AF1_x(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AU1_AH2_AF2_x(AF2 a) { return f32tof16(a.x) | (f32tof16(a.y) << 16); } +#define AU1_AH2_AF2(a) AU1_AH2_AF2_x(AF2(a)) +#define AU1_AB4Unorm_AF4(x) D3DCOLORtoUBYTE4(AF4(x)) +//------------------------------------------------------------------------------------------------------------------------------ +AF2 AF2_AH2_AU1_x(AU1 x) { return AF2(f16tof32(x & 0xFFFF), f16tof32(x >> 16)); } +#define AF2_AH2_AU1(x) AF2_AH2_AU1_x(AU1(x)) +//============================================================================================================================== +AF1 AF1_x(AF1 a) { return AF1(a); } +AF2 AF2_x(AF1 a) { return AF2(a, a); } +AF3 AF3_x(AF1 a) { return AF3(a, a, a); } +AF4 AF4_x(AF1 a) { return AF4(a, a, a, a); } +#define AF1_(a) AF1_x(AF1(a)) +#define AF2_(a) AF2_x(AF1(a)) +#define AF3_(a) AF3_x(AF1(a)) +#define AF4_(a) AF4_x(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AU1_x(AU1 a) { return AU1(a); } +AU2 AU2_x(AU1 a) { return AU2(a, a); } +AU3 AU3_x(AU1 a) { return AU3(a, a, a); } +AU4 AU4_x(AU1 a) { return AU4(a, a, a, a); } +#define AU1_(a) AU1_x(AU1(a)) +#define AU2_(a) AU2_x(AU1(a)) +#define AU3_(a) AU3_x(AU1(a)) +#define AU4_(a) AU4_x(AU1(a)) +//============================================================================================================================== +AU1 AAbsSU1(AU1 a) { return AU1(abs(ASU1(a))); } +AU2 AAbsSU2(AU2 a) { return AU2(abs(ASU2(a))); } +AU3 AAbsSU3(AU3 a) { return AU3(abs(ASU3(a))); } +AU4 AAbsSU4(AU4 a) { return AU4(abs(ASU4(a))); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 ABfe(AU1 src, AU1 off, AU1 bits) { AU1 mask = (1u << bits) - 1; return (src >> off) & mask; } +AU1 ABfi(AU1 src, AU1 ins, AU1 mask) { return (ins & mask) | (src & (~mask)); } +AU1 ABfiM(AU1 src, AU1 ins, AU1 bits) { AU1 mask = (1u << bits) - 1; return (ins & mask) | (src & (~mask)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AClampF1(AF1 x, AF1 n, AF1 m) { return max(n, min(x, m)); } +AF2 AClampF2(AF2 x, AF2 n, AF2 m) { return max(n, min(x, m)); } +AF3 AClampF3(AF3 x, AF3 n, AF3 m) { return max(n, min(x, m)); } +AF4 AClampF4(AF4 x, AF4 n, AF4 m) { return max(n, min(x, m)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AFractF1(AF1 x) { return x - floor(x); } +AF2 AFractF2(AF2 x) { return x - floor(x); } +AF3 AFractF3(AF3 x) { return x - floor(x); } +AF4 AFractF4(AF4 x) { return x - floor(x); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ALerpF1(AF1 x, AF1 y, AF1 a) { return lerp(x, y, a); } +AF2 ALerpF2(AF2 x, AF2 y, AF2 a) { return lerp(x, y, a); } +AF3 ALerpF3(AF3 x, AF3 y, AF3 a) { return lerp(x, y, a); } +AF4 ALerpF4(AF4 x, AF4 y, AF4 a) { return lerp(x, y, a); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AMax3F1(AF1 x, AF1 y, AF1 z) { return max(x, max(y, z)); } +AF2 AMax3F2(AF2 x, AF2 y, AF2 z) { return max(x, max(y, z)); } +AF3 AMax3F3(AF3 x, AF3 y, AF3 z) { return max(x, max(y, z)); } +AF4 AMax3F4(AF4 x, AF4 y, AF4 z) { return max(x, max(y, z)); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMax3SU1(AU1 x, AU1 y, AU1 z) { return AU1(max(ASU1(x), max(ASU1(y), ASU1(z)))); } +AU2 AMax3SU2(AU2 x, AU2 y, AU2 z) { return AU2(max(ASU2(x), max(ASU2(y), ASU2(z)))); } +AU3 AMax3SU3(AU3 x, AU3 y, AU3 z) { return AU3(max(ASU3(x), max(ASU3(y), ASU3(z)))); } +AU4 AMax3SU4(AU4 x, AU4 y, AU4 z) { return AU4(max(ASU4(x), max(ASU4(y), ASU4(z)))); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMax3U1(AU1 x, AU1 y, AU1 z) { return max(x, max(y, z)); } +AU2 AMax3U2(AU2 x, AU2 y, AU2 z) { return max(x, max(y, z)); } +AU3 AMax3U3(AU3 x, AU3 y, AU3 z) { return max(x, max(y, z)); } +AU4 AMax3U4(AU4 x, AU4 y, AU4 z) { return max(x, max(y, z)); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMaxSU1(AU1 a, AU1 b) { return AU1(max(ASU1(a), ASU1(b))); } +AU2 AMaxSU2(AU2 a, AU2 b) { return AU2(max(ASU2(a), ASU2(b))); } +AU3 AMaxSU3(AU3 a, AU3 b) { return AU3(max(ASU3(a), ASU3(b))); } +AU4 AMaxSU4(AU4 a, AU4 b) { return AU4(max(ASU4(a), ASU4(b))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AMed3F1(AF1 x, AF1 y, AF1 z) { return max(min(x, y), min(max(x, y), z)); } +AF2 AMed3F2(AF2 x, AF2 y, AF2 z) { return max(min(x, y), min(max(x, y), z)); } +AF3 AMed3F3(AF3 x, AF3 y, AF3 z) { return max(min(x, y), min(max(x, y), z)); } +AF4 AMed3F4(AF4 x, AF4 y, AF4 z) { return max(min(x, y), min(max(x, y), z)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AMin3F1(AF1 x, AF1 y, AF1 z) { return min(x, min(y, z)); } +AF2 AMin3F2(AF2 x, AF2 y, AF2 z) { return min(x, min(y, z)); } +AF3 AMin3F3(AF3 x, AF3 y, AF3 z) { return min(x, min(y, z)); } +AF4 AMin3F4(AF4 x, AF4 y, AF4 z) { return min(x, min(y, z)); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMin3SU1(AU1 x, AU1 y, AU1 z) { return AU1(min(ASU1(x), min(ASU1(y), ASU1(z)))); } +AU2 AMin3SU2(AU2 x, AU2 y, AU2 z) { return AU2(min(ASU2(x), min(ASU2(y), ASU2(z)))); } +AU3 AMin3SU3(AU3 x, AU3 y, AU3 z) { return AU3(min(ASU3(x), min(ASU3(y), ASU3(z)))); } +AU4 AMin3SU4(AU4 x, AU4 y, AU4 z) { return AU4(min(ASU4(x), min(ASU4(y), ASU4(z)))); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMin3U1(AU1 x, AU1 y, AU1 z) { return min(x, min(y, z)); } +AU2 AMin3U2(AU2 x, AU2 y, AU2 z) { return min(x, min(y, z)); } +AU3 AMin3U3(AU3 x, AU3 y, AU3 z) { return min(x, min(y, z)); } +AU4 AMin3U4(AU4 x, AU4 y, AU4 z) { return min(x, min(y, z)); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AMinSU1(AU1 a, AU1 b) { return AU1(min(ASU1(a), ASU1(b))); } +AU2 AMinSU2(AU2 a, AU2 b) { return AU2(min(ASU2(a), ASU2(b))); } +AU3 AMinSU3(AU3 a, AU3 b) { return AU3(min(ASU3(a), ASU3(b))); } +AU4 AMinSU4(AU4 a, AU4 b) { return AU4(min(ASU4(a), ASU4(b))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ANCosF1(AF1 x) { return cos(x * AF1_(A_2PI)); } +AF2 ANCosF2(AF2 x) { return cos(x * AF2_(A_2PI)); } +AF3 ANCosF3(AF3 x) { return cos(x * AF3_(A_2PI)); } +AF4 ANCosF4(AF4 x) { return cos(x * AF4_(A_2PI)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ANSinF1(AF1 x) { return sin(x * AF1_(A_2PI)); } +AF2 ANSinF2(AF2 x) { return sin(x * AF2_(A_2PI)); } +AF3 ANSinF3(AF3 x) { return sin(x * AF3_(A_2PI)); } +AF4 ANSinF4(AF4 x) { return sin(x * AF4_(A_2PI)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ARcpF1(AF1 x) { return rcp(x); } +AF2 ARcpF2(AF2 x) { return rcp(x); } +AF3 ARcpF3(AF3 x) { return rcp(x); } +AF4 ARcpF4(AF4 x) { return rcp(x); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ARsqF1(AF1 x) { return rsqrt(x); } +AF2 ARsqF2(AF2 x) { return rsqrt(x); } +AF3 ARsqF3(AF3 x) { return rsqrt(x); } +AF4 ARsqF4(AF4 x) { return rsqrt(x); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ASatF1(AF1 x) { return saturate(x); } +AF2 ASatF2(AF2 x) { return saturate(x); } +AF3 ASatF3(AF3 x) { return saturate(x); } +AF4 ASatF4(AF4 x) { return saturate(x); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AShrSU1(AU1 a, AU1 b) { return AU1(ASU1(a) >> ASU1(b)); } +AU2 AShrSU2(AU2 a, AU2 b) { return AU2(ASU2(a) >> ASU2(b)); } +AU3 AShrSU3(AU3 a, AU3 b) { return AU3(ASU3(a) >> ASU3(b)); } +AU4 AShrSU4(AU4 a, AU4 b) { return AU4(ASU4(a) >> ASU4(b)); } + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// +// GPU COMMON +// +// +//============================================================================================================================== +#ifdef A_GPU + // Negative and positive infinity. +#define A_INFP_F AF1_AU1(0x7f800000u) +#define A_INFN_F AF1_AU1(0xff800000u) +//------------------------------------------------------------------------------------------------------------------------------ + // Copy sign from 's' to positive 'd'. +AF1 ACpySgnF1(AF1 d, AF1 s) { return AF1_AU1(AU1_AF1(d) | (AU1_AF1(s) & AU1_(0x80000000u))); } +AF2 ACpySgnF2(AF2 d, AF2 s) { return AF2_AU2(AU2_AF2(d) | (AU2_AF2(s) & AU2_(0x80000000u))); } +AF3 ACpySgnF3(AF3 d, AF3 s) { return AF3_AU3(AU3_AF3(d) | (AU3_AF3(s) & AU3_(0x80000000u))); } +AF4 ACpySgnF4(AF4 d, AF4 s) { return AF4_AU4(AU4_AF4(d) | (AU4_AF4(s) & AU4_(0x80000000u))); } +//------------------------------------------------------------------------------------------------------------------------------ + // Single operation to return (useful to create a mask to use in lerp for branch free logic), + // m=NaN := 0 + // m>=0 := 0 + // m<0 := 1 + // Uses the following useful floating point logic, + // saturate(+a*(-INF)==-INF) := 0 + // saturate( 0*(-INF)== NaN) := 0 + // saturate(-a*(-INF)==+INF) := 1 +AF1 ASignedF1(AF1 m) { return ASatF1(m * AF1_(A_INFN_F)); } +AF2 ASignedF2(AF2 m) { return ASatF2(m * AF2_(A_INFN_F)); } +AF3 ASignedF3(AF3 m) { return ASatF3(m * AF3_(A_INFN_F)); } +AF4 ASignedF4(AF4 m) { return ASatF4(m * AF4_(A_INFN_F)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AGtZeroF1(AF1 m) { return ASatF1(m * AF1_(A_INFP_F)); } +AF2 AGtZeroF2(AF2 m) { return ASatF2(m * AF2_(A_INFP_F)); } +AF3 AGtZeroF3(AF3 m) { return ASatF3(m * AF3_(A_INFP_F)); } +AF4 AGtZeroF4(AF4 m) { return ASatF4(m * AF4_(A_INFP_F)); } +//============================================================================================================================== +#ifdef A_HALF +#ifdef A_HLSL_6_2 +#define A_INFP_H AH1_AW1((uint16_t)0x7c00u) +#define A_INFN_H AH1_AW1((uint16_t)0xfc00u) +#else +#define A_INFP_H AH1_AW1(0x7c00u) +#define A_INFN_H AH1_AW1(0xfc00u) +#endif + +//------------------------------------------------------------------------------------------------------------------------------ +AH1 ACpySgnH1(AH1 d, AH1 s) { return AH1_AW1(AW1_AH1(d) | (AW1_AH1(s) & AW1_(0x8000u))); } +AH2 ACpySgnH2(AH2 d, AH2 s) { return AH2_AW2(AW2_AH2(d) | (AW2_AH2(s) & AW2_(0x8000u))); } +AH3 ACpySgnH3(AH3 d, AH3 s) { return AH3_AW3(AW3_AH3(d) | (AW3_AH3(s) & AW3_(0x8000u))); } +AH4 ACpySgnH4(AH4 d, AH4 s) { return AH4_AW4(AW4_AH4(d) | (AW4_AH4(s) & AW4_(0x8000u))); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 ASignedH1(AH1 m) { return ASatH1(m * AH1_(A_INFN_H)); } +AH2 ASignedH2(AH2 m) { return ASatH2(m * AH2_(A_INFN_H)); } +AH3 ASignedH3(AH3 m) { return ASatH3(m * AH3_(A_INFN_H)); } +AH4 ASignedH4(AH4 m) { return ASatH4(m * AH4_(A_INFN_H)); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AGtZeroH1(AH1 m) { return ASatH1(m * AH1_(A_INFP_H)); } +AH2 AGtZeroH2(AH2 m) { return ASatH2(m * AH2_(A_INFP_H)); } +AH3 AGtZeroH3(AH3 m) { return ASatH3(m * AH3_(A_INFP_H)); } +AH4 AGtZeroH4(AH4 m) { return ASatH4(m * AH4_(A_INFP_H)); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// [FIS] FLOAT INTEGER SORTABLE +//------------------------------------------------------------------------------------------------------------------------------ +// Float to integer sortable. +// - If sign bit=0, flip the sign bit (positives). +// - If sign bit=1, flip all bits (negatives). +// Integer sortable to float. +// - If sign bit=1, flip the sign bit (positives). +// - If sign bit=0, flip all bits (negatives). +// Has nice side effects. +// - Larger integers are more positive values. +// - Float zero is mapped to center of integers (so clear to integer zero is a nice default for atomic max usage). +// Burns 3 ops for conversion {shift,or,xor}. +//============================================================================================================================== +AU1 AFisToU1(AU1 x) { return x ^ ((AShrSU1(x, AU1_(31))) | AU1_(0x80000000)); } +AU1 AFisFromU1(AU1 x) { return x ^ ((~AShrSU1(x, AU1_(31))) | AU1_(0x80000000)); } +//------------------------------------------------------------------------------------------------------------------------------ + // Just adjust high 16-bit value (useful when upper part of 32-bit word is a 16-bit float value). +AU1 AFisToHiU1(AU1 x) { return x ^ ((AShrSU1(x, AU1_(15))) | AU1_(0x80000000)); } +AU1 AFisFromHiU1(AU1 x) { return x ^ ((~AShrSU1(x, AU1_(15))) | AU1_(0x80000000)); } +//------------------------------------------------------------------------------------------------------------------------------ +#ifdef A_HALF +AW1 AFisToW1(AW1 x) { return x ^ ((AShrSW1(x, AW1_(15))) | AW1_(0x8000)); } +AW1 AFisFromW1(AW1 x) { return x ^ ((~AShrSW1(x, AW1_(15))) | AW1_(0x8000)); } +//------------------------------------------------------------------------------------------------------------------------------ +AW2 AFisToW2(AW2 x) { return x ^ ((AShrSW2(x, AW2_(15))) | AW2_(0x8000)); } +AW2 AFisFromW2(AW2 x) { return x ^ ((~AShrSW2(x, AW2_(15))) | AW2_(0x8000)); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// [PERM] V_PERM_B32 +//------------------------------------------------------------------------------------------------------------------------------ +// Support for V_PERM_B32 started in the 3rd generation of GCN. +//------------------------------------------------------------------------------------------------------------------------------ +// yyyyxxxx - The 'i' input. +// 76543210 +// ======== +// HGFEDCBA - Naming on permutation. +//------------------------------------------------------------------------------------------------------------------------------ +// TODO +// ==== +// - Make sure compiler optimizes this. +//============================================================================================================================== +#ifdef A_HALF +AU1 APerm0E0A(AU2 i) { return((i.x) & 0xffu) | ((i.y << 16) & 0xff0000u); } +AU1 APerm0F0B(AU2 i) { return((i.x >> 8) & 0xffu) | ((i.y << 8) & 0xff0000u); } +AU1 APerm0G0C(AU2 i) { return((i.x >> 16) & 0xffu) | ((i.y) & 0xff0000u); } +AU1 APerm0H0D(AU2 i) { return((i.x >> 24) & 0xffu) | ((i.y >> 8) & 0xff0000u); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 APermHGFA(AU2 i) { return((i.x) & 0x000000ffu) | (i.y & 0xffffff00u); } +AU1 APermHGFC(AU2 i) { return((i.x >> 16) & 0x000000ffu) | (i.y & 0xffffff00u); } +AU1 APermHGAE(AU2 i) { return((i.x << 8) & 0x0000ff00u) | (i.y & 0xffff00ffu); } +AU1 APermHGCE(AU2 i) { return((i.x >> 8) & 0x0000ff00u) | (i.y & 0xffff00ffu); } +AU1 APermHAFE(AU2 i) { return((i.x << 16) & 0x00ff0000u) | (i.y & 0xff00ffffu); } +AU1 APermHCFE(AU2 i) { return((i.x) & 0x00ff0000u) | (i.y & 0xff00ffffu); } +AU1 APermAGFE(AU2 i) { return((i.x << 24) & 0xff000000u) | (i.y & 0x00ffffffu); } +AU1 APermCGFE(AU2 i) { return((i.x << 8) & 0xff000000u) | (i.y & 0x00ffffffu); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 APermGCEA(AU2 i) { return((i.x) & 0x00ff00ffu) | ((i.y << 8) & 0xff00ff00u); } +AU1 APermGECA(AU2 i) { return(((i.x) & 0xffu) | ((i.x >> 8) & 0xff00u) | ((i.y << 16) & 0xff0000u) | ((i.y << 8) & 0xff000000u)); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// [BUC] BYTE UNSIGNED CONVERSION +//------------------------------------------------------------------------------------------------------------------------------ +// Designed to use the optimal conversion, enables the scaling to possibly be factored into other computation. +// Works on a range of {0 to A_BUC_<32,16>}, for <32-bit, and 16-bit> respectively. +//------------------------------------------------------------------------------------------------------------------------------ +// OPCODE NOTES +// ============ +// GCN does not do UNORM or SNORM for bytes in opcodes. +// - V_CVT_F32_UBYTE{0,1,2,3} - Unsigned byte to float. +// - V_CVT_PKACC_U8_F32 - Float to unsigned byte (does bit-field insert into 32-bit integer). +// V_PERM_B32 does byte packing with ability to zero fill bytes as well. +// - Can pull out byte values from two sources, and zero fill upper 8-bits of packed hi and lo. +//------------------------------------------------------------------------------------------------------------------------------ +// BYTE : FLOAT - ABuc{0,1,2,3}{To,From}U1() - Designed for V_CVT_F32_UBYTE* and V_CVT_PKACCUM_U8_F32 ops. +// ==== ===== +// 0 : 0 +// 1 : 1 +// ... +// 255 : 255 +// : 256 (just outside the encoding range) +//------------------------------------------------------------------------------------------------------------------------------ +// BYTE : FLOAT - ABuc{0,1,2,3}{To,From}U2() - Designed for 16-bit denormal tricks and V_PERM_B32. +// ==== ===== +// 0 : 0 +// 1 : 1/512 +// 2 : 1/256 +// ... +// 64 : 1/8 +// 128 : 1/4 +// 255 : 255/512 +// : 1/2 (just outside the encoding range) +//------------------------------------------------------------------------------------------------------------------------------ +// OPTIMAL IMPLEMENTATIONS ON AMD ARCHITECTURES +// ============================================ +// r=ABuc0FromU1(i) +// V_CVT_F32_UBYTE0 r,i +// -------------------------------------------- +// r=ABuc0ToU1(d,i) +// V_CVT_PKACCUM_U8_F32 r,i,0,d +// -------------------------------------------- +// d=ABuc0FromU2(i) +// Where 'k0' is an SGPR with 0x0E0A +// Where 'k1' is an SGPR with {32768.0} packed into the lower 16-bits +// V_PERM_B32 d,i.x,i.y,k0 +// V_PK_FMA_F16 d,d,k1.x,0 +// -------------------------------------------- +// r=ABuc0ToU2(d,i) +// Where 'k0' is an SGPR with {1.0/32768.0} packed into the lower 16-bits +// Where 'k1' is an SGPR with 0x???? +// Where 'k2' is an SGPR with 0x???? +// V_PK_FMA_F16 i,i,k0.x,0 +// V_PERM_B32 r.x,i,i,k1 +// V_PERM_B32 r.y,i,i,k2 +//============================================================================================================================== + // Peak range for 32-bit and 16-bit operations. +#define A_BUC_32 (255.0) +#define A_BUC_16 (255.0/512.0) +//============================================================================================================================== +#if 1 + // Designed to be one V_CVT_PKACCUM_U8_F32. + // The extra min is required to pattern match to V_CVT_PKACCUM_U8_F32. +AU1 ABuc0ToU1(AU1 d, AF1 i) { return (d & 0xffffff00u) | ((min(AU1(i), 255u)) & (0x000000ffu)); } +AU1 ABuc1ToU1(AU1 d, AF1 i) { return (d & 0xffff00ffu) | ((min(AU1(i), 255u) << 8) & (0x0000ff00u)); } +AU1 ABuc2ToU1(AU1 d, AF1 i) { return (d & 0xff00ffffu) | ((min(AU1(i), 255u) << 16) & (0x00ff0000u)); } +AU1 ABuc3ToU1(AU1 d, AF1 i) { return (d & 0x00ffffffu) | ((min(AU1(i), 255u) << 24) & (0xff000000u)); } +//------------------------------------------------------------------------------------------------------------------------------ + // Designed to be one V_CVT_F32_UBYTE*. +AF1 ABuc0FromU1(AU1 i) { return AF1((i) & 255u); } +AF1 ABuc1FromU1(AU1 i) { return AF1((i >> 8) & 255u); } +AF1 ABuc2FromU1(AU1 i) { return AF1((i >> 16) & 255u); } +AF1 ABuc3FromU1(AU1 i) { return AF1((i >> 24) & 255u); } +#endif +//============================================================================================================================== +#ifdef A_HALF + // Takes {x0,x1} and {y0,y1} and builds {{x0,y0},{x1,y1}}. +AW2 ABuc01ToW2(AH2 x, AH2 y) { + x *= AH2_(1.0 / 32768.0); y *= AH2_(1.0 / 32768.0); + return AW2_AU1(APermGCEA(AU2(AU1_AW2(AW2_AH2(x)), AU1_AW2(AW2_AH2(y))))); +} +//------------------------------------------------------------------------------------------------------------------------------ + // Designed for 3 ops to do SOA to AOS and conversion. +AU2 ABuc0ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0))); + return AU2(APermHGFA(AU2(d.x, b)), APermHGFC(AU2(d.y, b))); +} +AU2 ABuc1ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0))); + return AU2(APermHGAE(AU2(d.x, b)), APermHGCE(AU2(d.y, b))); +} +AU2 ABuc2ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0))); + return AU2(APermHAFE(AU2(d.x, b)), APermHCFE(AU2(d.y, b))); +} +AU2 ABuc3ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0))); + return AU2(APermAGFE(AU2(d.x, b)), APermCGFE(AU2(d.y, b))); +} +//------------------------------------------------------------------------------------------------------------------------------ + // Designed for 2 ops to do both AOS to SOA, and conversion. +AH2 ABuc0FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0E0A(i))) * AH2_(32768.0); } +AH2 ABuc1FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0F0B(i))) * AH2_(32768.0); } +AH2 ABuc2FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0G0C(i))) * AH2_(32768.0); } +AH2 ABuc3FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0H0D(i))) * AH2_(32768.0); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// [BSC] BYTE SIGNED CONVERSION +//------------------------------------------------------------------------------------------------------------------------------ +// Similar to [BUC]. +// Works on a range of {-/+ A_BSC_<32,16>}, for <32-bit, and 16-bit> respectively. +//------------------------------------------------------------------------------------------------------------------------------ +// ENCODING (without zero-based encoding) +// ======== +// 0 = unused (can be used to mean something else) +// 1 = lowest value +// 128 = exact zero center (zero based encoding +// 255 = highest value +//------------------------------------------------------------------------------------------------------------------------------ +// Zero-based [Zb] flips the MSB bit of the byte (making 128 "exact zero" actually zero). +// This is useful if there is a desire for cleared values to decode as zero. +//------------------------------------------------------------------------------------------------------------------------------ +// BYTE : FLOAT - ABsc{0,1,2,3}{To,From}U2() - Designed for 16-bit denormal tricks and V_PERM_B32. +// ==== ===== +// 0 : -127/512 (unused) +// 1 : -126/512 +// 2 : -125/512 +// ... +// 128 : 0 +// ... +// 255 : 127/512 +// : 1/4 (just outside the encoding range) +//============================================================================================================================== + // Peak range for 32-bit and 16-bit operations. +#define A_BSC_32 (127.0) +#define A_BSC_16 (127.0/512.0) +//============================================================================================================================== +#if 1 +AU1 ABsc0ToU1(AU1 d, AF1 i) { return (d & 0xffffff00u) | ((min(AU1(i + 128.0), 255u)) & (0x000000ffu)); } +AU1 ABsc1ToU1(AU1 d, AF1 i) { return (d & 0xffff00ffu) | ((min(AU1(i + 128.0), 255u) << 8) & (0x0000ff00u)); } +AU1 ABsc2ToU1(AU1 d, AF1 i) { return (d & 0xff00ffffu) | ((min(AU1(i + 128.0), 255u) << 16) & (0x00ff0000u)); } +AU1 ABsc3ToU1(AU1 d, AF1 i) { return (d & 0x00ffffffu) | ((min(AU1(i + 128.0), 255u) << 24) & (0xff000000u)); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 ABsc0ToZbU1(AU1 d, AF1 i) { return ((d & 0xffffff00u) | ((min(AU1(trunc(i) + 128.0), 255u)) & (0x000000ffu))) ^ 0x00000080u; } +AU1 ABsc1ToZbU1(AU1 d, AF1 i) { return ((d & 0xffff00ffu) | ((min(AU1(trunc(i) + 128.0), 255u) << 8) & (0x0000ff00u))) ^ 0x00008000u; } +AU1 ABsc2ToZbU1(AU1 d, AF1 i) { return ((d & 0xff00ffffu) | ((min(AU1(trunc(i) + 128.0), 255u) << 16) & (0x00ff0000u))) ^ 0x00800000u; } +AU1 ABsc3ToZbU1(AU1 d, AF1 i) { return ((d & 0x00ffffffu) | ((min(AU1(trunc(i) + 128.0), 255u) << 24) & (0xff000000u))) ^ 0x80000000u; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ABsc0FromU1(AU1 i) { return AF1((i) & 255u) - 128.0; } +AF1 ABsc1FromU1(AU1 i) { return AF1((i >> 8) & 255u) - 128.0; } +AF1 ABsc2FromU1(AU1 i) { return AF1((i >> 16) & 255u) - 128.0; } +AF1 ABsc3FromU1(AU1 i) { return AF1((i >> 24) & 255u) - 128.0; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ABsc0FromZbU1(AU1 i) { return AF1(((i) & 255u) ^ 0x80u) - 128.0; } +AF1 ABsc1FromZbU1(AU1 i) { return AF1(((i >> 8) & 255u) ^ 0x80u) - 128.0; } +AF1 ABsc2FromZbU1(AU1 i) { return AF1(((i >> 16) & 255u) ^ 0x80u) - 128.0; } +AF1 ABsc3FromZbU1(AU1 i) { return AF1(((i >> 24) & 255u) ^ 0x80u) - 128.0; } +#endif +//============================================================================================================================== +#ifdef A_HALF + // Takes {x0,x1} and {y0,y1} and builds {{x0,y0},{x1,y1}}. +AW2 ABsc01ToW2(AH2 x, AH2 y) { + x = x * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0); y = y * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0); + return AW2_AU1(APermGCEA(AU2(AU1_AW2(AW2_AH2(x)), AU1_AW2(AW2_AH2(y))))); +} +//------------------------------------------------------------------------------------------------------------------------------ +AU2 ABsc0ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))); + return AU2(APermHGFA(AU2(d.x, b)), APermHGFC(AU2(d.y, b))); +} +AU2 ABsc1ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))); + return AU2(APermHGAE(AU2(d.x, b)), APermHGCE(AU2(d.y, b))); +} +AU2 ABsc2ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))); + return AU2(APermHAFE(AU2(d.x, b)), APermHCFE(AU2(d.y, b))); +} +AU2 ABsc3ToU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))); + return AU2(APermAGFE(AU2(d.x, b)), APermCGFE(AU2(d.y, b))); +} +//------------------------------------------------------------------------------------------------------------------------------ +AU2 ABsc0ToZbU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))) ^ 0x00800080u; + return AU2(APermHGFA(AU2(d.x, b)), APermHGFC(AU2(d.y, b))); +} +AU2 ABsc1ToZbU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))) ^ 0x00800080u; + return AU2(APermHGAE(AU2(d.x, b)), APermHGCE(AU2(d.y, b))); +} +AU2 ABsc2ToZbU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))) ^ 0x00800080u; + return AU2(APermHAFE(AU2(d.x, b)), APermHCFE(AU2(d.y, b))); +} +AU2 ABsc3ToZbU2(AU2 d, AH2 i) { + AU1 b = AU1_AW2(AW2_AH2(i * AH2_(1.0 / 32768.0) + AH2_(0.25 / 32768.0))) ^ 0x00800080u; + return AU2(APermAGFE(AU2(d.x, b)), APermCGFE(AU2(d.y, b))); +} +//------------------------------------------------------------------------------------------------------------------------------ +AH2 ABsc0FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0E0A(i))) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc1FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0F0B(i))) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc2FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0G0C(i))) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc3FromU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0H0D(i))) * AH2_(32768.0) - AH2_(0.25); } +//------------------------------------------------------------------------------------------------------------------------------ +AH2 ABsc0FromZbU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0E0A(i) ^ 0x00800080u)) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc1FromZbU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0F0B(i) ^ 0x00800080u)) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc2FromZbU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0G0C(i) ^ 0x00800080u)) * AH2_(32768.0) - AH2_(0.25); } +AH2 ABsc3FromZbU2(AU2 i) { return AH2_AW2(AW2_AU1(APerm0H0D(i) ^ 0x00800080u)) * AH2_(32768.0) - AH2_(0.25); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// HALF APPROXIMATIONS +//------------------------------------------------------------------------------------------------------------------------------ +// These support only positive inputs. +// Did not see value yet in specialization for range. +// Using quick testing, ended up mostly getting the same "best" approximation for various ranges. +// With hardware that can co-execute transcendentals, the value in approximations could be less than expected. +// However from a latency perspective, if execution of a transcendental is 4 clk, with no packed support, -> 8 clk total. +// And co-execution would require a compiler interleaving a lot of independent work for packed usage. +//------------------------------------------------------------------------------------------------------------------------------ +// The one Newton Raphson iteration form of rsq() was skipped (requires 6 ops total). +// Same with sqrt(), as this could be x*rsq() (7 ops). +//============================================================================================================================== +#ifdef A_HALF + // Minimize squared error across full positive range, 2 ops. + // The 0x1de2 based approximation maps {0 to 1} input maps to < 1 output. +AH1 APrxLoSqrtH1(AH1 a) { return AH1_AW1((AW1_AH1(a) >> AW1_(1)) + AW1_(0x1de2)); } +AH2 APrxLoSqrtH2(AH2 a) { return AH2_AW2((AW2_AH2(a) >> AW2_(1)) + AW2_(0x1de2)); } +AH3 APrxLoSqrtH3(AH3 a) { return AH3_AW3((AW3_AH3(a) >> AW3_(1)) + AW3_(0x1de2)); } +AH4 APrxLoSqrtH4(AH4 a) { return AH4_AW4((AW4_AH4(a) >> AW4_(1)) + AW4_(0x1de2)); } +//------------------------------------------------------------------------------------------------------------------------------ + // Lower precision estimation, 1 op. + // Minimize squared error across {smallest normal to 16384.0}. +AH1 APrxLoRcpH1(AH1 a) { return AH1_AW1(AW1_(0x7784) - AW1_AH1(a)); } +AH2 APrxLoRcpH2(AH2 a) { return AH2_AW2(AW2_(0x7784) - AW2_AH2(a)); } +AH3 APrxLoRcpH3(AH3 a) { return AH3_AW3(AW3_(0x7784) - AW3_AH3(a)); } +AH4 APrxLoRcpH4(AH4 a) { return AH4_AW4(AW4_(0x7784) - AW4_AH4(a)); } +//------------------------------------------------------------------------------------------------------------------------------ + // Medium precision estimation, one Newton Raphson iteration, 3 ops. +AH1 APrxMedRcpH1(AH1 a) { AH1 b = AH1_AW1(AW1_(0x778d) - AW1_AH1(a)); return b * (-b * a + AH1_(2.0)); } +AH2 APrxMedRcpH2(AH2 a) { AH2 b = AH2_AW2(AW2_(0x778d) - AW2_AH2(a)); return b * (-b * a + AH2_(2.0)); } +AH3 APrxMedRcpH3(AH3 a) { AH3 b = AH3_AW3(AW3_(0x778d) - AW3_AH3(a)); return b * (-b * a + AH3_(2.0)); } +AH4 APrxMedRcpH4(AH4 a) { AH4 b = AH4_AW4(AW4_(0x778d) - AW4_AH4(a)); return b * (-b * a + AH4_(2.0)); } +//------------------------------------------------------------------------------------------------------------------------------ + // Minimize squared error across {smallest normal to 16384.0}, 2 ops. +AH1 APrxLoRsqH1(AH1 a) { return AH1_AW1(AW1_(0x59a3) - (AW1_AH1(a) >> AW1_(1))); } +AH2 APrxLoRsqH2(AH2 a) { return AH2_AW2(AW2_(0x59a3) - (AW2_AH2(a) >> AW2_(1))); } +AH3 APrxLoRsqH3(AH3 a) { return AH3_AW3(AW3_(0x59a3) - (AW3_AH3(a) >> AW3_(1))); } +AH4 APrxLoRsqH4(AH4 a) { return AH4_AW4(AW4_(0x59a3) - (AW4_AH4(a) >> AW4_(1))); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// FLOAT APPROXIMATIONS +//------------------------------------------------------------------------------------------------------------------------------ +// Michal Drobot has an excellent presentation on these: "Low Level Optimizations For GCN", +// - Idea dates back to SGI, then to Quake 3, etc. +// - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf +// - sqrt(x)=rsqrt(x)*x +// - rcp(x)=rsqrt(x)*rsqrt(x) for positive x +// - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h +//------------------------------------------------------------------------------------------------------------------------------ +// These below are from perhaps less complete searching for optimal. +// Used FP16 normal range for testing with +4096 32-bit step size for sampling error. +// So these match up well with the half approximations. +//============================================================================================================================== +AF1 APrxLoSqrtF1(AF1 a) { return AF1_AU1((AU1_AF1(a) >> AU1_(1)) + AU1_(0x1fbc4639)); } +AF1 APrxLoRcpF1(AF1 a) { return AF1_AU1(AU1_(0x7ef07ebb) - AU1_AF1(a)); } +AF1 APrxMedRcpF1(AF1 a) { AF1 b = AF1_AU1(AU1_(0x7ef19fff) - AU1_AF1(a)); return b * (-b * a + AF1_(2.0)); } +AF1 APrxLoRsqF1(AF1 a) { return AF1_AU1(AU1_(0x5f347d74) - (AU1_AF1(a) >> AU1_(1))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 APrxLoSqrtF2(AF2 a) { return AF2_AU2((AU2_AF2(a) >> AU2_(1)) + AU2_(0x1fbc4639)); } +AF2 APrxLoRcpF2(AF2 a) { return AF2_AU2(AU2_(0x7ef07ebb) - AU2_AF2(a)); } +AF2 APrxMedRcpF2(AF2 a) { AF2 b = AF2_AU2(AU2_(0x7ef19fff) - AU2_AF2(a)); return b * (-b * a + AF2_(2.0)); } +AF2 APrxLoRsqF2(AF2 a) { return AF2_AU2(AU2_(0x5f347d74) - (AU2_AF2(a) >> AU2_(1))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF3 APrxLoSqrtF3(AF3 a) { return AF3_AU3((AU3_AF3(a) >> AU3_(1)) + AU3_(0x1fbc4639)); } +AF3 APrxLoRcpF3(AF3 a) { return AF3_AU3(AU3_(0x7ef07ebb) - AU3_AF3(a)); } +AF3 APrxMedRcpF3(AF3 a) { AF3 b = AF3_AU3(AU3_(0x7ef19fff) - AU3_AF3(a)); return b * (-b * a + AF3_(2.0)); } +AF3 APrxLoRsqF3(AF3 a) { return AF3_AU3(AU3_(0x5f347d74) - (AU3_AF3(a) >> AU3_(1))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF4 APrxLoSqrtF4(AF4 a) { return AF4_AU4((AU4_AF4(a) >> AU4_(1)) + AU4_(0x1fbc4639)); } +AF4 APrxLoRcpF4(AF4 a) { return AF4_AU4(AU4_(0x7ef07ebb) - AU4_AF4(a)); } +AF4 APrxMedRcpF4(AF4 a) { AF4 b = AF4_AU4(AU4_(0x7ef19fff) - AU4_AF4(a)); return b * (-b * a + AF4_(2.0)); } +AF4 APrxLoRsqF4(AF4 a) { return AF4_AU4(AU4_(0x5f347d74) - (AU4_AF4(a) >> AU4_(1))); } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// PQ APPROXIMATIONS +//------------------------------------------------------------------------------------------------------------------------------ +// PQ is very close to x^(1/8). The functions below Use the fast float approximation method to do +// PQ<~>Gamma2 (4th power and fast 4th root) and PQ<~>Linear (8th power and fast 8th root). Maximum error is ~0.2%. +//============================================================================================================================== +// Helpers +AF1 Quart(AF1 a) { a = a * a; return a * a; } +AF1 Oct(AF1 a) { a = a * a; a = a * a; return a * a; } +AF2 Quart(AF2 a) { a = a * a; return a * a; } +AF2 Oct(AF2 a) { a = a * a; a = a * a; return a * a; } +AF3 Quart(AF3 a) { a = a * a; return a * a; } +AF3 Oct(AF3 a) { a = a * a; a = a * a; return a * a; } +AF4 Quart(AF4 a) { a = a * a; return a * a; } +AF4 Oct(AF4 a) { a = a * a; a = a * a; return a * a; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 APrxPQToGamma2(AF1 a) { return Quart(a); } +AF1 APrxPQToLinear(AF1 a) { return Oct(a); } +AF1 APrxLoGamma2ToPQ(AF1 a) { return AF1_AU1((AU1_AF1(a) >> AU1_(2)) + AU1_(0x2F9A4E46)); } +AF1 APrxMedGamma2ToPQ(AF1 a) { AF1 b = AF1_AU1((AU1_AF1(a) >> AU1_(2)) + AU1_(0x2F9A4E46)); AF1 b4 = Quart(b); return b - b * (b4 - a) / (AF1_(4.0) * b4); } +AF1 APrxHighGamma2ToPQ(AF1 a) { return sqrt(sqrt(a)); } +AF1 APrxLoLinearToPQ(AF1 a) { return AF1_AU1((AU1_AF1(a) >> AU1_(3)) + AU1_(0x378D8723)); } +AF1 APrxMedLinearToPQ(AF1 a) { AF1 b = AF1_AU1((AU1_AF1(a) >> AU1_(3)) + AU1_(0x378D8723)); AF1 b8 = Oct(b); return b - b * (b8 - a) / (AF1_(8.0) * b8); } +AF1 APrxHighLinearToPQ(AF1 a) { return sqrt(sqrt(sqrt(a))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 APrxPQToGamma2(AF2 a) { return Quart(a); } +AF2 APrxPQToLinear(AF2 a) { return Oct(a); } +AF2 APrxLoGamma2ToPQ(AF2 a) { return AF2_AU2((AU2_AF2(a) >> AU2_(2)) + AU2_(0x2F9A4E46)); } +AF2 APrxMedGamma2ToPQ(AF2 a) { AF2 b = AF2_AU2((AU2_AF2(a) >> AU2_(2)) + AU2_(0x2F9A4E46)); AF2 b4 = Quart(b); return b - b * (b4 - a) / (AF1_(4.0) * b4); } +AF2 APrxHighGamma2ToPQ(AF2 a) { return sqrt(sqrt(a)); } +AF2 APrxLoLinearToPQ(AF2 a) { return AF2_AU2((AU2_AF2(a) >> AU2_(3)) + AU2_(0x378D8723)); } +AF2 APrxMedLinearToPQ(AF2 a) { AF2 b = AF2_AU2((AU2_AF2(a) >> AU2_(3)) + AU2_(0x378D8723)); AF2 b8 = Oct(b); return b - b * (b8 - a) / (AF1_(8.0) * b8); } +AF2 APrxHighLinearToPQ(AF2 a) { return sqrt(sqrt(sqrt(a))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF3 APrxPQToGamma2(AF3 a) { return Quart(a); } +AF3 APrxPQToLinear(AF3 a) { return Oct(a); } +AF3 APrxLoGamma2ToPQ(AF3 a) { return AF3_AU3((AU3_AF3(a) >> AU3_(2)) + AU3_(0x2F9A4E46)); } +AF3 APrxMedGamma2ToPQ(AF3 a) { AF3 b = AF3_AU3((AU3_AF3(a) >> AU3_(2)) + AU3_(0x2F9A4E46)); AF3 b4 = Quart(b); return b - b * (b4 - a) / (AF1_(4.0) * b4); } +AF3 APrxHighGamma2ToPQ(AF3 a) { return sqrt(sqrt(a)); } +AF3 APrxLoLinearToPQ(AF3 a) { return AF3_AU3((AU3_AF3(a) >> AU3_(3)) + AU3_(0x378D8723)); } +AF3 APrxMedLinearToPQ(AF3 a) { AF3 b = AF3_AU3((AU3_AF3(a) >> AU3_(3)) + AU3_(0x378D8723)); AF3 b8 = Oct(b); return b - b * (b8 - a) / (AF1_(8.0) * b8); } +AF3 APrxHighLinearToPQ(AF3 a) { return sqrt(sqrt(sqrt(a))); } +//------------------------------------------------------------------------------------------------------------------------------ +AF4 APrxPQToGamma2(AF4 a) { return Quart(a); } +AF4 APrxPQToLinear(AF4 a) { return Oct(a); } +AF4 APrxLoGamma2ToPQ(AF4 a) { return AF4_AU4((AU4_AF4(a) >> AU4_(2)) + AU4_(0x2F9A4E46)); } +AF4 APrxMedGamma2ToPQ(AF4 a) { AF4 b = AF4_AU4((AU4_AF4(a) >> AU4_(2)) + AU4_(0x2F9A4E46)); AF4 b4 = Quart(b); return b - b * (b4 - a) / (AF1_(4.0) * b4); } +AF4 APrxHighGamma2ToPQ(AF4 a) { return sqrt(sqrt(a)); } +AF4 APrxLoLinearToPQ(AF4 a) { return AF4_AU4((AU4_AF4(a) >> AU4_(3)) + AU4_(0x378D8723)); } +AF4 APrxMedLinearToPQ(AF4 a) { AF4 b = AF4_AU4((AU4_AF4(a) >> AU4_(3)) + AU4_(0x378D8723)); AF4 b8 = Oct(b); return b - b * (b8 - a) / (AF1_(8.0) * b8); } +AF4 APrxHighLinearToPQ(AF4 a) { return sqrt(sqrt(sqrt(a))); } +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// PARABOLIC SIN & COS +//------------------------------------------------------------------------------------------------------------------------------ +// Approximate answers to transcendental questions. +//------------------------------------------------------------------------------------------------------------------------------ +//============================================================================================================================== +#if 1 + // Valid input range is {-1 to 1} representing {0 to 2 pi}. + // Output range is {-1/4 to 1/4} representing {-1 to 1}. +AF1 APSinF1(AF1 x) { return x * abs(x) - x; } // MAD. +AF2 APSinF2(AF2 x) { return x * abs(x) - x; } +AF1 APCosF1(AF1 x) { x = AFractF1(x * AF1_(0.5) + AF1_(0.75)); x = x * AF1_(2.0) - AF1_(1.0); return APSinF1(x); } // 3x MAD, FRACT +AF2 APCosF2(AF2 x) { x = AFractF2(x * AF2_(0.5) + AF2_(0.75)); x = x * AF2_(2.0) - AF2_(1.0); return APSinF2(x); } +AF2 APSinCosF1(AF1 x) { AF1 y = AFractF1(x * AF1_(0.5) + AF1_(0.75)); y = y * AF1_(2.0) - AF1_(1.0); return APSinF2(AF2(x, y)); } +#endif +//------------------------------------------------------------------------------------------------------------------------------ +#ifdef A_HALF + // For a packed {sin,cos} pair, + // - Native takes 16 clocks and 4 issue slots (no packed transcendentals). + // - Parabolic takes 8 clocks and 8 issue slots (only fract is non-packed). +AH1 APSinH1(AH1 x) { return x * abs(x) - x; } +AH2 APSinH2(AH2 x) { return x * abs(x) - x; } // AND,FMA +AH1 APCosH1(AH1 x) { x = AFractH1(x * AH1_(0.5) + AH1_(0.75)); x = x * AH1_(2.0) - AH1_(1.0); return APSinH1(x); } +AH2 APCosH2(AH2 x) { x = AFractH2(x * AH2_(0.5) + AH2_(0.75)); x = x * AH2_(2.0) - AH2_(1.0); return APSinH2(x); } // 3x FMA, 2xFRACT, AND +AH2 APSinCosH1(AH1 x) { AH1 y = AFractH1(x * AH1_(0.5) + AH1_(0.75)); y = y * AH1_(2.0) - AH1_(1.0); return APSinH2(AH2(x, y)); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// [ZOL] ZERO ONE LOGIC +//------------------------------------------------------------------------------------------------------------------------------ +// Conditional free logic designed for easy 16-bit packing, and backwards porting to 32-bit. +//------------------------------------------------------------------------------------------------------------------------------ +// 0 := false +// 1 := true +//------------------------------------------------------------------------------------------------------------------------------ +// AndNot(x,y) -> !(x&y) .... One op. +// AndOr(x,y,z) -> (x&y)|z ... One op. +// GtZero(x) -> x>0.0 ..... One op. +// Sel(x,y,z) -> x?y:z ..... Two ops, has no precision loss. +// Signed(x) -> x<0.0 ..... One op. +// ZeroPass(x,y) -> x?0:y ..... Two ops, 'y' is a pass through safe for aliasing as integer. +//------------------------------------------------------------------------------------------------------------------------------ +// OPTIMIZATION NOTES +// ================== +// - On Vega to use 2 constants in a packed op, pass in as one AW2 or one AH2 'k.xy' and use as 'k.xx' and 'k.yy'. +// For example 'a.xy*k.xx+k.yy'. +//============================================================================================================================== +#if 1 +AU1 AZolAndU1(AU1 x, AU1 y) { return min(x, y); } +AU2 AZolAndU2(AU2 x, AU2 y) { return min(x, y); } +AU3 AZolAndU3(AU3 x, AU3 y) { return min(x, y); } +AU4 AZolAndU4(AU4 x, AU4 y) { return min(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AZolNotU1(AU1 x) { return x ^ AU1_(1); } +AU2 AZolNotU2(AU2 x) { return x ^ AU2_(1); } +AU3 AZolNotU3(AU3 x) { return x ^ AU3_(1); } +AU4 AZolNotU4(AU4 x) { return x ^ AU4_(1); } +//------------------------------------------------------------------------------------------------------------------------------ +AU1 AZolOrU1(AU1 x, AU1 y) { return max(x, y); } +AU2 AZolOrU2(AU2 x, AU2 y) { return max(x, y); } +AU3 AZolOrU3(AU3 x, AU3 y) { return max(x, y); } +AU4 AZolOrU4(AU4 x, AU4 y) { return max(x, y); } +//============================================================================================================================== +AU1 AZolF1ToU1(AF1 x) { return AU1(x); } +AU2 AZolF2ToU2(AF2 x) { return AU2(x); } +AU3 AZolF3ToU3(AF3 x) { return AU3(x); } +AU4 AZolF4ToU4(AF4 x) { return AU4(x); } +//------------------------------------------------------------------------------------------------------------------------------ + // 2 ops, denormals don't work in 32-bit on PC (and if they are enabled, OMOD is disabled). +AU1 AZolNotF1ToU1(AF1 x) { return AU1(AF1_(1.0) - x); } +AU2 AZolNotF2ToU2(AF2 x) { return AU2(AF2_(1.0) - x); } +AU3 AZolNotF3ToU3(AF3 x) { return AU3(AF3_(1.0) - x); } +AU4 AZolNotF4ToU4(AF4 x) { return AU4(AF4_(1.0) - x); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolU1ToF1(AU1 x) { return AF1(x); } +AF2 AZolU2ToF2(AU2 x) { return AF2(x); } +AF3 AZolU3ToF3(AU3 x) { return AF3(x); } +AF4 AZolU4ToF4(AU4 x) { return AF4(x); } +//============================================================================================================================== +AF1 AZolAndF1(AF1 x, AF1 y) { return min(x, y); } +AF2 AZolAndF2(AF2 x, AF2 y) { return min(x, y); } +AF3 AZolAndF3(AF3 x, AF3 y) { return min(x, y); } +AF4 AZolAndF4(AF4 x, AF4 y) { return min(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 ASolAndNotF1(AF1 x, AF1 y) { return (-x) * y + AF1_(1.0); } +AF2 ASolAndNotF2(AF2 x, AF2 y) { return (-x) * y + AF2_(1.0); } +AF3 ASolAndNotF3(AF3 x, AF3 y) { return (-x) * y + AF3_(1.0); } +AF4 ASolAndNotF4(AF4 x, AF4 y) { return (-x) * y + AF4_(1.0); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolAndOrF1(AF1 x, AF1 y, AF1 z) { return ASatF1(x * y + z); } +AF2 AZolAndOrF2(AF2 x, AF2 y, AF2 z) { return ASatF2(x * y + z); } +AF3 AZolAndOrF3(AF3 x, AF3 y, AF3 z) { return ASatF3(x * y + z); } +AF4 AZolAndOrF4(AF4 x, AF4 y, AF4 z) { return ASatF4(x * y + z); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolGtZeroF1(AF1 x) { return ASatF1(x * AF1_(A_INFP_F)); } +AF2 AZolGtZeroF2(AF2 x) { return ASatF2(x * AF2_(A_INFP_F)); } +AF3 AZolGtZeroF3(AF3 x) { return ASatF3(x * AF3_(A_INFP_F)); } +AF4 AZolGtZeroF4(AF4 x) { return ASatF4(x * AF4_(A_INFP_F)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolNotF1(AF1 x) { return AF1_(1.0) - x; } +AF2 AZolNotF2(AF2 x) { return AF2_(1.0) - x; } +AF3 AZolNotF3(AF3 x) { return AF3_(1.0) - x; } +AF4 AZolNotF4(AF4 x) { return AF4_(1.0) - x; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolOrF1(AF1 x, AF1 y) { return max(x, y); } +AF2 AZolOrF2(AF2 x, AF2 y) { return max(x, y); } +AF3 AZolOrF3(AF3 x, AF3 y) { return max(x, y); } +AF4 AZolOrF4(AF4 x, AF4 y) { return max(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolSelF1(AF1 x, AF1 y, AF1 z) { AF1 r = (-x) * z + z; return x * y + r; } +AF2 AZolSelF2(AF2 x, AF2 y, AF2 z) { AF2 r = (-x) * z + z; return x * y + r; } +AF3 AZolSelF3(AF3 x, AF3 y, AF3 z) { AF3 r = (-x) * z + z; return x * y + r; } +AF4 AZolSelF4(AF4 x, AF4 y, AF4 z) { AF4 r = (-x) * z + z; return x * y + r; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolSignedF1(AF1 x) { return ASatF1(x * AF1_(A_INFN_F)); } +AF2 AZolSignedF2(AF2 x) { return ASatF2(x * AF2_(A_INFN_F)); } +AF3 AZolSignedF3(AF3 x) { return ASatF3(x * AF3_(A_INFN_F)); } +AF4 AZolSignedF4(AF4 x) { return ASatF4(x * AF4_(A_INFN_F)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AZolZeroPassF1(AF1 x, AF1 y) { return AF1_AU1((AU1_AF1(x) != AU1_(0)) ? AU1_(0) : AU1_AF1(y)); } +AF2 AZolZeroPassF2(AF2 x, AF2 y) { return AF2_AU2((AU2_AF2(x) != AU2_(0)) ? AU2_(0) : AU2_AF2(y)); } +AF3 AZolZeroPassF3(AF3 x, AF3 y) { return AF3_AU3((AU3_AF3(x) != AU3_(0)) ? AU3_(0) : AU3_AF3(y)); } +AF4 AZolZeroPassF4(AF4 x, AF4 y) { return AF4_AU4((AU4_AF4(x) != AU4_(0)) ? AU4_(0) : AU4_AF4(y)); } +#endif +//============================================================================================================================== +#ifdef A_HALF +AW1 AZolAndW1(AW1 x, AW1 y) { return min(x, y); } +AW2 AZolAndW2(AW2 x, AW2 y) { return min(x, y); } +AW3 AZolAndW3(AW3 x, AW3 y) { return min(x, y); } +AW4 AZolAndW4(AW4 x, AW4 y) { return min(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AW1 AZolNotW1(AW1 x) { return x ^ AW1_(1); } +AW2 AZolNotW2(AW2 x) { return x ^ AW2_(1); } +AW3 AZolNotW3(AW3 x) { return x ^ AW3_(1); } +AW4 AZolNotW4(AW4 x) { return x ^ AW4_(1); } +//------------------------------------------------------------------------------------------------------------------------------ +AW1 AZolOrW1(AW1 x, AW1 y) { return max(x, y); } +AW2 AZolOrW2(AW2 x, AW2 y) { return max(x, y); } +AW3 AZolOrW3(AW3 x, AW3 y) { return max(x, y); } +AW4 AZolOrW4(AW4 x, AW4 y) { return max(x, y); } +//============================================================================================================================== + // Uses denormal trick. +AW1 AZolH1ToW1(AH1 x) { return AW1_AH1(x * AH1_AW1(AW1_(1))); } +AW2 AZolH2ToW2(AH2 x) { return AW2_AH2(x * AH2_AW2(AW2_(1))); } +AW3 AZolH3ToW3(AH3 x) { return AW3_AH3(x * AH3_AW3(AW3_(1))); } +AW4 AZolH4ToW4(AH4 x) { return AW4_AH4(x * AH4_AW4(AW4_(1))); } +//------------------------------------------------------------------------------------------------------------------------------ + // AMD arch lacks a packed conversion opcode. +AH1 AZolW1ToH1(AW1 x) { return AH1_AW1(x * AW1_AH1(AH1_(1.0))); } +AH2 AZolW2ToH2(AW2 x) { return AH2_AW2(x * AW2_AH2(AH2_(1.0))); } +AH3 AZolW1ToH3(AW3 x) { return AH3_AW3(x * AW3_AH3(AH3_(1.0))); } +AH4 AZolW2ToH4(AW4 x) { return AH4_AW4(x * AW4_AH4(AH4_(1.0))); } +//============================================================================================================================== +AH1 AZolAndH1(AH1 x, AH1 y) { return min(x, y); } +AH2 AZolAndH2(AH2 x, AH2 y) { return min(x, y); } +AH3 AZolAndH3(AH3 x, AH3 y) { return min(x, y); } +AH4 AZolAndH4(AH4 x, AH4 y) { return min(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 ASolAndNotH1(AH1 x, AH1 y) { return (-x) * y + AH1_(1.0); } +AH2 ASolAndNotH2(AH2 x, AH2 y) { return (-x) * y + AH2_(1.0); } +AH3 ASolAndNotH3(AH3 x, AH3 y) { return (-x) * y + AH3_(1.0); } +AH4 ASolAndNotH4(AH4 x, AH4 y) { return (-x) * y + AH4_(1.0); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolAndOrH1(AH1 x, AH1 y, AH1 z) { return ASatH1(x * y + z); } +AH2 AZolAndOrH2(AH2 x, AH2 y, AH2 z) { return ASatH2(x * y + z); } +AH3 AZolAndOrH3(AH3 x, AH3 y, AH3 z) { return ASatH3(x * y + z); } +AH4 AZolAndOrH4(AH4 x, AH4 y, AH4 z) { return ASatH4(x * y + z); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolGtZeroH1(AH1 x) { return ASatH1(x * AH1_(A_INFP_H)); } +AH2 AZolGtZeroH2(AH2 x) { return ASatH2(x * AH2_(A_INFP_H)); } +AH3 AZolGtZeroH3(AH3 x) { return ASatH3(x * AH3_(A_INFP_H)); } +AH4 AZolGtZeroH4(AH4 x) { return ASatH4(x * AH4_(A_INFP_H)); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolNotH1(AH1 x) { return AH1_(1.0) - x; } +AH2 AZolNotH2(AH2 x) { return AH2_(1.0) - x; } +AH3 AZolNotH3(AH3 x) { return AH3_(1.0) - x; } +AH4 AZolNotH4(AH4 x) { return AH4_(1.0) - x; } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolOrH1(AH1 x, AH1 y) { return max(x, y); } +AH2 AZolOrH2(AH2 x, AH2 y) { return max(x, y); } +AH3 AZolOrH3(AH3 x, AH3 y) { return max(x, y); } +AH4 AZolOrH4(AH4 x, AH4 y) { return max(x, y); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolSelH1(AH1 x, AH1 y, AH1 z) { AH1 r = (-x) * z + z; return x * y + r; } +AH2 AZolSelH2(AH2 x, AH2 y, AH2 z) { AH2 r = (-x) * z + z; return x * y + r; } +AH3 AZolSelH3(AH3 x, AH3 y, AH3 z) { AH3 r = (-x) * z + z; return x * y + r; } +AH4 AZolSelH4(AH4 x, AH4 y, AH4 z) { AH4 r = (-x) * z + z; return x * y + r; } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AZolSignedH1(AH1 x) { return ASatH1(x * AH1_(A_INFN_H)); } +AH2 AZolSignedH2(AH2 x) { return ASatH2(x * AH2_(A_INFN_H)); } +AH3 AZolSignedH3(AH3 x) { return ASatH3(x * AH3_(A_INFN_H)); } +AH4 AZolSignedH4(AH4 x) { return ASatH4(x * AH4_(A_INFN_H)); } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// COLOR CONVERSIONS +//------------------------------------------------------------------------------------------------------------------------------ +// These are all linear to/from some other space (where 'linear' has been shortened out of the function name). +// So 'ToGamma' is 'LinearToGamma', and 'FromGamma' is 'LinearFromGamma'. +// These are branch free implementations. +// The AToSrgbF1() function is useful for stores for compute shaders for GPUs without hardware linear->sRGB store conversion. +//------------------------------------------------------------------------------------------------------------------------------ +// TRANSFER FUNCTIONS +// ================== +// 709 ..... Rec709 used for some HDTVs +// Gamma ... Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native +// Pq ...... PQ native for HDR10 +// Srgb .... The sRGB output, typical of PC displays, useful for 10-bit output, or storing to 8-bit UNORM without SRGB type +// Two ..... Gamma 2.0, fastest conversion (useful for intermediate pass approximations) +// Three ... Gamma 3.0, less fast, but good for HDR. +//------------------------------------------------------------------------------------------------------------------------------ +// KEEPING TO SPEC +// =============== +// Both Rec.709 and sRGB have a linear segment which as spec'ed would intersect the curved segment 2 times. +// (a.) For 8-bit sRGB, steps {0 to 10.3} are in the linear region (4% of the encoding range). +// (b.) For 8-bit 709, steps {0 to 20.7} are in the linear region (8% of the encoding range). +// Also there is a slight step in the transition regions. +// Precision of the coefficients in the spec being the likely cause. +// Main usage case of the sRGB code is to do the linear->sRGB converstion in a compute shader before store. +// This is to work around lack of hardware (typically only ROP does the conversion for free). +// To "correct" the linear segment, would be to introduce error, because hardware decode of sRGB->linear is fixed (and free). +// So this header keeps with the spec. +// For linear->sRGB transforms, the linear segment in some respects reduces error, because rounding in that region is linear. +// Rounding in the curved region in hardware (and fast software code) introduces error due to rounding in non-linear. +//------------------------------------------------------------------------------------------------------------------------------ +// FOR PQ +// ====== +// Both input and output is {0.0-1.0}, and where output 1.0 represents 10000.0 cd/m^2. +// All constants are only specified to FP32 precision. +// External PQ source reference, +// - https://github.com/ampas/aces-dev/blob/master/transforms/ctl/utilities/ACESlib.Utilities_Color.a1.0.1.ctl +//------------------------------------------------------------------------------------------------------------------------------ +// PACKED VERSIONS +// =============== +// These are the A*H2() functions. +// There is no PQ functions as FP16 seemed to not have enough precision for the conversion. +// The remaining functions are "good enough" for 8-bit, and maybe 10-bit if not concerned about a few 1-bit errors. +// Precision is lowest in the 709 conversion, higher in sRGB, higher still in Two and Gamma (when using 2.2 at least). +//------------------------------------------------------------------------------------------------------------------------------ +// NOTES +// ===== +// Could be faster for PQ conversions to be in ALU or a texture lookup depending on usage case. +//============================================================================================================================== +#if 1 +AF1 ATo709F1(AF1 c) { + AF3 j = AF3(0.018 * 4.5, 4.5, 0.45); AF2 k = AF2(1.099, -0.099); + return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); +} +AF2 ATo709F2(AF2 c) { + AF3 j = AF3(0.018 * 4.5, 4.5, 0.45); AF2 k = AF2(1.099, -0.099); + return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); +} +AF3 ATo709F3(AF3 c) { + AF3 j = AF3(0.018 * 4.5, 4.5, 0.45); AF2 k = AF2(1.099, -0.099); + return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); +} +//------------------------------------------------------------------------------------------------------------------------------ + // Note 'rcpX' is '1/x', where the 'x' is what would be used in AFromGamma(). +AF1 AToGammaF1(AF1 c, AF1 rcpX) { return pow(c, AF1_(rcpX)); } +AF2 AToGammaF2(AF2 c, AF1 rcpX) { return pow(c, AF2_(rcpX)); } +AF3 AToGammaF3(AF3 c, AF1 rcpX) { return pow(c, AF3_(rcpX)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AToPqF1(AF1 x) { + AF1 p = pow(x, AF1_(0.159302)); + return pow((AF1_(0.835938) + AF1_(18.8516) * p) / (AF1_(1.0) + AF1_(18.6875) * p), AF1_(78.8438)); +} +AF2 AToPqF1(AF2 x) { + AF2 p = pow(x, AF2_(0.159302)); + return pow((AF2_(0.835938) + AF2_(18.8516) * p) / (AF2_(1.0) + AF2_(18.6875) * p), AF2_(78.8438)); +} +AF3 AToPqF1(AF3 x) { + AF3 p = pow(x, AF3_(0.159302)); + return pow((AF3_(0.835938) + AF3_(18.8516) * p) / (AF3_(1.0) + AF3_(18.6875) * p), AF3_(78.8438)); +} +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AToSrgbF1(AF1 c) { + AF3 j = AF3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AF2 k = AF2(1.055, -0.055); + return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); +} +AF2 AToSrgbF2(AF2 c) { + AF3 j = AF3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AF2 k = AF2(1.055, -0.055); + return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); +} +AF3 AToSrgbF3(AF3 c) { + AF3 j = AF3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AF2 k = AF2(1.055, -0.055); + return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); +} +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AToTwoF1(AF1 c) { return sqrt(c); } +AF2 AToTwoF2(AF2 c) { return sqrt(c); } +AF3 AToTwoF3(AF3 c) { return sqrt(c); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AToThreeF1(AF1 c) { return pow(c, AF1_(1.0 / 3.0)); } +AF2 AToThreeF2(AF2 c) { return pow(c, AF2_(1.0 / 3.0)); } +AF3 AToThreeF3(AF3 c) { return pow(c, AF3_(1.0 / 3.0)); } +#endif +//============================================================================================================================== +#if 1 + // Unfortunately median won't work here. +AF1 AFrom709F1(AF1 c) { + AF3 j = AF3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AF2 k = AF2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelF1(AZolSignedF1(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); +} +AF2 AFrom709F2(AF2 c) { + AF3 j = AF3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AF2 k = AF2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelF2(AZolSignedF2(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); +} +AF3 AFrom709F3(AF3 c) { + AF3 j = AF3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AF2 k = AF2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelF3(AZolSignedF3(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); +} +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AFromGammaF1(AF1 c, AF1 x) { return pow(c, AF1_(x)); } +AF2 AFromGammaF2(AF2 c, AF1 x) { return pow(c, AF2_(x)); } +AF3 AFromGammaF3(AF3 c, AF1 x) { return pow(c, AF3_(x)); } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AFromPqF1(AF1 x) { + AF1 p = pow(x, AF1_(0.0126833)); + return pow(ASatF1(p - AF1_(0.835938)) / (AF1_(18.8516) - AF1_(18.6875) * p), AF1_(6.27739)); +} +AF2 AFromPqF1(AF2 x) { + AF2 p = pow(x, AF2_(0.0126833)); + return pow(ASatF2(p - AF2_(0.835938)) / (AF2_(18.8516) - AF2_(18.6875) * p), AF2_(6.27739)); +} +AF3 AFromPqF1(AF3 x) { + AF3 p = pow(x, AF3_(0.0126833)); + return pow(ASatF3(p - AF3_(0.835938)) / (AF3_(18.8516) - AF3_(18.6875) * p), AF3_(6.27739)); +} +//------------------------------------------------------------------------------------------------------------------------------ + // Unfortunately median won't work here. +AF1 AFromSrgbF1(AF1 c) { + AF3 j = AF3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AF2 k = AF2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelF1(AZolSignedF1(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); +} +AF2 AFromSrgbF2(AF2 c) { + AF3 j = AF3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AF2 k = AF2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelF2(AZolSignedF2(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); +} +AF3 AFromSrgbF3(AF3 c) { + AF3 j = AF3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AF2 k = AF2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelF3(AZolSignedF3(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); +} +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AFromTwoF1(AF1 c) { return c * c; } +AF2 AFromTwoF2(AF2 c) { return c * c; } +AF3 AFromTwoF3(AF3 c) { return c * c; } +//------------------------------------------------------------------------------------------------------------------------------ +AF1 AFromThreeF1(AF1 c) { return c * c * c; } +AF2 AFromThreeF2(AF2 c) { return c * c * c; } +AF3 AFromThreeF3(AF3 c) { return c * c * c; } +#endif +//============================================================================================================================== +#ifdef A_HALF +AH1 ATo709H1(AH1 c) { + AH3 j = AH3(0.018 * 4.5, 4.5, 0.45); AH2 k = AH2(1.099, -0.099); + return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); +} +AH2 ATo709H2(AH2 c) { + AH3 j = AH3(0.018 * 4.5, 4.5, 0.45); AH2 k = AH2(1.099, -0.099); + return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); +} +AH3 ATo709H3(AH3 c) { + AH3 j = AH3(0.018 * 4.5, 4.5, 0.45); AH2 k = AH2(1.099, -0.099); + return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); +} +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AToGammaH1(AH1 c, AH1 rcpX) { return pow(c, AH1_(rcpX)); } +AH2 AToGammaH2(AH2 c, AH1 rcpX) { return pow(c, AH2_(rcpX)); } +AH3 AToGammaH3(AH3 c, AH1 rcpX) { return pow(c, AH3_(rcpX)); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AToSrgbH1(AH1 c) { + AH3 j = AH3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AH2 k = AH2(1.055, -0.055); + return clamp(j.x, c * j.y, pow(c, j.z) * k.x + k.y); +} +AH2 AToSrgbH2(AH2 c) { + AH3 j = AH3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AH2 k = AH2(1.055, -0.055); + return clamp(j.xx, c * j.yy, pow(c, j.zz) * k.xx + k.yy); +} +AH3 AToSrgbH3(AH3 c) { + AH3 j = AH3(0.0031308 * 12.92, 12.92, 1.0 / 2.4); AH2 k = AH2(1.055, -0.055); + return clamp(j.xxx, c * j.yyy, pow(c, j.zzz) * k.xxx + k.yyy); +} +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AToTwoH1(AH1 c) { return sqrt(c); } +AH2 AToTwoH2(AH2 c) { return sqrt(c); } +AH3 AToTwoH3(AH3 c) { return sqrt(c); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AToThreeF1(AH1 c) { return pow(c, AH1_(1.0 / 3.0)); } +AH2 AToThreeF2(AH2 c) { return pow(c, AH2_(1.0 / 3.0)); } +AH3 AToThreeF3(AH3 c) { return pow(c, AH3_(1.0 / 3.0)); } +#endif +//============================================================================================================================== +#ifdef A_HALF +AH1 AFrom709H1(AH1 c) { + AH3 j = AH3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AH2 k = AH2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelH1(AZolSignedH1(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); +} +AH2 AFrom709H2(AH2 c) { + AH3 j = AH3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AH2 k = AH2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelH2(AZolSignedH2(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); +} +AH3 AFrom709H3(AH3 c) { + AH3 j = AH3(0.081 / 4.5, 1.0 / 4.5, 1.0 / 0.45); AH2 k = AH2(1.0 / 1.099, 0.099 / 1.099); + return AZolSelH3(AZolSignedH3(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); +} +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AFromGammaH1(AH1 c, AH1 x) { return pow(c, AH1_(x)); } +AH2 AFromGammaH2(AH2 c, AH1 x) { return pow(c, AH2_(x)); } +AH3 AFromGammaH3(AH3 c, AH1 x) { return pow(c, AH3_(x)); } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AHromSrgbF1(AH1 c) { + AH3 j = AH3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AH2 k = AH2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelH1(AZolSignedH1(c - j.x), c * j.y, pow(c * k.x + k.y, j.z)); +} +AH2 AHromSrgbF2(AH2 c) { + AH3 j = AH3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AH2 k = AH2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelH2(AZolSignedH2(c - j.xx), c * j.yy, pow(c * k.xx + k.yy, j.zz)); +} +AH3 AHromSrgbF3(AH3 c) { + AH3 j = AH3(0.04045 / 12.92, 1.0 / 12.92, 2.4); AH2 k = AH2(1.0 / 1.055, 0.055 / 1.055); + return AZolSelH3(AZolSignedH3(c - j.xxx), c * j.yyy, pow(c * k.xxx + k.yyy, j.zzz)); +} +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AFromTwoH1(AH1 c) { return c * c; } +AH2 AFromTwoH2(AH2 c) { return c * c; } +AH3 AFromTwoH3(AH3 c) { return c * c; } +//------------------------------------------------------------------------------------------------------------------------------ +AH1 AFromThreeH1(AH1 c) { return c * c * c; } +AH2 AFromThreeH2(AH2 c) { return c * c * c; } +AH3 AFromThreeH3(AH3 c) { return c * c * c; } +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// CS REMAP +//============================================================================================================================== + // Simple remap 64x1 to 8x8 with rotated 2x2 pixel quads in quad linear. + // 543210 + // ====== + // ..xxx. + // yy...y +AU2 ARmp8x8(AU1 a) { return AU2(ABfe(a, 1u, 3u), ABfiM(ABfe(a, 3u, 3u), a, 1u)); } +//============================================================================================================================== + // More complex remap 64x1 to 8x8 which is necessary for 2D wave reductions. + // 543210 + // ====== + // .xx..x + // y..yy. + // Details, + // LANE TO 8x8 MAPPING + // =================== + // 00 01 08 09 10 11 18 19 + // 02 03 0a 0b 12 13 1a 1b + // 04 05 0c 0d 14 15 1c 1d + // 06 07 0e 0f 16 17 1e 1f + // 20 21 28 29 30 31 38 39 + // 22 23 2a 2b 32 33 3a 3b + // 24 25 2c 2d 34 35 3c 3d + // 26 27 2e 2f 36 37 3e 3f +AU2 ARmpRed8x8(AU1 a) { return AU2(ABfiM(ABfe(a, 2u, 3u), a, 1u), ABfiM(ABfe(a, 3u, 3u), ABfe(a, 1u, 2u), 2u)); } +//============================================================================================================================== +#ifdef A_HALF +AW2 ARmp8x8H(AU1 a) { return AW2(ABfe(a, 1u, 3u), ABfiM(ABfe(a, 3u, 3u), a, 1u)); } +AW2 ARmpRed8x8H(AU1 a) { return AW2(ABfiM(ABfe(a, 2u, 3u), a, 1u), ABfiM(ABfe(a, 3u, 3u), ABfe(a, 1u, 2u), 2u)); } +#endif +#endif +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// REFERENCE +// +//------------------------------------------------------------------------------------------------------------------------------ +// IEEE FLOAT RULES +// ================ +// - saturate(NaN)=0, saturate(-INF)=0, saturate(+INF)=1 +// - {+/-}0 * {+/-}INF = NaN +// - -INF + (+INF) = NaN +// - {+/-}0 / {+/-}0 = NaN +// - {+/-}INF / {+/-}INF = NaN +// - a<(-0) := sqrt(a) = NaN (a=-0.0 won't NaN) +// - 0 == -0 +// - 4/0 = +INF +// - 4/-0 = -INF +// - 4+INF = +INF +// - 4-INF = -INF +// - 4*(+INF) = +INF +// - 4*(-INF) = -INF +// - -4*(+INF) = -INF +// - sqrt(+INF) = +INF +//------------------------------------------------------------------------------------------------------------------------------ +// FP16 ENCODING +// ============= +// fedcba9876543210 +// ---------------- +// ......mmmmmmmmmm 10-bit mantissa (encodes 11-bit 0.5 to 1.0 except for denormals) +// .eeeee.......... 5-bit exponent +// .00000.......... denormals +// .00001.......... -14 exponent +// .11110.......... 15 exponent +// .111110000000000 infinity +// .11111nnnnnnnnnn NaN with n!=0 +// s............... sign +//------------------------------------------------------------------------------------------------------------------------------ +// FP16/INT16 ALIASING DENORMAL +// ============================ +// 11-bit unsigned integers alias with half float denormal/normal values, +// 1 = 2^(-24) = 1/16777216 ....................... first denormal value +// 2 = 2^(-23) +// ... +// 1023 = 2^(-14)*(1-2^(-10)) = 2^(-14)*(1-1/1024) ... last denormal value +// 1024 = 2^(-14) = 1/16384 .......................... first normal value that still maps to integers +// 2047 .............................................. last normal value that still maps to integers +// Scaling limits, +// 2^15 = 32768 ...................................... largest power of 2 scaling +// Largest pow2 conversion mapping is at *32768, +// 1 : 2^(-9) = 1/512 +// 2 : 1/256 +// 4 : 1/128 +// 8 : 1/64 +// 16 : 1/32 +// 32 : 1/16 +// 64 : 1/8 +// 128 : 1/4 +// 256 : 1/2 +// 512 : 1 +// 1024 : 2 +// 2047 : a little less than 4 +//============================================================================================================================== +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// +// GPU/CPU PORTABILITY +// +// +//------------------------------------------------------------------------------------------------------------------------------ +// This is the GPU implementation. +// See the CPU implementation for docs. +//============================================================================================================================== +#ifdef A_GPU +#define A_TRUE true +#define A_FALSE false +#define A_STATIC +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// VECTOR ARGUMENT/RETURN/INITIALIZATION PORTABILITY +//============================================================================================================================== +#define retAD2 AD2 +#define retAD3 AD3 +#define retAD4 AD4 +#define retAF2 AF2 +#define retAF3 AF3 +#define retAF4 AF4 +#define retAL2 AL2 +#define retAL3 AL3 +#define retAL4 AL4 +#define retAU2 AU2 +#define retAU3 AU3 +#define retAU4 AU4 +//------------------------------------------------------------------------------------------------------------------------------ +#define inAD2 in AD2 +#define inAD3 in AD3 +#define inAD4 in AD4 +#define inAF2 in AF2 +#define inAF3 in AF3 +#define inAF4 in AF4 +#define inAL2 in AL2 +#define inAL3 in AL3 +#define inAL4 in AL4 +#define inAU2 in AU2 +#define inAU3 in AU3 +#define inAU4 in AU4 +//------------------------------------------------------------------------------------------------------------------------------ +#define inoutAD2 inout AD2 +#define inoutAD3 inout AD3 +#define inoutAD4 inout AD4 +#define inoutAF2 inout AF2 +#define inoutAF3 inout AF3 +#define inoutAF4 inout AF4 +#define inoutAL2 inout AL2 +#define inoutAL3 inout AL3 +#define inoutAL4 inout AL4 +#define inoutAU2 inout AU2 +#define inoutAU3 inout AU3 +#define inoutAU4 inout AU4 +//------------------------------------------------------------------------------------------------------------------------------ +#define outAD2 out AD2 +#define outAD3 out AD3 +#define outAD4 out AD4 +#define outAF2 out AF2 +#define outAF3 out AF3 +#define outAF4 out AF4 +#define outAL2 out AL2 +#define outAL3 out AL3 +#define outAL4 out AL4 +#define outAU2 out AU2 +#define outAU3 out AU3 +#define outAU4 out AU4 +//------------------------------------------------------------------------------------------------------------------------------ +#define varAD2(x) AD2 x +#define varAD3(x) AD3 x +#define varAD4(x) AD4 x +#define varAF2(x) AF2 x +#define varAF3(x) AF3 x +#define varAF4(x) AF4 x +#define varAL2(x) AL2 x +#define varAL3(x) AL3 x +#define varAL4(x) AL4 x +#define varAU2(x) AU2 x +#define varAU3(x) AU3 x +#define varAU4(x) AU4 x +//------------------------------------------------------------------------------------------------------------------------------ +#define initAD2(x,y) AD2(x,y) +#define initAD3(x,y,z) AD3(x,y,z) +#define initAD4(x,y,z,w) AD4(x,y,z,w) +#define initAF2(x,y) AF2(x,y) +#define initAF3(x,y,z) AF3(x,y,z) +#define initAF4(x,y,z,w) AF4(x,y,z,w) +#define initAL2(x,y) AL2(x,y) +#define initAL3(x,y,z) AL3(x,y,z) +#define initAL4(x,y,z,w) AL4(x,y,z,w) +#define initAU2(x,y) AU2(x,y) +#define initAU3(x,y,z) AU3(x,y,z) +#define initAU4(x,y,z,w) AU4(x,y,z,w) +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// SCALAR RETURN OPS +//============================================================================================================================== +#define AAbsD1(a) abs(AD1(a)) +#define AAbsF1(a) abs(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define ACosD1(a) cos(AD1(a)) +#define ACosF1(a) cos(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define ADotD2(a,b) dot(AD2(a),AD2(b)) +#define ADotD3(a,b) dot(AD3(a),AD3(b)) +#define ADotD4(a,b) dot(AD4(a),AD4(b)) +#define ADotF2(a,b) dot(AF2(a),AF2(b)) +#define ADotF3(a,b) dot(AF3(a),AF3(b)) +#define ADotF4(a,b) dot(AF4(a),AF4(b)) +//------------------------------------------------------------------------------------------------------------------------------ +#define AExp2D1(a) exp2(AD1(a)) +#define AExp2F1(a) exp2(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define AFloorD1(a) floor(AD1(a)) +#define AFloorF1(a) floor(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define ALog2D1(a) log2(AD1(a)) +#define ALog2F1(a) log2(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define AMaxD1(a,b) max(a,b) +#define AMaxF1(a,b) max(a,b) +#define AMaxL1(a,b) max(a,b) +#define AMaxU1(a,b) max(a,b) +//------------------------------------------------------------------------------------------------------------------------------ +#define AMinD1(a,b) min(a,b) +#define AMinF1(a,b) min(a,b) +#define AMinL1(a,b) min(a,b) +#define AMinU1(a,b) min(a,b) +//------------------------------------------------------------------------------------------------------------------------------ +#define ASinD1(a) sin(AD1(a)) +#define ASinF1(a) sin(AF1(a)) +//------------------------------------------------------------------------------------------------------------------------------ +#define ASqrtD1(a) sqrt(AD1(a)) +#define ASqrtF1(a) sqrt(AF1(a)) +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// SCALAR RETURN OPS - DEPENDENT +//============================================================================================================================== +#define APowD1(a,b) pow(AD1(a),AF1(b)) +#define APowF1(a,b) pow(AF1(a),AF1(b)) +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// VECTOR OPS +//------------------------------------------------------------------------------------------------------------------------------ +// These are added as needed for production or prototyping, so not necessarily a complete set. +// They follow a convention of taking in a destination and also returning the destination value to increase utility. +//============================================================================================================================== +//============================================================================================================================== +AF2 opAAbsF2(outAF2 d, inAF2 a) { d = abs(a); return d; } +AF3 opAAbsF3(outAF3 d, inAF3 a) { d = abs(a); return d; } +AF4 opAAbsF4(outAF4 d, inAF4 a) { d = abs(a); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAAddF2(outAF2 d, inAF2 a, inAF2 b) { d = a + b; return d; } +AF3 opAAddF3(outAF3 d, inAF3 a, inAF3 b) { d = a + b; return d; } +AF4 opAAddF4(outAF4 d, inAF4 a, inAF4 b) { d = a + b; return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAAddOneF2(outAF2 d, inAF2 a, AF1 b) { d = a + AF2_(b); return d; } +AF3 opAAddOneF3(outAF3 d, inAF3 a, AF1 b) { d = a + AF3_(b); return d; } +AF4 opAAddOneF4(outAF4 d, inAF4 a, AF1 b) { d = a + AF4_(b); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opACpyF2(outAF2 d, inAF2 a) { d = a; return d; } +AF3 opACpyF3(outAF3 d, inAF3 a) { d = a; return d; } +AF4 opACpyF4(outAF4 d, inAF4 a) { d = a; return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opALerpF2(outAF2 d, inAF2 a, inAF2 b, inAF2 c) { d = ALerpF2(a, b, c); return d; } +AF3 opALerpF3(outAF3 d, inAF3 a, inAF3 b, inAF3 c) { d = ALerpF3(a, b, c); return d; } +AF4 opALerpF4(outAF4 d, inAF4 a, inAF4 b, inAF4 c) { d = ALerpF4(a, b, c); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opALerpOneF2(outAF2 d, inAF2 a, inAF2 b, AF1 c) { d = ALerpF2(a, b, AF2_(c)); return d; } +AF3 opALerpOneF3(outAF3 d, inAF3 a, inAF3 b, AF1 c) { d = ALerpF3(a, b, AF3_(c)); return d; } +AF4 opALerpOneF4(outAF4 d, inAF4 a, inAF4 b, AF1 c) { d = ALerpF4(a, b, AF4_(c)); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAMaxF2(outAF2 d, inAF2 a, inAF2 b) { d = max(a, b); return d; } +AF3 opAMaxF3(outAF3 d, inAF3 a, inAF3 b) { d = max(a, b); return d; } +AF4 opAMaxF4(outAF4 d, inAF4 a, inAF4 b) { d = max(a, b); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAMinF2(outAF2 d, inAF2 a, inAF2 b) { d = min(a, b); return d; } +AF3 opAMinF3(outAF3 d, inAF3 a, inAF3 b) { d = min(a, b); return d; } +AF4 opAMinF4(outAF4 d, inAF4 a, inAF4 b) { d = min(a, b); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAMulF2(outAF2 d, inAF2 a, inAF2 b) { d = a * b; return d; } +AF3 opAMulF3(outAF3 d, inAF3 a, inAF3 b) { d = a * b; return d; } +AF4 opAMulF4(outAF4 d, inAF4 a, inAF4 b) { d = a * b; return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opAMulOneF2(outAF2 d, inAF2 a, AF1 b) { d = a * AF2_(b); return d; } +AF3 opAMulOneF3(outAF3 d, inAF3 a, AF1 b) { d = a * AF3_(b); return d; } +AF4 opAMulOneF4(outAF4 d, inAF4 a, AF1 b) { d = a * AF4_(b); return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opANegF2(outAF2 d, inAF2 a) { d = -a; return d; } +AF3 opANegF3(outAF3 d, inAF3 a) { d = -a; return d; } +AF4 opANegF4(outAF4 d, inAF4 a) { d = -a; return d; } +//------------------------------------------------------------------------------------------------------------------------------ +AF2 opARcpF2(outAF2 d, inAF2 a) { d = ARcpF2(a); return d; } +AF3 opARcpF3(outAF3 d, inAF3 a) { d = ARcpF3(a); return d; } +AF4 opARcpF4(outAF4 d, inAF4 a) { d = ARcpF4(a); return d; } +#endif +#endif \ No newline at end of file diff --git a/MODULE_Common/ffx_fsr1.hlsli b/MODULE_Common/ffx_fsr1.hlsli new file mode 100644 index 000000000..f6c677aa4 --- /dev/null +++ b/MODULE_Common/ffx_fsr1.hlsli @@ -0,0 +1,535 @@ +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// +// AMD FidelityFX SUPER RESOLUTION [FSR 1] ::: SPATIAL SCALING & EXTRAS - v1.20210629 +// +// +//------------------------------------------------------------------------------------------------------------------------------ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------------------------------------------------------------ +// FidelityFX Super Resolution Sample +// +// Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved. +// 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. +//------------------------------------------------------------------------------------------------------------------------------ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------------------------------------------------------------ +// ABOUT +// ===== +// FSR is a collection of algorithms relating to generating a higher resolution image. +// This specific header focuses on single-image non-temporal image scaling, and related tools. +// +// The core functions are EASU and RCAS: +// [EASU] Edge Adaptive Spatial Upsampling ....... 1x to 4x area range spatial scaling, clamped adaptive elliptical filter. +// [RCAS] Robust Contrast Adaptive Sharpening .... A non-scaling variation on CAS. +// RCAS needs to be applied after EASU as a separate pass. +// +// Optional utility functions are: +// [LFGA] Linear Film Grain Applicator ........... Tool to apply film grain after scaling. +// [SRTM] Simple Reversible Tone-Mapper .......... Linear HDR {0 to FP16_MAX} to {0 to 1} and back. +// [TEPD] Temporal Energy Preserving Dither ...... Temporally energy preserving dithered {0 to 1} linear to gamma 2.0 conversion. +// See each individual sub-section for inline documentation. +//------------------------------------------------------------------------------------------------------------------------------ +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//------------------------------------------------------------------------------------------------------------------------------ +// FUNCTION PERMUTATIONS +// ===================== +// *F() ..... Single item computation with 32-bit. +// *H() ..... Single item computation with 16-bit, with packing (aka two 16-bit ops in parallel) when possible. +// *Hx2() ... Processing two items in parallel with 16-bit, easier packing. +// Not all interfaces in this file have a *Hx2() form. +//============================================================================================================================== +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// FSR - [EASU] EDGE ADAPTIVE SPATIAL UPSAMPLING +// +//------------------------------------------------------------------------------------------------------------------------------ +// EASU provides a high quality spatial-only scaling at relatively low cost. +// Meaning EASU is appropiate for laptops and other low-end GPUs. +// Quality from 1x to 4x area scaling is good. +//------------------------------------------------------------------------------------------------------------------------------ +// The scalar uses a modified fast approximation to the standard lanczos(size=2) kernel. +// EASU runs in a single pass, so it applies a directionally and anisotropically adaptive radial lanczos. +// This is also kept as simple as possible to have minimum runtime. +//------------------------------------------------------------------------------------------------------------------------------ +// The lanzcos filter has negative lobes, so by itself it will introduce ringing. +// To remove all ringing, the algorithm uses the nearest 2x2 input texels as a neighborhood, +// and limits output to the minimum and maximum of that neighborhood. +//------------------------------------------------------------------------------------------------------------------------------ +// Input image requirements: +// +// Color needs to be encoded as 3 channel[red, green, blue](e.g.XYZ not supported) +// Each channel needs to be in the range[0, 1] +// Any color primaries are supported +// Display / tonemapping curve needs to be as if presenting to sRGB display or similar(e.g.Gamma 2.0) +// There should be no banding in the input +// There should be no high amplitude noise in the input +// There should be no noise in the input that is not at input pixel granularity +// For performance purposes, use 32bpp formats +//------------------------------------------------------------------------------------------------------------------------------ +// Best to apply EASU at the end of the frame after tonemapping +// but before film grain or composite of the UI. +//------------------------------------------------------------------------------------------------------------------------------ +// Example of including this header for D3D HLSL : +// +// #define A_GPU 1 +// #define A_HLSL 1 +// #define A_HALF 1 +// #include "ffx_a.h" +// #define FSR_EASU_H 1 +// #define FSR_RCAS_H 1 +// //declare input callbacks +// #include "ffx_fsr1.h" +// +// Example of including this header for Vulkan GLSL : +// +// #define A_GPU 1 +// #define A_GLSL 1 +// #define A_HALF 1 +// #include "ffx_a.h" +// #define FSR_EASU_H 1 +// #define FSR_RCAS_H 1 +// //declare input callbacks +// #include "ffx_fsr1.h" +// +// Example of including this header for Vulkan HLSL : +// +// #define A_GPU 1 +// #define A_HLSL 1 +// #define A_HLSL_6_2 1 +// #define A_NO_16_BIT_CAST 1 +// #define A_HALF 1 +// #include "ffx_a.h" +// #define FSR_EASU_H 1 +// #define FSR_RCAS_H 1 +// //declare input callbacks +// #include "ffx_fsr1.h" +// +// Example of declaring the required input callbacks for GLSL : +// The callbacks need to gather4 for each color channel using the specified texture coordinate 'p'. +// EASU uses gather4 to reduce position computation logic and for free Arrays of Structures to Structures of Arrays conversion. +// +// AH4 FsrEasuRH(AF2 p){return AH4(textureGather(sampler2D(tex,sam),p,0));} +// AH4 FsrEasuGH(AF2 p){return AH4(textureGather(sampler2D(tex,sam),p,1));} +// AH4 FsrEasuBH(AF2 p){return AH4(textureGather(sampler2D(tex,sam),p,2));} +// ... +// The FsrEasuCon function needs to be called from the CPU or GPU to set up constants. +// The difference in viewport and input image size is there to support Dynamic Resolution Scaling. +// To use FsrEasuCon() on the CPU, define A_CPU before including ffx_a and ffx_fsr1. +// Including a GPU example here, the 'con0' through 'con3' values would be stored out to a constant buffer. +// AU4 con0,con1,con2,con3; +// FsrEasuCon(con0,con1,con2,con3, +// 1920.0,1080.0, // Viewport size (top left aligned) in the input image which is to be scaled. +// 3840.0,2160.0, // The size of the input image. +// 2560.0,1440.0); // The output resolution. +//============================================================================================================================== +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// CONSTANT SETUP +//============================================================================================================================== +// Call to setup required constant values (works on CPU or GPU). + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// NON-PACKED 32-BIT VERSION +//============================================================================================================================== +#if defined(A_GPU)&&defined(FSR_EASU_F) + // Input callback prototypes, need to be implemented by calling shader +AF4 FsrEasuRF(AF2 p); +AF4 FsrEasuGF(AF2 p); +AF4 FsrEasuBF(AF2 p); +//------------------------------------------------------------------------------------------------------------------------------ + // Filtering for a given tap for the scalar. +void FsrEasuTapF( + inout AF3 aC, // Accumulated color, with negative lobe. + inout AF1 aW, // Accumulated weight. + AF2 off, // Pixel offset from resolve position to tap. + AF2 dir, // Gradient direction. + AF2 len, // Length. + AF1 lob, // Negative lobe strength. + AF1 clp, // Clipping point. + AF3 c) { // Tap color. + // Rotate offset by direction. + AF2 v; + v.x = (off.x * (dir.x)) + (off.y * dir.y); + v.y = (off.x * (-dir.y)) + (off.y * dir.x); + // Anisotropy. + v *= len; + // Compute distance^2. + AF1 d2 = v.x * v.x + v.y * v.y; + // Limit to the window as at corner, 2 taps can easily be outside. + d2 = min(d2, clp); + // Approximation of lancos2 without sin() or rcp(), or sqrt() to get x. + // (25/16 * (2/5 * x^2 - 1)^2 - (25/16 - 1)) * (1/4 * x^2 - 1)^2 + // |_______________________________________| |_______________| + // base window + // The general form of the 'base' is, + // (a*(b*x^2-1)^2-(a-1)) + // Where 'a=1/(2*b-b^2)' and 'b' moves around the negative lobe. + AF1 wB = AF1_(2.0 / 5.0) * d2 + AF1_(-1.0); + AF1 wA = lob * d2 + AF1_(-1.0); + wB *= wB; + wA *= wA; + wB = AF1_(25.0 / 16.0) * wB + AF1_(-(25.0 / 16.0 - 1.0)); + AF1 w = wB * wA; + // Do weighted average. + aC += c * w; aW += w; +} +//------------------------------------------------------------------------------------------------------------------------------ + // Accumulate direction and length. +void FsrEasuSetF( + inout AF2 dir, + inout AF1 len, + AF2 pp, + AP1 biS, AP1 biT, AP1 biU, AP1 biV, + AF1 lA, AF1 lB, AF1 lC, AF1 lD, AF1 lE) { + // Compute bilinear weight, branches factor out as predicates are compiler time immediates. + // s t + // u v + AF1 w = AF1_(0.0); + if (biS)w = (AF1_(1.0) - pp.x) * (AF1_(1.0) - pp.y); + if (biT)w = pp.x * (AF1_(1.0) - pp.y); + if (biU)w = (AF1_(1.0) - pp.x) * pp.y; + if (biV)w = pp.x * pp.y; + // Direction is the '+' diff. + // a + // b c d + // e + // Then takes magnitude from abs average of both sides of 'c'. + // Length converts gradient reversal to 0, smoothly to non-reversal at 1, shaped, then adding horz and vert terms. + AF1 dc = lD - lC; + AF1 cb = lC - lB; + AF1 lenX = max(abs(dc), abs(cb)); + lenX = APrxLoRcpF1(lenX); + AF1 dirX = lD - lB; + dir.x += dirX * w; + lenX = ASatF1(abs(dirX) * lenX); + lenX *= lenX; + len += lenX * w; + // Repeat for the y axis. + AF1 ec = lE - lC; + AF1 ca = lC - lA; + AF1 lenY = max(abs(ec), abs(ca)); + lenY = APrxLoRcpF1(lenY); + AF1 dirY = lE - lA; + dir.y += dirY * w; + lenY = ASatF1(abs(dirY) * lenY); + lenY *= lenY; + len += lenY * w; +} +//------------------------------------------------------------------------------------------------------------------------------ +void FsrEasuF( + out AF3 pix, + AU2 ip, // Integer pixel position in output. + AU4 con0, // Constants generated by FsrEasuCon(). + AU4 con1, + AU4 con2, + AU4 con3) { + //------------------------------------------------------------------------------------------------------------------------------ + // Get position of 'f'. + AF2 pp = AF2(ip) * AF2_AU2(con0.xy) + AF2_AU2(con0.zw); + AF2 fp = floor(pp); + pp -= fp; + //------------------------------------------------------------------------------------------------------------------------------ + // 12-tap kernel. + // b c + // e f g h + // i j k l + // n o + // Gather 4 ordering. + // a b + // r g + // For packed FP16, need either {rg} or {ab} so using the following setup for gather in all versions, + // a b <- unused (z) + // r g + // a b a b + // r g r g + // a b + // r g <- unused (z) + // Allowing dead-code removal to remove the 'z's. + AF2 p0 = fp * AF2_AU2(con1.xy) + AF2_AU2(con1.zw); + // These are from p0 to avoid pulling two constants on pre-Navi hardware. + AF2 p1 = p0 + AF2_AU2(con2.xy); + AF2 p2 = p0 + AF2_AU2(con2.zw); + AF2 p3 = p0 + AF2_AU2(con3.xy); + AF4 bczzR = FsrEasuRF(p0); + AF4 bczzG = FsrEasuGF(p0); + AF4 bczzB = FsrEasuBF(p0); + AF4 ijfeR = FsrEasuRF(p1); + AF4 ijfeG = FsrEasuGF(p1); + AF4 ijfeB = FsrEasuBF(p1); + AF4 klhgR = FsrEasuRF(p2); + AF4 klhgG = FsrEasuGF(p2); + AF4 klhgB = FsrEasuBF(p2); + AF4 zzonR = FsrEasuRF(p3); + AF4 zzonG = FsrEasuGF(p3); + AF4 zzonB = FsrEasuBF(p3); + //------------------------------------------------------------------------------------------------------------------------------ + // Simplest multi-channel approximate luma possible (luma times 2, in 2 FMA/MAD). + AF4 bczzL = bczzB * AF4_(0.5) + (bczzR * AF4_(0.5) + bczzG); + AF4 ijfeL = ijfeB * AF4_(0.5) + (ijfeR * AF4_(0.5) + ijfeG); + AF4 klhgL = klhgB * AF4_(0.5) + (klhgR * AF4_(0.5) + klhgG); + AF4 zzonL = zzonB * AF4_(0.5) + (zzonR * AF4_(0.5) + zzonG); + // Rename. + AF1 bL = bczzL.x; + AF1 cL = bczzL.y; + AF1 iL = ijfeL.x; + AF1 jL = ijfeL.y; + AF1 fL = ijfeL.z; + AF1 eL = ijfeL.w; + AF1 kL = klhgL.x; + AF1 lL = klhgL.y; + AF1 hL = klhgL.z; + AF1 gL = klhgL.w; + AF1 oL = zzonL.z; + AF1 nL = zzonL.w; + // Accumulate for bilinear interpolation. + AF2 dir = AF2_(0.0); + AF1 len = AF1_(0.0); + FsrEasuSetF(dir, len, pp, true, false, false, false, bL, eL, fL, gL, jL); + FsrEasuSetF(dir, len, pp, false, true, false, false, cL, fL, gL, hL, kL); + FsrEasuSetF(dir, len, pp, false, false, true, false, fL, iL, jL, kL, nL); + FsrEasuSetF(dir, len, pp, false, false, false, true, gL, jL, kL, lL, oL); + //------------------------------------------------------------------------------------------------------------------------------ + // Normalize with approximation, and cleanup close to zero. + AF2 dir2 = dir * dir; + AF1 dirR = dir2.x + dir2.y; + AP1 zro = dirR < AF1_(1.0 / 32768.0); + dirR = APrxLoRsqF1(dirR); + dirR = zro ? AF1_(1.0) : dirR; + dir.x = zro ? AF1_(1.0) : dir.x; + dir *= AF2_(dirR); + // Transform from {0 to 2} to {0 to 1} range, and shape with square. + len = len * AF1_(0.5); + len *= len; + // Stretch kernel {1.0 vert|horz, to sqrt(2.0) on diagonal}. + AF1 stretch = (dir.x * dir.x + dir.y * dir.y) * APrxLoRcpF1(max(abs(dir.x), abs(dir.y))); + // Anisotropic length after rotation, + // x := 1.0 lerp to 'stretch' on edges + // y := 1.0 lerp to 2x on edges + AF2 len2 = AF2(AF1_(1.0) + (stretch - AF1_(1.0)) * len, AF1_(1.0) + AF1_(-0.5) * len); + // Based on the amount of 'edge', + // the window shifts from +/-{sqrt(2.0) to slightly beyond 2.0}. + AF1 lob = AF1_(0.5) + AF1_((1.0 / 4.0 - 0.04) - 0.5) * len; + // Set distance^2 clipping point to the end of the adjustable window. + AF1 clp = APrxLoRcpF1(lob); + //------------------------------------------------------------------------------------------------------------------------------ + // Accumulation mixed with min/max of 4 nearest. + // b c + // e f g h + // i j k l + // n o + AF3 min4 = min(AMin3F3(AF3(ijfeR.z, ijfeG.z, ijfeB.z), AF3(klhgR.w, klhgG.w, klhgB.w), AF3(ijfeR.y, ijfeG.y, ijfeB.y)), + AF3(klhgR.x, klhgG.x, klhgB.x)); + AF3 max4 = max(AMax3F3(AF3(ijfeR.z, ijfeG.z, ijfeB.z), AF3(klhgR.w, klhgG.w, klhgB.w), AF3(ijfeR.y, ijfeG.y, ijfeB.y)), + AF3(klhgR.x, klhgG.x, klhgB.x)); + // Accumulation. + AF3 aC = AF3_(0.0); + AF1 aW = AF1_(0.0); + FsrEasuTapF(aC, aW, AF2(0.0, -1.0) - pp, dir, len2, lob, clp, AF3(bczzR.x, bczzG.x, bczzB.x)); // b + FsrEasuTapF(aC, aW, AF2(1.0, -1.0) - pp, dir, len2, lob, clp, AF3(bczzR.y, bczzG.y, bczzB.y)); // c + FsrEasuTapF(aC, aW, AF2(-1.0, 1.0) - pp, dir, len2, lob, clp, AF3(ijfeR.x, ijfeG.x, ijfeB.x)); // i + FsrEasuTapF(aC, aW, AF2(0.0, 1.0) - pp, dir, len2, lob, clp, AF3(ijfeR.y, ijfeG.y, ijfeB.y)); // j + FsrEasuTapF(aC, aW, AF2(0.0, 0.0) - pp, dir, len2, lob, clp, AF3(ijfeR.z, ijfeG.z, ijfeB.z)); // f + FsrEasuTapF(aC, aW, AF2(-1.0, 0.0) - pp, dir, len2, lob, clp, AF3(ijfeR.w, ijfeG.w, ijfeB.w)); // e + FsrEasuTapF(aC, aW, AF2(1.0, 1.0) - pp, dir, len2, lob, clp, AF3(klhgR.x, klhgG.x, klhgB.x)); // k + FsrEasuTapF(aC, aW, AF2(2.0, 1.0) - pp, dir, len2, lob, clp, AF3(klhgR.y, klhgG.y, klhgB.y)); // l + FsrEasuTapF(aC, aW, AF2(2.0, 0.0) - pp, dir, len2, lob, clp, AF3(klhgR.z, klhgG.z, klhgB.z)); // h + FsrEasuTapF(aC, aW, AF2(1.0, 0.0) - pp, dir, len2, lob, clp, AF3(klhgR.w, klhgG.w, klhgB.w)); // g + FsrEasuTapF(aC, aW, AF2(1.0, 2.0) - pp, dir, len2, lob, clp, AF3(zzonR.z, zzonG.z, zzonB.z)); // o + FsrEasuTapF(aC, aW, AF2(0.0, 2.0) - pp, dir, len2, lob, clp, AF3(zzonR.w, zzonG.w, zzonB.w)); // n + //------------------------------------------------------------------------------------------------------------------------------ + // Normalize and dering. + pix = min(max4, max(min4, aC * AF3_(ARcpF1(aW)))); +} +#endif + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// +// FSR - [RCAS] ROBUST CONTRAST ADAPTIVE SHARPENING +// +//------------------------------------------------------------------------------------------------------------------------------ +// CAS uses a simplified mechanism to convert local contrast into a variable amount of sharpness. +// RCAS uses a more exact mechanism, solving for the maximum local sharpness possible before clipping. +// RCAS also has a built in process to limit sharpening of what it detects as possible noise. +// RCAS sharper does not support scaling, as it should be applied after EASU scaling. +// Pass EASU output straight into RCAS, no color conversions necessary. +//------------------------------------------------------------------------------------------------------------------------------ +// RCAS is based on the following logic. +// RCAS uses a 5 tap filter in a cross pattern (same as CAS), +// w n +// w 1 w for taps w m e +// w s +// Where 'w' is the negative lobe weight. +// output = (w*(n+e+w+s)+m)/(4*w+1) +// RCAS solves for 'w' by seeing where the signal might clip out of the {0 to 1} input range, +// 0 == (w*(n+e+w+s)+m)/(4*w+1) -> w = -m/(n+e+w+s) +// 1 == (w*(n+e+w+s)+m)/(4*w+1) -> w = (1-m)/(n+e+w+s-4*1) +// Then chooses the 'w' which results in no clipping, limits 'w', and multiplies by the 'sharp' amount. +// This solution above has issues with MSAA input as the steps along the gradient cause edge detection issues. +// So RCAS uses 4x the maximum and 4x the minimum (depending on equation)in place of the individual taps. +// As well as switching from 'm' to either the minimum or maximum (depending on side), to help in energy conservation. +// This stabilizes RCAS. +// RCAS does a simple highpass which is normalized against the local contrast then shaped, +// 0.25 +// 0.25 -1 0.25 +// 0.25 +// This is used as a noise detection filter, to reduce the effect of RCAS on grain, and focus on real edges. +// +// GLSL example for the required callbacks : +// +// AH4 FsrRcasLoadH(ASW2 p){return AH4(imageLoad(imgSrc,ASU2(p)));} +// void FsrRcasInputH(inout AH1 r,inout AH1 g,inout AH1 b) +// { +// //do any simple input color conversions here or leave empty if none needed +// } +// +// FsrRcasCon need to be called from the CPU or GPU to set up constants. +// Including a GPU example here, the 'con' value would be stored out to a constant buffer. +// +// AU4 con; +// FsrRcasCon(con, +// 0.0); // The scale is {0.0 := maximum sharpness, to N>0, where N is the number of stops (halving) of the reduction of sharpness}. +// --------------- +// RCAS sharpening supports a CAS-like pass-through alpha via, +// #define FSR_RCAS_PASSTHROUGH_ALPHA 1 +// RCAS also supports a define to enable a more expensive path to avoid some sharpening of noise. +// Would suggest it is better to apply film grain after RCAS sharpening (and after scaling) instead of using this define, +// #define FSR_RCAS_DENOISE 1 +//============================================================================================================================== +// This is set at the limit of providing unnatural results for sharpening. +#define FSR_RCAS_LIMIT (0.25-(1.0/16.0)) + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//_____________________________________________________________/\_______________________________________________________________ +//============================================================================================================================== +// NON-PACKED 32-BIT VERSION +//============================================================================================================================== +#if defined(A_GPU)&&defined(FSR_RCAS_F) + // Input callback prototypes that need to be implemented by calling shader +AF4 FsrRcasLoadF(ASU2 p); +void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b); +//------------------------------------------------------------------------------------------------------------------------------ +void FsrRcasF( + out AF1 pixR, // Output values, non-vector so port between RcasFilter() and RcasFilterH() is easy. + out AF1 pixG, + out AF1 pixB, +#ifdef FSR_RCAS_PASSTHROUGH_ALPHA + out AF1 pixA, +#endif + AU2 ip, // Integer pixel position in output. + AU4 con) { // Constant generated by RcasSetup(). + // Algorithm uses minimal 3x3 pixel neighborhood. + // b + // d e f + // h + ASU2 sp = ASU2(ip); + AF3 b = FsrRcasLoadF(sp + ASU2(0, -1)).rgb; + AF3 d = FsrRcasLoadF(sp + ASU2(-1, 0)).rgb; +#ifdef FSR_RCAS_PASSTHROUGH_ALPHA + AF4 ee = FsrRcasLoadF(sp); + AF3 e = ee.rgb; pixA = ee.a; +#else + AF3 e = FsrRcasLoadF(sp).rgb; +#endif + AF3 f = FsrRcasLoadF(sp + ASU2(1, 0)).rgb; + AF3 h = FsrRcasLoadF(sp + ASU2(0, 1)).rgb; + // Rename (32-bit) or regroup (16-bit). + AF1 bR = b.r; + AF1 bG = b.g; + AF1 bB = b.b; + AF1 dR = d.r; + AF1 dG = d.g; + AF1 dB = d.b; + AF1 eR = e.r; + AF1 eG = e.g; + AF1 eB = e.b; + AF1 fR = f.r; + AF1 fG = f.g; + AF1 fB = f.b; + AF1 hR = h.r; + AF1 hG = h.g; + AF1 hB = h.b; + // Run optional input transform. + FsrRcasInputF(bR, bG, bB); + FsrRcasInputF(dR, dG, dB); + FsrRcasInputF(eR, eG, eB); + FsrRcasInputF(fR, fG, fB); + FsrRcasInputF(hR, hG, hB); + // Luma times 2. + AF1 bL = bB * AF1_(0.5) + (bR * AF1_(0.5) + bG); + AF1 dL = dB * AF1_(0.5) + (dR * AF1_(0.5) + dG); + AF1 eL = eB * AF1_(0.5) + (eR * AF1_(0.5) + eG); + AF1 fL = fB * AF1_(0.5) + (fR * AF1_(0.5) + fG); + AF1 hL = hB * AF1_(0.5) + (hR * AF1_(0.5) + hG); + // Noise detection. + AF1 nz = AF1_(0.25) * bL + AF1_(0.25) * dL + AF1_(0.25) * fL + AF1_(0.25) * hL - eL; + nz = ASatF1(abs(nz) * APrxMedRcpF1(AMax3F1(AMax3F1(bL, dL, eL), fL, hL) - AMin3F1(AMin3F1(bL, dL, eL), fL, hL))); + nz = AF1_(-0.5) * nz + AF1_(1.0); + // Min and max of ring. + AF1 mn4R = min(AMin3F1(bR, dR, fR), hR); + AF1 mn4G = min(AMin3F1(bG, dG, fG), hG); + AF1 mn4B = min(AMin3F1(bB, dB, fB), hB); + AF1 mx4R = max(AMax3F1(bR, dR, fR), hR); + AF1 mx4G = max(AMax3F1(bG, dG, fG), hG); + AF1 mx4B = max(AMax3F1(bB, dB, fB), hB); + // Immediate constants for peak range. + AF2 peakC = AF2(1.0, -1.0 * 4.0); + // Limiters, these need to be high precision RCPs. + AF1 hitMinR = mn4R * ARcpF1(AF1_(4.0) * mx4R); + AF1 hitMinG = mn4G * ARcpF1(AF1_(4.0) * mx4G); + AF1 hitMinB = mn4B * ARcpF1(AF1_(4.0) * mx4B); + AF1 hitMaxR = (peakC.x - mx4R) * ARcpF1(AF1_(4.0) * mn4R + peakC.y); + AF1 hitMaxG = (peakC.x - mx4G) * ARcpF1(AF1_(4.0) * mn4G + peakC.y); + AF1 hitMaxB = (peakC.x - mx4B) * ARcpF1(AF1_(4.0) * mn4B + peakC.y); + AF1 lobeR = max(-hitMinR, hitMaxR); + AF1 lobeG = max(-hitMinG, hitMaxG); + AF1 lobeB = max(-hitMinB, hitMaxB); + AF1 lobe = max(AF1_(-FSR_RCAS_LIMIT), min(AMax3F1(lobeR, lobeG, lobeB), AF1_(0.0))) * AF1_AU1(con.x); + // Apply noise removal. +#ifdef FSR_RCAS_DENOISE + lobe *= nz; +#endif + // Resolve, which needs the medium precision rcp approximation to avoid visible tonality changes. + AF1 rcpL = APrxMedRcpF1(AF1_(4.0) * lobe + AF1_(1.0)); + pixR = (lobe * bR + lobe * dR + lobe * hR + lobe * fR + eR) * rcpL; + pixG = (lobe * bG + lobe * dG + lobe * hG + lobe * fG + eG) * rcpL; + pixB = (lobe * bB + lobe * dB + lobe * hB + lobe * fB + eB) * rcpL; + return; +} +#endif + diff --git a/MODULE_Common/test.hlsl b/MODULE_Common/test.hlsl new file mode 100644 index 000000000..74c219494 --- /dev/null +++ b/MODULE_Common/test.hlsl @@ -0,0 +1,2002 @@ +#line 1 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\FfxEasuShader.hlsl" +cbuffer constants : register ( b0 ) { + int2 srcSize : packoffset ( c0 . x ) ; + int2 destSize : packoffset ( c0 . z ) ; +} ; + + + + +#line 1 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\EffectCommon\\common.hlsli" + + + + + + + + + + + + + + + +#line 18 + + + + + + +#line 25 + + +#line 33 + + +static float2 maxCoord0 ; + + +#line 90 + + + + + +#line 1 "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.19041.0\\um\\d2d1effecthelpers.hlsli" + + +#line 27 + + +#line 30 + +Texture2D < float4 > InputTexture0 : register ( t0 ) ; SamplerState InputSampler0 : register ( s0 ) ; + + +#line 35 + + +#line 38 + + +#line 41 + + +#line 44 + + +#line 47 + + +#line 50 + + +#line 53 + + + + +#line 60 + + +#line 64 + + +#line 69 + +static float4 __d2dstatic_scenePos = float4 ( 0 , 0 , 0 , 0 ) ; + + +#line 75 + + + +static float4 __d2dstatic_input0 = float4 ( 0 , 0 , 0 , 0 ) ; static float4 __d2dstatic_uv0 = float4 ( 0 , 0 , 0 , 0 ) ; + + +#line 82 + + +#line 85 + + +#line 88 + + +#line 91 + + +#line 94 + + +#line 97 + + +#line 100 + + +#line 105 + + +#line 109 + + + + + +#line 116 + + +#line 124 + + + + + + + + + + +#line 139 + + + + + + +#line 148 + + + + + + +#line 157 + + + + + + +#line 166 + + + + + + +#line 175 + + + + + + +#line 184 + + + + + + +#line 193 + + + + + + +#line 202 + + + + + + +#line 211 + + + + + + +#line 221 + + + + +#line 245 + + + + + + +#line 253 + + +#line 276 + + +#line 279 + + + + +#line 284 +float4 D2D_ENTRY_Impl ( ) ; + +#line 287 +float4 D2D_ENTRY ( float4 pos : SV_POSITION , float4 __d2dinput_scenePos : SCENE_POSITION , float4 __d2dinput_uv0 : TEXCOORD0 ) : SV_TARGET +{ + __d2dstatic_scenePos = __d2dinput_scenePos ; __d2dstatic_uv0 = __d2dinput_uv0 ; + return D2D_ENTRY_Impl ( ) ; +} + + + + + +#line 302 + +inline float4 D2DGetScenePosition ( ) +{ + return __d2dstatic_scenePos ; +} + + + + + + + + + + + + +#line 95 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\EffectCommon\\common.hlsli" + + + + + + +#line 102 + + +#line 105 + + + + + + + + + + + + +#line 118 + + +#line 122 +void InitMagpieSampleInput ( ) { + + maxCoord0 = float2 ( ( srcSize . x - 1 ) * ( __d2dstatic_uv0 ) . z , ( srcSize . y - 1 ) * ( __d2dstatic_uv0 ) . w ) ; + +#line 145 + + +} + +void InitMagpieSampleInputWithScale ( float2 scale ) { + InitMagpieSampleInput ( ) ; + +#line 153 + ( __d2dstatic_uv0 ) . xy /= scale ; +} + +#line 157 + + +#line 181 + + + +#line 10 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\FfxEasuShader.hlsl" + + + + + +#line 1 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\ffx_a.hlsli" + + +#line 94 + + +#line 110 + + +#line 131 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +uint AU1_AH1_AF1_x ( float a ) { return f32tof16 ( a ) ; } + + +uint AU1_AH2_AF2_x ( float2 a ) { return f32tof16 ( a . x ) | ( f32tof16 ( a . y ) << 16 ) ; } + + + +float2 AF2_AH2_AU1_x ( uint x ) { return float2 ( f16tof32 ( x & 0xFFFF ) , f16tof32 ( x >> 16 ) ) ; } + + +float AF1_x ( float a ) { return float ( a ) ; } +float2 AF2_x ( float a ) { return float2 ( a , a ) ; } +float3 AF3_x ( float a ) { return float3 ( a , a , a ) ; } +float4 AF4_x ( float a ) { return float4 ( a , a , a , a ) ; } + + + + + +uint AU1_x ( uint a ) { return uint ( a ) ; } +uint2 AU2_x ( uint a ) { return uint2 ( a , a ) ; } +uint3 AU3_x ( uint a ) { return uint3 ( a , a , a ) ; } +uint4 AU4_x ( uint a ) { return uint4 ( a , a , a , a ) ; } + + + + + +uint AAbsSU1 ( uint a ) { return uint ( abs ( int ( a ) ) ) ; } +uint2 AAbsSU2 ( uint2 a ) { return uint2 ( abs ( int2 ( a ) ) ) ; } +uint3 AAbsSU3 ( uint3 a ) { return uint3 ( abs ( int3 ( a ) ) ) ; } +uint4 AAbsSU4 ( uint4 a ) { return uint4 ( abs ( int4 ( a ) ) ) ; } + +uint ABfe ( uint src , uint off , uint bits ) { uint mask = ( 1u << bits ) - 1 ; return ( src >> off ) & mask ; } +uint ABfi ( uint src , uint ins , uint mask ) { return ( ins & mask ) | ( src & ( ~ mask ) ) ; } +uint ABfiM ( uint src , uint ins , uint bits ) { uint mask = ( 1u << bits ) - 1 ; return ( ins & mask ) | ( src & ( ~ mask ) ) ; } + +float AClampF1 ( float x , float n , float m ) { return max ( n , min ( x , m ) ) ; } +float2 AClampF2 ( float2 x , float2 n , float2 m ) { return max ( n , min ( x , m ) ) ; } +float3 AClampF3 ( float3 x , float3 n , float3 m ) { return max ( n , min ( x , m ) ) ; } +float4 AClampF4 ( float4 x , float4 n , float4 m ) { return max ( n , min ( x , m ) ) ; } + +float AFractF1 ( float x ) { return x - floor ( x ) ; } +float2 AFractF2 ( float2 x ) { return x - floor ( x ) ; } +float3 AFractF3 ( float3 x ) { return x - floor ( x ) ; } +float4 AFractF4 ( float4 x ) { return x - floor ( x ) ; } + +float ALerpF1 ( float x , float y , float a ) { return lerp ( x , y , a ) ; } +float2 ALerpF2 ( float2 x , float2 y , float2 a ) { return lerp ( x , y , a ) ; } +float3 ALerpF3 ( float3 x , float3 y , float3 a ) { return lerp ( x , y , a ) ; } +float4 ALerpF4 ( float4 x , float4 y , float4 a ) { return lerp ( x , y , a ) ; } + +float AMax3F1 ( float x , float y , float z ) { return max ( x , max ( y , z ) ) ; } +float2 AMax3F2 ( float2 x , float2 y , float2 z ) { return max ( x , max ( y , z ) ) ; } +float3 AMax3F3 ( float3 x , float3 y , float3 z ) { return max ( x , max ( y , z ) ) ; } +float4 AMax3F4 ( float4 x , float4 y , float4 z ) { return max ( x , max ( y , z ) ) ; } + +uint AMax3SU1 ( uint x , uint y , uint z ) { return uint ( max ( int ( x ) , max ( int ( y ) , int ( z ) ) ) ) ; } +uint2 AMax3SU2 ( uint2 x , uint2 y , uint2 z ) { return uint2 ( max ( int2 ( x ) , max ( int2 ( y ) , int2 ( z ) ) ) ) ; } +uint3 AMax3SU3 ( uint3 x , uint3 y , uint3 z ) { return uint3 ( max ( int3 ( x ) , max ( int3 ( y ) , int3 ( z ) ) ) ) ; } +uint4 AMax3SU4 ( uint4 x , uint4 y , uint4 z ) { return uint4 ( max ( int4 ( x ) , max ( int4 ( y ) , int4 ( z ) ) ) ) ; } + +uint AMax3U1 ( uint x , uint y , uint z ) { return max ( x , max ( y , z ) ) ; } +uint2 AMax3U2 ( uint2 x , uint2 y , uint2 z ) { return max ( x , max ( y , z ) ) ; } +uint3 AMax3U3 ( uint3 x , uint3 y , uint3 z ) { return max ( x , max ( y , z ) ) ; } +uint4 AMax3U4 ( uint4 x , uint4 y , uint4 z ) { return max ( x , max ( y , z ) ) ; } + +uint AMaxSU1 ( uint a , uint b ) { return uint ( max ( int ( a ) , int ( b ) ) ) ; } +uint2 AMaxSU2 ( uint2 a , uint2 b ) { return uint2 ( max ( int2 ( a ) , int2 ( b ) ) ) ; } +uint3 AMaxSU3 ( uint3 a , uint3 b ) { return uint3 ( max ( int3 ( a ) , int3 ( b ) ) ) ; } +uint4 AMaxSU4 ( uint4 a , uint4 b ) { return uint4 ( max ( int4 ( a ) , int4 ( b ) ) ) ; } + +float AMed3F1 ( float x , float y , float z ) { return max ( min ( x , y ) , min ( max ( x , y ) , z ) ) ; } +float2 AMed3F2 ( float2 x , float2 y , float2 z ) { return max ( min ( x , y ) , min ( max ( x , y ) , z ) ) ; } +float3 AMed3F3 ( float3 x , float3 y , float3 z ) { return max ( min ( x , y ) , min ( max ( x , y ) , z ) ) ; } +float4 AMed3F4 ( float4 x , float4 y , float4 z ) { return max ( min ( x , y ) , min ( max ( x , y ) , z ) ) ; } + +float AMin3F1 ( float x , float y , float z ) { return min ( x , min ( y , z ) ) ; } +float2 AMin3F2 ( float2 x , float2 y , float2 z ) { return min ( x , min ( y , z ) ) ; } +float3 AMin3F3 ( float3 x , float3 y , float3 z ) { return min ( x , min ( y , z ) ) ; } +float4 AMin3F4 ( float4 x , float4 y , float4 z ) { return min ( x , min ( y , z ) ) ; } + +uint AMin3SU1 ( uint x , uint y , uint z ) { return uint ( min ( int ( x ) , min ( int ( y ) , int ( z ) ) ) ) ; } +uint2 AMin3SU2 ( uint2 x , uint2 y , uint2 z ) { return uint2 ( min ( int2 ( x ) , min ( int2 ( y ) , int2 ( z ) ) ) ) ; } +uint3 AMin3SU3 ( uint3 x , uint3 y , uint3 z ) { return uint3 ( min ( int3 ( x ) , min ( int3 ( y ) , int3 ( z ) ) ) ) ; } +uint4 AMin3SU4 ( uint4 x , uint4 y , uint4 z ) { return uint4 ( min ( int4 ( x ) , min ( int4 ( y ) , int4 ( z ) ) ) ) ; } + +uint AMin3U1 ( uint x , uint y , uint z ) { return min ( x , min ( y , z ) ) ; } +uint2 AMin3U2 ( uint2 x , uint2 y , uint2 z ) { return min ( x , min ( y , z ) ) ; } +uint3 AMin3U3 ( uint3 x , uint3 y , uint3 z ) { return min ( x , min ( y , z ) ) ; } +uint4 AMin3U4 ( uint4 x , uint4 y , uint4 z ) { return min ( x , min ( y , z ) ) ; } + +uint AMinSU1 ( uint a , uint b ) { return uint ( min ( int ( a ) , int ( b ) ) ) ; } +uint2 AMinSU2 ( uint2 a , uint2 b ) { return uint2 ( min ( int2 ( a ) , int2 ( b ) ) ) ; } +uint3 AMinSU3 ( uint3 a , uint3 b ) { return uint3 ( min ( int3 ( a ) , int3 ( b ) ) ) ; } +uint4 AMinSU4 ( uint4 a , uint4 b ) { return uint4 ( min ( int4 ( a ) , int4 ( b ) ) ) ; } + +float ANCosF1 ( float x ) { return cos ( x * AF1_x ( float ( 6.28318530718 ) ) ) ; } +float2 ANCosF2 ( float2 x ) { return cos ( x * AF2_x ( float ( 6.28318530718 ) ) ) ; } +float3 ANCosF3 ( float3 x ) { return cos ( x * AF3_x ( float ( 6.28318530718 ) ) ) ; } +float4 ANCosF4 ( float4 x ) { return cos ( x * AF4_x ( float ( 6.28318530718 ) ) ) ; } + +float ANSinF1 ( float x ) { return sin ( x * AF1_x ( float ( 6.28318530718 ) ) ) ; } +float2 ANSinF2 ( float2 x ) { return sin ( x * AF2_x ( float ( 6.28318530718 ) ) ) ; } +float3 ANSinF3 ( float3 x ) { return sin ( x * AF3_x ( float ( 6.28318530718 ) ) ) ; } +float4 ANSinF4 ( float4 x ) { return sin ( x * AF4_x ( float ( 6.28318530718 ) ) ) ; } + +float ARcpF1 ( float x ) { return rcp ( x ) ; } +float2 ARcpF2 ( float2 x ) { return rcp ( x ) ; } +float3 ARcpF3 ( float3 x ) { return rcp ( x ) ; } +float4 ARcpF4 ( float4 x ) { return rcp ( x ) ; } + +float ARsqF1 ( float x ) { return rsqrt ( x ) ; } +float2 ARsqF2 ( float2 x ) { return rsqrt ( x ) ; } +float3 ARsqF3 ( float3 x ) { return rsqrt ( x ) ; } +float4 ARsqF4 ( float4 x ) { return rsqrt ( x ) ; } + +float ASatF1 ( float x ) { return saturate ( x ) ; } +float2 ASatF2 ( float2 x ) { return saturate ( x ) ; } +float3 ASatF3 ( float3 x ) { return saturate ( x ) ; } +float4 ASatF4 ( float4 x ) { return saturate ( x ) ; } + +uint AShrSU1 ( uint a , uint b ) { return uint ( int ( a ) >> int ( b ) ) ; } +uint2 AShrSU2 ( uint2 a , uint2 b ) { return uint2 ( int2 ( a ) >> int2 ( b ) ) ; } +uint3 AShrSU3 ( uint3 a , uint3 b ) { return uint3 ( int3 ( a ) >> int3 ( b ) ) ; } +uint4 AShrSU4 ( uint4 a , uint4 b ) { return uint4 ( int4 ( a ) >> int4 ( b ) ) ; } + +#line 296 + + +#line 312 + + + + + + + + + + + + + + + + + +#line 331 +min16float2 AH2_AU1_x ( uint x ) { float2 t = f16tof32 ( uint2 ( x & 0xFFFF , x >> 16 ) ) ; return min16float2 ( t ) ; } +min16float4 AH4_AU2_x ( uint2 x ) { return min16float4 ( AH2_AU1_x ( x . x ) , AH2_AU1_x ( x . y ) ) ; } +min16uint2 AW2_AU1_x ( uint x ) { uint2 t = uint2 ( x & 0xFFFF , x >> 16 ) ; return min16uint2 ( t ) ; } +min16uint4 AW4_AU2_x ( uint2 x ) { return min16uint4 ( AW2_AU1_x ( x . x ) , AW2_AU1_x ( x . y ) ) ; } + + + + + +uint AU1_AH2_x ( min16float2 x ) { return f32tof16 ( x . x ) + ( f32tof16 ( x . y ) << 16 ) ; } +uint2 AU2_AH4_x ( min16float4 x ) { return uint2 ( AU1_AH2_x ( x . xy ) , AU1_AH2_x ( x . zw ) ) ; } +uint AU1_AW2_x ( min16uint2 x ) { return uint ( x . x ) + ( uint ( x . y ) << 16 ) ; } +uint2 AU2_AW4_x ( min16uint4 x ) { return uint2 ( AU1_AW2_x ( x . xy ) , AU1_AW2_x ( x . zw ) ) ; } + + + + + +#line 354 + + + + + + + +#line 366 + + + + + + + +min16float AH1_x ( min16float a ) { return min16float ( a ) ; } +min16float2 AH2_x ( min16float a ) { return min16float2 ( a , a ) ; } +min16float3 AH3_x ( min16float a ) { return min16float3 ( a , a , a ) ; } +min16float4 AH4_x ( min16float a ) { return min16float4 ( a , a , a , a ) ; } + + + + + +min16uint AW1_x ( min16uint a ) { return min16uint ( a ) ; } +min16uint2 AW2_x ( min16uint a ) { return min16uint2 ( a , a ) ; } +min16uint3 AW3_x ( min16uint a ) { return min16uint3 ( a , a , a ) ; } +min16uint4 AW4_x ( min16uint a ) { return min16uint4 ( a , a , a , a ) ; } + + + + + +min16uint AAbsSW1 ( min16uint a ) { return min16uint ( abs ( min16int ( a ) ) ) ; } +min16uint2 AAbsSW2 ( min16uint2 a ) { return min16uint2 ( abs ( min16int2 ( a ) ) ) ; } +min16uint3 AAbsSW3 ( min16uint3 a ) { return min16uint3 ( abs ( min16int3 ( a ) ) ) ; } +min16uint4 AAbsSW4 ( min16uint4 a ) { return min16uint4 ( abs ( min16int4 ( a ) ) ) ; } + +min16float AClampH1 ( min16float x , min16float n , min16float m ) { return max ( n , min ( x , m ) ) ; } +min16float2 AClampH2 ( min16float2 x , min16float2 n , min16float2 m ) { return max ( n , min ( x , m ) ) ; } +min16float3 AClampH3 ( min16float3 x , min16float3 n , min16float3 m ) { return max ( n , min ( x , m ) ) ; } +min16float4 AClampH4 ( min16float4 x , min16float4 n , min16float4 m ) { return max ( n , min ( x , m ) ) ; } + +#line 402 +min16float AFractH1 ( min16float x ) { return x - floor ( x ) ; } +min16float2 AFractH2 ( min16float2 x ) { return x - floor ( x ) ; } +min16float3 AFractH3 ( min16float3 x ) { return x - floor ( x ) ; } +min16float4 AFractH4 ( min16float4 x ) { return x - floor ( x ) ; } + +min16float ALerpH1 ( min16float x , min16float y , min16float a ) { return lerp ( x , y , a ) ; } +min16float2 ALerpH2 ( min16float2 x , min16float2 y , min16float2 a ) { return lerp ( x , y , a ) ; } +min16float3 ALerpH3 ( min16float3 x , min16float3 y , min16float3 a ) { return lerp ( x , y , a ) ; } +min16float4 ALerpH4 ( min16float4 x , min16float4 y , min16float4 a ) { return lerp ( x , y , a ) ; } + +min16float AMax3H1 ( min16float x , min16float y , min16float z ) { return max ( x , max ( y , z ) ) ; } +min16float2 AMax3H2 ( min16float2 x , min16float2 y , min16float2 z ) { return max ( x , max ( y , z ) ) ; } +min16float3 AMax3H3 ( min16float3 x , min16float3 y , min16float3 z ) { return max ( x , max ( y , z ) ) ; } +min16float4 AMax3H4 ( min16float4 x , min16float4 y , min16float4 z ) { return max ( x , max ( y , z ) ) ; } + +min16uint AMaxSW1 ( min16uint a , min16uint b ) { return min16uint ( max ( int ( a ) , int ( b ) ) ) ; } +min16uint2 AMaxSW2 ( min16uint2 a , min16uint2 b ) { return min16uint2 ( max ( int2 ( a ) , int2 ( b ) ) ) ; } +min16uint3 AMaxSW3 ( min16uint3 a , min16uint3 b ) { return min16uint3 ( max ( int3 ( a ) , int3 ( b ) ) ) ; } +min16uint4 AMaxSW4 ( min16uint4 a , min16uint4 b ) { return min16uint4 ( max ( int4 ( a ) , int4 ( b ) ) ) ; } + +min16float AMin3H1 ( min16float x , min16float y , min16float z ) { return min ( x , min ( y , z ) ) ; } +min16float2 AMin3H2 ( min16float2 x , min16float2 y , min16float2 z ) { return min ( x , min ( y , z ) ) ; } +min16float3 AMin3H3 ( min16float3 x , min16float3 y , min16float3 z ) { return min ( x , min ( y , z ) ) ; } +min16float4 AMin3H4 ( min16float4 x , min16float4 y , min16float4 z ) { return min ( x , min ( y , z ) ) ; } + +min16uint AMinSW1 ( min16uint a , min16uint b ) { return min16uint ( min ( int ( a ) , int ( b ) ) ) ; } +min16uint2 AMinSW2 ( min16uint2 a , min16uint2 b ) { return min16uint2 ( min ( int2 ( a ) , int2 ( b ) ) ) ; } +min16uint3 AMinSW3 ( min16uint3 a , min16uint3 b ) { return min16uint3 ( min ( int3 ( a ) , int3 ( b ) ) ) ; } +min16uint4 AMinSW4 ( min16uint4 a , min16uint4 b ) { return min16uint4 ( min ( int4 ( a ) , int4 ( b ) ) ) ; } + +min16float ARcpH1 ( min16float x ) { return rcp ( x ) ; } +min16float2 ARcpH2 ( min16float2 x ) { return rcp ( x ) ; } +min16float3 ARcpH3 ( min16float3 x ) { return rcp ( x ) ; } +min16float4 ARcpH4 ( min16float4 x ) { return rcp ( x ) ; } + +min16float ARsqH1 ( min16float x ) { return rsqrt ( x ) ; } +min16float2 ARsqH2 ( min16float2 x ) { return rsqrt ( x ) ; } +min16float3 ARsqH3 ( min16float3 x ) { return rsqrt ( x ) ; } +min16float4 ARsqH4 ( min16float4 x ) { return rsqrt ( x ) ; } + +min16float ASatH1 ( min16float x ) { return saturate ( x ) ; } +min16float2 ASatH2 ( min16float2 x ) { return saturate ( x ) ; } +min16float3 ASatH3 ( min16float3 x ) { return saturate ( x ) ; } +min16float4 ASatH4 ( min16float4 x ) { return saturate ( x ) ; } + +min16uint AShrSW1 ( min16uint a , min16uint b ) { return min16uint ( min16int ( a ) >> min16int ( b ) ) ; } +min16uint2 AShrSW2 ( min16uint2 a , min16uint2 b ) { return min16uint2 ( min16int2 ( a ) >> min16int2 ( b ) ) ; } +min16uint3 AShrSW3 ( min16uint3 a , min16uint3 b ) { return min16uint3 ( min16int3 ( a ) >> min16int3 ( b ) ) ; } +min16uint4 AShrSW4 ( min16uint4 a , min16uint4 b ) { return min16uint4 ( min16int4 ( a ) >> min16int4 ( b ) ) ; } + + +#line 467 + + + + + +#line 473 +float ACpySgnF1 ( float d , float s ) { return asfloat ( uint ( asuint ( float ( d ) ) | ( asuint ( float ( s ) ) & AU1_x ( uint ( 0x80000000u ) ) ) ) ) ; } +float2 ACpySgnF2 ( float2 d , float2 s ) { return asfloat ( uint2 ( asuint ( float2 ( d ) ) | ( asuint ( float2 ( s ) ) & AU2_x ( uint ( 0x80000000u ) ) ) ) ) ; } +float3 ACpySgnF3 ( float3 d , float3 s ) { return asfloat ( uint3 ( asuint ( float3 ( d ) ) | ( asuint ( float3 ( s ) ) & AU3_x ( uint ( 0x80000000u ) ) ) ) ) ; } +float4 ACpySgnF4 ( float4 d , float4 s ) { return asfloat ( uint4 ( asuint ( float4 ( d ) ) | ( asuint ( float4 ( s ) ) & AU4_x ( uint ( 0x80000000u ) ) ) ) ) ; } + +#line 486 +float ASignedF1 ( float m ) { return ASatF1 ( m * AF1_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float2 ASignedF2 ( float2 m ) { return ASatF2 ( m * AF2_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float3 ASignedF3 ( float3 m ) { return ASatF3 ( m * AF3_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float4 ASignedF4 ( float4 m ) { return ASatF4 ( m * AF4_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } + +float AGtZeroF1 ( float m ) { return ASatF1 ( m * AF1_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float2 AGtZeroF2 ( float2 m ) { return ASatF2 ( m * AF2_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float3 AGtZeroF3 ( float3 m ) { return ASatF3 ( m * AF3_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float4 AGtZeroF4 ( float4 m ) { return ASatF4 ( m * AF4_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } + + + +#line 500 + + + + + +#line 506 +min16float ACpySgnH1 ( min16float d , min16float s ) { return min16float ( f16tof32 ( uint ( min16uint ( f32tof16 ( float ( d ) ) ) | ( min16uint ( f32tof16 ( float ( s ) ) ) & AW1_x ( min16uint ( 0x8000u ) ) ) ) ) ) ; } +min16float2 ACpySgnH2 ( min16float2 d , min16float2 s ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( min16uint2 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) ) | ( min16uint2 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) ) & AW2_x ( min16uint ( 0x8000u ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint2 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) ) | ( min16uint2 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) ) & AW2_x ( min16uint ( 0x8000u ) ) ) ) . y ) ) ) ) ; } +min16float3 ACpySgnH3 ( min16float3 d , min16float3 s ) { return min16float3 ( min16float ( f16tof32 ( uint ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) ) | ( min16uint3 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) ) & AW3_x ( min16uint ( 0x8000u ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) ) | ( min16uint3 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) ) & AW3_x ( min16uint ( 0x8000u ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) ) | ( min16uint3 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) ) & AW3_x ( min16uint ( 0x8000u ) ) ) ) . z ) ) ) ) ; } +min16float4 ACpySgnH4 ( min16float4 d , min16float4 s ) { return min16float4 ( min16float ( f16tof32 ( uint ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . w ) ) ) ) | ( min16uint4 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . w ) ) ) ) & AW4_x ( min16uint ( 0x8000u ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . w ) ) ) ) | ( min16uint4 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . w ) ) ) ) & AW4_x ( min16uint ( 0x8000u ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . w ) ) ) ) | ( min16uint4 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . w ) ) ) ) & AW4_x ( min16uint ( 0x8000u ) ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( d ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( d ) . w ) ) ) ) | ( min16uint4 ( min16uint ( f32tof16 ( float ( ( s ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( s ) . w ) ) ) ) & AW4_x ( min16uint ( 0x8000u ) ) ) ) . w ) ) ) ) ; } + +min16float ASignedH1 ( min16float m ) { return ASatH1 ( m * AH1_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float2 ASignedH2 ( min16float2 m ) { return ASatH2 ( m * AH2_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float3 ASignedH3 ( min16float3 m ) { return ASatH3 ( m * AH3_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float4 ASignedH4 ( min16float4 m ) { return ASatH4 ( m * AH4_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } + +min16float AGtZeroH1 ( min16float m ) { return ASatH1 ( m * AH1_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float2 AGtZeroH2 ( min16float2 m ) { return ASatH2 ( m * AH2_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float3 AGtZeroH3 ( min16float3 m ) { return ASatH3 ( m * AH3_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float4 AGtZeroH4 ( min16float4 m ) { return ASatH4 ( m * AH4_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } + + +#line 538 +uint AFisToU1 ( uint x ) { return x ^ ( ( AShrSU1 ( x , AU1_x ( uint ( 31 ) ) ) ) | AU1_x ( uint ( 0x80000000 ) ) ) ; } +uint AFisFromU1 ( uint x ) { return x ^ ( ( ~ AShrSU1 ( x , AU1_x ( uint ( 31 ) ) ) ) | AU1_x ( uint ( 0x80000000 ) ) ) ; } + +#line 542 +uint AFisToHiU1 ( uint x ) { return x ^ ( ( AShrSU1 ( x , AU1_x ( uint ( 15 ) ) ) ) | AU1_x ( uint ( 0x80000000 ) ) ) ; } +uint AFisFromHiU1 ( uint x ) { return x ^ ( ( ~ AShrSU1 ( x , AU1_x ( uint ( 15 ) ) ) ) | AU1_x ( uint ( 0x80000000 ) ) ) ; } + + +min16uint AFisToW1 ( min16uint x ) { return x ^ ( ( AShrSW1 ( x , AW1_x ( min16uint ( 15 ) ) ) ) | AW1_x ( min16uint ( 0x8000 ) ) ) ; } +min16uint AFisFromW1 ( min16uint x ) { return x ^ ( ( ~ AShrSW1 ( x , AW1_x ( min16uint ( 15 ) ) ) ) | AW1_x ( min16uint ( 0x8000 ) ) ) ; } + +min16uint2 AFisToW2 ( min16uint2 x ) { return x ^ ( ( AShrSW2 ( x , AW2_x ( min16uint ( 15 ) ) ) ) | AW2_x ( min16uint ( 0x8000 ) ) ) ; } +min16uint2 AFisFromW2 ( min16uint2 x ) { return x ^ ( ( ~ AShrSW2 ( x , AW2_x ( min16uint ( 15 ) ) ) ) | AW2_x ( min16uint ( 0x8000 ) ) ) ; } + + +#line 569 + +uint APerm0E0A ( uint2 i ) { return ( ( i . x ) & 0xffu ) | ( ( i . y << 16 ) & 0xff0000u ) ; } +uint APerm0F0B ( uint2 i ) { return ( ( i . x >> 8 ) & 0xffu ) | ( ( i . y << 8 ) & 0xff0000u ) ; } +uint APerm0G0C ( uint2 i ) { return ( ( i . x >> 16 ) & 0xffu ) | ( ( i . y ) & 0xff0000u ) ; } +uint APerm0H0D ( uint2 i ) { return ( ( i . x >> 24 ) & 0xffu ) | ( ( i . y >> 8 ) & 0xff0000u ) ; } + +uint APermHGFA ( uint2 i ) { return ( ( i . x ) & 0x000000ffu ) | ( i . y & 0xffffff00u ) ; } +uint APermHGFC ( uint2 i ) { return ( ( i . x >> 16 ) & 0x000000ffu ) | ( i . y & 0xffffff00u ) ; } +uint APermHGAE ( uint2 i ) { return ( ( i . x << 8 ) & 0x0000ff00u ) | ( i . y & 0xffff00ffu ) ; } +uint APermHGCE ( uint2 i ) { return ( ( i . x >> 8 ) & 0x0000ff00u ) | ( i . y & 0xffff00ffu ) ; } +uint APermHAFE ( uint2 i ) { return ( ( i . x << 16 ) & 0x00ff0000u ) | ( i . y & 0xff00ffffu ) ; } +uint APermHCFE ( uint2 i ) { return ( ( i . x ) & 0x00ff0000u ) | ( i . y & 0xff00ffffu ) ; } +uint APermAGFE ( uint2 i ) { return ( ( i . x << 24 ) & 0xff000000u ) | ( i . y & 0x00ffffffu ) ; } +uint APermCGFE ( uint2 i ) { return ( ( i . x << 8 ) & 0xff000000u ) | ( i . y & 0x00ffffffu ) ; } + +uint APermGCEA ( uint2 i ) { return ( ( i . x ) & 0x00ff00ffu ) | ( ( i . y << 8 ) & 0xff00ff00u ) ; } +uint APermGECA ( uint2 i ) { return ( ( ( i . x ) & 0xffu ) | ( ( i . x >> 8 ) & 0xff00u ) | ( ( i . y << 16 ) & 0xff0000u ) | ( ( i . y << 8 ) & 0xff000000u ) ) ; } + + +#line 646 + + + + + +#line 652 +uint ABuc0ToU1 ( uint d , float i ) { return ( d & 0xffffff00u ) | ( ( min ( uint ( i ) , 255u ) ) & ( 0x000000ffu ) ) ; } +uint ABuc1ToU1 ( uint d , float i ) { return ( d & 0xffff00ffu ) | ( ( min ( uint ( i ) , 255u ) << 8 ) & ( 0x0000ff00u ) ) ; } +uint ABuc2ToU1 ( uint d , float i ) { return ( d & 0xff00ffffu ) | ( ( min ( uint ( i ) , 255u ) << 16 ) & ( 0x00ff0000u ) ) ; } +uint ABuc3ToU1 ( uint d , float i ) { return ( d & 0x00ffffffu ) | ( ( min ( uint ( i ) , 255u ) << 24 ) & ( 0xff000000u ) ) ; } + +#line 658 +float ABuc0FromU1 ( uint i ) { return float ( ( i ) & 255u ) ; } +float ABuc1FromU1 ( uint i ) { return float ( ( i >> 8 ) & 255u ) ; } +float ABuc2FromU1 ( uint i ) { return float ( ( i >> 16 ) & 255u ) ; } +float ABuc3FromU1 ( uint i ) { return float ( ( i >> 24 ) & 255u ) ; } + + + + +min16uint2 ABuc01ToW2 ( min16float2 x , min16float2 y ) { + x *= AH2_x ( min16float ( 1.0 / 32768.0 ) ) ; y *= AH2_x ( min16float ( 1.0 / 32768.0 ) ) ; + return AW2_AU1_x ( uint ( APermGCEA ( uint2 ( AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( x ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( x ) . y ) ) ) ) ) ) , AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( y ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( y ) . y ) ) ) ) ) ) ) ) ) ) ; +} + +#line 672 +uint2 ABuc0ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHGFA ( uint2 ( d . x , b ) ) , APermHGFC ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABuc1ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHGAE ( uint2 ( d . x , b ) ) , APermHGCE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABuc2ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHAFE ( uint2 ( d . x , b ) ) , APermHCFE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABuc3ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermAGFE ( uint2 ( d . x , b ) ) , APermCGFE ( uint2 ( d . y , b ) ) ) ; +} + +#line 690 +min16float2 ABuc0FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) ; } +min16float2 ABuc1FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) ; } +min16float2 ABuc2FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) ; } +min16float2 ABuc3FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) ; } + + +#line 726 + + + + +uint ABsc0ToU1 ( uint d , float i ) { return ( d & 0xffffff00u ) | ( ( min ( uint ( i + 128.0 ) , 255u ) ) & ( 0x000000ffu ) ) ; } +uint ABsc1ToU1 ( uint d , float i ) { return ( d & 0xffff00ffu ) | ( ( min ( uint ( i + 128.0 ) , 255u ) << 8 ) & ( 0x0000ff00u ) ) ; } +uint ABsc2ToU1 ( uint d , float i ) { return ( d & 0xff00ffffu ) | ( ( min ( uint ( i + 128.0 ) , 255u ) << 16 ) & ( 0x00ff0000u ) ) ; } +uint ABsc3ToU1 ( uint d , float i ) { return ( d & 0x00ffffffu ) | ( ( min ( uint ( i + 128.0 ) , 255u ) << 24 ) & ( 0xff000000u ) ) ; } + +uint ABsc0ToZbU1 ( uint d , float i ) { return ( ( d & 0xffffff00u ) | ( ( min ( uint ( trunc ( i ) + 128.0 ) , 255u ) ) & ( 0x000000ffu ) ) ) ^ 0x00000080u ; } +uint ABsc1ToZbU1 ( uint d , float i ) { return ( ( d & 0xffff00ffu ) | ( ( min ( uint ( trunc ( i ) + 128.0 ) , 255u ) << 8 ) & ( 0x0000ff00u ) ) ) ^ 0x00008000u ; } +uint ABsc2ToZbU1 ( uint d , float i ) { return ( ( d & 0xff00ffffu ) | ( ( min ( uint ( trunc ( i ) + 128.0 ) , 255u ) << 16 ) & ( 0x00ff0000u ) ) ) ^ 0x00800000u ; } +uint ABsc3ToZbU1 ( uint d , float i ) { return ( ( d & 0x00ffffffu ) | ( ( min ( uint ( trunc ( i ) + 128.0 ) , 255u ) << 24 ) & ( 0xff000000u ) ) ) ^ 0x80000000u ; } + +float ABsc0FromU1 ( uint i ) { return float ( ( i ) & 255u ) - 128.0 ; } +float ABsc1FromU1 ( uint i ) { return float ( ( i >> 8 ) & 255u ) - 128.0 ; } +float ABsc2FromU1 ( uint i ) { return float ( ( i >> 16 ) & 255u ) - 128.0 ; } +float ABsc3FromU1 ( uint i ) { return float ( ( i >> 24 ) & 255u ) - 128.0 ; } + +float ABsc0FromZbU1 ( uint i ) { return float ( ( ( i ) & 255u ) ^ 0x80u ) - 128.0 ; } +float ABsc1FromZbU1 ( uint i ) { return float ( ( ( i >> 8 ) & 255u ) ^ 0x80u ) - 128.0 ; } +float ABsc2FromZbU1 ( uint i ) { return float ( ( ( i >> 16 ) & 255u ) ^ 0x80u ) - 128.0 ; } +float ABsc3FromZbU1 ( uint i ) { return float ( ( ( i >> 24 ) & 255u ) ^ 0x80u ) - 128.0 ; } + + + + +min16uint2 ABsc01ToW2 ( min16float2 x , min16float2 y ) { + x = x * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ; y = y * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ; + return AW2_AU1_x ( uint ( APermGCEA ( uint2 ( AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( x ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( x ) . y ) ) ) ) ) ) , AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( y ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( y ) . y ) ) ) ) ) ) ) ) ) ) ; +} + +uint2 ABsc0ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHGFA ( uint2 ( d . x , b ) ) , APermHGFC ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc1ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHGAE ( uint2 ( d . x , b ) ) , APermHGCE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc2ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermHAFE ( uint2 ( d . x , b ) ) , APermHCFE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc3ToU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ; + return uint2 ( APermAGFE ( uint2 ( d . x , b ) ) , APermCGFE ( uint2 ( d . y , b ) ) ) ; +} + +uint2 ABsc0ToZbU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ^ 0x00800080u ; + return uint2 ( APermHGFA ( uint2 ( d . x , b ) ) , APermHGFC ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc1ToZbU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ^ 0x00800080u ; + return uint2 ( APermHGAE ( uint2 ( d . x , b ) ) , APermHGCE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc2ToZbU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ^ 0x00800080u ; + return uint2 ( APermHAFE ( uint2 ( d . x , b ) ) , APermHCFE ( uint2 ( d . y , b ) ) ) ; +} +uint2 ABsc3ToZbU2 ( uint2 d , min16float2 i ) { + uint b = AU1_AW2_x ( min16uint2 ( min16uint2 ( min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( i * AH2_x ( min16float ( 1.0 / 32768.0 ) ) + AH2_x ( min16float ( 0.25 / 32768.0 ) ) ) . y ) ) ) ) ) ) ^ 0x00800080u ; + return uint2 ( APermAGFE ( uint2 ( d . x , b ) ) , APermCGFE ( uint2 ( d . y , b ) ) ) ; +} + +min16float2 ABsc0FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc1FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc2FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc3FromU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } + +min16float2 ABsc0FromZbU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ^ 0x00800080u ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0E0A ( i ) ^ 0x00800080u ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc1FromZbU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ^ 0x00800080u ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0F0B ( i ) ^ 0x00800080u ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc2FromZbU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ^ 0x00800080u ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0G0C ( i ) ^ 0x00800080u ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } +min16float2 ABsc3FromZbU2 ( uint2 i ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ^ 0x00800080u ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_AU1_x ( uint ( APerm0H0D ( i ) ^ 0x00800080u ) ) ) . y ) ) ) ) * AH2_x ( min16float ( 32768.0 ) ) - AH2_x ( min16float ( 0.25 ) ) ; } + + +#line 818 + + +#line 821 +min16float APrxLoSqrtH1 ( min16float a ) { return min16float ( f16tof32 ( uint ( ( min16uint ( f32tof16 ( float ( a ) ) ) >> AW1_x ( min16uint ( 1 ) ) ) + AW1_x ( min16uint ( 0x1de2 ) ) ) ) ) ; } +min16float2 APrxLoSqrtH2 ( min16float2 a ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( ( min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) >> AW2_x ( min16uint ( 1 ) ) ) + AW2_x ( min16uint ( 0x1de2 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) >> AW2_x ( min16uint ( 1 ) ) ) + AW2_x ( min16uint ( 0x1de2 ) ) ) . y ) ) ) ) ; } +min16float3 APrxLoSqrtH3 ( min16float3 a ) { return min16float3 ( min16float ( f16tof32 ( uint ( ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) + AW3_x ( min16uint ( 0x1de2 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) + AW3_x ( min16uint ( 0x1de2 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) + AW3_x ( min16uint ( 0x1de2 ) ) ) . z ) ) ) ) ; } +min16float4 APrxLoSqrtH4 ( min16float4 a ) { return min16float4 ( min16float ( f16tof32 ( uint ( ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) + AW4_x ( min16uint ( 0x1de2 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) + AW4_x ( min16uint ( 0x1de2 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) + AW4_x ( min16uint ( 0x1de2 ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) + AW4_x ( min16uint ( 0x1de2 ) ) ) . w ) ) ) ) ; } + +#line 828 +min16float APrxLoRcpH1 ( min16float a ) { return min16float ( f16tof32 ( uint ( AW1_x ( min16uint ( 0x7784 ) ) - min16uint ( f32tof16 ( float ( a ) ) ) ) ) ) ; } +min16float2 APrxLoRcpH2 ( min16float2 a ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x7784 ) ) - min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x7784 ) ) - min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) ) . y ) ) ) ) ; } +min16float3 APrxLoRcpH3 ( min16float3 a ) { return min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x7784 ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x7784 ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x7784 ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . z ) ) ) ) ; } +min16float4 APrxLoRcpH4 ( min16float4 a ) { return min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x7784 ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x7784 ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x7784 ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x7784 ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . w ) ) ) ) ; } + +#line 834 +min16float APrxMedRcpH1 ( min16float a ) { min16float b = min16float ( f16tof32 ( uint ( AW1_x ( min16uint ( 0x778d ) ) - min16uint ( f32tof16 ( float ( a ) ) ) ) ) ) ; return b * ( - b * a + AH1_x ( min16float ( 2.0 ) ) ) ; } +min16float2 APrxMedRcpH2 ( min16float2 a ) { min16float2 b = min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x778d ) ) - min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x778d ) ) - min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) ) . y ) ) ) ) ; return b * ( - b * a + AH2_x ( min16float ( 2.0 ) ) ) ; } +min16float3 APrxMedRcpH3 ( min16float3 a ) { min16float3 b = min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x778d ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x778d ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x778d ) ) - min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) ) . z ) ) ) ) ; return b * ( - b * a + AH3_x ( min16float ( 2.0 ) ) ) ; } +min16float4 APrxMedRcpH4 ( min16float4 a ) { min16float4 b = min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x778d ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x778d ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x778d ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x778d ) ) - min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) ) . w ) ) ) ) ; return b * ( - b * a + AH4_x ( min16float ( 2.0 ) ) ) ; } + +#line 840 +min16float APrxLoRsqH1 ( min16float a ) { return min16float ( f16tof32 ( uint ( AW1_x ( min16uint ( 0x59a3 ) ) - ( min16uint ( f32tof16 ( float ( a ) ) ) >> AW1_x ( min16uint ( 1 ) ) ) ) ) ) ; } +min16float2 APrxLoRsqH2 ( min16float2 a ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x59a3 ) ) - ( min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) >> AW2_x ( min16uint ( 1 ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 0x59a3 ) ) - ( min16uint2 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) ) >> AW2_x ( min16uint ( 1 ) ) ) ) . y ) ) ) ) ; } +min16float3 APrxLoRsqH3 ( min16float3 a ) { return min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x59a3 ) ) - ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x59a3 ) ) - ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 0x59a3 ) ) - ( min16uint3 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) ) >> AW3_x ( min16uint ( 1 ) ) ) ) . z ) ) ) ) ; } +min16float4 APrxLoRsqH4 ( min16float4 a ) { return min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x59a3 ) ) - ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x59a3 ) ) - ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x59a3 ) ) - ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 0x59a3 ) ) - ( min16uint4 ( min16uint ( f32tof16 ( float ( ( a ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( a ) . w ) ) ) ) >> AW4_x ( min16uint ( 1 ) ) ) ) . w ) ) ) ) ; } + + +#line 862 +float APrxLoSqrtF1 ( float a ) { return asfloat ( uint ( ( asuint ( float ( a ) ) >> AU1_x ( uint ( 1 ) ) ) + AU1_x ( uint ( 0x1fbc4639 ) ) ) ) ; } +float APrxLoRcpF1 ( float a ) { return asfloat ( uint ( AU1_x ( uint ( 0x7ef07ebb ) ) - asuint ( float ( a ) ) ) ) ; } +float APrxMedRcpF1 ( float a ) { float b = asfloat ( uint ( AU1_x ( uint ( 0x7ef19fff ) ) - asuint ( float ( a ) ) ) ) ; return b * ( - b * a + AF1_x ( float ( 2.0 ) ) ) ; } +float APrxLoRsqF1 ( float a ) { return asfloat ( uint ( AU1_x ( uint ( 0x5f347d74 ) ) - ( asuint ( float ( a ) ) >> AU1_x ( uint ( 1 ) ) ) ) ) ; } + +float2 APrxLoSqrtF2 ( float2 a ) { return asfloat ( uint2 ( ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 1 ) ) ) + AU2_x ( uint ( 0x1fbc4639 ) ) ) ) ; } +float2 APrxLoRcpF2 ( float2 a ) { return asfloat ( uint2 ( AU2_x ( uint ( 0x7ef07ebb ) ) - asuint ( float2 ( a ) ) ) ) ; } +float2 APrxMedRcpF2 ( float2 a ) { float2 b = asfloat ( uint2 ( AU2_x ( uint ( 0x7ef19fff ) ) - asuint ( float2 ( a ) ) ) ) ; return b * ( - b * a + AF2_x ( float ( 2.0 ) ) ) ; } +float2 APrxLoRsqF2 ( float2 a ) { return asfloat ( uint2 ( AU2_x ( uint ( 0x5f347d74 ) ) - ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 1 ) ) ) ) ) ; } + +float3 APrxLoSqrtF3 ( float3 a ) { return asfloat ( uint3 ( ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 1 ) ) ) + AU3_x ( uint ( 0x1fbc4639 ) ) ) ) ; } +float3 APrxLoRcpF3 ( float3 a ) { return asfloat ( uint3 ( AU3_x ( uint ( 0x7ef07ebb ) ) - asuint ( float3 ( a ) ) ) ) ; } +float3 APrxMedRcpF3 ( float3 a ) { float3 b = asfloat ( uint3 ( AU3_x ( uint ( 0x7ef19fff ) ) - asuint ( float3 ( a ) ) ) ) ; return b * ( - b * a + AF3_x ( float ( 2.0 ) ) ) ; } +float3 APrxLoRsqF3 ( float3 a ) { return asfloat ( uint3 ( AU3_x ( uint ( 0x5f347d74 ) ) - ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 1 ) ) ) ) ) ; } + +float4 APrxLoSqrtF4 ( float4 a ) { return asfloat ( uint4 ( ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 1 ) ) ) + AU4_x ( uint ( 0x1fbc4639 ) ) ) ) ; } +float4 APrxLoRcpF4 ( float4 a ) { return asfloat ( uint4 ( AU4_x ( uint ( 0x7ef07ebb ) ) - asuint ( float4 ( a ) ) ) ) ; } +float4 APrxMedRcpF4 ( float4 a ) { float4 b = asfloat ( uint4 ( AU4_x ( uint ( 0x7ef19fff ) ) - asuint ( float4 ( a ) ) ) ) ; return b * ( - b * a + AF4_x ( float ( 2.0 ) ) ) ; } +float4 APrxLoRsqF4 ( float4 a ) { return asfloat ( uint4 ( AU4_x ( uint ( 0x5f347d74 ) ) - ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 1 ) ) ) ) ) ; } + +#line 891 +float Quart ( float a ) { a = a * a ; return a * a ; } +float Oct ( float a ) { a = a * a ; a = a * a ; return a * a ; } +float2 Quart ( float2 a ) { a = a * a ; return a * a ; } +float2 Oct ( float2 a ) { a = a * a ; a = a * a ; return a * a ; } +float3 Quart ( float3 a ) { a = a * a ; return a * a ; } +float3 Oct ( float3 a ) { a = a * a ; a = a * a ; return a * a ; } +float4 Quart ( float4 a ) { a = a * a ; return a * a ; } +float4 Oct ( float4 a ) { a = a * a ; a = a * a ; return a * a ; } + +float APrxPQToGamma2 ( float a ) { return Quart ( a ) ; } +float APrxPQToLinear ( float a ) { return Oct ( a ) ; } +float APrxLoGamma2ToPQ ( float a ) { return asfloat ( uint ( ( asuint ( float ( a ) ) >> AU1_x ( uint ( 2 ) ) ) + AU1_x ( uint ( 0x2F9A4E46 ) ) ) ) ; } +float APrxMedGamma2ToPQ ( float a ) { float b = asfloat ( uint ( ( asuint ( float ( a ) ) >> AU1_x ( uint ( 2 ) ) ) + AU1_x ( uint ( 0x2F9A4E46 ) ) ) ) ; float b4 = Quart ( b ) ; return b - b * ( b4 - a ) / ( AF1_x ( float ( 4.0 ) ) * b4 ) ; } +float APrxHighGamma2ToPQ ( float a ) { return sqrt ( sqrt ( a ) ) ; } +float APrxLoLinearToPQ ( float a ) { return asfloat ( uint ( ( asuint ( float ( a ) ) >> AU1_x ( uint ( 3 ) ) ) + AU1_x ( uint ( 0x378D8723 ) ) ) ) ; } +float APrxMedLinearToPQ ( float a ) { float b = asfloat ( uint ( ( asuint ( float ( a ) ) >> AU1_x ( uint ( 3 ) ) ) + AU1_x ( uint ( 0x378D8723 ) ) ) ) ; float b8 = Oct ( b ) ; return b - b * ( b8 - a ) / ( AF1_x ( float ( 8.0 ) ) * b8 ) ; } +float APrxHighLinearToPQ ( float a ) { return sqrt ( sqrt ( sqrt ( a ) ) ) ; } + +float2 APrxPQToGamma2 ( float2 a ) { return Quart ( a ) ; } +float2 APrxPQToLinear ( float2 a ) { return Oct ( a ) ; } +float2 APrxLoGamma2ToPQ ( float2 a ) { return asfloat ( uint2 ( ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 2 ) ) ) + AU2_x ( uint ( 0x2F9A4E46 ) ) ) ) ; } +float2 APrxMedGamma2ToPQ ( float2 a ) { float2 b = asfloat ( uint2 ( ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 2 ) ) ) + AU2_x ( uint ( 0x2F9A4E46 ) ) ) ) ; float2 b4 = Quart ( b ) ; return b - b * ( b4 - a ) / ( AF1_x ( float ( 4.0 ) ) * b4 ) ; } +float2 APrxHighGamma2ToPQ ( float2 a ) { return sqrt ( sqrt ( a ) ) ; } +float2 APrxLoLinearToPQ ( float2 a ) { return asfloat ( uint2 ( ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 3 ) ) ) + AU2_x ( uint ( 0x378D8723 ) ) ) ) ; } +float2 APrxMedLinearToPQ ( float2 a ) { float2 b = asfloat ( uint2 ( ( asuint ( float2 ( a ) ) >> AU2_x ( uint ( 3 ) ) ) + AU2_x ( uint ( 0x378D8723 ) ) ) ) ; float2 b8 = Oct ( b ) ; return b - b * ( b8 - a ) / ( AF1_x ( float ( 8.0 ) ) * b8 ) ; } +float2 APrxHighLinearToPQ ( float2 a ) { return sqrt ( sqrt ( sqrt ( a ) ) ) ; } + +float3 APrxPQToGamma2 ( float3 a ) { return Quart ( a ) ; } +float3 APrxPQToLinear ( float3 a ) { return Oct ( a ) ; } +float3 APrxLoGamma2ToPQ ( float3 a ) { return asfloat ( uint3 ( ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 2 ) ) ) + AU3_x ( uint ( 0x2F9A4E46 ) ) ) ) ; } +float3 APrxMedGamma2ToPQ ( float3 a ) { float3 b = asfloat ( uint3 ( ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 2 ) ) ) + AU3_x ( uint ( 0x2F9A4E46 ) ) ) ) ; float3 b4 = Quart ( b ) ; return b - b * ( b4 - a ) / ( AF1_x ( float ( 4.0 ) ) * b4 ) ; } +float3 APrxHighGamma2ToPQ ( float3 a ) { return sqrt ( sqrt ( a ) ) ; } +float3 APrxLoLinearToPQ ( float3 a ) { return asfloat ( uint3 ( ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 3 ) ) ) + AU3_x ( uint ( 0x378D8723 ) ) ) ) ; } +float3 APrxMedLinearToPQ ( float3 a ) { float3 b = asfloat ( uint3 ( ( asuint ( float3 ( a ) ) >> AU3_x ( uint ( 3 ) ) ) + AU3_x ( uint ( 0x378D8723 ) ) ) ) ; float3 b8 = Oct ( b ) ; return b - b * ( b8 - a ) / ( AF1_x ( float ( 8.0 ) ) * b8 ) ; } +float3 APrxHighLinearToPQ ( float3 a ) { return sqrt ( sqrt ( sqrt ( a ) ) ) ; } + +float4 APrxPQToGamma2 ( float4 a ) { return Quart ( a ) ; } +float4 APrxPQToLinear ( float4 a ) { return Oct ( a ) ; } +float4 APrxLoGamma2ToPQ ( float4 a ) { return asfloat ( uint4 ( ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 2 ) ) ) + AU4_x ( uint ( 0x2F9A4E46 ) ) ) ) ; } +float4 APrxMedGamma2ToPQ ( float4 a ) { float4 b = asfloat ( uint4 ( ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 2 ) ) ) + AU4_x ( uint ( 0x2F9A4E46 ) ) ) ) ; float4 b4 = Quart ( b ) ; return b - b * ( b4 - a ) / ( AF1_x ( float ( 4.0 ) ) * b4 ) ; } +float4 APrxHighGamma2ToPQ ( float4 a ) { return sqrt ( sqrt ( a ) ) ; } +float4 APrxLoLinearToPQ ( float4 a ) { return asfloat ( uint4 ( ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 3 ) ) ) + AU4_x ( uint ( 0x378D8723 ) ) ) ) ; } +float4 APrxMedLinearToPQ ( float4 a ) { float4 b = asfloat ( uint4 ( ( asuint ( float4 ( a ) ) >> AU4_x ( uint ( 3 ) ) ) + AU4_x ( uint ( 0x378D8723 ) ) ) ) ; float4 b8 = Oct ( b ) ; return b - b * ( b8 - a ) / ( AF1_x ( float ( 8.0 ) ) * b8 ) ; } +float4 APrxHighLinearToPQ ( float4 a ) { return sqrt ( sqrt ( sqrt ( a ) ) ) ; } + +#line 944 + + +#line 947 +float APSinF1 ( float x ) { return x * abs ( x ) - x ; } +float2 APSinF2 ( float2 x ) { return x * abs ( x ) - x ; } +float APCosF1 ( float x ) { x = AFractF1 ( x * AF1_x ( float ( 0.5 ) ) + AF1_x ( float ( 0.75 ) ) ) ; x = x * AF1_x ( float ( 2.0 ) ) - AF1_x ( float ( 1.0 ) ) ; return APSinF1 ( x ) ; } +float2 APCosF2 ( float2 x ) { x = AFractF2 ( x * AF2_x ( float ( 0.5 ) ) + AF2_x ( float ( 0.75 ) ) ) ; x = x * AF2_x ( float ( 2.0 ) ) - AF2_x ( float ( 1.0 ) ) ; return APSinF2 ( x ) ; } +float2 APSinCosF1 ( float x ) { float y = AFractF1 ( x * AF1_x ( float ( 0.5 ) ) + AF1_x ( float ( 0.75 ) ) ) ; y = y * AF1_x ( float ( 2.0 ) ) - AF1_x ( float ( 1.0 ) ) ; return APSinF2 ( float2 ( x , y ) ) ; } + + + + +#line 958 +min16float APSinH1 ( min16float x ) { return x * abs ( x ) - x ; } +min16float2 APSinH2 ( min16float2 x ) { return x * abs ( x ) - x ; } +min16float APCosH1 ( min16float x ) { x = AFractH1 ( x * AH1_x ( min16float ( 0.5 ) ) + AH1_x ( min16float ( 0.75 ) ) ) ; x = x * AH1_x ( min16float ( 2.0 ) ) - AH1_x ( min16float ( 1.0 ) ) ; return APSinH1 ( x ) ; } +min16float2 APCosH2 ( min16float2 x ) { x = AFractH2 ( x * AH2_x ( min16float ( 0.5 ) ) + AH2_x ( min16float ( 0.75 ) ) ) ; x = x * AH2_x ( min16float ( 2.0 ) ) - AH2_x ( min16float ( 1.0 ) ) ; return APSinH2 ( x ) ; } +min16float2 APSinCosH1 ( min16float x ) { min16float y = AFractH1 ( x * AH1_x ( min16float ( 0.5 ) ) + AH1_x ( min16float ( 0.75 ) ) ) ; y = y * AH1_x ( min16float ( 2.0 ) ) - AH1_x ( min16float ( 1.0 ) ) ; return APSinH2 ( min16float2 ( x , y ) ) ; } + + +#line 987 + +uint AZolAndU1 ( uint x , uint y ) { return min ( x , y ) ; } +uint2 AZolAndU2 ( uint2 x , uint2 y ) { return min ( x , y ) ; } +uint3 AZolAndU3 ( uint3 x , uint3 y ) { return min ( x , y ) ; } +uint4 AZolAndU4 ( uint4 x , uint4 y ) { return min ( x , y ) ; } + +uint AZolNotU1 ( uint x ) { return x ^ AU1_x ( uint ( 1 ) ) ; } +uint2 AZolNotU2 ( uint2 x ) { return x ^ AU2_x ( uint ( 1 ) ) ; } +uint3 AZolNotU3 ( uint3 x ) { return x ^ AU3_x ( uint ( 1 ) ) ; } +uint4 AZolNotU4 ( uint4 x ) { return x ^ AU4_x ( uint ( 1 ) ) ; } + +uint AZolOrU1 ( uint x , uint y ) { return max ( x , y ) ; } +uint2 AZolOrU2 ( uint2 x , uint2 y ) { return max ( x , y ) ; } +uint3 AZolOrU3 ( uint3 x , uint3 y ) { return max ( x , y ) ; } +uint4 AZolOrU4 ( uint4 x , uint4 y ) { return max ( x , y ) ; } + +uint AZolF1ToU1 ( float x ) { return uint ( x ) ; } +uint2 AZolF2ToU2 ( float2 x ) { return uint2 ( x ) ; } +uint3 AZolF3ToU3 ( float3 x ) { return uint3 ( x ) ; } +uint4 AZolF4ToU4 ( float4 x ) { return uint4 ( x ) ; } + +#line 1009 +uint AZolNotF1ToU1 ( float x ) { return uint ( AF1_x ( float ( 1.0 ) ) - x ) ; } +uint2 AZolNotF2ToU2 ( float2 x ) { return uint2 ( AF2_x ( float ( 1.0 ) ) - x ) ; } +uint3 AZolNotF3ToU3 ( float3 x ) { return uint3 ( AF3_x ( float ( 1.0 ) ) - x ) ; } +uint4 AZolNotF4ToU4 ( float4 x ) { return uint4 ( AF4_x ( float ( 1.0 ) ) - x ) ; } + +float AZolU1ToF1 ( uint x ) { return float ( x ) ; } +float2 AZolU2ToF2 ( uint2 x ) { return float2 ( x ) ; } +float3 AZolU3ToF3 ( uint3 x ) { return float3 ( x ) ; } +float4 AZolU4ToF4 ( uint4 x ) { return float4 ( x ) ; } + +float AZolAndF1 ( float x , float y ) { return min ( x , y ) ; } +float2 AZolAndF2 ( float2 x , float2 y ) { return min ( x , y ) ; } +float3 AZolAndF3 ( float3 x , float3 y ) { return min ( x , y ) ; } +float4 AZolAndF4 ( float4 x , float4 y ) { return min ( x , y ) ; } + +float ASolAndNotF1 ( float x , float y ) { return ( - x ) * y + AF1_x ( float ( 1.0 ) ) ; } +float2 ASolAndNotF2 ( float2 x , float2 y ) { return ( - x ) * y + AF2_x ( float ( 1.0 ) ) ; } +float3 ASolAndNotF3 ( float3 x , float3 y ) { return ( - x ) * y + AF3_x ( float ( 1.0 ) ) ; } +float4 ASolAndNotF4 ( float4 x , float4 y ) { return ( - x ) * y + AF4_x ( float ( 1.0 ) ) ; } + +float AZolAndOrF1 ( float x , float y , float z ) { return ASatF1 ( x * y + z ) ; } +float2 AZolAndOrF2 ( float2 x , float2 y , float2 z ) { return ASatF2 ( x * y + z ) ; } +float3 AZolAndOrF3 ( float3 x , float3 y , float3 z ) { return ASatF3 ( x * y + z ) ; } +float4 AZolAndOrF4 ( float4 x , float4 y , float4 z ) { return ASatF4 ( x * y + z ) ; } + +float AZolGtZeroF1 ( float x ) { return ASatF1 ( x * AF1_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float2 AZolGtZeroF2 ( float2 x ) { return ASatF2 ( x * AF2_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float3 AZolGtZeroF3 ( float3 x ) { return ASatF3 ( x * AF3_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } +float4 AZolGtZeroF4 ( float4 x ) { return ASatF4 ( x * AF4_x ( float ( asfloat ( uint ( 0x7f800000u ) ) ) ) ) ; } + +float AZolNotF1 ( float x ) { return AF1_x ( float ( 1.0 ) ) - x ; } +float2 AZolNotF2 ( float2 x ) { return AF2_x ( float ( 1.0 ) ) - x ; } +float3 AZolNotF3 ( float3 x ) { return AF3_x ( float ( 1.0 ) ) - x ; } +float4 AZolNotF4 ( float4 x ) { return AF4_x ( float ( 1.0 ) ) - x ; } + +float AZolOrF1 ( float x , float y ) { return max ( x , y ) ; } +float2 AZolOrF2 ( float2 x , float2 y ) { return max ( x , y ) ; } +float3 AZolOrF3 ( float3 x , float3 y ) { return max ( x , y ) ; } +float4 AZolOrF4 ( float4 x , float4 y ) { return max ( x , y ) ; } + +float AZolSelF1 ( float x , float y , float z ) { float r = ( - x ) * z + z ; return x * y + r ; } +float2 AZolSelF2 ( float2 x , float2 y , float2 z ) { float2 r = ( - x ) * z + z ; return x * y + r ; } +float3 AZolSelF3 ( float3 x , float3 y , float3 z ) { float3 r = ( - x ) * z + z ; return x * y + r ; } +float4 AZolSelF4 ( float4 x , float4 y , float4 z ) { float4 r = ( - x ) * z + z ; return x * y + r ; } + +float AZolSignedF1 ( float x ) { return ASatF1 ( x * AF1_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float2 AZolSignedF2 ( float2 x ) { return ASatF2 ( x * AF2_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float3 AZolSignedF3 ( float3 x ) { return ASatF3 ( x * AF3_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } +float4 AZolSignedF4 ( float4 x ) { return ASatF4 ( x * AF4_x ( float ( asfloat ( uint ( 0xff800000u ) ) ) ) ) ; } + +float AZolZeroPassF1 ( float x , float y ) { return asfloat ( uint ( ( asuint ( float ( x ) ) != AU1_x ( uint ( 0 ) ) ) ? AU1_x ( uint ( 0 ) ) : asuint ( float ( y ) ) ) ) ; } +float2 AZolZeroPassF2 ( float2 x , float2 y ) { return asfloat ( uint2 ( ( asuint ( float2 ( x ) ) != AU2_x ( uint ( 0 ) ) ) ? AU2_x ( uint ( 0 ) ) : asuint ( float2 ( y ) ) ) ) ; } +float3 AZolZeroPassF3 ( float3 x , float3 y ) { return asfloat ( uint3 ( ( asuint ( float3 ( x ) ) != AU3_x ( uint ( 0 ) ) ) ? AU3_x ( uint ( 0 ) ) : asuint ( float3 ( y ) ) ) ) ; } +float4 AZolZeroPassF4 ( float4 x , float4 y ) { return asfloat ( uint4 ( ( asuint ( float4 ( x ) ) != AU4_x ( uint ( 0 ) ) ) ? AU4_x ( uint ( 0 ) ) : asuint ( float4 ( y ) ) ) ) ; } + + + +min16uint AZolAndW1 ( min16uint x , min16uint y ) { return min ( x , y ) ; } +min16uint2 AZolAndW2 ( min16uint2 x , min16uint2 y ) { return min ( x , y ) ; } +min16uint3 AZolAndW3 ( min16uint3 x , min16uint3 y ) { return min ( x , y ) ; } +min16uint4 AZolAndW4 ( min16uint4 x , min16uint4 y ) { return min ( x , y ) ; } + +min16uint AZolNotW1 ( min16uint x ) { return x ^ AW1_x ( min16uint ( 1 ) ) ; } +min16uint2 AZolNotW2 ( min16uint2 x ) { return x ^ AW2_x ( min16uint ( 1 ) ) ; } +min16uint3 AZolNotW3 ( min16uint3 x ) { return x ^ AW3_x ( min16uint ( 1 ) ) ; } +min16uint4 AZolNotW4 ( min16uint4 x ) { return x ^ AW4_x ( min16uint ( 1 ) ) ; } + +min16uint AZolOrW1 ( min16uint x , min16uint y ) { return max ( x , y ) ; } +min16uint2 AZolOrW2 ( min16uint2 x , min16uint2 y ) { return max ( x , y ) ; } +min16uint3 AZolOrW3 ( min16uint3 x , min16uint3 y ) { return max ( x , y ) ; } +min16uint4 AZolOrW4 ( min16uint4 x , min16uint4 y ) { return max ( x , y ) ; } + +#line 1082 +min16uint AZolH1ToW1 ( min16float x ) { return min16uint ( f32tof16 ( float ( x * min16float ( f16tof32 ( uint ( AW1_x ( min16uint ( 1 ) ) ) ) ) ) ) ) ; } +min16uint2 AZolH2ToW2 ( min16float2 x ) { return min16uint2 ( min16uint ( f32tof16 ( float ( ( x * min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 1 ) ) ) . y ) ) ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float2 ( min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW2_x ( min16uint ( 1 ) ) ) . y ) ) ) ) ) . y ) ) ) ) ; } +min16uint3 AZolH3ToW3 ( min16float3 x ) { return min16uint3 ( min16uint ( f32tof16 ( float ( ( x * min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . z ) ) ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . z ) ) ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float3 ( min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW3_x ( min16uint ( 1 ) ) ) . z ) ) ) ) ) . z ) ) ) ) ; } +min16uint4 AZolH4ToW4 ( min16float4 x ) { return min16uint4 ( min16uint ( f32tof16 ( float ( ( x * min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . w ) ) ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . w ) ) ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . w ) ) ) ) ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( x * min16float4 ( min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( AW4_x ( min16uint ( 1 ) ) ) . w ) ) ) ) ) . w ) ) ) ) ; } + +#line 1088 +min16float AZolW1ToH1 ( min16uint x ) { return min16float ( f16tof32 ( uint ( x * min16uint ( f32tof16 ( float ( AH1_x ( min16float ( 1.0 ) ) ) ) ) ) ) ) ; } +min16float2 AZolW2ToH2 ( min16uint2 x ) { return min16float2 ( min16float ( f16tof32 ( uint ( ( x * min16uint2 ( min16uint ( f32tof16 ( float ( ( AH2_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH2_x ( min16float ( 1.0 ) ) ) . y ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint2 ( min16uint ( f32tof16 ( float ( ( AH2_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH2_x ( min16float ( 1.0 ) ) ) . y ) ) ) ) ) . y ) ) ) ) ; } +min16float3 AZolW1ToH3 ( min16uint3 x ) { return min16float3 ( min16float ( f16tof32 ( uint ( ( x * min16uint3 ( min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . z ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint3 ( min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . z ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint3 ( min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH3_x ( min16float ( 1.0 ) ) ) . z ) ) ) ) ) . z ) ) ) ) ; } +min16float4 AZolW2ToH4 ( min16uint4 x ) { return min16float4 ( min16float ( f16tof32 ( uint ( ( x * min16uint4 ( min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . w ) ) ) ) ) . x ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint4 ( min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . w ) ) ) ) ) . y ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint4 ( min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . w ) ) ) ) ) . z ) ) ) , min16float ( f16tof32 ( uint ( ( x * min16uint4 ( min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . x ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . y ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . z ) ) ) , min16uint ( f32tof16 ( float ( ( AH4_x ( min16float ( 1.0 ) ) ) . w ) ) ) ) ) . w ) ) ) ) ; } + +min16float AZolAndH1 ( min16float x , min16float y ) { return min ( x , y ) ; } +min16float2 AZolAndH2 ( min16float2 x , min16float2 y ) { return min ( x , y ) ; } +min16float3 AZolAndH3 ( min16float3 x , min16float3 y ) { return min ( x , y ) ; } +min16float4 AZolAndH4 ( min16float4 x , min16float4 y ) { return min ( x , y ) ; } + +min16float ASolAndNotH1 ( min16float x , min16float y ) { return ( - x ) * y + AH1_x ( min16float ( 1.0 ) ) ; } +min16float2 ASolAndNotH2 ( min16float2 x , min16float2 y ) { return ( - x ) * y + AH2_x ( min16float ( 1.0 ) ) ; } +min16float3 ASolAndNotH3 ( min16float3 x , min16float3 y ) { return ( - x ) * y + AH3_x ( min16float ( 1.0 ) ) ; } +min16float4 ASolAndNotH4 ( min16float4 x , min16float4 y ) { return ( - x ) * y + AH4_x ( min16float ( 1.0 ) ) ; } + +min16float AZolAndOrH1 ( min16float x , min16float y , min16float z ) { return ASatH1 ( x * y + z ) ; } +min16float2 AZolAndOrH2 ( min16float2 x , min16float2 y , min16float2 z ) { return ASatH2 ( x * y + z ) ; } +min16float3 AZolAndOrH3 ( min16float3 x , min16float3 y , min16float3 z ) { return ASatH3 ( x * y + z ) ; } +min16float4 AZolAndOrH4 ( min16float4 x , min16float4 y , min16float4 z ) { return ASatH4 ( x * y + z ) ; } + +min16float AZolGtZeroH1 ( min16float x ) { return ASatH1 ( x * AH1_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float2 AZolGtZeroH2 ( min16float2 x ) { return ASatH2 ( x * AH2_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float3 AZolGtZeroH3 ( min16float3 x ) { return ASatH3 ( x * AH3_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } +min16float4 AZolGtZeroH4 ( min16float4 x ) { return ASatH4 ( x * AH4_x ( min16float ( min16float ( f16tof32 ( uint ( 0x7c00u ) ) ) ) ) ) ; } + +min16float AZolNotH1 ( min16float x ) { return AH1_x ( min16float ( 1.0 ) ) - x ; } +min16float2 AZolNotH2 ( min16float2 x ) { return AH2_x ( min16float ( 1.0 ) ) - x ; } +min16float3 AZolNotH3 ( min16float3 x ) { return AH3_x ( min16float ( 1.0 ) ) - x ; } +min16float4 AZolNotH4 ( min16float4 x ) { return AH4_x ( min16float ( 1.0 ) ) - x ; } + +min16float AZolOrH1 ( min16float x , min16float y ) { return max ( x , y ) ; } +min16float2 AZolOrH2 ( min16float2 x , min16float2 y ) { return max ( x , y ) ; } +min16float3 AZolOrH3 ( min16float3 x , min16float3 y ) { return max ( x , y ) ; } +min16float4 AZolOrH4 ( min16float4 x , min16float4 y ) { return max ( x , y ) ; } + +min16float AZolSelH1 ( min16float x , min16float y , min16float z ) { min16float r = ( - x ) * z + z ; return x * y + r ; } +min16float2 AZolSelH2 ( min16float2 x , min16float2 y , min16float2 z ) { min16float2 r = ( - x ) * z + z ; return x * y + r ; } +min16float3 AZolSelH3 ( min16float3 x , min16float3 y , min16float3 z ) { min16float3 r = ( - x ) * z + z ; return x * y + r ; } +min16float4 AZolSelH4 ( min16float4 x , min16float4 y , min16float4 z ) { min16float4 r = ( - x ) * z + z ; return x * y + r ; } + +min16float AZolSignedH1 ( min16float x ) { return ASatH1 ( x * AH1_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float2 AZolSignedH2 ( min16float2 x ) { return ASatH2 ( x * AH2_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float3 AZolSignedH3 ( min16float3 x ) { return ASatH3 ( x * AH3_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } +min16float4 AZolSignedH4 ( min16float4 x ) { return ASatH4 ( x * AH4_x ( min16float ( min16float ( f16tof32 ( uint ( 0xfc00u ) ) ) ) ) ) ; } + + +#line 1185 + +float ATo709F1 ( float c ) { + float3 j = float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; float2 k = float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . x , c * j . y , pow ( c , j . z ) * k . x + k . y ) ; +} +float2 ATo709F2 ( float2 c ) { + float3 j = float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; float2 k = float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . xx , c * j . yy , pow ( c , j . zz ) * k . xx + k . yy ) ; +} +float3 ATo709F3 ( float3 c ) { + float3 j = float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; float2 k = float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . xxx , c * j . yyy , pow ( c , j . zzz ) * k . xxx + k . yyy ) ; +} + +#line 1200 +float AToGammaF1 ( float c , float rcpX ) { return pow ( c , AF1_x ( float ( rcpX ) ) ) ; } +float2 AToGammaF2 ( float2 c , float rcpX ) { return pow ( c , AF2_x ( float ( rcpX ) ) ) ; } +float3 AToGammaF3 ( float3 c , float rcpX ) { return pow ( c , AF3_x ( float ( rcpX ) ) ) ; } + +float AToPqF1 ( float x ) { + float p = pow ( x , AF1_x ( float ( 0.159302 ) ) ) ; + return pow ( ( AF1_x ( float ( 0.835938 ) ) + AF1_x ( float ( 18.8516 ) ) * p ) / ( AF1_x ( float ( 1.0 ) ) + AF1_x ( float ( 18.6875 ) ) * p ) , AF1_x ( float ( 78.8438 ) ) ) ; +} +float2 AToPqF1 ( float2 x ) { + float2 p = pow ( x , AF2_x ( float ( 0.159302 ) ) ) ; + return pow ( ( AF2_x ( float ( 0.835938 ) ) + AF2_x ( float ( 18.8516 ) ) * p ) / ( AF2_x ( float ( 1.0 ) ) + AF2_x ( float ( 18.6875 ) ) * p ) , AF2_x ( float ( 78.8438 ) ) ) ; +} +float3 AToPqF1 ( float3 x ) { + float3 p = pow ( x , AF3_x ( float ( 0.159302 ) ) ) ; + return pow ( ( AF3_x ( float ( 0.835938 ) ) + AF3_x ( float ( 18.8516 ) ) * p ) / ( AF3_x ( float ( 1.0 ) ) + AF3_x ( float ( 18.6875 ) ) * p ) , AF3_x ( float ( 78.8438 ) ) ) ; +} + +float AToSrgbF1 ( float c ) { + float3 j = float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; float2 k = float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . x , c * j . y , pow ( c , j . z ) * k . x + k . y ) ; +} +float2 AToSrgbF2 ( float2 c ) { + float3 j = float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; float2 k = float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . xx , c * j . yy , pow ( c , j . zz ) * k . xx + k . yy ) ; +} +float3 AToSrgbF3 ( float3 c ) { + float3 j = float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; float2 k = float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . xxx , c * j . yyy , pow ( c , j . zzz ) * k . xxx + k . yyy ) ; +} + +float AToTwoF1 ( float c ) { return sqrt ( c ) ; } +float2 AToTwoF2 ( float2 c ) { return sqrt ( c ) ; } +float3 AToTwoF3 ( float3 c ) { return sqrt ( c ) ; } + +float AToThreeF1 ( float c ) { return pow ( c , AF1_x ( float ( 1.0 / 3.0 ) ) ) ; } +float2 AToThreeF2 ( float2 c ) { return pow ( c , AF2_x ( float ( 1.0 / 3.0 ) ) ) ; } +float3 AToThreeF3 ( float3 c ) { return pow ( c , AF3_x ( float ( 1.0 / 3.0 ) ) ) ; } + + + + +float AFrom709F1 ( float c ) { + float3 j = float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; float2 k = float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelF1 ( AZolSignedF1 ( c - j . x ) , c * j . y , pow ( c * k . x + k . y , j . z ) ) ; +} +float2 AFrom709F2 ( float2 c ) { + float3 j = float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; float2 k = float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelF2 ( AZolSignedF2 ( c - j . xx ) , c * j . yy , pow ( c * k . xx + k . yy , j . zz ) ) ; +} +float3 AFrom709F3 ( float3 c ) { + float3 j = float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; float2 k = float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelF3 ( AZolSignedF3 ( c - j . xxx ) , c * j . yyy , pow ( c * k . xxx + k . yyy , j . zzz ) ) ; +} + +float AFromGammaF1 ( float c , float x ) { return pow ( c , AF1_x ( float ( x ) ) ) ; } +float2 AFromGammaF2 ( float2 c , float x ) { return pow ( c , AF2_x ( float ( x ) ) ) ; } +float3 AFromGammaF3 ( float3 c , float x ) { return pow ( c , AF3_x ( float ( x ) ) ) ; } + +float AFromPqF1 ( float x ) { + float p = pow ( x , AF1_x ( float ( 0.0126833 ) ) ) ; + return pow ( ASatF1 ( p - AF1_x ( float ( 0.835938 ) ) ) / ( AF1_x ( float ( 18.8516 ) ) - AF1_x ( float ( 18.6875 ) ) * p ) , AF1_x ( float ( 6.27739 ) ) ) ; +} +float2 AFromPqF1 ( float2 x ) { + float2 p = pow ( x , AF2_x ( float ( 0.0126833 ) ) ) ; + return pow ( ASatF2 ( p - AF2_x ( float ( 0.835938 ) ) ) / ( AF2_x ( float ( 18.8516 ) ) - AF2_x ( float ( 18.6875 ) ) * p ) , AF2_x ( float ( 6.27739 ) ) ) ; +} +float3 AFromPqF1 ( float3 x ) { + float3 p = pow ( x , AF3_x ( float ( 0.0126833 ) ) ) ; + return pow ( ASatF3 ( p - AF3_x ( float ( 0.835938 ) ) ) / ( AF3_x ( float ( 18.8516 ) ) - AF3_x ( float ( 18.6875 ) ) * p ) , AF3_x ( float ( 6.27739 ) ) ) ; +} + +#line 1272 +float AFromSrgbF1 ( float c ) { + float3 j = float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; float2 k = float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelF1 ( AZolSignedF1 ( c - j . x ) , c * j . y , pow ( c * k . x + k . y , j . z ) ) ; +} +float2 AFromSrgbF2 ( float2 c ) { + float3 j = float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; float2 k = float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelF2 ( AZolSignedF2 ( c - j . xx ) , c * j . yy , pow ( c * k . xx + k . yy , j . zz ) ) ; +} +float3 AFromSrgbF3 ( float3 c ) { + float3 j = float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; float2 k = float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelF3 ( AZolSignedF3 ( c - j . xxx ) , c * j . yyy , pow ( c * k . xxx + k . yyy , j . zzz ) ) ; +} + +float AFromTwoF1 ( float c ) { return c * c ; } +float2 AFromTwoF2 ( float2 c ) { return c * c ; } +float3 AFromTwoF3 ( float3 c ) { return c * c ; } + +float AFromThreeF1 ( float c ) { return c * c * c ; } +float2 AFromThreeF2 ( float2 c ) { return c * c * c ; } +float3 AFromThreeF3 ( float3 c ) { return c * c * c ; } + + + +min16float ATo709H1 ( min16float c ) { + min16float3 j = min16float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; min16float2 k = min16float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . x , c * j . y , pow ( c , j . z ) * k . x + k . y ) ; +} +min16float2 ATo709H2 ( min16float2 c ) { + min16float3 j = min16float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; min16float2 k = min16float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . xx , c * j . yy , pow ( c , j . zz ) * k . xx + k . yy ) ; +} +min16float3 ATo709H3 ( min16float3 c ) { + min16float3 j = min16float3 ( 0.018 * 4.5 , 4.5 , 0.45 ) ; min16float2 k = min16float2 ( 1.099 , - 0.099 ) ; + return clamp ( j . xxx , c * j . yyy , pow ( c , j . zzz ) * k . xxx + k . yyy ) ; +} + +min16float AToGammaH1 ( min16float c , min16float rcpX ) { return pow ( c , AH1_x ( min16float ( rcpX ) ) ) ; } +min16float2 AToGammaH2 ( min16float2 c , min16float rcpX ) { return pow ( c , AH2_x ( min16float ( rcpX ) ) ) ; } +min16float3 AToGammaH3 ( min16float3 c , min16float rcpX ) { return pow ( c , AH3_x ( min16float ( rcpX ) ) ) ; } + +min16float AToSrgbH1 ( min16float c ) { + min16float3 j = min16float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; min16float2 k = min16float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . x , c * j . y , pow ( c , j . z ) * k . x + k . y ) ; +} +min16float2 AToSrgbH2 ( min16float2 c ) { + min16float3 j = min16float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; min16float2 k = min16float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . xx , c * j . yy , pow ( c , j . zz ) * k . xx + k . yy ) ; +} +min16float3 AToSrgbH3 ( min16float3 c ) { + min16float3 j = min16float3 ( 0.0031308 * 12.92 , 12.92 , 1.0 / 2.4 ) ; min16float2 k = min16float2 ( 1.055 , - 0.055 ) ; + return clamp ( j . xxx , c * j . yyy , pow ( c , j . zzz ) * k . xxx + k . yyy ) ; +} + +min16float AToTwoH1 ( min16float c ) { return sqrt ( c ) ; } +min16float2 AToTwoH2 ( min16float2 c ) { return sqrt ( c ) ; } +min16float3 AToTwoH3 ( min16float3 c ) { return sqrt ( c ) ; } + +min16float AToThreeF1 ( min16float c ) { return pow ( c , AH1_x ( min16float ( 1.0 / 3.0 ) ) ) ; } +min16float2 AToThreeF2 ( min16float2 c ) { return pow ( c , AH2_x ( min16float ( 1.0 / 3.0 ) ) ) ; } +min16float3 AToThreeF3 ( min16float3 c ) { return pow ( c , AH3_x ( min16float ( 1.0 / 3.0 ) ) ) ; } + + + +min16float AFrom709H1 ( min16float c ) { + min16float3 j = min16float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; min16float2 k = min16float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelH1 ( AZolSignedH1 ( c - j . x ) , c * j . y , pow ( c * k . x + k . y , j . z ) ) ; +} +min16float2 AFrom709H2 ( min16float2 c ) { + min16float3 j = min16float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; min16float2 k = min16float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelH2 ( AZolSignedH2 ( c - j . xx ) , c * j . yy , pow ( c * k . xx + k . yy , j . zz ) ) ; +} +min16float3 AFrom709H3 ( min16float3 c ) { + min16float3 j = min16float3 ( 0.081 / 4.5 , 1.0 / 4.5 , 1.0 / 0.45 ) ; min16float2 k = min16float2 ( 1.0 / 1.099 , 0.099 / 1.099 ) ; + return AZolSelH3 ( AZolSignedH3 ( c - j . xxx ) , c * j . yyy , pow ( c * k . xxx + k . yyy , j . zzz ) ) ; +} + +min16float AFromGammaH1 ( min16float c , min16float x ) { return pow ( c , AH1_x ( min16float ( x ) ) ) ; } +min16float2 AFromGammaH2 ( min16float2 c , min16float x ) { return pow ( c , AH2_x ( min16float ( x ) ) ) ; } +min16float3 AFromGammaH3 ( min16float3 c , min16float x ) { return pow ( c , AH3_x ( min16float ( x ) ) ) ; } + +min16float AHromSrgbF1 ( min16float c ) { + min16float3 j = min16float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; min16float2 k = min16float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelH1 ( AZolSignedH1 ( c - j . x ) , c * j . y , pow ( c * k . x + k . y , j . z ) ) ; +} +min16float2 AHromSrgbF2 ( min16float2 c ) { + min16float3 j = min16float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; min16float2 k = min16float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelH2 ( AZolSignedH2 ( c - j . xx ) , c * j . yy , pow ( c * k . xx + k . yy , j . zz ) ) ; +} +min16float3 AHromSrgbF3 ( min16float3 c ) { + min16float3 j = min16float3 ( 0.04045 / 12.92 , 1.0 / 12.92 , 2.4 ) ; min16float2 k = min16float2 ( 1.0 / 1.055 , 0.055 / 1.055 ) ; + return AZolSelH3 ( AZolSignedH3 ( c - j . xxx ) , c * j . yyy , pow ( c * k . xxx + k . yyy , j . zzz ) ) ; +} + +min16float AFromTwoH1 ( min16float c ) { return c * c ; } +min16float2 AFromTwoH2 ( min16float2 c ) { return c * c ; } +min16float3 AFromTwoH3 ( min16float3 c ) { return c * c ; } + +min16float AFromThreeH1 ( min16float c ) { return c * c * c ; } +min16float2 AFromThreeH2 ( min16float2 c ) { return c * c * c ; } +min16float3 AFromThreeH3 ( min16float3 c ) { return c * c * c ; } + + +#line 1384 +uint2 ARmp8x8 ( uint a ) { return uint2 ( ABfe ( a , 1u , 3u ) , ABfiM ( ABfe ( a , 3u , 3u ) , a , 1u ) ) ; } + +#line 1402 +uint2 ARmpRed8x8 ( uint a ) { return uint2 ( ABfiM ( ABfe ( a , 2u , 3u ) , a , 1u ) , ABfiM ( ABfe ( a , 3u , 3u ) , ABfe ( a , 1u , 2u ) , 2u ) ) ; } + + +min16uint2 ARmp8x8H ( uint a ) { return min16uint2 ( ABfe ( a , 1u , 3u ) , ABfiM ( ABfe ( a , 3u , 3u ) , a , 1u ) ) ; } +min16uint2 ARmpRed8x8H ( uint a ) { return min16uint2 ( ABfiM ( ABfe ( a , 2u , 3u ) , a , 1u ) , ABfiM ( ABfe ( a , 3u , 3u ) , ABfe ( a , 1u , 2u ) , 2u ) ) ; } + + + +#line 1492 + + + + + +#line 1502 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#line 1585 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +#line 1628 + + + +#line 1640 +float2 opAAbsF2 ( out float2 d , in float2 a ) { d = abs ( a ) ; return d ; } +float3 opAAbsF3 ( out float3 d , in float3 a ) { d = abs ( a ) ; return d ; } +float4 opAAbsF4 ( out float4 d , in float4 a ) { d = abs ( a ) ; return d ; } + +float2 opAAddF2 ( out float2 d , in float2 a , in float2 b ) { d = a + b ; return d ; } +float3 opAAddF3 ( out float3 d , in float3 a , in float3 b ) { d = a + b ; return d ; } +float4 opAAddF4 ( out float4 d , in float4 a , in float4 b ) { d = a + b ; return d ; } + +float2 opAAddOneF2 ( out float2 d , in float2 a , float b ) { d = a + AF2_x ( float ( b ) ) ; return d ; } +float3 opAAddOneF3 ( out float3 d , in float3 a , float b ) { d = a + AF3_x ( float ( b ) ) ; return d ; } +float4 opAAddOneF4 ( out float4 d , in float4 a , float b ) { d = a + AF4_x ( float ( b ) ) ; return d ; } + +float2 opACpyF2 ( out float2 d , in float2 a ) { d = a ; return d ; } +float3 opACpyF3 ( out float3 d , in float3 a ) { d = a ; return d ; } +float4 opACpyF4 ( out float4 d , in float4 a ) { d = a ; return d ; } + +float2 opALerpF2 ( out float2 d , in float2 a , in float2 b , in float2 c ) { d = ALerpF2 ( a , b , c ) ; return d ; } +float3 opALerpF3 ( out float3 d , in float3 a , in float3 b , in float3 c ) { d = ALerpF3 ( a , b , c ) ; return d ; } +float4 opALerpF4 ( out float4 d , in float4 a , in float4 b , in float4 c ) { d = ALerpF4 ( a , b , c ) ; return d ; } + +float2 opALerpOneF2 ( out float2 d , in float2 a , in float2 b , float c ) { d = ALerpF2 ( a , b , AF2_x ( float ( c ) ) ) ; return d ; } +float3 opALerpOneF3 ( out float3 d , in float3 a , in float3 b , float c ) { d = ALerpF3 ( a , b , AF3_x ( float ( c ) ) ) ; return d ; } +float4 opALerpOneF4 ( out float4 d , in float4 a , in float4 b , float c ) { d = ALerpF4 ( a , b , AF4_x ( float ( c ) ) ) ; return d ; } + +float2 opAMaxF2 ( out float2 d , in float2 a , in float2 b ) { d = max ( a , b ) ; return d ; } +float3 opAMaxF3 ( out float3 d , in float3 a , in float3 b ) { d = max ( a , b ) ; return d ; } +float4 opAMaxF4 ( out float4 d , in float4 a , in float4 b ) { d = max ( a , b ) ; return d ; } + +float2 opAMinF2 ( out float2 d , in float2 a , in float2 b ) { d = min ( a , b ) ; return d ; } +float3 opAMinF3 ( out float3 d , in float3 a , in float3 b ) { d = min ( a , b ) ; return d ; } +float4 opAMinF4 ( out float4 d , in float4 a , in float4 b ) { d = min ( a , b ) ; return d ; } + +float2 opAMulF2 ( out float2 d , in float2 a , in float2 b ) { d = a * b ; return d ; } +float3 opAMulF3 ( out float3 d , in float3 a , in float3 b ) { d = a * b ; return d ; } +float4 opAMulF4 ( out float4 d , in float4 a , in float4 b ) { d = a * b ; return d ; } + +float2 opAMulOneF2 ( out float2 d , in float2 a , float b ) { d = a * AF2_x ( float ( b ) ) ; return d ; } +float3 opAMulOneF3 ( out float3 d , in float3 a , float b ) { d = a * AF3_x ( float ( b ) ) ; return d ; } +float4 opAMulOneF4 ( out float4 d , in float4 a , float b ) { d = a * AF4_x ( float ( b ) ) ; return d ; } + +float2 opANegF2 ( out float2 d , in float2 a ) { d = - a ; return d ; } +float3 opANegF3 ( out float3 d , in float3 a ) { d = - a ; return d ; } +float4 opANegF4 ( out float4 d , in float4 a ) { d = - a ; return d ; } + +float2 opARcpF2 ( out float2 d , in float2 a ) { d = ARcpF2 ( a ) ; return d ; } +float3 opARcpF3 ( out float3 d , in float3 a ) { d = ARcpF3 ( a ) ; return d ; } +float4 opARcpF4 ( out float4 d , in float4 a ) { d = ARcpF4 ( a ) ; return d ; } + + + +#line 1688 + + +#line 14 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\FfxEasuShader.hlsl" + + + +min16float4 FsrEasuRH ( float2 p ) { + return min16float4 ( ( InputTexture0 . GatherRed ( InputSampler0 , ( p ) , ( 0 ) ) ) ) ; +} +min16float4 FsrEasuGH ( float2 p ) { + return min16float4 ( ( InputTexture0 . GatherGreen ( InputSampler0 , ( p ) , ( 0 ) ) ) ) ; +} +min16float4 FsrEasuBH ( float2 p ) { + return min16float4 ( ( InputTexture0 . GatherBlue ( InputSampler0 , ( p ) , ( 0 ) ) ) ) ; +} + +#line 28 + + +#line 1 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\ffx_fsr1.hlsli" + + +#line 156 +void FsrEasuCon ( +out uint4 con0 , +out uint4 con1 , +out uint4 con2 , +out uint4 con3 , + +float inputViewportInPixelsX , +float inputViewportInPixelsY , + +float inputSizeInPixelsX , +float inputSizeInPixelsY , + +float outputSizeInPixelsX , +float outputSizeInPixelsY ) { + + con0 [ 0 ] = asuint ( float ( inputViewportInPixelsX * ARcpF1 ( outputSizeInPixelsX ) ) ) ; + con0 [ 1 ] = asuint ( float ( inputViewportInPixelsY * ARcpF1 ( outputSizeInPixelsY ) ) ) ; + con0 [ 2 ] = asuint ( float ( AF1_x ( float ( 0.5 ) ) * inputViewportInPixelsX * ARcpF1 ( outputSizeInPixelsX ) - AF1_x ( float ( 0.5 ) ) ) ) ; + con0 [ 3 ] = asuint ( float ( AF1_x ( float ( 0.5 ) ) * inputViewportInPixelsY * ARcpF1 ( outputSizeInPixelsY ) - AF1_x ( float ( 0.5 ) ) ) ) ; + +#line 177 + con1 [ 0 ] = asuint ( float ( ARcpF1 ( inputSizeInPixelsX ) ) ) ; + con1 [ 1 ] = asuint ( float ( ARcpF1 ( inputSizeInPixelsY ) ) ) ; + +#line 193 + con1 [ 2 ] = asuint ( float ( AF1_x ( float ( 1.0 ) ) * ARcpF1 ( inputSizeInPixelsX ) ) ) ; + con1 [ 3 ] = asuint ( float ( AF1_x ( float ( - 1.0 ) ) * ARcpF1 ( inputSizeInPixelsY ) ) ) ; + + con2 [ 0 ] = asuint ( float ( AF1_x ( float ( - 1.0 ) ) * ARcpF1 ( inputSizeInPixelsX ) ) ) ; + con2 [ 1 ] = asuint ( float ( AF1_x ( float ( 2.0 ) ) * ARcpF1 ( inputSizeInPixelsY ) ) ) ; + con2 [ 2 ] = asuint ( float ( AF1_x ( float ( 1.0 ) ) * ARcpF1 ( inputSizeInPixelsX ) ) ) ; + con2 [ 3 ] = asuint ( float ( AF1_x ( float ( 2.0 ) ) * ARcpF1 ( inputSizeInPixelsY ) ) ) ; + con3 [ 0 ] = asuint ( float ( AF1_x ( float ( 0.0 ) ) * ARcpF1 ( inputSizeInPixelsX ) ) ) ; + con3 [ 1 ] = asuint ( float ( AF1_x ( float ( 4.0 ) ) * ARcpF1 ( inputSizeInPixelsY ) ) ) ; + con3 [ 2 ] = con3 [ 3 ] = 0 ; +} + +#line 206 +void FsrEasuConOffset ( +out uint4 con0 , +out uint4 con1 , +out uint4 con2 , +out uint4 con3 , + +float inputViewportInPixelsX , +float inputViewportInPixelsY , + +float inputSizeInPixelsX , +float inputSizeInPixelsY , + +float outputSizeInPixelsX , +float outputSizeInPixelsY , + +float inputOffsetInPixelsX , +float inputOffsetInPixelsY ) { + FsrEasuCon ( con0 , con1 , con2 , con3 , inputViewportInPixelsX , inputViewportInPixelsY , inputSizeInPixelsX , inputSizeInPixelsY , outputSizeInPixelsX , outputSizeInPixelsY ) ; + con0 [ 2 ] = asuint ( float ( AF1_x ( float ( 0.5 ) ) * inputViewportInPixelsX * ARcpF1 ( outputSizeInPixelsX ) - AF1_x ( float ( 0.5 ) ) + inputOffsetInPixelsX ) ) ; + con0 [ 3 ] = asuint ( float ( AF1_x ( float ( 0.5 ) ) * inputViewportInPixelsY * ARcpF1 ( outputSizeInPixelsY ) - AF1_x ( float ( 0.5 ) ) + inputOffsetInPixelsY ) ) ; +} + +#line 442 + + +#line 449 + + +min16float4 FsrEasuRH ( float2 p ) ; +min16float4 FsrEasuGH ( float2 p ) ; +min16float4 FsrEasuBH ( float2 p ) ; + +#line 456 +void FsrEasuTapH ( +inout min16float2 aCR , inout min16float2 aCG , inout min16float2 aCB , +inout min16float2 aW , +min16float2 offX , min16float2 offY , +min16float2 dir , +min16float2 len , +min16float lob , +min16float clp , +min16float2 cR , min16float2 cG , min16float2 cB ) { + min16float2 vX , vY ; + vX = offX * dir . xx + offY * dir . yy ; + vY = offX * ( - dir . yy ) + offY * dir . xx ; + vX *= len . x ; vY *= len . y ; + min16float2 d2 = vX * vX + vY * vY ; + d2 = min ( d2 , AH2_x ( min16float ( clp ) ) ) ; + min16float2 wB = AH2_x ( min16float ( 2.0 / 5.0 ) ) * d2 + AH2_x ( min16float ( - 1.0 ) ) ; + min16float2 wA = AH2_x ( min16float ( lob ) ) * d2 + AH2_x ( min16float ( - 1.0 ) ) ; + wB *= wB ; + wA *= wA ; + wB = AH2_x ( min16float ( 25.0 / 16.0 ) ) * wB + AH2_x ( min16float ( - ( 25.0 / 16.0 - 1.0 ) ) ) ; + min16float2 w = wB * wA ; + aCR += cR * w ; aCG += cG * w ; aCB += cB * w ; aW += w ; +} + +#line 481 +void FsrEasuSetH ( +inout min16float2 dirPX , inout min16float2 dirPY , +inout min16float2 lenP , +min16float2 pp , +bool biST , bool biUV , +min16float2 lA , min16float2 lB , min16float2 lC , min16float2 lD , min16float2 lE ) { + min16float2 w = AH2_x ( min16float ( 0.0 ) ) ; + if ( biST ) w = ( min16float2 ( 1.0 , 0.0 ) + min16float2 ( - pp . x , pp . x ) ) * AH2_x ( min16float ( AH1_x ( min16float ( 1.0 ) ) - pp . y ) ) ; + if ( biUV ) w = ( min16float2 ( 1.0 , 0.0 ) + min16float2 ( - pp . x , pp . x ) ) * AH2_x ( min16float ( pp . y ) ) ; + + min16float2 dc = lD - lC ; + min16float2 cb = lC - lB ; + min16float2 lenX = max ( abs ( dc ) , abs ( cb ) ) ; + lenX = ARcpH2 ( lenX ) ; + min16float2 dirX = lD - lB ; + dirPX += dirX * w ; + lenX = ASatH2 ( abs ( dirX ) * lenX ) ; + lenX *= lenX ; + lenP += lenX * w ; + min16float2 ec = lE - lC ; + min16float2 ca = lC - lA ; + min16float2 lenY = max ( abs ( ec ) , abs ( ca ) ) ; + lenY = ARcpH2 ( lenY ) ; + min16float2 dirY = lE - lA ; + dirPY += dirY * w ; + lenY = ASatH2 ( abs ( dirY ) * lenY ) ; + lenY *= lenY ; + lenP += lenY * w ; +} + +void FsrEasuH ( +out min16float3 pix , +uint2 ip , +uint4 con0 , +uint4 con1 , +uint4 con2 , +uint4 con3 ) { + + float2 pp = float2 ( ip ) * asfloat ( uint2 ( con0 . xy ) ) + asfloat ( uint2 ( con0 . zw ) ) ; + float2 fp = floor ( pp ) ; + pp -= fp ; + min16float2 ppp = min16float2 ( pp ) ; + + float2 p0 = fp * asfloat ( uint2 ( con1 . xy ) ) + asfloat ( uint2 ( con1 . zw ) ) ; + float2 p1 = p0 + asfloat ( uint2 ( con2 . xy ) ) ; + float2 p2 = p0 + asfloat ( uint2 ( con2 . zw ) ) ; + float2 p3 = p0 + asfloat ( uint2 ( con3 . xy ) ) ; + min16float4 bczzR = FsrEasuRH ( p0 ) ; + min16float4 bczzG = FsrEasuGH ( p0 ) ; + min16float4 bczzB = FsrEasuBH ( p0 ) ; + min16float4 ijfeR = FsrEasuRH ( p1 ) ; + min16float4 ijfeG = FsrEasuGH ( p1 ) ; + min16float4 ijfeB = FsrEasuBH ( p1 ) ; + min16float4 klhgR = FsrEasuRH ( p2 ) ; + min16float4 klhgG = FsrEasuGH ( p2 ) ; + min16float4 klhgB = FsrEasuBH ( p2 ) ; + min16float4 zzonR = FsrEasuRH ( p3 ) ; + min16float4 zzonG = FsrEasuGH ( p3 ) ; + min16float4 zzonB = FsrEasuBH ( p3 ) ; + + min16float4 bczzL = bczzB * AH4_x ( min16float ( 0.5 ) ) + ( bczzR * AH4_x ( min16float ( 0.5 ) ) + bczzG ) ; + min16float4 ijfeL = ijfeB * AH4_x ( min16float ( 0.5 ) ) + ( ijfeR * AH4_x ( min16float ( 0.5 ) ) + ijfeG ) ; + min16float4 klhgL = klhgB * AH4_x ( min16float ( 0.5 ) ) + ( klhgR * AH4_x ( min16float ( 0.5 ) ) + klhgG ) ; + min16float4 zzonL = zzonB * AH4_x ( min16float ( 0.5 ) ) + ( zzonR * AH4_x ( min16float ( 0.5 ) ) + zzonG ) ; + min16float bL = bczzL . x ; + min16float cL = bczzL . y ; + min16float iL = ijfeL . x ; + min16float jL = ijfeL . y ; + min16float fL = ijfeL . z ; + min16float eL = ijfeL . w ; + min16float kL = klhgL . x ; + min16float lL = klhgL . y ; + min16float hL = klhgL . z ; + min16float gL = klhgL . w ; + min16float oL = zzonL . z ; + min16float nL = zzonL . w ; + + min16float2 dirPX = AH2_x ( min16float ( 0.0 ) ) ; + min16float2 dirPY = AH2_x ( min16float ( 0.0 ) ) ; + min16float2 lenP = AH2_x ( min16float ( 0.0 ) ) ; + FsrEasuSetH ( dirPX , dirPY , lenP , ppp , true , false , min16float2 ( bL , cL ) , min16float2 ( eL , fL ) , min16float2 ( fL , gL ) , min16float2 ( gL , hL ) , min16float2 ( jL , kL ) ) ; + FsrEasuSetH ( dirPX , dirPY , lenP , ppp , false , true , min16float2 ( fL , gL ) , min16float2 ( iL , jL ) , min16float2 ( jL , kL ) , min16float2 ( kL , lL ) , min16float2 ( nL , oL ) ) ; + min16float2 dir = min16float2 ( dirPX . r + dirPX . g , dirPY . r + dirPY . g ) ; + min16float len = lenP . r + lenP . g ; + + min16float2 dir2 = dir * dir ; + min16float dirR = dir2 . x + dir2 . y ; + bool zro = dirR < AH1_x ( min16float ( 1.0 / 32768.0 ) ) ; + dirR = APrxLoRsqH1 ( dirR ) ; + dirR = zro ? AH1_x ( min16float ( 1.0 ) ) : dirR ; + dir . x = zro ? AH1_x ( min16float ( 1.0 ) ) : dir . x ; + dir *= AH2_x ( min16float ( dirR ) ) ; + len = len * AH1_x ( min16float ( 0.5 ) ) ; + len *= len ; + min16float stretch = ( dir . x * dir . x + dir . y * dir . y ) * APrxLoRcpH1 ( max ( abs ( dir . x ) , abs ( dir . y ) ) ) ; + min16float2 len2 = min16float2 ( AH1_x ( min16float ( 1.0 ) ) + ( stretch - AH1_x ( min16float ( 1.0 ) ) ) * len , AH1_x ( min16float ( 1.0 ) ) + AH1_x ( min16float ( - 0.5 ) ) * len ) ; + min16float lob = AH1_x ( min16float ( 0.5 ) ) + AH1_x ( min16float ( ( 1.0 / 4.0 - 0.04 ) - 0.5 ) ) * len ; + min16float clp = APrxLoRcpH1 ( lob ) ; + +#line 581 + min16float2 bothR = max ( max ( min16float2 ( - ijfeR . z , ijfeR . z ) , min16float2 ( - klhgR . w , klhgR . w ) ) , max ( min16float2 ( - ijfeR . y , ijfeR . y ) , min16float2 ( - klhgR . x , klhgR . x ) ) ) ; + min16float2 bothG = max ( max ( min16float2 ( - ijfeG . z , ijfeG . z ) , min16float2 ( - klhgG . w , klhgG . w ) ) , max ( min16float2 ( - ijfeG . y , ijfeG . y ) , min16float2 ( - klhgG . x , klhgG . x ) ) ) ; + min16float2 bothB = max ( max ( min16float2 ( - ijfeB . z , ijfeB . z ) , min16float2 ( - klhgB . w , klhgB . w ) ) , max ( min16float2 ( - ijfeB . y , ijfeB . y ) , min16float2 ( - klhgB . x , klhgB . x ) ) ) ; + + min16float2 pR = AH2_x ( min16float ( 0.0 ) ) ; + min16float2 pG = AH2_x ( min16float ( 0.0 ) ) ; + min16float2 pB = AH2_x ( min16float ( 0.0 ) ) ; + min16float2 pW = AH2_x ( min16float ( 0.0 ) ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( 0.0 , 1.0 ) - ppp . xx , min16float2 ( - 1.0 , - 1.0 ) - ppp . yy , dir , len2 , lob , clp , bczzR . xy , bczzG . xy , bczzB . xy ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( - 1.0 , 0.0 ) - ppp . xx , min16float2 ( 1.0 , 1.0 ) - ppp . yy , dir , len2 , lob , clp , ijfeR . xy , ijfeG . xy , ijfeB . xy ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( 0.0 , - 1.0 ) - ppp . xx , min16float2 ( 0.0 , 0.0 ) - ppp . yy , dir , len2 , lob , clp , ijfeR . zw , ijfeG . zw , ijfeB . zw ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( 1.0 , 2.0 ) - ppp . xx , min16float2 ( 1.0 , 1.0 ) - ppp . yy , dir , len2 , lob , clp , klhgR . xy , klhgG . xy , klhgB . xy ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( 2.0 , 1.0 ) - ppp . xx , min16float2 ( 0.0 , 0.0 ) - ppp . yy , dir , len2 , lob , clp , klhgR . zw , klhgG . zw , klhgB . zw ) ; + FsrEasuTapH ( pR , pG , pB , pW , min16float2 ( 1.0 , 0.0 ) - ppp . xx , min16float2 ( 2.0 , 2.0 ) - ppp . yy , dir , len2 , lob , clp , zzonR . zw , zzonG . zw , zzonB . zw ) ; + min16float3 aC = min16float3 ( pR . x + pR . y , pG . x + pG . y , pB . x + pB . y ) ; + min16float aW = pW . x + pW . y ; + +#line 599 + pix = min ( min16float3 ( bothR . y , bothG . y , bothB . y ) , max ( - min16float3 ( bothR . x , bothG . x , bothB . x ) , aC * AH3_x ( min16float ( ARcpH1 ( aW ) ) ) ) ) ; +} + + +#line 661 + + +#line 669 +void FsrRcasCon ( +out uint4 con , + +float sharpness ) { + + sharpness = exp2 ( float ( - sharpness ) ) ; + float2 hSharp = float2 ( sharpness , sharpness ) ; + con [ 0 ] = asuint ( float ( sharpness ) ) ; + con [ 1 ] = AU1_AH2_AF2_x ( float2 ( hSharp ) ) ; + con [ 2 ] = 0 ; + con [ 3 ] = 0 ; +} + +#line 779 + + +#line 786 + + +min16float4 FsrRcasLoadH ( min16int2 p ) ; +void FsrRcasInputH ( inout min16float r , inout min16float g , inout min16float b ) ; + +void FsrRcasH ( +out min16float pixR , +out min16float pixG , +out min16float pixB , + +#line 797 + +uint2 ip , +uint4 con ) { + +#line 804 + min16int2 sp = min16int2 ( ip ) ; + min16float3 b = FsrRcasLoadH ( sp + min16int2 ( 0 , - 1 ) ) . rgb ; + min16float3 d = FsrRcasLoadH ( sp + min16int2 ( - 1 , 0 ) ) . rgb ; + +#line 810 + + min16float3 e = FsrRcasLoadH ( sp ) . rgb ; + + min16float3 f = FsrRcasLoadH ( sp + min16int2 ( 1 , 0 ) ) . rgb ; + min16float3 h = FsrRcasLoadH ( sp + min16int2 ( 0 , 1 ) ) . rgb ; + + min16float bR = b . r ; + min16float bG = b . g ; + min16float bB = b . b ; + min16float dR = d . r ; + min16float dG = d . g ; + min16float dB = d . b ; + min16float eR = e . r ; + min16float eG = e . g ; + min16float eB = e . b ; + min16float fR = f . r ; + min16float fG = f . g ; + min16float fB = f . b ; + min16float hR = h . r ; + min16float hG = h . g ; + min16float hB = h . b ; + + FsrRcasInputH ( bR , bG , bB ) ; + FsrRcasInputH ( dR , dG , dB ) ; + FsrRcasInputH ( eR , eG , eB ) ; + FsrRcasInputH ( fR , fG , fB ) ; + FsrRcasInputH ( hR , hG , hB ) ; + + min16float bL = bB * AH1_x ( min16float ( 0.5 ) ) + ( bR * AH1_x ( min16float ( 0.5 ) ) + bG ) ; + min16float dL = dB * AH1_x ( min16float ( 0.5 ) ) + ( dR * AH1_x ( min16float ( 0.5 ) ) + dG ) ; + min16float eL = eB * AH1_x ( min16float ( 0.5 ) ) + ( eR * AH1_x ( min16float ( 0.5 ) ) + eG ) ; + min16float fL = fB * AH1_x ( min16float ( 0.5 ) ) + ( fR * AH1_x ( min16float ( 0.5 ) ) + fG ) ; + min16float hL = hB * AH1_x ( min16float ( 0.5 ) ) + ( hR * AH1_x ( min16float ( 0.5 ) ) + hG ) ; + + min16float nz = AH1_x ( min16float ( 0.25 ) ) * bL + AH1_x ( min16float ( 0.25 ) ) * dL + AH1_x ( min16float ( 0.25 ) ) * fL + AH1_x ( min16float ( 0.25 ) ) * hL - eL ; + nz = ASatH1 ( abs ( nz ) * APrxMedRcpH1 ( AMax3H1 ( AMax3H1 ( bL , dL , eL ) , fL , hL ) - AMin3H1 ( AMin3H1 ( bL , dL , eL ) , fL , hL ) ) ) ; + nz = AH1_x ( min16float ( - 0.5 ) ) * nz + AH1_x ( min16float ( 1.0 ) ) ; + + min16float mn4R = min ( AMin3H1 ( bR , dR , fR ) , hR ) ; + min16float mn4G = min ( AMin3H1 ( bG , dG , fG ) , hG ) ; + min16float mn4B = min ( AMin3H1 ( bB , dB , fB ) , hB ) ; + min16float mx4R = max ( AMax3H1 ( bR , dR , fR ) , hR ) ; + min16float mx4G = max ( AMax3H1 ( bG , dG , fG ) , hG ) ; + min16float mx4B = max ( AMax3H1 ( bB , dB , fB ) , hB ) ; + + min16float2 peakC = min16float2 ( 1.0 , - 1.0 * 4.0 ) ; + + min16float hitMinR = mn4R * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mx4R ) ; + min16float hitMinG = mn4G * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mx4G ) ; + min16float hitMinB = mn4B * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mx4B ) ; + min16float hitMaxR = ( peakC . x - mx4R ) * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mn4R + peakC . y ) ; + min16float hitMaxG = ( peakC . x - mx4G ) * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mn4G + peakC . y ) ; + min16float hitMaxB = ( peakC . x - mx4B ) * ARcpH1 ( AH1_x ( min16float ( 4.0 ) ) * mn4B + peakC . y ) ; + min16float lobeR = max ( - hitMinR , hitMaxR ) ; + min16float lobeG = max ( - hitMinG , hitMaxG ) ; + min16float lobeB = max ( - hitMinB , hitMaxB ) ; + min16float lobe = max ( AH1_x ( min16float ( - ( 0.25 - ( 1.0 / 16.0 ) ) ) ) , min ( AMax3H1 ( lobeR , lobeG , lobeB ) , AH1_x ( min16float ( 0.0 ) ) ) ) * AH2_AU1_x ( uint ( con . y ) ) . x ; + +#line 870 + + + min16float rcpL = APrxMedRcpH1 ( AH1_x ( min16float ( 4.0 ) ) * lobe + AH1_x ( min16float ( 1.0 ) ) ) ; + pixR = ( lobe * bR + lobe * dR + lobe * hR + lobe * fR + eR ) * rcpL ; + pixG = ( lobe * bG + lobe * dG + lobe * hG + lobe * fG + eG ) * rcpL ; + pixB = ( lobe * bB + lobe * dB + lobe * hB + lobe * fB + eB ) * rcpL ; +} + + +#line 997 + + +#line 1024 + + +void FsrLfgaF ( inout float3 c , float3 t , float a ) { c += ( t * AF3_x ( float ( a ) ) ) * min ( AF3_x ( float ( 1.0 ) ) - c , c ) ; } + + + + +void FsrLfgaH ( inout min16float3 c , min16float3 t , min16float a ) { c += ( t * AH3_x ( min16float ( a ) ) ) * min ( AH3_x ( min16float ( 1.0 ) ) - c , c ) ; } + +#line 1034 +void FsrLfgaHx2 ( inout min16float2 cR , inout min16float2 cG , inout min16float2 cB , min16float2 tR , min16float2 tG , min16float2 tB , min16float a ) { + cR += ( tR * AH2_x ( min16float ( a ) ) ) * min ( AH2_x ( min16float ( 1.0 ) ) - cR , cR ) ; cG += ( tG * AH2_x ( min16float ( a ) ) ) * min ( AH2_x ( min16float ( 1.0 ) ) - cG , cG ) ; cB += ( tB * AH2_x ( min16float ( a ) ) ) * min ( AH2_x ( min16float ( 1.0 ) ) - cB , cB ) ; +} + + +#line 1055 + +void FsrSrtmF ( inout float3 c ) { c *= AF3_x ( float ( ARcpF1 ( AMax3F1 ( c . r , c . g , c . b ) + AF1_x ( float ( 1.0 ) ) ) ) ) ; } + +void FsrSrtmInvF ( inout float3 c ) { c *= AF3_x ( float ( ARcpF1 ( max ( AF1_x ( float ( 1.0 / 32768.0 ) ) , AF1_x ( float ( 1.0 ) ) - AMax3F1 ( c . r , c . g , c . b ) ) ) ) ) ; } + + + +void FsrSrtmH ( inout min16float3 c ) { c *= AH3_x ( min16float ( ARcpH1 ( AMax3H1 ( c . r , c . g , c . b ) + AH1_x ( min16float ( 1.0 ) ) ) ) ) ; } +void FsrSrtmInvH ( inout min16float3 c ) { c *= AH3_x ( min16float ( ARcpH1 ( max ( AH1_x ( min16float ( 1.0 / 32768.0 ) ) , AH1_x ( min16float ( 1.0 ) ) - AMax3H1 ( c . r , c . g , c . b ) ) ) ) ) ; } + +void FsrSrtmHx2 ( inout min16float2 cR , inout min16float2 cG , inout min16float2 cB ) { + min16float2 rcp = ARcpH2 ( AMax3H2 ( cR , cG , cB ) + AH2_x ( min16float ( 1.0 ) ) ) ; cR *= rcp ; cG *= rcp ; cB *= rcp ; +} +void FsrSrtmInvHx2 ( inout min16float2 cR , inout min16float2 cG , inout min16float2 cB ) { + min16float2 rcp = ARcpH2 ( max ( AH2_x ( min16float ( 1.0 / 32768.0 ) ) , AH2_x ( min16float ( 1.0 ) ) - AMax3H2 ( cR , cG , cB ) ) ) ; cR *= rcp ; cG *= rcp ; cB *= rcp ; +} + + +#line 1097 + + +#line 1101 +float FsrTepdDitF ( uint2 p , uint f ) { + float x = AF1_x ( float ( p . x + f ) ) ; + float y = AF1_x ( float ( p . y ) ) ; + + float a = AF1_x ( float ( ( 1.0 + sqrt ( 5.0 ) ) / 2.0 ) ) ; + + float b = AF1_x ( float ( 1.0 / 3.69 ) ) ; + x = x * a + ( y * b ) ; + return AFractF1 ( x ) ; +} + +#line 1115 +void FsrTepdC8F ( inout float3 c , float dit ) { + float3 n = sqrt ( c ) ; + n = floor ( n * AF3_x ( float ( 255.0 ) ) ) * AF3_x ( float ( 1.0 / 255.0 ) ) ; + float3 a = n * n ; + float3 b = n + AF3_x ( float ( 1.0 / 255.0 ) ) ; b = b * b ; + +#line 1123 + float3 r = ( c - b ) * APrxMedRcpF3 ( a - b ) ; + +#line 1126 + c = ASatF3 ( n + AGtZeroF3 ( AF3_x ( float ( dit ) ) - r ) * AF3_x ( float ( 1.0 / 255.0 ) ) ) ; +} + +#line 1132 +void FsrTepdC10F ( inout float3 c , float dit ) { + float3 n = sqrt ( c ) ; + n = floor ( n * AF3_x ( float ( 1023.0 ) ) ) * AF3_x ( float ( 1.0 / 1023.0 ) ) ; + float3 a = n * n ; + float3 b = n + AF3_x ( float ( 1.0 / 1023.0 ) ) ; b = b * b ; + float3 r = ( c - b ) * APrxMedRcpF3 ( a - b ) ; + c = ASatF3 ( n + AGtZeroF3 ( AF3_x ( float ( dit ) ) - r ) * AF3_x ( float ( 1.0 / 1023.0 ) ) ) ; +} + + + +min16float FsrTepdDitH ( uint2 p , uint f ) { + float x = AF1_x ( float ( p . x + f ) ) ; + float y = AF1_x ( float ( p . y ) ) ; + float a = AF1_x ( float ( ( 1.0 + sqrt ( 5.0 ) ) / 2.0 ) ) ; + float b = AF1_x ( float ( 1.0 / 3.69 ) ) ; + x = x * a + ( y * b ) ; + return min16float ( AFractF1 ( x ) ) ; +} + +void FsrTepdC8H ( inout min16float3 c , min16float dit ) { + min16float3 n = sqrt ( c ) ; + n = floor ( n * AH3_x ( min16float ( 255.0 ) ) ) * AH3_x ( min16float ( 1.0 / 255.0 ) ) ; + min16float3 a = n * n ; + min16float3 b = n + AH3_x ( min16float ( 1.0 / 255.0 ) ) ; b = b * b ; + min16float3 r = ( c - b ) * APrxMedRcpH3 ( a - b ) ; + c = ASatH3 ( n + AGtZeroH3 ( AH3_x ( min16float ( dit ) ) - r ) * AH3_x ( min16float ( 1.0 / 255.0 ) ) ) ; +} + +void FsrTepdC10H ( inout min16float3 c , min16float dit ) { + min16float3 n = sqrt ( c ) ; + n = floor ( n * AH3_x ( min16float ( 1023.0 ) ) ) * AH3_x ( min16float ( 1.0 / 1023.0 ) ) ; + min16float3 a = n * n ; + min16float3 b = n + AH3_x ( min16float ( 1.0 / 1023.0 ) ) ; b = b * b ; + min16float3 r = ( c - b ) * APrxMedRcpH3 ( a - b ) ; + c = ASatH3 ( n + AGtZeroH3 ( AH3_x ( min16float ( dit ) ) - r ) * AH3_x ( min16float ( 1.0 / 1023.0 ) ) ) ; +} + +#line 1171 +min16float2 FsrTepdDitHx2 ( uint2 p , uint f ) { + float2 x ; + x . x = AF1_x ( float ( p . x + f ) ) ; + x . y = x . x + AF1_x ( float ( 8.0 ) ) ; + float y = AF1_x ( float ( p . y ) ) ; + float a = AF1_x ( float ( ( 1.0 + sqrt ( 5.0 ) ) / 2.0 ) ) ; + float b = AF1_x ( float ( 1.0 / 3.69 ) ) ; + x = x * AF2_x ( float ( a ) ) + AF2_x ( float ( y * b ) ) ; + return min16float2 ( AFractF2 ( x ) ) ; +} + +void FsrTepdC8Hx2 ( inout min16float2 cR , inout min16float2 cG , inout min16float2 cB , min16float2 dit ) { + min16float2 nR = sqrt ( cR ) ; + min16float2 nG = sqrt ( cG ) ; + min16float2 nB = sqrt ( cB ) ; + nR = floor ( nR * AH2_x ( min16float ( 255.0 ) ) ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ; + nG = floor ( nG * AH2_x ( min16float ( 255.0 ) ) ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ; + nB = floor ( nB * AH2_x ( min16float ( 255.0 ) ) ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ; + min16float2 aR = nR * nR ; + min16float2 aG = nG * nG ; + min16float2 aB = nB * nB ; + min16float2 bR = nR + AH2_x ( min16float ( 1.0 / 255.0 ) ) ; bR = bR * bR ; + min16float2 bG = nG + AH2_x ( min16float ( 1.0 / 255.0 ) ) ; bG = bG * bG ; + min16float2 bB = nB + AH2_x ( min16float ( 1.0 / 255.0 ) ) ; bB = bB * bB ; + min16float2 rR = ( cR - bR ) * APrxMedRcpH2 ( aR - bR ) ; + min16float2 rG = ( cG - bG ) * APrxMedRcpH2 ( aG - bG ) ; + min16float2 rB = ( cB - bB ) * APrxMedRcpH2 ( aB - bB ) ; + cR = ASatH2 ( nR + AGtZeroH2 ( dit - rR ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ) ; + cG = ASatH2 ( nG + AGtZeroH2 ( dit - rG ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ) ; + cB = ASatH2 ( nB + AGtZeroH2 ( dit - rB ) * AH2_x ( min16float ( 1.0 / 255.0 ) ) ) ; +} + +void FsrTepdC10Hx2 ( inout min16float2 cR , inout min16float2 cG , inout min16float2 cB , min16float2 dit ) { + min16float2 nR = sqrt ( cR ) ; + min16float2 nG = sqrt ( cG ) ; + min16float2 nB = sqrt ( cB ) ; + nR = floor ( nR * AH2_x ( min16float ( 1023.0 ) ) ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; + nG = floor ( nG * AH2_x ( min16float ( 1023.0 ) ) ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; + nB = floor ( nB * AH2_x ( min16float ( 1023.0 ) ) ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; + min16float2 aR = nR * nR ; + min16float2 aG = nG * nG ; + min16float2 aB = nB * nB ; + min16float2 bR = nR + AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; bR = bR * bR ; + min16float2 bG = nG + AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; bG = bG * bG ; + min16float2 bB = nB + AH2_x ( min16float ( 1.0 / 1023.0 ) ) ; bB = bB * bB ; + min16float2 rR = ( cR - bR ) * APrxMedRcpH2 ( aR - bR ) ; + min16float2 rG = ( cG - bG ) * APrxMedRcpH2 ( aG - bG ) ; + min16float2 rB = ( cB - bB ) * APrxMedRcpH2 ( aB - bB ) ; + cR = ASatH2 ( nR + AGtZeroH2 ( dit - rR ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ) ; + cG = ASatH2 ( nG + AGtZeroH2 ( dit - rG ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ) ; + cB = ASatH2 ( nB + AGtZeroH2 ( dit - rB ) * AH2_x ( min16float ( 1.0 / 1023.0 ) ) ) ; +} + + +#line 1223 + + +#line 31 "C:\\Users\\LiuXu\\source\\repos\\Magpie\\MODULE_Common\\FfxEasuShader.hlsl" +float4 main_Impl ( ) { + uint4 con0 , con1 , con2 , con3 ; + FsrEasuCon ( con0 , con1 , con2 , con3 , 1280 , 720 , 1280 , 720 , 1920 , 1080 ) ; + return float4 ( 1.0f , 1.0f , 1.0f , 1.0f ) ; +} \ No newline at end of file