-
Notifications
You must be signed in to change notification settings - Fork 21
/
FSR1.0-For-URP10.6.0-Patch.patch
4505 lines (4476 loc) · 272 KB
/
FSR1.0-For-URP10.6.0-Patch.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineCameraEditor.cs b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineCameraEditor.cs
index b5a8b52e2c..81fce48bb9 100644
--- a/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineCameraEditor.cs
+++ b/com.unity.render-pipelines.universal/Editor/UniversalRenderPipelineCameraEditor.cs
@@ -47,6 +47,7 @@ namespace UnityEditor.Rendering.Universal
public static GUIContent volumeTrigger = EditorGUIUtility.TrTextContent("Volume Trigger", "A transform that will act as a trigger for volume blending. If none is set, the camera itself will act as a trigger.");
public static GUIContent renderPostProcessing = EditorGUIUtility.TrTextContent("Post Processing", "Enable this to make this camera render post-processing effects.");
+ public static GUIContent AMDFSR = EditorGUIUtility.TrTextContent("AMD FSR 1.0", "AMD FidelityFX Super Resolution 1.0 is a cutting edge super-optimized spatial upscaling technology that produces impressive image quality at fast framerates.");
public static GUIContent antialiasing = EditorGUIUtility.TrTextContent("Anti-aliasing", "The anti-aliasing method to use.");
public static GUIContent antialiasingQuality = EditorGUIUtility.TrTextContent("Quality", "The quality level to use for the selected anti-aliasing method.");
public static GUIContent stopNaN = EditorGUIUtility.TrTextContent("Stop NaN", "Automatically replaces NaN/Inf in shaders by a black pixel to avoid breaking some effects. This will affect performances and should only be used if you experience NaN issues that you can't fix. Has no effect on GLES2 platforms.");
@@ -139,6 +140,7 @@ namespace UnityEditor.Rendering.Universal
SerializedProperty m_AdditionalCameraDataVolumeLayerMask;
SerializedProperty m_AdditionalCameraDataVolumeTrigger;
SerializedProperty m_AdditionalCameraDataRenderPostProcessing;
+ SerializedProperty m_AdditionalCameraDataRenderAMDFSR;
SerializedProperty m_AdditionalCameraDataAntialiasing;
SerializedProperty m_AdditionalCameraDataAntialiasingQuality;
SerializedProperty m_AdditionalCameraDataStopNaN;
@@ -416,6 +418,7 @@ namespace UnityEditor.Rendering.Universal
m_AdditionalCameraDataVolumeLayerMask = m_AdditionalCameraDataSO.FindProperty("m_VolumeLayerMask");
m_AdditionalCameraDataVolumeTrigger = m_AdditionalCameraDataSO.FindProperty("m_VolumeTrigger");
m_AdditionalCameraDataRenderPostProcessing = m_AdditionalCameraDataSO.FindProperty("m_RenderPostProcessing");
+ m_AdditionalCameraDataRenderAMDFSR = m_AdditionalCameraDataSO.FindProperty("m_AMDFSR");
m_AdditionalCameraDataAntialiasing = m_AdditionalCameraDataSO.FindProperty("m_Antialiasing");
m_AdditionalCameraDataAntialiasingQuality = m_AdditionalCameraDataSO.FindProperty("m_AntialiasingQuality");
m_AdditionalCameraDataStopNaN = m_AdditionalCameraDataSO.FindProperty("m_StopNaN");
@@ -820,6 +823,8 @@ namespace UnityEditor.Rendering.Universal
void DrawPostProcessing()
{
EditorGUILayout.PropertyField(m_AdditionalCameraDataRenderPostProcessing, Styles.renderPostProcessing);
+ if (m_AdditionalCameraDataRenderPostProcessing.boolValue)
+ EditorGUILayout.PropertyField(m_AdditionalCameraDataRenderAMDFSR, Styles.AMDFSR);
// Draw Final Post-processing
DrawIntPopup(m_AdditionalCameraDataAntialiasing, Styles.antialiasing, Styles.antialiasingOptions, Styles.antialiasingValues);
diff --git a/com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.cs b/com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.cs
index 3229a87476..4ace94fb6f 100644
--- a/com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.cs
+++ b/com.unity.render-pipelines.universal/Runtime/Data/PostProcessData.cs
@@ -64,6 +64,11 @@ namespace UnityEngine.Rendering.Universal
[Reload("Shaders/PostProcessing/FinalPost.shader")]
public Shader finalPostPassPS;
+
+ [Reload("Shaders/PostProcessing/EdgeAdaptiveSpatialUpsampling.compute")]
+ public ComputeShader easuCS;
+ [Reload("Shaders/PostProcessing/RobustContrastAdaptiveSharpen.compute")]
+ public ComputeShader rcasCS;
}
[Serializable, ReloadGroup]
diff --git a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs
index 16f4876cec..0dfd63e500 100644
--- a/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs
+++ b/com.unity.render-pipelines.universal/Runtime/ForwardRenderer.cs
@@ -478,8 +478,8 @@ namespace UnityEngine.Rendering.Universal
bool lastCameraInTheStack = cameraData.resolveFinalTarget;
bool hasCaptureActions = renderingData.cameraData.captureActions != null && lastCameraInTheStack;
- bool applyFinalPostProcessing = anyPostProcessing && lastCameraInTheStack &&
- renderingData.cameraData.antialiasing == AntialiasingMode.FastApproximateAntialiasing;
+ bool applyFinalPostProcessing = anyPostProcessing && lastCameraInTheStack && (
+ (renderingData.cameraData.antialiasing == AntialiasingMode.FastApproximateAntialiasing) || (renderingData.cameraData.enableFSR));
// When post-processing is enabled we can use the stack to resolve rendering to camera target (screen or RT).
// However when there are render passes executing after post we avoid resolving to screen so rendering continues (before sRGBConvertion etc)
@@ -505,7 +505,7 @@ namespace UnityEngine.Rendering.Universal
// Do FXAA or any other final post-processing effect that might need to run after AA.
if (applyFinalPostProcessing)
{
- m_FinalPostProcessPass.SetupFinalPass(sourceForFinalPass);
+ m_FinalPostProcessPass.SetupFinalPass(sourceForFinalPass, cameraTargetDescriptor);
EnqueuePass(m_FinalPostProcessPass);
}
diff --git a/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs b/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs
index 94c00822cc..3171f92864 100644
--- a/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs
+++ b/com.unity.render-pipelines.universal/Runtime/Passes/PostProcessPass.cs
@@ -126,7 +126,20 @@ namespace UnityEngine.Rendering.Universal.Internal
m_ResetHistory = true;
}
- public void Cleanup() => m_Materials.Cleanup();
+ public void Cleanup()
+ {
+ m_Materials.Cleanup();
+ if (easuCB != null)
+ {
+ easuCB.Release();
+ easuCB = null;
+ }
+ if (rcasCB != null)
+ {
+ rcasCB.Release();
+ rcasCB = null;
+ }
+ }
public void Setup(in RenderTextureDescriptor baseDescriptor, in RenderTargetHandle source, in RenderTargetHandle destination, in RenderTargetHandle depth, in RenderTargetHandle internalLut, bool hasFinalPass, bool enableSRGBConversion)
{
@@ -142,18 +155,30 @@ namespace UnityEngine.Rendering.Universal.Internal
m_EnableSRGBConversionIfNeeded = enableSRGBConversion;
}
- public void SetupFinalPass(in RenderTargetHandle source)
+ public void SetupFinalPass(in RenderTargetHandle source, in RenderTextureDescriptor finalDesc = new RenderTextureDescriptor())
{
m_Source = source;
m_Destination = RenderTargetHandle.CameraTarget;
m_IsFinalPass = true;
m_HasFinalPass = false;
m_EnableSRGBConversionIfNeeded = true;
+ m_Descriptor = finalDesc;
}
+ ComputeBuffer easuCB;
+ ComputeBuffer rcasCB;
/// <inheritdoc/>
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
{
+ var enableFSR = renderingData.cameraData.enableFSR;
+ if(enableFSR)
+ {
+ if (easuCB == null)
+ easuCB = new ComputeBuffer(4, sizeof(uint) * 4);
+ if (rcasCB == null)
+ rcasCB = new ComputeBuffer(4, sizeof(uint) * 4);
+ }
+
if (m_Destination == RenderTargetHandle.CameraTarget)
return;
@@ -245,6 +270,17 @@ namespace UnityEngine.Rendering.Universal.Internal
RenderTextureDescriptor GetCompatibleDescriptor()
=> GetCompatibleDescriptor(m_Descriptor.width, m_Descriptor.height, m_Descriptor.graphicsFormat, m_Descriptor.depthBufferBits);
+ RenderTextureDescriptor GetUAVCompatibleDescriptor(int width, int height)
+ {
+ var desc = m_Descriptor;
+ desc.depthBufferBits = 0;
+ desc.msaaSamples = 1;
+ desc.width = width;
+ desc.height = height;
+ desc.enableRandomWrite = true;
+ return desc;
+ }
+
RenderTextureDescriptor GetCompatibleDescriptor(int width, int height, GraphicsFormat format, int depthBufferBits = 0)
{
var desc = m_Descriptor;
@@ -1227,17 +1263,112 @@ namespace UnityEngine.Rendering.Universal.Internal
// Note: We need to get the cameraData.targetTexture as this will get the targetTexture of the camera stack.
// Overlay cameras need to output to the target described in the base camera while doing camera stack.
RenderTargetIdentifier cameraTarget = (cameraData.targetTexture != null) ? new RenderTargetIdentifier(cameraData.targetTexture) : cameraTargetHandle.Identifier();
+ var oldCameraTarget = cameraTarget;
+ var enableFSR = cameraData.enableFSR;
+ if (enableFSR)
+ {
+ oldCameraTarget = cameraTarget;
+ cmd.GetTemporaryRT(ShaderConstants._EASUInputTexture, GetCompatibleDescriptor());
+ cameraTarget = ShaderConstants._EASUInputTexture;
+ }
cmd.SetRenderTarget(cameraTarget, colorLoadAction, RenderBufferStoreAction.Store, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare);
cmd.SetViewProjectionMatrices(Matrix4x4.identity, Matrix4x4.identity);
- cmd.SetViewport(cameraData.pixelRect);
+ if(!enableFSR)
+ cmd.SetViewport(cameraData.pixelRect);
cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, material);
cmd.SetViewProjectionMatrices(cameraData.camera.worldToCameraMatrix, cameraData.camera.projectionMatrix);
+
+ if (enableFSR)
+ DoFSR(cmd, ref cameraData, oldCameraTarget);
}
}
#endregion
+ #region EASU
+ void EdgeAdaptiveSpatialUpsampling(CommandBuffer cmd, CameraData cameraData, bool needs_convert_to_srgb)
+ {
+ var easuCS = m_Data.shaders.easuCS;
+ if (needs_convert_to_srgb)
+ {
+ easuCS.EnableKeyword("_AMD_FSR_NEEDS_CONVERT_TO_SRGB");
+ }
+ else
+ {
+ easuCS.DisableKeyword("_AMD_FSR_NEEDS_CONVERT_TO_SRGB");
+ }
+ int viewCount = 1;
+ int kinitialize_idx = easuCS.FindKernel("KInitialize");
+ int kmain_idx = easuCS.FindKernel("KMain");
+ cmd.SetComputeTextureParam(easuCS, kmain_idx, ShaderConstants._EASUInputTexture, ShaderConstants._EASUInputTexture);
+ int srcWidth = m_Descriptor.width;
+ int srcHeight = m_Descriptor.height;
+ int dstWidth = cameraData.pixelWidth;
+ int dstHeight = cameraData.pixelHeight;
+ cmd.SetComputeVectorParam(easuCS, ShaderConstants._EASUViewportSize, new Vector4(srcWidth, srcHeight));
+ cmd.SetComputeVectorParam(easuCS, ShaderConstants._EASUInputImageSize, new Vector4(srcWidth, srcHeight));
+ cmd.GetTemporaryRT(ShaderConstants._EASUOutputTexture, GetUAVCompatibleDescriptor(dstWidth, dstHeight));
+ cmd.SetComputeTextureParam(easuCS, kmain_idx, ShaderConstants._EASUOutputTexture, ShaderConstants._EASUOutputTexture);
+ cmd.SetComputeVectorParam(easuCS, ShaderConstants._EASUOutputSize, new Vector4(dstWidth, dstHeight, 1.0f / dstWidth, 1.0f / dstHeight));
+ cmd.SetComputeBufferParam(easuCS, kinitialize_idx, ShaderConstants._EASUParameters, easuCB);
+ cmd.SetComputeBufferParam(easuCS, kmain_idx, ShaderConstants._EASUParameters, easuCB);
+ cmd.DispatchCompute(easuCS, kinitialize_idx, 1, 1, 1);
+ int DivRoundUp(int x, int y) => (x + y - 1) / y;
+ int dispatchX = DivRoundUp((int)dstWidth, 8);
+ int dispatchY = DivRoundUp((int)dstHeight, 8);
+
+ cmd.DispatchCompute(easuCS, kmain_idx, dispatchX, dispatchY, viewCount);
+ }
+ #endregion
+
+ #region RCAS
+ void RobustContrastAdaptiveSharpening(CommandBuffer cmd, CameraData cameraData, bool needs_convert_to_srgb)
+ {
+ var rcasCS = m_Data.shaders.rcasCS;
+ if (needs_convert_to_srgb)
+ {
+ rcasCS.EnableKeyword("_AMD_FSR_NEEDS_CONVERT_TO_SRGB");
+ }
+ else
+ {
+ rcasCS.DisableKeyword("_AMD_FSR_NEEDS_CONVERT_TO_SRGB");
+ }
+ int viewCount = 1;
+ int kinitialize_idx = rcasCS.FindKernel("KInitialize");
+ int kmain_idx = rcasCS.FindKernel("KMain");
+
+ cmd.SetComputeFloatParam(rcasCS, ShaderConstants._RCASScale, 1.0f);
+ cmd.SetComputeTextureParam(rcasCS, kmain_idx, ShaderConstants._RCASInputTexture, ShaderConstants._EASUOutputTexture);
+ int dstWidth = cameraData.pixelWidth;
+ int dstHeight = cameraData.pixelHeight;
+ cmd.GetTemporaryRT(ShaderConstants._RCASOutputTexture, GetUAVCompatibleDescriptor(dstWidth, dstHeight));
+ cmd.SetComputeTextureParam(rcasCS, kmain_idx, ShaderConstants._RCASOutputTexture, ShaderConstants._RCASOutputTexture);
+ cmd.SetComputeBufferParam(rcasCS, kinitialize_idx, ShaderConstants._RCASParameters, rcasCB);
+ cmd.SetComputeBufferParam(rcasCS, kmain_idx, ShaderConstants._RCASParameters, rcasCB);
+ cmd.DispatchCompute(rcasCS, kinitialize_idx, 1, 1, 1);
+
+ int DivRoundUp(int x, int y) => (x + y - 1) / y;
+ int dispatchX = DivRoundUp((int)dstWidth, 8);
+ int dispatchY = DivRoundUp((int)dstHeight, 8);
+
+ cmd.DispatchCompute(rcasCS, kmain_idx, dispatchX, dispatchY, viewCount);
+ }
+ #endregion
+
+ #region FSR
+ void DoFSR(CommandBuffer cmd, ref CameraData cameraData, RenderTargetIdentifier dst)
+ {
+ bool needs_convert_to_srgb = !(cameraData.isHdrEnabled || QualitySettings.activeColorSpace == ColorSpace.Gamma);
+ using (new ProfilingScope(cmd, ProfilingSampler.Get(URPProfileId.FSR)))
+ {
+ EdgeAdaptiveSpatialUpsampling(cmd, cameraData, needs_convert_to_srgb);
+ RobustContrastAdaptiveSharpening(cmd, cameraData, needs_convert_to_srgb);
+ }
+ cmd.Blit(ShaderConstants._RCASOutputTexture, dst);
+ }
+ #endregion
+
#region Internal utilities
class MaterialLibrary
@@ -1339,6 +1470,20 @@ namespace UnityEngine.Rendering.Universal.Internal
public static readonly int _FullscreenProjMat = Shader.PropertyToID("_FullscreenProjMat");
+ // Edge Adaptive Spatial Upsampling
+ public static readonly int _EASUInputTexture = Shader.PropertyToID("_EASUInputTexture");
+ public static readonly int _EASUOutputTexture = Shader.PropertyToID("_EASUOutputTexture");
+ public static readonly int _EASUViewportSize = Shader.PropertyToID("_EASUViewportSize");
+ public static readonly int _EASUInputImageSize = Shader.PropertyToID("_EASUInputImageSize");
+ public static readonly int _EASUOutputSize = Shader.PropertyToID("_EASUOutputSize");
+ public static readonly int _EASUParameters = Shader.PropertyToID("_EASUParameters");
+
+ // Robust Contrast Adaptive Sharpening
+ public static readonly int _RCASInputTexture = Shader.PropertyToID("_RCASInputTexture");
+ public static readonly int _RCASScale = Shader.PropertyToID("_RCASScale");
+ public static readonly int _RCASParameters = Shader.PropertyToID("_RCASParameters");
+ public static readonly int _RCASOutputTexture = Shader.PropertyToID("_RCASOutputTexture");
+
public static int[] _BloomMipUp;
public static int[] _BloomMipDown;
}
diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalCameraData.cs b/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalCameraData.cs
index eede40c373..5323c4b691 100644
--- a/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalCameraData.cs
+++ b/com.unity.render-pipelines.universal/Runtime/UniversalAdditionalCameraData.cs
@@ -130,6 +130,15 @@ namespace UnityEngine.Rendering.Universal
[SerializeField] Transform m_VolumeTrigger = null;
[SerializeField] bool m_RenderPostProcessing = false;
+ public enum AMDFSR
+ {
+ Disabled = -1,
+ UltraQuality = 0,
+ Quality,
+ Balanced,
+ Performance
+ }
+ [SerializeField] AMDFSR m_AMDFSR = AMDFSR.Disabled;
[SerializeField] AntialiasingMode m_Antialiasing = AntialiasingMode.None;
[SerializeField] AntialiasingQuality m_AntialiasingQuality = AntialiasingQuality.High;
[SerializeField] bool m_StopNaN = false;
@@ -356,6 +365,11 @@ namespace UnityEngine.Rendering.Universal
get => m_RenderPostProcessing;
set => m_RenderPostProcessing = value;
}
+ public AMDFSR amdFSR
+ {
+ get => m_AMDFSR;
+ set => m_AMDFSR = value;
+ }
/// <summary>
/// Returns the current anti-aliasing mode used by this camera.
diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs
index 5c6101eb8b..984d5088f5 100644
--- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs
+++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs
@@ -487,6 +487,8 @@ namespace UnityEngine.Rendering.Universal
// Update volumeframework before initializing additional camera data
UpdateVolumeFramework(baseCamera, baseCameraAdditionalData);
InitializeCameraData(baseCamera, baseCameraAdditionalData, !isStackedRendering, out var baseCameraData);
+ if (baseCameraAdditionalData.amdFSR != UniversalAdditionalCameraData.AMDFSR.Disabled && !isStackedRendering)
+ baseCameraData.enableFSR = true;
#if ENABLE_VR && ENABLE_XR_MODULE
var originalTargetDesc = baseCameraData.cameraTargetDescriptor;
@@ -555,6 +557,8 @@ namespace UnityEngine.Rendering.Universal
#endif
UpdateVolumeFramework(currCamera, currCameraData);
InitializeAdditionalCameraData(currCamera, currCameraData, lastCamera, ref overlayCameraData);
+ if (baseCameraAdditionalData.amdFSR != UniversalAdditionalCameraData.AMDFSR.Disabled && lastCamera)
+ overlayCameraData.enableFSR = true;
#if ENABLE_VR && ENABLE_XR_MODULE
if (baseCameraData.xr.enabled)
m_XRSystem.UpdateFromCamera(ref overlayCameraData.xr, overlayCameraData);
@@ -690,6 +694,24 @@ namespace UnityEngine.Rendering.Universal
cameraData.isHdrEnabled, msaaSamples, needsAlphaChannel, cameraData.requiresOpaqueTexture);
}
+ private struct AMDFSRSettings
+ {
+ public readonly float m_RenderScale;
+ public readonly float m_MipmapBias;
+ public AMDFSRSettings(in float render_scale, in float mipmap_bias)
+ {
+ m_RenderScale = render_scale;
+ m_MipmapBias = mipmap_bias;
+ }
+ };
+ private static readonly AMDFSRSettings[] amdFSRSettingsPreset = new AMDFSRSettings[]
+ {
+ new AMDFSRSettings(.77f, -.38f),
+ new AMDFSRSettings(.67f, -.58f),
+ new AMDFSRSettings(.59f, -.79f),
+ new AMDFSRSettings(.50f, -1.0f)
+ };
+
/// <summary>
/// Initialize camera data settings common for all cameras in the stack. Overlay cameras will inherit
/// settings from base camera.
@@ -860,6 +882,17 @@ namespace UnityEngine.Rendering.Universal
}
cameraData.SetViewAndProjectionMatrix(camera.worldToCameraMatrix, projectionMatrix);
+
+ if (additionalCameraData != null)
+ {
+ if (additionalCameraData.amdFSR != UniversalAdditionalCameraData.AMDFSR.Disabled)
+ {
+ settings.msaaSampleCount = 8; // NOTE! You can also use some other AA solutions.
+ var amdFSRSetting = amdFSRSettingsPreset[(int)additionalCameraData.amdFSR];
+ cameraData.renderScale = amdFSRSetting.m_RenderScale;
+ Shader.SetGlobalFloat("amd_fsr_mipmap_bias", amdFSRSetting.m_MipmapBias);
+ }
+ }
}
static void InitializeRenderingData(UniversalRenderPipelineAsset settings, ref CameraData cameraData, ref CullingResults cullResults,
diff --git a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs
index 790855af5d..99ac49eb2d 100644
--- a/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs
+++ b/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipelineCore.cs
@@ -191,6 +191,8 @@ namespace UnityEngine.Rendering.Universal
/// When rendering a stack of cameras only the last camera in the stack will resolve to camera target.
/// </summary>
public bool resolveFinalTarget;
+
+ public bool enableFSR;
}
[MovedFrom("UnityEngine.Rendering.LWRP")] public struct ShadowData
@@ -733,6 +735,7 @@ namespace UnityEngine.Rendering.Universal
PaniniProjection,
UberPostProcess,
Bloom,
+ FSR,
FinalBlit
}
diff --git a/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl b/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl
index e835d9bffb..26d39cba63 100644
--- a/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl
+++ b/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl
@@ -30,7 +30,11 @@ half Alpha(half albedoAlpha, half4 color, half cutoff)
half4 SampleAlbedoAlpha(float2 uv, TEXTURE2D_PARAM(albedoAlphaMap, sampler_albedoAlphaMap))
{
+#ifdef _AMD_FSR
+ return SAMPLE_TEXTURE2D_BIAS(albedoAlphaMap, sampler_albedoAlphaMap, uv, amd_fsr_mipmap_bias);
+#else
return SAMPLE_TEXTURE2D(albedoAlphaMap, sampler_albedoAlphaMap, uv);
+#endif
}
half3 SampleNormal(float2 uv, TEXTURE2D_PARAM(bumpMap, sampler_bumpMap), half scale = 1.0h)
diff --git a/com.unity.render-pipelines.universal/Shaders/PostProcessing/EdgeAdaptiveSpatialUpsampling.compute b/com.unity.render-pipelines.universal/Shaders/PostProcessing/EdgeAdaptiveSpatialUpsampling.compute
new file mode 100644
index 0000000000..fa5a0db39f
--- /dev/null
+++ b/com.unity.render-pipelines.universal/Shaders/PostProcessing/EdgeAdaptiveSpatialUpsampling.compute
@@ -0,0 +1,92 @@
+#pragma kernel KMain
+#pragma kernel KInitialize
+
+#pragma multi_compile _ ENABLE_ALPHA _AMD_FSR_HALF _AMD_FSR_NEEDS_CONVERT_TO_SRGB
+#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
+
+#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
+
+#include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/amd_fsr.hlsl"
+
+// 4 elements:
+// [0] = const0
+// [1] = const1
+// [0] = const2
+// [1] = const3
+// ComputeBuffer is allocated with stride sizeof(int)*4, 4 elements
+RWStructuredBuffer<uint4> _EASUParameters;
+
+float4 _EASUViewportSize;
+float4 _EASUInputImageSize;
+float4 _EASUOutputSize;
+
+SamplerState s_linear_clamp_sampler;
+TEXTURE2D_X(_EASUInputTexture);
+RWTexture2D<float4> _EASUOutputTexture;
+
+#ifdef _AMD_FSR_HALF
+AH4 FsrEasuRH(AF2 p) { return AH4(AMD_FSR_TO_SRGB(GATHER_RED_TEXTURE2D_X(_EASUInputTexture, s_linear_clamp_sampler, p))); }
+AH4 FsrEasuGH(AF2 p){ return AH4(AMD_FSR_TO_SRGB(GATHER_GREEN_TEXTURE2D_X(_EASUInputTexture, s_linear_clamp_sampler, p))); }
+AH4 FsrEasuBH(AF2 p){ return AH4(AMD_FSR_TO_SRGB(GATHER_BLUE_TEXTURE2D_X (_EASUInputTexture, s_linear_clamp_sampler, p))); }
+#else
+AF4 FsrEasuRF(AF2 p){ return AMD_FSR_TO_SRGB(GATHER_RED_TEXTURE2D_X (_EASUInputTexture, s_linear_clamp_sampler, p)); }
+AF4 FsrEasuGF(AF2 p){ return AMD_FSR_TO_SRGB(GATHER_GREEN_TEXTURE2D_X(_EASUInputTexture, s_linear_clamp_sampler, p)); }
+AF4 FsrEasuBF(AF2 p){ return AMD_FSR_TO_SRGB(GATHER_BLUE_TEXTURE2D_X (_EASUInputTexture, s_linear_clamp_sampler, p)); }
+#endif
+
+[numthreads(64, 1, 1)]
+void KMain(uint3 LocalThreadId : SV_GroupThreadID, uint3 WorkGroupId : SV_GroupID, uint3 dispatchThreadId : SV_DispatchThreadID)
+{
+ // Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
+ AU2 gxy = ARmp8x8(LocalThreadId.x) + AU2(WorkGroupId.x<<3u, WorkGroupId.y<<3u);
+
+#ifdef ENABLE_ALPHA
+ AREAL alpha = LOAD_TEXTURE2D_X(_EASUInputTexture, gxy.xy).a;
+#else
+ AREAL alpha = 1.0;
+#endif
+
+ AU4 con0 = _EASUParameters[0];
+ AU4 con1 = _EASUParameters[1];
+ AU4 con2 = _EASUParameters[2];
+ AU4 con3 = _EASUParameters[3];
+ AF4 c;
+
+#ifdef _AMD_FSR_HALF
+ AH3 out_rgb;
+ FsrEasuH(out_rgb, gxy, con0, con1, con2, con3);
+#else
+ AF3 out_rgb;
+ FsrEasuF(out_rgb, gxy, con0, con1, con2, con3);
+#endif
+
+ c.rgb = out_rgb;
+
+ c.a = alpha;
+ _EASUOutputTexture[gxy] = c;
+}
+
+
+/*
+Doing this to avoid having to deal with any CPU side compilation of the headers.
+The FsrRcasCon is doing some extra parameter packing (log space / pows etc) so its better
+to keep this all in the GPU for simplicity sake, and avoid paying this cost for every wave.
+The headers also dont compile for c#, they are meant for c and c++.
+*/
+[numthreads(1,1,1)]
+void KInitialize()
+{
+ AU4 con0 = (AU4)0;
+ AU4 con1 = (AU4)0;
+ AU4 con2 = (AU4)0;
+ AU4 con3 = (AU4)0;
+ FsrEasuCon(con0,con1,con2,con3,
+ _EASUViewportSize.x, _EASUViewportSize.y,
+ _EASUInputImageSize.x,_EASUInputImageSize.y,
+ _EASUOutputSize.x, _EASUOutputSize.y);
+
+ _EASUParameters[0] = con0;
+ _EASUParameters[1] = con1;
+ _EASUParameters[2] = con2;
+ _EASUParameters[3] = con3;
+}
diff --git a/com.unity.render-pipelines.universal/Shaders/PostProcessing/RobustContrastAdaptiveSharpen.compute b/com.unity.render-pipelines.universal/Shaders/PostProcessing/RobustContrastAdaptiveSharpen.compute
new file mode 100644
index 0000000000..a751164ac1
--- /dev/null
+++ b/com.unity.render-pipelines.universal/Shaders/PostProcessing/RobustContrastAdaptiveSharpen.compute
@@ -0,0 +1,74 @@
+#pragma kernel KMain
+#pragma kernel KInitialize
+
+#pragma multi_compile _ ENABLE_ALPHA _AMD_FSR_HALF _AMD_FSR_NEEDS_CONVERT_TO_SRGB
+#pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
+
+
+#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
+
+#include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/amd_fsr.hlsl"
+
+// one element:
+// [0] = const0
+// ComputeBuffer is allocated with stride sizeof(int)*4, 1 element
+RWStructuredBuffer<uint4> _RCASParameters;
+
+float _RCASScale;
+
+TEXTURE2D_X(_RCASInputTexture);
+RWTexture2D<float4> _RCASOutputTexture;
+
+#ifdef _AMD_FSR_HALF
+AH4 FsrRcasLoadH(ASW2 p) {return AH4(AMD_FSR_TO_SRGB(_RCASInputTexture[p])); }
+void FsrRcasInputH(inout AH1 r,inout AH1 g,inout AH1 b) {}
+#else
+AF4 FsrRcasLoadF(ASU2 p) {return AMD_FSR_TO_SRGB(_RCASInputTexture[p]); }
+void FsrRcasInputF(inout AF1 r,inout AF1 g,inout AF1 b) {}
+#endif
+
+void WritePix(AU2 gxy, AF4 casPix)
+{
+ _RCASOutputTexture[gxy] = casPix;
+}
+
+
+[numthreads(64, 1, 1)]
+void KMain(uint3 LocalThreadId : SV_GroupThreadID, uint3 WorkGroupId : SV_GroupID, uint3 dispatchThreadId : SV_DispatchThreadID)
+{
+ // Do remapping of local xy in workgroup for a more PS-like swizzle pattern.
+ AU2 gxy = ARmp8x8(LocalThreadId.x) + AU2(WorkGroupId.x << 3u, WorkGroupId.y << 3u);
+#ifdef ENABLE_ALPHA
+ AREAL alpha = LOAD_TEXTURE2D_X(_RCASInputTexture, gxy.xy).a;
+#else
+ AREAL alpha = 1.0;
+#endif
+
+
+ AU4 con = _RCASParameters[0];
+#ifdef _AMD_FSR_HALF
+ AH4 c;
+ FsrRcasH(c.r, c.g, c.b, gxy, con);
+#else
+ AF4 c;
+ FsrRcasF(c.r, c.g, c.b, gxy, con);
+#endif
+
+ c.a = alpha;
+ WritePix(gxy, c);
+}
+
+
+/*
+Doing this to avoid having to deal with any CPU side compilation of the headers.
+The FsrRcasCon is doing some extra parameter packing (log space / pows etc) so its better
+to keep this all in the GPU for simplicity sake, and avoid paying this cost for every wave.
+The headers also dont compile for c#, they are meant for c and c++.
+*/
+[numthreads(1,1,1)]
+void KInitialize()
+{
+ AU4 con;
+ FsrRcasCon(con, _RCASScale);
+ _RCASParameters[0] = con;
+}
diff --git a/com.unity.render-pipelines.universal/Shaders/PostProcessing/amd_fsr.hlsl b/com.unity.render-pipelines.universal/Shaders/PostProcessing/amd_fsr.hlsl
new file mode 100644
index 0000000000..62eff3b9df
--- /dev/null
+++ b/com.unity.render-pipelines.universal/Shaders/PostProcessing/amd_fsr.hlsl
@@ -0,0 +1,23 @@
+#define A_GPU 1
+#define A_HLSL 1
+
+#ifdef _AMD_FSR_HALF
+#define A_HALF 1
+#define FSR_EASU_H 1
+#define FSR_RCAS_H 1
+#define AREAL half
+#else
+#define FSR_EASU_F 1
+#define FSR_RCAS_F 1
+#define AREAL float
+#endif
+
+#include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/ffx_a.hlsl"
+#include "Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/ffx_fsr1.hlsl"
+
+
+#ifdef _AMD_FSR_NEEDS_CONVERT_TO_SRGB
+#define AMD_FSR_TO_SRGB(color) AToSrgbF4(color)
+#else
+#define AMD_FSR_TO_SRGB(color) (color)
+#endif
\ No newline at end of file
diff --git a/com.unity.render-pipelines.universal/Shaders/PostProcessing/ffx_a.hlsl b/com.unity.render-pipelines.universal/Shaders/PostProcessing/ffx_a.hlsl
new file mode 100644
index 0000000000..12f4d6ba94
--- /dev/null
+++ b/com.unity.render-pipelines.universal/Shaders/PostProcessing/ffx_a.hlsl
@@ -0,0 +1,2664 @@
+//==============================================================================================================================
+//
+// [A] SHADER PORTABILITY 1.20210629
+//
+//==============================================================================================================================
+// FidelityFX Super Resolution Sample
+//
+// Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files(the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions :
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//------------------------------------------------------------------------------------------------------------------------------
+// MIT LICENSE
+// ===========
+// Copyright (c) 2014 Michal Drobot (for concepts used in "FLOAT APPROXIMATIONS").
+// -----------
+// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
+// files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
+// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+// -----------
+// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
+// Software.
+// -----------
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//------------------------------------------------------------------------------------------------------------------------------
+// ABOUT
+// =====
+// Common central point for high-level shading language and C portability for various shader headers.
+//------------------------------------------------------------------------------------------------------------------------------
+// DEFINES
+// =======
+// A_CPU ..... Include the CPU related code.
+// A_GPU ..... Include the GPU related code.
+// A_GLSL .... Using GLSL.
+// A_HLSL .... Using HLSL.
+// A_HLSL_6_2 Using HLSL 6.2 with new 'uint16_t' and related types (requires '-enable-16bit-types').
+// A_NO_16_BIT_CAST Don't use instructions that are not availabe in SPIR-V (needed for running A_HLSL_6_2 on Vulkan)
+// A_GCC ..... Using a GCC compatible compiler (else assume MSVC compatible compiler by default).
+// =======
+// A_BYTE .... Support 8-bit integer.
+// A_HALF .... Support 16-bit integer and floating point.
+// A_LONG .... Support 64-bit integer.
+// A_DUBL .... Support 64-bit floating point.
+// =======
+// A_WAVE .... Support wave-wide operations.
+//------------------------------------------------------------------------------------------------------------------------------
+// To get #include "ffx_a.h" working in GLSL use '#extension GL_GOOGLE_include_directive:require'.
+//------------------------------------------------------------------------------------------------------------------------------
+// SIMPLIFIED TYPE SYSTEM
+// ======================
+// - All ints will be unsigned with exception of when signed is required.
+// - Type naming simplified and shortened "A<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).
+//------------------------------------------------------------------------------------------------------------------------------
+// CHANGE LOG
+// ==========
+// 20200914 - Expanded wave ops and prx code.
+// 20200713 - Added [ZOL] section, fixed serious bugs in sRGB and Rec.709 color conversion code, etc.
+//==============================================================================================================================
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+// COMMON
+//==============================================================================================================================
+#define A_2PI 6.28318530718
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//_____________________________________________________________/\_______________________________________________________________
+//==============================================================================================================================
+//
+//
+// CPU
+//
+//
+//==============================================================================================================================
+#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
+//
+//------------------------------------------------------------------------------------------------------------------------------
+// Get CPU and GPU to share all setup code, without duplicate code paths.
+// 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_llabs(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_(labs((long)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 AClampD1(AD1 x,AD1 n,AD1 m){return AMaxD1(n,AMinD1(x,m));}
+ A_STATIC AF1 AClampF1(AF1 x,AF1 n,AF1 m){return AMaxF1(n,AMinF1(x,m));}
+//------------------------------------------------------------------------------------------------------------------------------
+ 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));}