Ver código fonte

merge from development

Signed-off-by: greerdv <[email protected]>
greerdv 2 anos atrás
pai
commit
ce8f5ea3d0
100 arquivos alterados com 4602 adições e 292 exclusões
  1. 0 4
      Assets/Editor/Icons/Components/NetBinding.svg
  2. 0 22
      Assets/Editor/Icons/Components/Viewport/NetBinding.svg
  3. 13 0
      AutomatedTesting/Editor/Icons/Components/NetworkTestLevelEntity.svg
  4. 13 0
      AutomatedTesting/Editor/Icons/Components/NetworkTestPlayer.svg
  5. 13 0
      AutomatedTesting/Editor/Icons/Components/SimpleScriptPlayer.svg
  6. 25 0
      AutomatedTesting/Editor/Icons/Components/Viewport/NetworkTestLevelEntity.svg
  7. 25 0
      AutomatedTesting/Editor/Icons/Components/Viewport/NetworkTestPlayer.svg
  8. 25 0
      AutomatedTesting/Editor/Icons/Components/Viewport/SimpleScriptPlayer.svg
  9. 7 0
      AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_LevelEntityComponentCRUD.py
  10. 6 1
      AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Menus_EditMenuOptions.py
  11. 6 6
      AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Menus_ViewMenuOptions.py
  12. 20 0
      Code/Editor/Core/EditorActionsHandler.cpp
  13. 5 0
      Code/Editor/Core/EditorActionsHandler.h
  14. 9 0
      Code/Editor/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp
  15. 17 5
      Code/Framework/AzCore/AzCore/Instance/InstancePool.h
  16. 33 1
      Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSceneQueries.h
  17. 3 3
      Code/Framework/AzFramework/AzFramework/Physics/Configuration/SystemConfiguration.h
  18. 3 3
      Code/Framework/AzQtComponents/AzQtComponents/Components/Widgets/ElidingLabel.cpp
  19. 21 0
      Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeActionHandler.cpp
  20. 1 0
      Code/Framework/AzToolsFramework/AzToolsFramework/Editor/ActionManagerIdentifiers/EditorActionUpdaterIdentifiers.h
  21. 1 1
      Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp
  22. 82 28
      Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp
  23. 5 0
      Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.h
  24. 1 5
      Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.cpp
  25. 0 4
      Code/Legacy/CryCommon/crycommon_files.cmake
  26. 2 0
      Code/Legacy/CrySystem/CMakeLists.txt
  27. 11 2
      Gems/AWSCore/Code/Source/AWSCoreSystemComponent.cpp
  28. 2 0
      Gems/AWSCore/Code/Source/AWSCoreSystemComponent.h
  29. 68 0
      Gems/Atom/Feature/Common/Assets/Passes/DownsampleSinglePassLuminance.pass
  30. 6 25
      Gems/Atom/Feature/Common/Assets/Passes/LightAdaptationParent.pass
  31. 4 0
      Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset
  32. 161 0
      Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DownsampleSinglePassLuminance.azsl
  33. 28 0
      Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DownsampleSinglePassLuminance.shader
  34. 3 0
      Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake
  35. 3 0
      Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceFeatures.h
  36. 1 1
      Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp
  37. 5 0
      Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp
  38. 3 0
      Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp
  39. 1 0
      Gems/Atom/RHI/Vulkan/Code/Source/RHI/PhysicalDevice.cpp
  40. 1 0
      Gems/Atom/RHI/Vulkan/Code/Source/RHI/PhysicalDevice.h
  41. 19 0
      Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/LICENSE
  42. 6 0
      Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/PackageInfo.json
  43. 1907 0
      Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/ffx_a.h
  44. 1297 0
      Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/ffx_spd.h
  45. 2 0
      Gems/Atom/RPI/Assets/atom_rpi_asset_files.cmake
  46. 2 2
      Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ComputePass.h
  47. 92 0
      Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.h
  48. 3 0
      Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h
  49. 4 4
      Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ComputePass.cpp
  50. 2 0
      Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp
  51. 269 0
      Gems/Atom/RPI/Code/Source/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.cpp
  52. 2 0
      Gems/Atom/RPI/Code/atom_rpi_public_files.cmake
  53. 2 2
      Gems/AtomTressFX/Code/Components/EditorHairComponent.cpp
  54. 14 1
      Gems/AudioEngineWwise/CMakeLists.txt
  55. 95 37
      Gems/AudioEngineWwise/Code/CMakeLists.txt
  56. 1 2
      Gems/AudioEngineWwise/Code/Source/AudioEngineWwiseGemSystemComponent.cpp
  57. 9 6
      Gems/AudioEngineWwise/Code/Source/AudioEngineWwiseModule.cpp
  58. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderComponent.cpp
  59. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderComponent.h
  60. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderWorker.cpp
  61. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderComponent.cpp
  62. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderComponent.h
  63. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderWorker.cpp
  64. 1 1
      Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderWorker.h
  65. 0 1
      Gems/AudioEngineWwise/Code/Source/Engine/AudioSystemImpl_wwise.cpp
  66. 1 1
      Gems/AudioEngineWwise/Code/Tests/AudioControlBuilderTest.cpp
  67. 1 1
      Gems/AudioEngineWwise/Code/Tests/AudioEngineWwiseBuilderTest.cpp
  68. 18 0
      Gems/AudioEngineWwise/Code/audioenginewwise_builder_files.cmake
  69. 11 0
      Gems/AudioEngineWwise/Code/audioenginewwise_builder_shared_files.cmake
  70. 0 8
      Gems/AudioEngineWwise/Code/audioenginewwise_editor_files.cmake
  71. 1 1
      Gems/AudioEngineWwise/Code/audioenginewwise_editor_shared_files.cmake
  72. 14 22
      Gems/AudioEngineWwise/Code/audioenginewwise_files.cmake
  73. 7 0
      Gems/AudioEngineWwise/Code/audioenginewwise_shared_files.cmake
  74. 14 1
      Gems/AudioSystem/CMakeLists.txt
  75. 93 56
      Gems/AudioSystem/Code/CMakeLists.txt
  76. 0 0
      Gems/AudioSystem/Code/Include/Engine/IAudioInterfacesCommonData.h
  77. 0 0
      Gems/AudioSystem/Code/Include/Engine/IAudioSystem.h
  78. 0 0
      Gems/AudioSystem/Code/Include/Engine/MicrophoneBus.h
  79. 0 0
      Gems/AudioSystem/Code/Include/Engine/NullAudioSystem.h
  80. 1 1
      Gems/AudioSystem/Code/Source/AudioSystemGemSystemComponent.cpp
  81. 1 1
      Gems/AudioSystem/Code/Source/AudioSystemModule.cpp
  82. 0 1
      Gems/AudioSystem/Code/Source/Engine/AudioProxy.cpp
  83. 18 0
      Gems/AudioSystem/Code/audiosystem_api_files.cmake
  84. 12 0
      Gems/AudioSystem/Code/audiosystem_editor_api_files.cmake
  85. 0 6
      Gems/AudioSystem/Code/audiosystem_editor_files.cmake
  86. 2 0
      Gems/AudioSystem/Code/audiosystem_editor_shared_files.cmake
  87. 0 1
      Gems/AudioSystem/Code/audiosystem_editor_tests_files.cmake
  88. 9 15
      Gems/AudioSystem/Code/audiosystem_files.cmake
  89. 12 2
      Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp
  90. 1 0
      Gems/HttpRequestor/Code/Source/HttpRequestManager.h
  91. 3 0
      Gems/LmbrCentral/Code/CMakeLists.txt
  92. 2 0
      Gems/Maestro/Code/CMakeLists.txt
  93. 1 2
      Gems/Microphone/Code/CMakeLists.txt
  94. 1 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/LocalPredictionPlayerInput.svg
  95. 2 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkBinding.svg
  96. 3 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkCharacter.svg
  97. 1 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHierarchyChild.svg
  98. 1 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHierarchyRoot.svg
  99. 3 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHitVolumes.svg
  100. 3 0
      Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkRigidBody.svg

Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 4
Assets/Editor/Icons/Components/NetBinding.svg


Diferenças do arquivo suprimidas por serem muito extensas
+ 0 - 22
Assets/Editor/Icons/Components/Viewport/NetBinding.svg


+ 13 - 0
AutomatedTesting/Editor/Icons/Components/NetworkTestLevelEntity.svg

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder </title>
+    <defs>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="path-1"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder-" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <mask id="mask-2" fill="white">
+            <use xlink:href="#path-1"></use>
+        </mask>
+        <use id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero" xlink:href="#path-1"></use>
+    </g>
+</svg>

+ 13 - 0
AutomatedTesting/Editor/Icons/Components/NetworkTestPlayer.svg

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder </title>
+    <defs>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="path-1"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder-" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <mask id="mask-2" fill="white">
+            <use xlink:href="#path-1"></use>
+        </mask>
+        <use id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero" xlink:href="#path-1"></use>
+    </g>
+</svg>

+ 13 - 0
AutomatedTesting/Editor/Icons/Components/SimpleScriptPlayer.svg

@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder </title>
+    <defs>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="path-1"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder-" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <mask id="mask-2" fill="white">
+            <use xlink:href="#path-1"></use>
+        </mask>
+        <use id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero" xlink:href="#path-1"></use>
+    </g>
+</svg>

+ 25 - 0
AutomatedTesting/Editor/Icons/Components/Viewport/NetworkTestLevelEntity.svg

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder - box</title>
+    <defs>
+        <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
+            <stop stop-color="#ADADAD" stop-opacity="0" offset="0%"></stop>
+            <stop stop-color="#9D9D9D" offset="100%"></stop>
+        </linearGradient>
+        <path d="M20.924815,0 C23.1021676,0 23.9566542,1.77846722 23.9566542,3.01865122 C23.9566542,4.25883521 23.9566542,18.7815894 23.9566542,20.6420628 C23.9566542,22.3929727 22.7281352,23.9566542 20.924815,23.9566542 C19.1214948,23.9566542 4.64929841,23.9566542 2.80929064,23.9566542 C1.38661643,23.9566542 0,22.5147712 0,21.1586662 C0,19.8025612 0,4.03532882 0,2.67255351 C0,1.3097782 1.36539793,0 2.60955829,0 C3.85371865,0 18.9601214,0 20.924815,0 Z" id="path-2"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder---box" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="icon/general/color/-box-template" transform="translate(0.000000, 0.086473)">
+            <mask id="mask-3" fill="white">
+                <use xlink:href="#path-2"></use>
+            </mask>
+            <use id="Path-3" fill="url(#linearGradient-1)" xlink:href="#path-2"></use>
+            <g id="Group" mask="url(#mask-3)" fill="#CCCCCC">
+                <g id="icon/color/AI" style="mix-blend-mode: multiply;">
+                    <rect id="Rectangle-2" x="0" y="0" width="24" height="24"></rect>
+                </g>
+            </g>
+        </g>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero"></path>
+    </g>
+</svg>

+ 25 - 0
AutomatedTesting/Editor/Icons/Components/Viewport/NetworkTestPlayer.svg

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder - box</title>
+    <defs>
+        <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
+            <stop stop-color="#ADADAD" stop-opacity="0" offset="0%"></stop>
+            <stop stop-color="#9D9D9D" offset="100%"></stop>
+        </linearGradient>
+        <path d="M20.924815,0 C23.1021676,0 23.9566542,1.77846722 23.9566542,3.01865122 C23.9566542,4.25883521 23.9566542,18.7815894 23.9566542,20.6420628 C23.9566542,22.3929727 22.7281352,23.9566542 20.924815,23.9566542 C19.1214948,23.9566542 4.64929841,23.9566542 2.80929064,23.9566542 C1.38661643,23.9566542 0,22.5147712 0,21.1586662 C0,19.8025612 0,4.03532882 0,2.67255351 C0,1.3097782 1.36539793,0 2.60955829,0 C3.85371865,0 18.9601214,0 20.924815,0 Z" id="path-2"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder---box" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="icon/general/color/-box-template" transform="translate(0.000000, 0.086473)">
+            <mask id="mask-3" fill="white">
+                <use xlink:href="#path-2"></use>
+            </mask>
+            <use id="Path-3" fill="url(#linearGradient-1)" xlink:href="#path-2"></use>
+            <g id="Group" mask="url(#mask-3)" fill="#CCCCCC">
+                <g id="icon/color/AI" style="mix-blend-mode: multiply;">
+                    <rect id="Rectangle-2" x="0" y="0" width="24" height="24"></rect>
+                </g>
+            </g>
+        </g>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero"></path>
+    </g>
+</svg>

+ 25 - 0
AutomatedTesting/Editor/Icons/Components/Viewport/SimpleScriptPlayer.svg

@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <title>icon / Other / Component_Placeholder - box</title>
+    <defs>
+        <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1">
+            <stop stop-color="#ADADAD" stop-opacity="0" offset="0%"></stop>
+            <stop stop-color="#9D9D9D" offset="100%"></stop>
+        </linearGradient>
+        <path d="M20.924815,0 C23.1021676,0 23.9566542,1.77846722 23.9566542,3.01865122 C23.9566542,4.25883521 23.9566542,18.7815894 23.9566542,20.6420628 C23.9566542,22.3929727 22.7281352,23.9566542 20.924815,23.9566542 C19.1214948,23.9566542 4.64929841,23.9566542 2.80929064,23.9566542 C1.38661643,23.9566542 0,22.5147712 0,21.1586662 C0,19.8025612 0,4.03532882 0,2.67255351 C0,1.3097782 1.36539793,0 2.60955829,0 C3.85371865,0 18.9601214,0 20.924815,0 Z" id="path-2"></path>
+    </defs>
+    <g id="icon-/-Other-/-Component_Placeholder---box" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
+        <g id="icon/general/color/-box-template" transform="translate(0.000000, 0.086473)">
+            <mask id="mask-3" fill="white">
+                <use xlink:href="#path-2"></use>
+            </mask>
+            <use id="Path-3" fill="url(#linearGradient-1)" xlink:href="#path-2"></use>
+            <g id="Group" mask="url(#mask-3)" fill="#CCCCCC">
+                <g id="icon/color/AI" style="mix-blend-mode: multiply;">
+                    <rect id="Rectangle-2" x="0" y="0" width="24" height="24"></rect>
+                </g>
+            </g>
+        </g>
+        <path d="M6.88567588,11.4392131 L2.6789578,13.8679629 L2.6789578,18.7254625 L6.88567588,21.1542124 L11.092394,18.7254625 L11.092394,13.8679629 L6.88567588,11.4392131 Z M12.1907173,13.2338456 L12.1907173,19.3595798 L6.88567588,22.422447 L1.58063441,19.3595798 L1.58063441,13.2338456 L6.88567588,10.1709785 L12.1907173,13.2338456 Z M16.8621133,11.2561592 L12.5761306,13.7306725 L12.5761306,18.6796991 L16.8621133,21.1542124 L21.1480961,18.6796991 L21.1480961,13.7306725 L16.8621133,11.2561592 Z M22.2464194,13.0965552 L22.2464194,19.3138164 L16.8621133,22.422447 L11.4778072,19.3138164 L11.4778072,13.0965552 L16.8621133,9.98792459 L22.2464194,13.0965552 Z M11.7828422,3.01873379 L7.61534548,5.42483916 L7.61534548,10.2370499 L11.7828422,12.6431553 L15.950339,10.2370499 L15.950339,5.42483916 L11.7828422,3.01873379 Z M17.0486624,4.79072186 L17.0486624,10.8711672 L11.7828422,13.9113899 L6.51702209,10.8711672 L6.51702209,4.79072186 L11.7828422,1.75049918 L17.0486624,4.79072186 Z M11.2343588,13.8152765 L11.507349,14.2917792 L6.98034199,16.8853189 L2.14795994,14.2955445 L2.40736355,13.8115111 L6.97146167,16.2575066 L11.2343588,13.8152765 Z M6.69245108,16.5547281 L7.24161277,16.5547281 L7.24161277,21.4693642 L6.69245108,21.4693642 L6.69245108,16.5547281 Z M21.2855492,13.6863631 L21.5585394,14.1628658 L16.9582832,16.7983703 L12.0475971,14.1666312 L12.3070007,13.6825978 L16.9494029,16.1705579 L21.2855492,13.6863631 Z M16.6702444,16.4675015 L17.2194061,16.4675015 L17.2194061,21.4640481 L16.6702444,21.4640481 L16.6702444,16.4675015 Z M16.0945363,5.36800761 L16.3675265,5.84451037 L11.8767643,8.41728531 L7.08312819,5.84827569 L7.34253179,5.36424229 L11.8678839,7.78947295 L16.0945363,5.36800761 Z M11.5889465,8.08683212 L12.1381082,8.08683212 L12.1381082,12.9609376 L11.5889465,12.9609376 L11.5889465,8.08683212 Z" id="Combined-Shape" fill="#FFFFFF" fill-rule="nonzero"></path>
+    </g>
+</svg>

+ 7 - 0
AutomatedTesting/Gem/PythonTests/editor/EditorScripts/BasicEditorWorkflows_LevelEntityComponentCRUD.py

@@ -68,6 +68,7 @@ def BasicEditorWorkflows_LevelEntityComponentCRUD():
         import azlmbr.bus as bus
         import azlmbr.editor as editor
         import azlmbr.entity as entity
+        import azlmbr.legacy.general as general
         import azlmbr.math as math
         import azlmbr.paths as paths
 
@@ -85,6 +86,12 @@ def BasicEditorWorkflows_LevelEntityComponentCRUD():
         # 1) Create a new level
         lvl_name = "tmp_level"
         editor_window = pyside_utils.get_editor_main_window()
+
+        # The action manager doesn't register the menus until the next system tick, so need to wait
+        # until the menu bar has been populated
+        general.idle_enable(True)
+        await pyside_utils.wait_for_condition(lambda: len(editor_window.menuBar().actions()) > 1)
+
         new_level_action = pyside_utils.get_action_for_menu_path(editor_window, "File", "New Level")
         pyside_utils.trigger_action_async(new_level_action)
         active_modal_widget = await pyside_utils.wait_for_modal_widget()

+ 6 - 1
AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Menus_EditMenuOptions.py

@@ -26,6 +26,7 @@ def Menus_EditMenuOptions_Work():
     :return: None
     """
 
+    import azlmbr.legacy.general as general
     import editor_python_test_tools.hydra_editor_utils as hydra
     import pyside_utils
     from editor_python_test_tools.utils import Report
@@ -51,7 +52,6 @@ def Menus_EditMenuOptions_Work():
         ("Modify", "Transform Mode", "Scale"),
         ("Editor Settings", "Global Preferences"),
         ("Editor Settings", "Editor Settings Manager"),
-        ("Editor Settings", "Keyboard Customization", "Customize Keyboard"),
         # The following menu options are temporarily disabled due to https://github.com/o3de/o3de/issues/6746
         #("Editor Settings", "Keyboard Customization", "Export Keyboard Settings"),
         #("Editor Settings", "Keyboard Customization", "Import Keyboard Settings"),
@@ -60,6 +60,11 @@ def Menus_EditMenuOptions_Work():
     # 1) Open an existing simple level
     hydra.open_base_level()
 
+    # The action manager doesn't register the menus until the next system tick, so need to wait
+    # until the menu bar has been populated
+    general.idle_enable(True)
+    general.idle_wait_frames(1)
+
     # 2) Interact with Edit Menu options
     editor_window = pyside_utils.get_editor_main_window()
     for option in edit_menu_options:

+ 6 - 6
AutomatedTesting/Gem/PythonTests/editor/EditorScripts/Menus_ViewMenuOptions.py

@@ -26,20 +26,15 @@ def Menus_ViewMenuOptions_Work():
     :return: None
     """
 
+    import azlmbr.legacy.general as general
     import editor_python_test_tools.hydra_editor_utils as hydra
     import pyside_utils
     from editor_python_test_tools.utils import Report
 
     view_menu_options = [
-        ("Center on Selection",),
-        ("Show Quick Access Bar",),
-        ("Layouts", "Component Entity Layout",),
-        ("Layouts", "Save Layout",),
         ("Viewport", "Go to Position"),
         ("Viewport", "Center on Selection"),
         ("Viewport", "Go to Location"),
-        ("Viewport", "Remember Location"),
-        ("Viewport", "Switch Camera"),
         ("Viewport", "Show Helpers"),
         ("Viewport", "Show Icons"),
         ("Refresh Style",),
@@ -48,6 +43,11 @@ def Menus_ViewMenuOptions_Work():
     # 1) Open an existing simple level
     hydra.open_base_level()
 
+    # The action manager doesn't register the menus until the next system tick, so need to wait
+    # until the menu bar has been populated
+    general.idle_enable(True)
+    general.idle_wait_frames(1)
+
     # 2) Interact with View Menu options
     editor_window = pyside_utils.get_editor_main_window()
     for option in view_menu_options:

+ 20 - 0
Code/Editor/Core/EditorActionsHandler.cpp

@@ -20,6 +20,7 @@
 #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorContextIdentifiers.h>
 #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorMenuIdentifiers.h>
 #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorToolBarIdentifiers.h>
+#include <AzToolsFramework/Entity/EditorEntityContextBus.h>
 #include <AzToolsFramework/Viewport/LocalViewBookmarkLoader.h>
 #include <AzToolsFramework/Viewport/ViewportSettings.h>
 
@@ -140,11 +141,18 @@ void EditorActionsHandler::Initialize(MainWindow* mainWindow)
     m_defaultBookmarkCount = AzToolsFramework::LocalViewBookmarkLoader::DefaultViewBookmarkCount;
 
     const int DefaultViewportId = 0;
+
+    // Get EditorEntityContextId
+    AzFramework::EntityContextId editorEntityContextId = AzFramework::EntityContextId::CreateNull();
+    AzToolsFramework::EditorEntityContextRequestBus::BroadcastResult(
+        editorEntityContextId, &AzToolsFramework::EditorEntityContextRequests::GetEditorEntityContextId);
+
     AzToolsFramework::ActionManagerRegistrationNotificationBus::Handler::BusConnect();
     AzToolsFramework::EditorEventsBus::Handler::BusConnect();
     AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusConnect();
     AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusConnect();
     AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusConnect(DefaultViewportId);
+    AzToolsFramework::EditorPickModeNotificationBus::Handler::BusConnect(editorEntityContextId);
 
     m_editorViewportDisplayInfoHandler = new EditorViewportDisplayInfoHandler();
 
@@ -155,6 +163,7 @@ EditorActionsHandler::~EditorActionsHandler()
 {
     if (m_initialized)
     {
+        AzToolsFramework::EditorPickModeNotificationBus::Handler::BusDisconnect();
         AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler::BusDisconnect();
         AzToolsFramework::ToolsApplicationNotificationBus::Handler::BusDisconnect();
         AzToolsFramework::EditorEntityContextNotificationBus::Handler::BusDisconnect();
@@ -181,6 +190,7 @@ void EditorActionsHandler::OnActionUpdaterRegistrationHook()
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::AngleSnappingStateChangedUpdaterIdentifier);
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::DrawHelpersStateChangedUpdaterIdentifier);
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::OnlyShowHelpersForSelectedEntitiesUpdaterIdentifier);
+    m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::EntityPickingModeChangedUpdaterIdentifier);
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::EntitySelectionChangedUpdaterIdentifier);
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::GameModeStateChangedUpdaterIdentifier);
     m_actionManagerInterface->RegisterActionUpdater(EditorIdentifiers::GridSnappingStateChangedUpdaterIdentifier);
@@ -2040,6 +2050,16 @@ void EditorActionsHandler::OnOnlyShowHelpersForSelectedEntitiesChanged([[maybe_u
     m_actionManagerInterface->TriggerActionUpdater(EditorIdentifiers::OnlyShowHelpersForSelectedEntitiesUpdaterIdentifier);
 }
 
+void EditorActionsHandler::OnEntityPickModeStarted()
+{
+    m_actionManagerInterface->TriggerActionUpdater(EditorIdentifiers::EntityPickingModeChangedUpdaterIdentifier);
+}
+
+void EditorActionsHandler::OnEntityPickModeStopped()
+{
+    m_actionManagerInterface->TriggerActionUpdater(EditorIdentifiers::EntityPickingModeChangedUpdaterIdentifier);
+}
+
 bool EditorActionsHandler::IsRecentFileActionActive(int index)
 {
     return (index < m_recentFileActionsCount);

+ 5 - 0
Code/Editor/Core/EditorActionsHandler.h

@@ -40,6 +40,7 @@ class EditorActionsHandler
     , private AzToolsFramework::EditorEntityContextNotificationBus::Handler
     , private AzToolsFramework::ToolsApplicationNotificationBus::Handler
     , private AzToolsFramework::ViewportInteraction::ViewportSettingsNotificationBus::Handler
+    , private AzToolsFramework::EditorPickModeNotificationBus::Handler
 {
 public:
     void Initialize(MainWindow* mainWindow);
@@ -86,6 +87,10 @@ private:
     void OnIconsVisibilityChanged(bool enabled) override;
     void OnOnlyShowHelpersForSelectedEntitiesChanged(bool enabled) override;
 
+    // EditorPickModeNotificationBus overrides ...
+    void OnEntityPickModeStarted() override;
+    void OnEntityPickModeStopped() override;
+
     // Layouts
     void RefreshLayoutActions();
 

+ 9 - 0
Code/Editor/Plugins/ComponentEntityEditorPlugin/SandboxIntegration.cpp

@@ -1918,6 +1918,15 @@ AZStd::string SandboxIntegrationManager::GetComponentIconPath(const AZ::Uuid& co
                 {
                     iconPath = AZStd::move(iconFullPath);
                 }
+                else
+                {
+                    AZ_Warning(
+                        "SandboxIntegration",
+                        false,
+                        "Unable to find icon path \"%s\" for component type: %s",
+                        iconPath.c_str(),
+                        classData->m_editData->m_name);
+                }
             }
         }
     }

+ 17 - 5
Code/Framework/AzCore/AzCore/Instance/InstancePool.h

@@ -36,12 +36,19 @@ namespace AZ
         AZ_RTTI(InstancePool, "{D4FBBAD7-AA9D-4350-B5A1-72A1A09A7F16}", InstancePoolBase);
 
         using ResetInstance = AZStd::function<void(T&)>;
+        using CreateInstance = AZStd::function<T*()>;
 
-        InstancePool(ResetInstance resetFunctor = [](T&){})
+        InstancePool(ResetInstance resetFunctor, CreateInstance createFunctor)
             : m_resetFunction(resetFunctor)
+            , m_createFunction(createFunctor)
         {
         }
 
+        bool HasInstance()
+        {
+            return !m_instances.empty();
+        }
+
         // returns a recycled instance if present, but creates a new instance if necessary
         T* GetInstance()
         {
@@ -53,7 +60,7 @@ namespace AZ
             }
             else
             {
-                return new T;
+                return m_createFunction();
             }
         }
 
@@ -75,6 +82,7 @@ namespace AZ
     private:
         AZStd::vector<AZStd::unique_ptr<T>> m_instances;
         ResetInstance m_resetFunction;
+        CreateInstance m_createFunction;
     };
 
     class InstancePoolManagerInterface
@@ -98,9 +106,11 @@ namespace AZ
 
         // creates a pool with the explicit name given, and the reset function specified
         template<class T>
