common_def.h 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282
  1. // ==================================================================================================
  2. // Copyright (c) 2007-2021 Advanced Micro Devices, Inc. All rights reserved.
  3. // Copyright (c) 2004-2006 ATI Technologies Inc.
  4. // Copyright (c) <2014> <Michal Drobot>
  5. // ==================================================================================================
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files(the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions :
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. //
  26. // File Name: Common_Def
  27. // Description: common definitions used for CPU/HPC/GPU
  28. //
  29. // Pull changes:
  30. // Fixed build of cmp_core on Mac. (#164)
  31. //
  32. #ifndef CMP_COMMON_DEFINITIONS_H
  33. #define CMP_COMMON_DEFINITIONS_H
  34. //#define USE_CMP_FIDELITY_FX_H
  35. // Proxy ISPC compiler (Warning! Not all ASPM features will be available : expect build errors for specialized ASPM code!
  36. #ifdef ISPC
  37. #define ASPM
  38. #endif
  39. // Using OpenCL Compiler
  40. #ifdef __OPENCL_VERSION__
  41. #define ASPM_OPENCL
  42. #endif
  43. #ifdef USE_CMP_FIDELITY_FX_H
  44. // Fidelity FX SDK mapping
  45. #if defined(A_CPU)
  46. #ifndef ASPM_CPU
  47. #define ASPM_CPU
  48. #endif
  49. #endif
  50. #if defined(A_GPU)
  51. #ifndef ASPM_GPU
  52. #define ASPM_GPU
  53. #endif
  54. #endif
  55. #if defined(A_GLS)
  56. #ifndef ASPM_GLS
  57. #define ASPM_GLS
  58. #endif
  59. #endif
  60. #if defined(A_HLSL)
  61. #ifndef ASPM_HLSL
  62. #define ASPM_HLSL
  63. #endif
  64. #endif
  65. #if defined(A_GCC)
  66. #ifndef ASPM_GCC
  67. #define ASPM_GCC
  68. #endif
  69. #endif
  70. #endif
  71. #if (defined(ASPM_HLSL) || defined(ASPM_OPENCL))
  72. #ifndef ASPM_GPU
  73. #define ASPM_GPU
  74. #endif
  75. #endif
  76. //=======================================
  77. // Skip CMP if only using FidelityFX Code
  78. //=======================================
  79. #if !(defined(A_GPU) || defined(A_GLS) || defined(A_HLSL) || defined(A_GCC))
  80. // The shaders for UE4 require extension in the form of .ush in place of standard .h
  81. // this directive is used to make the change without users requiring to modify all of the include extensions
  82. // specific to UE4
  83. #ifdef ASPM_HLSL_UE4
  84. #pragma once
  85. #define INC_cmp_math_vec4 "cmp_math_vec4.ush"
  86. #define INC_cmp_math_func "cmp_math_func.ush"
  87. #else
  88. #define INC_cmp_math_vec4 "cmp_math_vec4.h"
  89. #define INC_cmp_math_func "cmp_math_func.h"
  90. #endif
  91. #if defined(__linux__) || defined(__APPLE__)
  92. #ifndef _LINUX
  93. #define _LINUX
  94. #endif
  95. #ifdef ASPM_GPU
  96. #undef ASPM_GPU
  97. #endif
  98. #include <cstring>
  99. #include <cmath>
  100. #include <stdio.h>
  101. #include INC_cmp_math_vec4
  102. #endif
  103. #ifdef _WIN32
  104. //#define USE_ASPM_CODE
  105. #include <cmath>
  106. #endif
  107. #ifndef CMP_MAX
  108. #define CMP_MAX(x, y) (((x) > (y)) ? (x) : (y))
  109. #endif
  110. #ifndef CMP_MIN
  111. #define CMP_MIN(x, y) (((x) < (y)) ? (x) : (y))
  112. #endif
  113. #ifndef cmp_isnan
  114. #ifdef ASPM_GPU
  115. #define cmp_isnan(x) isnan(x)
  116. #else
  117. #define cmp_isnan(x) std::isnan(x)
  118. #endif
  119. #endif
  120. #ifdef ASPM_GPU
  121. #define CMP_STATIC_CAST(x, y) (x)(y)
  122. #define CMP_TYPE_CAST(x) (x)
  123. #else
  124. #define CMP_STATIC_CAST(x, y) static_cast<x>(y)
  125. #define CMP_TYPE_CAST(x) (x&)
  126. #endif
  127. // Sets mapping BC1, BC2 & BC3 to decode Red,Green,Blue and Alpha
  128. // RGBA to channels [0,1,2,3] else BGRA maps to [0,1,2,3]
  129. // BC4 alpha always maps as AAAA to channels [0,1,2,3]
  130. // BC5 decoded (Red&Green) maps R,G,B=0,A=255 to [0,1,2,3] else maps [B=0,G,R,A=255] to [0,1,2,3]
  131. #define CMP_SET_BC13_DECODER_RGBA
  132. #define CMP_FLOAT_MAX 3.402823466e+38F // max value used to detect an Error in processing
  133. #define CMP_FLOAT_MAX_EXP 38
  134. #define USE_PROCESS_SEPERATE_ALPHA // Enable this to use higher quality code using CompressDualIndexBlock
  135. #define COMPRESSED_BLOCK_SIZE 16 // Size of a compressed block in bytes
  136. #define MAX_DIMENSION_BIG 4 // Max number of channels (RGBA)
  137. #define MAX_SUBSETS 3 // Maximum number of possible subsets
  138. #define MAX_SUBSET_SIZE 16 // Largest possible size for an individual subset
  139. #define BLOCK_SIZE_4X4X4 64
  140. #define BLOCK_SIZE_4X4 16
  141. #define BlockX 4
  142. #define BlockY 4
  143. //#define USE_BLOCK_LINEAR // Source Data is organized in linear form for each block : Experimental Code not fully developed
  144. //#define USE_DOUBLE // Default is to use float, enable to use double data types only for float definitions
  145. //---------------------------------------------
  146. // Predefinitions for GPU and CPU compiled code
  147. //---------------------------------------------
  148. #ifdef ASPM_HLSL
  149. // ==== Vectors ====
  150. typedef float2 CGU_Vec2f;
  151. typedef float2 CGV_Vec2f;
  152. typedef float3 CGU_Vec3f;
  153. typedef float3 CGV_Vec3f;
  154. typedef float4 CGU_Vec4f;
  155. typedef float4 CGV_Vec4f;
  156. typedef int2 CGU_Vec2i;
  157. typedef int2 CGV_Vec2i;
  158. typedef uint2 CGU_Vec2ui;
  159. typedef uint2 CGV_Vec2ui;
  160. typedef int3 CGU_Vec3i;
  161. typedef int3 CGV_Vec3i;
  162. typedef uint3 CGU_Vec3ui;
  163. typedef uint3 CGV_Vec3ui;
  164. typedef int4 CGU_Vec4i;
  165. typedef int4 CGV_Vec4i;
  166. typedef int4 CGU_Vec4uc;
  167. typedef int4 CGV_Vec4uc;
  168. typedef uint4 CGU_Vec4ui;
  169. typedef uint4 CGV_Vec4ui;
  170. // ==== Scalar Types ==== to remove from code
  171. typedef int CGU_INT8;
  172. typedef int CGU_INT;
  173. typedef int CGV_INT;
  174. typedef uint CGU_UINT8;
  175. typedef uint CGU_UINT;
  176. // ==== Scalar Types ====
  177. typedef int CGU_BOOL;
  178. typedef int CGV_BOOL;
  179. typedef int CGV_INT8;
  180. typedef int CGV_UINT8;
  181. typedef uint CGU_UINT16;
  182. typedef int CGU_INT32;
  183. typedef int CGV_INT32;
  184. typedef uint CGU_UINT32;
  185. typedef uint CGV_UINT32;
  186. typedef float CGV_FLOAT;
  187. typedef float CGU_FLOAT;
  188. typedef min16float CGU_MIN16_FLOAT; // FP16 GPU support defaults to 32 bit if no HW support
  189. #define TRUE 1
  190. #define FALSE 0
  191. #define CMP_CDECL
  192. #define BC7_ENCODECLASS
  193. #define CMP_EXPORT
  194. #define INLINE inline
  195. #define uniform
  196. #define varying
  197. #define CMP_GLOBAL
  198. #define CMP_KERNEL
  199. #define CMP_CONSTANT const
  200. #define CMP_STATIC static
  201. #define CMP_REFINOUT
  202. #define CMP_PTRINOUT
  203. #define CMP_INOUT inout
  204. #define CMP_OUT out
  205. #define CMP_IN in
  206. #define CMP_UNUSED(x) (x);
  207. #define CMP_UNROLL [unroll]
  208. #define CMP_SVGROUPINDEX :SV_GroupIndex
  209. #define CMP_SVGROUPID :SV_GroupID
  210. #define CMP_NUMTHREADS(x, y, z) [numthreads(x, y, z)]
  211. #else
  212. #define CMP_SVGROUPINDEX
  213. #define CMP_SVGROUPID
  214. #define CMP_NUMTHREADS(x, y, z)
  215. typedef enum
  216. {
  217. CGU_CORE_OK = 0, // No errors, call was successfull
  218. CGU_CORE_ERR_UNKOWN, // An unknown error occurred
  219. CGU_CORE_ERR_NEWMEM, // New Memory Allocation Failed
  220. CGU_CORE_ERR_INVALIDPTR, // The pointer value used is invalid or null
  221. CGU_CORE_ERR_RANGERED, // values for Red Channel is out of range (too high or too low)
  222. CGU_CORE_ERR_RANGEGREEN, // values for Green Channel is out of range (too high or too low)
  223. CGU_CORE_ERR_RANGEBLUE, // values for Blue Channel is out of range (too high or too low)
  224. } CGU_ERROR_CODES;
  225. #ifdef ASPM_OPENCL // GPU Based code using OpenCL
  226. // ==== Vectors ====
  227. typedef float2 CGU_Vec2f;
  228. typedef float2 CGV_Vec2f;
  229. typedef float3 CMP_Vec3f;
  230. typedef float3 CGU_Vec3f;
  231. typedef float3 CGV_Vec3f;
  232. typedef float4 CGU_Vec4f;
  233. typedef float4 CGV_Vec4f;
  234. typedef uchar3 CGU_Vec3uc;
  235. typedef uchar3 CGV_Vec3uc;
  236. typedef uchar4 CMP_Vec4uc;
  237. typedef uchar4 CGU_Vec4uc;
  238. typedef uchar4 CGV_Vec4uc;
  239. typedef int2 CGU_Vec2i;
  240. typedef int2 CGV_Vec2i;
  241. typedef int3 CGU_Vec3i;
  242. typedef int3 CGV_Vec3i;
  243. typedef int4 CGU_Vec4i;
  244. typedef int4 CGV_Vec4i;
  245. typedef uint2 CGU_Vec2ui;
  246. typedef uint2 CGV_Vec2ui;
  247. typedef uint3 CGU_Vec3ui;
  248. typedef uint3 CGV_Vec3ui;
  249. typedef uint4 CGU_Vec4ui;
  250. typedef uint4 CGV_Vec4ui;
  251. #define USE_BC7_SP_ERR_IDX
  252. #define BC7_ENCODECLASS
  253. #define ASPM_PRINT(args) printf args
  254. #define CMP_EXPORT
  255. #define INLINE
  256. #define uniform
  257. #define varying
  258. #define CMP_GLOBAL __global
  259. #define CMP_KERNEL __kernel
  260. #define CMP_CONSTANT __constant
  261. #define CMP_STATIC
  262. #define CMP_REFINOUT &
  263. #define CMP_PTRINOUT *
  264. #define CMP_INOUT
  265. #define CMP_OUT
  266. #define CMP_IN
  267. #define CMP_UNUSED(x)
  268. #define CMP_UNROLL
  269. typedef unsigned int CGU_DWORD; //32bits
  270. typedef int CGU_INT; //32bits
  271. typedef bool CGU_BOOL;
  272. typedef unsigned short CGU_SHORT; //16bits
  273. typedef float CGU_FLOAT;
  274. typedef half CGU_MIN16_FLOAT; // FP16 GPU support defaults to 32 bit if no HW support
  275. typedef unsigned int uint32; // need to remove this def
  276. typedef int CGV_INT;
  277. typedef unsigned int CGU_UINT;
  278. typedef int CGUV_INT;
  279. typedef int CGV_BOOL;
  280. typedef char CGU_INT8;
  281. typedef unsigned char CGU_UINT8;
  282. typedef short CGU_INT16;
  283. typedef unsigned short CGU_UINT16;
  284. typedef int CGU_INT32;
  285. typedef unsigned int CGU_UINT32;
  286. typedef unsigned long long CGU_UINT64;
  287. typedef char CGV_INT8;
  288. typedef unsigned char CGV_UINT8;
  289. typedef short CGV_INT16;
  290. typedef unsigned short CGV_UINT16;
  291. typedef int CGV_INT32;
  292. typedef unsigned int CGV_UINT32;
  293. typedef unsigned long CGV_UINT64;
  294. typedef float CGV_FLOAT;
  295. #define TRUE 1
  296. #define FALSE 0
  297. #define CMP_CDECL
  298. #else
  299. // CPU & ASPM definitions
  300. #define CMP_REFINOUT &
  301. #define CMP_PTRINOUT *
  302. #define CMP_INOUT
  303. #define CMP_OUT
  304. #define CMP_IN
  305. #define CMP_UNUSED(x) (void)(x);
  306. #define CMP_UNROLL
  307. #ifdef ASPM // SPMD ,SIMD CPU code
  308. // using hybrid (CPU/GPU) aspm compiler
  309. #define ASPM_PRINT(args) print args
  310. #define CMP_USE_FOREACH_ASPM
  311. #define __ASPM__
  312. #define BC7_ENCODECLASS
  313. #define USE_BC7_SP_ERR_IDX
  314. //#define USE_BC7_RAMP
  315. #define CMP_EXPORT export
  316. #define TRUE true
  317. #define FALSE false
  318. typedef uniform bool CGU_BOOL;
  319. typedef bool CGV_BOOL;
  320. typedef unsigned int8 uint8;
  321. typedef unsigned int16 uint16;
  322. typedef unsigned int32 uint32;
  323. typedef unsigned int64 uint64;
  324. typedef uniform float CGU_FLOAT;
  325. typedef varying float CGV_FLOAT;
  326. typedef uniform float CGU_MIN16_FLOAT;
  327. typedef uniform uint16 CGU_UINT16;
  328. typedef uniform uint8 CGU_UINT8;
  329. typedef varying uint8 CGV_UINT8;
  330. typedef uniform uint64 CGU_UINT64;
  331. typedef CGV_UINT8<4> CGV_Vec4uc;
  332. typedef CGU_UINT8<4> CGU_Vec4uc;
  333. typedef CGU_FLOAT<2> CGU_Vec2f;
  334. typedef CGV_FLOAT<2> CGV_Vec2f;
  335. typedef CGU_FLOAT<3> CGU_Vec3f;
  336. typedef CGV_FLOAT<3> CGV_Vec3f;
  337. typedef CGU_FLOAT<4> CGU_Vec4f;
  338. typedef CGV_FLOAT<4> CGV_Vec4f;
  339. typedef CGU_UINT32<3> CGU_Vec3ui;
  340. typedef CGV_UINT32<3> CGV_Vec3ui;
  341. typedef CGU_UINT32<4> CGU_Vec4ui;
  342. typedef CGV_UINT32<4> CGV_Vec4ui;
  343. #define CMP_CDECL
  344. #else // standard CPU code
  345. #include <stdio.h>
  346. #include <string>
  347. #include INC_cmp_math_vec4
  348. // using CPU compiler
  349. #define ASPM_PRINT(args) printf args
  350. #define USE_BC7_RAMP
  351. #define USE_BC7_SP_ERR_IDX
  352. #define CMP_EXPORT
  353. #define BC7_ENCODECLASS BC7_EncodeClass::
  354. #define TRUE 1
  355. #define FALSE 0
  356. #define uniform
  357. #define varying
  358. typedef char int8;
  359. typedef short int16;
  360. typedef int int32;
  361. typedef long long int64;
  362. typedef unsigned char uint8;
  363. typedef unsigned short uint16;
  364. typedef unsigned int uint32;
  365. typedef unsigned long long uint64;
  366. typedef int8 CGV_BOOL;
  367. typedef bool CGU_BOOL;
  368. typedef int16 CGU_WORD;
  369. typedef uint8 CGU_SHORT;
  370. typedef long CGU_LONG;
  371. typedef unsigned long CGU_ULONG;
  372. typedef uniform float CGU_FLOAT;
  373. typedef varying float CGV_FLOAT;
  374. typedef uniform float CGU_MIN16_FLOAT;
  375. typedef uniform uint8 CGU_UINT8;
  376. typedef varying uint8 CGV_UINT8;
  377. typedef uniform uint16 CGU_UINT16;
  378. typedef CMP_Vec3ui CGU_Vec3ui;
  379. typedef CMP_Vec3ui CGV_Vec3ui;
  380. typedef CMP_Vec2f CGU_Vec2f;
  381. typedef CMP_Vec3f CGU_Vec3f;
  382. typedef CMP_Vec4uc CGU_Vec4uc;
  383. typedef CMP_Vec4uc CGV_Vec4uc;
  384. typedef CMP_Vec4i CGU_Vec4i;
  385. typedef CMP_Vec4ui CGU_Vec4ui;
  386. typedef CMP_Vec4ui CGV_Vec4ui;
  387. typedef CMP_Vec4f CGU_Vec4f;
  388. typedef CMP_Vec4f CGV_Vec4f;
  389. #if defined(WIN32) || defined(_WIN64)
  390. #define CMP_CDECL __cdecl
  391. #else
  392. #define CMP_CDECL
  393. #endif
  394. #endif
  395. // Common CPU & ASPM definitions
  396. #define CMP_ASSERT(arg)
  397. #define CMP_GLOBAL
  398. #define CMP_KERNEL
  399. #define __local const
  400. #define __constant const
  401. #define CMP_CONSTANT const
  402. #define INLINE inline
  403. #define CMP_STATIC static
  404. typedef uniform int32 CGU_DWORD;
  405. typedef uniform uint8 CGU_UBYTE;
  406. typedef uniform int CGU_INT;
  407. typedef uniform int8 CGU_INT8;
  408. typedef uniform int16 CGU_INT16;
  409. typedef uniform uint16 CGU_UINT16;
  410. typedef uniform int32 CGU_INT32;
  411. typedef uniform uint32 CGU_UINT32;
  412. typedef uniform uint64 CGU_UINT64;
  413. typedef int CGV_INT;
  414. typedef int8 CGV_INT8;
  415. typedef int16 CGV_INT16;
  416. typedef int32 CGV_INT32;
  417. typedef uint16 CGV_UINT16;
  418. typedef uint32 CGV_UINT32;
  419. typedef uint64 CGV_UINT64;
  420. #endif // else ASPM_GPU
  421. #define CMP_UNIFORM uniform
  422. #define CMP_VARYING varying
  423. typedef struct
  424. {
  425. CGU_UINT32 m_src_width;
  426. CGU_UINT32 m_src_height;
  427. CGU_UINT32 m_width_in_blocks;
  428. CGU_UINT32 m_height_in_blocks;
  429. CGU_FLOAT m_fquality;
  430. } Source_Info;
  431. typedef unsigned char* CGU_PTR;
  432. // Ref Compute_CPU_HPC
  433. struct texture_surface
  434. {
  435. CGU_PTR ptr;
  436. CGU_INT width, height, stride;
  437. CGU_INT channels;
  438. };
  439. #endif // else ASPM_HLSL
  440. #endif // USE CMP defines
  441. //=======================================
  442. // using FidelityFX Code
  443. //=======================================
  444. #ifdef USE_CMP_FIDELITY_FX_H
  445. // ==================================================================================================
  446. // [A] SHADER PORTABILITY 1.20190530
  447. // ==================================================================================================
  448. // ABOUT
  449. // =====
  450. // Common central point for high-level shading language and C portability for various shader headers.
  451. //---------------------------------------------------------------------------------------------------
  452. // DEFINES TYPES FOR CMP AND FIDELITY FX
  453. // Both ASPM_ and A_ types are interchanable in code, the table below show compatibility between types
  454. // ==================================================================================================
  455. // Compressonator Fidelity FX Comments
  456. // ASPM_CPU A_CPU Include the CPU related code.
  457. // ASPM_GPU A_GPU Include the GPU related code.
  458. // ASPM_GLSL A_GLS Using GLSL.
  459. // ASMP_HLSL A_HLS Using HLSL.
  460. // - A_GCC Using a GCC compatible compiler (else assume MSVC compatible compiler by default).
  461. // =======
  462. // CGU_UINT8 A_BYTE Support 8-bit integer.
  463. // CGU_HALF A_HALF Support 16-bit integer and floating point.
  464. // A_LONG Support 64-bit integer. (GLSL & CPU only)
  465. // A_DUBL Support 64-bit floating point.
  466. // =======
  467. // A_WAVE Support wave-wide operations.
  468. //--------------------------------------------------------------------------------------------------
  469. // To get #include "common_def.h" working in GLSL use '#extension GL_GOOGLE_include_directive:require'
  470. //---------------------------------------------------------------------------------------------------
  471. // SIMPLIFIED TYPE SYSTEM FOR FX CODE
  472. // ==================================================================================================
  473. // - All ints will be unsigned with exception of when signed is required.
  474. // - Type naming simplified and shortened "A<type><#components>",
  475. // - H = 16-bit float (half)
  476. // - F = 32-bit float (float)
  477. // - D = 64-bit float (double)
  478. // - P = 1-bit integer (predicate, not using bool because 'B' is used for byte)
  479. // - B = 8-bit integer (byte)
  480. // - W = 16-bit integer (word)
  481. // - U = 32-bit integer (unsigned)
  482. // - L = 64-bit integer (long)
  483. // - Using "AS<type><#components>" for signed when required.
  484. //---------------------------------------------------------------------------------------------------
  485. // TODO
  486. // ====
  487. // - Make sure 'ALerp*(a,b,m)' does 'b*m+(-a*m+a)' (2 ops).
  488. // - Add subgroup ops.
  489. //------------------------------------------------------------------------------------------------------------------------------
  490. // CHANGE LOG
  491. // ==========
  492. // 20210518 - Merged CMP Common_def.h with ffx_a.h
  493. //==============================================================================================================================
  494. #define A_2PI 6.28318530718 // 2xPI
  495. //==============================================================================================================================
  496. // CPU
  497. //==============================================================================================================================
  498. // This provides a minimum subset of functionality compared to the GPU parts.
  499. //==============================================================================================================================
  500. #if defined(A_CPU) || !(defined(ASPM_GPU) || defined(ASPM_HLSL) || defined(ASPM_OPENCL))
  501. #include "stdint.h"
  502. // Supporting user defined overrides.
  503. #ifndef A_RESTRICT
  504. #define A_RESTRICT __restrict // CMP_RESTRICT
  505. #endif
  506. //------------------------------------------------------------------------------------------------------------------------------
  507. #ifndef A_STATIC
  508. #define A_STATIC static // CMP_STATIC
  509. #endif
  510. //------------------------------------------------------------------------------------------------------------------------------
  511. // Same types across CPU and GPU.
  512. // Predicate uses 32-bit integer (C friendly bool).
  513. typedef uint32_t AP1; // CGU_UINT32
  514. typedef float AF1; // CGU_FLOAT
  515. typedef double AD1; // CGU_DOUBLE
  516. typedef uint8_t AB1; // CGU_UINT8
  517. typedef uint16_t AW1; // CGU_UINT16
  518. typedef uint32_t AU1; // CGU_UINT32
  519. typedef uint64_t AL1; // CGU_UINT64
  520. typedef int8_t ASB1; // CGU_INT8
  521. typedef int16_t ASW1; // CGU_INT16
  522. typedef int32_t ASU1; // CGU_INT32
  523. typedef int64_t ASL1; // CGU_INT64
  524. //------------------------------------------------------------------------------------------------------------------------------
  525. #define AD1_(a) ((AD1)(a))
  526. #define AF1_(a) ((AF1)(a))
  527. #define AL1_(a) ((AL1)(a))
  528. #define AU1_(a) ((AU1)(a))
  529. //------------------------------------------------------------------------------------------------------------------------------
  530. #define ASL1_(a) ((ASL1)(a))
  531. #define ASU1_(a) ((ASU1)(a))
  532. //------------------------------------------------------------------------------------------------------------------------------
  533. A_STATIC AU1 AU1_AF1(AF1 a){union{AF1 f;AU1 u;}bits;bits.f=a;return bits.u;}
  534. //------------------------------------------------------------------------------------------------------------------------------
  535. #define A_TRUE 1
  536. #define A_FALSE 0
  537. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  538. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  539. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  540. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  541. //_____________________________________________________________/\_______________________________________________________________
  542. //==============================================================================================================================
  543. //
  544. // CPU/GPU PORTING
  545. //
  546. //------------------------------------------------------------------------------------------------------------------------------
  547. // Hackary to get CPU and GPU to share all setup code, without duplicate code paths.
  548. // Unfortunately this is the level of "ugly" that is required since the languages are very different.
  549. // This uses a lower-case prefix for special vector constructs.
  550. // - In C restrict pointers are used.
  551. // - In the shading language, in/inout/out arguments are used.
  552. // This depends on the ability to access a vector value in both languages via array syntax (aka color[2]).
  553. //==============================================================================================================================
  554. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  555. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  556. //_____________________________________________________________/\_______________________________________________________________
  557. //==============================================================================================================================
  558. // VECTOR ARGUMENT/RETURN/INITIALIZATION PORTABILITY
  559. //==============================================================================================================================
  560. #define retAD2 AD1 *A_RESTRICT
  561. #define retAD3 AD1 *A_RESTRICT
  562. #define retAD4 AD1 *A_RESTRICT
  563. #define retAF2 AF1 *A_RESTRICT
  564. #define retAF3 AF1 *A_RESTRICT
  565. #define retAF4 AF1 *A_RESTRICT
  566. #define retAL2 AL1 *A_RESTRICT
  567. #define retAL3 AL1 *A_RESTRICT
  568. #define retAL4 AL1 *A_RESTRICT
  569. #define retAU2 AU1 *A_RESTRICT
  570. #define retAU3 AU1 *A_RESTRICT
  571. #define retAU4 AU1 *A_RESTRICT
  572. //------------------------------------------------------------------------------------------------------------------------------
  573. #define inAD2 AD1 *A_RESTRICT
  574. #define inAD3 AD1 *A_RESTRICT
  575. #define inAD4 AD1 *A_RESTRICT
  576. #define inAF2 AF1 *A_RESTRICT
  577. #define inAF3 AF1 *A_RESTRICT
  578. #define inAF4 AF1 *A_RESTRICT
  579. #define inAL2 AL1 *A_RESTRICT
  580. #define inAL3 AL1 *A_RESTRICT
  581. #define inAL4 AL1 *A_RESTRICT
  582. #define inAU2 AU1 *A_RESTRICT
  583. #define inAU3 AU1 *A_RESTRICT
  584. #define inAU4 AU1 *A_RESTRICT
  585. //------------------------------------------------------------------------------------------------------------------------------
  586. #define inoutAD2 AD1 *A_RESTRICT
  587. #define inoutAD3 AD1 *A_RESTRICT
  588. #define inoutAD4 AD1 *A_RESTRICT
  589. #define inoutAF2 AF1 *A_RESTRICT
  590. #define inoutAF3 AF1 *A_RESTRICT
  591. #define inoutAF4 AF1 *A_RESTRICT
  592. #define inoutAL2 AL1 *A_RESTRICT
  593. #define inoutAL3 AL1 *A_RESTRICT
  594. #define inoutAL4 AL1 *A_RESTRICT
  595. #define inoutAU2 AU1 *A_RESTRICT
  596. #define inoutAU3 AU1 *A_RESTRICT
  597. #define inoutAU4 AU1 *A_RESTRICT
  598. //------------------------------------------------------------------------------------------------------------------------------
  599. #define outAD2 AD1 *A_RESTRICT
  600. #define outAD3 AD1 *A_RESTRICT
  601. #define outAD4 AD1 *A_RESTRICT
  602. #define outAF2 AF1 *A_RESTRICT
  603. #define outAF3 AF1 *A_RESTRICT
  604. #define outAF4 AF1 *A_RESTRICT
  605. #define outAL2 AL1 *A_RESTRICT
  606. #define outAL3 AL1 *A_RESTRICT
  607. #define outAL4 AL1 *A_RESTRICT
  608. #define outAU2 AU1 *A_RESTRICT
  609. #define outAU3 AU1 *A_RESTRICT
  610. #define outAU4 AU1 *A_RESTRICT
  611. //------------------------------------------------------------------------------------------------------------------------------
  612. #define varAD2(x) AD1 x[2]
  613. #define varAD3(x) AD1 x[3]
  614. #define varAD4(x) AD1 x[4]
  615. #define varAF2(x) AF1 x[2]
  616. #define varAF3(x) AF1 x[3]
  617. #define varAF4(x) AF1 x[4]
  618. #define varAL2(x) AL1 x[2]
  619. #define varAL3(x) AL1 x[3]
  620. #define varAL4(x) AL1 x[4]
  621. #define varAU2(x) AU1 x[2]
  622. #define varAU3(x) AU1 x[3]
  623. #define varAU4(x) AU1 x[4]
  624. //------------------------------------------------------------------------------------------------------------------------------
  625. #define initAD2(x,y) {x,y}
  626. #define initAD3(x,y,z) {x,y,z}
  627. #define initAD4(x,y,z,w) {x,y,z,w}
  628. #define initAF2(x,y) {x,y}
  629. #define initAF3(x,y,z) {x,y,z}
  630. #define initAF4(x,y,z,w) {x,y,z,w}
  631. #define initAL2(x,y) {x,y}
  632. #define initAL3(x,y,z) {x,y,z}
  633. #define initAL4(x,y,z,w) {x,y,z,w}
  634. #define initAU2(x,y) {x,y}
  635. #define initAU3(x,y,z) {x,y,z}
  636. #define initAU4(x,y,z,w) {x,y,z,w}
  637. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  638. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  639. //_____________________________________________________________/\_______________________________________________________________
  640. //==============================================================================================================================
  641. // SCALAR RETURN OPS
  642. //------------------------------------------------------------------------------------------------------------------------------
  643. // TODO
  644. // ====
  645. // - Replace transcendentals with manual versions.
  646. //==============================================================================================================================
  647. #ifdef A_GCC
  648. A_STATIC AD1 AAbsD1(AD1 a){return __builtin_fabs(a);}
  649. A_STATIC AF1 AAbsF1(AF1 a){return __builtin_fabsf(a);}
  650. A_STATIC AU1 AAbsSU1(AU1 a){return AU1_(__builtin_abs(ASU1_(a)));}
  651. A_STATIC AL1 AAbsSL1(AL1 a){return AL1_(__builtin_labs(ASL1_(a)));}
  652. #else
  653. A_STATIC AD1 AAbsD1(AD1 a){return fabs(a);}
  654. A_STATIC AF1 AAbsF1(AF1 a){return fabsf(a);}
  655. A_STATIC AU1 AAbsSU1(AU1 a){return AU1_(abs(ASU1_(a)));}
  656. A_STATIC AL1 AAbsSL1(AL1 a){return AL1_(llabs(ASL1_(a)));}
  657. #endif
  658. //------------------------------------------------------------------------------------------------------------------------------
  659. #ifdef A_GCC
  660. A_STATIC AD1 ACosD1(AD1 a){return __builtin_cos(a);}
  661. A_STATIC AF1 ACosF1(AF1 a){return __builtin_cosf(a);}
  662. #else
  663. A_STATIC AD1 ACosD1(AD1 a){return cos(a);}
  664. A_STATIC AF1 ACosF1(AF1 a){return cosf(a);}
  665. #endif
  666. //------------------------------------------------------------------------------------------------------------------------------
  667. A_STATIC AD1 ADotD2(inAD2 a,inAD2 b){return a[0]*b[0]+a[1]*b[1];}
  668. A_STATIC AD1 ADotD3(inAD3 a,inAD3 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];}
  669. A_STATIC AD1 ADotD4(inAD4 a,inAD4 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3];}
  670. A_STATIC AF1 ADotF2(inAF2 a,inAF2 b){return a[0]*b[0]+a[1]*b[1];}
  671. A_STATIC AF1 ADotF3(inAF3 a,inAF3 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];}
  672. A_STATIC AF1 ADotF4(inAF4 a,inAF4 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3];}
  673. //------------------------------------------------------------------------------------------------------------------------------
  674. #ifdef A_GCC
  675. A_STATIC AD1 AExp2D1(AD1 a){return __builtin_exp2(a);}
  676. A_STATIC AF1 AExp2F1(AF1 a){return __builtin_exp2f(a);}
  677. #else
  678. A_STATIC AD1 AExp2D1(AD1 a){return exp2(a);}
  679. A_STATIC AF1 AExp2F1(AF1 a){return exp2f(a);}
  680. #endif
  681. //------------------------------------------------------------------------------------------------------------------------------
  682. #ifdef A_GCC
  683. A_STATIC AD1 AFloorD1(AD1 a){return __builtin_floor(a);}
  684. A_STATIC AF1 AFloorF1(AF1 a){return __builtin_floorf(a);}
  685. #else
  686. A_STATIC AD1 AFloorD1(AD1 a){return floor(a);}
  687. A_STATIC AF1 AFloorF1(AF1 a){return floorf(a);}
  688. #endif
  689. //------------------------------------------------------------------------------------------------------------------------------
  690. A_STATIC AD1 ALerpD1(AD1 a,AD1 b,AD1 c){return b*c+(-a*c+a);}
  691. A_STATIC AF1 ALerpF1(AF1 a,AF1 b,AF1 c){return b*c+(-a*c+a);}
  692. //------------------------------------------------------------------------------------------------------------------------------
  693. #ifdef A_GCC
  694. A_STATIC AD1 ALog2D1(AD1 a){return __builtin_log2(a);}
  695. A_STATIC AF1 ALog2F1(AF1 a){return __builtin_log2f(a);}
  696. #else
  697. A_STATIC AD1 ALog2D1(AD1 a){return log2(a);}
  698. A_STATIC AF1 ALog2F1(AF1 a){return log2f(a);}
  699. #endif
  700. //------------------------------------------------------------------------------------------------------------------------------
  701. A_STATIC AD1 AMaxD1(AD1 a,AD1 b){return a>b?a:b;}
  702. A_STATIC AF1 AMaxF1(AF1 a,AF1 b){return a>b?a:b;}
  703. A_STATIC AL1 AMaxL1(AL1 a,AL1 b){return a>b?a:b;}
  704. A_STATIC AU1 AMaxU1(AU1 a,AU1 b){return a>b?a:b;}
  705. //------------------------------------------------------------------------------------------------------------------------------
  706. // These follow the convention that A integer types don't have signage, until they are operated on.
  707. A_STATIC AL1 AMaxSL1(AL1 a,AL1 b){return (ASL1_(a)>ASL1_(b))?a:b;}
  708. A_STATIC AU1 AMaxSU1(AU1 a,AU1 b){return (ASU1_(a)>ASU1_(b))?a:b;}
  709. //------------------------------------------------------------------------------------------------------------------------------
  710. A_STATIC AD1 AMinD1(AD1 a,AD1 b){return a<b?a:b;}
  711. A_STATIC AF1 AMinF1(AF1 a,AF1 b){return a<b?a:b;}
  712. A_STATIC AL1 AMinL1(AL1 a,AL1 b){return a<b?a:b;}
  713. A_STATIC AU1 AMinU1(AU1 a,AU1 b){return a<b?a:b;}
  714. //------------------------------------------------------------------------------------------------------------------------------
  715. A_STATIC AL1 AMinSL1(AL1 a,AL1 b){return (ASL1_(a)<ASL1_(b))?a:b;}
  716. A_STATIC AU1 AMinSU1(AU1 a,AU1 b){return (ASU1_(a)<ASU1_(b))?a:b;}
  717. //------------------------------------------------------------------------------------------------------------------------------
  718. A_STATIC AD1 ARcpD1(AD1 a){return 1.0/a;}
  719. A_STATIC AF1 ARcpF1(AF1 a){return 1.0f/a;}
  720. //------------------------------------------------------------------------------------------------------------------------------
  721. A_STATIC AL1 AShrSL1(AL1 a,AL1 b){return AL1_(ASL1_(a)>>ASL1_(b));}
  722. A_STATIC AU1 AShrSU1(AU1 a,AU1 b){return AU1_(ASU1_(a)>>ASU1_(b));}
  723. //------------------------------------------------------------------------------------------------------------------------------
  724. #ifdef A_GCC
  725. A_STATIC AD1 ASinD1(AD1 a){return __builtin_sin(a);}
  726. A_STATIC AF1 ASinF1(AF1 a){return __builtin_sinf(a);}
  727. #else
  728. A_STATIC AD1 ASinD1(AD1 a){return sin(a);}
  729. A_STATIC AF1 ASinF1(AF1 a){return sinf(a);}
  730. #endif
  731. //------------------------------------------------------------------------------------------------------------------------------
  732. #ifdef A_GCC
  733. A_STATIC AD1 ASqrtD1(AD1 a){return __builtin_sqrt(a);}
  734. A_STATIC AF1 ASqrtF1(AF1 a){return __builtin_sqrtf(a);}
  735. #else
  736. A_STATIC AD1 ASqrtD1(AD1 a){return sqrt(a);}
  737. A_STATIC AF1 ASqrtF1(AF1 a){return sqrtf(a);}
  738. #endif
  739. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  740. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  741. //_____________________________________________________________/\_______________________________________________________________
  742. //==============================================================================================================================
  743. // SCALAR RETURN OPS - DEPENDENT
  744. //==============================================================================================================================
  745. A_STATIC AD1 AFractD1(AD1 a){return a-AFloorD1(a);}
  746. A_STATIC AF1 AFractF1(AF1 a){return a-AFloorF1(a);}
  747. //------------------------------------------------------------------------------------------------------------------------------
  748. A_STATIC AD1 APowD1(AD1 a,AD1 b){return AExp2D1(b*ALog2D1(a));}
  749. A_STATIC AF1 APowF1(AF1 a,AF1 b){return AExp2F1(b*ALog2F1(a));}
  750. //------------------------------------------------------------------------------------------------------------------------------
  751. A_STATIC AD1 ARsqD1(AD1 a){return ARcpD1(ASqrtD1(a));}
  752. A_STATIC AF1 ARsqF1(AF1 a){return ARcpF1(ASqrtF1(a));}
  753. //------------------------------------------------------------------------------------------------------------------------------
  754. A_STATIC AD1 ASatD1(AD1 a){return AMinD1(1.0,AMaxD1(0.0,a));}
  755. A_STATIC AF1 ASatF1(AF1 a){return AMinF1(1.0f,AMaxF1(0.0f,a));}
  756. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  757. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  758. //_____________________________________________________________/\_______________________________________________________________
  759. //==============================================================================================================================
  760. // VECTOR OPS
  761. //------------------------------------------------------------------------------------------------------------------------------
  762. // These are added as needed for production or prototyping, so not necessarily a complete set.
  763. // They follow a convention of taking in a destination and also returning the destination value to increase utility.
  764. //==============================================================================================================================
  765. A_STATIC retAD2 opAAbsD2(outAD2 d,inAD2 a){d[0]=AAbsD1(a[0]);d[1]=AAbsD1(a[1]);return d;}
  766. A_STATIC retAD3 opAAbsD3(outAD3 d,inAD3 a){d[0]=AAbsD1(a[0]);d[1]=AAbsD1(a[1]);d[2]=AAbsD1(a[2]);return d;}
  767. A_STATIC retAD4 opAAbsD4(outAD4 d,inAD4 a){d[0]=AAbsD1(a[0]);d[1]=AAbsD1(a[1]);d[2]=AAbsD1(a[2]);d[3]=AAbsD1(a[3]);return d;}
  768. //------------------------------------------------------------------------------------------------------------------------------
  769. A_STATIC retAF2 opAAbsF2(outAF2 d,inAF2 a){d[0]=AAbsF1(a[0]);d[1]=AAbsF1(a[1]);return d;}
  770. A_STATIC retAF3 opAAbsF3(outAF3 d,inAF3 a){d[0]=AAbsF1(a[0]);d[1]=AAbsF1(a[1]);d[2]=AAbsF1(a[2]);return d;}
  771. A_STATIC retAF4 opAAbsF4(outAF4 d,inAF4 a){d[0]=AAbsF1(a[0]);d[1]=AAbsF1(a[1]);d[2]=AAbsF1(a[2]);d[3]=AAbsF1(a[3]);return d;}
  772. //==============================================================================================================================
  773. A_STATIC retAD2 opAAddD2(outAD2 d,inAD2 a,inAD2 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];return d;}
  774. A_STATIC retAD3 opAAddD3(outAD3 d,inAD3 a,inAD3 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];d[2]=a[2]+b[2];return d;}
  775. A_STATIC retAD4 opAAddD4(outAD4 d,inAD4 a,inAD4 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];d[2]=a[2]+b[2];d[3]=a[3]+b[3];return d;}
  776. //------------------------------------------------------------------------------------------------------------------------------
  777. A_STATIC retAF2 opAAddF2(outAF2 d,inAF2 a,inAF2 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];return d;}
  778. A_STATIC retAF3 opAAddF3(outAF3 d,inAF3 a,inAF3 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];d[2]=a[2]+b[2];return d;}
  779. A_STATIC retAF4 opAAddF4(outAF4 d,inAF4 a,inAF4 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];d[2]=a[2]+b[2];d[3]=a[3]+b[3];return d;}
  780. //==============================================================================================================================
  781. A_STATIC retAD2 opACpyD2(outAD2 d,inAD2 a){d[0]=a[0];d[1]=a[1];return d;}
  782. A_STATIC retAD3 opACpyD3(outAD3 d,inAD3 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];return d;}
  783. A_STATIC retAD4 opACpyD4(outAD4 d,inAD4 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];return d;}
  784. //------------------------------------------------------------------------------------------------------------------------------
  785. A_STATIC retAF2 opACpyF2(outAF2 d,inAF2 a){d[0]=a[0];d[1]=a[1];return d;}
  786. A_STATIC retAF3 opACpyF3(outAF3 d,inAF3 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];return d;}
  787. A_STATIC retAF4 opACpyF4(outAF4 d,inAF4 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];d[3]=a[3];return d;}
  788. //==============================================================================================================================
  789. A_STATIC retAD2 opALerpD2(outAD2 d,inAD2 a,inAD2 b,inAD2 c){d[0]=ALerpD1(a[0],b[0],c[0]);d[1]=ALerpD1(a[1],b[1],c[1]);return d;}
  790. A_STATIC retAD3 opALerpD3(outAD3 d,inAD3 a,inAD3 b,inAD3 c){d[0]=ALerpD1(a[0],b[0],c[0]);d[1]=ALerpD1(a[1],b[1],c[1]);d[2]=ALerpD1(a[2],b[2],c[2]);return d;}
  791. A_STATIC retAD4 opALerpD4(outAD4 d,inAD4 a,inAD4 b,inAD4 c){d[0]=ALerpD1(a[0],b[0],c[0]);d[1]=ALerpD1(a[1],b[1],c[1]);d[2]=ALerpD1(a[2],b[2],c[2]);d[3]=ALerpD1(a[3],b[3],c[3]);return d;}
  792. //------------------------------------------------------------------------------------------------------------------------------
  793. A_STATIC retAF2 opALerpF2(outAF2 d,inAF2 a,inAF2 b,inAF2 c){d[0]=ALerpF1(a[0],b[0],c[0]);d[1]=ALerpF1(a[1],b[1],c[1]);return d;}
  794. A_STATIC retAF3 opALerpF3(outAF3 d,inAF3 a,inAF3 b,inAF3 c){d[0]=ALerpF1(a[0],b[0],c[0]);d[1]=ALerpF1(a[1],b[1],c[1]);d[2]=ALerpF1(a[2],b[2],c[2]);return d;}
  795. A_STATIC retAF4 opALerpF4(outAF4 d,inAF4 a,inAF4 b,inAF4 c){d[0]=ALerpF1(a[0],b[0],c[0]);d[1]=ALerpF1(a[1],b[1],c[1]);d[2]=ALerpF1(a[2],b[2],c[2]);d[3]=ALerpF1(a[3],b[3],c[3]);return d;}
  796. //==============================================================================================================================
  797. A_STATIC retAD2 opALerpOneD2(outAD2 d,inAD2 a,inAD2 b,AD1 c){d[0]=ALerpD1(a[0],b[0],c);d[1]=ALerpD1(a[1],b[1],c);return d;}
  798. A_STATIC retAD3 opALerpOneD3(outAD3 d,inAD3 a,inAD3 b,AD1 c){d[0]=ALerpD1(a[0],b[0],c);d[1]=ALerpD1(a[1],b[1],c);d[2]=ALerpD1(a[2],b[2],c);return d;}
  799. A_STATIC retAD4 opALerpOneD4(outAD4 d,inAD4 a,inAD4 b,AD1 c){d[0]=ALerpD1(a[0],b[0],c);d[1]=ALerpD1(a[1],b[1],c);d[2]=ALerpD1(a[2],b[2],c);d[3]=ALerpD1(a[3],b[3],c);return d;}
  800. //------------------------------------------------------------------------------------------------------------------------------
  801. A_STATIC retAF2 opALerpOneF2(outAF2 d,inAF2 a,inAF2 b,AF1 c){d[0]=ALerpF1(a[0],b[0],c);d[1]=ALerpF1(a[1],b[1],c);return d;}
  802. A_STATIC retAF3 opALerpOneF3(outAF3 d,inAF3 a,inAF3 b,AF1 c){d[0]=ALerpF1(a[0],b[0],c);d[1]=ALerpF1(a[1],b[1],c);d[2]=ALerpF1(a[2],b[2],c);return d;}
  803. A_STATIC retAF4 opALerpOneF4(outAF4 d,inAF4 a,inAF4 b,AF1 c){d[0]=ALerpF1(a[0],b[0],c);d[1]=ALerpF1(a[1],b[1],c);d[2]=ALerpF1(a[2],b[2],c);d[3]=ALerpF1(a[3],b[3],c);return d;}
  804. //==============================================================================================================================
  805. A_STATIC retAD2 opAMaxD2(outAD2 d,inAD2 a,inAD2 b){d[0]=AMaxD1(a[0],b[0]);d[1]=AMaxD1(a[1],b[1]);return d;}
  806. A_STATIC retAD3 opAMaxD3(outAD3 d,inAD3 a,inAD3 b){d[0]=AMaxD1(a[0],b[0]);d[1]=AMaxD1(a[1],b[1]);d[2]=AMaxD1(a[2],b[2]);return d;}
  807. A_STATIC retAD4 opAMaxD4(outAD4 d,inAD4 a,inAD4 b){d[0]=AMaxD1(a[0],b[0]);d[1]=AMaxD1(a[1],b[1]);d[2]=AMaxD1(a[2],b[2]);d[3]=AMaxD1(a[3],b[3]);return d;}
  808. //------------------------------------------------------------------------------------------------------------------------------
  809. A_STATIC retAF2 opAMaxF2(outAF2 d,inAF2 a,inAF2 b){d[0]=AMaxF1(a[0],b[0]);d[1]=AMaxF1(a[1],b[1]);return d;}
  810. A_STATIC retAF3 opAMaxF3(outAF3 d,inAF3 a,inAF3 b){d[0]=AMaxF1(a[0],b[0]);d[1]=AMaxF1(a[1],b[1]);d[2]=AMaxF1(a[2],b[2]);return d;}
  811. A_STATIC retAF4 opAMaxF4(outAF4 d,inAF4 a,inAF4 b){d[0]=AMaxF1(a[0],b[0]);d[1]=AMaxF1(a[1],b[1]);d[2]=AMaxF1(a[2],b[2]);d[3]=AMaxF1(a[3],b[3]);return d;}
  812. //==============================================================================================================================
  813. A_STATIC retAD2 opAMinD2(outAD2 d,inAD2 a,inAD2 b){d[0]=AMinD1(a[0],b[0]);d[1]=AMinD1(a[1],b[1]);return d;}
  814. A_STATIC retAD3 opAMinD3(outAD3 d,inAD3 a,inAD3 b){d[0]=AMinD1(a[0],b[0]);d[1]=AMinD1(a[1],b[1]);d[2]=AMinD1(a[2],b[2]);return d;}
  815. A_STATIC retAD4 opAMinD4(outAD4 d,inAD4 a,inAD4 b){d[0]=AMinD1(a[0],b[0]);d[1]=AMinD1(a[1],b[1]);d[2]=AMinD1(a[2],b[2]);d[3]=AMinD1(a[3],b[3]);return d;}
  816. //------------------------------------------------------------------------------------------------------------------------------
  817. A_STATIC retAF2 opAMinF2(outAF2 d,inAF2 a,inAF2 b){d[0]=AMinF1(a[0],b[0]);d[1]=AMinF1(a[1],b[1]);return d;}
  818. A_STATIC retAF3 opAMinF3(outAF3 d,inAF3 a,inAF3 b){d[0]=AMinF1(a[0],b[0]);d[1]=AMinF1(a[1],b[1]);d[2]=AMinF1(a[2],b[2]);return d;}
  819. A_STATIC retAF4 opAMinF4(outAF4 d,inAF4 a,inAF4 b){d[0]=AMinF1(a[0],b[0]);d[1]=AMinF1(a[1],b[1]);d[2]=AMinF1(a[2],b[2]);d[3]=AMinF1(a[3],b[3]);return d;}
  820. //==============================================================================================================================
  821. A_STATIC retAD2 opAMulD2(outAD2 d,inAD2 a,inAD2 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];return d;}
  822. A_STATIC retAD3 opAMulD3(outAD3 d,inAD3 a,inAD3 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];d[2]=a[2]*b[2];return d;}
  823. A_STATIC retAD4 opAMulD4(outAD4 d,inAD4 a,inAD4 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];d[2]=a[2]*b[2];d[3]=a[3]*b[3];return d;}
  824. //------------------------------------------------------------------------------------------------------------------------------
  825. A_STATIC retAF2 opAMulF2(outAF2 d,inAF2 a,inAF2 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];return d;}
  826. A_STATIC retAF3 opAMulF3(outAF3 d,inAF3 a,inAF3 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];d[2]=a[2]*b[2];return d;}
  827. A_STATIC retAF4 opAMulF4(outAF4 d,inAF4 a,inAF4 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];d[2]=a[2]*b[2];d[3]=a[3]*b[3];return d;}
  828. //==============================================================================================================================
  829. A_STATIC retAD2 opAMulOneD2(outAD2 d,inAD2 a,AD1 b){d[0]=a[0]*b;d[1]=a[1]*b;return d;}
  830. A_STATIC retAD3 opAMulOneD3(outAD3 d,inAD3 a,AD1 b){d[0]=a[0]*b;d[1]=a[1]*b;d[2]=a[2]*b;return d;}
  831. A_STATIC retAD4 opAMulOneD4(outAD4 d,inAD4 a,AD1 b){d[0]=a[0]*b;d[1]=a[1]*b;d[2]=a[2]*b;d[3]=a[3]*b;return d;}
  832. //------------------------------------------------------------------------------------------------------------------------------
  833. A_STATIC retAF2 opAMulOneF2(outAF2 d,inAF2 a,AF1 b){d[0]=a[0]*b;d[1]=a[1]*b;return d;}
  834. A_STATIC retAF3 opAMulOneF3(outAF3 d,inAF3 a,AF1 b){d[0]=a[0]*b;d[1]=a[1]*b;d[2]=a[2]*b;return d;}
  835. A_STATIC retAF4 opAMulOneF4(outAF4 d,inAF4 a,AF1 b){d[0]=a[0]*b;d[1]=a[1]*b;d[2]=a[2]*b;d[3]=a[3]*b;return d;}
  836. //==============================================================================================================================
  837. A_STATIC retAD2 opANegD2(outAD2 d,inAD2 a){d[0]=-a[0];d[1]=-a[1];return d;}
  838. A_STATIC retAD3 opANegD3(outAD3 d,inAD3 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];return d;}
  839. A_STATIC retAD4 opANegD4(outAD4 d,inAD4 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];d[3]=-a[3];return d;}
  840. //------------------------------------------------------------------------------------------------------------------------------
  841. A_STATIC retAF2 opANegF2(outAF2 d,inAF2 a){d[0]=-a[0];d[1]=-a[1];return d;}
  842. A_STATIC retAF3 opANegF3(outAF3 d,inAF3 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];return d;}
  843. A_STATIC retAF4 opANegF4(outAF4 d,inAF4 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];d[3]=-a[3];return d;}
  844. //==============================================================================================================================
  845. A_STATIC retAD2 opARcpD2(outAD2 d,inAD2 a){d[0]=ARcpD1(a[0]);d[1]=ARcpD1(a[1]);return d;}
  846. A_STATIC retAD3 opARcpD3(outAD3 d,inAD3 a){d[0]=ARcpD1(a[0]);d[1]=ARcpD1(a[1]);d[2]=ARcpD1(a[2]);return d;}
  847. A_STATIC retAD4 opARcpD4(outAD4 d,inAD4 a){d[0]=ARcpD1(a[0]);d[1]=ARcpD1(a[1]);d[2]=ARcpD1(a[2]);d[3]=ARcpD1(a[3]);return d;}
  848. //------------------------------------------------------------------------------------------------------------------------------
  849. A_STATIC retAF2 opARcpF2(outAF2 d,inAF2 a){d[0]=ARcpF1(a[0]);d[1]=ARcpF1(a[1]);return d;}
  850. A_STATIC retAF3 opARcpF3(outAF3 d,inAF3 a){d[0]=ARcpF1(a[0]);d[1]=ARcpF1(a[1]);d[2]=ARcpF1(a[2]);return d;}
  851. A_STATIC retAF4 opARcpF4(outAF4 d,inAF4 a){d[0]=ARcpF1(a[0]);d[1]=ARcpF1(a[1]);d[2]=ARcpF1(a[2]);d[3]=ARcpF1(a[3]);return d;}
  852. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  853. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  854. //_____________________________________________________________/\_______________________________________________________________
  855. //==============================================================================================================================
  856. // HALF FLOAT PACKING
  857. //==============================================================================================================================
  858. // Convert float to half (in lower 16-bits of output).
  859. // Same fast technique as documented here: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
  860. // Supports denormals.
  861. // Conversion rules are to make computations possibly "safer" on the GPU,
  862. // -INF & -NaN -> -65504
  863. // +INF & +NaN -> +65504
  864. A_STATIC AU1 AU1_AH1_AF1(AF1 f){
  865. static AW1 base[512]={
  866. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  867. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  868. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  869. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  870. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  871. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
  872. 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,
  873. 0x0200,0x0400,0x0800,0x0c00,0x1000,0x1400,0x1800,0x1c00,0x2000,0x2400,0x2800,0x2c00,0x3000,0x3400,0x3800,0x3c00,
  874. 0x4000,0x4400,0x4800,0x4c00,0x5000,0x5400,0x5800,0x5c00,0x6000,0x6400,0x6800,0x6c00,0x7000,0x7400,0x7800,0x7bff,
  875. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  876. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  877. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  878. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  879. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  880. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  881. 0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
  882. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  883. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  884. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  885. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  886. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  887. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
  888. 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8001,0x8002,0x8004,0x8008,0x8010,0x8020,0x8040,0x8080,0x8100,
  889. 0x8200,0x8400,0x8800,0x8c00,0x9000,0x9400,0x9800,0x9c00,0xa000,0xa400,0xa800,0xac00,0xb000,0xb400,0xb800,0xbc00,
  890. 0xc000,0xc400,0xc800,0xcc00,0xd000,0xd400,0xd800,0xdc00,0xe000,0xe400,0xe800,0xec00,0xf000,0xf400,0xf800,0xfbff,
  891. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  892. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  893. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  894. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  895. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  896. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
  897. 0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff};
  898. static AB1 shift[512]={
  899. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  900. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  901. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  902. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  903. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  904. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  905. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,0x0f,
  906. 0x0e,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,
  907. 0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x18,
  908. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  909. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  910. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  911. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  912. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  913. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  914. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  915. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  916. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  917. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  918. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  919. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  920. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  921. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,0x0f,
  922. 0x0e,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,
  923. 0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x18,
  924. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  925. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  926. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  927. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  928. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  929. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
  930. 0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18};
  931. union{AF1 f;AU1 u;}bits;bits.f=f;AU1 u=bits.u;AU1 i=u>>23;return (AU1)(base[i])+((u&0x7fffff)>>shift[i]);}
  932. //------------------------------------------------------------------------------------------------------------------------------
  933. // Used to output packed constant.
  934. A_STATIC AU1 AU1_AH2_AF2(inAF2 a){return AU1_AH1_AF1(a[0])+(AU1_AH1_AF1(a[1])<<16);}
  935. #endif
  936. //==============================================================================================================================
  937. // GLSL
  938. //==============================================================================================================================
  939. #if (defined(A_GLSL) && defined(A_GPU)) || (defined(ASPM_GLSL) && defined(ASPM_GPU))
  940. #ifndef A_SKIP_EXT
  941. #ifdef A_HALF
  942. #extension GL_EXT_shader_16bit_storage:require
  943. #extension GL_EXT_shader_explicit_arithmetic_types:require
  944. #endif
  945. //------------------------------------------------------------------------------------------------------------------------------
  946. #ifdef A_LONG
  947. #extension GL_ARB_gpu_shader_int64:require
  948. // TODO: Fixme to more portable extension!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  949. #extension GL_NV_shader_atomic_int64:require
  950. #endif
  951. //------------------------------------------------------------------------------------------------------------------------------
  952. #ifdef A_WAVE
  953. #extension GL_KHR_shader_subgroup_arithmetic:require
  954. #extension GL_KHR_shader_subgroup_ballot:require
  955. #extension GL_KHR_shader_subgroup_quad:require
  956. #extension GL_KHR_shader_subgroup_shuffle:require
  957. #endif
  958. #endif
  959. //==============================================================================================================================
  960. #define AP1 bool
  961. #define AP2 bvec2
  962. #define AP3 bvec3
  963. #define AP4 bvec4
  964. //------------------------------------------------------------------------------------------------------------------------------
  965. #define AF1 float
  966. #define AF2 vec2
  967. #define AF3 vec3
  968. #define AF4 vec4
  969. //------------------------------------------------------------------------------------------------------------------------------
  970. #define AU1 uint
  971. #define AU2 uvec2
  972. #define AU3 uvec3
  973. #define AU4 uvec4
  974. //------------------------------------------------------------------------------------------------------------------------------
  975. #define ASU1 int
  976. #define ASU2 ivec2
  977. #define ASU3 ivec3
  978. #define ASU4 ivec4
  979. //==============================================================================================================================
  980. #define AF1_AU1(x) uintBitsToFloat(AU1(x))
  981. #define AF2_AU2(x) uintBitsToFloat(AU2(x))
  982. #define AF3_AU3(x) uintBitsToFloat(AU3(x))
  983. #define AF4_AU4(x) uintBitsToFloat(AU4(x))
  984. //------------------------------------------------------------------------------------------------------------------------------
  985. #define AU1_AF1(x) floatBitsToUint(AF1(x))
  986. #define AU2_AF2(x) floatBitsToUint(AF2(x))
  987. #define AU3_AF3(x) floatBitsToUint(AF3(x))
  988. #define AU4_AF4(x) floatBitsToUint(AF4(x))
  989. //------------------------------------------------------------------------------------------------------------------------------
  990. #define AU1_AH2_AF2 packHalf2x16
  991. #define AU1_AW2Unorm_AF2 packUnorm2x16
  992. #define AU1_AB4Unorm_AF4 packUnorm4x8
  993. //------------------------------------------------------------------------------------------------------------------------------
  994. #define AF2_AH2_AU1 unpackHalf2x16
  995. #define AF2_AW2Unorm_AU1 unpackUnorm2x16
  996. #define AF4_AB4Unorm_AU1 unpackUnorm4x8
  997. //==============================================================================================================================
  998. AF1 AF1_x(AF1 a){return AF1(a);}
  999. AF2 AF2_x(AF1 a){return AF2(a,a);}
  1000. AF3 AF3_x(AF1 a){return AF3(a,a,a);}
  1001. AF4 AF4_x(AF1 a){return AF4(a,a,a,a);}
  1002. #define AF1_(a) AF1_x(AF1(a))
  1003. #define AF2_(a) AF2_x(AF1(a))
  1004. #define AF3_(a) AF3_x(AF1(a))
  1005. #define AF4_(a) AF4_x(AF1(a))
  1006. //------------------------------------------------------------------------------------------------------------------------------
  1007. AU1 AU1_x(AU1 a){return AU1(a);}
  1008. AU2 AU2_x(AU1 a){return AU2(a,a);}
  1009. AU3 AU3_x(AU1 a){return AU3(a,a,a);}
  1010. AU4 AU4_x(AU1 a){return AU4(a,a,a,a);}
  1011. #define AU1_(a) AU1_x(AU1(a))
  1012. #define AU2_(a) AU2_x(AU1(a))
  1013. #define AU3_(a) AU3_x(AU1(a))
  1014. #define AU4_(a) AU4_x(AU1(a))
  1015. //==============================================================================================================================
  1016. AU1 AAbsSU1(AU1 a){return AU1(abs(ASU1(a)));}
  1017. AU2 AAbsSU2(AU2 a){return AU2(abs(ASU2(a)));}
  1018. AU3 AAbsSU3(AU3 a){return AU3(abs(ASU3(a)));}
  1019. AU4 AAbsSU4(AU4 a){return AU4(abs(ASU4(a)));}
  1020. //------------------------------------------------------------------------------------------------------------------------------
  1021. AU1 ABfe(AU1 src,AU1 off,AU1 bits){return bitfieldExtract(src,ASU1(off),ASU1(bits));}
  1022. AU1 ABfi(AU1 src,AU1 ins,AU1 mask){return (ins&mask)|(src&(~mask));}
  1023. // Proxy for V_BFI_B32 where the 'mask' is set as 'bits', 'mask=(1<<bits)-1', and 'bits' needs to be an immediate.
  1024. AU1 ABfiM(AU1 src,AU1 ins,AU1 bits){return bitfieldInsert(src,ins,0,ASU1(bits));}
  1025. //------------------------------------------------------------------------------------------------------------------------------
  1026. // V_FRACT_F32 (note DX frac() is different).
  1027. AF1 AFractF1(AF1 x){return fract(x);}
  1028. AF2 AFractF2(AF2 x){return fract(x);}
  1029. AF3 AFractF3(AF3 x){return fract(x);}
  1030. AF4 AFractF4(AF4 x){return fract(x);}
  1031. //------------------------------------------------------------------------------------------------------------------------------
  1032. AF1 ALerpF1(AF1 x,AF1 y,AF1 a){return mix(x,y,a);}
  1033. AF2 ALerpF2(AF2 x,AF2 y,AF2 a){return mix(x,y,a);}
  1034. AF3 ALerpF3(AF3 x,AF3 y,AF3 a){return mix(x,y,a);}
  1035. AF4 ALerpF4(AF4 x,AF4 y,AF4 a){return mix(x,y,a);}
  1036. //------------------------------------------------------------------------------------------------------------------------------
  1037. // V_MAX3_F32.
  1038. AF1 AMax3F1(AF1 x,AF1 y,AF1 z){return max(x,max(y,z));}
  1039. AF2 AMax3F2(AF2 x,AF2 y,AF2 z){return max(x,max(y,z));}
  1040. AF3 AMax3F3(AF3 x,AF3 y,AF3 z){return max(x,max(y,z));}
  1041. AF4 AMax3F4(AF4 x,AF4 y,AF4 z){return max(x,max(y,z));}
  1042. //------------------------------------------------------------------------------------------------------------------------------
  1043. AU1 AMax3SU1(AU1 x,AU1 y,AU1 z){return AU1(max(ASU1(x),max(ASU1(y),ASU1(z))));}
  1044. AU2 AMax3SU2(AU2 x,AU2 y,AU2 z){return AU2(max(ASU2(x),max(ASU2(y),ASU2(z))));}
  1045. AU3 AMax3SU3(AU3 x,AU3 y,AU3 z){return AU3(max(ASU3(x),max(ASU3(y),ASU3(z))));}
  1046. AU4 AMax3SU4(AU4 x,AU4 y,AU4 z){return AU4(max(ASU4(x),max(ASU4(y),ASU4(z))));}
  1047. //------------------------------------------------------------------------------------------------------------------------------
  1048. AU1 AMax3U1(AU1 x,AU1 y,AU1 z){return max(x,max(y,z));}
  1049. AU2 AMax3U2(AU2 x,AU2 y,AU2 z){return max(x,max(y,z));}
  1050. AU3 AMax3U3(AU3 x,AU3 y,AU3 z){return max(x,max(y,z));}
  1051. AU4 AMax3U4(AU4 x,AU4 y,AU4 z){return max(x,max(y,z));}
  1052. //------------------------------------------------------------------------------------------------------------------------------
  1053. AU1 AMaxSU1(AU1 a,AU1 b){return AU1(max(ASU1(a),ASU1(b)));}
  1054. AU2 AMaxSU2(AU2 a,AU2 b){return AU2(max(ASU2(a),ASU2(b)));}
  1055. AU3 AMaxSU3(AU3 a,AU3 b){return AU3(max(ASU3(a),ASU3(b)));}
  1056. AU4 AMaxSU4(AU4 a,AU4 b){return AU4(max(ASU4(a),ASU4(b)));}
  1057. //------------------------------------------------------------------------------------------------------------------------------
  1058. // Clamp has an easier pattern match for med3 when some ordering is known.
  1059. // V_MED3_F32.
  1060. AF1 AMed3F1(AF1 x,AF1 y,AF1 z){return max(min(x,y),min(max(x,y),z));}
  1061. AF2 AMed3F2(AF2 x,AF2 y,AF2 z){return max(min(x,y),min(max(x,y),z));}
  1062. AF3 AMed3F3(AF3 x,AF3 y,AF3 z){return max(min(x,y),min(max(x,y),z));}
  1063. AF4 AMed3F4(AF4 x,AF4 y,AF4 z){return max(min(x,y),min(max(x,y),z));}
  1064. //------------------------------------------------------------------------------------------------------------------------------
  1065. // V_MIN3_F32.
  1066. AF1 AMin3F1(AF1 x,AF1 y,AF1 z){return min(x,min(y,z));}
  1067. AF2 AMin3F2(AF2 x,AF2 y,AF2 z){return min(x,min(y,z));}
  1068. AF3 AMin3F3(AF3 x,AF3 y,AF3 z){return min(x,min(y,z));}
  1069. AF4 AMin3F4(AF4 x,AF4 y,AF4 z){return min(x,min(y,z));}
  1070. //------------------------------------------------------------------------------------------------------------------------------
  1071. AU1 AMin3SU1(AU1 x,AU1 y,AU1 z){return AU1(min(ASU1(x),min(ASU1(y),ASU1(z))));}
  1072. AU2 AMin3SU2(AU2 x,AU2 y,AU2 z){return AU2(min(ASU2(x),min(ASU2(y),ASU2(z))));}
  1073. AU3 AMin3SU3(AU3 x,AU3 y,AU3 z){return AU3(min(ASU3(x),min(ASU3(y),ASU3(z))));}
  1074. AU4 AMin3SU4(AU4 x,AU4 y,AU4 z){return AU4(min(ASU4(x),min(ASU4(y),ASU4(z))));}
  1075. //------------------------------------------------------------------------------------------------------------------------------
  1076. AU1 AMin3U1(AU1 x,AU1 y,AU1 z){return min(x,min(y,z));}
  1077. AU2 AMin3U2(AU2 x,AU2 y,AU2 z){return min(x,min(y,z));}
  1078. AU3 AMin3U3(AU3 x,AU3 y,AU3 z){return min(x,min(y,z));}
  1079. AU4 AMin3U4(AU4 x,AU4 y,AU4 z){return min(x,min(y,z));}
  1080. //------------------------------------------------------------------------------------------------------------------------------
  1081. AU1 AMinSU1(AU1 a,AU1 b){return AU1(min(ASU1(a),ASU1(b)));}
  1082. AU2 AMinSU2(AU2 a,AU2 b){return AU2(min(ASU2(a),ASU2(b)));}
  1083. AU3 AMinSU3(AU3 a,AU3 b){return AU3(min(ASU3(a),ASU3(b)));}
  1084. AU4 AMinSU4(AU4 a,AU4 b){return AU4(min(ASU4(a),ASU4(b)));}
  1085. //------------------------------------------------------------------------------------------------------------------------------
  1086. // Normalized trig. Valid input domain is {-256 to +256}. No GLSL compiler intrinsic exists to map to this currently.
  1087. // V_COS_F32.
  1088. AF1 ANCosF1(AF1 x){return cos(x*AF1_(A_2PI));}
  1089. AF2 ANCosF2(AF2 x){return cos(x*AF2_(A_2PI));}
  1090. AF3 ANCosF3(AF3 x){return cos(x*AF3_(A_2PI));}
  1091. AF4 ANCosF4(AF4 x){return cos(x*AF4_(A_2PI));}
  1092. //------------------------------------------------------------------------------------------------------------------------------
  1093. // Normalized trig. Valid input domain is {-256 to +256}. No GLSL compiler intrinsic exists to map to this currently.
  1094. // V_SIN_F32.
  1095. AF1 ANSinF1(AF1 x){return sin(x*AF1_(A_2PI));}
  1096. AF2 ANSinF2(AF2 x){return sin(x*AF2_(A_2PI));}
  1097. AF3 ANSinF3(AF3 x){return sin(x*AF3_(A_2PI));}
  1098. AF4 ANSinF4(AF4 x){return sin(x*AF4_(A_2PI));}
  1099. //------------------------------------------------------------------------------------------------------------------------------
  1100. AF1 ARcpF1(AF1 x){return AF1_(1.0)/x;}
  1101. AF2 ARcpF2(AF2 x){return AF2_(1.0)/x;}
  1102. AF3 ARcpF3(AF3 x){return AF3_(1.0)/x;}
  1103. AF4 ARcpF4(AF4 x){return AF4_(1.0)/x;}
  1104. //------------------------------------------------------------------------------------------------------------------------------
  1105. AF1 ARsqF1(AF1 x){return AF1_(1.0)/sqrt(x);}
  1106. AF2 ARsqF2(AF2 x){return AF2_(1.0)/sqrt(x);}
  1107. AF3 ARsqF3(AF3 x){return AF3_(1.0)/sqrt(x);}
  1108. AF4 ARsqF4(AF4 x){return AF4_(1.0)/sqrt(x);}
  1109. //------------------------------------------------------------------------------------------------------------------------------
  1110. AF1 ASatF1(AF1 x){return clamp(x,AF1_(0.0),AF1_(1.0));}
  1111. AF2 ASatF2(AF2 x){return clamp(x,AF2_(0.0),AF2_(1.0));}
  1112. AF3 ASatF3(AF3 x){return clamp(x,AF3_(0.0),AF3_(1.0));}
  1113. AF4 ASatF4(AF4 x){return clamp(x,AF4_(0.0),AF4_(1.0));}
  1114. //------------------------------------------------------------------------------------------------------------------------------
  1115. AU1 AShrSU1(AU1 a,AU1 b){return AU1(ASU1(a)>>ASU1(b));}
  1116. AU2 AShrSU2(AU2 a,AU2 b){return AU2(ASU2(a)>>ASU2(b));}
  1117. AU3 AShrSU3(AU3 a,AU3 b){return AU3(ASU3(a)>>ASU3(b));}
  1118. AU4 AShrSU4(AU4 a,AU4 b){return AU4(ASU4(a)>>ASU4(b));}
  1119. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1120. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1121. //_____________________________________________________________/\_______________________________________________________________
  1122. //==============================================================================================================================
  1123. // GLSL BYTE
  1124. //==============================================================================================================================
  1125. #ifdef A_BYTE
  1126. #define AB1 uint8_t
  1127. #define AB2 u8vec2
  1128. #define AB3 u8vec3
  1129. #define AB4 u8vec4
  1130. //------------------------------------------------------------------------------------------------------------------------------
  1131. #define ASB1 int8_t
  1132. #define ASB2 i8vec2
  1133. #define ASB3 i8vec3
  1134. #define ASB4 i8vec4
  1135. //------------------------------------------------------------------------------------------------------------------------------
  1136. AB1 AB1_x(AB1 a){return AB1(a);}
  1137. AB2 AB2_x(AB1 a){return AB2(a,a);}
  1138. AB3 AB3_x(AB1 a){return AB3(a,a,a);}
  1139. AB4 AB4_x(AB1 a){return AB4(a,a,a,a);}
  1140. #define AB1_(a) AB1_x(AB1(a))
  1141. #define AB2_(a) AB2_x(AB1(a))
  1142. #define AB3_(a) AB3_x(AB1(a))
  1143. #define AB4_(a) AB4_x(AB1(a))
  1144. #endif
  1145. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1146. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1147. //_____________________________________________________________/\_______________________________________________________________
  1148. //==============================================================================================================================
  1149. // GLSL HALF
  1150. //==============================================================================================================================
  1151. #ifdef A_HALF
  1152. #define AH1 float16_t
  1153. #define AH2 f16vec2
  1154. #define AH3 f16vec3
  1155. #define AH4 f16vec4
  1156. //------------------------------------------------------------------------------------------------------------------------------
  1157. #define AW1 uint16_t
  1158. #define AW2 u16vec2
  1159. #define AW3 u16vec3
  1160. #define AW4 u16vec4
  1161. //------------------------------------------------------------------------------------------------------------------------------
  1162. #define ASW1 int16_t
  1163. #define ASW2 i16vec2
  1164. #define ASW3 i16vec3
  1165. #define ASW4 i16vec4
  1166. //==============================================================================================================================
  1167. #define AH2_AU1(x) unpackFloat2x16(AU1(x))
  1168. AH4 AH4_AU2_x(AU2 x){return AH4(unpackFloat2x16(x.x),unpackFloat2x16(x.y));}
  1169. #define AH4_AU2(x) AH4_AU2_x(AU2(x))
  1170. #define AW2_AU1(x) unpackUint2x16(AU1(x))
  1171. #define AW4_AU2(x) unpackUint4x16(pack64(AU2(x)))
  1172. //------------------------------------------------------------------------------------------------------------------------------
  1173. #define AU1_AH2(x) packFloat2x16(AH2(x))
  1174. AU2 AU2_AH4_x(AH4 x){return AU2(packFloat2x16(x.xy),packFloat2x16(x.zw));}
  1175. #define AU2_AH4(x) AU2_AH4_x(AH4(x))
  1176. #define AU1_AW2(x) packUint2x16(AW2(x))
  1177. #define AU2_AW4(x) unpack32(packUint4x16(AW4(x)))
  1178. //==============================================================================================================================
  1179. #define AW1_AH1(x) halfBitsToUint16(AH1(x))
  1180. #define AW2_AH2(x) halfBitsToUint16(AH2(x))
  1181. #define AW3_AH3(x) halfBitsToUint16(AH3(x))
  1182. #define AW4_AH4(x) halfBitsToUint16(AH4(x))
  1183. //------------------------------------------------------------------------------------------------------------------------------
  1184. #define AH1_AW1(x) uint16BitsToHalf(AW1(x))
  1185. #define AH2_AW2(x) uint16BitsToHalf(AW2(x))
  1186. #define AH3_AW3(x) uint16BitsToHalf(AW3(x))
  1187. #define AH4_AW4(x) uint16BitsToHalf(AW4(x))
  1188. //==============================================================================================================================
  1189. AH1 AH1_x(AH1 a){return AH1(a);}
  1190. AH2 AH2_x(AH1 a){return AH2(a,a);}
  1191. AH3 AH3_x(AH1 a){return AH3(a,a,a);}
  1192. AH4 AH4_x(AH1 a){return AH4(a,a,a,a);}
  1193. #define AH1_(a) AH1_x(AH1(a))
  1194. #define AH2_(a) AH2_x(AH1(a))
  1195. #define AH3_(a) AH3_x(AH1(a))
  1196. #define AH4_(a) AH4_x(AH1(a))
  1197. //------------------------------------------------------------------------------------------------------------------------------
  1198. AW1 AW1_x(AW1 a){return AW1(a);}
  1199. AW2 AW2_x(AW1 a){return AW2(a,a);}
  1200. AW3 AW3_x(AW1 a){return AW3(a,a,a);}
  1201. AW4 AW4_x(AW1 a){return AW4(a,a,a,a);}
  1202. #define AW1_(a) AW1_x(AW1(a))
  1203. #define AW2_(a) AW2_x(AW1(a))
  1204. #define AW3_(a) AW3_x(AW1(a))
  1205. #define AW4_(a) AW4_x(AW1(a))
  1206. //==============================================================================================================================
  1207. AW1 AAbsSW1(AW1 a){return AW1(abs(ASW1(a)));}
  1208. AW2 AAbsSW2(AW2 a){return AW2(abs(ASW2(a)));}
  1209. AW3 AAbsSW3(AW3 a){return AW3(abs(ASW3(a)));}
  1210. AW4 AAbsSW4(AW4 a){return AW4(abs(ASW4(a)));}
  1211. //------------------------------------------------------------------------------------------------------------------------------
  1212. AH1 AFractH1(AH1 x){return fract(x);}
  1213. AH2 AFractH2(AH2 x){return fract(x);}
  1214. AH3 AFractH3(AH3 x){return fract(x);}
  1215. AH4 AFractH4(AH4 x){return fract(x);}
  1216. //------------------------------------------------------------------------------------------------------------------------------
  1217. AH1 ALerpH1(AH1 x,AH1 y,AH1 a){return mix(x,y,a);}
  1218. AH2 ALerpH2(AH2 x,AH2 y,AH2 a){return mix(x,y,a);}
  1219. AH3 ALerpH3(AH3 x,AH3 y,AH3 a){return mix(x,y,a);}
  1220. AH4 ALerpH4(AH4 x,AH4 y,AH4 a){return mix(x,y,a);}
  1221. //------------------------------------------------------------------------------------------------------------------------------
  1222. // No packed version of max3.
  1223. AH1 AMax3H1(AH1 x,AH1 y,AH1 z){return max(x,max(y,z));}
  1224. AH2 AMax3H2(AH2 x,AH2 y,AH2 z){return max(x,max(y,z));}
  1225. AH3 AMax3H3(AH3 x,AH3 y,AH3 z){return max(x,max(y,z));}
  1226. AH4 AMax3H4(AH4 x,AH4 y,AH4 z){return max(x,max(y,z));}
  1227. //------------------------------------------------------------------------------------------------------------------------------
  1228. AW1 AMaxSW1(AW1 a,AW1 b){return AW1(max(ASU1(a),ASU1(b)));}
  1229. AW2 AMaxSW2(AW2 a,AW2 b){return AW2(max(ASU2(a),ASU2(b)));}
  1230. AW3 AMaxSW3(AW3 a,AW3 b){return AW3(max(ASU3(a),ASU3(b)));}
  1231. AW4 AMaxSW4(AW4 a,AW4 b){return AW4(max(ASU4(a),ASU4(b)));}
  1232. //------------------------------------------------------------------------------------------------------------------------------
  1233. // No packed version of min3.
  1234. AH1 AMin3H1(AH1 x,AH1 y,AH1 z){return min(x,min(y,z));}
  1235. AH2 AMin3H2(AH2 x,AH2 y,AH2 z){return min(x,min(y,z));}
  1236. AH3 AMin3H3(AH3 x,AH3 y,AH3 z){return min(x,min(y,z));}
  1237. AH4 AMin3H4(AH4 x,AH4 y,AH4 z){return min(x,min(y,z));}
  1238. //------------------------------------------------------------------------------------------------------------------------------
  1239. AW1 AMinSW1(AW1 a,AW1 b){return AW1(min(ASU1(a),ASU1(b)));}
  1240. AW2 AMinSW2(AW2 a,AW2 b){return AW2(min(ASU2(a),ASU2(b)));}
  1241. AW3 AMinSW3(AW3 a,AW3 b){return AW3(min(ASU3(a),ASU3(b)));}
  1242. AW4 AMinSW4(AW4 a,AW4 b){return AW4(min(ASU4(a),ASU4(b)));}
  1243. //------------------------------------------------------------------------------------------------------------------------------
  1244. AH1 ARcpH1(AH1 x){return AH1_(1.0)/x;}
  1245. AH2 ARcpH2(AH2 x){return AH2_(1.0)/x;}
  1246. AH3 ARcpH3(AH3 x){return AH3_(1.0)/x;}
  1247. AH4 ARcpH4(AH4 x){return AH4_(1.0)/x;}
  1248. //------------------------------------------------------------------------------------------------------------------------------
  1249. AH1 ARsqH1(AH1 x){return AH1_(1.0)/sqrt(x);}
  1250. AH2 ARsqH2(AH2 x){return AH2_(1.0)/sqrt(x);}
  1251. AH3 ARsqH3(AH3 x){return AH3_(1.0)/sqrt(x);}
  1252. AH4 ARsqH4(AH4 x){return AH4_(1.0)/sqrt(x);}
  1253. //------------------------------------------------------------------------------------------------------------------------------
  1254. AH1 ASatH1(AH1 x){return clamp(x,AH1_(0.0),AH1_(1.0));}
  1255. AH2 ASatH2(AH2 x){return clamp(x,AH2_(0.0),AH2_(1.0));}
  1256. AH3 ASatH3(AH3 x){return clamp(x,AH3_(0.0),AH3_(1.0));}
  1257. AH4 ASatH4(AH4 x){return clamp(x,AH4_(0.0),AH4_(1.0));}
  1258. //------------------------------------------------------------------------------------------------------------------------------
  1259. AW1 AShrSW1(AW1 a,AW1 b){return AW1(ASW1(a)>>ASW1(b));}
  1260. AW2 AShrSW2(AW2 a,AW2 b){return AW2(ASW2(a)>>ASW2(b));}
  1261. AW3 AShrSW3(AW3 a,AW3 b){return AW3(ASW3(a)>>ASW3(b));}
  1262. AW4 AShrSW4(AW4 a,AW4 b){return AW4(ASW4(a)>>ASW4(b));}
  1263. #endif
  1264. //_____________________________________________________________/\_______________________________________________________________
  1265. //==============================================================================================================================
  1266. // GLSL DOUBLE
  1267. //==============================================================================================================================
  1268. #ifdef A_DUBL
  1269. #define AD1 double
  1270. #define AD2 dvec2
  1271. #define AD3 dvec3
  1272. #define AD4 dvec4
  1273. //------------------------------------------------------------------------------------------------------------------------------
  1274. AD1 AD1_x(AD1 a){return AD1(a);}
  1275. AD2 AD2_x(AD1 a){return AD2(a,a);}
  1276. AD3 AD3_x(AD1 a){return AD3(a,a,a);}
  1277. AD4 AD4_x(AD1 a){return AD4(a,a,a,a);}
  1278. #define AD1_(a) AD1_x(AD1(a))
  1279. #define AD2_(a) AD2_x(AD1(a))
  1280. #define AD3_(a) AD3_x(AD1(a))
  1281. #define AD4_(a) AD4_x(AD1(a))
  1282. //==============================================================================================================================
  1283. AD1 AFractD1(AD1 x){return fract(x);}
  1284. AD2 AFractD2(AD2 x){return fract(x);}
  1285. AD3 AFractD3(AD3 x){return fract(x);}
  1286. AD4 AFractD4(AD4 x){return fract(x);}
  1287. //------------------------------------------------------------------------------------------------------------------------------
  1288. AD1 ALerpD1(AD1 x,AD1 y,AD1 a){return mix(x,y,a);}
  1289. AD2 ALerpD2(AD2 x,AD2 y,AD2 a){return mix(x,y,a);}
  1290. AD3 ALerpD3(AD3 x,AD3 y,AD3 a){return mix(x,y,a);}
  1291. AD4 ALerpD4(AD4 x,AD4 y,AD4 a){return mix(x,y,a);}
  1292. //------------------------------------------------------------------------------------------------------------------------------
  1293. AD1 ARcpD1(AD1 x){return AD1_(1.0)/x;}
  1294. AD2 ARcpD2(AD2 x){return AD2_(1.0)/x;}
  1295. AD3 ARcpD3(AD3 x){return AD3_(1.0)/x;}
  1296. AD4 ARcpD4(AD4 x){return AD4_(1.0)/x;}
  1297. //------------------------------------------------------------------------------------------------------------------------------
  1298. AD1 ARsqD1(AD1 x){return AD1_(1.0)/sqrt(x);}
  1299. AD2 ARsqD2(AD2 x){return AD2_(1.0)/sqrt(x);}
  1300. AD3 ARsqD3(AD3 x){return AD3_(1.0)/sqrt(x);}
  1301. AD4 ARsqD4(AD4 x){return AD4_(1.0)/sqrt(x);}
  1302. //------------------------------------------------------------------------------------------------------------------------------
  1303. AD1 ASatD1(AD1 x){return clamp(x,AD1_(0.0),AD1_(1.0));}
  1304. AD2 ASatD2(AD2 x){return clamp(x,AD2_(0.0),AD2_(1.0));}
  1305. AD3 ASatD3(AD3 x){return clamp(x,AD3_(0.0),AD3_(1.0));}
  1306. AD4 ASatD4(AD4 x){return clamp(x,AD4_(0.0),AD4_(1.0));}
  1307. #endif
  1308. //_____________________________________________________________/\_______________________________________________________________
  1309. //==============================================================================================================================
  1310. // GLSL LONG
  1311. //==============================================================================================================================
  1312. #ifdef A_LONG
  1313. #define AL1 uint64_t
  1314. #define AL2 u64vec2
  1315. #define AL3 u64vec3
  1316. #define AL4 u64vec4
  1317. //------------------------------------------------------------------------------------------------------------------------------
  1318. #define ASL1 int64_t
  1319. #define ASL2 i64vec2
  1320. #define ASL3 i64vec3
  1321. #define ASL4 i64vec4
  1322. //------------------------------------------------------------------------------------------------------------------------------
  1323. #define AL1_AU2(x) packUint2x32(AU2(x))
  1324. #define AU2_AL1(x) unpackUint2x32(AL1(x))
  1325. //------------------------------------------------------------------------------------------------------------------------------
  1326. AL1 AL1_x(AL1 a){return AL1(a);}
  1327. AL2 AL2_x(AL1 a){return AL2(a,a);}
  1328. AL3 AL3_x(AL1 a){return AL3(a,a,a);}
  1329. AL4 AL4_x(AL1 a){return AL4(a,a,a,a);}
  1330. #define AL1_(a) AL1_x(AL1(a))
  1331. #define AL2_(a) AL2_x(AL1(a))
  1332. #define AL3_(a) AL3_x(AL1(a))
  1333. #define AL4_(a) AL4_x(AL1(a))
  1334. //==============================================================================================================================
  1335. AL1 AAbsSL1(AL1 a){return AL1(abs(ASL1(a)));}
  1336. AL2 AAbsSL2(AL2 a){return AL2(abs(ASL2(a)));}
  1337. AL3 AAbsSL3(AL3 a){return AL3(abs(ASL3(a)));}
  1338. AL4 AAbsSL4(AL4 a){return AL4(abs(ASL4(a)));}
  1339. //------------------------------------------------------------------------------------------------------------------------------
  1340. AL1 AMaxSL1(AL1 a,AL1 b){return AL1(max(ASU1(a),ASU1(b)));}
  1341. AL2 AMaxSL2(AL2 a,AL2 b){return AL2(max(ASU2(a),ASU2(b)));}
  1342. AL3 AMaxSL3(AL3 a,AL3 b){return AL3(max(ASU3(a),ASU3(b)));}
  1343. AL4 AMaxSL4(AL4 a,AL4 b){return AL4(max(ASU4(a),ASU4(b)));}
  1344. //------------------------------------------------------------------------------------------------------------------------------
  1345. AL1 AMinSL1(AL1 a,AL1 b){return AL1(min(ASU1(a),ASU1(b)));}
  1346. AL2 AMinSL2(AL2 a,AL2 b){return AL2(min(ASU2(a),ASU2(b)));}
  1347. AL3 AMinSL3(AL3 a,AL3 b){return AL3(min(ASU3(a),ASU3(b)));}
  1348. AL4 AMinSL4(AL4 a,AL4 b){return AL4(min(ASU4(a),ASU4(b)));}
  1349. #endif
  1350. //_____________________________________________________________/\_______________________________________________________________
  1351. //==============================================================================================================================
  1352. // WAVE OPERATIONS
  1353. //==============================================================================================================================
  1354. #ifdef A_WAVE
  1355. AF1 AWaveAdd(AF1 v){return subgroupAdd(v);}
  1356. AF2 AWaveAdd(AF2 v){return subgroupAdd(v);}
  1357. AF3 AWaveAdd(AF3 v){return subgroupAdd(v);}
  1358. AF4 AWaveAdd(AF4 v){return subgroupAdd(v);}
  1359. #endif
  1360. //==============================================================================================================================
  1361. #endif
  1362. //==============================================================================================================================
  1363. // HLSL
  1364. //==============================================================================================================================
  1365. #if (defined(A_HLSL) && defined(A_GPU)) || (defined(ASPM_HLSL) && defined(ASPM_GPU))
  1366. #define AP1 bool
  1367. #define AP2 bool2
  1368. #define AP3 bool3
  1369. #define AP4 bool4
  1370. //------------------------------------------------------------------------------------------------------------------------------
  1371. #define AF1 float
  1372. #define AF2 float2
  1373. #define AF3 float3
  1374. #define AF4 float4
  1375. //------------------------------------------------------------------------------------------------------------------------------
  1376. #define AU1 uint
  1377. #define AU2 uint2
  1378. #define AU3 uint3
  1379. #define AU4 uint4
  1380. //------------------------------------------------------------------------------------------------------------------------------
  1381. #define ASU1 int
  1382. #define ASU2 int2
  1383. #define ASU3 int3
  1384. #define ASU4 int4
  1385. //==============================================================================================================================
  1386. #define AF1_AU1(x) asfloat(AU1(x))
  1387. #define AF2_AU2(x) asfloat(AU2(x))
  1388. #define AF3_AU3(x) asfloat(AU3(x))
  1389. #define AF4_AU4(x) asfloat(AU4(x))
  1390. //------------------------------------------------------------------------------------------------------------------------------
  1391. #define AU1_AF1(x) asuint(AF1(x))
  1392. #define AU2_AF2(x) asuint(AF2(x))
  1393. #define AU3_AF3(x) asuint(AF3(x))
  1394. #define AU4_AF4(x) asuint(AF4(x))
  1395. //------------------------------------------------------------------------------------------------------------------------------
  1396. AU1 AU1_AH2_AF2_x(AF2 a){return f32tof16(a.x)|(f32tof16(a.y)<<16);}
  1397. #define AU1_AH2_AF2(a) AU1_AH2_AF2_x(AF2(a))
  1398. #define AU1_AB4Unorm_AF4(x) D3DCOLORtoUBYTE4(AF4(x))
  1399. //------------------------------------------------------------------------------------------------------------------------------
  1400. AF2 AF2_AH2_AU1_x(AU1 x){return AF2(f16tof32(x&0xFFFF),f16tof32(x>>16));}
  1401. #define AF2_AH2_AU1(x) AF2_AH2_AU1_x(AU1(x))
  1402. //==============================================================================================================================
  1403. AF1 AF1_x(AF1 a){return AF1(a);}
  1404. AF2 AF2_x(AF1 a){return AF2(a,a);}
  1405. AF3 AF3_x(AF1 a){return AF3(a,a,a);}
  1406. AF4 AF4_x(AF1 a){return AF4(a,a,a,a);}
  1407. #define AF1_(a) AF1_x(AF1(a))
  1408. #define AF2_(a) AF2_x(AF1(a))
  1409. #define AF3_(a) AF3_x(AF1(a))
  1410. #define AF4_(a) AF4_x(AF1(a))
  1411. //------------------------------------------------------------------------------------------------------------------------------
  1412. AU1 AU1_x(AU1 a){return AU1(a);}
  1413. AU2 AU2_x(AU1 a){return AU2(a,a);}
  1414. AU3 AU3_x(AU1 a){return AU3(a,a,a);}
  1415. AU4 AU4_x(AU1 a){return AU4(a,a,a,a);}
  1416. #define AU1_(a) AU1_x(AU1(a))
  1417. #define AU2_(a) AU2_x(AU1(a))
  1418. #define AU3_(a) AU3_x(AU1(a))
  1419. #define AU4_(a) AU4_x(AU1(a))
  1420. //==============================================================================================================================
  1421. AU1 AAbsSU1(AU1 a){return AU1(abs(ASU1(a)));}
  1422. AU2 AAbsSU2(AU2 a){return AU2(abs(ASU2(a)));}
  1423. AU3 AAbsSU3(AU3 a){return AU3(abs(ASU3(a)));}
  1424. AU4 AAbsSU4(AU4 a){return AU4(abs(ASU4(a)));}
  1425. //------------------------------------------------------------------------------------------------------------------------------
  1426. AU1 ABfe(AU1 src,AU1 off,AU1 bits){AU1 mask=(1<<bits)-1;return (src>>off)&mask;}
  1427. AU1 ABfi(AU1 src,AU1 ins,AU1 mask){return (ins&mask)|(src&(~mask));}
  1428. AU1 ABfiM(AU1 src,AU1 ins,AU1 bits){AU1 mask=(1<<bits)-1;return (ins&mask)|(src&(~mask));}
  1429. //------------------------------------------------------------------------------------------------------------------------------
  1430. AF1 AFractF1(AF1 x){return x-floor(x);}
  1431. AF2 AFractF2(AF2 x){return x-floor(x);}
  1432. AF3 AFractF3(AF3 x){return x-floor(x);}
  1433. AF4 AFractF4(AF4 x){return x-floor(x);}
  1434. //------------------------------------------------------------------------------------------------------------------------------
  1435. AF1 ALerpF1(AF1 x,AF1 y,AF1 a){return lerp(x,y,a);}
  1436. AF2 ALerpF2(AF2 x,AF2 y,AF2 a){return lerp(x,y,a);}
  1437. AF3 ALerpF3(AF3 x,AF3 y,AF3 a){return lerp(x,y,a);}
  1438. AF4 ALerpF4(AF4 x,AF4 y,AF4 a){return lerp(x,y,a);}
  1439. //------------------------------------------------------------------------------------------------------------------------------
  1440. AF1 AMax3F1(AF1 x,AF1 y,AF1 z){return max(x,max(y,z));}
  1441. AF2 AMax3F2(AF2 x,AF2 y,AF2 z){return max(x,max(y,z));}
  1442. AF3 AMax3F3(AF3 x,AF3 y,AF3 z){return max(x,max(y,z));}
  1443. AF4 AMax3F4(AF4 x,AF4 y,AF4 z){return max(x,max(y,z));}
  1444. //------------------------------------------------------------------------------------------------------------------------------
  1445. AU1 AMax3SU1(AU1 x,AU1 y,AU1 z){return AU1(max(ASU1(x),max(ASU1(y),ASU1(z))));}
  1446. AU2 AMax3SU2(AU2 x,AU2 y,AU2 z){return AU2(max(ASU2(x),max(ASU2(y),ASU2(z))));}
  1447. AU3 AMax3SU3(AU3 x,AU3 y,AU3 z){return AU3(max(ASU3(x),max(ASU3(y),ASU3(z))));}
  1448. AU4 AMax3SU4(AU4 x,AU4 y,AU4 z){return AU4(max(ASU4(x),max(ASU4(y),ASU4(z))));}
  1449. //------------------------------------------------------------------------------------------------------------------------------
  1450. AU1 AMax3U1(AU1 x,AU1 y,AU1 z){return max(x,max(y,z));}
  1451. AU2 AMax3U2(AU2 x,AU2 y,AU2 z){return max(x,max(y,z));}
  1452. AU3 AMax3U3(AU3 x,AU3 y,AU3 z){return max(x,max(y,z));}
  1453. AU4 AMax3U4(AU4 x,AU4 y,AU4 z){return max(x,max(y,z));}
  1454. //------------------------------------------------------------------------------------------------------------------------------
  1455. AU1 AMaxSU1(AU1 a,AU1 b){return AU1(max(ASU1(a),ASU1(b)));}
  1456. AU2 AMaxSU2(AU2 a,AU2 b){return AU2(max(ASU2(a),ASU2(b)));}
  1457. AU3 AMaxSU3(AU3 a,AU3 b){return AU3(max(ASU3(a),ASU3(b)));}
  1458. AU4 AMaxSU4(AU4 a,AU4 b){return AU4(max(ASU4(a),ASU4(b)));}
  1459. //------------------------------------------------------------------------------------------------------------------------------
  1460. AF1 AMed3F1(AF1 x,AF1 y,AF1 z){return max(min(x,y),min(max(x,y),z));}
  1461. AF2 AMed3F2(AF2 x,AF2 y,AF2 z){return max(min(x,y),min(max(x,y),z));}
  1462. AF3 AMed3F3(AF3 x,AF3 y,AF3 z){return max(min(x,y),min(max(x,y),z));}
  1463. AF4 AMed3F4(AF4 x,AF4 y,AF4 z){return max(min(x,y),min(max(x,y),z));}
  1464. //------------------------------------------------------------------------------------------------------------------------------
  1465. AF1 AMin3F1(AF1 x,AF1 y,AF1 z){return min(x,min(y,z));}
  1466. AF2 AMin3F2(AF2 x,AF2 y,AF2 z){return min(x,min(y,z));}
  1467. AF3 AMin3F3(AF3 x,AF3 y,AF3 z){return min(x,min(y,z));}
  1468. AF4 AMin3F4(AF4 x,AF4 y,AF4 z){return min(x,min(y,z));}
  1469. //------------------------------------------------------------------------------------------------------------------------------
  1470. AU1 AMin3SU1(AU1 x,AU1 y,AU1 z){return AU1(min(ASU1(x),min(ASU1(y),ASU1(z))));}
  1471. AU2 AMin3SU2(AU2 x,AU2 y,AU2 z){return AU2(min(ASU2(x),min(ASU2(y),ASU2(z))));}
  1472. AU3 AMin3SU3(AU3 x,AU3 y,AU3 z){return AU3(min(ASU3(x),min(ASU3(y),ASU3(z))));}
  1473. AU4 AMin3SU4(AU4 x,AU4 y,AU4 z){return AU4(min(ASU4(x),min(ASU4(y),ASU4(z))));}
  1474. //------------------------------------------------------------------------------------------------------------------------------
  1475. AU1 AMin3U1(AU1 x,AU1 y,AU1 z){return min(x,min(y,z));}
  1476. AU2 AMin3U2(AU2 x,AU2 y,AU2 z){return min(x,min(y,z));}
  1477. AU3 AMin3U3(AU3 x,AU3 y,AU3 z){return min(x,min(y,z));}
  1478. AU4 AMin3U4(AU4 x,AU4 y,AU4 z){return min(x,min(y,z));}
  1479. //------------------------------------------------------------------------------------------------------------------------------
  1480. AU1 AMinSU1(AU1 a,AU1 b){return AU1(min(ASU1(a),ASU1(b)));}
  1481. AU2 AMinSU2(AU2 a,AU2 b){return AU2(min(ASU2(a),ASU2(b)));}
  1482. AU3 AMinSU3(AU3 a,AU3 b){return AU3(min(ASU3(a),ASU3(b)));}
  1483. AU4 AMinSU4(AU4 a,AU4 b){return AU4(min(ASU4(a),ASU4(b)));}
  1484. //------------------------------------------------------------------------------------------------------------------------------
  1485. AF1 ANCosF1(AF1 x){return cos(x*AF1_(A_2PI));}
  1486. AF2 ANCosF2(AF2 x){return cos(x*AF2_(A_2PI));}
  1487. AF3 ANCosF3(AF3 x){return cos(x*AF3_(A_2PI));}
  1488. AF4 ANCosF4(AF4 x){return cos(x*AF4_(A_2PI));}
  1489. //------------------------------------------------------------------------------------------------------------------------------
  1490. AF1 ANSinF1(AF1 x){return sin(x*AF1_(A_2PI));}
  1491. AF2 ANSinF2(AF2 x){return sin(x*AF2_(A_2PI));}
  1492. AF3 ANSinF3(AF3 x){return sin(x*AF3_(A_2PI));}
  1493. AF4 ANSinF4(AF4 x){return sin(x*AF4_(A_2PI));}
  1494. //------------------------------------------------------------------------------------------------------------------------------
  1495. AF1 ARcpF1(AF1 x){return rcp(x);}
  1496. AF2 ARcpF2(AF2 x){return rcp(x);}
  1497. AF3 ARcpF3(AF3 x){return rcp(x);}
  1498. AF4 ARcpF4(AF4 x){return rcp(x);}
  1499. //------------------------------------------------------------------------------------------------------------------------------
  1500. AF1 ARsqF1(AF1 x){return rsqrt(x);}
  1501. AF2 ARsqF2(AF2 x){return rsqrt(x);}
  1502. AF3 ARsqF3(AF3 x){return rsqrt(x);}
  1503. AF4 ARsqF4(AF4 x){return rsqrt(x);}
  1504. //------------------------------------------------------------------------------------------------------------------------------
  1505. AF1 ASatF1(AF1 x){return saturate(x);}
  1506. AF2 ASatF2(AF2 x){return saturate(x);}
  1507. AF3 ASatF3(AF3 x){return saturate(x);}
  1508. AF4 ASatF4(AF4 x){return saturate(x);}
  1509. //------------------------------------------------------------------------------------------------------------------------------
  1510. AU1 AShrSU1(AU1 a,AU1 b){return AU1(ASU1(a)>>ASU1(b));}
  1511. AU2 AShrSU2(AU2 a,AU2 b){return AU2(ASU2(a)>>ASU2(b));}
  1512. AU3 AShrSU3(AU3 a,AU3 b){return AU3(ASU3(a)>>ASU3(b));}
  1513. AU4 AShrSU4(AU4 a,AU4 b){return AU4(ASU4(a)>>ASU4(b));}
  1514. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1515. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1516. //_____________________________________________________________/\_______________________________________________________________
  1517. //==============================================================================================================================
  1518. // HLSL BYTE
  1519. //==============================================================================================================================
  1520. #ifdef A_BYTE
  1521. #endif
  1522. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1523. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1524. //_____________________________________________________________/\_______________________________________________________________
  1525. //==============================================================================================================================
  1526. // HLSL HALF
  1527. //==============================================================================================================================
  1528. #ifdef A_HALF
  1529. #define AH1 min16float
  1530. #define AH2 min16float2
  1531. #define AH3 min16float3
  1532. #define AH4 min16float4
  1533. //------------------------------------------------------------------------------------------------------------------------------
  1534. #define AW1 min16uint
  1535. #define AW2 min16uint2
  1536. #define AW3 min16uint3
  1537. #define AW4 min16uint4
  1538. //------------------------------------------------------------------------------------------------------------------------------
  1539. #define ASW1 min16int
  1540. #define ASW2 min16int2
  1541. #define ASW3 min16int3
  1542. #define ASW4 min16int4
  1543. //==============================================================================================================================
  1544. // Need to use manual unpack to get optimal execution (don't use packed types in buffers directly).
  1545. // Unpack requires this pattern: https://gpuopen.com/first-steps-implementing-fp16/
  1546. AH2 AH2_AU1_x(AU1 x){AF2 t=f16tof32(AU2(x&0xFFFF,x>>16));return AH2(t);}
  1547. AH4 AH4_AU2_x(AU2 x){return AH4(AH2_AU1_x(x.x),AH2_AU1_x(x.y));}
  1548. AW2 AW2_AU1_x(AU1 x){AU2 t=AU2(x&0xFFFF,x>>16);return AW2(t);}
  1549. AW4 AW4_AU2_x(AU2 x){return AW4(AW2_AU1_x(x.x),AW2_AU1_x(x.y));}
  1550. #define AH2_AU1(x) AH2_AU1_x(AU1(x))
  1551. #define AH4_AU2(x) AH4_AU2_x(AU2(x))
  1552. #define AW2_AU1(x) AW2_AU1_x(AU1(x))
  1553. #define AW4_AU2(x) AW4_AU2_x(AU2(x))
  1554. //------------------------------------------------------------------------------------------------------------------------------
  1555. AU1 AU1_AH2_x(AH2 x){return f32tof16(x.x)+(f32tof16(x.y)<<16);}
  1556. AU2 AU2_AH4_x(AH4 x){return AU2(AU1_AH2_x(x.xy),AU1_AH2_x(x.zw));}
  1557. AU1 AU1_AW2_x(AW2 x){return AU1(x.x)+(AU1(x.y)<<16);}
  1558. AU2 AU2_AW4_x(AW4 x){return AU2(AU1_AW2_x(x.xy),AU1_AW2_x(x.zw));}
  1559. #define AU1_AH2(x) AU1_AH2_x(AH2(x))
  1560. #define AU2_AH4(x) AU2_AH4_x(AH4(x))
  1561. #define AU1_AW2(x) AU1_AW2_x(AW2(x))
  1562. #define AU2_AW4(x) AU2_AW4_x(AW4(x))
  1563. //==============================================================================================================================
  1564. // TODO: These are broken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1565. #define AW1_AH1(x) AW1(asuint(AF1(x)))
  1566. #define AW2_AH2(x) AW2(asuint(AF2(x)))
  1567. #define AW3_AH3(x) AW3(asuint(AF3(x)))
  1568. #define AW4_AH4(x) AW4(asuint(AF4(x)))
  1569. //------------------------------------------------------------------------------------------------------------------------------
  1570. // TODO: These are broken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1571. #define AH1_AW1(x) AH1(asfloat(AU1(x)))
  1572. #define AH2_AW2(x) AH2(asfloat(AU2(x)))
  1573. #define AH3_AW3(x) AH3(asfloat(AU3(x)))
  1574. #define AH4_AW4(x) AH4(asfloat(AU4(x)))
  1575. //==============================================================================================================================
  1576. AH1 AH1_x(AH1 a){return AH1(a);}
  1577. AH2 AH2_x(AH1 a){return AH2(a,a);}
  1578. AH3 AH3_x(AH1 a){return AH3(a,a,a);}
  1579. AH4 AH4_x(AH1 a){return AH4(a,a,a,a);}
  1580. #define AH1_(a) AH1_x(AH1(a))
  1581. #define AH2_(a) AH2_x(AH1(a))
  1582. #define AH3_(a) AH3_x(AH1(a))
  1583. #define AH4_(a) AH4_x(AH1(a))
  1584. //------------------------------------------------------------------------------------------------------------------------------
  1585. AW1 AW1_x(AW1 a){return AW1(a);}
  1586. AW2 AW2_x(AW1 a){return AW2(a,a);}
  1587. AW3 AW3_x(AW1 a){return AW3(a,a,a);}
  1588. AW4 AW4_x(AW1 a){return AW4(a,a,a,a);}
  1589. #define AW1_(a) AW1_x(AW1(a))
  1590. #define AW2_(a) AW2_x(AW1(a))
  1591. #define AW3_(a) AW3_x(AW1(a))
  1592. #define AW4_(a) AW4_x(AW1(a))
  1593. //==============================================================================================================================
  1594. AW1 AAbsSW1(AW1 a){return AW1(abs(ASW1(a)));}
  1595. AW2 AAbsSW2(AW2 a){return AW2(abs(ASW2(a)));}
  1596. AW3 AAbsSW3(AW3 a){return AW3(abs(ASW3(a)));}
  1597. AW4 AAbsSW4(AW4 a){return AW4(abs(ASW4(a)));}
  1598. //------------------------------------------------------------------------------------------------------------------------------
  1599. // V_FRACT_F16 (note DX frac() is different).
  1600. AH1 AFractH1(AH1 x){return x-floor(x);}
  1601. AH2 AFractH2(AH2 x){return x-floor(x);}
  1602. AH3 AFractH3(AH3 x){return x-floor(x);}
  1603. AH4 AFractH4(AH4 x){return x-floor(x);}
  1604. //------------------------------------------------------------------------------------------------------------------------------
  1605. AH1 ALerpH1(AH1 x,AH1 y,AH1 a){return lerp(x,y,a);}
  1606. AH2 ALerpH2(AH2 x,AH2 y,AH2 a){return lerp(x,y,a);}
  1607. AH3 ALerpH3(AH3 x,AH3 y,AH3 a){return lerp(x,y,a);}
  1608. AH4 ALerpH4(AH4 x,AH4 y,AH4 a){return lerp(x,y,a);}
  1609. //------------------------------------------------------------------------------------------------------------------------------
  1610. AH1 AMax3H1(AH1 x,AH1 y,AH1 z){return max(x,max(y,z));}
  1611. AH2 AMax3H2(AH2 x,AH2 y,AH2 z){return max(x,max(y,z));}
  1612. AH3 AMax3H3(AH3 x,AH3 y,AH3 z){return max(x,max(y,z));}
  1613. AH4 AMax3H4(AH4 x,AH4 y,AH4 z){return max(x,max(y,z));}
  1614. //------------------------------------------------------------------------------------------------------------------------------
  1615. AW1 AMaxSW1(AW1 a,AW1 b){return AW1(max(ASU1(a),ASU1(b)));}
  1616. AW2 AMaxSW2(AW2 a,AW2 b){return AW2(max(ASU2(a),ASU2(b)));}
  1617. AW3 AMaxSW3(AW3 a,AW3 b){return AW3(max(ASU3(a),ASU3(b)));}
  1618. AW4 AMaxSW4(AW4 a,AW4 b){return AW4(max(ASU4(a),ASU4(b)));}
  1619. //------------------------------------------------------------------------------------------------------------------------------
  1620. AH1 AMin3H1(AH1 x,AH1 y,AH1 z){return min(x,min(y,z));}
  1621. AH2 AMin3H2(AH2 x,AH2 y,AH2 z){return min(x,min(y,z));}
  1622. AH3 AMin3H3(AH3 x,AH3 y,AH3 z){return min(x,min(y,z));}
  1623. AH4 AMin3H4(AH4 x,AH4 y,AH4 z){return min(x,min(y,z));}
  1624. //------------------------------------------------------------------------------------------------------------------------------
  1625. AW1 AMinSW1(AW1 a,AW1 b){return AW1(min(ASU1(a),ASU1(b)));}
  1626. AW2 AMinSW2(AW2 a,AW2 b){return AW2(min(ASU2(a),ASU2(b)));}
  1627. AW3 AMinSW3(AW3 a,AW3 b){return AW3(min(ASU3(a),ASU3(b)));}
  1628. AW4 AMinSW4(AW4 a,AW4 b){return AW4(min(ASU4(a),ASU4(b)));}
  1629. //------------------------------------------------------------------------------------------------------------------------------
  1630. AH1 ARcpH1(AH1 x){return rcp(x);}
  1631. AH2 ARcpH2(AH2 x){return rcp(x);}
  1632. AH3 ARcpH3(AH3 x){return rcp(x);}
  1633. AH4 ARcpH4(AH4 x){return rcp(x);}
  1634. //------------------------------------------------------------------------------------------------------------------------------
  1635. AH1 ARsqH1(AH1 x){return rsqrt(x);}
  1636. AH2 ARsqH2(AH2 x){return rsqrt(x);}
  1637. AH3 ARsqH3(AH3 x){return rsqrt(x);}
  1638. AH4 ARsqH4(AH4 x){return rsqrt(x);}
  1639. //------------------------------------------------------------------------------------------------------------------------------
  1640. AH1 ASatH1(AH1 x){return saturate(x);}
  1641. AH2 ASatH2(AH2 x){return saturate(x);}
  1642. AH3 ASatH3(AH3 x){return saturate(x);}
  1643. AH4 ASatH4(AH4 x){return saturate(x);}
  1644. //------------------------------------------------------------------------------------------------------------------------------
  1645. AW1 AShrSW1(AW1 a,AW1 b){return AW1(ASW1(a)>>ASW1(b));}
  1646. AW2 AShrSW2(AW2 a,AW2 b){return AW2(ASW2(a)>>ASW2(b));}
  1647. AW3 AShrSW3(AW3 a,AW3 b){return AW3(ASW3(a)>>ASW3(b));}
  1648. AW4 AShrSW4(AW4 a,AW4 b){return AW4(ASW4(a)>>ASW4(b));}
  1649. #endif
  1650. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1651. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1652. //_____________________________________________________________/\_______________________________________________________________
  1653. //==============================================================================================================================
  1654. // HLSL DOUBLE
  1655. //==============================================================================================================================
  1656. #ifdef A_DUBL
  1657. #define AD1 double
  1658. #define AD2 double2
  1659. #define AD3 double3
  1660. #define AD4 double4
  1661. //------------------------------------------------------------------------------------------------------------------------------
  1662. AD1 AD1_x(AD1 a){return AD1(a);}
  1663. AD2 AD2_x(AD1 a){return AD2(a,a);}
  1664. AD3 AD3_x(AD1 a){return AD3(a,a,a);}
  1665. AD4 AD4_x(AD1 a){return AD4(a,a,a,a);}
  1666. #define AD1_(a) AD1_x(AD1(a))
  1667. #define AD2_(a) AD2_x(AD1(a))
  1668. #define AD3_(a) AD3_x(AD1(a))
  1669. #define AD4_(a) AD4_x(AD1(a))
  1670. //==============================================================================================================================
  1671. AD1 AFractD1(AD1 a){return a-floor(a);}
  1672. AD2 AFractD2(AD2 a){return a-floor(a);}
  1673. AD3 AFractD3(AD3 a){return a-floor(a);}
  1674. AD4 AFractD4(AD4 a){return a-floor(a);}
  1675. //------------------------------------------------------------------------------------------------------------------------------
  1676. AD1 ALerpD1(AD1 x,AD1 y,AD1 a){return lerp(x,y,a);}
  1677. AD2 ALerpD2(AD2 x,AD2 y,AD2 a){return lerp(x,y,a);}
  1678. AD3 ALerpD3(AD3 x,AD3 y,AD3 a){return lerp(x,y,a);}
  1679. AD4 ALerpD4(AD4 x,AD4 y,AD4 a){return lerp(x,y,a);}
  1680. //------------------------------------------------------------------------------------------------------------------------------
  1681. AD1 ARcpD1(AD1 x){return rcp(x);}
  1682. AD2 ARcpD2(AD2 x){return rcp(x);}
  1683. AD3 ARcpD3(AD3 x){return rcp(x);}
  1684. AD4 ARcpD4(AD4 x){return rcp(x);}
  1685. //------------------------------------------------------------------------------------------------------------------------------
  1686. AD1 ARsqD1(AD1 x){return rsqrt(x);}
  1687. AD2 ARsqD2(AD2 x){return rsqrt(x);}
  1688. AD3 ARsqD3(AD3 x){return rsqrt(x);}
  1689. AD4 ARsqD4(AD4 x){return rsqrt(x);}
  1690. //------------------------------------------------------------------------------------------------------------------------------
  1691. AD1 ASatD1(AD1 x){return saturate(x);}
  1692. AD2 ASatD2(AD2 x){return saturate(x);}
  1693. AD3 ASatD3(AD3 x){return saturate(x);}
  1694. AD4 ASatD4(AD4 x){return saturate(x);}
  1695. #endif
  1696. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1697. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1698. //_____________________________________________________________/\_______________________________________________________________
  1699. //==============================================================================================================================
  1700. // HLSL LONG
  1701. //==============================================================================================================================
  1702. #ifdef A_LONG
  1703. #endif
  1704. //==============================================================================================================================
  1705. #endif
  1706. //==============================================================================================================================
  1707. // GPU COMMON
  1708. //==============================================================================================================================
  1709. #if defined(A_GPU) || (defined(ASPM_GPU) && !(defined(ASPM_OPENCL)))
  1710. // Negative and positive infinity.
  1711. #define A_INFN_F AF1_AU1(0x7f800000u)
  1712. #define A_INFP_F AF1_AU1(0xff800000u)
  1713. //------------------------------------------------------------------------------------------------------------------------------
  1714. // Copy sign from 's' to positive 'd'.
  1715. AF1 ACpySgnF1(AF1 d,AF1 s){return AF1_AU1(AU1_AF1(d)|(AU1_AF1(s)&AU1_(0x80000000u)));}
  1716. AF2 ACpySgnF2(AF2 d,AF2 s){return AF2_AU2(AU2_AF2(d)|(AU2_AF2(s)&AU2_(0x80000000u)));}
  1717. AF3 ACpySgnF3(AF3 d,AF3 s){return AF3_AU3(AU3_AF3(d)|(AU3_AF3(s)&AU3_(0x80000000u)));}
  1718. AF4 ACpySgnF4(AF4 d,AF4 s){return AF4_AU4(AU4_AF4(d)|(AU4_AF4(s)&AU4_(0x80000000u)));}
  1719. //------------------------------------------------------------------------------------------------------------------------------
  1720. // Single operation to return (useful to create a mask to use in lerp for branch free logic),
  1721. // m=NaN := 0
  1722. // m>=0 := 0
  1723. // m<0 := 1
  1724. // Uses the following useful floating point logic,
  1725. // saturate(+a*(-INF)==-INF) := 0
  1726. // saturate( 0*(-INF)== NaN) := 0
  1727. // saturate(-a*(-INF)==+INF) := 1
  1728. AF1 ASignedF1(AF1 m){return ASatF1(m*AF1_(A_INFN_F));}
  1729. AF2 ASignedF2(AF2 m){return ASatF2(m*AF2_(A_INFN_F));}
  1730. AF3 ASignedF3(AF3 m){return ASatF3(m*AF3_(A_INFN_F));}
  1731. AF4 ASignedF4(AF4 m){return ASatF4(m*AF4_(A_INFN_F));}
  1732. //==============================================================================================================================
  1733. #ifdef A_HALF
  1734. #define A_INFN_H AH1_AW1(0x7c00u)
  1735. #define A_INFP_H AH1_AW1(0xfc00u)
  1736. //------------------------------------------------------------------------------------------------------------------------------
  1737. AH1 ACpySgnH1(AH1 d,AH1 s){return AH1_AW1(AW1_AH1(d)|(AW1_AH1(s)&AW1_(0x8000u)));}
  1738. AH2 ACpySgnH2(AH2 d,AH2 s){return AH2_AW2(AW2_AH2(d)|(AW2_AH2(s)&AW2_(0x8000u)));}
  1739. AH3 ACpySgnH3(AH3 d,AH3 s){return AH3_AW3(AW3_AH3(d)|(AW3_AH3(s)&AW3_(0x8000u)));}
  1740. AH4 ACpySgnH4(AH4 d,AH4 s){return AH4_AW4(AW4_AH4(d)|(AW4_AH4(s)&AW4_(0x8000u)));}
  1741. //------------------------------------------------------------------------------------------------------------------------------
  1742. AH1 ASignedH1(AH1 m){return ASatH1(m*AH1_(A_INFN_H));}
  1743. AH2 ASignedH2(AH2 m){return ASatH2(m*AH2_(A_INFN_H));}
  1744. AH3 ASignedH3(AH3 m){return ASatH3(m*AH3_(A_INFN_H));}
  1745. AH4 ASignedH4(AH4 m){return ASatH4(m*AH4_(A_INFN_H));}
  1746. #endif
  1747. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1748. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1749. //_____________________________________________________________/\_______________________________________________________________
  1750. //==============================================================================================================================
  1751. // HALF APPROXIMATIONS
  1752. //------------------------------------------------------------------------------------------------------------------------------
  1753. // These support only positive inputs.
  1754. // Did not see value yet in specialization for range.
  1755. // Using quick testing, ended up mostly getting the same "best" approximation for various ranges.
  1756. // With hardware that can co-execute transcendentals, the value in approximations could be less than expected.
  1757. // However from a latency perspective, if execution of a transcendental is 4 clk, with no packed support, -> 8 clk total.
  1758. // And co-execution would require a compiler interleaving a lot of independent work for packed usage.
  1759. //------------------------------------------------------------------------------------------------------------------------------
  1760. // The one Newton Raphson iteration form of rsq() was skipped (requires 6 ops total).
  1761. // Same with sqrt(), as this could be x*rsq() (7 ops).
  1762. //------------------------------------------------------------------------------------------------------------------------------
  1763. // IDEAS
  1764. // =====
  1765. // - Polaris hardware has 16-bit support, but non-double rate.
  1766. // Could be possible still get part double rate for some of this logic,
  1767. // by clearing out the lower half's sign when necessary and using 32-bit ops...
  1768. //==============================================================================================================================
  1769. #ifdef A_HALF
  1770. // Minimize squared error across full positive range, 2 ops.
  1771. // The 0x1de2 based approximation maps {0 to 1} input maps to < 1 output.
  1772. AH1 APrxLoSqrtH1(AH1 a){return AH1_AW1((AW1_AH1(a)>>AW1_(1))+AW1_(0x1de2));}
  1773. AH2 APrxLoSqrtH2(AH2 a){return AH2_AW2((AW2_AH2(a)>>AW2_(1))+AW2_(0x1de2));}
  1774. //------------------------------------------------------------------------------------------------------------------------------
  1775. // Lower precision estimation, 1 op.
  1776. // Minimize squared error across {smallest normal to 16384.0}.
  1777. AH1 APrxLoRcpH1(AH1 a){return AH1_AW1(AW1_(0x7784)-AW1_AH1(a));}
  1778. AH2 APrxLoRcpH2(AH2 a){return AH2_AW2(AW2_(0x7784)-AW2_AH2(a));}
  1779. //------------------------------------------------------------------------------------------------------------------------------
  1780. // Medium precision estimation, one Newton Raphson iteration, 3 ops.
  1781. AH1 APrxMedRcpH1(AH1 a){AH1 b=AH1_AW1(AW1_(0x778d)-AW1_AH1(a));return b*(-b*a+AH1_(2.0));}
  1782. AH2 APrxMedRcpH2(AH2 a){AH2 b=AH2_AW2(AW2_(0x778d)-AW2_AH2(a));return b*(-b*a+AH2_(2.0));}
  1783. //------------------------------------------------------------------------------------------------------------------------------
  1784. // Minimize squared error across {smallest normal to 16384.0}, 2 ops.
  1785. AH1 APrxLoRsqH1(AH1 a){return AH1_AW1(AW1_(0x59a3)-(AW1_AH1(a)>>AW1_(1)));}
  1786. AH2 APrxLoRsqH2(AH2 a){return AH2_AW2(AW2_(0x59a3)-(AW2_AH2(a)>>AW2_(1)));}
  1787. #endif
  1788. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1789. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1790. //_____________________________________________________________/\_______________________________________________________________
  1791. //==============================================================================================================================
  1792. // FLOAT APPROXIMATIONS
  1793. //------------------------------------------------------------------------------------------------------------------------------
  1794. // Michal Drobot has an excellent presentation on these: "Low Level Optimizations For GCN",
  1795. // - Idea dates back to SGI, then to Quake 3, etc.
  1796. // - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf
  1797. // - sqrt(x)=rsqrt(x)*x
  1798. // - rcp(x)=rsqrt(x)*rsqrt(x) for positive x
  1799. // - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h
  1800. //------------------------------------------------------------------------------------------------------------------------------
  1801. // These below are from perhaps less complete searching for optimal.
  1802. // Used FP16 normal range for testing with +4096 32-bit step size for sampling error.
  1803. // So these match up well with the half approximations.
  1804. //==============================================================================================================================
  1805. AF1 APrxLoSqrtF1(AF1 a){return AF1_AU1((AU1_AF1(a)>>AU1_(1))+AU1_(0x1fbc4639));}
  1806. AF1 APrxLoRcpF1(AF1 a){return AF1_AU1(AU1_(0x7ef07ebb)-AU1_AF1(a));}
  1807. AF1 APrxMedRcpF1(AF1 a){AF1 b=AF1_AU1(AU1_(0x7ef19fff)-AU1_AF1(a));return b*(-b*a+AF1_(2.0));}
  1808. AF1 APrxLoRsqF1(AF1 a){return AF1_AU1(AU1_(0x5f347d74)-(AU1_AF1(a)>>AU1_(1)));}
  1809. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1810. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1811. //_____________________________________________________________/\_______________________________________________________________
  1812. //==============================================================================================================================
  1813. // PARABOLIC SIN & COS
  1814. //------------------------------------------------------------------------------------------------------------------------------
  1815. // Approximate answers to transcendental questions.
  1816. //------------------------------------------------------------------------------------------------------------------------------
  1817. // TODO
  1818. // ====
  1819. // - Verify packed math ABS is correctly doing an AND.
  1820. //==============================================================================================================================
  1821. // Valid input range is {-1 to 1} representing {0 to 2 pi}.
  1822. // Output range is {-1/4 to -1/4} representing {-1 to 1}.
  1823. AF1 APSinF1(AF1 x){return x*abs(x)-x;} // MAD.
  1824. 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
  1825. //------------------------------------------------------------------------------------------------------------------------------
  1826. #ifdef A_HALF
  1827. // For a packed {sin,cos} pair,
  1828. // - Native takes 16 clocks and 4 issue slots (no packed transcendentals).
  1829. // - Parabolic takes 8 clocks and 8 issue slots (only fract is non-packed).
  1830. AH2 APSinH2(AH2 x){return x*abs(x)-x;} // AND,FMA
  1831. 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
  1832. #endif
  1833. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1834. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1835. //_____________________________________________________________/\_______________________________________________________________
  1836. //==============================================================================================================================
  1837. // COLOR CONVERSIONS
  1838. //------------------------------------------------------------------------------------------------------------------------------
  1839. // These are all linear to/from some other space (where 'linear' has been shortened out of the function name).
  1840. // So 'ToGamma' is 'LinearToGamma', and 'FromGamma' is 'LinearFromGamma'.
  1841. // These are branch free implementations.
  1842. // The AToSrgbF1() function is useful for stores for compute shaders for GPUs without hardware linear->sRGB store conversion.
  1843. //------------------------------------------------------------------------------------------------------------------------------
  1844. // TRANSFER FUNCTIONS
  1845. // ==================
  1846. // 709 ..... Rec709 used for some HDTVs
  1847. // Gamma ... Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native
  1848. // Pq ...... PQ native for HDR10
  1849. // Srgb .... The sRGB output, typical of PC displays, useful for 10-bit output, or storing to 8-bit UNORM without SRGB type
  1850. // Two ..... Gamma 2.0, fastest conversion (useful for intermediate pass approximations)
  1851. //------------------------------------------------------------------------------------------------------------------------------
  1852. // FOR PQ
  1853. // ======
  1854. // Both input and output is {0.0-1.0}, and where output 1.0 represents 10000.0 cd/m^2.
  1855. // All constants are only specified to FP32 precision.
  1856. // External PQ source reference,
  1857. // - https://github.com/ampas/aces-dev/blob/master/transforms/ctl/utilities/ACESlib.Utilities_Color.a1.0.1.ctl
  1858. //------------------------------------------------------------------------------------------------------------------------------
  1859. // PACKED VERSIONS
  1860. // ===============
  1861. // These are the A*H2() functions.
  1862. // There is no PQ functions as FP16 seemed to not have enough precision for the conversion.
  1863. // The remaining functions are "good enough" for 8-bit, and maybe 10-bit if not concerned about a few 1-bit errors.
  1864. // Precision is lowest in the 709 conversion, higher in sRGB, higher still in Two and Gamma (when using 2.2 at least).
  1865. //------------------------------------------------------------------------------------------------------------------------------
  1866. // NOTES
  1867. // =====
  1868. // Could be faster for PQ conversions to be in ALU or a texture lookup depending on usage case.
  1869. //==============================================================================================================================
  1870. AF1 ATo709F1(AF1 c){return max(min(c*AF1_(4.5),AF1_(0.018)),AF1_(1.099)*pow(c,AF1_(0.45))-AF1_(0.099));}
  1871. //------------------------------------------------------------------------------------------------------------------------------
  1872. // Note 'rcpX' is '1/x', where the 'x' is what would be used in AFromGamma().
  1873. AF1 AToGammaF1(AF1 c,AF1 rcpX){return pow(c,rcpX);}
  1874. //------------------------------------------------------------------------------------------------------------------------------
  1875. AF1 AToPqF1(AF1 x){AF1 p=pow(x,AF1_(0.159302));
  1876. return pow((AF1_(0.835938)+AF1_(18.8516)*p)/(AF1_(1.0)+AF1_(18.6875)*p),AF1_(78.8438));}
  1877. //------------------------------------------------------------------------------------------------------------------------------
  1878. AF1 AToSrgbF1(AF1 c){return max(min(c*AF1_(12.92),AF1_(0.0031308)),AF1_(1.055)*pow(c,AF1_(0.41666))-AF1_(0.055));}
  1879. //------------------------------------------------------------------------------------------------------------------------------
  1880. AF1 AToTwoF1(AF1 c){return sqrt(c);}
  1881. //==============================================================================================================================
  1882. AF1 AFrom709F1(AF1 c){return max(min(c*AF1_(1.0/4.5),AF1_(0.081)),
  1883. pow((c+AF1_(0.099))*(AF1_(1.0)/(AF1_(1.099))),AF1_(1.0/0.45)));}
  1884. //------------------------------------------------------------------------------------------------------------------------------
  1885. AF1 AFromGammaF1(AF1 c,AF1 x){return pow(c,x);}
  1886. //------------------------------------------------------------------------------------------------------------------------------
  1887. AF1 AFromPqF1(AF1 x){AF1 p=pow(x,AF1_(0.0126833));
  1888. return pow(ASatF1(p-AF1_(0.835938))/(AF1_(18.8516)-AF1_(18.6875)*p),AF1_(6.27739));}
  1889. //------------------------------------------------------------------------------------------------------------------------------
  1890. AF1 AFromSrgbF1(AF1 c){return max(min(c*AF1_(1.0/12.92),AF1_(0.04045)),
  1891. pow((c+AF1_(0.055))*(AF1_(1.0)/AF1_(1.055)),AF1_(2.4)));}
  1892. //------------------------------------------------------------------------------------------------------------------------------
  1893. AF1 AFromTwoF1(AF1 c){return c*c;}
  1894. //==============================================================================================================================
  1895. #ifdef A_HALF
  1896. AH2 ATo709H2(AH2 c){return max(min(c*AH2_(4.5),AH2_(0.018)),AH2_(1.099)*pow(c,AH2_(0.45))-AH2_(0.099));}
  1897. //------------------------------------------------------------------------------------------------------------------------------
  1898. AH2 AToGammaH2(AH2 c,AH1 rcpX){return pow(c,AH2_(rcpX));}
  1899. //------------------------------------------------------------------------------------------------------------------------------
  1900. AH2 AToSrgbH2(AH2 c){return max(min(c*AH2_(12.92),AH2_(0.0031308)),AH2_(1.055)*pow(c,AH2_(0.41666))-AH2_(0.055));}
  1901. //------------------------------------------------------------------------------------------------------------------------------
  1902. AH2 AToTwoH2(AH2 c){return sqrt(c);}
  1903. #endif
  1904. //==============================================================================================================================
  1905. #ifdef A_HALF
  1906. AH2 AFrom709H2(AH2 c){return max(min(c*AH2_(1.0/4.5),AH2_(0.081)),
  1907. pow((c+AH2_(0.099))*(AH2_(1.0)/(AH2_(1.099))),AH2_(1.0/0.45)));}
  1908. //------------------------------------------------------------------------------------------------------------------------------
  1909. AH2 AFromGammaH2(AH2 c,AH1 x){return pow(c,AH2_(x));}
  1910. //------------------------------------------------------------------------------------------------------------------------------
  1911. AH2 AFromSrgbH2(AH2 c){return max(min(c*AH2_(1.0/12.92),AH2_(0.04045)),
  1912. pow((c+AH2_(0.055))*(AH2_(1.0)/AH2_(1.055)),AH2_(2.4)));}
  1913. //------------------------------------------------------------------------------------------------------------------------------
  1914. AH2 AFromTwoH2(AH2 c){return c*c;}
  1915. #endif
  1916. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1917. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1918. //_____________________________________________________________/\_______________________________________________________________
  1919. //==============================================================================================================================
  1920. // CS REMAP
  1921. //==============================================================================================================================
  1922. // Simple remap 64x1 to 8x8 with rotated 2x2 pixel quads in quad linear.
  1923. // 543210
  1924. // ======
  1925. // ..xxx.
  1926. // yy...y
  1927. AU2 ARmp8x8(AU1 a){return AU2(ABfe(a,1u,3u),ABfiM(ABfe(a,3u,3u),a,1u));}
  1928. //==============================================================================================================================
  1929. // More complex remap 64x1 to 8x8 which is necessary for 2D wave reductions.
  1930. // 543210
  1931. // ======
  1932. // .xx..x
  1933. // y..yy.
  1934. // Details,
  1935. // LANE TO 8x8 MAPPING
  1936. // ===================
  1937. // 00 01 08 09 10 11 18 19
  1938. // 02 03 0a 0b 12 13 1a 1b
  1939. // 04 05 0c 0d 14 15 1c 1d
  1940. // 06 07 0e 0f 16 17 1e 1f
  1941. // 20 21 28 29 30 31 38 39
  1942. // 22 23 2a 2b 32 33 3a 3b
  1943. // 24 25 2c 2d 34 35 3c 3d
  1944. // 26 27 2e 2f 36 37 3e 3f
  1945. AU2 ARmpRed8x8(AU1 a){return AU2(ABfiM(ABfe(a,2u,3u),a,1u),ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u));}
  1946. #endif
  1947. //==============================================================================================================================
  1948. // GPU/CPU PORTABILITY
  1949. //------------------------------------------------------------------------------------------------------------------------------
  1950. // This is the GPU implementation.
  1951. // See the CPU implementation for docs.
  1952. //==============================================================================================================================
  1953. #if defined(A_GPU) || (defined(ASPM_GPU) && !(defined(ASPM_OPENCL)))
  1954. #define A_TRUE true
  1955. #define A_FALSE false
  1956. #define A_STATIC
  1957. //_____________________________________________________________/\_______________________________________________________________
  1958. //==============================================================================================================================
  1959. // VECTOR ARGUMENT/RETURN/INITIALIZATION PORTABILITY
  1960. //==============================================================================================================================
  1961. #define retAD2 AD2
  1962. #define retAD3 AD3
  1963. #define retAD4 AD4
  1964. #define retAF2 AF2
  1965. #define retAF3 AF3
  1966. #define retAF4 AF4
  1967. #define retAL2 AL2
  1968. #define retAL3 AL3
  1969. #define retAL4 AL4
  1970. #define retAU2 AU2
  1971. #define retAU3 AU3
  1972. #define retAU4 AU4
  1973. //------------------------------------------------------------------------------------------------------------------------------
  1974. #define inAD2 in AD2
  1975. #define inAD3 in AD3
  1976. #define inAD4 in AD4
  1977. #define inAF2 in AF2
  1978. #define inAF3 in AF3
  1979. #define inAF4 in AF4
  1980. #define inAL2 in AL2
  1981. #define inAL3 in AL3
  1982. #define inAL4 in AL4
  1983. #define inAU2 in AU2
  1984. #define inAU3 in AU3
  1985. #define inAU4 in AU4
  1986. //------------------------------------------------------------------------------------------------------------------------------
  1987. #define inoutAD2 inout AD2
  1988. #define inoutAD3 inout AD3
  1989. #define inoutAD4 inout AD4
  1990. #define inoutAF2 inout AF2
  1991. #define inoutAF3 inout AF3
  1992. #define inoutAF4 inout AF4
  1993. #define inoutAL2 inout AL2
  1994. #define inoutAL3 inout AL3
  1995. #define inoutAL4 inout AL4
  1996. #define inoutAU2 inout AU2
  1997. #define inoutAU3 inout AU3
  1998. #define inoutAU4 inout AU4
  1999. //------------------------------------------------------------------------------------------------------------------------------
  2000. #define outAD2 out AD2
  2001. #define outAD3 out AD3
  2002. #define outAD4 out AD4
  2003. #define outAF2 out AF2
  2004. #define outAF3 out AF3
  2005. #define outAF4 out AF4
  2006. #define outAL2 out AL2
  2007. #define outAL3 out AL3
  2008. #define outAL4 out AL4
  2009. #define outAU2 out AU2
  2010. #define outAU3 out AU3
  2011. #define outAU4 out AU4
  2012. //------------------------------------------------------------------------------------------------------------------------------
  2013. #define varAD2(x) AD2 x
  2014. #define varAD3(x) AD3 x
  2015. #define varAD4(x) AD4 x
  2016. #define varAF2(x) AF2 x
  2017. #define varAF3(x) AF3 x
  2018. #define varAF4(x) AF4 x
  2019. #define varAL2(x) AL2 x
  2020. #define varAL3(x) AL3 x
  2021. #define varAL4(x) AL4 x
  2022. #define varAU2(x) AU2 x
  2023. #define varAU3(x) AU3 x
  2024. #define varAU4(x) AU4 x
  2025. //------------------------------------------------------------------------------------------------------------------------------
  2026. #define initAD2(x,y) AD2(x,y)
  2027. #define initAD3(x,y,z) AD3(x,y,z)
  2028. #define initAD4(x,y,z,w) AD4(x,y,z,w)
  2029. #define initAF2(x,y) AF2(x,y)
  2030. #define initAF3(x,y,z) AF3(x,y,z)
  2031. #define initAF4(x,y,z,w) AF4(x,y,z,w)
  2032. #define initAL2(x,y) AL2(x,y)
  2033. #define initAL3(x,y,z) AL3(x,y,z)
  2034. #define initAL4(x,y,z,w) AL4(x,y,z,w)
  2035. #define initAU2(x,y) AU2(x,y)
  2036. #define initAU3(x,y,z) AU3(x,y,z)
  2037. #define initAU4(x,y,z,w) AU4(x,y,z,w)
  2038. //_____________________________________________________________/\_______________________________________________________________
  2039. //==============================================================================================================================
  2040. // SCALAR RETURN OPS
  2041. //==============================================================================================================================
  2042. #define AAbsD1(a) abs(AD1(a))
  2043. #define AAbsF1(a) abs(AF1(a))
  2044. //------------------------------------------------------------------------------------------------------------------------------
  2045. #define ACosD1(a) cos(AD1(a))
  2046. #define ACosF1(a) cos(AF1(a))
  2047. //------------------------------------------------------------------------------------------------------------------------------
  2048. #define ADotD2(a,b) dot(AD2(a),AD2(b))
  2049. #define ADotD3(a,b) dot(AD3(a),AD3(b))
  2050. #define ADotD4(a,b) dot(AD4(a),AD4(b))
  2051. #define ADotF2(a,b) dot(AF2(a),AF2(b))
  2052. #define ADotF3(a,b) dot(AF3(a),AF3(b))
  2053. #define ADotF4(a,b) dot(AF4(a),AF4(b))
  2054. //------------------------------------------------------------------------------------------------------------------------------
  2055. #define AExp2D1(a) exp2(AD1(a))
  2056. #define AExp2F1(a) exp2(AF1(a))
  2057. //------------------------------------------------------------------------------------------------------------------------------
  2058. #define AFloorD1(a) floor(AD1(a))
  2059. #define AFloorF1(a) floor(AF1(a))
  2060. //------------------------------------------------------------------------------------------------------------------------------
  2061. #define ALog2D1(a) log2(AD1(a))
  2062. #define ALog2F1(a) log2(AF1(a))
  2063. //------------------------------------------------------------------------------------------------------------------------------
  2064. #define AMaxD1(a,b) min(a,b)
  2065. #define AMaxF1(a,b) min(a,b)
  2066. #define AMaxL1(a,b) min(a,b)
  2067. #define AMaxU1(a,b) min(a,b)
  2068. //------------------------------------------------------------------------------------------------------------------------------
  2069. #define AMinD1(a,b) min(a,b)
  2070. #define AMinF1(a,b) min(a,b)
  2071. #define AMinL1(a,b) min(a,b)
  2072. #define AMinU1(a,b) min(a,b)
  2073. //------------------------------------------------------------------------------------------------------------------------------
  2074. #define ASinD1(a) sin(AD1(a))
  2075. #define ASinF1(a) sin(AF1(a))
  2076. //------------------------------------------------------------------------------------------------------------------------------
  2077. #define ASqrtD1(a) sqrt(AD1(a))
  2078. #define ASqrtF1(a) sqrt(AF1(a))
  2079. //_____________________________________________________________/\_______________________________________________________________
  2080. //==============================================================================================================================
  2081. // SCALAR RETURN OPS - DEPENDENT
  2082. //==============================================================================================================================
  2083. #define APowD1(a,b) pow(AD1(a),AF1(b))
  2084. #define APowF1(a,b) pow(AF1(a),AF1(b))
  2085. //_____________________________________________________________/\_______________________________________________________________
  2086. //==============================================================================================================================
  2087. // VECTOR OPS
  2088. //------------------------------------------------------------------------------------------------------------------------------
  2089. // These are added as needed for production or prototyping, so not necessarily a complete set.
  2090. // They follow a convention of taking in a destination and also returning the destination value to increase utility.
  2091. //==============================================================================================================================
  2092. #ifdef A_DUBL
  2093. AD2 opAAbsD2(outAD2 d,inAD2 a){d=abs(a);return d;}
  2094. AD3 opAAbsD3(outAD3 d,inAD3 a){d=abs(a);return d;}
  2095. AD4 opAAbsD4(outAD4 d,inAD4 a){d=abs(a);return d;}
  2096. //------------------------------------------------------------------------------------------------------------------------------
  2097. AD2 opAAddD2(outAD2 d,inAD2 a,inAD2 b){d=a+b;return d;}
  2098. AD3 opAAddD3(outAD3 d,inAD3 a,inAD3 b){d=a+b;return d;}
  2099. AD4 opAAddD4(outAD4 d,inAD4 a,inAD4 b){d=a+b;return d;}
  2100. //------------------------------------------------------------------------------------------------------------------------------
  2101. AD2 opACpyD2(outAD2 d,inAD2 a){d=a;return d;}
  2102. AD3 opACpyD3(outAD3 d,inAD3 a){d=a;return d;}
  2103. AD4 opACpyD4(outAD4 d,inAD4 a){d=a;return d;}
  2104. //------------------------------------------------------------------------------------------------------------------------------
  2105. AD2 opALerpD2(outAD2 d,inAD2 a,inAD2 b,inAD2 c){d=ALerpD2(a,b,c);return d;}
  2106. AD3 opALerpD3(outAD3 d,inAD3 a,inAD3 b,inAD3 c){d=ALerpD3(a,b,c);return d;}
  2107. AD4 opALerpD4(outAD4 d,inAD4 a,inAD4 b,inAD4 c){d=ALerpD4(a,b,c);return d;}
  2108. //------------------------------------------------------------------------------------------------------------------------------
  2109. AD2 opALerpOneD2(outAD2 d,inAD2 a,inAD2 b,AD1 c){d=ALerpD2(a,b,AD2_(c));return d;}
  2110. AD3 opALerpOneD3(outAD3 d,inAD3 a,inAD3 b,AD1 c){d=ALerpD3(a,b,AD3_(c));return d;}
  2111. AD4 opALerpOneD4(outAD4 d,inAD4 a,inAD4 b,AD1 c){d=ALerpD4(a,b,AD4_(c));return d;}
  2112. //------------------------------------------------------------------------------------------------------------------------------
  2113. AD2 opAMaxD2(outAD2 d,inAD2 a,inAD2 b){d=max(a,b);return d;}
  2114. AD3 opAMaxD3(outAD3 d,inAD3 a,inAD3 b){d=max(a,b);return d;}
  2115. AD4 opAMaxD4(outAD4 d,inAD4 a,inAD4 b){d=max(a,b);return d;}
  2116. //------------------------------------------------------------------------------------------------------------------------------
  2117. AD2 opAMinD2(outAD2 d,inAD2 a,inAD2 b){d=min(a,b);return d;}
  2118. AD3 opAMinD3(outAD3 d,inAD3 a,inAD3 b){d=min(a,b);return d;}
  2119. AD4 opAMinD4(outAD4 d,inAD4 a,inAD4 b){d=min(a,b);return d;}
  2120. //------------------------------------------------------------------------------------------------------------------------------
  2121. AD2 opAMulD2(outAD2 d,inAD2 a,inAD2 b){d=a*b;return d;}
  2122. AD3 opAMulD3(outAD3 d,inAD3 a,inAD3 b){d=a*b;return d;}
  2123. AD4 opAMulD4(outAD4 d,inAD4 a,inAD4 b){d=a*b;return d;}
  2124. //------------------------------------------------------------------------------------------------------------------------------
  2125. AD2 opAMulOneD2(outAD2 d,inAD2 a,AD1 b){d=a*AD2_(b);return d;}
  2126. AD3 opAMulOneD3(outAD3 d,inAD3 a,AD1 b){d=a*AD3_(b);return d;}
  2127. AD4 opAMulOneD4(outAD4 d,inAD4 a,AD1 b){d=a*AD4_(b);return d;}
  2128. //------------------------------------------------------------------------------------------------------------------------------
  2129. AD2 opANegD2(outAD2 d,inAD2 a){d=-a;return d;}
  2130. AD3 opANegD3(outAD3 d,inAD3 a){d=-a;return d;}
  2131. AD4 opANegD4(outAD4 d,inAD4 a){d=-a;return d;}
  2132. //------------------------------------------------------------------------------------------------------------------------------
  2133. AD2 opARcpD2(outAD2 d,inAD2 a){d=ARcpD2(a);return d;}
  2134. AD3 opARcpD3(outAD3 d,inAD3 a){d=ARcpD3(a);return d;}
  2135. AD4 opARcpD4(outAD4 d,inAD4 a){d=ARcpD4(a);return d;}
  2136. #endif
  2137. //==============================================================================================================================
  2138. AF2 opAAbsF2(outAF2 d,inAF2 a){d=abs(a);return d;}
  2139. AF3 opAAbsF3(outAF3 d,inAF3 a){d=abs(a);return d;}
  2140. AF4 opAAbsF4(outAF4 d,inAF4 a){d=abs(a);return d;}
  2141. //------------------------------------------------------------------------------------------------------------------------------
  2142. AF2 opAAddF2(outAF2 d,inAF2 a,inAF2 b){d=a+b;return d;}
  2143. AF3 opAAddF3(outAF3 d,inAF3 a,inAF3 b){d=a+b;return d;}
  2144. AF4 opAAddF4(outAF4 d,inAF4 a,inAF4 b){d=a+b;return d;}
  2145. //------------------------------------------------------------------------------------------------------------------------------
  2146. AF2 opACpyF2(outAF2 d,inAF2 a){d=a;return d;}
  2147. AF3 opACpyF3(outAF3 d,inAF3 a){d=a;return d;}
  2148. AF4 opACpyF4(outAF4 d,inAF4 a){d=a;return d;}
  2149. //------------------------------------------------------------------------------------------------------------------------------
  2150. AF2 opALerpF2(outAF2 d,inAF2 a,inAF2 b,inAF2 c){d=ALerpF2(a,b,c);return d;}
  2151. AF3 opALerpF3(outAF3 d,inAF3 a,inAF3 b,inAF3 c){d=ALerpF3(a,b,c);return d;}
  2152. AF4 opALerpF4(outAF4 d,inAF4 a,inAF4 b,inAF4 c){d=ALerpF4(a,b,c);return d;}
  2153. //------------------------------------------------------------------------------------------------------------------------------
  2154. AF2 opALerpOneF2(outAF2 d,inAF2 a,inAF2 b,AF1 c){d=ALerpF2(a,b,AF2_(c));return d;}
  2155. AF3 opALerpOneF3(outAF3 d,inAF3 a,inAF3 b,AF1 c){d=ALerpF3(a,b,AF3_(c));return d;}
  2156. AF4 opALerpOneF4(outAF4 d,inAF4 a,inAF4 b,AF1 c){d=ALerpF4(a,b,AF4_(c));return d;}
  2157. //------------------------------------------------------------------------------------------------------------------------------
  2158. AF2 opAMaxF2(outAF2 d,inAF2 a,inAF2 b){d=max(a,b);return d;}
  2159. AF3 opAMaxF3(outAF3 d,inAF3 a,inAF3 b){d=max(a,b);return d;}
  2160. AF4 opAMaxF4(outAF4 d,inAF4 a,inAF4 b){d=max(a,b);return d;}
  2161. //------------------------------------------------------------------------------------------------------------------------------
  2162. AF2 opAMinF2(outAF2 d,inAF2 a,inAF2 b){d=min(a,b);return d;}
  2163. AF3 opAMinF3(outAF3 d,inAF3 a,inAF3 b){d=min(a,b);return d;}
  2164. AF4 opAMinF4(outAF4 d,inAF4 a,inAF4 b){d=min(a,b);return d;}
  2165. //------------------------------------------------------------------------------------------------------------------------------
  2166. AF2 opAMulF2(outAF2 d,inAF2 a,inAF2 b){d=a*b;return d;}
  2167. AF3 opAMulF3(outAF3 d,inAF3 a,inAF3 b){d=a*b;return d;}
  2168. AF4 opAMulF4(outAF4 d,inAF4 a,inAF4 b){d=a*b;return d;}
  2169. //------------------------------------------------------------------------------------------------------------------------------
  2170. AF2 opAMulOneF2(outAF2 d,inAF2 a,AF1 b){d=a*AF2_(b);return d;}
  2171. AF3 opAMulOneF3(outAF3 d,inAF3 a,AF1 b){d=a*AF3_(b);return d;}
  2172. AF4 opAMulOneF4(outAF4 d,inAF4 a,AF1 b){d=a*AF4_(b);return d;}
  2173. //------------------------------------------------------------------------------------------------------------------------------
  2174. AF2 opANegF2(outAF2 d,inAF2 a){d=-a;return d;}
  2175. AF3 opANegF3(outAF3 d,inAF3 a){d=-a;return d;}
  2176. AF4 opANegF4(outAF4 d,inAF4 a){d=-a;return d;}
  2177. //------------------------------------------------------------------------------------------------------------------------------
  2178. AF2 opARcpF2(outAF2 d,inAF2 a){d=ARcpF2(a);return d;}
  2179. AF3 opARcpF3(outAF3 d,inAF3 a){d=ARcpF3(a);return d;}
  2180. AF4 opARcpF4(outAF4 d,inAF4 a){d=ARcpF4(a);return d;}
  2181. #endif
  2182. #endif // USE_CMP_FIDELITY_FX_H
  2183. #endif // Common_Def.h