-        AZ::Outcome<AZStd::shared_ptr<InstancePool<T>>, AZStd::string> CreatePool(AZ::Name name, typename InstancePool<T>::ResetInstance resetFunc)
+        AZ::Outcome<AZStd::shared_ptr<InstancePool<T>>, AZStd::string> CreatePool(
+            AZ::Name name, typename InstancePool<T>::ResetInstance resetFunc = [](T&){}, 
+            typename InstancePool<T>::CreateInstance createFunc = []() { return new T{}; })
         {
-            AZStd::shared_ptr<InstancePool<T>> instancePool = AZStd::make_shared<InstancePool<T>>(resetFunc);
+            AZStd::shared_ptr<InstancePool<T>> instancePool = AZStd::make_shared<InstancePool<T>>(resetFunc, createFunc);
             auto insertResult = m_nameToInstancePool.insert({ name, instancePool });
             if (!insertResult.second)
             {
@@ -135,7 +145,9 @@ namespace AZ
         // without having to manually coordinate the pool name. 
         // important note: to use this, the T type must either include the AZ_RTTI macro, or be externally exposed via AZ_TYPE_INFO_SPECIALIZE
         template<class T>
-        AZ::Outcome<AZStd::shared_ptr<InstancePool<T>>, AZStd::string> CreatePool(typename InstancePool<T>::ResetInstance resetFunc)
+        AZ::Outcome<AZStd::shared_ptr<InstancePool<T>>, AZStd::string> CreatePool(
+            typename InstancePool<T>::ResetInstance resetFunc = [](T&){}, 
+            typename InstancePool<T>::CreateInstance createFunc = []() { return new T{}; })
         {
             const char* name = AZ::AzTypeInfo<T>::Name();
             return CreatePool<T>(AZ::Name(name), resetFunc);

+ 33 - 1
Code/Framework/AzFramework/AzFramework/Physics/Common/PhysicsSceneQueries.h

@@ -132,12 +132,27 @@ namespace AzPhysics
     //! Not valid to be used with Scene::QueryScene functions
     struct SceneQueryRequest
     {
+        enum class RequestType : AZ::u8
+        {
+            Undefined = 0,
+            Raycast,
+            Shapecast,
+            Overlap
+        };
+
         AZ_CLASS_ALLOCATOR_DECL;
         AZ_RTTI(SceneQueryRequest, "{76ECAB7D-42BA-461F-82E6-DCED8E1BDCB9}");
+
+        explicit SceneQueryRequest(RequestType requestType)
+            : m_requestType(requestType)
+        {
+        }
+        SceneQueryRequest() = default;
         static void Reflect(AZ::ReflectContext* context);
         virtual ~SceneQueryRequest() = default;
 
-        AZ::u64 m_maxResults = 32; //!< The Maximum results for this request to return, this is limited by the value set in the SceneConfiguration
+        RequestType m_requestType = RequestType::Undefined;
+        AZ::u32 m_maxResults = 32; //!< The Maximum results for this request to return, this is limited by the value set in the SceneConfiguration
         CollisionGroup m_collisionGroup = CollisionGroup::All; //!< Collision filter for the query.
         SceneQuery::QueryType m_queryType = SceneQuery::QueryType::StaticAndDynamic; //!< Object types to include in the query
     };
@@ -149,6 +164,12 @@ namespace AzPhysics
     {
         AZ_CLASS_ALLOCATOR_DECL;
         AZ_RTTI(RayCastRequest, "{53EAD088-A391-48F1-8370-2A1DBA31512F}", SceneQueryRequest);
+
+        RayCastRequest()
+            : SceneQueryRequest(RequestType::Raycast)
+        {
+        }
+
         static void Reflect(AZ::ReflectContext* context);
 
         float m_distance = 500.0f; //!< The distance to cast along the direction.
@@ -165,6 +186,11 @@ namespace AzPhysics
     {
         AZ_CLASS_ALLOCATOR_DECL;
         AZ_RTTI(ShapeCastRequest, "{52F6C536-92F6-4C05-983D-0A74800AE56D}", SceneQueryRequest);
+
+        ShapeCastRequest()
+            : SceneQueryRequest(RequestType::Shapecast)
+        {
+        }
         static void Reflect(AZ::ReflectContext* context);
 
         float m_distance = 500.0f; //! The distance to cast along the direction.
@@ -207,6 +233,12 @@ namespace AzPhysics
     {
         AZ_CLASS_ALLOCATOR_DECL;
         AZ_RTTI(OverlapRequest, "{3DC986C2-316B-4C54-A0A6-8ABBB8ABCC4A}", SceneQueryRequest);
+
+        OverlapRequest()
+            : SceneQueryRequest(RequestType::Overlap)
+        {
+        }
+
         static void Reflect(AZ::ReflectContext* context);
 
         AZ::Transform m_pose = AZ::Transform::CreateIdentity(); //!< Initial shape pose

+ 3 - 3
Code/Framework/AzFramework/AzFramework/Physics/Configuration/SystemConfiguration.h

@@ -33,9 +33,9 @@ namespace AzPhysics
         float m_maxTimestep = 0.1f; //!< Maximum fixed timestep in seconds to run the physics update (10FPS).
         float m_fixedTimestep = DefaultFixedTimestep; //!< Timestep in seconds to run the physics update. See DefaultFixedTimestep.
 
-        AZ::u64 m_raycastBufferSize = 32; //!< Maximum number of hits that will be returned from a raycast.
-        AZ::u64 m_shapecastBufferSize = 32; //!< Maximum number of hits that can be returned from a shapecast.
-        AZ::u64 m_overlapBufferSize = 32; //!< Maximum number of overlaps that can be returned from an overlap query.
+        AZ::u32 m_raycastBufferSize = 32; //!< Maximum number of hits that will be returned from a raycast.
+        AZ::u32 m_shapecastBufferSize = 32; //!< Maximum number of hits that can be returned from a shapecast.
+        AZ::u32 m_overlapBufferSize = 32; //!< Maximum number of overlaps that can be returned from an overlap query.
 
         //! Contains the default global collision layers and groups.
         //! Each Physics Scene uses this as a base and will override as needed.

+ 3 - 3
Code/Framework/AzQtComponents/AzQtComponents/Components/Widgets/ElidingLabel.cpp

@@ -85,16 +85,16 @@ namespace AzQtComponents
         {
             // If RichText tags are elided using fontMetrics.elidedText(), they will break.
             // A TextDocument is used to produce elided text that takes this into account.
-            const QString ellipsis("...");
+            static const QString ellipsis(QStringLiteral("..."));
             const int maxLineWidth = TextRect().width();
 
-            QTextDocument doc;
+            static QTextDocument doc;
             doc.setHtml(m_text);
             doc.setDefaultFont(font());
             doc.setDocumentMargin(0.0);
 
             // Turn off wrapping so the document uses a single line.
-            QTextOption option = doc.defaultTextOption();
+            static QTextOption option = doc.defaultTextOption();
             option.setWrapMode(QTextOption::WrapMode::NoWrap);
             doc.setDefaultTextOption(option);
             doc.adjustSize();

+ 21 - 0
Code/Framework/AzToolsFramework/AzToolsFramework/ComponentMode/ComponentModeActionHandler.cpp

@@ -11,6 +11,7 @@
 #include <AzToolsFramework/ActionManager/Action/ActionManagerInterface.h>
 #include <AzToolsFramework/ActionManager/Menu/MenuManagerInterface.h>
 #include <AzToolsFramework/ActionManager/HotKey/HotKeyManagerInterface.h>
+#include <AzToolsFramework/API/ViewportEditorModeTrackerInterface.h>
 #include <AzToolsFramework/ComponentMode/EditorBaseComponentMode.h>
 #include <AzToolsFramework/ComponentMode/EditorComponentModeBus.h>
 #include <AzToolsFramework/Editor/ActionManagerIdentifiers/EditorActionUpdaterIdentifiers.h>
@@ -100,6 +101,26 @@ namespace AzToolsFramework
                 }
             );
 
+            // Disable this action if the Entity Picker is enabled while in Component Mode.
+            m_actionManagerInterface->InstallEnabledStateCallback(
+                actionIdentifier,
+                []()
+                {
+                    if (auto viewportEditorModeTracker = AZ::Interface<AzToolsFramework::ViewportEditorModeTrackerInterface>::Get())
+                    {
+                        auto viewportEditorModes = viewportEditorModeTracker->GetViewportEditorModes({ AzToolsFramework::GetEntityContextId() });
+                        if (viewportEditorModes->IsModeActive(AzToolsFramework::ViewportEditorMode::Pick))
+                        {
+                            return false;
+                        }
+                    }
+
+                    return true;
+                }
+            );
+
+            m_actionManagerInterface->AddActionToUpdater(EditorIdentifiers::EntityPickingModeChangedUpdaterIdentifier, actionIdentifier);
+
             // Only add this to the component modes, not default.
             m_actionManagerInterface->AssignModeToAction("SomeMode", actionIdentifier);
 

+ 1 - 0
Code/Framework/AzToolsFramework/AzToolsFramework/Editor/ActionManagerIdentifiers/EditorActionUpdaterIdentifiers.h

@@ -15,6 +15,7 @@ namespace EditorIdentifiers
     inline constexpr AZStd::string_view AngleSnappingStateChangedUpdaterIdentifier = "o3de.updater.onAngleSnappingStateChanged";
     inline constexpr AZStd::string_view ComponentModeChangedUpdaterIdentifier = "o3de.updater.onComponentModeChanged";
     inline constexpr AZStd::string_view DrawHelpersStateChangedUpdaterIdentifier = "o3de.updater.onViewportDrawHelpersStateChanged";
+    inline constexpr AZStd::string_view EntityPickingModeChangedUpdaterIdentifier = "o3de.updater.onEntityPickingModeChanged";
     inline constexpr AZStd::string_view EntitySelectionChangedUpdaterIdentifier = "o3de.updater.onEntitySelectionChanged";
     inline constexpr AZStd::string_view GameModeStateChangedUpdaterIdentifier = "o3de.updater.onGameModeStateChanged";
     inline constexpr AZStd::string_view GridShowingChangedUpdaterIdentifier = "o3de.updater.onGridShowingChanged";

+ 1 - 1
Code/Framework/AzToolsFramework/AzToolsFramework/Manipulators/EditorVertexSelection.cpp

@@ -83,7 +83,7 @@ namespace AzToolsFramework
         componentModeCollectionInterface->EnumerateActiveComponents(
             [&emptySelection](const AZ::EntityComponentIdPair& entityComponentIdPair, const AZ::Uuid&)
             {
-                int count;
+                int count = 0;
                 EditorVertexSelectionVariableRequestBus::EventResult(
                     count, entityComponentIdPair, &EditorVertexSelectionVariableRequests::GetSelectedVerticesCount);
 

+ 82 - 28
Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.cpp

@@ -22,7 +22,6 @@
 #include <AzToolsFramework/UI/DPEDebugViewer/DPEDebugModel.h>
 #include <AzToolsFramework/UI/DPEDebugViewer/DPEDebugWindow.h>
 #include <AzToolsFramework/UI/DocumentPropertyEditor/KeyQueryDPE.h>
-#include <AzToolsFramework/UI/DocumentPropertyEditor/PropertyEditorToolsSystemInterface.h>
 
 AZ_CVAR(
     bool,
@@ -204,18 +203,19 @@ namespace AzToolsFramework
 
         //! Treat all widgets in a shared column as one item.
         //! Sum all the widgets, but remove all shared widgets other than the first widget of each shared column.
-        const int itemCount = count() - SharedWidgetCount() + static_cast<int>(m_sharePriorColumn.size());
+        const int itemCount = count();
+        const int effectiveCount = itemCount - SharedWidgetCount() + static_cast<int>(m_sharePriorColumn.size());
 
-        if (itemCount > 0)
+        if (effectiveCount > 0)
         {
             // divide evenly, unless there are 2 columns, in which case follow the 2/5ths rule here:
             // https://www.o3de.org/docs/tools-ui/ux-patterns/component-card/overview/
-            int perItemWidth = (itemCount == 2 ? (rect.width() * 3) / 5 : rect.width() / itemCount);
+            const int perItemWidth = (effectiveCount == 2 ? (rect.width() * 3) / 5 : rect.width() / effectiveCount);
 
             // special case the first item to handle indent and the 2/5ths rule
             constexpr int indentSize = 15; // child indent of first item, in pixels
             QRect itemGeometry(rect);
-            itemGeometry.setRight(itemCount == 2 ? itemGeometry.width() - perItemWidth : perItemWidth);
+            itemGeometry.setRight(effectiveCount == 2 ? itemGeometry.width() - perItemWidth : perItemWidth);
             itemGeometry.setLeft(itemGeometry.left() + (m_depth * indentSize));
 
             if (m_showExpander)
@@ -225,7 +225,10 @@ namespace AzToolsFramework
                     CreateExpanderWidget();
                 }
                 m_expanderWidget->move(itemGeometry.topLeft());
-                m_expanderWidget->show();
+                if (auto* widgetParent = parentWidget(); widgetParent && widgetParent->isVisible())
+                {
+                    m_expanderWidget->show();
+                }
             }
 
             // space to leave for expander, whether it's there or not
@@ -236,11 +239,11 @@ namespace AzToolsFramework
             int sharedVectorIndex = 0;
             // iterate over each item, laying them left to right
             int layoutIndex = 0;
-            const int itemCountActual = count();
-            while (layoutIndex < itemCountActual)
+            while (layoutIndex < itemCount)
             {
                 size_t currentWidget = static_cast<size_t>(layoutIndex);
-                AzToolsFramework::DPERowWidget::AttributeInfo* attributes = GetRow()->GetAttributes(currentWidget);
+                auto* myRow = GetRow();
+                AzToolsFramework::DPERowWidget::AttributeInfo* attributes = myRow->GetAttributes(currentWidget);
 
                 //! If the current widget is the first widget of a shared column, create the shared column layout and add widgets to it
                 if (sharedVectorIndex < m_sharePriorColumn.size() &&
@@ -258,7 +261,7 @@ namespace AzToolsFramework
                     while (sharedWidgetIndex < numItems)
                     {
                         currentWidget = m_sharePriorColumn[sharedVectorIndex][sharedWidgetIndex];
-                        attributes = GetRow()->GetAttributes(currentWidget);
+                        attributes = myRow->GetAttributes(currentWidget);
                         // Save the alignment of the last widget in the shared column with an alignment attribute
                         if (attributes)
                         {
@@ -295,14 +298,13 @@ namespace AzToolsFramework
                     // if all widgets in this shared column take up only their minimum width, set the appropriate alignment with spacers
                     if (minWidthCount == numItems)
                     {
+                        QSpacerItem* spacer = new QSpacerItem(perItemWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
                         if (startSpacer)
                         {
-                            QSpacerItem* spacer = new QSpacerItem(perItemWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
                             sharedColumnLayout->insertSpacerItem(0, spacer);
                         }
                         if (endSpacer)
                         {
-                            QSpacerItem* spacer = new QSpacerItem(perItemWidth, 1, QSizePolicy::Expanding, QSizePolicy::Fixed);
                             sharedColumnLayout->addSpacerItem(spacer);
                         }
                     }
@@ -318,9 +320,9 @@ namespace AzToolsFramework
                         itemGeometry.setRight(itemGeometry.left() + perItemWidth);
                         sharedColumnLayout->setGeometry(itemGeometry);
                     }
-                    sharedVectorIndex++;
+                    ++sharedVectorIndex;
                     // Increase the layout index by the amount of widgets in the shared column we have iterated over
-                    layoutIndex = layoutIndex + sharedWidgetIndex;
+                    layoutIndex += sharedWidgetIndex;
                 }
                 // Widget is not in a shared column, lay it individually with its appropriate alignment
                 else
@@ -331,6 +333,7 @@ namespace AzToolsFramework
                     }
                     else
                     {
+                        auto* currItem = itemAt(layoutIndex);
                         itemGeometry.setLeft(itemGeometry.right() + 1);
                         itemGeometry.setRight(itemGeometry.left() + perItemWidth);
                         if (attributes)
@@ -338,17 +341,17 @@ namespace AzToolsFramework
                             switch (attributes->m_alignment)
                             {
                             case AZ::Dpe::Nodes::PropertyEditor::Align::AlignLeft:
-                                itemAt(layoutIndex)->setAlignment(Qt::AlignLeft);
+                                currItem->setAlignment(Qt::AlignLeft);
                                 break;
                             case AZ::Dpe::Nodes::PropertyEditor::Align::AlignCenter:
-                                itemAt(layoutIndex)->setAlignment(Qt::AlignCenter);
+                                currItem->setAlignment(Qt::AlignCenter);
                                 break;
                             case AZ::Dpe::Nodes::PropertyEditor::Align::AlignRight:
-                                itemAt(layoutIndex)->setAlignment(Qt::AlignRight);
+                                currItem->setAlignment(Qt::AlignRight);
                                 break;
                             }
                         }
-                        itemAt(layoutIndex)->setGeometry(itemGeometry);
+                        currItem->setGeometry(itemGeometry);
                     }
                     layoutIndex++;
                 }
@@ -994,7 +997,11 @@ namespace AzToolsFramework
         // insert after the found index; even if nothing were found and priorIndex is -1,
         // insert one after it, at position 0
         m_columnLayout->insertWidget(priorColumnIndex + 1, columnWidget);
-        columnWidget->show();
+
+        if (isVisible())
+        {
+            columnWidget->show();
+        }
     }
 
     QWidget* DPERowWidget::CreateWidgetForHandler(
@@ -1004,24 +1011,63 @@ namespace AzToolsFramework
         // if we found a valid handler, grab its widget to add to the column layout
         if (handlerId)
         {
+            auto poolManager = static_cast<AZ::InstancePoolManager*>(AZ::Interface<AZ::InstancePoolManagerInterface>::Get());
+            auto handlerName = AZ::Name(handlerId->m_name);
+            auto handlerPool = poolManager->GetPool<PropertyHandlerWidgetInterface>(handlerName);
+            if (!handlerPool)
+            {
+                auto* theDPE = GetDPE();
+                AZ_Assert(theDPE, "DPERowWidget should always be able to retrieve its DPE during widget creation!");
+                if (!theDPE)
+                {
+                    return nullptr;
+                }
+                AZStd::function<void(PropertyHandlerWidgetInterface&)> resetHandler = [](PropertyHandlerWidgetInterface& handler)
+                {
+                    DetachAndHide(handler.GetWidget());
+                };
+
+                AZStd::function<PropertyHandlerWidgetInterface*()> createHandler = [handlerId]()
+                {
+                    auto createdHandler = AZ::Interface<PropertyEditorToolsSystemInterface>::Get()->CreateHandlerInstance(handlerId);
+                    auto bareHandler = createdHandler.get();
+                    createdHandler.release();
+                    return bareHandler;
+                };
+
+                handlerPool = poolManager->CreatePool<PropertyHandlerWidgetInterface>(handlerName, resetHandler, createHandler)
+                                 .GetValue();
+                theDPE->RegisterHandlerPool(handlerPool);
+            }
+
             // store, then reference the unique_ptr that will manage the handler's lifetime
-            auto handler = AZ::Interface<PropertyEditorToolsSystemInterface>::Get()->CreateHandlerInstance(handlerId);
+            auto handler = handlerPool->GetInstance();
             handler->SetValueFromDom(domValue);
             createdWidget = handler->GetWidget();
             createdWidget->setEnabled(true);
-            m_widgetToPropertyHandlerInfo[createdWidget] = { handlerId, AZStd::move(handler) };
+            m_widgetToPropertyHandlerInfo[createdWidget] = { handlerId, AZStd::unique_ptr<PropertyHandlerWidgetInterface>(handler) };
         }
         return createdWidget;
     }
 
     void DPERowWidget::ReleaseHandler(HandlerInfo& handler)
     {
-        QTimer::singleShot(
-            0,
-            [interfacePointer = handler.hanlderInterface.get()]()
-            {
-                delete interfacePointer;
-            });
+        auto poolManager = static_cast<AZ::InstancePoolManager*>(AZ::Interface<AZ::InstancePoolManagerInterface>::Get());
+        auto handlerName = AZ::Name(handler.handlerId->m_name);
+        auto handlerPool = poolManager->GetPool<PropertyHandlerWidgetInterface>(handlerName);
+        if (handlerPool)
+        {
+            handlerPool->RecycleInstance(handler.hanlderInterface.get());
+        }
+        else
+        {
+            QTimer::singleShot(
+                0,
+                [interfacePointer = handler.hanlderInterface.get()]()
+                {
+                    delete interfacePointer;
+                });
+        }
         handler.hanlderInterface.release();
     }
 
@@ -1279,7 +1325,10 @@ namespace AzToolsFramework
                 m_layout->insertWidget(foundIndex + 1, widgetToAdd);
             }
         }
-        widgetToAdd->show();
+        if (isVisible())
+        {
+            widgetToAdd->show();
+        }
     }
 
     void DocumentPropertyEditor::SetSavedStateKey(AZ::u32 key, AZStd::string propertyEditorName)
@@ -1498,4 +1547,9 @@ namespace AzToolsFramework
 
         message.Match(AZ::DocumentPropertyEditor::Nodes::Adapter::QueryKey, showKeyQueryDialog);
     }
+
+    void DocumentPropertyEditor::RegisterHandlerPool(AZStd::shared_ptr<AZ::InstancePoolBase> handlerPool)
+    {
+        m_handlerPools.push_back(handlerPool);
+    }
 } // namespace AzToolsFramework

+ 5 - 0
Code/Framework/AzToolsFramework/AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditor.h

@@ -14,6 +14,7 @@
 #include <AzQtComponents/Components/Widgets/ElidingLabel.h>
 #include <AzToolsFramework/UI/DocumentPropertyEditor/DocumentPropertyEditorSettings.h>
 #include <AzToolsFramework/UI/DocumentPropertyEditor/IPropertyEditor.h>
+#include <AzToolsFramework/UI/DocumentPropertyEditor/PropertyEditorToolsSystemInterface.h>
 #include <AzToolsFramework/UI/DocumentPropertyEditor/PropertyHandlerWidget.h>
 
 #include <QHBoxLayout>
@@ -241,6 +242,8 @@ namespace AzToolsFramework
                 ->GetPool<AzQtComponents::ElidingLabel>();
         }
 
+        void RegisterHandlerPool(AZStd::shared_ptr<AZ::InstancePoolBase> handlerPool);
+
     public slots:
         //! set the DOM adapter for this DPE to inspect
         void SetAdapter(AZ::DocumentPropertyEditor::DocumentAdapterPtr theAdapter);
@@ -270,6 +273,8 @@ namespace AzToolsFramework
         // incurring the cost of creating and destroying them
         AZStd::shared_ptr<AZ::InstancePool<DPERowWidget>> m_rowPool;
         AZStd::shared_ptr<AZ::InstancePool<AzQtComponents::ElidingLabel>> m_labelPool;
+
+        AZStd::vector<AZStd::shared_ptr<AZ::InstancePoolBase>> m_handlerPools;
     };
 } // namespace AzToolsFramework
 

+ 1 - 5
Code/Framework/AzToolsFramework/AzToolsFramework/UI/PropertyEditor/ComponentEditor.cpp

@@ -644,11 +644,7 @@ namespace AzToolsFramework
         m_componentType = AZ::Uuid::CreateNull();
 
         GetHeader()->SetTitle(ComponentEditorConstants::kUnknownComponentTitle);
-
-        AZStd::string iconPath;
-        AzToolsFramework::EditorRequests::Bus::BroadcastResult(
-            iconPath, &AzToolsFramework::EditorRequests::Bus::Events::GetDefaultComponentEditorIcon);
-        GetHeader()->SetIcon(QIcon(iconPath.c_str()));
+        GetHeader()->SetIcon(QIcon());
     }
 
     QString ComponentEditor::BuildHeaderTooltip()

+ 0 - 4
Code/Legacy/CryCommon/crycommon_files.cmake

@@ -7,8 +7,6 @@
 #
 
 set(FILES
-    IAudioInterfacesCommonData.h
-    IAudioSystem.h
     ICmdLine.h
     IConsole.h
     IFont.h
@@ -30,7 +28,6 @@ set(FILES
     IValidator.h
     IWindowMessageHandler.h
     IXml.h
-    MicrophoneBus.h
     INavigationSystem.h
     IMNM.h
     SerializationTypes.h
@@ -48,7 +45,6 @@ set(FILES
     CryVersion.h
     MiniQueue.h
     MultiThread_Containers.h
-    NullAudioSystem.h
     PNoise3.h
     ProjectDefines.h
     Range.h

+ 2 - 0
Code/Legacy/CrySystem/CMakeLists.txt

@@ -33,6 +33,8 @@ ly_add_target(
             Legacy::CrySystem.XMLBinary
             Legacy::RemoteConsoleCore
             AZ::AzFramework
+        PUBLIC
+            Gem::AudioSystem.API
 )
 
 ly_add_source_properties(

+ 11 - 2
Gems/AWSCore/Code/Source/AWSCoreSystemComponent.cpp

@@ -137,12 +137,21 @@ namespace AWSCore
 
     void AWSCoreSystemComponent::InitAWSApi()
     {
-        AWSNativeSDKInit::InitializationManager::InitAwsApi();
+        // Multiple different Gems might try to use the AWSNativeSDK, so make sure it only gets initialized / shutdown once
+        // by the first Gem to try using it.
+        m_ownsAwsNativeInitialization = !AWSNativeSDKInit::InitializationManager::IsInitialized();
+        if (m_ownsAwsNativeInitialization)
+        {
+            AWSNativeSDKInit::InitializationManager::InitAwsApi();
+        }
     }
 
     void AWSCoreSystemComponent::ShutdownAWSApi()
     {
-        AWSNativeSDKInit::InitializationManager::Shutdown();
+        if (m_ownsAwsNativeInitialization)
+        {
+            AWSNativeSDKInit::InitializationManager::Shutdown();
+        }
     }
 
     AZ::JobContext* AWSCoreSystemComponent::GetDefaultJobContext()

+ 2 - 0
Gems/AWSCore/Code/Source/AWSCoreSystemComponent.h

@@ -77,6 +77,8 @@ namespace AWSCore
         AZStd::unique_ptr<AWSCoreConfiguration> m_awsCoreConfiguration;
         AZStd::unique_ptr<AWSCredentialManager> m_awsCredentialManager;
         AZStd::unique_ptr<AWSResourceMappingManager> m_awsResourceMappingManager;
+
+        bool m_ownsAwsNativeInitialization = false; // Track whether or not this module initialized the native layer
     };
 
 } // namespace AWSCore

+ 68 - 0
Gems/Atom/Feature/Common/Assets/Passes/DownsampleSinglePassLuminance.pass

@@ -0,0 +1,68 @@
+{
+    "Type": "JsonSerialization",
+    "Version": 1,
+    "ClassName": "PassAsset",
+    "ClassData": {
+        "PassTemplate": {
+            "Name": "DownsampleSinglePassLuminanceTemplate",
+            "PassClass": "DownsampleSinglePassLuminancePass",
+            "PassData": {
+                "$type": "ComputePassData",
+                "Make Fullscreen Pass": false,
+                "ShaderAsset": {
+                    "FilePath": "Shaders/PostProcessing/DownsampleSinglePassLuminance.shader" 
+                }
+            },
+            "Slots": [
+                {
+                    "Name": "Input",
+                    "SlotType": "Input",
+                    "ShaderInputName": "m_inputImage",
+                    "ScopeAttachmentUsage": "Shader",
+                    "ImageViewDesc": {
+                        "MipSliceMin": "0",
+                        "MipSliceMax": "0"
+                    }
+                },                
+                {
+                    "Name": "Output",
+                    "SlotType": "Output",
+                    "ShaderInputName": "m_imageDestination",
+                    "ScopeAttachmentUsage": "Shader",
+                    "ImageViewDesc": {
+                        "MipSliceMin": 0,
+                        "MipSliceMax": 12
+                    }
+                }
+            ],
+            "ImageAttachments": [
+                {
+                    "Name": "LuminanceMinAvgMax",
+                    "SizeSource": {
+                        "Source": {
+                            "Pass": "This",
+                            "Attachment": "Input"
+                        },
+                        "Multipliers": {
+                            "WidthMultiplier": 0.5,
+                            "HeightMultiplier": 0.5
+                        }
+                    },
+                    "ImageDescriptor": {
+                        "Format": "R16G16B16A16_FLOAT"
+                    },
+                    "GenerateFullMipChain": true
+                }
+            ],
+            "Connections": [
+                {
+                    "LocalSlot": "Output",
+                    "AttachmentRef": {
+                        "Pass": "This",
+                        "Attachment": "LuminanceMinAvgMax"
+                    }
+                }
+            ]
+        }
+    }
+}

+ 6 - 25
Gems/Atom/Feature/Common/Assets/Passes/LightAdaptationParent.pass

@@ -39,15 +39,15 @@
                 {
                     "LocalSlot": "LuminanceMipChainOutput",
                     "AttachmentRef": {
-                        "Pass": "DownsampleLuminanceMipChain",
-                        "Attachment": "MipChainInputOutput"
+                        "Pass": "DownsampleSinglePassLuminance",
+                        "Attachment": "Output"
                     }
                 }
             ],
             "PassRequests": [
                 {
-                    "Name": "DownsampleLuminanceMinAvgMax",
-                    "TemplateName": "DownsampleLuminanceMinAvgMaxCS",
+                    "Name": "DownsampleSinglePassLuminance",
+                    "TemplateName": "DownsampleSinglePassLuminanceTemplate",
                     "Connections": [
                         {
                             "LocalSlot": "Input",
@@ -58,25 +58,6 @@
                         }
                     ]
                 },
-                {
-                    "Name": "DownsampleLuminanceMipChain",
-                    "TemplateName": "DownsampleMipChainTemplate",
-                    "Connections": [
-                        {
-                            "LocalSlot": "MipChainInputOutput",
-                            "AttachmentRef": {
-                                "Pass": "DownsampleLuminanceMinAvgMax",
-                                "Attachment": "Output"
-                            }
-                        }
-                    ],
-                    "PassData": {
-                        "$type": "DownsampleMipChainPassData",
-                        "ShaderAsset": {
-                            "FilePath": "Shaders/PostProcessing/DownsampleMinAvgMaxCS.shader"
-                        }
-                    }
-                },
                 {
                     "Name": "EyeAdaptationPass",
                     "TemplateName": "EyeAdaptationTemplate",
@@ -85,8 +66,8 @@
                         {
                             "LocalSlot": "SceneLuminanceInput",
                             "AttachmentRef": {
-                                "Pass": "DownsampleLuminanceMipChain",
-                                "Attachment": "MipChainInputOutput"
+                                "Pass": "DownsampleSinglePassLuminance",
+                                "Attachment": "Output"
                             }
                         }
                     ]

+ 4 - 0
Gems/Atom/Feature/Common/Assets/Passes/PassTemplates.azasset

@@ -128,6 +128,10 @@
                 "Name": "DownsampleMipChainTemplate",
                 "Path": "Passes/DownsampleMipChain.pass"
             },
+            {
+                "Name": "DownsampleSinglePassLuminanceTemplate",
+                "Path": "Passes/DownsampleSinglePassLuminance.pass"
+            },
             {
                 "Name": "DisplayMapperTemplate",
                 "Path": "Passes/DisplayMapper.pass"

+ 161 - 0
Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DownsampleSinglePassLuminance.azsl

@@ -0,0 +1,161 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+// refer https://github.com/GPUOpen-Effects/FidelityFX-SPD/blob/c52944f547884774a1b33066f740e6bf89f927f5/sample/src/DX12/SPDIntegration.hlsl
+
+#include <Atom/RPI/Math.azsli>
+#include <Atom/Features/SrgSemantics.azsli>
+#include <Atom/Features/ColorManagement/TransformColor.azsli>
+
+struct SpdGlobalAtomicBuffer
+{
+    uint m_counter;
+};
+
+ShaderResourceGroup PassSrg : SRG_PerPass
+{
+    Texture2D<float4> m_inputImage;
+    RWTexture2D<float4> m_imageDestination[13];
+    [[verbatim("globallycoherent")]] RWTexture2D<float4> m_mip6;
+    [[verbatim("globallycoherent")]] RWStructuredBuffer<SpdGlobalAtomicBuffer> m_globalAtomic;
+
+    // Mip level count of m_imageDestination.
+    uint m_destinationMipLevelCount;
+    // The steps of this downsample computation.  It may slightly larger than m_destinationMipLevelCount.
+    uint m_spdMipLevelCount;
+    uint m_numWorkGroups;
+
+    uint2 m_imageSize;
+}
+
+#define A_GPU
+#define A_HLSL
+#include <External/FidelityFX/ffx-spd/ffx_a.h>
+
+groupshared AU1 s_spdCounter;
+
+groupshared AF1 s_spdIntermediateR[16][16];
+groupshared AF1 s_spdIntermediateG[16][16];
+groupshared AF1 s_spdIntermediateB[16][16];
+groupshared AF1 s_spdIntermediateA[16][16];
+
+AF4 SpdLoadSourceImage(AF2 tex, AU1 /* slice */)
+{
+    if (tex.x < PassSrg::m_imageSize.x &&
+        tex.y < PassSrg::m_imageSize.y)
+    {
+        const float3 rgb = PassSrg::m_inputImage[tex].rgb;
+        const float luminance = CalculateLuminance(rgb, ColorSpaceId::ACEScg);
+        return AF4(luminance, luminance, luminance, 1.);
+    }
+    else
+    {
+        return AF4(FLOAT_32_MAX, 0., 0., 0.);
+    }
+}
+
+AF4 SpdLoad(ASU2 tex, AU1 /* slice */)
+{
+    const AU1 GloballyCoherentMipIndex = 6;
+    if ((tex.x >> GloballyCoherentMipIndex) < PassSrg::m_imageSize.x &&
+        (tex.y >> GloballyCoherentMipIndex) < PassSrg::m_imageSize.y)
+    {
+        return PassSrg::m_mip6[tex];
+    }
+    else
+    {
+        return AF4(FLOAT_32_MAX, 0., 0., 0.);
+    }
+}
+
+void SpdStore(ASU2 pix, AF4 value, AU1 mip, AU1 /* slice */)
+{
+    // Store to the globally coherent working mip slice.
+    if (mip == 5 && value.w > 0.)
+        PassSrg::m_mip6[pix] = value;
+    
+    const AU1 mipAdjusted = min(mip, PassSrg::m_destinationMipLevelCount - 1);
+    PassSrg::m_imageDestination[mipAdjusted][pix] = value;
+}
+
+void SpdIncreaseAtomicCounter(AU1 /* slice*/)
+{
+    InterlockedAdd(PassSrg::m_globalAtomic[0].m_counter, 1, s_spdCounter);
+}
+
+AU1 SpdGetAtomicCounter()
+{
+    return s_spdCounter;
+}
+
+void SpdResetAtomicCounter(AU1 /* slice */)
+{
+    PassSrg::m_globalAtomic[0].m_counter = 0;
+}
+
+AF4 SpdLoadIntermediate(AU1 x, AU1 y)
+{
+    return AF4(
+        s_spdIntermediateR[x][y],
+        s_spdIntermediateG[x][y],
+        s_spdIntermediateB[x][y],
+        s_spdIntermediateA[x][y]);
+}
+
+void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value)
+{
+    s_spdIntermediateR[x][y] = value.x;
+    s_spdIntermediateG[x][y] = value.y;
+    s_spdIntermediateB[x][y] = value.z;
+    s_spdIntermediateA[x][y] = value.w;
+}
+
+float GetValueWithFlag(float value, float flag, float errorValue)
+{
+    return (flag > 0.) ? value : errorValue;
+}
+
+float MinWithFlag(AF4 v0, AF4 v1)
+{
+    return min(
+        GetValueWithFlag(v0.x, v0.w, FLOAT_32_MAX),
+        GetValueWithFlag(v1.x, v1.w, FLOAT_32_MAX));
+}
+
+float MaxWithFlag(AF4 v0, AF4 v1)
+{
+    return max(
+        GetValueWithFlag(v0.z, v0.w, 0.),
+        GetValueWithFlag(v1.z, v1.w, 0.));
+}
+
+AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3)
+{
+    const float weightSum = v0.w + v1.w + v2.w + v3.w;
+    const float minValue = min(MinWithFlag(v0, v1), MinWithFlag(v2, v3));
+    const float avgValue = weightSum > 0. ? 
+        (v0.y * v0.w + v1.y * v1.w + v2.y * v2.w + v3.y * v3.w) / weightSum :
+        0.;
+    const float maxValue = max(MaxWithFlag(v0, v1), MaxWithFlag(v2, v3));
+    const float weightValue =  weightSum * 0.25;
+    return AF4(minValue, avgValue, maxValue, weightValue);
+}
+
+#include <External/FidelityFX/ffx-spd/ffx_spd.h>
+
+[numthreads(256, 1, 1)]
+void MainCS(uint3 workGroupId : SV_GroupID, uint localThreadIndex : SV_GroupIndex)
+{
+    SpdDownsample(
+        AU2(workGroupId.xy), 
+        AU1(localThreadIndex),  
+        AU1(PassSrg::m_spdMipLevelCount),
+        AU1(PassSrg::m_numWorkGroups),
+        AU1(workGroupId.z),
+        AU2(0, 0));
+}

+ 28 - 0
Gems/Atom/Feature/Common/Assets/Shaders/PostProcessing/DownsampleSinglePassLuminance.shader

@@ -0,0 +1,28 @@
+{
+    "Source": "DownsampleSinglePassLuminance.azsl",
+
+    "ProgramSettings":
+    {
+      "EntryPoints":
+      [
+        {
+          "name": "MainCS",
+          "type": "Compute"
+        }
+      ]
+    },
+
+    "AddBuildArguments": { 
+      "dxc" : ["-fspv-target-env=vulkan1.1"] 
+    },
+
+    "Supervariants":
+    [
+        {
+            "Name": "NoWave",
+            "AddBuildArguments": {
+                "preprocessor": ["-DSPD_NO_WAVE_OPERATIONS"]
+            }
+        }
+    ]
+}

+ 3 - 0
Gems/Atom/Feature/Common/Assets/atom_feature_common_asset_files.cmake

@@ -80,6 +80,7 @@ set(FILES
     Passes/DownsampleLuminanceMinAvgMaxCS.pass
     Passes/DownsampleMinAvgMaxCS.pass
     Passes/DownsampleMipChain.pass
+    Passes/DownsampleSinglePassLuminance.pass
     Passes/EnvironmentCubeMapPipeline.pass
     Passes/EsmShadowmaps.pass
     Passes/EyeAdaptation.pass
@@ -478,6 +479,8 @@ set(FILES
     Shaders/PostProcessing/DownsampleLuminanceMinAvgMaxCS.shader
     Shaders/PostProcessing/DownsampleMinAvgMaxCS.azsl
     Shaders/PostProcessing/DownsampleMinAvgMaxCS.shader
+    Shaders/PostProcessing/DownsampleSinglePassLuminance.azsl
+    Shaders/PostProcessing/DownsampleSinglePassLuminance.shader
     Shaders/PostProcessing/EyeAdaptation.azsl
     Shaders/PostProcessing/EyeAdaptation.shader
     Shaders/PostProcessing/EyeAdaptationUtil.azsli

+ 3 - 0
Gems/Atom/RHI/Code/Include/Atom/RHI.Reflect/DeviceFeatures.h

@@ -92,6 +92,9 @@ namespace AZ
             //! Otherwise, the image is read by the CPU during scope execution (so it must not be modified by either CPU or GPU at that time).
             bool m_dynamicShadingRateImage = false;
             
+            //! Whether the adapter supports wave/subgroup operation
+            bool m_waveOperation = false;
+
             /// Additional features here.
         };
     }

+ 1 - 1
Gems/Atom/RHI/Code/Source/RHI/RHIUtils.cpp

@@ -22,7 +22,7 @@ namespace AZ
         Ptr<Device> GetRHIDevice()
         {
             RHISystemInterface* rhiSystem = RHISystemInterface::Get();
-            AZ_Assert(rhiSystem, "Failed to retrieve rpi system.");
+            AZ_Assert(rhiSystem, "Failed to retrieve rhi system.");
             return rhiSystem->GetDevice();
         }
 

+ 5 - 0
Gems/Atom/RHI/DX12/Code/Source/RHI/Device.cpp

@@ -157,6 +157,11 @@ namespace AZ
             // DX12's tile resource implementation uses undefined swizzle tile layout which only requires tier 1
             m_features.m_tiledResource = options.TiledResourcesTier >= D3D12_TILED_RESOURCES_TIER_1;
 
+            // Check support of wive operation
+            D3D12_FEATURE_DATA_SHADER_MODEL shaderModel;
+            GetDevice()->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel));
+            m_features.m_waveOperation = shaderModel.HighestShaderModel >= D3D_SHADER_MODEL_6_0;
+
 #ifdef AZ_DX12_DXR_SUPPORT
             D3D12_FEATURE_DATA_D3D12_OPTIONS5 options5;
             GetDevice()->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS5, &options5, sizeof(options5));

+ 3 - 0
Gems/Atom/RHI/Vulkan/Code/Source/RHI/Device.cpp

@@ -997,6 +997,9 @@ namespace AZ
                 && deviceProperties.sparseProperties.residencyStandard2DBlockShape
                 && deviceProperties.sparseProperties.residencyStandard3DBlockShape;
 
+            // Check if the Vulkan device support subgroup operations
+            m_features.m_waveOperation = physicalDevice.IsFeatureSupported(DeviceFeature::SubgroupOperation);
+
             // check for the VK_KHR_RAY_TRACING_PIPELINE_EXTENSION_NAME in the list of physical device extensions
             // to determine if ray tracing is supported on this device
             StringList deviceExtensions = physicalDevice.GetDeviceExtensionNames();

+ 1 - 0
Gems/Atom/RHI/Vulkan/Code/Source/RHI/PhysicalDevice.cpp

@@ -284,6 +284,7 @@ namespace AZ
                 (m_vulkan12Features.separateDepthStencilLayouts));
             m_features.set(static_cast<size_t>(DeviceFeature::DescriptorIndexing), VK_DEVICE_EXTENSION_SUPPORTED(context, EXT_descriptor_indexing));
             m_features.set(static_cast<size_t>(DeviceFeature::BufferDeviceAddress), VK_DEVICE_EXTENSION_SUPPORTED(context, EXT_buffer_device_address));
+            m_features.set(static_cast<size_t>(DeviceFeature::SubgroupOperation), (majorVersion >= 1 && minorVersion >= 1));
         }
 
         RawStringList PhysicalDevice::FilterSupportedOptionalExtensions()

+ 1 - 0
Gems/Atom/RHI/Vulkan/Code/Source/RHI/PhysicalDevice.h

@@ -33,6 +33,7 @@ namespace AZ
             SeparateDepthStencil,
             DescriptorIndexing,
             BufferDeviceAddress,
+            SubgroupOperation,
             Count // Must be last
         };
 

+ 19 - 0
Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/LICENSE

@@ -0,0 +1,19 @@
+Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 6 - 0
Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/PackageInfo.json

@@ -0,0 +1,6 @@
+{
+    "PackageName": "FidelityFX SPD",
+    "URL": "https://github.com/GPUOpen-Effects/FidelityFX-SPD",
+    "License": "MIT license",
+    "LicenseFile": "LICENSE"
+}

+ 1907 - 0
Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/ffx_a.h

@@ -0,0 +1,1907 @@
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//                                              [A] SHADER PORTABILITY 1.20190530
+//
+//==============================================================================================================================
+// LICENSE
+// =======
+// Copyright (c) 2017-2019 Advanced Micro Devices, Inc. All rights reserved.
+// Copyright (c) <2014> <Michal Drobot>
+// -------
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
+// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+// -------
+// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
+// Software.
+// -------
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR
+// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//------------------------------------------------------------------------------------------------------------------------------
+// ABOUT
+// =====
+// Common central point for high-level shading language and C portability for various shader headers.
+//------------------------------------------------------------------------------------------------------------------------------
+// DEFINES
+// =======
+// A_CPU ..... Include the CPU related code.
+// A_GPU ..... Include the GPU related code.
+// A_GLSL .... Using GLSL.
+// A_HLSL .... Using HLSL.
+// A_GCC ..... Using a GCC compatible compiler (else assume MSVC compatible compiler by default).
+// =======
+// A_BYTE .... Support 8-bit integer.
+// A_HALF .... Support 16-bit integer and floating point.
+// A_LONG .... Support 64-bit integer.
+// A_DUBL .... Support 64-bit floating point.
+// =======
+// A_WAVE .... Support wave-wide operations.
+//------------------------------------------------------------------------------------------------------------------------------
+// To get #include "ffx_a.h" working in GLSL use '#extension GL_GOOGLE_include_directive:require'.
+//------------------------------------------------------------------------------------------------------------------------------
+// SIMPLIFIED TYPE SYSTEM
+// ======================
+//  - All ints will be unsigned with exception of when signed is required.
+//  - Type naming simplified and shortened "A<type><#components>",
+//     - H = 16-bit float (half)
+//     - F = 32-bit float (float)
+//     - D = 64-bit float (double)
+//     - P = 1-bit integer (predicate, not using bool because 'B' is used for byte)
+//     - B = 8-bit integer (byte)
+//     - W = 16-bit integer (word)
+//     - U = 32-bit integer (unsigned)
+//     - L = 64-bit integer (long)
+//  - Using "AS<type><#components>" for signed when required.
+//------------------------------------------------------------------------------------------------------------------------------
+// TODO
+// ====
+//  - Make sure 'ALerp*(a,b,m)' does 'b*m+(-a*m+a)' (2 ops).
+//  - Add subgroup ops.
+//------------------------------------------------------------------------------------------------------------------------------
+// CHANGE LOG
+// ==========
+// 20190531 - Fixed changed to llabs() because long is int on Windows.
+// 20190530 - Updated for new CPU/GPU portability.
+// 20190528 - Fix AU1_AH2_x() on HLSL (had incorrectly swapped x and y), fixed asuint() cases.
+// 20190527 - Added min3/max3 for low precision for HLSL.
+// 20190526 - Updated with half approximations, added ARsq*(), and ASat*() for CPU.
+// 20190519 - Added more approximations.
+// 20190514 - Added long conversions.
+// 20190513 - Added the real BFI moved the other one to ABfiM().
+// 20190507 - Added extra remap useful for 2D reductions.
+// 20190507 - Started adding wave ops, add parabolic sin/cos.
+// 20190505 - Added ASigned*() and friends, setup more auto-typecast, GLSL extensions, etc.
+// 20190504 - Added min3/max3 for 32-bit integers.
+// 20190503 - Added type reinterpretation for half.
+// 20190416 - Added min3/max3 for half.
+// 20190405 - Misc bug fixing.
+// 20190404 - Cleaned up color conversion code. Switched "splat" to shorter naming "type_". Misc bug fixing.
+//==============================================================================================================================
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                           COMMON
+//==============================================================================================================================
+#define A_2PI 6.28318530718
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+//                                                             CPU
+//
+//
+//==============================================================================================================================
+// Requires standard C types: stdint.h
+// Requires a collection of standard math intrinsics.
+//  - Requires VS2013 when not using GCC to get exp2() and log2().
+//  - https://blogs.msdn.microsoft.com/vcblog/2013/07/19/c99-library-support-in-visual-studio-2013/
+//------------------------------------------------------------------------------------------------------------------------------
+// This provides a minimum subset of functionality compared to the GPU parts.
+//==============================================================================================================================
+#ifdef A_CPU
+ // Supporting user defined overrides.
+ #ifndef A_RESTRICT
+  #define A_RESTRICT __restrict
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifndef A_STATIC
+  #define A_STATIC static
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ // Same types across CPU and GPU.
+ // Predicate uses 32-bit integer (C friendly bool).
+ typedef uint32_t AP1;
+ typedef float AF1;
+ typedef double AD1;
+ typedef uint8_t AB1;
+ typedef uint16_t AW1;
+ typedef uint32_t AU1;
+ typedef uint64_t AL1;
+ typedef int8_t ASB1;
+ typedef int16_t ASW1;
+ typedef int32_t ASU1;
+ typedef int64_t ASL1;
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AD1_(a) ((AD1)(a))
+ #define AF1_(a) ((AF1)(a))
+ #define AL1_(a) ((AL1)(a))
+ #define AU1_(a) ((AU1)(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ASL1_(a) ((ASL1)(a))
+ #define ASU1_(a) ((ASU1)(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AU1 AU1_AF1(AF1 a){union{AF1 f;AU1 u;}bits;bits.f=a;return bits.u;}
+//------------------------------------------------------------------------------------------------------------------------------
+ #define A_TRUE 1
+ #define A_FALSE 0
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//                                                       CPU/GPU PORTING
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// Hackary to get CPU and GPU to share all setup code, without duplicate code paths.
+// Unfortunately this is the level of "ugly" that is required since the languages are very different.
+// This uses a lower-case prefix for special vector constructs.
+//  - In C restrict pointers are used.
+//  - In the shading language, in/inout/out arguments are used.
+// This depends on the ability to access a vector value in both languages via array syntax (aka color[2]).
+//==============================================================================================================================
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                     VECTOR ARGUMENT/RETURN/INITIALIZATION PORTABILITY
+//==============================================================================================================================
+ #define retAD2 AD1 *A_RESTRICT
+ #define retAD3 AD1 *A_RESTRICT
+ #define retAD4 AD1 *A_RESTRICT
+ #define retAF2 AF1 *A_RESTRICT
+ #define retAF3 AF1 *A_RESTRICT
+ #define retAF4 AF1 *A_RESTRICT
+ #define retAL2 AL1 *A_RESTRICT
+ #define retAL3 AL1 *A_RESTRICT
+ #define retAL4 AL1 *A_RESTRICT
+ #define retAU2 AU1 *A_RESTRICT
+ #define retAU3 AU1 *A_RESTRICT
+ #define retAU4 AU1 *A_RESTRICT
+//------------------------------------------------------------------------------------------------------------------------------
+ #define inAD2 AD1 *A_RESTRICT
+ #define inAD3 AD1 *A_RESTRICT
+ #define inAD4 AD1 *A_RESTRICT
+ #define inAF2 AF1 *A_RESTRICT
+ #define inAF3 AF1 *A_RESTRICT
+ #define inAF4 AF1 *A_RESTRICT
+ #define inAL2 AL1 *A_RESTRICT
+ #define inAL3 AL1 *A_RESTRICT
+ #define inAL4 AL1 *A_RESTRICT
+ #define inAU2 AU1 *A_RESTRICT
+ #define inAU3 AU1 *A_RESTRICT
+ #define inAU4 AU1 *A_RESTRICT
+//------------------------------------------------------------------------------------------------------------------------------
+ #define inoutAD2 AD1 *A_RESTRICT
+ #define inoutAD3 AD1 *A_RESTRICT
+ #define inoutAD4 AD1 *A_RESTRICT
+ #define inoutAF2 AF1 *A_RESTRICT
+ #define inoutAF3 AF1 *A_RESTRICT
+ #define inoutAF4 AF1 *A_RESTRICT
+ #define inoutAL2 AL1 *A_RESTRICT
+ #define inoutAL3 AL1 *A_RESTRICT
+ #define inoutAL4 AL1 *A_RESTRICT
+ #define inoutAU2 AU1 *A_RESTRICT
+ #define inoutAU3 AU1 *A_RESTRICT
+ #define inoutAU4 AU1 *A_RESTRICT
+//------------------------------------------------------------------------------------------------------------------------------
+ #define outAD2 AD1 *A_RESTRICT
+ #define outAD3 AD1 *A_RESTRICT
+ #define outAD4 AD1 *A_RESTRICT
+ #define outAF2 AF1 *A_RESTRICT
+ #define outAF3 AF1 *A_RESTRICT
+ #define outAF4 AF1 *A_RESTRICT
+ #define outAL2 AL1 *A_RESTRICT
+ #define outAL3 AL1 *A_RESTRICT
+ #define outAL4 AL1 *A_RESTRICT
+ #define outAU2 AU1 *A_RESTRICT
+ #define outAU3 AU1 *A_RESTRICT
+ #define outAU4 AU1 *A_RESTRICT
+//------------------------------------------------------------------------------------------------------------------------------
+ #define varAD2(x) AD1 x[2]
+ #define varAD3(x) AD1 x[3]
+ #define varAD4(x) AD1 x[4]
+ #define varAF2(x) AF1 x[2]
+ #define varAF3(x) AF1 x[3]
+ #define varAF4(x) AF1 x[4]
+ #define varAL2(x) AL1 x[2]
+ #define varAL3(x) AL1 x[3]
+ #define varAL4(x) AL1 x[4]
+ #define varAU2(x) AU1 x[2]
+ #define varAU3(x) AU1 x[3]
+ #define varAU4(x) AU1 x[4]
+//------------------------------------------------------------------------------------------------------------------------------
+ #define initAD2(x,y) {x,y}
+ #define initAD3(x,y,z) {x,y,z}
+ #define initAD4(x,y,z,w) {x,y,z,w}
+ #define initAF2(x,y) {x,y}
+ #define initAF3(x,y,z) {x,y,z}
+ #define initAF4(x,y,z,w) {x,y,z,w}
+ #define initAL2(x,y) {x,y}
+ #define initAL3(x,y,z) {x,y,z}
+ #define initAL4(x,y,z,w) {x,y,z,w}
+ #define initAU2(x,y) {x,y}
+ #define initAU3(x,y,z) {x,y,z}
+ #define initAU4(x,y,z,w) {x,y,z,w}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                     SCALAR RETURN OPS
+//------------------------------------------------------------------------------------------------------------------------------
+// TODO
+// ====
+//  - Replace transcendentals with manual versions. 
+//==============================================================================================================================
+ #ifdef A_GCC
+  A_STATIC AD1 AAbsD1(AD1 a){return __builtin_fabs(a);}
+  A_STATIC AF1 AAbsF1(AF1 a){return __builtin_fabsf(a);}
+  A_STATIC AU1 AAbsSU1(AU1 a){return AU1_(__builtin_abs(ASU1_(a)));}
+  A_STATIC AL1 AAbsSL1(AL1 a){return AL1_(__builtin_labs(ASL1_(a)));}
+ #else
+  A_STATIC AD1 AAbsD1(AD1 a){return fabs(a);}
+  A_STATIC AF1 AAbsF1(AF1 a){return fabsf(a);}
+  A_STATIC AU1 AAbsSU1(AU1 a){return AU1_(abs(ASU1_(a)));}
+  A_STATIC AL1 AAbsSL1(AL1 a){return AL1_(llabs(ASL1_(a)));}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 ACosD1(AD1 a){return __builtin_cos(a);}
+  A_STATIC AF1 ACosF1(AF1 a){return __builtin_cosf(a);}
+ #else
+  A_STATIC AD1 ACosD1(AD1 a){return cos(a);}
+  A_STATIC AF1 ACosF1(AF1 a){return cosf(a);}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 ADotD2(inAD2 a,inAD2 b){return a[0]*b[0]+a[1]*b[1];}
+ A_STATIC AD1 ADotD3(inAD3 a,inAD3 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];}
+ 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];}
+ A_STATIC AF1 ADotF2(inAF2 a,inAF2 b){return a[0]*b[0]+a[1]*b[1];}
+ A_STATIC AF1 ADotF3(inAF3 a,inAF3 b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];}
+ 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];}
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 AExp2D1(AD1 a){return __builtin_exp2(a);}
+  A_STATIC AF1 AExp2F1(AF1 a){return __builtin_exp2f(a);}
+ #else
+  A_STATIC AD1 AExp2D1(AD1 a){return exp2(a);}
+  A_STATIC AF1 AExp2F1(AF1 a){return exp2f(a);}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 AFloorD1(AD1 a){return __builtin_floor(a);}
+  A_STATIC AF1 AFloorF1(AF1 a){return __builtin_floorf(a);}
+ #else
+  A_STATIC AD1 AFloorD1(AD1 a){return floor(a);}
+  A_STATIC AF1 AFloorF1(AF1 a){return floorf(a);}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 ALerpD1(AD1 a,AD1 b,AD1 c){return b*c+(-a*c+a);}
+ A_STATIC AF1 ALerpF1(AF1 a,AF1 b,AF1 c){return b*c+(-a*c+a);}
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 ALog2D1(AD1 a){return __builtin_log2(a);}
+  A_STATIC AF1 ALog2F1(AF1 a){return __builtin_log2f(a);}
+ #else
+  A_STATIC AD1 ALog2D1(AD1 a){return log2(a);}
+  A_STATIC AF1 ALog2F1(AF1 a){return log2f(a);}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 AMaxD1(AD1 a,AD1 b){return a>b?a:b;}
+ A_STATIC AF1 AMaxF1(AF1 a,AF1 b){return a>b?a:b;}
+ A_STATIC AL1 AMaxL1(AL1 a,AL1 b){return a>b?a:b;}
+ A_STATIC AU1 AMaxU1(AU1 a,AU1 b){return a>b?a:b;}
+//------------------------------------------------------------------------------------------------------------------------------
+ // These follow the convention that A integer types don't have signage, until they are operated on. 
+ A_STATIC AL1 AMaxSL1(AL1 a,AL1 b){return (ASL1_(a)>ASL1_(b))?a:b;}
+ A_STATIC AU1 AMaxSU1(AU1 a,AU1 b){return (ASU1_(a)>ASU1_(b))?a:b;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 AMinD1(AD1 a,AD1 b){return a<b?a:b;}
+ A_STATIC AF1 AMinF1(AF1 a,AF1 b){return a<b?a:b;}
+ A_STATIC AL1 AMinL1(AL1 a,AL1 b){return a<b?a:b;}
+ A_STATIC AU1 AMinU1(AU1 a,AU1 b){return a<b?a:b;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AL1 AMinSL1(AL1 a,AL1 b){return (ASL1_(a)<ASL1_(b))?a:b;}
+ A_STATIC AU1 AMinSU1(AU1 a,AU1 b){return (ASU1_(a)<ASU1_(b))?a:b;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 ARcpD1(AD1 a){return 1.0/a;}
+ A_STATIC AF1 ARcpF1(AF1 a){return 1.0f/a;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AL1 AShrSL1(AL1 a,AL1 b){return AL1_(ASL1_(a)>>ASL1_(b));}
+ A_STATIC AU1 AShrSU1(AU1 a,AU1 b){return AU1_(ASU1_(a)>>ASU1_(b));}
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 ASinD1(AD1 a){return __builtin_sin(a);}
+  A_STATIC AF1 ASinF1(AF1 a){return __builtin_sinf(a);}
+ #else
+  A_STATIC AD1 ASinD1(AD1 a){return sin(a);}
+  A_STATIC AF1 ASinF1(AF1 a){return sinf(a);}
+ #endif
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_GCC
+  A_STATIC AD1 ASqrtD1(AD1 a){return __builtin_sqrt(a);}
+  A_STATIC AF1 ASqrtF1(AF1 a){return __builtin_sqrtf(a);}
+ #else
+  A_STATIC AD1 ASqrtD1(AD1 a){return sqrt(a);}
+  A_STATIC AF1 ASqrtF1(AF1 a){return sqrtf(a);}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                               SCALAR RETURN OPS - DEPENDENT
+//==============================================================================================================================
+ A_STATIC AD1 AFractD1(AD1 a){return a-AFloorD1(a);}
+ A_STATIC AF1 AFractF1(AF1 a){return a-AFloorF1(a);}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 APowD1(AD1 a,AD1 b){return AExp2D1(b*ALog2D1(a));}
+ A_STATIC AF1 APowF1(AF1 a,AF1 b){return AExp2F1(b*ALog2F1(a));}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 ARsqD1(AD1 a){return ARcpD1(ASqrtD1(a));}
+ A_STATIC AF1 ARsqF1(AF1 a){return ARcpF1(ASqrtF1(a));}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC AD1 ASatD1(AD1 a){return AMinD1(1.0,AMaxD1(0.0,a));}
+ A_STATIC AF1 ASatF1(AF1 a){return AMinF1(1.0f,AMaxF1(0.0f,a));}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         VECTOR OPS
+//------------------------------------------------------------------------------------------------------------------------------
+// These are added as needed for production or prototyping, so not necessarily a complete set.
+// They follow a convention of taking in a destination and also returning the destination value to increase utility.
+//==============================================================================================================================
+ A_STATIC retAD2 opAAbsD2(outAD2 d,inAD2 a){d[0]=AAbsD1(a[0]);d[1]=AAbsD1(a[1]);return d;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opAAbsF2(outAF2 d,inAF2 a){d[0]=AAbsF1(a[0]);d[1]=AAbsF1(a[1]);return d;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opAAddD2(outAD2 d,inAD2 a,inAD2 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];return d;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opAAddF2(outAF2 d,inAF2 a,inAF2 b){d[0]=a[0]+b[0];d[1]=a[1]+b[1];return d;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opACpyD2(outAD2 d,inAD2 a){d[0]=a[0];d[1]=a[1];return d;}
+ A_STATIC retAD3 opACpyD3(outAD3 d,inAD3 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];return d;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opACpyF2(outAF2 d,inAF2 a){d[0]=a[0];d[1]=a[1];return d;}
+ A_STATIC retAF3 opACpyF3(outAF3 d,inAF3 a){d[0]=a[0];d[1]=a[1];d[2]=a[2];return d;}
+ 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;}
+//==============================================================================================================================
+ 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;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ 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;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ 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;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ 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;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opAMulD2(outAD2 d,inAD2 a,inAD2 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];return d;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opAMulF2(outAF2 d,inAF2 a,inAF2 b){d[0]=a[0]*b[0];d[1]=a[1]*b[1];return d;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opAMulOneD2(outAD2 d,inAD2 a,AD1 b){d[0]=a[0]*b;d[1]=a[1]*b;return d;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opAMulOneF2(outAF2 d,inAF2 a,AF1 b){d[0]=a[0]*b;d[1]=a[1]*b;return d;}
+ 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;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opANegD2(outAD2 d,inAD2 a){d[0]=-a[0];d[1]=-a[1];return d;}
+ A_STATIC retAD3 opANegD3(outAD3 d,inAD3 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];return d;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opANegF2(outAF2 d,inAF2 a){d[0]=-a[0];d[1]=-a[1];return d;}
+ A_STATIC retAF3 opANegF3(outAF3 d,inAF3 a){d[0]=-a[0];d[1]=-a[1];d[2]=-a[2];return d;}
+ 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;}
+//==============================================================================================================================
+ A_STATIC retAD2 opARcpD2(outAD2 d,inAD2 a){d[0]=ARcpD1(a[0]);d[1]=ARcpD1(a[1]);return d;}
+ 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;}
+ 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;}
+//------------------------------------------------------------------------------------------------------------------------------
+ A_STATIC retAF2 opARcpF2(outAF2 d,inAF2 a){d[0]=ARcpF1(a[0]);d[1]=ARcpF1(a[1]);return d;}
+ 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;}
+ 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;}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                     HALF FLOAT PACKING
+//==============================================================================================================================
+ // Convert float to half (in lower 16-bits of output).
+ // Same fast technique as documented here: ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf
+ // Supports denormals.
+ // Conversion rules are to make computations possibly "safer" on the GPU,
+ //  -INF & -NaN -> -65504
+ //  +INF & +NaN -> +65504
+ A_STATIC AU1 AU1_AH1_AF1(AF1 f){
+  static AW1 base[512]={
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
+   0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,
+   0x0200,0x0400,0x0800,0x0c00,0x1000,0x1400,0x1800,0x1c00,0x2000,0x2400,0x2800,0x2c00,0x3000,0x3400,0x3800,0x3c00,
+   0x4000,0x4400,0x4800,0x4c00,0x5000,0x5400,0x5800,0x5c00,0x6000,0x6400,0x6800,0x6c00,0x7000,0x7400,0x7800,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,0x7bff,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,
+   0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8001,0x8002,0x8004,0x8008,0x8010,0x8020,0x8040,0x8080,0x8100,
+   0x8200,0x8400,0x8800,0x8c00,0x9000,0x9400,0x9800,0x9c00,0xa000,0xa400,0xa800,0xac00,0xb000,0xb400,0xb800,0xbc00,
+   0xc000,0xc400,0xc800,0xcc00,0xd000,0xd400,0xd800,0xdc00,0xe000,0xe400,0xe800,0xec00,0xf000,0xf400,0xf800,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,
+   0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff,0xfbff};
+  static AB1 shift[512]={
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,0x0f,
+   0x0e,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,
+   0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x17,0x16,0x15,0x14,0x13,0x12,0x11,0x10,0x0f,
+   0x0e,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,
+   0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x0d,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,
+   0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18};
+  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]);}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Used to output packed constant.
+ A_STATIC AU1 AU1_AH2_AF2(inAF2 a){return AU1_AH1_AF1(a[0])+(AU1_AH1_AF1(a[1])<<16);}
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+//                                                            GLSL
+//
+//
+//==============================================================================================================================
+#if defined(A_GLSL) && defined(A_GPU)
+ #ifndef A_SKIP_EXT
+  #ifdef A_HALF
+   #extension GL_EXT_shader_16bit_storage:require
+   #extension GL_EXT_shader_explicit_arithmetic_types:require 
+  #endif
+//------------------------------------------------------------------------------------------------------------------------------
+  #ifdef A_LONG
+   #extension GL_ARB_gpu_shader_int64:require
+   // TODO: Fixme to more portable extension!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+   #extension GL_NV_shader_atomic_int64:require
+  #endif
+//------------------------------------------------------------------------------------------------------------------------------
+  #ifdef A_WAVE
+   #extension GL_KHR_shader_subgroup_arithmetic:require
+   #extension GL_KHR_shader_subgroup_ballot:require
+   #extension GL_KHR_shader_subgroup_quad:require
+   #extension GL_KHR_shader_subgroup_shuffle:require
+  #endif
+ #endif
+//==============================================================================================================================
+ #define AP1 bool
+ #define AP2 bvec2
+ #define AP3 bvec3
+ #define AP4 bvec4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AF1 float
+ #define AF2 vec2
+ #define AF3 vec3
+ #define AF4 vec4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AU1 uint
+ #define AU2 uvec2
+ #define AU3 uvec3
+ #define AU4 uvec4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ASU1 int
+ #define ASU2 ivec2
+ #define ASU3 ivec3
+ #define ASU4 ivec4
+//==============================================================================================================================
+ #define AF1_AU1(x) uintBitsToFloat(AU1(x))
+ #define AF2_AU2(x) uintBitsToFloat(AU2(x))
+ #define AF3_AU3(x) uintBitsToFloat(AU3(x))
+ #define AF4_AU4(x) uintBitsToFloat(AU4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AU1_AF1(x) floatBitsToUint(AF1(x))
+ #define AU2_AF2(x) floatBitsToUint(AF2(x))
+ #define AU3_AF3(x) floatBitsToUint(AF3(x))
+ #define AU4_AF4(x) floatBitsToUint(AF4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AU1_AH2_AF2 packHalf2x16
+ #define AU1_AW2Unorm_AF2 packUnorm2x16
+ #define AU1_AB4Unorm_AF4 packUnorm4x8
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AF2_AH2_AU1 unpackHalf2x16
+ #define AF2_AW2Unorm_AU1 unpackUnorm2x16
+ #define AF4_AB4Unorm_AU1 unpackUnorm4x8
+//==============================================================================================================================
+ AF1 AF1_x(AF1 a){return AF1(a);}
+ AF2 AF2_x(AF1 a){return AF2(a,a);}
+ AF3 AF3_x(AF1 a){return AF3(a,a,a);}
+ AF4 AF4_x(AF1 a){return AF4(a,a,a,a);}
+ #define AF1_(a) AF1_x(AF1(a))
+ #define AF2_(a) AF2_x(AF1(a))
+ #define AF3_(a) AF3_x(AF1(a))
+ #define AF4_(a) AF4_x(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AU1_x(AU1 a){return AU1(a);}
+ AU2 AU2_x(AU1 a){return AU2(a,a);}
+ AU3 AU3_x(AU1 a){return AU3(a,a,a);}
+ AU4 AU4_x(AU1 a){return AU4(a,a,a,a);}
+ #define AU1_(a) AU1_x(AU1(a))
+ #define AU2_(a) AU2_x(AU1(a))
+ #define AU3_(a) AU3_x(AU1(a))
+ #define AU4_(a) AU4_x(AU1(a))
+//==============================================================================================================================
+ AU1 AAbsSU1(AU1 a){return AU1(abs(ASU1(a)));}
+ AU2 AAbsSU2(AU2 a){return AU2(abs(ASU2(a)));}
+ AU3 AAbsSU3(AU3 a){return AU3(abs(ASU3(a)));}
+ AU4 AAbsSU4(AU4 a){return AU4(abs(ASU4(a)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 ABfe(AU1 src,AU1 off,AU1 bits){return bitfieldExtract(src,ASU1(off),ASU1(bits));}
+ AU1 ABfi(AU1 src,AU1 ins,AU1 mask){return (ins&mask)|(src&(~mask));}
+ // Proxy for V_BFI_B32 where the 'mask' is set as 'bits', 'mask=(1<<bits)-1', and 'bits' needs to be an immediate.
+ AU1 ABfiM(AU1 src,AU1 ins,AU1 bits){return bitfieldInsert(src,ins,0,ASU1(bits));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // V_FRACT_F32 (note DX frac() is different).
+ AF1 AFractF1(AF1 x){return fract(x);}
+ AF2 AFractF2(AF2 x){return fract(x);}
+ AF3 AFractF3(AF3 x){return fract(x);}
+ AF4 AFractF4(AF4 x){return fract(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ALerpF1(AF1 x,AF1 y,AF1 a){return mix(x,y,a);}
+ AF2 ALerpF2(AF2 x,AF2 y,AF2 a){return mix(x,y,a);}
+ AF3 ALerpF3(AF3 x,AF3 y,AF3 a){return mix(x,y,a);}
+ AF4 ALerpF4(AF4 x,AF4 y,AF4 a){return mix(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+ // V_MAX3_F32.
+ AF1 AMax3F1(AF1 x,AF1 y,AF1 z){return max(x,max(y,z));}
+ AF2 AMax3F2(AF2 x,AF2 y,AF2 z){return max(x,max(y,z));}
+ AF3 AMax3F3(AF3 x,AF3 y,AF3 z){return max(x,max(y,z));}
+ AF4 AMax3F4(AF4 x,AF4 y,AF4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMax3SU1(AU1 x,AU1 y,AU1 z){return AU1(max(ASU1(x),max(ASU1(y),ASU1(z))));}
+ AU2 AMax3SU2(AU2 x,AU2 y,AU2 z){return AU2(max(ASU2(x),max(ASU2(y),ASU2(z))));}
+ AU3 AMax3SU3(AU3 x,AU3 y,AU3 z){return AU3(max(ASU3(x),max(ASU3(y),ASU3(z))));}
+ AU4 AMax3SU4(AU4 x,AU4 y,AU4 z){return AU4(max(ASU4(x),max(ASU4(y),ASU4(z))));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMax3U1(AU1 x,AU1 y,AU1 z){return max(x,max(y,z));}
+ AU2 AMax3U2(AU2 x,AU2 y,AU2 z){return max(x,max(y,z));}
+ AU3 AMax3U3(AU3 x,AU3 y,AU3 z){return max(x,max(y,z));}
+ AU4 AMax3U4(AU4 x,AU4 y,AU4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMaxSU1(AU1 a,AU1 b){return AU1(max(ASU1(a),ASU1(b)));}
+ AU2 AMaxSU2(AU2 a,AU2 b){return AU2(max(ASU2(a),ASU2(b)));}
+ AU3 AMaxSU3(AU3 a,AU3 b){return AU3(max(ASU3(a),ASU3(b)));}
+ AU4 AMaxSU4(AU4 a,AU4 b){return AU4(max(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Clamp has an easier pattern match for med3 when some ordering is known.
+ // V_MED3_F32.
+ AF1 AMed3F1(AF1 x,AF1 y,AF1 z){return max(min(x,y),min(max(x,y),z));}
+ AF2 AMed3F2(AF2 x,AF2 y,AF2 z){return max(min(x,y),min(max(x,y),z));}
+ AF3 AMed3F3(AF3 x,AF3 y,AF3 z){return max(min(x,y),min(max(x,y),z));}
+ AF4 AMed3F4(AF4 x,AF4 y,AF4 z){return max(min(x,y),min(max(x,y),z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // V_MIN3_F32.
+ AF1 AMin3F1(AF1 x,AF1 y,AF1 z){return min(x,min(y,z));}
+ AF2 AMin3F2(AF2 x,AF2 y,AF2 z){return min(x,min(y,z));}
+ AF3 AMin3F3(AF3 x,AF3 y,AF3 z){return min(x,min(y,z));}
+ AF4 AMin3F4(AF4 x,AF4 y,AF4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMin3SU1(AU1 x,AU1 y,AU1 z){return AU1(min(ASU1(x),min(ASU1(y),ASU1(z))));}
+ AU2 AMin3SU2(AU2 x,AU2 y,AU2 z){return AU2(min(ASU2(x),min(ASU2(y),ASU2(z))));}
+ AU3 AMin3SU3(AU3 x,AU3 y,AU3 z){return AU3(min(ASU3(x),min(ASU3(y),ASU3(z))));}
+ AU4 AMin3SU4(AU4 x,AU4 y,AU4 z){return AU4(min(ASU4(x),min(ASU4(y),ASU4(z))));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMin3U1(AU1 x,AU1 y,AU1 z){return min(x,min(y,z));}
+ AU2 AMin3U2(AU2 x,AU2 y,AU2 z){return min(x,min(y,z));}
+ AU3 AMin3U3(AU3 x,AU3 y,AU3 z){return min(x,min(y,z));}
+ AU4 AMin3U4(AU4 x,AU4 y,AU4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMinSU1(AU1 a,AU1 b){return AU1(min(ASU1(a),ASU1(b)));}
+ AU2 AMinSU2(AU2 a,AU2 b){return AU2(min(ASU2(a),ASU2(b)));}
+ AU3 AMinSU3(AU3 a,AU3 b){return AU3(min(ASU3(a),ASU3(b)));}
+ AU4 AMinSU4(AU4 a,AU4 b){return AU4(min(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Normalized trig. Valid input domain is {-256 to +256}. No GLSL compiler intrinsic exists to map to this currently.
+ // V_COS_F32.
+ AF1 ANCosF1(AF1 x){return cos(x*AF1_(A_2PI));}
+ AF2 ANCosF2(AF2 x){return cos(x*AF2_(A_2PI));}
+ AF3 ANCosF3(AF3 x){return cos(x*AF3_(A_2PI));}
+ AF4 ANCosF4(AF4 x){return cos(x*AF4_(A_2PI));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Normalized trig. Valid input domain is {-256 to +256}. No GLSL compiler intrinsic exists to map to this currently.
+ // V_SIN_F32.
+ AF1 ANSinF1(AF1 x){return sin(x*AF1_(A_2PI));}
+ AF2 ANSinF2(AF2 x){return sin(x*AF2_(A_2PI));}
+ AF3 ANSinF3(AF3 x){return sin(x*AF3_(A_2PI));}
+ AF4 ANSinF4(AF4 x){return sin(x*AF4_(A_2PI));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ARcpF1(AF1 x){return AF1_(1.0)/x;}
+ AF2 ARcpF2(AF2 x){return AF2_(1.0)/x;}
+ AF3 ARcpF3(AF3 x){return AF3_(1.0)/x;}
+ AF4 ARcpF4(AF4 x){return AF4_(1.0)/x;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ARsqF1(AF1 x){return AF1_(1.0)/sqrt(x);}
+ AF2 ARsqF2(AF2 x){return AF2_(1.0)/sqrt(x);}
+ AF3 ARsqF3(AF3 x){return AF3_(1.0)/sqrt(x);}
+ AF4 ARsqF4(AF4 x){return AF4_(1.0)/sqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ASatF1(AF1 x){return clamp(x,AF1_(0.0),AF1_(1.0));}
+ AF2 ASatF2(AF2 x){return clamp(x,AF2_(0.0),AF2_(1.0));}
+ AF3 ASatF3(AF3 x){return clamp(x,AF3_(0.0),AF3_(1.0));}
+ AF4 ASatF4(AF4 x){return clamp(x,AF4_(0.0),AF4_(1.0));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AShrSU1(AU1 a,AU1 b){return AU1(ASU1(a)>>ASU1(b));}
+ AU2 AShrSU2(AU2 a,AU2 b){return AU2(ASU2(a)>>ASU2(b));}
+ AU3 AShrSU3(AU3 a,AU3 b){return AU3(ASU3(a)>>ASU3(b));}
+ AU4 AShrSU4(AU4 a,AU4 b){return AU4(ASU4(a)>>ASU4(b));}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                          GLSL BYTE
+//==============================================================================================================================
+ #ifdef A_BYTE
+  #define AB1 uint8_t
+  #define AB2 u8vec2
+  #define AB3 u8vec3
+  #define AB4 u8vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define ASB1 int8_t
+  #define ASB2 i8vec2
+  #define ASB3 i8vec3
+  #define ASB4 i8vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  AB1 AB1_x(AB1 a){return AB1(a);}
+  AB2 AB2_x(AB1 a){return AB2(a,a);}
+  AB3 AB3_x(AB1 a){return AB3(a,a,a);}
+  AB4 AB4_x(AB1 a){return AB4(a,a,a,a);}
+  #define AB1_(a) AB1_x(AB1(a))
+  #define AB2_(a) AB2_x(AB1(a))
+  #define AB3_(a) AB3_x(AB1(a))
+  #define AB4_(a) AB4_x(AB1(a))
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                          GLSL HALF
+//==============================================================================================================================
+ #ifdef A_HALF
+  #define AH1 float16_t
+  #define AH2 f16vec2
+  #define AH3 f16vec3
+  #define AH4 f16vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define AW1 uint16_t
+  #define AW2 u16vec2
+  #define AW3 u16vec3
+  #define AW4 u16vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define ASW1 int16_t
+  #define ASW2 i16vec2
+  #define ASW3 i16vec3
+  #define ASW4 i16vec4
+//==============================================================================================================================
+  #define AH2_AU1(x) unpackFloat2x16(AU1(x))
+  AH4 AH4_AU2_x(AU2 x){return AH4(unpackFloat2x16(x.x),unpackFloat2x16(x.y));}
+  #define AH4_AU2(x) AH4_AU2_x(AU2(x))
+  #define AW2_AU1(x) unpackUint2x16(AU1(x))
+  #define AW4_AU2(x) unpackUint4x16(pack64(AU2(x)))
+//------------------------------------------------------------------------------------------------------------------------------
+  #define AU1_AH2(x) packFloat2x16(AH2(x))
+  AU2 AU2_AH4_x(AH4 x){return AU2(packFloat2x16(x.xy),packFloat2x16(x.zw));}
+  #define AU2_AH4(x) AU2_AH4_x(AH4(x))
+  #define AU1_AW2(x) packUint2x16(AW2(x))
+  #define AU2_AW4(x) unpack32(packUint4x16(AW4(x)))
+//==============================================================================================================================
+  #define AW1_AH1(x) halfBitsToUint16(AH1(x))
+  #define AW2_AH2(x) halfBitsToUint16(AH2(x))
+  #define AW3_AH3(x) halfBitsToUint16(AH3(x))
+  #define AW4_AH4(x) halfBitsToUint16(AH4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+  #define AH1_AW1(x) uint16BitsToHalf(AW1(x))
+  #define AH2_AW2(x) uint16BitsToHalf(AW2(x))
+  #define AH3_AW3(x) uint16BitsToHalf(AW3(x))
+  #define AH4_AW4(x) uint16BitsToHalf(AW4(x))
+//==============================================================================================================================
+  AH1 AH1_x(AH1 a){return AH1(a);}
+  AH2 AH2_x(AH1 a){return AH2(a,a);}
+  AH3 AH3_x(AH1 a){return AH3(a,a,a);}
+  AH4 AH4_x(AH1 a){return AH4(a,a,a,a);}
+  #define AH1_(a) AH1_x(AH1(a))
+  #define AH2_(a) AH2_x(AH1(a))
+  #define AH3_(a) AH3_x(AH1(a))
+  #define AH4_(a) AH4_x(AH1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AW1_x(AW1 a){return AW1(a);}
+  AW2 AW2_x(AW1 a){return AW2(a,a);}
+  AW3 AW3_x(AW1 a){return AW3(a,a,a);}
+  AW4 AW4_x(AW1 a){return AW4(a,a,a,a);}
+  #define AW1_(a) AW1_x(AW1(a))
+  #define AW2_(a) AW2_x(AW1(a))
+  #define AW3_(a) AW3_x(AW1(a))
+  #define AW4_(a) AW4_x(AW1(a))
+//==============================================================================================================================
+  AW1 AAbsSW1(AW1 a){return AW1(abs(ASW1(a)));}
+  AW2 AAbsSW2(AW2 a){return AW2(abs(ASW2(a)));}
+  AW3 AAbsSW3(AW3 a){return AW3(abs(ASW3(a)));}
+  AW4 AAbsSW4(AW4 a){return AW4(abs(ASW4(a)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 AFractH1(AH1 x){return fract(x);}
+  AH2 AFractH2(AH2 x){return fract(x);}
+  AH3 AFractH3(AH3 x){return fract(x);}
+  AH4 AFractH4(AH4 x){return fract(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ALerpH1(AH1 x,AH1 y,AH1 a){return mix(x,y,a);}
+  AH2 ALerpH2(AH2 x,AH2 y,AH2 a){return mix(x,y,a);}
+  AH3 ALerpH3(AH3 x,AH3 y,AH3 a){return mix(x,y,a);}
+  AH4 ALerpH4(AH4 x,AH4 y,AH4 a){return mix(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+  // No packed version of max3.
+  AH1 AMax3H1(AH1 x,AH1 y,AH1 z){return max(x,max(y,z));}
+  AH2 AMax3H2(AH2 x,AH2 y,AH2 z){return max(x,max(y,z));}
+  AH3 AMax3H3(AH3 x,AH3 y,AH3 z){return max(x,max(y,z));}
+  AH4 AMax3H4(AH4 x,AH4 y,AH4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AMaxSW1(AW1 a,AW1 b){return AW1(max(ASU1(a),ASU1(b)));}
+  AW2 AMaxSW2(AW2 a,AW2 b){return AW2(max(ASU2(a),ASU2(b)));}
+  AW3 AMaxSW3(AW3 a,AW3 b){return AW3(max(ASU3(a),ASU3(b)));}
+  AW4 AMaxSW4(AW4 a,AW4 b){return AW4(max(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  // No packed version of min3.
+  AH1 AMin3H1(AH1 x,AH1 y,AH1 z){return min(x,min(y,z));}
+  AH2 AMin3H2(AH2 x,AH2 y,AH2 z){return min(x,min(y,z));}
+  AH3 AMin3H3(AH3 x,AH3 y,AH3 z){return min(x,min(y,z));}
+  AH4 AMin3H4(AH4 x,AH4 y,AH4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AMinSW1(AW1 a,AW1 b){return AW1(min(ASU1(a),ASU1(b)));}
+  AW2 AMinSW2(AW2 a,AW2 b){return AW2(min(ASU2(a),ASU2(b)));}
+  AW3 AMinSW3(AW3 a,AW3 b){return AW3(min(ASU3(a),ASU3(b)));}
+  AW4 AMinSW4(AW4 a,AW4 b){return AW4(min(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ARcpH1(AH1 x){return AH1_(1.0)/x;}
+  AH2 ARcpH2(AH2 x){return AH2_(1.0)/x;}
+  AH3 ARcpH3(AH3 x){return AH3_(1.0)/x;}
+  AH4 ARcpH4(AH4 x){return AH4_(1.0)/x;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ARsqH1(AH1 x){return AH1_(1.0)/sqrt(x);}
+  AH2 ARsqH2(AH2 x){return AH2_(1.0)/sqrt(x);}
+  AH3 ARsqH3(AH3 x){return AH3_(1.0)/sqrt(x);}
+  AH4 ARsqH4(AH4 x){return AH4_(1.0)/sqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ASatH1(AH1 x){return clamp(x,AH1_(0.0),AH1_(1.0));}
+  AH2 ASatH2(AH2 x){return clamp(x,AH2_(0.0),AH2_(1.0));}
+  AH3 ASatH3(AH3 x){return clamp(x,AH3_(0.0),AH3_(1.0));}
+  AH4 ASatH4(AH4 x){return clamp(x,AH4_(0.0),AH4_(1.0));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AShrSW1(AW1 a,AW1 b){return AW1(ASW1(a)>>ASW1(b));}
+  AW2 AShrSW2(AW2 a,AW2 b){return AW2(ASW2(a)>>ASW2(b));}
+  AW3 AShrSW3(AW3 a,AW3 b){return AW3(ASW3(a)>>ASW3(b));}
+  AW4 AShrSW4(AW4 a,AW4 b){return AW4(ASW4(a)>>ASW4(b));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         GLSL DOUBLE
+//==============================================================================================================================
+ #ifdef A_DUBL
+  #define AD1 double
+  #define AD2 dvec2
+  #define AD3 dvec3
+  #define AD4 dvec4
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 AD1_x(AD1 a){return AD1(a);}
+  AD2 AD2_x(AD1 a){return AD2(a,a);}
+  AD3 AD3_x(AD1 a){return AD3(a,a,a);}
+  AD4 AD4_x(AD1 a){return AD4(a,a,a,a);}
+  #define AD1_(a) AD1_x(AD1(a))
+  #define AD2_(a) AD2_x(AD1(a))
+  #define AD3_(a) AD3_x(AD1(a))
+  #define AD4_(a) AD4_x(AD1(a))
+//==============================================================================================================================
+  AD1 AFractD1(AD1 x){return fract(x);}
+  AD2 AFractD2(AD2 x){return fract(x);}
+  AD3 AFractD3(AD3 x){return fract(x);}
+  AD4 AFractD4(AD4 x){return fract(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ALerpD1(AD1 x,AD1 y,AD1 a){return mix(x,y,a);}
+  AD2 ALerpD2(AD2 x,AD2 y,AD2 a){return mix(x,y,a);}
+  AD3 ALerpD3(AD3 x,AD3 y,AD3 a){return mix(x,y,a);}
+  AD4 ALerpD4(AD4 x,AD4 y,AD4 a){return mix(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ARcpD1(AD1 x){return AD1_(1.0)/x;}
+  AD2 ARcpD2(AD2 x){return AD2_(1.0)/x;}
+  AD3 ARcpD3(AD3 x){return AD3_(1.0)/x;}
+  AD4 ARcpD4(AD4 x){return AD4_(1.0)/x;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ARsqD1(AD1 x){return AD1_(1.0)/sqrt(x);}
+  AD2 ARsqD2(AD2 x){return AD2_(1.0)/sqrt(x);}
+  AD3 ARsqD3(AD3 x){return AD3_(1.0)/sqrt(x);}
+  AD4 ARsqD4(AD4 x){return AD4_(1.0)/sqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ASatD1(AD1 x){return clamp(x,AD1_(0.0),AD1_(1.0));}
+  AD2 ASatD2(AD2 x){return clamp(x,AD2_(0.0),AD2_(1.0));}
+  AD3 ASatD3(AD3 x){return clamp(x,AD3_(0.0),AD3_(1.0));}
+  AD4 ASatD4(AD4 x){return clamp(x,AD4_(0.0),AD4_(1.0));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         GLSL LONG
+//==============================================================================================================================
+ #ifdef A_LONG
+  #define AL1 uint64_t
+  #define AL2 u64vec2
+  #define AL3 u64vec3
+  #define AL4 u64vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define ASL1 int64_t
+  #define ASL2 i64vec2
+  #define ASL3 i64vec3
+  #define ASL4 i64vec4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define AL1_AU2(x) packUint2x32(AU2(x))
+  #define AU2_AL1(x) unpackUint2x32(AL1(x))
+//------------------------------------------------------------------------------------------------------------------------------
+  AL1 AL1_x(AL1 a){return AL1(a);}
+  AL2 AL2_x(AL1 a){return AL2(a,a);}
+  AL3 AL3_x(AL1 a){return AL3(a,a,a);}
+  AL4 AL4_x(AL1 a){return AL4(a,a,a,a);}
+  #define AL1_(a) AL1_x(AL1(a))
+  #define AL2_(a) AL2_x(AL1(a))
+  #define AL3_(a) AL3_x(AL1(a))
+  #define AL4_(a) AL4_x(AL1(a))
+//==============================================================================================================================
+  AL1 AAbsSL1(AL1 a){return AL1(abs(ASL1(a)));}
+  AL2 AAbsSL2(AL2 a){return AL2(abs(ASL2(a)));}
+  AL3 AAbsSL3(AL3 a){return AL3(abs(ASL3(a)));}
+  AL4 AAbsSL4(AL4 a){return AL4(abs(ASL4(a)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AL1 AMaxSL1(AL1 a,AL1 b){return AL1(max(ASU1(a),ASU1(b)));}
+  AL2 AMaxSL2(AL2 a,AL2 b){return AL2(max(ASU2(a),ASU2(b)));}
+  AL3 AMaxSL3(AL3 a,AL3 b){return AL3(max(ASU3(a),ASU3(b)));}
+  AL4 AMaxSL4(AL4 a,AL4 b){return AL4(max(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AL1 AMinSL1(AL1 a,AL1 b){return AL1(min(ASU1(a),ASU1(b)));}
+  AL2 AMinSL2(AL2 a,AL2 b){return AL2(min(ASU2(a),ASU2(b)));}
+  AL3 AMinSL3(AL3 a,AL3 b){return AL3(min(ASU3(a),ASU3(b)));}
+  AL4 AMinSL4(AL4 a,AL4 b){return AL4(min(ASU4(a),ASU4(b)));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                      WAVE OPERATIONS
+//==============================================================================================================================
+ #ifdef A_WAVE
+  AF1 AWaveAdd(AF1 v){return subgroupAdd(v);}
+  AF2 AWaveAdd(AF2 v){return subgroupAdd(v);}
+  AF3 AWaveAdd(AF3 v){return subgroupAdd(v);}
+  AF4 AWaveAdd(AF4 v){return subgroupAdd(v);}
+ #endif
+//==============================================================================================================================
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+//                                                            HLSL
+//
+//
+//==============================================================================================================================
+#if defined(A_HLSL) && defined(A_GPU)
+ #define AP1 bool
+ #define AP2 bool2
+ #define AP3 bool3
+ #define AP4 bool4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AF1 float
+ #define AF2 float2
+ #define AF3 float3
+ #define AF4 float4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AU1 uint
+ #define AU2 uint2
+ #define AU3 uint3
+ #define AU4 uint4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ASU1 int
+ #define ASU2 int2
+ #define ASU3 int3
+ #define ASU4 int4
+//==============================================================================================================================
+ #define AF1_AU1(x) asfloat(AU1(x))
+ #define AF2_AU2(x) asfloat(AU2(x))
+ #define AF3_AU3(x) asfloat(AU3(x))
+ #define AF4_AU4(x) asfloat(AU4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AU1_AF1(x) asuint(AF1(x))
+ #define AU2_AF2(x) asuint(AF2(x))
+ #define AU3_AF3(x) asuint(AF3(x))
+ #define AU4_AF4(x) asuint(AF4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AU1_AH2_AF2_x(AF2 a){return f32tof16(a.x)|(f32tof16(a.y)<<16);}
+ #define AU1_AH2_AF2(a) AU1_AH2_AF2_x(AF2(a)) 
+ #define AU1_AB4Unorm_AF4(x) D3DCOLORtoUBYTE4(AF4(x))
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 AF2_AH2_AU1_x(AU1 x){return AF2(f16tof32(x&0xFFFF),f16tof32(x>>16));}
+ #define AF2_AH2_AU1(x) AF2_AH2_AU1_x(AU1(x))
+//==============================================================================================================================
+ AF1 AF1_x(AF1 a){return AF1(a);}
+ AF2 AF2_x(AF1 a){return AF2(a,a);}
+ AF3 AF3_x(AF1 a){return AF3(a,a,a);}
+ AF4 AF4_x(AF1 a){return AF4(a,a,a,a);}
+ #define AF1_(a) AF1_x(AF1(a))
+ #define AF2_(a) AF2_x(AF1(a))
+ #define AF3_(a) AF3_x(AF1(a))
+ #define AF4_(a) AF4_x(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AU1_x(AU1 a){return AU1(a);}
+ AU2 AU2_x(AU1 a){return AU2(a,a);}
+ AU3 AU3_x(AU1 a){return AU3(a,a,a);}
+ AU4 AU4_x(AU1 a){return AU4(a,a,a,a);}
+ #define AU1_(a) AU1_x(AU1(a))
+ #define AU2_(a) AU2_x(AU1(a))
+ #define AU3_(a) AU3_x(AU1(a))
+ #define AU4_(a) AU4_x(AU1(a))
+//==============================================================================================================================
+ AU1 AAbsSU1(AU1 a){return AU1(abs(ASU1(a)));}
+ AU2 AAbsSU2(AU2 a){return AU2(abs(ASU2(a)));}
+ AU3 AAbsSU3(AU3 a){return AU3(abs(ASU3(a)));}
+ AU4 AAbsSU4(AU4 a){return AU4(abs(ASU4(a)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 ABfe(AU1 src,AU1 off,AU1 bits){AU1 mask=(1<<bits)-1;return (src>>off)&mask;}
+ AU1 ABfi(AU1 src,AU1 ins,AU1 mask){return (ins&mask)|(src&(~mask));}
+ AU1 ABfiM(AU1 src,AU1 ins,AU1 bits){AU1 mask=(1<<bits)-1;return (ins&mask)|(src&(~mask));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AFractF1(AF1 x){return x-floor(x);}
+ AF2 AFractF2(AF2 x){return x-floor(x);}
+ AF3 AFractF3(AF3 x){return x-floor(x);}
+ AF4 AFractF4(AF4 x){return x-floor(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ALerpF1(AF1 x,AF1 y,AF1 a){return lerp(x,y,a);}
+ AF2 ALerpF2(AF2 x,AF2 y,AF2 a){return lerp(x,y,a);}
+ AF3 ALerpF3(AF3 x,AF3 y,AF3 a){return lerp(x,y,a);}
+ AF4 ALerpF4(AF4 x,AF4 y,AF4 a){return lerp(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AMax3F1(AF1 x,AF1 y,AF1 z){return max(x,max(y,z));}
+ AF2 AMax3F2(AF2 x,AF2 y,AF2 z){return max(x,max(y,z));}
+ AF3 AMax3F3(AF3 x,AF3 y,AF3 z){return max(x,max(y,z));}
+ AF4 AMax3F4(AF4 x,AF4 y,AF4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMax3SU1(AU1 x,AU1 y,AU1 z){return AU1(max(ASU1(x),max(ASU1(y),ASU1(z))));}
+ AU2 AMax3SU2(AU2 x,AU2 y,AU2 z){return AU2(max(ASU2(x),max(ASU2(y),ASU2(z))));}
+ AU3 AMax3SU3(AU3 x,AU3 y,AU3 z){return AU3(max(ASU3(x),max(ASU3(y),ASU3(z))));}
+ AU4 AMax3SU4(AU4 x,AU4 y,AU4 z){return AU4(max(ASU4(x),max(ASU4(y),ASU4(z))));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMax3U1(AU1 x,AU1 y,AU1 z){return max(x,max(y,z));}
+ AU2 AMax3U2(AU2 x,AU2 y,AU2 z){return max(x,max(y,z));}
+ AU3 AMax3U3(AU3 x,AU3 y,AU3 z){return max(x,max(y,z));}
+ AU4 AMax3U4(AU4 x,AU4 y,AU4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMaxSU1(AU1 a,AU1 b){return AU1(max(ASU1(a),ASU1(b)));}
+ AU2 AMaxSU2(AU2 a,AU2 b){return AU2(max(ASU2(a),ASU2(b)));}
+ AU3 AMaxSU3(AU3 a,AU3 b){return AU3(max(ASU3(a),ASU3(b)));}
+ AU4 AMaxSU4(AU4 a,AU4 b){return AU4(max(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AMed3F1(AF1 x,AF1 y,AF1 z){return max(min(x,y),min(max(x,y),z));}
+ AF2 AMed3F2(AF2 x,AF2 y,AF2 z){return max(min(x,y),min(max(x,y),z));}
+ AF3 AMed3F3(AF3 x,AF3 y,AF3 z){return max(min(x,y),min(max(x,y),z));}
+ AF4 AMed3F4(AF4 x,AF4 y,AF4 z){return max(min(x,y),min(max(x,y),z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AMin3F1(AF1 x,AF1 y,AF1 z){return min(x,min(y,z));}
+ AF2 AMin3F2(AF2 x,AF2 y,AF2 z){return min(x,min(y,z));}
+ AF3 AMin3F3(AF3 x,AF3 y,AF3 z){return min(x,min(y,z));}
+ AF4 AMin3F4(AF4 x,AF4 y,AF4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMin3SU1(AU1 x,AU1 y,AU1 z){return AU1(min(ASU1(x),min(ASU1(y),ASU1(z))));}
+ AU2 AMin3SU2(AU2 x,AU2 y,AU2 z){return AU2(min(ASU2(x),min(ASU2(y),ASU2(z))));}
+ AU3 AMin3SU3(AU3 x,AU3 y,AU3 z){return AU3(min(ASU3(x),min(ASU3(y),ASU3(z))));}
+ AU4 AMin3SU4(AU4 x,AU4 y,AU4 z){return AU4(min(ASU4(x),min(ASU4(y),ASU4(z))));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMin3U1(AU1 x,AU1 y,AU1 z){return min(x,min(y,z));}
+ AU2 AMin3U2(AU2 x,AU2 y,AU2 z){return min(x,min(y,z));}
+ AU3 AMin3U3(AU3 x,AU3 y,AU3 z){return min(x,min(y,z));}
+ AU4 AMin3U4(AU4 x,AU4 y,AU4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AMinSU1(AU1 a,AU1 b){return AU1(min(ASU1(a),ASU1(b)));}
+ AU2 AMinSU2(AU2 a,AU2 b){return AU2(min(ASU2(a),ASU2(b)));}
+ AU3 AMinSU3(AU3 a,AU3 b){return AU3(min(ASU3(a),ASU3(b)));}
+ AU4 AMinSU4(AU4 a,AU4 b){return AU4(min(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ANCosF1(AF1 x){return cos(x*AF1_(A_2PI));}
+ AF2 ANCosF2(AF2 x){return cos(x*AF2_(A_2PI));}
+ AF3 ANCosF3(AF3 x){return cos(x*AF3_(A_2PI));}
+ AF4 ANCosF4(AF4 x){return cos(x*AF4_(A_2PI));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ANSinF1(AF1 x){return sin(x*AF1_(A_2PI));}
+ AF2 ANSinF2(AF2 x){return sin(x*AF2_(A_2PI));}
+ AF3 ANSinF3(AF3 x){return sin(x*AF3_(A_2PI));}
+ AF4 ANSinF4(AF4 x){return sin(x*AF4_(A_2PI));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ARcpF1(AF1 x){return rcp(x);}
+ AF2 ARcpF2(AF2 x){return rcp(x);}
+ AF3 ARcpF3(AF3 x){return rcp(x);}
+ AF4 ARcpF4(AF4 x){return rcp(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ARsqF1(AF1 x){return rsqrt(x);}
+ AF2 ARsqF2(AF2 x){return rsqrt(x);}
+ AF3 ARsqF3(AF3 x){return rsqrt(x);}
+ AF4 ARsqF4(AF4 x){return rsqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 ASatF1(AF1 x){return saturate(x);}
+ AF2 ASatF2(AF2 x){return saturate(x);}
+ AF3 ASatF3(AF3 x){return saturate(x);}
+ AF4 ASatF4(AF4 x){return saturate(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+ AU1 AShrSU1(AU1 a,AU1 b){return AU1(ASU1(a)>>ASU1(b));}
+ AU2 AShrSU2(AU2 a,AU2 b){return AU2(ASU2(a)>>ASU2(b));}
+ AU3 AShrSU3(AU3 a,AU3 b){return AU3(ASU3(a)>>ASU3(b));}
+ AU4 AShrSU4(AU4 a,AU4 b){return AU4(ASU4(a)>>ASU4(b));}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                          HLSL BYTE
+//==============================================================================================================================
+ #ifdef A_BYTE
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                          HLSL HALF
+//==============================================================================================================================
+ #ifdef A_HALF
+  #define AH1 min16float
+  #define AH2 min16float2
+  #define AH3 min16float3
+  #define AH4 min16float4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define AW1 min16uint
+  #define AW2 min16uint2
+  #define AW3 min16uint3
+  #define AW4 min16uint4
+//------------------------------------------------------------------------------------------------------------------------------
+  #define ASW1 min16int
+  #define ASW2 min16int2
+  #define ASW3 min16int3
+  #define ASW4 min16int4
+//==============================================================================================================================
+  // Need to use manual unpack to get optimal execution (don't use packed types in buffers directly).
+  // Unpack requires this pattern: https://gpuopen.com/first-steps-implementing-fp16/
+  AH2 AH2_AU1_x(AU1 x){AF2 t=f16tof32(AU2(x&0xFFFF,x>>16));return AH2(t);}
+  AH4 AH4_AU2_x(AU2 x){return AH4(AH2_AU1_x(x.x),AH2_AU1_x(x.y));}
+  AW2 AW2_AU1_x(AU1 x){AU2 t=AU2(x&0xFFFF,x>>16);return AW2(t);}
+  AW4 AW4_AU2_x(AU2 x){return AW4(AW2_AU1_x(x.x),AW2_AU1_x(x.y));}
+  #define AH2_AU1(x) AH2_AU1_x(AU1(x))
+  #define AH4_AU2(x) AH4_AU2_x(AU2(x))
+  #define AW2_AU1(x) AW2_AU1_x(AU1(x))
+  #define AW4_AU2(x) AW4_AU2_x(AU2(x))
+//------------------------------------------------------------------------------------------------------------------------------
+  AU1 AU1_AH2_x(AH2 x){return f32tof16(x.x)+(f32tof16(x.y)<<16);}
+  AU2 AU2_AH4_x(AH4 x){return AU2(AU1_AH2_x(x.xy),AU1_AH2_x(x.zw));}
+  AU1 AU1_AW2_x(AW2 x){return AU1(x.x)+(AU1(x.y)<<16);}
+  AU2 AU2_AW4_x(AW4 x){return AU2(AU1_AW2_x(x.xy),AU1_AW2_x(x.zw));}
+  #define AU1_AH2(x) AU1_AH2_x(AH2(x))
+  #define AU2_AH4(x) AU2_AH4_x(AH4(x))
+  #define AU1_AW2(x) AU1_AW2_x(AW2(x))
+  #define AU2_AW4(x) AU2_AW4_x(AW4(x))
+//==============================================================================================================================
+  // TODO: These are broken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  #define AW1_AH1(x) AW1(asuint(AF1(x)))
+  #define AW2_AH2(x) AW2(asuint(AF2(x)))
+  #define AW3_AH3(x) AW3(asuint(AF3(x)))
+  #define AW4_AH4(x) AW4(asuint(AF4(x)))
+//------------------------------------------------------------------------------------------------------------------------------
+  // TODO: These are broken!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+  #define AH1_AW1(x) AH1(asfloat(AU1(x)))
+  #define AH2_AW2(x) AH2(asfloat(AU2(x)))
+  #define AH3_AW3(x) AH3(asfloat(AU3(x)))
+  #define AH4_AW4(x) AH4(asfloat(AU4(x)))
+//==============================================================================================================================
+  AH1 AH1_x(AH1 a){return AH1(a);}
+  AH2 AH2_x(AH1 a){return AH2(a,a);}
+  AH3 AH3_x(AH1 a){return AH3(a,a,a);}
+  AH4 AH4_x(AH1 a){return AH4(a,a,a,a);}
+  #define AH1_(a) AH1_x(AH1(a))
+  #define AH2_(a) AH2_x(AH1(a))
+  #define AH3_(a) AH3_x(AH1(a))
+  #define AH4_(a) AH4_x(AH1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AW1_x(AW1 a){return AW1(a);}
+  AW2 AW2_x(AW1 a){return AW2(a,a);}
+  AW3 AW3_x(AW1 a){return AW3(a,a,a);}
+  AW4 AW4_x(AW1 a){return AW4(a,a,a,a);}
+  #define AW1_(a) AW1_x(AW1(a))
+  #define AW2_(a) AW2_x(AW1(a))
+  #define AW3_(a) AW3_x(AW1(a))
+  #define AW4_(a) AW4_x(AW1(a))
+//==============================================================================================================================
+  AW1 AAbsSW1(AW1 a){return AW1(abs(ASW1(a)));}
+  AW2 AAbsSW2(AW2 a){return AW2(abs(ASW2(a)));}
+  AW3 AAbsSW3(AW3 a){return AW3(abs(ASW3(a)));}
+  AW4 AAbsSW4(AW4 a){return AW4(abs(ASW4(a)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // V_FRACT_F16 (note DX frac() is different).
+  AH1 AFractH1(AH1 x){return x-floor(x);}
+  AH2 AFractH2(AH2 x){return x-floor(x);}
+  AH3 AFractH3(AH3 x){return x-floor(x);}
+  AH4 AFractH4(AH4 x){return x-floor(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ALerpH1(AH1 x,AH1 y,AH1 a){return lerp(x,y,a);}
+  AH2 ALerpH2(AH2 x,AH2 y,AH2 a){return lerp(x,y,a);}
+  AH3 ALerpH3(AH3 x,AH3 y,AH3 a){return lerp(x,y,a);}
+  AH4 ALerpH4(AH4 x,AH4 y,AH4 a){return lerp(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 AMax3H1(AH1 x,AH1 y,AH1 z){return max(x,max(y,z));}
+  AH2 AMax3H2(AH2 x,AH2 y,AH2 z){return max(x,max(y,z));}
+  AH3 AMax3H3(AH3 x,AH3 y,AH3 z){return max(x,max(y,z));}
+  AH4 AMax3H4(AH4 x,AH4 y,AH4 z){return max(x,max(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AMaxSW1(AW1 a,AW1 b){return AW1(max(ASU1(a),ASU1(b)));}
+  AW2 AMaxSW2(AW2 a,AW2 b){return AW2(max(ASU2(a),ASU2(b)));}
+  AW3 AMaxSW3(AW3 a,AW3 b){return AW3(max(ASU3(a),ASU3(b)));}
+  AW4 AMaxSW4(AW4 a,AW4 b){return AW4(max(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 AMin3H1(AH1 x,AH1 y,AH1 z){return min(x,min(y,z));}
+  AH2 AMin3H2(AH2 x,AH2 y,AH2 z){return min(x,min(y,z));}
+  AH3 AMin3H3(AH3 x,AH3 y,AH3 z){return min(x,min(y,z));}
+  AH4 AMin3H4(AH4 x,AH4 y,AH4 z){return min(x,min(y,z));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AMinSW1(AW1 a,AW1 b){return AW1(min(ASU1(a),ASU1(b)));}
+  AW2 AMinSW2(AW2 a,AW2 b){return AW2(min(ASU2(a),ASU2(b)));}
+  AW3 AMinSW3(AW3 a,AW3 b){return AW3(min(ASU3(a),ASU3(b)));}
+  AW4 AMinSW4(AW4 a,AW4 b){return AW4(min(ASU4(a),ASU4(b)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ARcpH1(AH1 x){return rcp(x);}
+  AH2 ARcpH2(AH2 x){return rcp(x);}
+  AH3 ARcpH3(AH3 x){return rcp(x);}
+  AH4 ARcpH4(AH4 x){return rcp(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ARsqH1(AH1 x){return rsqrt(x);}
+  AH2 ARsqH2(AH2 x){return rsqrt(x);}
+  AH3 ARsqH3(AH3 x){return rsqrt(x);}
+  AH4 ARsqH4(AH4 x){return rsqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ASatH1(AH1 x){return saturate(x);}
+  AH2 ASatH2(AH2 x){return saturate(x);}
+  AH3 ASatH3(AH3 x){return saturate(x);}
+  AH4 ASatH4(AH4 x){return saturate(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AW1 AShrSW1(AW1 a,AW1 b){return AW1(ASW1(a)>>ASW1(b));}
+  AW2 AShrSW2(AW2 a,AW2 b){return AW2(ASW2(a)>>ASW2(b));}
+  AW3 AShrSW3(AW3 a,AW3 b){return AW3(ASW3(a)>>ASW3(b));}
+  AW4 AShrSW4(AW4 a,AW4 b){return AW4(ASW4(a)>>ASW4(b));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         HLSL DOUBLE
+//==============================================================================================================================
+ #ifdef A_DUBL
+  #define AD1 double
+  #define AD2 double2
+  #define AD3 double3
+  #define AD4 double4
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 AD1_x(AD1 a){return AD1(a);}
+  AD2 AD2_x(AD1 a){return AD2(a,a);}
+  AD3 AD3_x(AD1 a){return AD3(a,a,a);}
+  AD4 AD4_x(AD1 a){return AD4(a,a,a,a);}
+  #define AD1_(a) AD1_x(AD1(a))
+  #define AD2_(a) AD2_x(AD1(a))
+  #define AD3_(a) AD3_x(AD1(a))
+  #define AD4_(a) AD4_x(AD1(a))
+//==============================================================================================================================
+  AD1 AFractD1(AD1 a){return a-floor(a);}
+  AD2 AFractD2(AD2 a){return a-floor(a);}
+  AD3 AFractD3(AD3 a){return a-floor(a);}
+  AD4 AFractD4(AD4 a){return a-floor(a);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ALerpD1(AD1 x,AD1 y,AD1 a){return lerp(x,y,a);}
+  AD2 ALerpD2(AD2 x,AD2 y,AD2 a){return lerp(x,y,a);}
+  AD3 ALerpD3(AD3 x,AD3 y,AD3 a){return lerp(x,y,a);}
+  AD4 ALerpD4(AD4 x,AD4 y,AD4 a){return lerp(x,y,a);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ARcpD1(AD1 x){return rcp(x);}
+  AD2 ARcpD2(AD2 x){return rcp(x);}
+  AD3 ARcpD3(AD3 x){return rcp(x);}
+  AD4 ARcpD4(AD4 x){return rcp(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ARsqD1(AD1 x){return rsqrt(x);}
+  AD2 ARsqD2(AD2 x){return rsqrt(x);}
+  AD3 ARsqD3(AD3 x){return rsqrt(x);}
+  AD4 ARsqD4(AD4 x){return rsqrt(x);}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD1 ASatD1(AD1 x){return saturate(x);}
+  AD2 ASatD2(AD2 x){return saturate(x);}
+  AD3 ASatD3(AD3 x){return saturate(x);}
+  AD4 ASatD4(AD4 x){return saturate(x);}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         HLSL LONG
+//==============================================================================================================================
+ #ifdef A_LONG
+ #endif
+//==============================================================================================================================
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+//                                                          GPU COMMON
+//
+//
+//==============================================================================================================================
+#ifdef A_GPU
+ // Negative and positive infinity.
+ #define A_INFN_F AF1_AU1(0x7f800000u)
+ #define A_INFP_F AF1_AU1(0xff800000u)
+//------------------------------------------------------------------------------------------------------------------------------
+ // Copy sign from 's' to positive 'd'.
+ AF1 ACpySgnF1(AF1 d,AF1 s){return AF1_AU1(AU1_AF1(d)|(AU1_AF1(s)&AU1_(0x80000000u)));}
+ AF2 ACpySgnF2(AF2 d,AF2 s){return AF2_AU2(AU2_AF2(d)|(AU2_AF2(s)&AU2_(0x80000000u)));}
+ AF3 ACpySgnF3(AF3 d,AF3 s){return AF3_AU3(AU3_AF3(d)|(AU3_AF3(s)&AU3_(0x80000000u)));}
+ AF4 ACpySgnF4(AF4 d,AF4 s){return AF4_AU4(AU4_AF4(d)|(AU4_AF4(s)&AU4_(0x80000000u)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Single operation to return (useful to create a mask to use in lerp for branch free logic),
+ //  m=NaN := 0
+ //  m>=0  := 0
+ //  m<0   := 1
+ // Uses the following useful floating point logic,
+ //  saturate(+a*(-INF)==-INF) := 0
+ //  saturate( 0*(-INF)== NaN) := 0
+ //  saturate(-a*(-INF)==+INF) := 1
+ AF1 ASignedF1(AF1 m){return ASatF1(m*AF1_(A_INFN_F));}
+ AF2 ASignedF2(AF2 m){return ASatF2(m*AF2_(A_INFN_F));}
+ AF3 ASignedF3(AF3 m){return ASatF3(m*AF3_(A_INFN_F));}
+ AF4 ASignedF4(AF4 m){return ASatF4(m*AF4_(A_INFN_F));}
+//==============================================================================================================================
+ #ifdef A_HALF
+  #define A_INFN_H AH1_AW1(0x7c00u)
+  #define A_INFP_H AH1_AW1(0xfc00u)
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ACpySgnH1(AH1 d,AH1 s){return AH1_AW1(AW1_AH1(d)|(AW1_AH1(s)&AW1_(0x8000u)));}
+  AH2 ACpySgnH2(AH2 d,AH2 s){return AH2_AW2(AW2_AH2(d)|(AW2_AH2(s)&AW2_(0x8000u)));}
+  AH3 ACpySgnH3(AH3 d,AH3 s){return AH3_AW3(AW3_AH3(d)|(AW3_AH3(s)&AW3_(0x8000u)));}
+  AH4 ACpySgnH4(AH4 d,AH4 s){return AH4_AW4(AW4_AH4(d)|(AW4_AH4(s)&AW4_(0x8000u)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH1 ASignedH1(AH1 m){return ASatH1(m*AH1_(A_INFN_H));}
+  AH2 ASignedH2(AH2 m){return ASatH2(m*AH2_(A_INFN_H));}
+  AH3 ASignedH3(AH3 m){return ASatH3(m*AH3_(A_INFN_H));}
+  AH4 ASignedH4(AH4 m){return ASatH4(m*AH4_(A_INFN_H));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                     HALF APPROXIMATIONS
+//------------------------------------------------------------------------------------------------------------------------------
+// These support only positive inputs.
+// Did not see value yet in specialization for range.
+// Using quick testing, ended up mostly getting the same "best" approximation for various ranges.
+// With hardware that can co-execute transcendentals, the value in approximations could be less than expected.
+// However from a latency perspective, if execution of a transcendental is 4 clk, with no packed support, -> 8 clk total.
+// And co-execution would require a compiler interleaving a lot of independent work for packed usage.
+//------------------------------------------------------------------------------------------------------------------------------
+// The one Newton Raphson iteration form of rsq() was skipped (requires 6 ops total).
+// Same with sqrt(), as this could be x*rsq() (7 ops).
+//------------------------------------------------------------------------------------------------------------------------------
+// IDEAS
+// =====
+//  - Polaris hardware has 16-bit support, but non-double rate.
+//    Could be possible still get part double rate for some of this logic, 
+//    by clearing out the lower half's sign when necessary and using 32-bit ops...
+//==============================================================================================================================
+ #ifdef A_HALF
+  // Minimize squared error across full positive range, 2 ops.
+  // The 0x1de2 based approximation maps {0 to 1} input maps to < 1 output.
+  AH1 APrxLoSqrtH1(AH1 a){return AH1_AW1((AW1_AH1(a)>>AW1_(1))+AW1_(0x1de2));}
+  AH2 APrxLoSqrtH2(AH2 a){return AH2_AW2((AW2_AH2(a)>>AW2_(1))+AW2_(0x1de2));}
+//------------------------------------------------------------------------------------------------------------------------------
+  // Lower precision estimation, 1 op.
+  // Minimize squared error across {smallest normal to 16384.0}.
+  AH1 APrxLoRcpH1(AH1 a){return AH1_AW1(AW1_(0x7784)-AW1_AH1(a));}
+  AH2 APrxLoRcpH2(AH2 a){return AH2_AW2(AW2_(0x7784)-AW2_AH2(a));}
+//------------------------------------------------------------------------------------------------------------------------------
+  // Medium precision estimation, one Newton Raphson iteration, 3 ops.
+  AH1 APrxMedRcpH1(AH1 a){AH1 b=AH1_AW1(AW1_(0x778d)-AW1_AH1(a));return b*(-b*a+AH1_(2.0));}
+  AH2 APrxMedRcpH2(AH2 a){AH2 b=AH2_AW2(AW2_(0x778d)-AW2_AH2(a));return b*(-b*a+AH2_(2.0));}
+//------------------------------------------------------------------------------------------------------------------------------
+  // Minimize squared error across {smallest normal to 16384.0}, 2 ops.
+  AH1 APrxLoRsqH1(AH1 a){return AH1_AW1(AW1_(0x59a3)-(AW1_AH1(a)>>AW1_(1)));}
+  AH2 APrxLoRsqH2(AH2 a){return AH2_AW2(AW2_(0x59a3)-(AW2_AH2(a)>>AW2_(1)));}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                    FLOAT APPROXIMATIONS
+//------------------------------------------------------------------------------------------------------------------------------
+// Michal Drobot has an excellent presentation on these: "Low Level Optimizations For GCN",
+//  - Idea dates back to SGI, then to Quake 3, etc.
+//  - https://michaldrobot.files.wordpress.com/2014/05/gcn_alu_opt_digitaldragons2014.pdf
+//     - sqrt(x)=rsqrt(x)*x
+//     - rcp(x)=rsqrt(x)*rsqrt(x) for positive x
+//  - https://github.com/michaldrobot/ShaderFastLibs/blob/master/ShaderFastMathLib.h
+//------------------------------------------------------------------------------------------------------------------------------
+// These below are from perhaps less complete searching for optimal.
+// Used FP16 normal range for testing with +4096 32-bit step size for sampling error.
+// So these match up well with the half approximations.
+//==============================================================================================================================
+ AF1 APrxLoSqrtF1(AF1 a){return AF1_AU1((AU1_AF1(a)>>AU1_(1))+AU1_(0x1fbc4639));}
+ AF1 APrxLoRcpF1(AF1 a){return AF1_AU1(AU1_(0x7ef07ebb)-AU1_AF1(a));}
+ AF1 APrxMedRcpF1(AF1 a){AF1 b=AF1_AU1(AU1_(0x7ef19fff)-AU1_AF1(a));return b*(-b*a+AF1_(2.0));}
+ AF1 APrxLoRsqF1(AF1 a){return AF1_AU1(AU1_(0x5f347d74)-(AU1_AF1(a)>>AU1_(1)));}
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                    PARABOLIC SIN & COS
+//------------------------------------------------------------------------------------------------------------------------------
+// Approximate answers to transcendental questions.
+//------------------------------------------------------------------------------------------------------------------------------
+// TODO
+// ====
+//  - Verify packed math ABS is correctly doing an AND.
+//==============================================================================================================================
+ // Valid input range is {-1 to 1} representing {0 to 2 pi}.
+ // Output range is {-1/4 to -1/4} representing {-1 to 1}.
+ AF1 APSinF1(AF1 x){return x*abs(x)-x;} // MAD.
+ 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 
+//------------------------------------------------------------------------------------------------------------------------------
+ #ifdef A_HALF
+  // For a packed {sin,cos} pair,
+  //  - Native takes 16 clocks and 4 issue slots (no packed transcendentals).
+  //  - Parabolic takes 8 clocks and 8 issue slots (only fract is non-packed).
+  AH2 APSinH2(AH2 x){return x*abs(x)-x;} // AND,FMA
+  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 
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                      COLOR CONVERSIONS
+//------------------------------------------------------------------------------------------------------------------------------
+// These are all linear to/from some other space (where 'linear' has been shortened out of the function name).
+// So 'ToGamma' is 'LinearToGamma', and 'FromGamma' is 'LinearFromGamma'.
+// These are branch free implementations.
+// The AToSrgbF1() function is useful for stores for compute shaders for GPUs without hardware linear->sRGB store conversion.
+//------------------------------------------------------------------------------------------------------------------------------
+// TRANSFER FUNCTIONS
+// ==================
+// 709 ..... Rec709 used for some HDTVs
+// Gamma ... Typically 2.2 for some PC displays, or 2.4-2.5 for CRTs, or 2.2 FreeSync2 native
+// Pq ...... PQ native for HDR10
+// Srgb .... The sRGB output, typical of PC displays, useful for 10-bit output, or storing to 8-bit UNORM without SRGB type
+// Two ..... Gamma 2.0, fastest conversion (useful for intermediate pass approximations)
+//------------------------------------------------------------------------------------------------------------------------------
+// FOR PQ
+// ======
+// Both input and output is {0.0-1.0}, and where output 1.0 represents 10000.0 cd/m^2.
+// All constants are only specified to FP32 precision.
+// External PQ source reference,
+//  - https://github.com/ampas/aces-dev/blob/master/transforms/ctl/utilities/ACESlib.Utilities_Color.a1.0.1.ctl
+//------------------------------------------------------------------------------------------------------------------------------
+// PACKED VERSIONS
+// ===============
+// These are the A*H2() functions.
+// There is no PQ functions as FP16 seemed to not have enough precision for the conversion.
+// The remaining functions are "good enough" for 8-bit, and maybe 10-bit if not concerned about a few 1-bit errors.
+// Precision is lowest in the 709 conversion, higher in sRGB, higher still in Two and Gamma (when using 2.2 at least).
+//------------------------------------------------------------------------------------------------------------------------------
+// NOTES
+// =====
+// Could be faster for PQ conversions to be in ALU or a texture lookup depending on usage case.
+//==============================================================================================================================
+ 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));}
+//------------------------------------------------------------------------------------------------------------------------------
+ // Note 'rcpX' is '1/x', where the 'x' is what would be used in AFromGamma().
+ AF1 AToGammaF1(AF1 c,AF1 rcpX){return pow(c,rcpX);} 
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AToPqF1(AF1 x){AF1 p=pow(x,AF1_(0.159302));
+  return pow((AF1_(0.835938)+AF1_(18.8516)*p)/(AF1_(1.0)+AF1_(18.6875)*p),AF1_(78.8438));}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AToTwoF1(AF1 c){return sqrt(c);}
+//==============================================================================================================================
+ AF1 AFrom709F1(AF1 c){return max(min(c*AF1_(1.0/4.5),AF1_(0.081)),
+  pow((c+AF1_(0.099))*(AF1_(1.0)/(AF1_(1.099))),AF1_(1.0/0.45)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AFromGammaF1(AF1 c,AF1 x){return pow(c,x);} 
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AFromPqF1(AF1 x){AF1 p=pow(x,AF1_(0.0126833));
+  return pow(ASatF1(p-AF1_(0.835938))/(AF1_(18.8516)-AF1_(18.6875)*p),AF1_(6.27739));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AFromSrgbF1(AF1 c){return max(min(c*AF1_(1.0/12.92),AF1_(0.04045)),
+  pow((c+AF1_(0.055))*(AF1_(1.0)/AF1_(1.055)),AF1_(2.4)));}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF1 AFromTwoF1(AF1 c){return c*c;}
+//==============================================================================================================================
+ #ifdef A_HALF
+  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));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH2 AToGammaH2(AH2 c,AH1 rcpX){return pow(c,AH2_(rcpX));} 
+//------------------------------------------------------------------------------------------------------------------------------
+  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));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH2 AToTwoH2(AH2 c){return sqrt(c);}
+ #endif
+//==============================================================================================================================
+ #ifdef A_HALF
+  AH2 AFrom709H2(AH2 c){return max(min(c*AH2_(1.0/4.5),AH2_(0.081)),
+   pow((c+AH2_(0.099))*(AH2_(1.0)/(AH2_(1.099))),AH2_(1.0/0.45)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH2 AFromGammaH2(AH2 c,AH1 x){return pow(c,AH2_(x));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH2 AFromSrgbH2(AH2 c){return max(min(c*AH2_(1.0/12.92),AH2_(0.04045)),
+   pow((c+AH2_(0.055))*(AH2_(1.0)/AH2_(1.055)),AH2_(2.4)));}
+//------------------------------------------------------------------------------------------------------------------------------
+  AH2 AFromTwoH2(AH2 c){return c*c;}
+ #endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                          CS REMAP
+//==============================================================================================================================
+ // Simple remap 64x1 to 8x8 with rotated 2x2 pixel quads in quad linear.
+ //  543210
+ //  ======
+ //  ..xxx.
+ //  yy...y
+ AU2 ARmp8x8(AU1 a){return AU2(ABfe(a,1u,3u),ABfiM(ABfe(a,3u,3u),a,1u));}
+//==============================================================================================================================
+ // More complex remap 64x1 to 8x8 which is necessary for 2D wave reductions.
+ //  543210
+ //  ======
+ //  .xx..x
+ //  y..yy.
+ // Details,
+ //  LANE TO 8x8 MAPPING
+ //  ===================
+ //  00 01 08 09 10 11 18 19 
+ //  02 03 0a 0b 12 13 1a 1b
+ //  04 05 0c 0d 14 15 1c 1d
+ //  06 07 0e 0f 16 17 1e 1f 
+ //  20 21 28 29 30 31 38 39 
+ //  22 23 2a 2b 32 33 3a 3b
+ //  24 25 2c 2d 34 35 3c 3d
+ //  26 27 2e 2f 36 37 3e 3f 
+ AU2 ARmpRed8x8(AU1 a){return AU2(ABfiM(ABfe(a,2u,3u),a,1u),ABfiM(ABfe(a,3u,3u),ABfe(a,1u,2u),2u));}
+#endif
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//                                                          REFERENCE
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// IEEE FLOAT RULES
+// ================
+//  - saturate(NaN)=0, saturate(-INF)=0, saturate(+INF)=1
+//  - {+/-}0 * {+/-}INF = NaN
+//  - -INF + (+INF) = NaN
+//  - {+/-}0 / {+/-}0 = NaN
+//  - {+/-}INF / {+/-}INF = NaN
+//  - a<(-0) := sqrt(a) = NaN (a=-0.0 won't NaN)
+//  - 0 == -0
+//  - 4/0 = +INF
+//  - 4/-0 = -INF
+//  - 4+INF = +INF
+//  - 4-INF = -INF
+//  - 4*(+INF) = +INF
+//  - 4*(-INF) = -INF
+//  - -4*(+INF) = -INF
+//  - sqrt(+INF) = +INF
+//------------------------------------------------------------------------------------------------------------------------------
+// FP16 ENCODING
+// =============
+// fedcba9876543210
+// ----------------
+// ......mmmmmmmmmm  10-bit mantissa (encodes 11-bit 0.5 to 1.0 except for denormals)
+// .eeeee..........  5-bit exponent
+// .00000..........  denormals
+// .00001..........  -14 exponent
+// .11110..........   15 exponent
+// .111110000000000  infinity
+// .11111nnnnnnnnnn  NaN with n!=0
+// s...............  sign
+//------------------------------------------------------------------------------------------------------------------------------
+// FP16/INT16 ALIASING DENORMAL
+// ============================
+// 11-bit unsigned integers alias with half float denormal/normal values,
+//     1 = 2^(-24) = 1/16777216 ....................... first denormal value
+//     2 = 2^(-23)
+//   ...
+//  1023 = 2^(-14)*(1-2^(-10)) = 2^(-14)*(1-1/1024) ... last denormal value
+//  1024 = 2^(-14) = 1/16384 .......................... first normal value that still maps to integers
+//  2047 .............................................. last normal value that still maps to integers 
+// Scaling limits,
+//  2^15 = 32768 ...................................... largest power of 2 scaling
+// Largest pow2 conversion mapping is at *32768,
+//     1 : 2^(-9) = 1/128
+//  1024 : 8
+//  2047 : a little less than 16
+//==============================================================================================================================
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+//                                                     GPU/CPU PORTABILITY
+//
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// This is the GPU implementation.
+// See the CPU implementation for docs.
+//==============================================================================================================================
+#ifdef A_GPU
+ #define A_TRUE true
+ #define A_FALSE false
+ #define A_STATIC
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                     VECTOR ARGUMENT/RETURN/INITIALIZATION PORTABILITY
+//==============================================================================================================================
+ #define retAD2 AD2
+ #define retAD3 AD3
+ #define retAD4 AD4
+ #define retAF2 AF2
+ #define retAF3 AF3
+ #define retAF4 AF4
+ #define retAL2 AL2
+ #define retAL3 AL3
+ #define retAL4 AL4
+ #define retAU2 AU2
+ #define retAU3 AU3
+ #define retAU4 AU4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define inAD2 in AD2
+ #define inAD3 in AD3
+ #define inAD4 in AD4
+ #define inAF2 in AF2
+ #define inAF3 in AF3
+ #define inAF4 in AF4
+ #define inAL2 in AL2
+ #define inAL3 in AL3
+ #define inAL4 in AL4
+ #define inAU2 in AU2
+ #define inAU3 in AU3
+ #define inAU4 in AU4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define inoutAD2 inout AD2
+ #define inoutAD3 inout AD3
+ #define inoutAD4 inout AD4
+ #define inoutAF2 inout AF2
+ #define inoutAF3 inout AF3
+ #define inoutAF4 inout AF4
+ #define inoutAL2 inout AL2
+ #define inoutAL3 inout AL3
+ #define inoutAL4 inout AL4
+ #define inoutAU2 inout AU2
+ #define inoutAU3 inout AU3
+ #define inoutAU4 inout AU4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define outAD2 out AD2
+ #define outAD3 out AD3
+ #define outAD4 out AD4
+ #define outAF2 out AF2
+ #define outAF3 out AF3
+ #define outAF4 out AF4
+ #define outAL2 out AL2
+ #define outAL3 out AL3
+ #define outAL4 out AL4
+ #define outAU2 out AU2
+ #define outAU3 out AU3
+ #define outAU4 out AU4
+//------------------------------------------------------------------------------------------------------------------------------
+ #define varAD2(x) AD2 x
+ #define varAD3(x) AD3 x
+ #define varAD4(x) AD4 x
+ #define varAF2(x) AF2 x
+ #define varAF3(x) AF3 x
+ #define varAF4(x) AF4 x
+ #define varAL2(x) AL2 x
+ #define varAL3(x) AL3 x
+ #define varAL4(x) AL4 x
+ #define varAU2(x) AU2 x
+ #define varAU3(x) AU3 x
+ #define varAU4(x) AU4 x
+//------------------------------------------------------------------------------------------------------------------------------
+ #define initAD2(x,y) AD2(x,y)
+ #define initAD3(x,y,z) AD3(x,y,z)
+ #define initAD4(x,y,z,w) AD4(x,y,z,w)
+ #define initAF2(x,y) AF2(x,y)
+ #define initAF3(x,y,z) AF3(x,y,z)
+ #define initAF4(x,y,z,w) AF4(x,y,z,w)
+ #define initAL2(x,y) AL2(x,y)
+ #define initAL3(x,y,z) AL3(x,y,z)
+ #define initAL4(x,y,z,w) AL4(x,y,z,w)
+ #define initAU2(x,y) AU2(x,y)
+ #define initAU3(x,y,z) AU3(x,y,z)
+ #define initAU4(x,y,z,w) AU4(x,y,z,w)
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                     SCALAR RETURN OPS
+//==============================================================================================================================
+ #define AAbsD1(a) abs(AD1(a))
+ #define AAbsF1(a) abs(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ACosD1(a) cos(AD1(a))
+ #define ACosF1(a) cos(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ADotD2(a,b) dot(AD2(a),AD2(b))
+ #define ADotD3(a,b) dot(AD3(a),AD3(b))
+ #define ADotD4(a,b) dot(AD4(a),AD4(b))
+ #define ADotF2(a,b) dot(AF2(a),AF2(b))
+ #define ADotF3(a,b) dot(AF3(a),AF3(b))
+ #define ADotF4(a,b) dot(AF4(a),AF4(b))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AExp2D1(a) exp2(AD1(a))
+ #define AExp2F1(a) exp2(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AFloorD1(a) floor(AD1(a))
+ #define AFloorF1(a) floor(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ALog2D1(a) log2(AD1(a))
+ #define ALog2F1(a) log2(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AMaxD1(a,b) min(a,b)
+ #define AMaxF1(a,b) min(a,b)
+ #define AMaxL1(a,b) min(a,b)
+ #define AMaxU1(a,b) min(a,b)
+//------------------------------------------------------------------------------------------------------------------------------
+ #define AMinD1(a,b) min(a,b)
+ #define AMinF1(a,b) min(a,b)
+ #define AMinL1(a,b) min(a,b)
+ #define AMinU1(a,b) min(a,b)
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ASinD1(a) sin(AD1(a))
+ #define ASinF1(a) sin(AF1(a))
+//------------------------------------------------------------------------------------------------------------------------------
+ #define ASqrtD1(a) sqrt(AD1(a))
+ #define ASqrtF1(a) sqrt(AF1(a))
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                               SCALAR RETURN OPS - DEPENDENT
+//==============================================================================================================================
+ #define APowD1(a,b) pow(AD1(a),AF1(b))
+ #define APowF1(a,b) pow(AF1(a),AF1(b))
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//                                                         VECTOR OPS
+//------------------------------------------------------------------------------------------------------------------------------
+// These are added as needed for production or prototyping, so not necessarily a complete set.
+// They follow a convention of taking in a destination and also returning the destination value to increase utility.
+//==============================================================================================================================
+ #ifdef A_DUBL
+  AD2 opAAbsD2(outAD2 d,inAD2 a){d=abs(a);return d;}
+  AD3 opAAbsD3(outAD3 d,inAD3 a){d=abs(a);return d;}
+  AD4 opAAbsD4(outAD4 d,inAD4 a){d=abs(a);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opAAddD2(outAD2 d,inAD2 a,inAD2 b){d=a+b;return d;}
+  AD3 opAAddD3(outAD3 d,inAD3 a,inAD3 b){d=a+b;return d;}
+  AD4 opAAddD4(outAD4 d,inAD4 a,inAD4 b){d=a+b;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opACpyD2(outAD2 d,inAD2 a){d=a;return d;}
+  AD3 opACpyD3(outAD3 d,inAD3 a){d=a;return d;}
+  AD4 opACpyD4(outAD4 d,inAD4 a){d=a;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opALerpD2(outAD2 d,inAD2 a,inAD2 b,inAD2 c){d=ALerpD2(a,b,c);return d;}
+  AD3 opALerpD3(outAD3 d,inAD3 a,inAD3 b,inAD3 c){d=ALerpD3(a,b,c);return d;}
+  AD4 opALerpD4(outAD4 d,inAD4 a,inAD4 b,inAD4 c){d=ALerpD4(a,b,c);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opALerpOneD2(outAD2 d,inAD2 a,inAD2 b,AD1 c){d=ALerpD2(a,b,AD2_(c));return d;}
+  AD3 opALerpOneD3(outAD3 d,inAD3 a,inAD3 b,AD1 c){d=ALerpD3(a,b,AD3_(c));return d;}
+  AD4 opALerpOneD4(outAD4 d,inAD4 a,inAD4 b,AD1 c){d=ALerpD4(a,b,AD4_(c));return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opAMaxD2(outAD2 d,inAD2 a,inAD2 b){d=max(a,b);return d;}
+  AD3 opAMaxD3(outAD3 d,inAD3 a,inAD3 b){d=max(a,b);return d;}
+  AD4 opAMaxD4(outAD4 d,inAD4 a,inAD4 b){d=max(a,b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opAMinD2(outAD2 d,inAD2 a,inAD2 b){d=min(a,b);return d;}
+  AD3 opAMinD3(outAD3 d,inAD3 a,inAD3 b){d=min(a,b);return d;}
+  AD4 opAMinD4(outAD4 d,inAD4 a,inAD4 b){d=min(a,b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opAMulD2(outAD2 d,inAD2 a,inAD2 b){d=a*b;return d;}
+  AD3 opAMulD3(outAD3 d,inAD3 a,inAD3 b){d=a*b;return d;}
+  AD4 opAMulD4(outAD4 d,inAD4 a,inAD4 b){d=a*b;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opAMulOneD2(outAD2 d,inAD2 a,AD1 b){d=a*AD2_(b);return d;}
+  AD3 opAMulOneD3(outAD3 d,inAD3 a,AD1 b){d=a*AD3_(b);return d;}
+  AD4 opAMulOneD4(outAD4 d,inAD4 a,AD1 b){d=a*AD4_(b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opANegD2(outAD2 d,inAD2 a){d=-a;return d;}
+  AD3 opANegD3(outAD3 d,inAD3 a){d=-a;return d;}
+  AD4 opANegD4(outAD4 d,inAD4 a){d=-a;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+  AD2 opARcpD2(outAD2 d,inAD2 a){d=ARcpD2(a);return d;}
+  AD3 opARcpD3(outAD3 d,inAD3 a){d=ARcpD3(a);return d;}
+  AD4 opARcpD4(outAD4 d,inAD4 a){d=ARcpD4(a);return d;}
+ #endif
+//==============================================================================================================================
+ AF2 opAAbsF2(outAF2 d,inAF2 a){d=abs(a);return d;}
+ AF3 opAAbsF3(outAF3 d,inAF3 a){d=abs(a);return d;}
+ AF4 opAAbsF4(outAF4 d,inAF4 a){d=abs(a);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opAAddF2(outAF2 d,inAF2 a,inAF2 b){d=a+b;return d;}
+ AF3 opAAddF3(outAF3 d,inAF3 a,inAF3 b){d=a+b;return d;}
+ AF4 opAAddF4(outAF4 d,inAF4 a,inAF4 b){d=a+b;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opACpyF2(outAF2 d,inAF2 a){d=a;return d;}
+ AF3 opACpyF3(outAF3 d,inAF3 a){d=a;return d;}
+ AF4 opACpyF4(outAF4 d,inAF4 a){d=a;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opALerpF2(outAF2 d,inAF2 a,inAF2 b,inAF2 c){d=ALerpF2(a,b,c);return d;}
+ AF3 opALerpF3(outAF3 d,inAF3 a,inAF3 b,inAF3 c){d=ALerpF3(a,b,c);return d;}
+ AF4 opALerpF4(outAF4 d,inAF4 a,inAF4 b,inAF4 c){d=ALerpF4(a,b,c);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opALerpOneF2(outAF2 d,inAF2 a,inAF2 b,AF1 c){d=ALerpF2(a,b,AF2_(c));return d;}
+ AF3 opALerpOneF3(outAF3 d,inAF3 a,inAF3 b,AF1 c){d=ALerpF3(a,b,AF3_(c));return d;}
+ AF4 opALerpOneF4(outAF4 d,inAF4 a,inAF4 b,AF1 c){d=ALerpF4(a,b,AF4_(c));return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opAMaxF2(outAF2 d,inAF2 a,inAF2 b){d=max(a,b);return d;}
+ AF3 opAMaxF3(outAF3 d,inAF3 a,inAF3 b){d=max(a,b);return d;}
+ AF4 opAMaxF4(outAF4 d,inAF4 a,inAF4 b){d=max(a,b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opAMinF2(outAF2 d,inAF2 a,inAF2 b){d=min(a,b);return d;}
+ AF3 opAMinF3(outAF3 d,inAF3 a,inAF3 b){d=min(a,b);return d;}
+ AF4 opAMinF4(outAF4 d,inAF4 a,inAF4 b){d=min(a,b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opAMulF2(outAF2 d,inAF2 a,inAF2 b){d=a*b;return d;}
+ AF3 opAMulF3(outAF3 d,inAF3 a,inAF3 b){d=a*b;return d;}
+ AF4 opAMulF4(outAF4 d,inAF4 a,inAF4 b){d=a*b;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opAMulOneF2(outAF2 d,inAF2 a,AF1 b){d=a*AF2_(b);return d;}
+ AF3 opAMulOneF3(outAF3 d,inAF3 a,AF1 b){d=a*AF3_(b);return d;}
+ AF4 opAMulOneF4(outAF4 d,inAF4 a,AF1 b){d=a*AF4_(b);return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opANegF2(outAF2 d,inAF2 a){d=-a;return d;}
+ AF3 opANegF3(outAF3 d,inAF3 a){d=-a;return d;}
+ AF4 opANegF4(outAF4 d,inAF4 a){d=-a;return d;}
+//------------------------------------------------------------------------------------------------------------------------------
+ AF2 opARcpF2(outAF2 d,inAF2 a){d=ARcpF2(a);return d;}
+ AF3 opARcpF3(outAF3 d,inAF3 a){d=ARcpF3(a);return d;}
+ AF4 opARcpF4(outAF4 d,inAF4 a){d=ARcpF4(a);return d;}
+#endif

+ 1297 - 0
Gems/Atom/RPI/Assets/ShaderLib/External/FidelityFX/ffx-spd/ffx_spd.h

@@ -0,0 +1,1297 @@
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//                                         [FFX SPD] Single Pass Downsampler 2.0
+//
+//==============================================================================================================================
+// LICENSE
+// =======
+// Copyright (c) 2017-2020 Advanced Micro Devices, Inc. All rights reserved.
+// -------
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
+// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+// -------
+// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
+// Software.
+// -------
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR
+// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// CHANGELIST v2.0
+// ===============
+// - Added support for cube and array textures. SpdDownsample and SpdDownsampleH shader functions now take index of texture slice
+//   as an additional parameter. For regular texture use 0.
+// - Added support for updating only sub-rectangle of the texture. Additional, optional parameter workGroupOffset added to shader
+//   functions SpdDownsample and SpdDownsampleH.
+// - Added C function SpdSetup that helps to setup constants to be passed as a constant buffer.
+// - The global atomic counter is automatically reset to 0 by the shader at the end, so you do not need to clear it before every
+//   use, just once after creation
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// INTEGRATION SUMMARY FOR CPU
+// ===========================
+// // you need to provide as constants:
+// // number of mip levels to be computed (maximum is 12)
+// // number of total thread groups: ((widthInPixels+63)>>6) * ((heightInPixels+63)>>6)
+// // workGroupOffset -> by default 0, if you only downsample a rectancle within the source texture use SpdSetup function to calculate correct offset
+// ...
+// // Dispatch the shader such that each thread group works on a 64x64 sub-tile of the source image
+// // for Cube Textures or Texture2DArray, use the z dimension
+// vkCmdDispatch(cmdBuf,(widthInPixels+63)>>6,(heightInPixels+63)>>6, slices);
+
+// // you can also use the SpdSetup function:
+// //on top of your cpp file:
+// #define A_CPU
+// #include "ffx_a.h"
+// #include "ffx_spd.h"
+// // before your dispatch call, use SpdSetup function to get your constants
+// varAU2(dispatchThreadGroupCountXY); // output variable
+// varAU2(workGroupOffset);  // output variable, this constants are required if Left and Top are not 0,0
+// varAU2(numWorkGroupsAndMips); // output variable
+// // input information about your source texture:
+// // left and top of the rectancle within your texture you want to downsample
+// // width and height of the rectancle you want to downsample
+// // if complete source texture should get downsampled: left = 0, top = 0, width = sourceTexture.width, height = sourceTexture.height
+// varAU4(rectInfo) = initAU4(0, 0, m_Texture.GetWidth(), m_Texture.GetHeight()); // left, top, width, height
+// SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo);
+// ...
+// // constants:
+// data.numWorkGroupsPerSlice = numWorkGroupsAndMips[0];
+// data.mips = numWorkGroupsAndMips[1];
+// data.workGroupOffset[0] = workGroupOffset[0];
+// data.workGroupOffset[1] = workGroupOffset[1];
+// ...
+// uint32_t dispatchX = dispatchThreadGroupCountXY[0];
+// uint32_t dispatchY = dispatchThreadGroupCountXY[1];
+// uint32_t dispatchZ = m_CubeTexture.GetArraySize(); // slices - for 2D Texture this is 1, for cube texture 6
+// vkCmdDispatch(cmd_buf, dispatchX, dispatchY, dispatchZ);
+
+//------------------------------------------------------------------------------------------------------------------------------
+// INTEGRATION SUMMARY FOR GPU
+// ===========================
+
+// [SAMPLER] - if you want to use a sampler with linear filtering for loading the source image
+// follow additionally the instructions marked with [SAMPLER]
+// add following define:
+// #define SPD_LINEAR_SAMPLER
+// this is recommended, as using one sample() with linear filter to reduce 2x2 is faster
+// than 4x load() plus manual averaging
+
+// // Setup layout. Example below for VK_FORMAT_R16G16B16A16_SFLOAT.
+// // Note: If you use SRGB format for UAV load() and store() (if it's supported), you need to convert to and from linear space
+// // when using UAV load() and store()
+// // approximate conversion to linear (load function): x*x
+// // approximate conversion from linear (store function): sqrt()
+// // or use more accurate functions from ffx_a.h: AFromSrgbF1(value) and AToSrgbF1(value)
+// // Recommendation: use UNORM format instead of SRGB for UAV access, and SRGB for SRV access
+// // look in the sample app to see how it's done
+
+// // source image
+// // if cube texture use image2DArray / Texture2DArray and adapt your load/store/sample calls
+// GLSL: layout(set=0,binding=0,rgba16f)uniform image2D imgSrc;
+// [SAMPLER]: layout(set=0,binding=0)uniform texture2D imgSrc;
+// HLSL: [[vk::binding(0)]] Texture2D<float4> imgSrc :register(u0);
+
+// // destination -> 12 is the maximum number of mips supported by SPD
+// GLSL: layout(set=0,binding=1,rgba16f) uniform coherent image2D imgDst[12];
+// HLSL: [[vk::binding(1)]] globallycoherent RWTexture2D<float4> imgDst[12] :register(u1);
+
+// // global atomic counter - MUST be initialized to 0
+// // SPD resets the counter back after each run by calling SpdResetAtomicCounter(slice)
+// // if you have more than 1 slice (== if you downsample a cube texture or a texture2Darray)
+// // you have an array of counters: counter[6] -> if you have 6 slices for example
+// // GLSL:
+// layout(std430, set=0, binding=2) coherent buffer SpdGlobalAtomicBuffer
+// {
+//    uint counter;
+// } spdGlobalAtomic;
+// // HLSL:
+// struct SpdGlobalAtomicBuffer
+// {
+//    uint counter;
+// };
+// [[vk::binding(2)]] globallycoherent RWStructuredBuffer<SpdGlobalAtomicBuffer> spdGlobalAtomic;
+
+// // [SAMPLER] add sampler
+// GLSL: layout(set=0, binding=3) uniform sampler srcSampler;
+// HLSL: [[vk::binding(3)]] SamplerState srcSampler :register(s0);
+
+// // constants - either push constant or constant buffer
+// // or calculate within shader
+// // [SAMPLER] when using sampler add inverse source image size
+// // GLSL:
+// layout(push_constant) uniform SpdConstants {
+//    uint mips; // needed to opt out earlier if mips are < 12
+//    uint numWorkGroups; // number of total thread groups, so numWorkGroupsX * numWorkGroupsY * 1
+//                        // it is important to NOT take the number of slices (z dimension) into account here
+//                        // as each slice has its own counter!
+//    vec2 workGroupOffset; // optional - use SpdSetup() function to calculate correct workgroup offset
+// } spdConstants;
+// // HLSL:
+// [[vk::push_constant]]
+// cbuffer spdConstants {
+//    uint mips;
+//    uint numWorkGroups;
+//    float2 workGroupOffset; // optional
+// };
+
+// ...
+// // Setup pre-portability-header defines (sets up GLSL/HLSL path, etc)
+// #define A_GPU 1
+// #define A_GLSL 1 // or // #define A_HLSL 1
+
+// // if you want to use PACKED version
+// // recommended if bpc <= 16bit
+// #define A_HALF
+
+// ...
+// // Include the portability header (or copy it in without an include).
+// #include "ffx_a.h"
+// ...
+
+// // Define LDS variables
+// shared AF4 spdIntermediate[16][16]; // HLSL: groupshared
+// shared AU1 spdCounter; // HLSL: groupshared
+// // PACKED version
+// shared AH4 spdIntermediate[16][16]; // HLSL: groupshared
+// // Note: You can also use
+// shared AF1 spdIntermediateR[16][16];
+// shared AF1 spdIntermediateG[16][16];
+// shared AF1 spdIntermediateB[16][16];
+// shared AF1 spdIntermediateA[16][16];
+// // or for Packed version:
+// shared AH2 spdIntermediateRG[16][16];
+// shared AH2 spdIntermediateBA[16][16];
+// // This is potentially faster
+// // Adapt your load and store functions accordingly
+
+// // if subgroup operations are not supported / can't use SM6.0
+// #define SPD_NO_WAVE_OPERATIONS
+
+// // Define the fetch function(s) and the reduction function
+// // if non-power-of-2 textures, add border controls to the load and store functions
+// // to make sure the borders of the mip level look as you want it
+// // if you don't add border controls you'll read zeros past the border
+// // if you load with a sampler, this is obv. handled by your sampler :)
+// // this is also the place where you need to do color space transformation if needed
+// // E.g. if your texture format is SRGB/UNORM and you use the UAV load and store functions
+// // no automatic to/from linear conversions are happening
+// // there is to/from linear conversions when using a sampler and render target approach
+// // conversion to linear (load function): x*x
+// // conversion from linear (store function): sqrt()
+
+// AU1 slice parameter is for Cube textures and texture2DArray
+// if downsampling Texture2D you can ignore this parameter, otherwise use it to access correct slice
+// // Load from source image
+// GLSL: AF4 SpdLoadSourceImage(ASU2 p, AU1 slice){return imageLoad(imgSrc, p);}
+// HLSL: AF4 SpdLoadSourceImage(ASU2 tex, AU1 slice){return imgSrc[tex];}
+// [SAMPLER] don't forget to add the define #SPD_LINEAR_SAMPLER :)
+// GLSL:
+// AF4 SpdLoadSourceImage(ASU2 p, AU1 slice){
+//    AF2 textureCoord = p * invInputSize + invInputSize;
+//    return texture(sampler2D(imgSrc, srcSampler), textureCoord);
+// }
+// HLSL:
+// AF4 SpdLoadSourceImage(ASU2 p, AU1 slice){
+//    AF2 textureCoord = p * invInputSize + invInputSize;
+//    return imgSrc.SampleLevel(srcSampler, textureCoord, 0);
+// }
+
+// // SpdLoad() takes a 32-bit signed integer 2D coordinate and loads color.
+// // Loads the 5th mip level, each value is computed by a different thread group
+// // last thread group will access all its elements and compute the subsequent mips
+// // reminder: if non-power-of-2 textures, add border controls if you do not want to read zeros past the border
+// GLSL: AF4 SpdLoad(ASU2 p, AU1 slice){return imageLoad(imgDst[5],p);}
+// HLSL: AF4 SpdLoad(ASU2 tex, AU1 slice){return imgDst[5][tex];}
+
+// Define the store function
+// GLSL: void SpdStore(ASU2 p, AF4 value, AU1 mip, AU1 slice){imageStore(imgDst[mip], p, value);}
+// HLSL: void SpdStore(ASU2 pix, AF4 value, AU1 mip, AU1 slice){imgDst[mip][pix] = value;}
+
+// // Define the atomic counter increase function
+// // each slice only reads and stores to its specific slice counter
+// // so, if you have several slices it's
+// // InterlockedAdd(spdGlobalAtomic[0].counter[slice], 1, spdCounter);
+// // GLSL:
+// void SpdIncreaseAtomicCounter(AU1 slice){spdCounter = atomicAdd(spdGlobalAtomic.counter, 1);}
+// AU1 SpdGetAtomicCounter() {return spdCounter;}
+// void SpdResetAtomicCounter(AU1 slice){spdGlobalAtomic.counter[slice] = 0;}
+// // HLSL:
+// void SpdIncreaseAtomicCounter(AU1 slice){InterlockedAdd(spdGlobalAtomic[0].counter, 1, spdCounter);}
+// AU1 SpdGetAtomicCounter(){return spdCounter;}
+// void SpdResetAtomicCounter(AU1 slice){spdGlobalAtomic[0].counter[slice] = 0;}
+
+// // Define the LDS load and store functions
+// // GLSL:
+// AF4 SpdLoadIntermediate(AU1 x, AU1 y){return spdIntermediate[x][y];}
+// void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value){spdIntermediate[x][y] = value;}
+// // HLSL:
+// AF4 SpdLoadIntermediate(AU1 x, AU1 y){return spdIntermediate[x][y];}
+// void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value){spdIntermediate[x][y] = value;}
+
+// // Define your reduction function: takes as input the four 2x2 values and returns 1 output value
+// Example below: computes the average value
+// AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3){return (v0+v1+v2+v3)*0.25;}
+
+// // PACKED VERSION
+// Load from source image
+// GLSL: AH4 SpdLoadSourceImageH(ASU2 p, AU1 slice){return AH4(imageLoad(imgSrc, p));}
+// HLSL: AH4 SpdLoadSourceImageH(ASU2 tex, AU1 slice){return AH4(imgSrc[tex]);}
+// [SAMPLER]
+// GLSL:
+// AH4 SpdLoadSourceImageH(ASU2 p, AU1 slice){
+//    AF2 textureCoord = p * invInputSize + invInputSize;
+//    return AH4(texture(sampler2D(imgSrc, srcSampler), textureCoord));
+// }
+// HLSL:
+// AH4 SpdLoadSourceImageH(ASU2 p, AU1 slice){
+//    AF2 textureCoord = p * invInputSize + invInputSize;
+//    return AH4(imgSrc.SampleLevel(srcSampler, textureCoord, 0));
+// }
+
+// // SpdLoadH() takes a 32-bit signed integer 2D coordinate and loads color.
+// // Loads the 5th mip level, each value is computed by a different thread group
+// // last thread group will access all its elements and compute the subsequent mips
+// GLSL: AH4 SpdLoadH(ASU2 p, AU1 slice){return AH4(imageLoad(imgDst[5],p));}
+// HLSL: AH4 SpdLoadH(ASU2 tex, AU1 slice){return AH4(imgDst[5][tex]);}
+
+// Define the store function
+// GLSL: void SpdStoreH(ASU2 p, AH4 value, AU1 mip, AU1 slice){imageStore(imgDst[mip], p, AF4(value));}
+// HLSL: void SpdStoreH(ASU2 pix, AH4 value, AU1 index, AU1 slice){imgDst[index][pix] = AF4(value);}
+
+// // Define the atomic counter increase function
+// // GLSL:
+// void SpdIncreaseAtomicCounter(AU1 slice){spd_counter = atomicAdd(spdGlobalAtomic.counter, 1);}
+// AU1 SpdGetAtomicCounter() {return spdCounter;}
+// // HLSL:
+// void SpdIncreaseAtomicCounter(AU1 slice){InterlockedAdd(spdGlobalAtomic[0].counter, 1, spdCounter);}
+// AU1 SpdGetAtomicCounter(){return spdCounter;}
+
+// // Define the LDS load and store functions
+// // GLSL:
+// AH4 SpdLoadIntermediateH(AU1 x, AU1 y){return spdIntermediate[x][y];}
+// void SpdStoreIntermediateH(AU1 x, AU1 y, AH4 value){spdIntermediate[x][y] = value;}
+// // HLSL:
+// AH4 SpdLoadIntermediate(AU1 x, AU1 y){return spdIntermediate[x][y];}
+// void SpdStoreIntermediate(AU1 x, AU1 y, AH4 value){spdIntermediate[x][y] = value;}
+
+// // Define your reduction function: takes as input the four 2x2 values and returns 1 output value
+// Example below: computes the average value
+// AH4 SpdReduce4H(AH4 v0, AH4 v1, AH4 v2, AH4 v3){return (v0+v1+v2+v3)*AH1(0.25);}
+
+// //
+
+// // If you only use PACKED version
+// #define SPD_PACKED_ONLY
+
+// // Include this SPD (single pass downsampler) header file (or copy it in without an include).
+// #include "ffx_spd.h"
+// ...
+
+// // Example in shader integration
+// // GLSL:
+// layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
+// void main(){
+//  // Call the downsampling function
+// // WorkGroupId.z should be 0 if you only downsample a Texture2D!
+//  SpdDownsample(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), 
+//    AU1(spdConstants.mips), AU1(spdConstants.numWorkGroups), AU1(WorkGroupId.z));
+//
+// // PACKED:
+//  SpdDownsampleH(AU2(gl_WorkGroupID.xy), AU1(gl_LocalInvocationIndex), 
+//    AU1(spdConstants.mips), AU1(spdConstants.numWorkGroups), AU1(WorkGroupId.z));
+// ...
+// // HLSL:
+// [numthreads(256,1,1)]
+// void main(uint3 WorkGroupId : SV_GroupID, uint LocalThreadIndex : SV_GroupIndex) {
+//  SpdDownsample(AU2(WorkGroupId.xy), AU1(LocalThreadIndex),  
+//    AU1(mips), AU1(numWorkGroups), AU1(WorkGroupId.z));
+//
+// // PACKED:
+//  SpdDownsampleH(AU2(WorkGroupId.xy), AU1(LocalThreadIndex),  
+//    AU1(mips), AU1(numWorkGroups), AU1(WorkGroupId.z));
+// ...
+
+//
+//------------------------------------------------------------------------------------------------------------------------------
+
+//==============================================================================================================================
+//                                                     SPD Setup
+//==============================================================================================================================
+#ifdef A_CPU
+A_STATIC void SpdSetup(
+outAU2 dispatchThreadGroupCountXY, // CPU side: dispatch thread group count xy
+outAU2 workGroupOffset, // GPU side: pass in as constant
+outAU2 numWorkGroupsAndMips, // GPU side: pass in as constant
+inAU4 rectInfo, // left, top, width, height
+ASU1 mips // optional: if -1, calculate based on rect width and height
+){
+    workGroupOffset[0] = rectInfo[0] / 64; // rectInfo[0] = left
+    workGroupOffset[1] = rectInfo[1] / 64; // rectInfo[1] = top
+
+    AU1 endIndexX = (rectInfo[0] + rectInfo[2] - 1) / 64; // rectInfo[0] = left, rectInfo[2] = width
+    AU1 endIndexY = (rectInfo[1] + rectInfo[3] - 1) / 64; // rectInfo[1] = top, rectInfo[3] = height
+
+    dispatchThreadGroupCountXY[0] = endIndexX + 1 - workGroupOffset[0];
+    dispatchThreadGroupCountXY[1] = endIndexY + 1 - workGroupOffset[1];
+
+    numWorkGroupsAndMips[0] = (dispatchThreadGroupCountXY[0]) * (dispatchThreadGroupCountXY[1]);
+
+    if (mips >= 0) {
+        numWorkGroupsAndMips[1] = AU1(mips);
+    } else { // calculate based on rect width and height
+        AU1 resolution = AMaxU1(rectInfo[2], rectInfo[3]);
+        numWorkGroupsAndMips[1] = AU1((AMinF1(AFloorF1(ALog2F1(AF1(resolution))), AF1(12))));
+    }
+}
+
+A_STATIC void SpdSetup(
+    outAU2 dispatchThreadGroupCountXY, // CPU side: dispatch thread group count xy
+    outAU2 workGroupOffset, // GPU side: pass in as constant
+    outAU2 numWorkGroupsAndMips, // GPU side: pass in as constant
+    inAU4 rectInfo // left, top, width, height
+) {
+    SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo, -1);
+}
+#endif // #ifdef A_CPU
+//==============================================================================================================================
+//                                                     NON-PACKED VERSION
+//==============================================================================================================================
+#ifdef A_GPU
+#ifdef SPD_PACKED_ONLY
+  // Avoid compiler error
+  AF4 SpdLoadSourceImage(ASU2 p, AU1 slice){return AF4(0.0,0.0,0.0,0.0);}
+  AF4 SpdLoad(ASU2 p, AU1 slice){return AF4(0.0,0.0,0.0,0.0);}
+  void SpdStore(ASU2 p, AF4 value, AU1 mip, AU1 slice){}
+  AF4 SpdLoadIntermediate(AU1 x, AU1 y){return AF4(0.0,0.0,0.0,0.0);}
+  void SpdStoreIntermediate(AU1 x, AU1 y, AF4 value){}
+  AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3){return AF4(0.0,0.0,0.0,0.0);}
+#endif // #ifdef SPD_PACKED_ONLY
+
+//_____________________________________________________________/\_______________________________________________________________
+#if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS)
+#extension GL_KHR_shader_subgroup_quad:require
+#endif
+
+void SpdWorkgroupShuffleBarrier() {
+#ifdef A_GLSL
+    barrier();
+#endif 
+#ifdef A_HLSL
+    GroupMemoryBarrierWithGroupSync();
+#endif
+}
+
+// Only last active workgroup should proceed
+bool SpdExitWorkgroup(AU1 numWorkGroups, AU1 localInvocationIndex, AU1 slice) 
+{
+    // global atomic counter
+    if (localInvocationIndex == 0)
+    {
+        SpdIncreaseAtomicCounter(slice);
+    }
+    SpdWorkgroupShuffleBarrier();
+    return (SpdGetAtomicCounter() != (numWorkGroups - 1));
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+// User defined: AF4 SpdReduce4(AF4 v0, AF4 v1, AF4 v2, AF4 v3);
+
+AF4 SpdReduceQuad(AF4 v)
+{
+    #if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS)
+    AF4 v0 = v;
+    AF4 v1 = subgroupQuadSwapHorizontal(v);
+    AF4 v2 = subgroupQuadSwapVertical(v);
+    AF4 v3 = subgroupQuadSwapDiagonal(v);
+    return SpdReduce4(v0, v1, v2, v3);
+    #elif defined(A_HLSL) && !defined(SPD_NO_WAVE_OPERATIONS)
+    // requires SM6.0
+    AU1 quad = WaveGetLaneIndex() &  (~0x3);
+    AF4 v0 = v;
+    AF4 v1 = WaveReadLaneAt(v, quad | 1);
+    AF4 v2 = WaveReadLaneAt(v, quad | 2);
+    AF4 v3 = WaveReadLaneAt(v, quad | 3);
+    return SpdReduce4(v0, v1, v2, v3);
+    /*
+    // if SM6.0 is not available, you can use the AMD shader intrinsics
+    // the AMD shader intrinsics are available in AMD GPU Services (AGS) library:
+    // https://gpuopen.com/amd-gpu-services-ags-library/
+    // works for DX11
+    AF4 v0 = v;
+    AF4 v1;
+    v1.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    AF4 v2;
+    v2.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    AF4 v3;
+    v3.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    return SpdReduce4(v0, v1, v2, v3);
+    */
+    #endif
+    return v;
+}
+
+AF4 SpdReduceIntermediate(AU2 i0, AU2 i1, AU2 i2, AU2 i3)
+{
+    AF4 v0 = SpdLoadIntermediate(i0.x, i0.y);
+    AF4 v1 = SpdLoadIntermediate(i1.x, i1.y);
+    AF4 v2 = SpdLoadIntermediate(i2.x, i2.y);
+    AF4 v3 = SpdLoadIntermediate(i3.x, i3.y);
+    return SpdReduce4(v0, v1, v2, v3);
+}
+
+AF4 SpdReduceLoad4(AU2 i0, AU2 i1, AU2 i2, AU2 i3, AU1 slice)
+{
+    AF4 v0 = SpdLoad(ASU2(i0), slice);
+    AF4 v1 = SpdLoad(ASU2(i1), slice);
+    AF4 v2 = SpdLoad(ASU2(i2), slice);
+    AF4 v3 = SpdLoad(ASU2(i3), slice);
+    return SpdReduce4(v0, v1, v2, v3);
+}
+
+AF4 SpdReduceLoad4(AU2 base, AU1 slice)
+{
+    return SpdReduceLoad4(
+        AU2(base + AU2(0, 0)),
+        AU2(base + AU2(0, 1)), 
+        AU2(base + AU2(1, 0)), 
+        AU2(base + AU2(1, 1)),
+        slice);
+}
+
+AF4 SpdReduceLoadSourceImage4(AU2 i0, AU2 i1, AU2 i2, AU2 i3, AU1 slice)
+{
+    AF4 v0 = SpdLoadSourceImage(ASU2(i0), slice);
+    AF4 v1 = SpdLoadSourceImage(ASU2(i1), slice);
+    AF4 v2 = SpdLoadSourceImage(ASU2(i2), slice);
+    AF4 v3 = SpdLoadSourceImage(ASU2(i3), slice);
+    return SpdReduce4(v0, v1, v2, v3);
+}
+
+AF4 SpdReduceLoadSourceImage(AU2 base, AU1 slice)
+{
+#ifdef SPD_LINEAR_SAMPLER
+    return SpdLoadSourceImage(ASU2(base), slice);
+#else
+    return SpdReduceLoadSourceImage4(
+        AU2(base + AU2(0, 0)),
+        AU2(base + AU2(0, 1)), 
+        AU2(base + AU2(1, 0)), 
+        AU2(base + AU2(1, 1)),
+        slice);
+#endif
+}
+
+void SpdDownsampleMips_0_1_Intrinsics(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+    AF4 v[4];
+
+    ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2);
+    ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y);
+    v[0] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[0], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y);
+    v[1] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[1], 0, slice);
+    
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16);
+    v[2] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[2], 0, slice);
+    
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16);
+    v[3] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[3], 0, slice);
+
+    if (mip <= 1)
+        return;
+
+    v[0] = SpdReduceQuad(v[0]);
+    v[1] = SpdReduceQuad(v[1]);
+    v[2] = SpdReduceQuad(v[2]);
+    v[3] = SpdReduceQuad(v[3]);
+
+    if ((localInvocationIndex % 4) == 0)
+    {
+        SpdStore(ASU2(workGroupID.xy * 16) + 
+            ASU2(x/2, y/2), v[0], 1, slice);
+        SpdStoreIntermediate(
+            x/2, y/2, v[0]);
+
+        SpdStore(ASU2(workGroupID.xy * 16) + 
+            ASU2(x/2 + 8, y/2), v[1], 1, slice);
+        SpdStoreIntermediate(
+            x/2 + 8, y/2, v[1]);
+
+        SpdStore(ASU2(workGroupID.xy * 16) + 
+            ASU2(x/2, y/2 + 8), v[2], 1, slice);
+        SpdStoreIntermediate(
+            x/2, y/2 + 8, v[2]);
+
+        SpdStore(ASU2(workGroupID.xy * 16) + 
+            ASU2(x/2 + 8, y/2 + 8), v[3], 1, slice);
+        SpdStoreIntermediate(
+            x/2 + 8, y/2 + 8, v[3]);
+    }
+}
+
+void SpdDownsampleMips_0_1_LDS(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice) 
+{
+    AF4 v[4];
+
+    ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2);
+    ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y);
+    v[0] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[0], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y);
+    v[1] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[1], 0, slice);
+    
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16);
+    v[2] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[2], 0, slice);
+    
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16);
+    v[3] = SpdReduceLoadSourceImage(tex, slice);
+    SpdStore(pix, v[3], 0, slice);
+
+    if (mip <= 1)
+        return;
+
+    for (int i = 0; i < 4; i++)
+    {
+        SpdStoreIntermediate(x, y, v[i]);
+        SpdWorkgroupShuffleBarrier();
+        if (localInvocationIndex < 64)
+        {
+            v[i] = SpdReduceIntermediate(
+                AU2(x * 2 + 0, y * 2 + 0),
+                AU2(x * 2 + 1, y * 2 + 0),
+                AU2(x * 2 + 0, y * 2 + 1),
+                AU2(x * 2 + 1, y * 2 + 1)
+            );
+            SpdStore(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1, slice);
+        }
+        SpdWorkgroupShuffleBarrier();
+    }
+
+    if (localInvocationIndex < 64)
+    {
+        SpdStoreIntermediate(x + 0, y + 0, v[0]);
+        SpdStoreIntermediate(x + 8, y + 0, v[1]);
+        SpdStoreIntermediate(x + 0, y + 8, v[2]);
+        SpdStoreIntermediate(x + 8, y + 8, v[3]);
+    }
+}
+
+void SpdDownsampleMips_0_1(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice) 
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    SpdDownsampleMips_0_1_LDS(x, y, workGroupID, localInvocationIndex, mip, slice);
+#else
+    SpdDownsampleMips_0_1_Intrinsics(x, y, workGroupID, localInvocationIndex, mip, slice);
+#endif
+}
+
+
+void SpdDownsampleMip_2(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 64)
+    {
+        AF4 v = SpdReduceIntermediate(
+            AU2(x * 2 + 0, y * 2 + 0),
+            AU2(x * 2 + 1, y * 2 + 0),
+            AU2(x * 2 + 0, y * 2 + 1),
+            AU2(x * 2 + 1, y * 2 + 1)
+        );
+        SpdStore(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip, slice);
+        // store to LDS, try to reduce bank conflicts
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 x
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        // ...
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        SpdStoreIntermediate(x * 2 + y % 2, y * 2, v);
+    }
+#else
+    AF4 v = SpdLoadIntermediate(x, y);
+    v = SpdReduceQuad(v);
+    // quad index 0 stores result
+    if (localInvocationIndex % 4 == 0)
+    {
+        SpdStore(ASU2(workGroupID.xy * 8) + ASU2(x/2, y/2), v, mip, slice);
+        SpdStoreIntermediate(x + (y/2) % 2, y, v);
+    }
+#endif
+}
+
+void SpdDownsampleMip_3(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 16)
+    {
+        // x 0 x 0
+        // 0 0 0 0
+        // 0 x 0 x
+        // 0 0 0 0
+        AF4 v = SpdReduceIntermediate(
+            AU2(x * 4 + 0 + 0, y * 4 + 0),
+            AU2(x * 4 + 2 + 0, y * 4 + 0),
+            AU2(x * 4 + 0 + 1, y * 4 + 2),
+            AU2(x * 4 + 2 + 1, y * 4 + 2)
+        );
+        SpdStore(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip, slice);
+        // store to LDS
+        // x 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 x 0 0 0 x 0 0 0 x 0 0 0 x 0 0
+        // ...
+        // 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x 0
+        // ...
+        // 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x
+        // ...
+        SpdStoreIntermediate(x * 4 + y, y * 4, v);
+    }
+#else
+    if (localInvocationIndex < 64)
+    {
+        AF4 v = SpdLoadIntermediate(x * 2 + y % 2,y * 2);
+        v = SpdReduceQuad(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStore(ASU2(workGroupID.xy * 4) + ASU2(x/2, y/2), v, mip, slice);
+            SpdStoreIntermediate(x * 2 + y/2, y * 2, v);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMip_4(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 4)
+    {
+        // x 0 0 0 x 0 0 0
+        // ...
+        // 0 x 0 0 0 x 0 0
+        AF4 v = SpdReduceIntermediate(
+            AU2(x * 8 + 0 + 0 + y * 2, y * 8 + 0),
+            AU2(x * 8 + 4 + 0 + y * 2, y * 8 + 0),
+            AU2(x * 8 + 0 + 1 + y * 2, y * 8 + 4),
+            AU2(x * 8 + 4 + 1 + y * 2, y * 8 + 4)
+        );
+        SpdStore(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip, slice);
+        // store to LDS
+        // x x x x 0 ...
+        // 0 ...
+        SpdStoreIntermediate(x + y * 2, 0, v);
+    }
+#else
+    if (localInvocationIndex < 16)
+    {
+        AF4 v = SpdLoadIntermediate(x * 4 + y,y * 4);
+        v = SpdReduceQuad(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStore(ASU2(workGroupID.xy * 2) + ASU2(x/2, y/2), v, mip, slice);
+            SpdStoreIntermediate(x / 2 + y, 0, v);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMip_5(AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 1)
+    {
+        // x x x x 0 ...
+        // 0 ...
+        AF4 v = SpdReduceIntermediate(
+            AU2(0, 0),
+            AU2(1, 0),
+            AU2(2, 0),
+            AU2(3, 0)
+        );
+        SpdStore(ASU2(workGroupID.xy), v, mip, slice);
+    }
+#else
+    if (localInvocationIndex < 4)
+    {
+        AF4 v = SpdLoadIntermediate(localInvocationIndex,0);
+        v = SpdReduceQuad(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStore(ASU2(workGroupID.xy), v, mip, slice);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMips_6_7(AU1 x, AU1 y, AU1 mips, AU1 slice)
+{
+    ASU2 tex = ASU2(x * 4 + 0, y * 4 + 0);
+    ASU2 pix = ASU2(x * 2 + 0, y * 2 + 0);
+    AF4 v0 = SpdReduceLoad4(tex, slice);
+    SpdStore(pix, v0, 6, slice);
+
+    tex = ASU2(x * 4 + 2, y * 4 + 0);
+    pix = ASU2(x * 2 + 1, y * 2 + 0);
+    AF4 v1 = SpdReduceLoad4(tex, slice);
+    SpdStore(pix, v1, 6, slice);
+
+    tex = ASU2(x * 4 + 0, y * 4 + 2);
+    pix = ASU2(x * 2 + 0, y * 2 + 1);
+    AF4 v2 = SpdReduceLoad4(tex, slice);
+    SpdStore(pix, v2, 6, slice);
+
+    tex = ASU2(x * 4 + 2, y * 4 + 2);
+    pix = ASU2(x * 2 + 1, y * 2 + 1);
+    AF4 v3 = SpdReduceLoad4(tex, slice);
+    SpdStore(pix, v3, 6, slice);
+
+    if (mips <= 7) return;
+    // no barrier needed, working on values only from the same thread
+
+    AF4 v = SpdReduce4(v0, v1, v2, v3);
+    SpdStore(ASU2(x, y), v, 7, slice);
+    SpdStoreIntermediate(x, y, v);
+}
+
+void SpdDownsampleNextFour(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips, AU1 slice)
+{
+    if (mips <= baseMip) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_2(x, y, workGroupID, localInvocationIndex, baseMip, slice);
+
+    if (mips <= baseMip + 1) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_3(x, y, workGroupID, localInvocationIndex, baseMip + 1, slice);
+
+    if (mips <= baseMip + 2) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_4(x, y, workGroupID, localInvocationIndex, baseMip + 2, slice);
+
+    if (mips <= baseMip + 3) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_5(workGroupID, localInvocationIndex, baseMip + 3, slice);
+}
+
+void SpdDownsample(
+    AU2 workGroupID,
+    AU1 localInvocationIndex,
+    AU1 mips,
+    AU1 numWorkGroups,
+    AU1 slice
+) {
+    AU2 sub_xy = ARmpRed8x8(localInvocationIndex % 64);
+    AU1 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2);
+    AU1 y = sub_xy.y + 8 * ((localInvocationIndex >> 7));
+    SpdDownsampleMips_0_1(x, y, workGroupID, localInvocationIndex, mips, slice);
+
+    SpdDownsampleNextFour(x, y, workGroupID, localInvocationIndex, 2, mips, slice);
+
+    if (mips <= 6) return;
+
+    if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex, slice)) return;
+
+    SpdResetAtomicCounter(slice);
+
+    // After mip 6 there is only a single workgroup left that downsamples the remaining up to 64x64 texels.
+    SpdDownsampleMips_6_7(x, y, mips, slice);
+
+    SpdDownsampleNextFour(x, y, AU2(0,0), localInvocationIndex, 8, mips, slice);
+}
+
+void SpdDownsample(
+    AU2 workGroupID,
+    AU1 localInvocationIndex,
+    AU1 mips,
+    AU1 numWorkGroups,
+    AU1 slice,
+    AU2 workGroupOffset
+) {
+    SpdDownsample(workGroupID + workGroupOffset, localInvocationIndex, mips, numWorkGroups, slice);
+}
+
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+//==============================================================================================================================
+//                                                       PACKED VERSION
+//==============================================================================================================================
+
+#ifdef A_HALF
+
+#ifdef A_GLSL
+#extension GL_EXT_shader_subgroup_extended_types_float16:require
+#endif
+
+AH4 SpdReduceQuadH(AH4 v)
+{
+    #if defined(A_GLSL) && !defined(SPD_NO_WAVE_OPERATIONS)
+    AH4 v0 = v;
+    AH4 v1 = subgroupQuadSwapHorizontal(v);
+    AH4 v2 = subgroupQuadSwapVertical(v);
+    AH4 v3 = subgroupQuadSwapDiagonal(v);
+    return SpdReduce4H(v0, v1, v2, v3);
+    #elif defined(A_HLSL) && !defined(SPD_NO_WAVE_OPERATIONS)
+    // requires SM6.0
+    AU1 quad = WaveGetLaneIndex() &  (~0x3);
+    AH4 v0 = v;
+    AH4 v1 = WaveReadLaneAt(v, quad | 1);
+    AH4 v2 = WaveReadLaneAt(v, quad | 2);
+    AH4 v3 = WaveReadLaneAt(v, quad | 3);
+    return SpdReduce4H(v0, v1, v2, v3);
+    /*
+    // if SM6.0 is not available, you can use the AMD shader intrinsics
+    // the AMD shader intrinsics are available in AMD GPU Services (AGS) library:
+    // https://gpuopen.com/amd-gpu-services-ags-library/
+    // works for DX11
+    AH4 v0 = v;
+    AH4 v1;
+    v1.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    v1.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX1);
+    AH4 v2;
+    v2.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    v2.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_SwapX2);
+    AH4 v3;
+    v3.x = AmdExtD3DShaderIntrinsics_SwizzleF(v.x, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.y = AmdExtD3DShaderIntrinsics_SwizzleF(v.y, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.z = AmdExtD3DShaderIntrinsics_SwizzleF(v.z, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    v3.w = AmdExtD3DShaderIntrinsics_SwizzleF(v.w, AmdExtD3DShaderIntrinsicsSwizzle_ReverseX4);
+    return SpdReduce4H(v0, v1, v2, v3);
+    */
+    #endif
+    return AH4(0.0, 0.0, 0.0, 0.0);
+
+}
+
+AH4 SpdReduceIntermediateH(AU2 i0, AU2 i1, AU2 i2, AU2 i3)
+{
+    AH4 v0 = SpdLoadIntermediateH(i0.x, i0.y);
+    AH4 v1 = SpdLoadIntermediateH(i1.x, i1.y);
+    AH4 v2 = SpdLoadIntermediateH(i2.x, i2.y);
+    AH4 v3 = SpdLoadIntermediateH(i3.x, i3.y);
+    return SpdReduce4H(v0, v1, v2, v3);
+}
+
+AH4 SpdReduceLoad4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3, AU1 slice)
+{
+    AH4 v0 = SpdLoadH(ASU2(i0), slice);
+    AH4 v1 = SpdLoadH(ASU2(i1), slice);
+    AH4 v2 = SpdLoadH(ASU2(i2), slice);
+    AH4 v3 = SpdLoadH(ASU2(i3), slice);
+    return SpdReduce4H(v0, v1, v2, v3);
+}
+
+AH4 SpdReduceLoad4H(AU2 base, AU1 slice)
+{
+    return SpdReduceLoad4H(
+        AU2(base + AU2(0, 0)),
+        AU2(base + AU2(0, 1)), 
+        AU2(base + AU2(1, 0)), 
+        AU2(base + AU2(1, 1)),
+        slice);
+}
+
+AH4 SpdReduceLoadSourceImage4H(AU2 i0, AU2 i1, AU2 i2, AU2 i3, AU1 slice)
+{
+    AH4 v0 = SpdLoadSourceImageH(ASU2(i0), slice);
+    AH4 v1 = SpdLoadSourceImageH(ASU2(i1), slice);
+    AH4 v2 = SpdLoadSourceImageH(ASU2(i2), slice);
+    AH4 v3 = SpdLoadSourceImageH(ASU2(i3), slice);
+    return SpdReduce4H(v0, v1, v2, v3);
+}
+
+AH4 SpdReduceLoadSourceImageH(AU2 base, AU1 slice)
+{
+#ifdef SPD_LINEAR_SAMPLER
+    return SpdLoadSourceImageH(ASU2(base), slice);
+#else
+    return SpdReduceLoadSourceImage4H(
+        AU2(base + AU2(0, 0)),
+        AU2(base + AU2(0, 1)), 
+        AU2(base + AU2(1, 0)), 
+        AU2(base + AU2(1, 1)),
+        slice);
+#endif
+}
+
+void SpdDownsampleMips_0_1_IntrinsicsH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips, AU1 slice)
+{
+    AH4 v[4];
+
+    ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2);
+    ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y);
+    v[0] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[0], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y);
+    v[1] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[1], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16);
+    v[2] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[2], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16);
+    v[3] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[3], 0, slice);
+
+    if (mips <= 1)
+        return;
+
+    v[0] = SpdReduceQuadH(v[0]);
+    v[1] = SpdReduceQuadH(v[1]);
+    v[2] = SpdReduceQuadH(v[2]);
+    v[3] = SpdReduceQuadH(v[3]);
+
+    if ((localInvocationIndex % 4) == 0)
+    {
+        SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2, y/2), v[0], 1, slice);
+        SpdStoreIntermediateH(x/2, y/2, v[0]);
+
+        SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2 + 8, y/2), v[1], 1, slice);
+        SpdStoreIntermediateH(x/2 + 8, y/2, v[1]);
+
+        SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2, y/2 + 8), v[2], 1, slice);
+        SpdStoreIntermediateH(x/2, y/2 + 8, v[2]);
+
+        SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x/2 + 8, y/2 + 8), v[3], 1, slice);
+        SpdStoreIntermediateH(x/2 + 8, y/2 + 8, v[3]);
+    }
+}
+
+void SpdDownsampleMips_0_1_LDSH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips, AU1 slice) 
+{
+    AH4 v[4];
+
+    ASU2 tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2);
+    ASU2 pix = ASU2(workGroupID.xy * 32) + ASU2(x, y);
+    v[0] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[0], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y);
+    v[1] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[1], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x, y + 16);
+    v[2] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[2], 0, slice);
+
+    tex = ASU2(workGroupID.xy * 64) + ASU2(x * 2 + 32, y * 2 + 32);
+    pix = ASU2(workGroupID.xy * 32) + ASU2(x + 16, y + 16);
+    v[3] = SpdReduceLoadSourceImageH(tex, slice);
+    SpdStoreH(pix, v[3], 0, slice);
+
+    if (mips <= 1)
+        return;
+
+    for (int i = 0; i < 4; i++)
+    {
+        SpdStoreIntermediateH(x, y, v[i]);
+        SpdWorkgroupShuffleBarrier();
+        if (localInvocationIndex < 64)
+        {
+            v[i] = SpdReduceIntermediateH(
+                AU2(x * 2 + 0, y * 2 + 0),
+                AU2(x * 2 + 1, y * 2 + 0),
+                AU2(x * 2 + 0, y * 2 + 1),
+                AU2(x * 2 + 1, y * 2 + 1)
+            );
+            SpdStoreH(ASU2(workGroupID.xy * 16) + ASU2(x + (i % 2) * 8, y + (i / 2) * 8), v[i], 1, slice);
+        }
+        SpdWorkgroupShuffleBarrier();
+    }
+
+    if (localInvocationIndex < 64)
+    {
+        SpdStoreIntermediateH(x + 0, y + 0, v[0]);
+        SpdStoreIntermediateH(x + 8, y + 0, v[1]);
+        SpdStoreIntermediateH(x + 0, y + 8, v[2]);
+        SpdStoreIntermediateH(x + 8, y + 8, v[3]);
+    }
+}
+
+void SpdDownsampleMips_0_1H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mips, AU1 slice) 
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    SpdDownsampleMips_0_1_LDSH(x, y, workGroupID, localInvocationIndex, mips, slice);
+#else
+    SpdDownsampleMips_0_1_IntrinsicsH(x, y, workGroupID, localInvocationIndex, mips, slice);
+#endif
+}
+
+
+void SpdDownsampleMip_2H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 64)
+    {
+        AH4 v = SpdReduceIntermediateH(
+            AU2(x * 2 + 0, y * 2 + 0),
+            AU2(x * 2 + 1, y * 2 + 0),
+            AU2(x * 2 + 0, y * 2 + 1),
+            AU2(x * 2 + 1, y * 2 + 1)
+        );
+        SpdStoreH(ASU2(workGroupID.xy * 8) + ASU2(x, y), v, mip, slice);
+        // store to LDS, try to reduce bank conflicts
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0 x
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        // ...
+        // x 0 x 0 x 0 x 0 x 0 x 0 x 0 x 0
+        SpdStoreIntermediateH(x * 2 + y % 2, y * 2, v);
+    }
+#else
+    AH4 v = SpdLoadIntermediateH(x, y);
+    v = SpdReduceQuadH(v);
+    // quad index 0 stores result
+    if (localInvocationIndex % 4 == 0)
+    {   
+        SpdStoreH(ASU2(workGroupID.xy * 8) + ASU2(x/2, y/2), v, mip, slice);
+        SpdStoreIntermediateH(x + (y/2) % 2, y, v);
+    }
+#endif
+}
+
+void SpdDownsampleMip_3H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 16)
+    {
+        // x 0 x 0
+        // 0 0 0 0
+        // 0 x 0 x
+        // 0 0 0 0
+        AH4 v = SpdReduceIntermediateH(
+            AU2(x * 4 + 0 + 0, y * 4 + 0),
+            AU2(x * 4 + 2 + 0, y * 4 + 0),
+            AU2(x * 4 + 0 + 1, y * 4 + 2),
+            AU2(x * 4 + 2 + 1, y * 4 + 2)
+        );
+        SpdStoreH(ASU2(workGroupID.xy * 4) + ASU2(x, y), v, mip, slice);
+        // store to LDS
+        // x 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+        // 0 x 0 0 0 x 0 0 0 x 0 0 0 x 0 0
+        // ...
+        // 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x 0
+        // ...
+        // 0 0 0 x 0 0 0 x 0 0 0 x 0 0 0 x
+        // ...
+        SpdStoreIntermediateH(x * 4 + y, y * 4, v);
+    }
+#else
+    if (localInvocationIndex < 64)
+    {
+        AH4 v = SpdLoadIntermediateH(x * 2 + y % 2,y * 2);
+        v = SpdReduceQuadH(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStoreH(ASU2(workGroupID.xy * 4) + ASU2(x/2, y/2), v, mip, slice);
+            SpdStoreIntermediateH(x * 2 + y/2, y * 2, v);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMip_4H(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 4)
+    {
+        // x 0 0 0 x 0 0 0
+        // ...
+        // 0 x 0 0 0 x 0 0
+        AH4 v = SpdReduceIntermediateH(
+            AU2(x * 8 + 0 + 0 + y * 2, y * 8 + 0),
+            AU2(x * 8 + 4 + 0 + y * 2, y * 8 + 0),
+            AU2(x * 8 + 0 + 1 + y * 2, y * 8 + 4),
+            AU2(x * 8 + 4 + 1 + y * 2, y * 8 + 4)
+        );
+        SpdStoreH(ASU2(workGroupID.xy * 2) + ASU2(x, y), v, mip, slice);
+        // store to LDS
+        // x x x x 0 ...
+        // 0 ...
+        SpdStoreIntermediateH(x + y * 2, 0, v);
+    }
+#else
+    if (localInvocationIndex < 16)
+    {
+        AH4 v = SpdLoadIntermediateH(x * 4 + y,y * 4);
+        v = SpdReduceQuadH(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStoreH(ASU2(workGroupID.xy * 2) + ASU2(x/2, y/2), v, mip, slice);
+            SpdStoreIntermediateH(x / 2 + y, 0, v);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMip_5H(AU2 workGroupID, AU1 localInvocationIndex, AU1 mip, AU1 slice)
+{
+#ifdef SPD_NO_WAVE_OPERATIONS
+    if (localInvocationIndex < 1)
+    {
+        // x x x x 0 ...
+        // 0 ...
+        AH4 v = SpdReduceIntermediateH(
+            AU2(0, 0),
+            AU2(1, 0),
+            AU2(2, 0),
+            AU2(3, 0)
+        );
+        SpdStoreH(ASU2(workGroupID.xy), v, mip, slice);
+    }
+#else
+    if (localInvocationIndex < 4)
+    {
+        AH4 v = SpdLoadIntermediateH(localInvocationIndex,0);
+        v = SpdReduceQuadH(v);
+        // quad index 0 stores result
+        if (localInvocationIndex % 4 == 0)
+        {   
+            SpdStoreH(ASU2(workGroupID.xy), v, mip, slice);
+        }
+    }
+#endif
+}
+
+void SpdDownsampleMips_6_7H(AU1 x, AU1 y, AU1 mips, AU1 slice)
+{
+    ASU2 tex = ASU2(x * 4 + 0, y * 4 + 0);
+    ASU2 pix = ASU2(x * 2 + 0, y * 2 + 0);
+    AH4 v0 = SpdReduceLoad4H(tex, slice);
+    SpdStoreH(pix, v0, 6, slice);
+
+    tex = ASU2(x * 4 + 2, y * 4 + 0);
+    pix = ASU2(x * 2 + 1, y * 2 + 0);
+    AH4 v1 = SpdReduceLoad4H(tex, slice);
+    SpdStoreH(pix, v1, 6, slice);
+
+    tex = ASU2(x * 4 + 0, y * 4 + 2);
+    pix = ASU2(x * 2 + 0, y * 2 + 1);
+    AH4 v2 = SpdReduceLoad4H(tex, slice);
+    SpdStoreH(pix, v2, 6, slice);
+
+    tex = ASU2(x * 4 + 2, y * 4 + 2);
+    pix = ASU2(x * 2 + 1, y * 2 + 1);
+    AH4 v3 = SpdReduceLoad4H(tex, slice);
+    SpdStoreH(pix, v3, 6, slice);
+
+    if (mips < 8) return;
+    // no barrier needed, working on values only from the same thread
+
+    AH4 v = SpdReduce4H(v0, v1, v2, v3);
+    SpdStoreH(ASU2(x, y), v, 7, slice);
+    SpdStoreIntermediateH(x, y, v);
+}
+
+void SpdDownsampleNextFourH(AU1 x, AU1 y, AU2 workGroupID, AU1 localInvocationIndex, AU1 baseMip, AU1 mips, AU1 slice)
+{
+    if (mips <= baseMip) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_2H(x, y, workGroupID, localInvocationIndex, baseMip, slice);
+
+    if (mips <= baseMip + 1) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_3H(x, y, workGroupID, localInvocationIndex, baseMip + 1, slice);
+
+    if (mips <= baseMip + 2) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_4H(x, y, workGroupID, localInvocationIndex, baseMip + 2, slice);
+
+    if (mips <= baseMip + 3) return;
+    SpdWorkgroupShuffleBarrier();
+    SpdDownsampleMip_5H(workGroupID, localInvocationIndex, baseMip + 3, slice);
+}
+
+void SpdDownsampleH(
+    AU2 workGroupID,
+    AU1 localInvocationIndex,
+    AU1 mips,
+    AU1 numWorkGroups,
+    AU1 slice
+) {
+    AU2 sub_xy = ARmpRed8x8(localInvocationIndex % 64);
+    AU1 x = sub_xy.x + 8 * ((localInvocationIndex >> 6) % 2);
+    AU1 y = sub_xy.y + 8 * ((localInvocationIndex >> 7));
+
+    SpdDownsampleMips_0_1H(x, y, workGroupID, localInvocationIndex, mips, slice);
+
+    SpdDownsampleNextFourH(x, y, workGroupID, localInvocationIndex, 2, mips, slice);
+
+    if (mips < 7) return;
+
+    if (SpdExitWorkgroup(numWorkGroups, localInvocationIndex, slice)) return;
+
+    SpdResetAtomicCounter(slice);
+
+    // After mip 6 there is only a single workgroup left that downsamples the remaining up to 64x64 texels.
+    SpdDownsampleMips_6_7H(x, y, mips, slice);
+
+    SpdDownsampleNextFourH(x, y, AU2(0,0), localInvocationIndex, 8, mips, slice);
+}
+
+void SpdDownsampleH(
+    AU2 workGroupID,
+    AU1 localInvocationIndex,
+    AU1 mips,
+    AU1 numWorkGroups,
+    AU1 slice,
+    AU2 workGroupOffset
+) {
+    SpdDownsampleH(workGroupID + workGroupOffset, localInvocationIndex, mips, numWorkGroups, slice);
+}
+
+#endif // #ifdef A_HALF
+#endif // #ifdef A_GPU

+ 2 - 0
Gems/Atom/RPI/Assets/atom_rpi_asset_files.cmake

@@ -12,6 +12,8 @@ set(FILES
     ShaderLib/Atom/RPI/TangentSpace.azsli
     ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultDrawSrg.azsli
     ShaderLib/Atom/RPI/ShaderResourceGroups/DefaultSceneSrg.azsli
+    ShaderLib/External/FidelityFX/ffx-spd/ffx_a.h
+    ShaderLib/External/FidelityFX/ffx-spd/ffx_spd.h
     Shaders/DecomposeMsImage.azsl
     Shaders/DecomposeMsImage.shader
     Shaders/ImagePreview.azsl

+ 2 - 2
Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/ComputePass.h

@@ -47,7 +47,7 @@ namespace AZ
             Data::Instance<Shader> GetShader() const;
 
         protected:
-            ComputePass(const PassDescriptor& descriptor);
+            ComputePass(const PassDescriptor& descriptor, AZ::Name supervariant = AZ::Name(""));
 
             // Pass behavior overrides...
             void FrameBeginInternal(FramePrepareParams params) override;
@@ -78,7 +78,7 @@ namespace AZ
             void OnShaderAssetReinitialized(const Data::Asset<ShaderAsset>& shaderAsset) override;
             void OnShaderVariantReinitialized(const ShaderVariant& shaderVariant) override;
 
-            void LoadShader();
+            void LoadShader(AZ::Name supervariant = AZ::Name(""));
             PassDescriptor m_passDescriptor;
 
         };

+ 92 - 0
Gems/Atom/RPI/Code/Include/Atom/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.h

@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+#pragma once
+
+#include <Atom/RPI.Public/Pass/Pass.h>
+#include <Atom/RPI.Public/Pass/ComputePass.h>
+#include <Atom/RPI.Reflect/Pass/PassDescriptor.h>
+
+namespace AZ::RPI
+{
+    //! This pass takes a texture without auxiliary mip slices as input
+    //! a texture with mip slices as output.
+    //! It then recursively downsamples that mip to lower mip levels using single dispatch of compute shader.
+    class DownsampleSinglePassLuminancePass final
+        : public ComputePass
+    {
+        AZ_RPI_PASS(DownsampleSinglePassMipChainPass);
+
+    public:
+        AZ_RTTI(DownsampleSinglePassMipChainPass, "{6842F4D2-D884-4E2A-B48B-E9240BCB8F45}", ComputePass);
+        AZ_CLASS_ALLOCATOR(DownsampleSinglePassLuminancePass, SystemAllocator, 0);
+
+        static Ptr<DownsampleSinglePassLuminancePass> Create(const PassDescriptor& descriptor);
+        virtual ~DownsampleSinglePassLuminancePass() = default;
+
+    private:
+        struct SpdGlobalAtomicBuffer
+        {
+            uint32_t m_counter;
+        };
+
+        explicit DownsampleSinglePassLuminancePass(const PassDescriptor& descriptor, AZ::Name supervariant);
+
+        // Pass Behaviour Overrides...
+        void BuildInternal() override;
+        void ResetInternal() override;
+        void FrameBeginInternal(FramePrepareParams params) override;
+
+        // Scope producer functions...
+        void CompileResources(const RHI::FrameGraphCompileContext& context) override;
+
+        void BuildGlobalAtomicBuffer();
+        void InitializeIndices();
+        void GetDestinationInfo();
+        void CalculateSpdThreadDimensionAndMips();
+        void BuildPassAttachment();
+
+        void SetConstants();
+
+        static constexpr uint32_t SpdMipLevelCountMax = 13;
+        static constexpr uint32_t GloballyCoherentMipIndex = 6;
+        const Name Mip6Name{"m_mip6"};
+        const Name GlobalAtomicName{"m_globalAtomic"};
+
+        // Dimension of the destination mip chain image.
+        AZStd::array<uint32_t, 2> m_destinationImageSize = {0, 0};
+        uint32_t m_destinationMipLevelCount = 0;
+
+        // Number of mip levels for SPD computation
+        // which can be slightly greater than m_destinationMipLevelCount for
+        // computation of non power of 2 width.
+        uint32_t m_spdMipLevelCount = 0;
+
+        bool m_indicesAreInitialized = false;
+        uint32_t m_targetThreadCountWidth = 1;
+        uint32_t m_targetThreadCountHeight = 1;
+        RHI::ShaderInputConstantIndex m_spdMipLevelCountIndex;
+        RHI::ShaderInputConstantIndex m_destinationMipLevelCountIndex;
+        RHI::ShaderInputConstantIndex m_numWorkGroupsIndex;
+        RHI::ShaderInputConstantIndex m_imageSizeIndex;
+        RHI::ShaderInputImageIndex m_imageDestinationIndex;
+        RHI::ShaderInputImageIndex m_mip6ImageIndex;
+        RHI::ShaderInputBufferIndex m_globalAtomicIndex;
+
+        // Attachment for transient image and its image descriptor.
+        Ptr<PassAttachment> m_mip6PassAttachment;
+        RHI::ImageDescriptor m_mip6ImageDescriptor;
+
+        // Attachment for transient buffer.
+        Ptr<PassAttachment> m_counterPassAttachment;
+
+        // Retainer of image views for each mip level of in/out image.
+        AZStd::array<Ptr<RHI::ImageView>, SpdMipLevelCountMax> m_imageViews;
+
+        Data::Instance<Buffer> m_globalAtomicBuffer;
+    };
+}   // namespace AZ::RPI

+ 3 - 0
Gems/Atom/RPI/Code/Include/Atom/RPI.Reflect/Shader/ShaderCommonTypes.h

@@ -36,6 +36,9 @@ namespace AZ
         //! The NoMSAA supervariant is auto-generated by AZSLc.
         static constexpr const char* NoMsaaSupervariantName = "NoMSAA";
 
+        //! The NoWave supervariant is auto-generated by MCPP.
+        static constexpr const char* NoWaveSupervariantName = "NoWave";
+
         static const SupervariantIndex InvalidSupervariantIndex;
 
         enum class ShaderStageType : uint32_t

+ 4 - 4
Gems/Atom/RPI/Code/Source/RPI.Public/Pass/ComputePass.cpp

@@ -40,7 +40,7 @@ namespace AZ
             return pass;
         }
 
-        ComputePass::ComputePass(const PassDescriptor& descriptor)
+        ComputePass::ComputePass(const PassDescriptor& descriptor, AZ::Name supervariant)
             : RenderPass(descriptor)
             , m_passDescriptor(descriptor)
         {
@@ -58,10 +58,10 @@ namespace AZ
             dispatchArgs.m_totalNumberOfThreadsZ = passData->m_totalNumberOfThreadsZ;
             m_dispatchItem.m_arguments = dispatchArgs;
 
-            LoadShader();
+            LoadShader(supervariant);
         }
 
-        void ComputePass::LoadShader()
+        void ComputePass::LoadShader(AZ::Name supervariant)
         {
             // Load ComputePassData...
             const ComputePassData* passData = PassUtils::GetPassData<ComputePassData>(m_passDescriptor);
@@ -93,7 +93,7 @@ namespace AZ
                 return;
             }
 
-            m_shader = Shader::FindOrCreate(shaderAsset);
+            m_shader = Shader::FindOrCreate(shaderAsset, supervariant);
             if (m_shader == nullptr)
             {
                 AZ_Error("PassSystem", false, "[ComputePass '%s']: Failed to load shader '%s'!",

+ 2 - 0
Gems/Atom/RPI/Code/Source/RPI.Public/Pass/PassFactory.cpp

@@ -14,6 +14,7 @@
 #include <Atom/RPI.Public/Pass/ParentPass.h>
 #include <Atom/RPI.Public/Pass/PassLibrary.h>
 #include <Atom/RPI.Public/Pass/Specific/DownsampleMipChainPass.h>
+#include <Atom/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.h>
 #include <Atom/RPI.Public/Pass/Pass.h>
 #include <Atom/RPI.Public/Pass/PassFactory.h>
 #include <Atom/RPI.Public/Pass/PassFilter.h>
@@ -68,6 +69,7 @@ namespace AZ
             AddPassCreator(Name("MSAAResolvePass"), &MSAAResolvePass::Create);
             AddPassCreator(Name("MSAAResolveFullScreenPass"), &MSAAResolveFullScreenPass::Create);
             AddPassCreator(Name("DownsampleMipChainPass"), &DownsampleMipChainPass::Create);
+            AddPassCreator(Name("DownsampleSinglePassLuminancePass"), &DownsampleSinglePassLuminancePass::Create);
             AddPassCreator(Name("EnvironmentCubeMapPass"), &EnvironmentCubeMapPass::Create);
             AddPassCreator(Name("RenderToTexturePass"), &RenderToTexturePass::Create);
             AddPassCreator(Name("SelectorPass"), &SelectorPass::Create);

+ 269 - 0
Gems/Atom/RPI/Code/Source/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.cpp

@@ -0,0 +1,269 @@
+/*
+ * Copyright (c) Contributors to the Open 3D Engine Project.
+ * For complete copyright and license terms please see the LICENSE at the root of this distribution.
+ *
+ * SPDX-License-Identifier: Apache-2.0 OR MIT
+ *
+ */
+
+#include <Atom/RHI/Factory.h>
+#include <Atom/RHI/RHIUtils.h>
+#include <Atom/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.h>
+#include <Atom/RPI.Reflect/Buffer/BufferAssetCreator.h>
+
+namespace AZ::RPI
+{
+    Ptr<DownsampleSinglePassLuminancePass> DownsampleSinglePassLuminancePass::Create(const PassDescriptor& descriptor)
+    {
+        // Check capability of wave operation
+        bool isWaveSupported = RHI::GetRHIDevice()->GetFeatures().m_waveOperation;
+        const char* supervariantName = isWaveSupported ? "" : AZ::RPI::NoWaveSupervariantName;
+        Ptr<DownsampleSinglePassLuminancePass> pass = aznew DownsampleSinglePassLuminancePass(descriptor, AZ::Name(supervariantName));
+        return pass;
+    }
+
+    DownsampleSinglePassLuminancePass::DownsampleSinglePassLuminancePass(const PassDescriptor& descriptor, AZ::Name supervariant)
+        : ComputePass(descriptor, supervariant)
+    {
+        BuildGlobalAtomicBuffer();
+    }
+
+    void DownsampleSinglePassLuminancePass::BuildInternal()
+    {
+        GetDestinationInfo();
+        CalculateSpdThreadDimensionAndMips();
+        BuildPassAttachment();
+        ComputePass::BuildInternal();
+    }
+
+    void DownsampleSinglePassLuminancePass::ResetInternal()
+    {
+        m_indicesAreInitialized = false;
+        m_spdMipLevelCountIndex.Reset();
+        m_destinationMipLevelCountIndex.Reset();
+        m_numWorkGroupsIndex.Reset();
+        m_imageSizeIndex.Reset();
+        m_imageDestinationIndex.Reset();
+        m_mip6ImageIndex.Reset();
+        m_globalAtomicIndex.Reset();
+        ComputePass::ResetInternal();
+    }
+
+    void DownsampleSinglePassLuminancePass::FrameBeginInternal(FramePrepareParams params)
+    {
+        SetConstants();
+        ComputePass::FrameBeginInternal(params);
+    }
+
+    void DownsampleSinglePassLuminancePass::CompileResources(const RHI::FrameGraphCompileContext& context)
+    {
+        if (!m_shaderResourceGroup)
+        {
+            return;
+        }
+        ShaderResourceGroup& srg = *m_shaderResourceGroup;
+
+        static constexpr uint32_t ThreadGroupSizeX = 256;
+        static constexpr uint32_t ArraySliceCount = 1;
+        SetTargetThreadCounts(m_targetThreadCountWidth * ThreadGroupSizeX,
+            m_targetThreadCountHeight,
+            ArraySliceCount);
+
+        // Input/Output Mip Slices
+        PassAttachmentBinding& outBinding = GetOutputBinding(0);
+        PassAttachment* attachment = outBinding.GetAttachment().get();
+        if (!attachment)
+        {
+            return;
+        }
+        const uint32_t mipLevelCount = attachment->m_descriptor.m_image.m_mipLevels;
+        RHI::AttachmentId attachmentId = attachment->GetAttachmentId();
+        const RHI::Image* rhiImage = context.GetImage(attachmentId);
+        if (!rhiImage)
+        {
+            return;
+        }
+
+        RHI::ResultCode result = RHI::ResultCode::Success;
+        RHI::ImageViewDescriptor imageViewDescriptor;
+        for (uint32_t mipIndex = 0; mipIndex < GetMin(mipLevelCount, SpdMipLevelCountMax); ++mipIndex)
+        {
+            imageViewDescriptor.m_mipSliceMin = static_cast<uint16_t>(mipIndex);
+            imageViewDescriptor.m_mipSliceMax = static_cast<uint16_t>(mipIndex);
+            Ptr<RHI::ImageView> imageView = RHI::Factory::Get().CreateImageView();
+            result = imageView->Init(*rhiImage, imageViewDescriptor);
+            if (result != RHI::ResultCode::Success)
+            {
+                AZ_Assert(false, "DownsampleSingelPassMipChainPass failed to create RHI::ImageView.");
+                return;
+            }
+            srg.SetImageView(m_imageDestinationIndex, imageView.get(), mipIndex);
+            m_imageViews[mipIndex] = imageView;
+        }
+
+        // Set Globally coherent image view.
+        const RHI::ImageView* mip6ImageView = context.GetImageView(m_mip6PassAttachment->GetAttachmentId());
+        srg.SetImageView(m_mip6ImageIndex, mip6ImageView);
+
+        // Set Global Atomic buffer.
+        srg.SetBuffer(m_globalAtomicIndex, m_globalAtomicBuffer);
+
+        ComputePass::CompileResources(context);
+    }
+
+    void DownsampleSinglePassLuminancePass::BuildGlobalAtomicBuffer()
+    {
+        const SpdGlobalAtomicBuffer initialData = {0};
+
+        RPI::CommonBufferDescriptor descriptor;
+        descriptor.m_poolType = RPI::CommonBufferPoolType::ReadWrite;
+        descriptor.m_bufferName = "DownsampleSinglePassMipChainPass GlobalAtomic";
+        descriptor.m_elementSize = sizeof(SpdGlobalAtomicBuffer);
+        descriptor.m_byteCount = sizeof(SpdGlobalAtomicBuffer);
+        descriptor.m_bufferData = reinterpret_cast<const void*>(&initialData);
+        m_globalAtomicBuffer = RPI::BufferSystemInterface::Get()->CreateBufferFromCommonPool(descriptor);
+        AZ_Assert(m_globalAtomicBuffer, "DownsampleSinglePassMipChainPass Building Global Atomic Buffer failed.")
+    }
+
+    void DownsampleSinglePassLuminancePass::InitializeIndices()
+    {
+        if (!m_shaderResourceGroup)
+        {
+            return;
+        }
+        const ShaderResourceGroup& srg = *m_shaderResourceGroup;
+
+        m_spdMipLevelCountIndex = srg.FindShaderInputConstantIndex(Name("m_spdMipLevelCount"));
+        m_destinationMipLevelCountIndex = srg.FindShaderInputConstantIndex(Name("m_destinationMipLevelCount"));
+        m_numWorkGroupsIndex = srg.FindShaderInputConstantIndex(Name("m_numWorkGroups"));
+        m_imageSizeIndex = srg.FindShaderInputConstantIndex(Name("m_imageSize"));
+        m_imageDestinationIndex = srg.FindShaderInputImageIndex(Name("m_imageDestination"));
+        m_mip6ImageIndex = srg.FindShaderInputImageIndex(Mip6Name);
+        m_globalAtomicIndex = srg.FindShaderInputBufferIndex(GlobalAtomicName);
+        m_indicesAreInitialized = true;
+    }
+
+    void DownsampleSinglePassLuminancePass::GetDestinationInfo()
+    {
+        // Get the input attachment for this pass (at binding 0)
+        AZ_Error(
+            "DownsampleSinglePassMipChainPass",
+            GetInputCount() > 0,
+            "[DownsampleSinglePassMipChainPass '%s']: must have an input",
+            GetPathName().GetCStr());
+        PassAttachment* attachment = GetInputBinding(0).GetAttachment().get();
+
+        if (attachment)
+        {
+            m_destinationImageSize[0] = attachment->m_descriptor.m_image.m_size.m_width;
+            m_destinationImageSize[1] = attachment->m_descriptor.m_image.m_size.m_height;
+
+            // m_mipLevels of the attachment has not been initialized yet, so it is calculated below:
+            const uint32_t maxDimension = GetMax(m_destinationImageSize[0], m_destinationImageSize[1]);
+            m_destinationMipLevelCount = static_cast<uint32_t>(floorf(log2f(maxDimension * 1.f)));
+        }
+    }
+
+    void DownsampleSinglePassLuminancePass::CalculateSpdThreadDimensionAndMips()
+    {
+        // Each SPD thread group computes for sub-region of size 64x64 in mip level 0 slice
+        // where 64 == (1 << GloballyCoherentMipIndex).
+        static const uint32_t groupImageWidth = 1 << GloballyCoherentMipIndex;
+        m_targetThreadCountWidth = (m_destinationImageSize[0] + groupImageWidth - 1) / groupImageWidth;
+        m_targetThreadCountHeight = (m_destinationImageSize[1] + groupImageWidth - 1) / groupImageWidth;
+
+        const uint32_t maxDimension = GetMax(m_destinationImageSize[0], m_destinationImageSize[1]);
+        m_spdMipLevelCount = m_destinationMipLevelCount;
+        if (static_cast<uint32_t>(1 << m_spdMipLevelCount) != maxDimension)
+        {
+            ++m_spdMipLevelCount;
+        }
+    }
+
+    void DownsampleSinglePassLuminancePass::BuildPassAttachment()
+    {
+        // Build "Mip6" image attachment.
+        {
+            // SPD stores each mip level value into groupshared float arrays except mip 6,
+            // and do into this "Mip6" image only for mip 6. So the precision of the image
+            // should be same as float variable (32 bit float).
+            m_mip6ImageDescriptor =
+                RHI::ImageDescriptor::Create2D(
+                    RHI::ImageBindFlags::ShaderReadWrite,
+                    m_targetThreadCountWidth,
+                    m_targetThreadCountHeight,
+                    RHI::Format::R32G32B32A32_FLOAT);
+
+            m_mip6PassAttachment = aznew PassAttachment();
+            m_mip6PassAttachment->m_name = "Mip6";
+            const Name attachmentPath(AZStd::string::format(
+                "%s.%s",
+                GetPathName().GetCStr(),
+                m_mip6PassAttachment->m_name.GetCStr()));
+            m_mip6PassAttachment->m_path = attachmentPath;
+            m_mip6PassAttachment->m_lifetime = RHI::AttachmentLifetimeType::Transient;
+            m_mip6PassAttachment->m_descriptor = m_mip6ImageDescriptor;
+            m_ownedAttachments.push_back(m_mip6PassAttachment);
+
+            PassAttachmentBinding binding;
+            binding.m_name = m_mip6PassAttachment->m_name;
+            binding.m_slotType = PassSlotType::InputOutput;
+            binding.m_shaderInputName = Mip6Name;
+            binding.m_scopeAttachmentUsage = RHI::ScopeAttachmentUsage::Shader;
+            binding.SetAttachment(m_mip6PassAttachment);
+            AddAttachmentBinding(binding);
+        }
+
+        // Build "GlobalAtomic" buffer attachment.
+        {
+            auto bufferDescriptor = RHI::BufferDescriptor(RHI::BufferBindFlags::ShaderReadWrite, 4);
+            bufferDescriptor.m_alignment = 4;
+
+            m_counterPassAttachment = aznew PassAttachment();
+            m_counterPassAttachment->m_name = "GlobalAtomic";
+            const Name attachmentPath(AZStd::string::format(
+                    "%s.%s",
+                    GetPathName().GetCStr(),
+                    m_counterPassAttachment->m_name.GetCStr()));
+            m_counterPassAttachment->m_path = attachmentPath;
+            m_counterPassAttachment->m_lifetime = RHI::AttachmentLifetimeType::Imported;
+            m_counterPassAttachment->m_descriptor = bufferDescriptor;
+            m_counterPassAttachment->m_importedResource = m_globalAtomicBuffer;
+            m_ownedAttachments.push_back(m_counterPassAttachment);
+
+            PassAttachmentBinding binding;
+            binding.m_name = m_counterPassAttachment->m_name;
+            binding.m_slotType = PassSlotType::InputOutput;
+            binding.m_shaderInputName = GlobalAtomicName;
+            binding.m_scopeAttachmentUsage = RHI::ScopeAttachmentUsage::Shader;
+            binding.SetAttachment(m_counterPassAttachment);
+            AddAttachmentBinding(binding);
+        }
+    }
+
+    void DownsampleSinglePassLuminancePass::SetConstants()
+    {
+        if (!m_indicesAreInitialized)
+        {
+            InitializeIndices();
+        }
+
+        if (!m_shaderResourceGroup)
+        {
+            return;
+        }
+
+        // For the setting up of the parameter for SPD shader, refer to:
+        // https://github.com/GPUOpen-Effects/FidelityFX-SPD/blob/c52944f547884774a1b33066f740e6bf89f927f5/ffx-spd/ffx_spd.h#L327
+
+        bool succeeded = true;
+        ShaderResourceGroup& srg = *m_shaderResourceGroup;
+        succeeded &= srg.SetConstant(
+            m_numWorkGroupsIndex,
+            m_targetThreadCountWidth * m_targetThreadCountHeight);
+        succeeded &= srg.SetConstant(m_spdMipLevelCountIndex, m_spdMipLevelCount);
+        succeeded &= srg.SetConstant(m_destinationMipLevelCountIndex, m_destinationMipLevelCount);
+        succeeded &= srg.SetConstantArray(m_imageSizeIndex, m_destinationImageSize);
+        AZ_Assert(succeeded, "DownsampleSinglePassMipChainPass failed to set constants.");
+    }
+}   // namespace AZ::RPI

+ 2 - 0
Gems/Atom/RPI/Code/atom_rpi_public_files.cmake

@@ -77,6 +77,7 @@ set(FILES
     Include/Atom/RPI.Public/Pass/MSAAResolvePass.h
     Include/Atom/RPI.Public/Pass/SlowClearPass.h
     Include/Atom/RPI.Public/Pass/Specific/DownsampleMipChainPass.h
+    Include/Atom/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.h
     Include/Atom/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.h
     Include/Atom/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.h
     Include/Atom/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.h
@@ -155,6 +156,7 @@ set(FILES
     Source/RPI.Public/Pass/MSAAResolvePass.cpp
     Source/RPI.Public/Pass/SlowClearPass.cpp
     Source/RPI.Public/Pass/Specific/DownsampleMipChainPass.cpp
+    Source/RPI.Public/Pass/Specific/DownsampleSinglePassLuminancePass.cpp
     Source/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.cpp
     Source/RPI.Public/Pass/Specific/EnvironmentCubeMapPass.cpp
     Source/RPI.Public/Pass/Specific/MSAAResolveFullScreenPass.cpp

+ 2 - 2
Gems/AtomTressFX/Code/Components/EditorHairComponent.cpp

@@ -33,8 +33,8 @@ namespace AZ
                             "Atom Hair", "Controls Hair Properties")
                             ->ClassElement(Edit::ClassElements::EditorData, "")
                                 ->Attribute(Edit::Attributes::Category, "Graphics/Mesh")
-                                ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/Component_Placeholder.svg")
-                                ->Attribute(AZ::Edit::Attributes::ViewportIcon, "editor/icons/components/viewport/component_placeholder.png")
+                                ->Attribute(AZ::Edit::Attributes::Icon, "Icons/Components/Component_Placeholder.svg")
+                                ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Icons/Components/Viewport/Component_Placeholder.svg")
                                 ->Attribute(Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game", 0x232b318c))
                                 ->Attribute(Edit::Attributes::AutoExpand, true)
                             ;

+ 14 - 1
Gems/AudioEngineWwise/CMakeLists.txt

@@ -6,8 +6,21 @@
 #
 #
 
-set(gem_path ${CMAKE_CURRENT_LIST_DIR})
+# Query the gem name from the gem.json file if possible
+# otherwise fallback to using "AudioEngineWwise"
+o3de_find_ancestor_gem_root(gem_path gem_name "${CMAKE_CURRENT_SOURCE_DIR}")
+if (NOT gem_name)
+    set(gem_name "AudioEngineWwise")
+endif()
+
+# Fallback to using the current source CMakeLists.txt directory as the gem root path
+if (NOT gem_path)
+    set(gem_path ${CMAKE_CURRENT_SOURCE_DIR})
+endif()
+
 set(gem_json ${gem_path}/gem.json)
+
 o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)
+o3de_pal_dir(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
 
 add_subdirectory(Code)

+ 95 - 37
Gems/AudioEngineWwise/Code/CMakeLists.txt

@@ -32,16 +32,17 @@ endif()
 # Clients
 ################################################################################
 ly_add_target(
-    NAME AudioEngineWwise.Static STATIC
+    NAME ${gem_name}.Private.Object STATIC
     NAMESPACE Gem
     FILES_CMAKE
         audioenginewwise_files.cmake
         ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
     PLATFORM_INCLUDE_FILES
         ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
+    TARGET_PROPERTIES
+        O3DE_PRIVATE_TARGET TRUE
     INCLUDE_DIRECTORIES
         PRIVATE
-            Source
             Source/Engine
             ${pal_dir}
             ${common_dir}
@@ -52,37 +53,32 @@ ly_add_target(
         PUBLIC
             3rdParty::Wwise
             Legacy::CryCommon
-            Gem::AudioSystem.Static
+            Gem::AudioSystem.API
 )
 
 ly_add_target(
-    NAME AudioEngineWwise ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
+    NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
     NAMESPACE Gem
     FILES_CMAKE
         audioenginewwise_shared_files.cmake
     INCLUDE_DIRECTORIES
         PRIVATE
-            Source
             Source/Engine
             ${pal_dir}
             ${common_dir}
-    COMPILE_DEFINITIONS
-        PUBLIC
-            ${AUDIOENGINEWWISE_COMPILEDEFINITIONS}
     BUILD_DEPENDENCIES
         PRIVATE
-            Gem::AudioEngineWwise.Static
+            Gem::${gem_name}.Private.Object
 )
 
-# we'll load the above "Gem::AudioEngineWwise" module in clients.
-ly_create_alias(NAME AudioEngineWwise.Clients NAMESPACE Gem TARGETS Gem::AudioEngineWwise)
+ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name})
 
 ################################################################################
 # Tests
 ################################################################################
 if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
    ly_add_target(
-        NAME AudioEngineWwise.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
+        NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
         NAMESPACE Gem
         FILES_CMAKE
             audioenginewwise_tests_files.cmake
@@ -90,20 +86,22 @@ if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
         INCLUDE_DIRECTORIES
             PRIVATE
                 Tests
-                Source
                 Source/Engine
                 ${pal_dir}
                 ${common_dir}
         BUILD_DEPENDENCIES
+            PUBLIC
+                Gem::AudioSystem.API
             PRIVATE
                 AZ::AzTest
-                Gem::AudioEngineWwise.Static
+                Gem::${gem_name}.Private.Object
     )
+
     ly_add_googletest(
-        NAME Gem::AudioEngineWwise.Tests
+        NAME Gem::${gem_name}.Tests
     )
 
-    list(APPEND testTargets AudioEngineWwise.Tests)
+    list(APPEND testTargets ${gem_name}.Tests)
 
     ly_add_target_files(
         TARGETS
@@ -114,37 +112,43 @@ if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
             Test.Assets/Gems/AudioEngineWwise/sounds/wwise/soundbanks
     )
 
-endif()
+endif() # PAL_TRAIT_BUILD_TESTS_SUPPORTED
+
 
 ################################################################################
 # Tools / Builders
 ################################################################################
 if (PAL_TRAIT_BUILD_HOST_TOOLS)
     ly_add_target(
-        NAME AudioEngineWwise.Editor.Static STATIC
+        NAME ${gem_name}.Editor.Private.Object STATIC
         NAMESPACE Gem
         AUTORCC
         FILES_CMAKE
             audioenginewwise_editor_files.cmake
+        TARGET_PROPERTIES
+            O3DE_PRIVATE_TARGET TRUE
+        COMPILE_DEFINITIONS
+            PUBLIC
+                ${AUDIOENGINEWWISE_COMPILEDEFINITIONS}
         INCLUDE_DIRECTORIES
             PRIVATE
                 Source/Engine
                 Source/Editor
                 ${pal_dir}
-                Source
         BUILD_DEPENDENCIES
+            PUBLIC
+                3rdParty::Wwise
+                Gem::AudioSystem.Editor.API
+                Legacy::CryCommon
             PRIVATE
                 Legacy::EditorCore
-            PUBLIC
-                AZ::AssetBuilderSDK
-                Gem::AudioEngineWwise.Static
-                Gem::AudioSystem.Editor
+                Gem::${gem_name}.Private.Object
         RUNTIME_DEPENDENCIES
             Gem::AudioSystem.Editor
     )
 
     ly_add_target(
-        NAME AudioEngineWwise.Editor GEM_MODULE
+        NAME ${gem_name}.Editor GEM_MODULE
         NAMESPACE Gem
         FILES_CMAKE
             audioenginewwise_editor_shared_files.cmake
@@ -153,44 +157,98 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
                 AUDIO_ENGINE_WWISE_EDITOR
         INCLUDE_DIRECTORIES
             PRIVATE
-                Source/Builder
                 Source/Engine
                 Source/Editor
                 ${pal_dir}
-                Source
         BUILD_DEPENDENCIES
+            PUBLIC
+                Gem::AudioSystem.API
             PRIVATE
-                Gem::AudioEngineWwise.Editor.Static
+                Gem::${gem_name}.Editor.Private.Object
         RUNTIME_DEPENDENCIES
             Gem::AudioSystem.Editor
     )
 
-    # by default, we'll load the above "Gem::AudioEngineWwise.Editor" module in builders and tools.
-    ly_create_alias(NAME AudioEngineWwise.Builders NAMESPACE Gem TARGETS Gem::AudioEngineWwise.Editor)
-    ly_create_alias(NAME AudioEngineWwise.Tools NAMESPACE Gem TARGETS Gem::AudioEngineWwise.Editor)
+    ly_add_target(
+        NAME ${gem_name}.Builder.Private.Object STATIC
+        NAMESPACE Gem
+        FILES_CMAKE
+            audioenginewwise_builder_files.cmake
+        TARGET_PROPERTIES
+            O3DE_PRIVATE_TARGET TRUE
+        COMPILE_DEFINITIONS
+            PUBLIC
+                ${AUDIOENGINEWWISE_COMPILEDEFINITIONS}
+        INCLUDE_DIRECTORIES
+            PRIVATE
+                Source/Builder
+                Source/Engine
+                ${pal_dir}
+        BUILD_DEPENDENCIES
+            PUBLIC
+                3rdParty::Wwise
+                AZ::AssetBuilderSDK
+                Gem::AudioSystem.API
+            PRIVATE
+                Legacy::EditorCore
+    )
+
+    ly_add_target(
+        NAME ${gem_name}.Builder GEM_MODULE
+        NAMESPACE Gem
+        FILES_CMAKE
+            audioenginewwise_builder_shared_files.cmake
+        COMPILE_DEFINITIONS
+            PRIVATE
+                AUDIO_ENGINE_WWISE_BUILDER
+        INCLUDE_DIRECTORIES
+            PRIVATE
+                Source/Builder
+                Source/Editor
+                Source/Engine
+                ${pal_dir}
+        BUILD_DEPENDENCIES
+            PUBLIC
+                Gem::AudioSystem.API
+                Gem::AudioSystem.Editor.API
+                Legacy::CryCommon
+            PRIVATE
+                Gem::${gem_name}.Builder.Private.Object
+                Gem::${gem_name}.Private.Object
+    )
+
+    ly_create_alias(NAME ${gem_name}.Builders   NAMESPACE Gem TARGETS Gem::${gem_name}.Builder)
+    ly_create_alias(NAME ${gem_name}.Tools      NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
 
     if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
         ly_add_target(
-            NAME AudioEngineWwise.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
+            NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
             NAMESPACE Gem
             FILES_CMAKE
                 audioenginewwise_editor_tests_files.cmake
+                audioenginewwise_editor_shared_files.cmake
             INCLUDE_DIRECTORIES
                 PRIVATE
                     Tests
+                    Source/Builder
                     Source/Editor
-                    Source
+                    Source/Engine
+                    ${pal_dir}
             BUILD_DEPENDENCIES
+                PUBLIC
+                    Gem::AudioSystem.API
                 PRIVATE
                     AZ::AzTest
-                    Gem::AudioEngineWwise.Editor.Static
+                    Gem::${gem_name}.Editor.Private.Object
+                    Gem::${gem_name}.Builder.Private.Object
                     Legacy::CryCommon
         )
+
         ly_add_googletest(
-            NAME Gem::AudioEngineWwise.Editor.Tests
+            NAME Gem::${gem_name}.Editor.Tests
         )
 
-        list(APPEND editorTestTargets AudioEngineWwise.Editor.Tests)
+        list(APPEND editorTestTargets ${gem_name}.Editor.Tests)
 
         ly_add_target_files(
             TARGETS
@@ -243,5 +301,5 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
                 Test.Assets/Gems/AudioEngineWwise/sounds/wwise
         )
 
-    endif()
-endif()
+    endif() # PAL_TRAIT_BUILD_TESTS_SUPPORTED
+endif() # PAL_TRAIT_BUILD_HOST_TOOLS

+ 1 - 2
Gems/AudioEngineWwise/Code/Source/AudioEngineWwiseGemSystemComponent.cpp

@@ -6,9 +6,8 @@
  *
  */
 
-#include <AudioEngineWwiseGemSystemComponent.h>
+#include "AudioEngineWwiseGemSystemComponent.h"
 
-#include <AzCore/PlatformDef.h>
 #include <AzCore/Console/ILogger.h>
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzCore/Serialization/EditContext.h>

+ 9 - 6
Gems/AudioEngineWwise/Code/Source/AudioEngineWwiseModule.cpp

@@ -11,12 +11,12 @@
 #include <AzCore/Memory/SystemAllocator.h>
 #include <IGem.h>
 
-#include <AudioEngineWwiseGemSystemComponent.h>
+#include "AudioEngineWwiseGemSystemComponent.h"
 
-#if defined(AUDIO_ENGINE_WWISE_EDITOR)
+#if defined(AUDIO_ENGINE_WWISE_BUILDER)
     #include <AudioControlBuilderComponent.h>
     #include <WwiseBuilderComponent.h>
-#endif // AUDIO_ENGINE_WWISE_EDITOR
+#endif // AUDIO_ENGINE_WWISE_BUILDER
 
 namespace AudioEngineWwiseGem
 {
@@ -31,11 +31,12 @@ namespace AudioEngineWwiseGem
             : CryHooksModule()
         {
             m_descriptors.insert(m_descriptors.end(), {
-                AudioEngineWwiseGemSystemComponent::CreateDescriptor(),
-            #if defined(AUDIO_ENGINE_WWISE_EDITOR)
+            #if defined(AUDIO_ENGINE_WWISE_BUILDER)
                 AudioControlBuilder::BuilderPluginComponent::CreateDescriptor(),
                 WwiseBuilder::BuilderPluginComponent::CreateDescriptor(),
-            #endif // AUDIO_ENGINE_WWISE_EDITOR
+            #else
+                AudioEngineWwiseGemSystemComponent::CreateDescriptor(),
+            #endif // AUDIO_ENGINE_WWISE_BUILDER
             });
         }
 
@@ -45,7 +46,9 @@ namespace AudioEngineWwiseGem
         AZ::ComponentTypeList GetRequiredSystemComponents() const override
         {
             return AZ::ComponentTypeList {
+            #if !defined(AUDIO_ENGINE_WWISE_BUILDER)
                 azrtti_typeid<AudioEngineWwiseGemSystemComponent>(),
+            #endif // !AUDIO_ENGINE_WWISE_BUILDER
             };
         }
     };

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderComponent.cpp

@@ -6,7 +6,7 @@
  *
  */
 
-#include <Builder/AudioControlBuilderComponent.h>
+#include <AudioControlBuilderComponent.h>
 
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzCore/Serialization/EditContextConstants.inl>

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderComponent.h

@@ -9,7 +9,7 @@
 #pragma once
 
 #include <AzCore/Component/Component.h>
-#include <Builder/AudioControlBuilderWorker.h>
+#include <AudioControlBuilderWorker.h>
 
 namespace AudioControlBuilder
 {

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/AudioControlBuilderWorker.cpp

@@ -6,7 +6,7 @@
  *
  */
 
-#include <Builder/AudioControlBuilderWorker.h>
+#include <AudioControlBuilderWorker.h>
 
 #include <AzCore/AzCore_Traits_Platform.h>
 #include <AzCore/IO/SystemFile.h>

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderComponent.cpp

@@ -6,7 +6,7 @@
  *
  */
 
-#include <Builder/WwiseBuilderComponent.h>
+#include <WwiseBuilderComponent.h>
 
 #include <AzCore/Serialization/SerializeContext.h>
 #include <AzCore/Serialization/EditContextConstants.inl>

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderComponent.h

@@ -9,7 +9,7 @@
 #pragma once
 
 #include <AzCore/Component/Component.h>
-#include <Builder/WwiseBuilderWorker.h>
+#include <WwiseBuilderWorker.h>
 
 namespace WwiseBuilder
 {

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderWorker.cpp

@@ -6,7 +6,7 @@
  *
  */
 
-#include <Builder/WwiseBuilderWorker.h>
+#include <WwiseBuilderWorker.h>
 
 #include <AzCore/Debug/Trace.h>
 #include <AzCore/IO/FileIO.h>

+ 1 - 1
Gems/AudioEngineWwise/Code/Source/Builder/WwiseBuilderWorker.h

@@ -12,7 +12,7 @@
 #include <AssetBuilderSDK/AssetBuilderBusses.h>
 #include <AssetBuilderSDK/AssetBuilderSDK.h>
 
-#include <Engine/Config_wwise.h>
+#include <Config_wwise.h>
 
 namespace WwiseBuilder
 {

+ 0 - 1
Gems/AudioEngineWwise/Code/Source/Engine/AudioSystemImpl_wwise.cpp

@@ -2132,4 +2132,3 @@ namespace Audio
     }
 
 } // namespace Audio
-

+ 1 - 1
Gems/AudioEngineWwise/Code/Tests/AudioControlBuilderTest.cpp

@@ -8,7 +8,7 @@
 
 #include <AzTest/AzTest.h>
 #include <AzTest/Utils.h>
-#include <Builder/AudioControlBuilderComponent.h>
+#include <AudioControlBuilderComponent.h>
 
 #include <AzCore/IO/FileIO.h>
 #include <AzFramework/IO/LocalFileIO.h>

+ 1 - 1
Gems/AudioEngineWwise/Code/Tests/AudioEngineWwiseBuilderTest.cpp

@@ -8,7 +8,7 @@
 
 #include <AzTest/AzTest.h>
 #include <AzTest/Utils.h>
-#include <Builder/WwiseBuilderComponent.h>
+#include <WwiseBuilderComponent.h>
 
 #include <AzCore/IO/FileIO.h>
 #include <AzCore/IO/Path/Path.h>

+ 18 - 0
Gems/AudioEngineWwise/Code/audioenginewwise_builder_files.cmake

@@ -0,0 +1,18 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+set(FILES
+    Source/Builder/AudioControlBuilderComponent.cpp
+    Source/Builder/AudioControlBuilderComponent.h
+    Source/Builder/AudioControlBuilderWorker.cpp
+    Source/Builder/AudioControlBuilderWorker.h
+    Source/Builder/WwiseBuilderComponent.cpp
+    Source/Builder/WwiseBuilderComponent.h
+    Source/Builder/WwiseBuilderWorker.cpp
+    Source/Builder/WwiseBuilderWorker.h
+)

+ 11 - 0
Gems/AudioEngineWwise/Code/audioenginewwise_builder_shared_files.cmake

@@ -0,0 +1,11 @@
+#
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+#
+
+set(FILES
+    Source/AudioEngineWwiseModule.cpp
+)

+ 0 - 8
Gems/AudioEngineWwise/Code/audioenginewwise_editor_files.cmake

@@ -8,14 +8,6 @@
 
 set(FILES
     Source/Editor/EditorWwise.qrc
-    Source/Builder/AudioControlBuilderComponent.cpp
-    Source/Builder/AudioControlBuilderComponent.h
-    Source/Builder/AudioControlBuilderWorker.cpp
-    Source/Builder/AudioControlBuilderWorker.h
-    Source/Builder/WwiseBuilderComponent.cpp
-    Source/Builder/WwiseBuilderComponent.h
-    Source/Builder/WwiseBuilderWorker.cpp
-    Source/Builder/WwiseBuilderWorker.h
     Source/Editor/AudioSystemControl_wwise.cpp
     Source/Editor/AudioSystemEditor_wwise.cpp
     Source/Editor/AudioWwiseLoader.cpp

+ 1 - 1
Gems/AudioEngineWwise/Code/audioenginewwise_editor_shared_files.cmake

@@ -7,7 +7,7 @@
 #
 
 set(FILES
-    Source/AudioEngineWwiseModule.cpp
     Source/AudioEngineWwiseGemSystemComponent.cpp
     Source/AudioEngineWwiseGemSystemComponent.h
+    Source/AudioEngineWwiseModule.cpp
 )

+ 14 - 22
Gems/AudioEngineWwise/Code/audioenginewwise_files.cmake

@@ -7,22 +7,6 @@
 #
 
 set(FILES
-    Source/AudioEngineWwiseGemSystemComponent.cpp
-    Source/AudioEngineWwiseGemSystemComponent.h
-    Source/Engine/ATLEntities_wwise.h
-    Source/Engine/AudioSourceManager.h
-    Source/Engine/AudioSystemImpl_wwise.h
-    Source/Engine/AudioSystemImplCVars.h
-    Source/Engine/Common_wwise.h
-    Source/Engine/Config_wwise.h
-    Source/Engine/FileIOHandler_wwise.h
-    Source/Engine/PluginRegistration_wwise.h
-    Source/Engine/AudioSourceManager.cpp
-    Source/Engine/AudioSystemImpl_wwise.cpp
-    Source/Engine/AudioSystemImplCVars.cpp
-    Source/Engine/Common_wwise.cpp
-    Source/Engine/Config_wwise.cpp
-    Source/Engine/FileIOHandler_wwise.cpp
     Source/Engine/AudioInput/AudioInputFile.cpp
     Source/Engine/AudioInput/AudioInputFile.h
     Source/Engine/AudioInput/AudioInputMicrophone.cpp
@@ -31,10 +15,18 @@ set(FILES
     Source/Engine/AudioInput/AudioInputStream.h
     Source/Engine/AudioInput/WavParser.cpp
     Source/Engine/AudioInput/WavParser.h
+    Source/Engine/ATLEntities_wwise.h
+    Source/Engine/AudioSourceManager.cpp
+    Source/Engine/AudioSourceManager.h
+    Source/Engine/AudioSystemImpl_wwise.cpp
+    Source/Engine/AudioSystemImpl_wwise.h
+    Source/Engine/AudioSystemImplCVars.cpp
+    Source/Engine/AudioSystemImplCVars.h
+    Source/Engine/Common_wwise.cpp
+    Source/Engine/Common_wwise.h
+    Source/Engine/Config_wwise.cpp
+    Source/Engine/Config_wwise.h
+    Source/Engine/FileIOHandler_wwise.cpp
+    Source/Engine/FileIOHandler_wwise.h
+    Source/Engine/PluginRegistration_wwise.h
 )
-   
-# Skip the following file that is also used in the editor shared target so the compiler will recognize its the same symbol
-set(SKIP_UNITY_BUILD_INCLUSION_FILES
-    Source/AudioEngineWwiseGemSystemComponent.cpp
-)
-

+ 7 - 0
Gems/AudioEngineWwise/Code/audioenginewwise_shared_files.cmake

@@ -7,5 +7,12 @@
 #
 
 set(FILES
+    Source/AudioEngineWwiseGemSystemComponent.cpp
+    Source/AudioEngineWwiseGemSystemComponent.h
     Source/AudioEngineWwiseModule.cpp
 )
+
+# Skip the following file that is also used in the editor shared target so the compiler will recognize its the same symbol
+set(SKIP_UNITY_BUILD_INCLUSION_FILES
+    Source/AudioEngineWwiseGemSystemComponent.cpp
+)

+ 14 - 1
Gems/AudioSystem/CMakeLists.txt

@@ -6,8 +6,21 @@
 #
 #
 
-set(gem_path ${CMAKE_CURRENT_LIST_DIR})
+# Query the gem name from the gem.json file if possible
+# otherwise fallback to using "AudioSystem"
+o3de_find_ancestor_gem_root(gem_path gem_name "${CMAKE_CURRENT_SOURCE_DIR}")
+if (NOT gem_name)
+    set(gem_name "AudioSystem")
+endif()
+
+# Fallback to using the current source CMakeLists.txt directory as the gem root path
+if (NOT gem_path)
+    set(gem_path ${CMAKE_CURRENT_SOURCE_DIR})
+endif()
+
 set(gem_json ${gem_path}/gem.json)
+
 o3de_restricted_path(${gem_json} gem_restricted_path gem_parent_relative_path)
+o3de_pal_dir(pal_dir ${CMAKE_CURRENT_SOURCE_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
 
 add_subdirectory(Code)

+ 93 - 56
Gems/AudioSystem/Code/CMakeLists.txt

@@ -12,55 +12,71 @@ set(AUDIOSYSTEM_COMPILEDEFINITIONS
 
 o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")
 
+################################################################################
+# Client Targets
+################################################################################
+ly_add_target(
+    NAME ${gem_name}.API INTERFACE
+    NAMESPACE Gem
+    FILES_CMAKE
+        audiosystem_api_files.cmake
+    INCLUDE_DIRECTORIES
+        INTERFACE
+            Include/Engine
+    BUILD_DEPENDENCIES
+        INTERFACE
+            AZ::AzCore
+)
+
 ly_add_target(
-    NAME AudioSystem.Static STATIC
+    NAME ${gem_name}.Private.Object STATIC
     NAMESPACE Gem
     FILES_CMAKE
         audiosystem_files.cmake
         ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
+    TARGET_PROPERTIES
+        O3DE_PRIVATE_TARGET TRUE
     INCLUDE_DIRECTORIES
         PRIVATE
-            Source
+            Include/Engine
             Source/Engine
             ${pal_dir}
-        PUBLIC
-            Include
-            Include/Engine
     PLATFORM_INCLUDE_FILES
             ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}.cmake
     COMPILE_DEFINITIONS
         PUBLIC
             ${AUDIOSYSTEM_COMPILEDEFINITIONS}
     BUILD_DEPENDENCIES
-        PRIVATE
-            Legacy::CryCommon
+        PUBLIC
+            AZ::AzCore
+            AZ::AzFramework
+            Gem::${gem_name}.API
             Gem::Atom_RPI.Public
+            Legacy::CryCommon # Temporary, needs to be removed
 )
 
 ly_add_target(
-    NAME AudioSystem ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
+    NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE}
     NAMESPACE Gem
     FILES_CMAKE
         audiosystem_shared_files.cmake
     INCLUDE_DIRECTORIES
         PRIVATE
-            Source
             Source/Engine
             ${pal_dir}
-        PUBLIC
-            Include
-            Include/Engine
     COMPILE_DEFINITIONS
         PUBLIC
             ${AUDIOSYSTEM_COMPILEDEFINITIONS}
     BUILD_DEPENDENCIES
+        PUBLIC
+            Gem::${gem_name}.API
         PRIVATE
-            Legacy::CryCommon
-            Gem::AudioSystem.Static
+            Gem::${gem_name}.Private.Object
 )
 
-# AudioSystem should use the above target on clients.
-ly_create_alias(NAME AudioSystem.Clients  NAMESPACE Gem TARGETS Gem::AudioSystem)
+# AudioSystem aliases for Clients (no Servers)
+ly_create_alias(NAME ${gem_name}.Clients        NAMESPACE Gem TARGETS Gem::${gem_name})
+ly_create_alias(NAME ${gem_name}.Clients.API    NAMESPACE Gem TARGETS Gem::${gem_name}.API)
 
 ################################################################################
 # Tests
@@ -68,7 +84,7 @@ ly_create_alias(NAME AudioSystem.Clients  NAMESPACE Gem TARGETS Gem::AudioSystem
 if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
     set(common_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/Common)
     ly_add_target(
-        NAME AudioSystem.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
+        NAME ${gem_name}.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
         NAMESPACE Gem
         FILES_CMAKE
             audiosystem_tests_files.cmake
@@ -76,23 +92,21 @@ if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
         INCLUDE_DIRECTORIES
             PRIVATE
                 Tests
-                Source
                 Source/Engine
-                Include/Engine
         BUILD_DEPENDENCIES
+            PUBLIC
+                Gem::${gem_name}.API
             PRIVATE
                 AZ::AzTest
-                AZ::AzFramework
-                Legacy::CryCommon
-                Gem::AudioSystem.Static
-        RUNTIME_DEPENDENCIES
-            Gem::LmbrCentral
+                Gem::${gem_name}.Private.Object
+                Legacy::CryCommon   # Temporary, needs to be removed
     )
+
     ly_add_googletest(
-        NAME Gem::AudioSystem.Tests
+        NAME Gem::${gem_name}.Tests
     )
 
-    list(APPEND testTargets AudioSystem.Tests)
+    list(APPEND testTargets ${gem_name}.Tests)
 
     ly_add_target_files(
         TARGETS
@@ -158,91 +172,114 @@ if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
         OUTPUT_SUBDIRECTORY
             Test.Assets/Gems/AudioSystem/ATLData/OneOne
     )
-endif ()
+
+endif() # PAL_TRAIT_BUILD_TESTS_SUPPORTED
+
 
 ################################################################################
 # Editor
 ################################################################################
 if (PAL_TRAIT_BUILD_HOST_TOOLS)
     ly_add_target(
-        NAME AudioSystem.Editor.Static STATIC
+        NAME ${gem_name}.Editor.API INTERFACE
+        NAMESPACE Gem
+        FILES_CMAKE
+            audiosystem_editor_api_files.cmake
+        INCLUDE_DIRECTORIES
+            INTERFACE
+                Include/Editor
+        BUILD_DEPENDENCIES
+            INTERFACE
+                AZ::AzCore
+    )
+
+    ly_add_target(
+        NAME ${gem_name}.Editor.Private.Object STATIC
         NAMESPACE Gem
         AUTOMOC
         AUTOUIC
         AUTORCC
         FILES_CMAKE
             audiosystem_editor_files.cmake
+        TARGET_PROPERTIES
+            O3DE_PRIVATE_TARGET TRUE
         INCLUDE_DIRECTORIES
             PRIVATE
-                .
-                Source
+                .               # <-- This is needed for Automoc, Autouic, Autorcc
                 Source/Engine
-                Include/Engine
                 Source/Editor
                 ${pal_dir}
-            PUBLIC
-                Include/Editor
         COMPILE_DEFINITIONS
             PUBLIC
-                AUDIO_SYSTEM_EDITOR
+                ${AUDIOSYSTEM_COMPILEDEFINITIONS}
         BUILD_DEPENDENCIES
             PUBLIC
-                3rdParty::Qt::Core
-                3rdParty::Qt::Gui
-                3rdParty::Qt::Widgets
                 AZ::AzCore
                 AZ::AzToolsFramework
-                Legacy::CryCommon
                 Legacy::EditorCore
                 Legacy::EditorCommon
-                Gem::AudioSystem.Static
-                Gem::Atom_RPI.Public
+                Gem::${gem_name}.API
+                Gem::${gem_name}.Editor.API
+                Legacy::CryCommon   # Temporary, needs to be removed
+            PRIVATE
+                Gem::${gem_name}.Private.Object
+                3rdParty::Qt::Core
+                3rdParty::Qt::Widgets
+                3rdParty::Qt::Gui
     )
-    ly_add_target(
-        NAME AudioSystem.Editor GEM_MODULE
 
+    ly_add_target(
+        NAME ${gem_name}.Editor GEM_MODULE
         NAMESPACE Gem
         FILES_CMAKE
             audiosystem_editor_shared_files.cmake
         INCLUDE_DIRECTORIES
             PRIVATE
-                Source
                 Source/Editor
-            PUBLIC
-                Include/Editor
+                Source/Engine
+        COMPILE_DEFINITIONS
+            PRIVATE
+                AUDIO_SYSTEM_EDITOR
         BUILD_DEPENDENCIES
+            PUBLIC
+                Gem::${gem_name}.API
+                Gem::${gem_name}.Editor.API
             PRIVATE
                 3rdParty::Qt::Core
-                Gem::AudioSystem.Editor.Static
+                Gem::Atom_RPI.Public
+                Gem::${gem_name}.Editor.Private.Object
     )
 
     # use the above "Editor" target in tools and builders:
-    ly_create_alias(NAME AudioSystem.Tools    NAMESPACE Gem TARGETS Gem::AudioSystem.Editor)
-    ly_create_alias(NAME AudioSystem.Builders NAMESPACE Gem TARGETS Gem::AudioSystem.Editor)
+    ly_create_alias(NAME ${gem_name}.Tools    NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
+    ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}.Editor)
 
     if (PAL_TRAIT_BUILD_TESTS_SUPPORTED)
         ly_add_target(
-            NAME AudioSystem.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
+            NAME ${gem_name}.Editor.Tests ${PAL_TRAIT_TEST_TARGET_TYPE}
             NAMESPACE Gem
             FILES_CMAKE
                 audiosystem_editor_tests_files.cmake
+                audiosystem_editor_shared_files.cmake
             INCLUDE_DIRECTORIES
                 PRIVATE
                     Tests
                     Source/Editor
-                    Source/Audio
-                    Source
+                    Source/Engine
             BUILD_DEPENDENCIES
+                PUBLIC
+                    Gem::${gem_name}.API
+                    Gem::${gem_name}.Editor.API
                 PRIVATE
                     AZ::AzTest
                     3rdParty::Qt::Core
-                    Gem::AudioSystem.Editor.Static
+                    Gem::Atom_RPI.Public
+                    Gem::${gem_name}.Editor.Private.Object
         )
+
         ly_add_googletest(
             NAME Gem::AudioSystem.Editor.Tests
         )
-    endif()
-endif ()
-
-
 
+    endif() # PAL_TRAIT_BUILD_TESTS_SUPPORTED
+endif() # PAL_TRAIT_BUILD_HOST_TOOLS

+ 0 - 0
Code/Legacy/CryCommon/IAudioInterfacesCommonData.h → Gems/AudioSystem/Code/Include/Engine/IAudioInterfacesCommonData.h


+ 0 - 0
Code/Legacy/CryCommon/IAudioSystem.h → Gems/AudioSystem/Code/Include/Engine/IAudioSystem.h


+ 0 - 0
Code/Legacy/CryCommon/MicrophoneBus.h → Gems/AudioSystem/Code/Include/Engine/MicrophoneBus.h


+ 0 - 0
Code/Legacy/CryCommon/NullAudioSystem.h → Gems/AudioSystem/Code/Include/Engine/NullAudioSystem.h


+ 1 - 1
Gems/AudioSystem/Code/Source/AudioSystemGemSystemComponent.cpp

@@ -6,7 +6,7 @@
  *
  */
 
-#include <AudioSystemGemSystemComponent.h>
+#include "AudioSystemGemSystemComponent.h"
 
 #include <AzCore/Console/IConsole.h>
 #include <AzCore/Console/ILogger.h>

+ 1 - 1
Gems/AudioSystem/Code/Source/AudioSystemModule.cpp

@@ -11,7 +11,7 @@
 #include <AzCore/Memory/SystemAllocator.h>
 #include <IGem.h>
 
-#include <AudioSystemGemSystemComponent.h>
+#include "AudioSystemGemSystemComponent.h"
 
 namespace AudioSystemGem
 {

+ 0 - 1
Gems/AudioSystem/Code/Source/Engine/AudioProxy.cpp

@@ -11,7 +11,6 @@
 
 #include <ATLCommon.h>
 #include <SoundCVars.h>
-#include <MathConversion.h>
 
 namespace Audio
 {

+ 18 - 0
Gems/AudioSystem/Code/audiosystem_api_files.cmake

@@ -0,0 +1,18 @@
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+set(FILES
+    Include/Engine/ATLCommon.h
+    Include/Engine/ATLEntityData.h
+    Include/Engine/AudioAllocators.h
+    Include/Engine/AudioFileUtils.h
+    Include/Engine/AudioRingBuffer.h
+    Include/Engine/IAudioInterfacesCommonData.h
+    Include/Engine/IAudioSystem.h
+    Include/Engine/IAudioSystemImplementation.h
+    Include/Engine/MicrophoneBus.h
+    Include/Engine/NullAudioSystem.h
+)

+ 12 - 0
Gems/AudioSystem/Code/audiosystem_editor_api_files.cmake

@@ -0,0 +1,12 @@
+# Copyright (c) Contributors to the Open 3D Engine Project.
+# For complete copyright and license terms please see the LICENSE at the root of this distribution.
+#
+# SPDX-License-Identifier: Apache-2.0 OR MIT
+#
+
+set(FILES
+    Include/Editor/ACETypes.h
+    Include/Editor/IAudioConnection.h
+    Include/Editor/IAudioSystemControl.h
+    Include/Editor/IAudioSystemEditor.h
+)

+ 0 - 6
Gems/AudioSystem/Code/audiosystem_editor_files.cmake

@@ -25,10 +25,6 @@ set(FILES
     Source/Editor/QSimpleAudioControlListWidget.h
     Source/Editor/QTreeWidgetFilter.cpp
     Source/Editor/QTreeWidgetFilter.h
-    Include/Editor/ACETypes.h
-    Include/Editor/IAudioConnection.h
-    Include/Editor/IAudioSystemControl.h
-    Include/Editor/IAudioSystemEditor.h
     Source/Editor/ATLControlsModel.cpp
     Source/Editor/ATLControlsPanel.cpp
     Source/Editor/ATLControlsResourceDialog.cpp
@@ -58,6 +54,4 @@ set(FILES
     Source/Editor/AudioSystemPanel.h
     Source/Editor/ImplementationManager.h
     Source/Editor/InspectorPanel.h
-    Source/AudioSystemGemSystemComponent.cpp
-    Source/AudioSystemGemSystemComponent.h
 )

+ 2 - 0
Gems/AudioSystem/Code/audiosystem_editor_shared_files.cmake

@@ -7,5 +7,7 @@
 #
 
 set(FILES
+    Source/AudioSystemGemSystemComponent.cpp
+    Source/AudioSystemGemSystemComponent.h
     Source/AudioSystemModule.cpp
 )

+ 0 - 1
Gems/AudioSystem/Code/audiosystem_editor_tests_files.cmake

@@ -8,5 +8,4 @@
 
 set(FILES
     Tests/AudioSystemEditorTest.cpp
-    Source/AudioSystemModule.cpp
 )

+ 9 - 15
Gems/AudioSystem/Code/audiosystem_files.cmake

@@ -7,28 +7,22 @@
 #
 
 set(FILES
-    Include/Engine/ATLEntityData.h
-    Include/Engine/AudioAllocators.h
-    Include/Engine/AudioFileUtils.h
-    Include/Engine/AudioRingBuffer.h
-    Include/Engine/ATLCommon.h
-    Include/Engine/IAudioSystemImplementation.h
-    Source/Engine/ATL.h
-    Source/Engine/ATLAudioObject.h
-    Source/Engine/ATLComponents.h
-    Source/Engine/ATLEntities.h
-    Source/Engine/ATLUtils.h
-    Source/Engine/AudioProxy.h
-    Source/Engine/AudioSystem.h
-    Source/Engine/FileCacheManager.h
-    Source/Engine/SoundCVars.h
     Source/Engine/ATL.cpp
+    Source/Engine/ATL.h
     Source/Engine/ATLAudioObject.cpp
+    Source/Engine/ATLAudioObject.h
     Source/Engine/ATLComponents.cpp
+    Source/Engine/ATLComponents.h
     Source/Engine/ATLEntities.cpp
+    Source/Engine/ATLEntities.h
     Source/Engine/ATLUtils.cpp
+    Source/Engine/ATLUtils.h
     Source/Engine/AudioProxy.cpp
+    Source/Engine/AudioProxy.h
     Source/Engine/AudioSystem.cpp
+    Source/Engine/AudioSystem.h
     Source/Engine/FileCacheManager.cpp
+    Source/Engine/FileCacheManager.h
     Source/Engine/SoundCVars.cpp
+    Source/Engine/SoundCVars.h
 )

+ 12 - 2
Gems/HttpRequestor/Code/Source/HttpRequestManager.cpp

@@ -35,7 +35,14 @@ namespace HttpRequestor
         desc.m_name = s_loggingName;
         desc.m_cpuId = AFFINITY_MASK_USERTHREADS;
         m_runThread = true;
-        AWSNativeSDKInit::InitializationManager::InitAwsApi();
+
+        // Multiple different Gems might try to use the AWSNativeSDK, so make sure it only gets initialized / shutdown once
+        // by the first Gem to try using it.
+        m_ownsAwsNativeInitialization = !AWSNativeSDKInit::InitializationManager::IsInitialized();
+        if (m_ownsAwsNativeInitialization)
+        {
+            AWSNativeSDKInit::InitializationManager::InitAwsApi();
+        }
         auto function = [this]
         {
             ThreadFunction();
@@ -53,7 +60,10 @@ namespace HttpRequestor
         }
 
         // Shutdown after background thread has closed.
-        AWSNativeSDKInit::InitializationManager::Shutdown();
+        if (m_ownsAwsNativeInitialization)
+        {
+            AWSNativeSDKInit::InitializationManager::Shutdown();
+        }
     }
 
     void Manager::AddRequest(Parameters&& httpRequestParameters)

+ 1 - 0
Gems/HttpRequestor/Code/Source/HttpRequestManager.h

@@ -53,6 +53,7 @@ namespace HttpRequestor
         AZStd::atomic<bool>                     m_runThread;                        // Run flag used to signal the worker thread
         AZStd::thread                           m_thread;                           // This is the thread that will be used for all async operations
         static const char*                      s_loggingName;                      // Name to use for log messages etc...
+        bool                                    m_ownsAwsNativeInitialization = false; // Whether or not this module initialized the native layer
     };
 
     using ManagerPtr = AZStd::shared_ptr<Manager>;

+ 3 - 0
Gems/LmbrCentral/Code/CMakeLists.txt

@@ -26,6 +26,8 @@ ly_add_target(
         PRIVATE
             Legacy::CryCommon
             AZ::AzFramework
+        PUBLIC
+            Gem::AudioSystem.API
 )
 
 ly_add_target(
@@ -86,6 +88,7 @@ if (PAL_TRAIT_BUILD_HOST_TOOLS)
                 Legacy::Editor.Headers
                 AZ::AzToolsFramework
                 AZ::AssetBuilderSDK
+                Gem::AudioSystem.API
     )
 
     ly_add_target(

+ 2 - 0
Gems/Maestro/Code/CMakeLists.txt

@@ -19,6 +19,8 @@ ly_add_target(
     BUILD_DEPENDENCIES
         PRIVATE
             Legacy::CryCommon
+        PUBLIC
+            Gem::AudioSystem.API
 )
 
 ly_add_target(

+ 1 - 2
Gems/Microphone/Code/CMakeLists.txt

@@ -20,9 +20,8 @@ ly_add_target(
         PUBLIC
             Source
     BUILD_DEPENDENCIES
-        PRIVATE
-            Gem::AudioSystem.Static
         PUBLIC
+            Gem::AudioSystem.API
             3rdParty::libsamplerate
             Legacy::CryCommon
     COMPILE_DEFINITIONS

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/LocalPredictionPlayerInput.svg


Diferenças do arquivo suprimidas por serem muito extensas
+ 2 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkBinding.svg


+ 3 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkCharacter.svg

@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M8.66983 1.85144C10.248 1.85144 11.6764 2.42976 12.7085 3.36416C13.5674 2.64139 14.6643 2.20789 15.8595 2.20789C18.613 2.20789 20.845 4.50851 20.845 7.34648C20.845 7.9153 20.7554 8.46252 20.5898 8.97396C21.5246 9.91729 22.1152 11.3047 22.1152 12.8514C22.1152 15.6935 20.1214 17.9974 17.6618 17.9974C17.5349 17.9974 17.4093 17.9913 17.2851 17.9793C17.2586 17.9798 17.232 17.98 17.2054 17.98H6.9373C6.81574 17.9916 6.6928 17.9974 6.56867 17.9974C4.1091 17.9974 2.11523 15.6935 2.11523 12.8514C2.11523 11.3902 2.6423 10.0712 3.48874 9.13451C3.15585 8.48184 2.97021 7.75548 2.97021 6.99004C2.97021 4.15207 5.52202 1.85144 8.66983 1.85144ZM22.1153 20.8477V19.8477H15.0533C15.0512 19.2971 14.6043 18.8514 14.0533 18.8514H10.1153C9.5643 18.8514 9.11737 19.2971 9.11533 19.8477H2.11532L2.11532 20.8477H9.11532V21C9.11532 21.5523 9.56304 22 10.1153 22H14.0533C14.6055 22 15.0533 21.5523 15.0533 21V20.8477H22.1153ZM13.888 16.1233V9.02601H16.6152V7.2344H6.61523V9.02601H9.34251V16.1233H11.1607V12.5677H12.0698V16.1233H13.888ZM10.2516 5.45662C10.2516 6.193 10.8621 6.78995 11.6152 6.78995C12.3684 6.78995 12.9789 6.193 12.9789 5.45662C12.9789 4.72024 12.3684 4.12329 11.6152 4.12329C10.8621 4.12329 10.2516 4.72024 10.2516 5.45662Z" fill="#D179BD"/>
+</svg>

Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHierarchyChild.svg


Diferenças do arquivo suprimidas por serem muito extensas
+ 1 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHierarchyRoot.svg


+ 3 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkHitVolumes.svg

@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M12.1817 3.43844C11.1496 2.50404 9.72119 1.92572 8.14297 1.92572C4.99516 1.92572 2.44336 4.22635 2.44336 7.06432C2.44336 7.82976 2.62899 8.55612 2.96189 9.20879C2.11545 10.1455 1.58838 11.4645 1.58838 12.9257C1.58838 15.7678 3.58225 18.0717 6.04181 18.0717C6.16594 18.0717 6.28889 18.0658 6.41045 18.0543H16.6785C16.7052 18.0543 16.7317 18.0541 16.7582 18.0536C16.8824 18.0656 17.0081 18.0717 17.1349 18.0717C19.5945 18.0717 21.5884 15.7678 21.5884 12.9257C21.5884 11.3789 20.9978 9.99157 20.063 9.04824C20.2285 8.5368 20.3182 7.98958 20.3182 7.42076C20.3182 4.58279 18.0861 2.28217 15.3327 2.28217C14.1375 2.28217 13.0405 2.71567 12.1817 3.43844ZM21.5885 19.9219V20.9219H14.5264V21.0743C14.5264 21.6266 14.0787 22.0743 13.5264 22.0743H9.58847C9.03618 22.0743 8.58847 21.6266 8.58847 21.0743V20.9219H1.58847L1.58847 19.9219H8.58847C8.59051 19.3714 9.03744 18.9257 9.58847 18.9257H13.5264C14.0774 18.9257 14.5244 19.3714 14.5264 19.9219H21.5885ZM17.5547 7.22466L11.6827 4.22052L5.58838 7.22466L5.6221 13.9647L11.6785 17.2205L17.5884 14.1651L17.5547 7.22466ZM6.43994 13.6097V7.88283L11.3088 5.4313L11.3088 6.91376L11.586 6.8042L11.8633 6.91376L11.8633 5.30881L16.7216 7.88283V13.8104L11.6829 16.5773L6.43994 13.6097ZM7.3141 13.6105V9.3561L11.5777 7.06349L15.8554 9.3561V13.6105L11.5737 16.0558L7.3141 13.6105ZM8.10596 13.0994V10.1235L11.1142 11.7325V14.8569L8.10596 13.0994ZM15.0708 13.1089V10.1627L12.0172 11.734V14.8765L15.0708 13.1089Z" fill="#D179BD"/>
+</svg>

+ 3 - 0
Gems/Multiplayer/Assets/Editor/Icons/Components/NetworkRigidBody.svg

@@ -0,0 +1,3 @@
+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path fill-rule="evenodd" clip-rule="evenodd" d="M8.55435 1.92572C10.1326 1.92572 11.561 2.50404 12.5931 3.43844C13.4519 2.71567 14.5488 2.28217 15.7441 2.28217C18.4975 2.28217 20.7296 4.58279 20.7296 7.42076C20.7296 7.98958 20.6399 8.5368 20.4743 9.04824C21.4092 9.99157 21.9998 11.3789 21.9998 12.9257C21.9998 15.7678 20.0059 18.0717 17.5463 18.0717C17.4194 18.0717 17.2938 18.0656 17.1696 18.0536C17.1431 18.0541 17.1165 18.0543 17.0899 18.0543H6.82182C6.70026 18.0658 6.57732 18.0717 6.45319 18.0717C3.99363 18.0717 1.99976 15.7678 1.99976 12.9257C1.99976 11.4645 2.52682 10.1455 3.37327 9.20879C3.04037 8.55612 2.85474 7.82976 2.85474 7.06432C2.85474 4.22635 5.40654 1.92572 8.55435 1.92572ZM21.9998 20.9219V19.9219H14.9378C14.9357 19.3714 14.4888 18.9257 13.9378 18.9257H9.99984C9.44882 18.9257 9.00189 19.3714 8.99985 19.9219H1.99984L1.99984 20.9219H8.99984V21.0743C8.99984 21.6266 9.44756 22.0743 9.99984 22.0743H13.9378C14.4901 22.0743 14.9378 21.6266 14.9378 21.0743V20.9219H21.9998ZM10.9999 10.5H5.49989V16H10.9999V10.5ZM15.495 8.00006L19.3841 11.8891L15.5491 15.8316L11.66 11.9425L15.495 8.00006ZM14.3464 5.78919L9.17811 3.90808L7.33699 9.09077L12.5053 10.9719L14.3464 5.78919Z" fill="#D179BD"/>
+</svg>

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff