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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
|
sb << "// Slang HLSL compatibility library\n";
sb << "\n";
sb << "typedef uint UINT;\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLAppendStructuredBufferType) struct AppendStructuredBuffer\n";
sb << "{\n";
sb << " __intrinsic_op void Append(T value);\n";
sb << "\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint numStructs,\n";
sb << " out uint stride);\n";
sb << "};\n";
sb << "\n";
sb << "__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer\n";
sb << "{\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint dim);\n";
sb << "\n";
sb << " __intrinsic_op uint Load(int location);\n";
sb << " __intrinsic_op uint Load(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint2 Load2(int location);\n";
sb << " __intrinsic_op uint2 Load2(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint3 Load3(int location);\n";
sb << " __intrinsic_op uint3 Load3(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint4 Load4(int location);\n";
sb << " __intrinsic_op uint4 Load4(int location, out uint status);\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLStructuredBufferType) struct StructuredBuffer\n";
sb << "{\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint numStructs,\n";
sb << " out uint stride);\n";
sb << "\n";
sb << " __intrinsic_op T Load(int location);\n";
sb << " __intrinsic_op T Load(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op __subscript(uint index) -> T;\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLConsumeStructuredBufferType) struct ConsumeStructuredBuffer\n";
sb << "{\n";
sb << " __intrinsic_op T Consume();\n";
sb << "\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint numStructs,\n";
sb << " out uint stride);\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T, let N : int> __magic_type(HLSLInputPatchType) struct InputPatch\n";
sb << "{\n";
sb << " __intrinsic_op __subscript(uint index) -> T;\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch\n";
sb << "{\n";
sb << " __intrinsic_op __subscript(uint index) -> T { set; }\n";
sb << "};\n";
sb << "\n";
sb << "__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer\n";
sb << "{\n";
sb << " // Note(tfoley): supports alll operations from `ByteAddressBuffer`\n";
sb << " // TODO(tfoley): can this be made a sub-type?\n";
sb << "\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint dim);\n";
sb << "\n";
sb << " __intrinsic_op uint Load(int location);\n";
sb << " __intrinsic_op uint Load(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint2 Load2(int location);\n";
sb << " __intrinsic_op uint2 Load2(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint3 Load3(int location);\n";
sb << " __intrinsic_op uint3 Load3(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op uint4 Load4(int location);\n";
sb << " __intrinsic_op uint4 Load4(int location, out uint status);\n";
sb << "\n";
sb << " // Added operations:\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedAdd(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedAdd(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedAnd(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedAnd(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedCompareExchange(\n";
sb << " UINT dest,\n";
sb << " UINT compare_value,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedCompareExchange(\n";
sb << " UINT dest,\n";
sb << " UINT compare_value,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedCompareStore(\n";
sb << " UINT dest,\n";
sb << " UINT compare_value,\n";
sb << " UINT value);\n";
sb << " __intrinsic_op void InterlockedCompareStore(\n";
sb << " UINT dest,\n";
sb << " UINT compare_value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedExchange(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedExchange(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedMax(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedMax(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedMin(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedMin(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedOr(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedOr(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void InterlockedXor(\n";
sb << " UINT dest,\n";
sb << " UINT value,\n";
sb << " out UINT original_value);\n";
sb << " __intrinsic_op void InterlockedXor(\n";
sb << " UINT dest,\n";
sb << " UINT value);\n";
sb << "\n";
sb << " __intrinsic_op void Store(\n";
sb << " uint address,\n";
sb << " uint value);\n";
sb << "\n";
sb << " __intrinsic_op void Store2(\n";
sb << " uint address,\n";
sb << " uint2 value);\n";
sb << "\n";
sb << " __intrinsic_op void Store3(\n";
sb << " uint address,\n";
sb << " uint3 value);\n";
sb << "\n";
sb << " __intrinsic_op void Store4(\n";
sb << " uint address,\n";
sb << " uint4 value);\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLRWStructuredBufferType) struct RWStructuredBuffer\n";
sb << "{\n";
sb << " __intrinsic_op uint DecrementCounter();\n";
sb << "\n";
sb << " __intrinsic_op void GetDimensions(\n";
sb << " out uint numStructs,\n";
sb << " out uint stride);\n";
sb << "\n";
sb << " __intrinsic_op void IncrementCounter();\n";
sb << "\n";
sb << " __intrinsic_op T Load(int location);\n";
sb << " __intrinsic_op T Load(int location, out uint status);\n";
sb << "\n";
sb << " __intrinsic_op __subscript(uint index) -> T { get; set; }\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLPointStreamType) struct PointStream\n";
sb << "{\n";
sb << " void Append(T value);\n";
sb << " void RestartStrip();\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLLineStreamType) struct LineStream\n";
sb << "{\n";
sb << " void Append(T value);\n";
sb << " void RestartStrip();\n";
sb << "};\n";
sb << "\n";
sb << "__generic<T> __magic_type(HLSLTriangleStreamType) struct TriangleStream\n";
sb << "{\n";
sb << " void Append(T value);\n";
sb << " void RestartStrip();\n";
sb << "};\n";
sb << "\n";
sb << "// Note(tfoley): Trying to systematically add all the HLSL builtins\n";
sb << "\n";
sb << "// Try to terminate the current draw or dispatch call (HLSL SM 4.0)\n";
sb << "__intrinsic_op void abort();\n";
sb << "\n";
sb << "// Absolute value (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinSignedArithmeticType> __intrinsic_op T abs(T x);\n";
sb << "__generic<T : __BuiltinSignedArithmeticType, let N : int> __intrinsic_op vector<T,N> abs(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinSignedArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> abs(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Inverse cosine (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T acos(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> acos(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> acos(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Test if all components are non-zero (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T all(T x);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> all(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> all(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Barrier for writes to all memory spaces (HLSL SM 5.0)\n";
sb << "__intrinsic_op void AllMemoryBarrier();\n";
sb << "\n";
sb << "// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)\n";
sb << "__intrinsic_op void AllMemoryBarrierWithGroupSync();\n";
sb << "\n";
sb << "// Test if any components is non-zero (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T any(T x);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> any(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> any(matrix<T,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Reinterpret bits as a double (HLSL SM 5.0)\n";
sb << "__intrinsic_op double asdouble(uint lowbits, uint highbits);\n";
sb << "\n";
sb << "// Reinterpret bits as a float (HLSL SM 4.0)\n";
sb << "__intrinsic_op float asfloat( int x);\n";
sb << "__intrinsic_op float asfloat(uint x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<float,N> asfloat(vector< int,N> x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<float,N> asfloat(vector<uint,N> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<float,N,M> asfloat(matrix< int,N,M> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<float,N,M> asfloat(matrix<uint,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Inverse sine (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T asin(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> asin(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> asin(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Reinterpret bits as an int (HLSL SM 4.0)\n";
sb << "__intrinsic_op int asint(float x);\n";
sb << "__intrinsic_op int asint(uint x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<int,N> asint(vector<float,N> x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<int,N> asint(vector<uint,N> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<int,N,M> asint(matrix<float,N,M> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<int,N,M> asint(matrix<uint,N,M> x);\n";
sb << "\n";
sb << "// Reinterpret bits of double as a uint (HLSL SM 5.0)\n";
sb << "__intrinsic_op void asuint(double value, out uint lowbits, out uint highbits);\n";
sb << "\n";
sb << "// Reinterpret bits as a uint (HLSL SM 4.0)\n";
sb << "__intrinsic_op uint asuint(float x);\n";
sb << "__intrinsic_op uint asuint(int x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<uint,N> asuint(vector<float,N> x);\n";
sb << "__generic<let N : int> __intrinsic_op vector<uint,N> asuint(vector<int,N> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<uint,N,M> asuint(matrix<float,N,M> x);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<uint,N,M> asuint(matrix<int,N,M> x);\n";
sb << "\n";
sb << "// Inverse tangent (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T atan(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> atan(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> atan(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n";
sb << "__intrinsic_op\n";
sb << "T atan2(T y, T x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> atan2(vector<T,N> y, vector<T,N> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl,\"atan($0,$1)\")\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> atan2(matrix<T,N,M> y, matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Ceiling (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T ceil(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> ceil(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> ceil(matrix<T,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Check access status to tiled resource\n";
sb << "__intrinsic_op bool CheckAccessFullyMapped(uint status);\n";
sb << "\n";
sb << "// Clamp (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T clamp(T x, T min, T max);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> clamp(vector<T,N> x, vector<T,N> min, vector<T,N> max);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> clamp(matrix<T,N,M> x, matrix<T,N,M> min, matrix<T,N,M> max);\n";
sb << "\n";
sb << "// Clip (discard) fragment conditionally\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op void clip(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op void clip(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op void clip(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Cosine\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T cos(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> cos(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> cos(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Hyperbolic cosine\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T cosh(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> cosh(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> cosh(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Population count\n";
sb << "__intrinsic_op uint countbits(uint value);\n";
sb << "\n";
sb << "// Cross product\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op vector<T,3> cross(vector<T,3> x, vector<T,3> y);\n";
sb << "\n";
sb << "// Convert encoded color\n";
sb << "__intrinsic_op int4 D3DCOLORtoUBYTE4(float4 x);\n";
sb << "\n";
sb << "// Partial-difference derivatives\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl, dFdx)\n";
sb << "__intrinsic_op\n";
sb << "T ddx(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl, dFdx)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddx(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl, dFdx)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> ddx(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxCoarse)\n";
sb << "__intrinsic_op\n";
sb << "T ddx_coarse(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxCoarse)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddx_coarse(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxCoarse)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> ddx_coarse(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxFine)\n";
sb << "__intrinsic_op\n";
sb << "T ddx_fine(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxFine)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddx_fine(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdxFine)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> ddx_fine(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl, dFdy)\n";
sb << "__intrinsic_op\n";
sb << "T ddy(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl, dFdy)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddy(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl, dFdy)\n";
sb << "__intrinsic_op\n";
sb << " matrix<T,N,M> ddy(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyCoarse)\n";
sb << "__intrinsic_op\n";
sb << "T ddy_coarse(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyCoarse)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddy_coarse(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyCoarse)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> ddy_coarse(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyFine)\n";
sb << "__intrinsic_op\n";
sb << "T ddy_fine(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyFine)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> ddy_fine(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__glsl_extension(GL_ARB_derivative_control)\n";
sb << "__target_intrinsic(glsl, dFdyFine)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> ddy_fine(matrix<T,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Radians to degrees\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T degrees(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> degrees(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> degrees(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Matrix determinant\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op T determinant(matrix<T,N,N> m);\n";
sb << "\n";
sb << "// Barrier for device memory\n";
sb << "__intrinsic_op void DeviceMemoryBarrier();\n";
sb << "__intrinsic_op void DeviceMemoryBarrierWithGroupSync();\n";
sb << "\n";
sb << "// Vector distance\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op T distance(vector<T,N> x, vector<T,N> y);\n";
sb << "\n";
sb << "// Vector dot product\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op T dot(vector<T,N> x, vector<T,N> y);\n";
sb << "\n";
sb << "// Helper for computing distance terms for lighting (obsolete)\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op vector<T,4> dst(vector<T,4> x, vector<T,4> y);\n";
sb << "\n";
sb << "// Error message\n";
sb << "\n";
sb << "// __intrinsic_op void errorf( string format, ... );\n";
sb << "\n";
sb << "// Attribute evaluation\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T EvaluateAttributeAtCentroid(T x);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> EvaluateAttributeAtCentroid(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> EvaluateAttributeAtCentroid(matrix<T,N,M> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T EvaluateAttributeAtSample(T x, uint sampleindex);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> EvaluateAttributeAtSample(vector<T,N> x, uint sampleindex);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> EvaluateAttributeAtSample(matrix<T,N,M> x, uint sampleindex);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T EvaluateAttributeSnapped(T x, int2 offset);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> EvaluateAttributeSnapped(vector<T,N> x, int2 offset);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> EvaluateAttributeSnapped(matrix<T,N,M> x, int2 offset);\n";
sb << "\n";
sb << "// Base-e exponent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T exp(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> exp(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> exp(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Base-2 exponent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T exp2(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> exp2(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> exp2(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Convert 16-bit float stored in low bits of integer\n";
sb << "__intrinsic_op float f16tof32(uint value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<float,N> f16tof32(vector<uint,N> value);\n";
sb << "\n";
sb << "// Convert to 16-bit float stored in low bits of integer\n";
sb << "__intrinsic_op uint f32tof16(float value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<uint,N> f32tof16(vector<float,N> value);\n";
sb << "\n";
sb << "// Flip surface normal to face forward, if needed\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> faceforward(vector<T,N> n, vector<T,N> i, vector<T,N> ng);\n";
sb << "\n";
sb << "// Find first set bit starting at high bit and working down\n";
sb << "__intrinsic_op int firstbithigh(int value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<int,N> firstbithigh(vector<int,N> value);\n";
sb << "\n";
sb << "__intrinsic_op uint firstbithigh(uint value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<uint,N> firstbithigh(vector<uint,N> value);\n";
sb << "\n";
sb << "// Find first set bit starting at low bit and working up\n";
sb << "__intrinsic_op int firstbitlow(int value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<int,N> firstbitlow(vector<int,N> value);\n";
sb << "\n";
sb << "__intrinsic_op uint firstbitlow(uint value);\n";
sb << "__generic<let N : int> __intrinsic_op vector<uint,N> firstbitlow(vector<uint,N> value);\n";
sb << "\n";
sb << "// Floor (HLSL SM 1.0)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T floor(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> floor(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> floor(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Fused multiply-add for doubles\n";
sb << "__intrinsic_op double fma(double a, double b, double c);\n";
sb << "__generic<let N : int> __intrinsic_op vector<double, N> fma(vector<double, N> a, vector<double, N> b, vector<double, N> c);\n";
sb << "__generic<let N : int, let M : int> __intrinsic_op matrix<double,N,M> fma(matrix<double,N,M> a, matrix<double,N,M> b, matrix<double,N,M> c);\n";
sb << "\n";
sb << "// Floating point remainder of x/y\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T fmod(T x, T y);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> fmod(vector<T,N> x, vector<T,N> y);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> fmod(matrix<T,N,M> x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// Fractional part\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl, fract)\n";
sb << "__intrinsic_op\n";
sb << "T frac(T x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl, fract)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> frac(vector<T,N> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl, fract)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> frac(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Split float into mantissa and exponent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T frexp(T x, out T exp);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> frexp(vector<T,N> x, out vector<T,N> exp);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> frexp(matrix<T,N,M> x, out matrix<T,N,M> exp);\n";
sb << "\n";
sb << "// Texture filter width\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T fwidth(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> fwidth(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> fwidth(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Get number of samples in render target\n";
sb << "__intrinsic_op uint GetRenderTargetSampleCount();\n";
sb << "\n";
sb << "// Get position of given sample\n";
sb << "__intrinsic_op float2 GetRenderTargetSamplePosition(int Index);\n";
sb << "\n";
sb << "// Group memory barrier\n";
sb << "__intrinsic_op void GroupMemoryBarrier();\n";
sb << "__intrinsic_op void GroupMemoryBarrierWithGroupSync();\n";
sb << "\n";
sb << "// Atomics\n";
sb << "__intrinsic_op void InterlockedAdd(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedAdd(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedAnd(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedAnd(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedCompareExchange(in out int dest, int compare_value, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedCompareExchange(in out uint dest, uint compare_value, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedCompareStore(in out int dest, int compare_value, int value);\n";
sb << "__intrinsic_op void InterlockedCompareStore(in out uint dest, uint compare_value, uint value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedExchange(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedExchange(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedMax(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedMax(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedMin(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedMin(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedOr(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedOr(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "__intrinsic_op void InterlockedXor(in out int dest, int value, out int original_value);\n";
sb << "__intrinsic_op void InterlockedXor(in out uint dest, uint value, out uint original_value);\n";
sb << "\n";
sb << "// Is floating-point value finite?\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op bool isfinite(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<bool,N> isfinite(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<bool,N,M> isfinite(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Is floating-point value infinite?\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op bool isinf(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<bool,N> isinf(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<bool,N,M> isinf(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Is floating-point value not-a-number?\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op bool isnan(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<bool,N> isnan(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<bool,N,M> isnan(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Construct float from mantissa and exponent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T ldexp(T x, T exp);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> ldexp(vector<T,N> x, vector<T,N> exp);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> ldexp(matrix<T,N,M> x, matrix<T,N,M> exp);\n";
sb << "\n";
sb << "// Vector length\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op T length(vector<T,N> x);\n";
sb << "\n";
sb << "// Linear interpolation\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl, mix)\n";
sb << "__intrinsic_op\n";
sb << "T lerp(T x, T y, T s);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl, mix)\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> lerp(vector<T,N> x, vector<T,N> y, vector<T,N> s);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl, mix)\n";
sb << "__intrinsic_op\n";
sb << "matrix<T,N,M> lerp(matrix<T,N,M> x, matrix<T,N,M> y, matrix<T,N,M> s);\n";
sb << "\n";
sb << "// Legacy lighting function (obsolete)\n";
sb << "__intrinsic_op float4 lit(float n_dot_l, float n_dot_h, float m);\n";
sb << "\n";
sb << "// Base-e logarithm\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T log(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> log(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> log(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Base-10 logarithm\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T log10(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> log10(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> log10(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Base-2 logarithm\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T log2(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> log2(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> log2(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// multiply-add\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T mad(T mvalue, T avalue, T bvalue);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> mad(vector<T,N> mvalue, vector<T,N> avalue, vector<T,N> bvalue);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> mad(matrix<T,N,M> mvalue, matrix<T,N,M> avalue, matrix<T,N,M> bvalue);\n";
sb << "\n";
sb << "// maximum\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T max(T x, T y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> max(vector<T,N> x, vector<T,N> y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> max(matrix<T,N,M> x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// minimum\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T min(T x, T y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> min(vector<T,N> x, vector<T,N> y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> min(matrix<T,N,M> x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// split into integer and fractional parts (both with same sign)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T modf(T x, out T ip);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> modf(vector<T,N> x, out vector<T,N> ip);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> modf(matrix<T,N,M> x, out matrix<T,N,M> ip);\n";
sb << "\n";
sb << "// msad4 (whatever that is)\n";
sb << "__intrinsic_op uint4 msad4(uint reference, uint2 source, uint4 accum);\n";
sb << "\n";
sb << "// General inner products\n";
sb << "\n";
sb << "// scalar-scalar\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T mul(T x, T y);\n";
sb << "\n";
sb << "// scalar-vector and vector-scalar\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> mul(vector<T,N> x, T y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> mul(T x, vector<T,N> y);\n";
sb << "\n";
sb << "// scalar-matrix and matrix-scalar\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M :int> __intrinsic_op matrix<T,N,M> mul(matrix<T,N,M> x, T y);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M :int> __intrinsic_op matrix<T,N,M> mul(T x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// vector-vector (dot product)\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op(dot) T mul(vector<T,N> x, vector<T,N> y);\n";
sb << "\n";
sb << "// vector-matrix\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op(mulVectorMatrix) vector<T,M> mul(vector<T,N> x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// matrix-vector\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op(mulMatrixVector) vector<T,N> mul(matrix<T,N,M> x, vector<T,M> y);\n";
sb << "\n";
sb << "// matrix-matrix\n";
sb << "__generic<T : __BuiltinArithmeticType, let R : int, let N : int, let C : int> __intrinsic_op(mulMatrixMatrix) matrix<T,R,C> mul(matrix<T,R,N> x, matrix<T,N,C> y);\n";
sb << "\n";
sb << "// noise (deprecated)\n";
sb << "__intrinsic_op float noise(float x);\n";
sb << "__generic<let N : int> __intrinsic_op float noise(vector<float, N> x);\n";
sb << "\n";
sb << "// Normalize a vector\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> normalize(vector<T,N> x);\n";
sb << "\n";
sb << "// Raise to a power\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T pow(T x, T y);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> pow(vector<T,N> x, vector<T,N> y);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> pow(matrix<T,N,M> x, matrix<T,N,M> y);\n";
sb << "\n";
sb << "// Output message\n";
sb << "\n";
sb << "// __intrinsic_op void printf( string format, ... );\n";
sb << "\n";
sb << "// Tessellation factor fixup routines\n";
sb << "\n";
sb << "__intrinsic_op void Process2DQuadTessFactorsAvg(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float2 InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void Process2DQuadTessFactorsMax(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float2 InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void Process2DQuadTessFactorsMin(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float2 InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessIsolineTessFactors(\n";
sb << " in float RawDetailFactor,\n";
sb << " in float RawDensityFactor,\n";
sb << " out float RoundedDetailFactor,\n";
sb << " out float RoundedDensityFactor);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessQuadTessFactorsAvg(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessQuadTessFactorsMax(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessQuadTessFactorsMin(\n";
sb << " in float4 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float4 RoundedEdgeTessFactors,\n";
sb << " out float2 RoundedInsideTessFactors,\n";
sb << " out float2 UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessTriTessFactorsAvg(\n";
sb << " in float3 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float3 RoundedEdgeTessFactors,\n";
sb << " out float RoundedInsideTessFactor,\n";
sb << " out float UnroundedInsideTessFactor);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessTriTessFactorsMax(\n";
sb << " in float3 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float3 RoundedEdgeTessFactors,\n";
sb << " out float RoundedInsideTessFactor,\n";
sb << " out float UnroundedInsideTessFactor);\n";
sb << "\n";
sb << "__intrinsic_op void ProcessTriTessFactorsMin(\n";
sb << " in float3 RawEdgeFactors,\n";
sb << " in float InsideScale,\n";
sb << " out float3 RoundedEdgeTessFactors,\n";
sb << " out float RoundedInsideTessFactors,\n";
sb << " out float UnroundedInsideTessFactors);\n";
sb << "\n";
sb << "// Degrees to radians\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T radians(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> radians(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> radians(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Approximate reciprocal\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T rcp(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> rcp(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> rcp(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Reflect incident vector across plane with given normal\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> reflect(vector<T,N> i, vector<T,N> n);\n";
sb << "\n";
sb << "// Refract incident vector given surface normal and index of refraction\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__intrinsic_op\n";
sb << "vector<T,N> refract(vector<T,N> i, vector<T,N> n, float eta);\n";
sb << "\n";
sb << "// Reverse order of bits\n";
sb << "__intrinsic_op uint reversebits(uint value);\n";
sb << "__generic<let N : int> vector<uint,N> reversebits(vector<uint,N> value);\n";
sb << "\n";
sb << "// Round-to-nearest\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T round(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> round(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> round(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Reciprocal of square root\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T rsqrt(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> rsqrt(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> rsqrt(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Clamp value to [0,1] range\n";
sb << "__generic<T : __BuiltinFloatingPointType>\n";
sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\") __intrinsic_op\n";
sb << "T saturate(T x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int>\n";
sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\") __intrinsic_op\n";
sb << "vector<T,N> saturate(vector<T,N> x);\n";
sb << "\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>\n";
sb << "__target_intrinsic(glsl, \"clamp($0, 0, 1)\") __intrinsic_op\n";
sb << "matrix<T,N,M> saturate(matrix<T,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Extract sign of value\n";
sb << "__generic<T : __BuiltinSignedArithmeticType> __intrinsic_op int sign(T x);\n";
sb << "__generic<T : __BuiltinSignedArithmeticType, let N : int> __intrinsic_op vector<int,N> sign(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinSignedArithmeticType, let N : int, let M : int> __intrinsic_op matrix<int,N,M> sign(matrix<T,N,M> x);\n";
sb << "\n";
sb << "\n";
sb << "// Sine\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T sin(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> sin(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> sin(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Sine and cosine\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op void sincos(T x, out T s, out T c);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op void sincos(vector<T,N> x, out vector<T,N> s, out vector<T,N> c);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op void sincos(matrix<T,N,M> x, out matrix<T,N,M> s, out matrix<T,N,M> c);\n";
sb << "\n";
sb << "// Hyperbolic Sine\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T sinh(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> sinh(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> sinh(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Smooth step (Hermite interpolation)\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T smoothstep(T min, T max, T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> smoothstep(vector<T,N> min, vector<T,N> max, vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> smoothstep(matrix<T,N,M> min, matrix<T,N,M> max, matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Square root\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T sqrt(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> sqrt(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> sqrt(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Step function\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T step(T y, T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> step(vector<T,N> y, vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> step(matrix<T,N,M> y, matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Tangent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T tan(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> tan(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> tan(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Hyperbolic tangent\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T tanh(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> tanh(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> tanh(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Legacy texture-fetch operations\n";
sb << "\n";
sb << "/*\n";
sb << "__intrinsic_op float4 tex1D(sampler1D s, float t);\n";
sb << "__intrinsic_op float4 tex1D(sampler1D s, float t, float ddx, float ddy);\n";
sb << "__intrinsic_op float4 tex1Dbias(sampler1D s, float4 t);\n";
sb << "__intrinsic_op float4 tex1Dgrad(sampler1D s, float t, float ddx, float ddy);\n";
sb << "__intrinsic_op float4 tex1Dlod(sampler1D s, float4 t);\n";
sb << "__intrinsic_op float4 tex1Dproj(sampler1D s, float4 t);\n";
sb << "\n";
sb << "__intrinsic_op float4 tex2D(sampler2D s, float2 t);\n";
sb << "__intrinsic_op float4 tex2D(sampler2D s, float2 t, float2 ddx, float2 ddy);\n";
sb << "__intrinsic_op float4 tex2Dbias(sampler2D s, float4 t);\n";
sb << "__intrinsic_op float4 tex2Dgrad(sampler2D s, float2 t, float2 ddx, float2 ddy);\n";
sb << "__intrinsic_op float4 tex2Dlod(sampler2D s, float4 t);\n";
sb << "__intrinsic_op float4 tex2Dproj(sampler2D s, float4 t);\n";
sb << "\n";
sb << "__intrinsic_op float4 tex3D(sampler3D s, float3 t);\n";
sb << "__intrinsic_op float4 tex3D(sampler3D s, float3 t, float3 ddx, float3 ddy);\n";
sb << "__intrinsic_op float4 tex3Dbias(sampler3D s, float4 t);\n";
sb << "__intrinsic_op float4 tex3Dgrad(sampler3D s, float3 t, float3 ddx, float3 ddy);\n";
sb << "__intrinsic_op float4 tex3Dlod(sampler3D s, float4 t);\n";
sb << "__intrinsic_op float4 tex3Dproj(sampler3D s, float4 t);\n";
sb << "\n";
sb << "__intrinsic_op float4 texCUBE(samplerCUBE s, float3 t);\n";
sb << "__intrinsic_op float4 texCUBE(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n";
sb << "__intrinsic_op float4 texCUBEbias(samplerCUBE s, float4 t);\n";
sb << "__intrinsic_op float4 texCUBEgrad(samplerCUBE s, float3 t, float3 ddx, float3 ddy);\n";
sb << "__intrinsic_op float4 texCUBElod(samplerCUBE s, float4 t);\n";
sb << "__intrinsic_op float4 texCUBEproj(samplerCUBE s, float4 t);\n";
sb << "*/\n";
sb << "\n";
sb << "// Matrix transpose\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,M,N> transpose(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Truncate to integer\n";
sb << "__generic<T : __BuiltinFloatingPointType> __intrinsic_op T trunc(T x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int> __intrinsic_op vector<T,N> trunc(vector<T,N> x);\n";
sb << "__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> trunc(matrix<T,N,M> x);\n";
sb << "\n";
sb << "// Shader model 6.0 stuff\n";
sb << "\n";
sb << "__intrinsic_op uint GlobalOrderedCountIncrement(uint countToAppendForThisLane);\n";
sb << "\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T QuadReadLaneAt(T sourceValue, int quadLaneID);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> QuadReadLaneAt(vector<T,N> sourceValue, int quadLaneID);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> QuadReadLaneAt(matrix<T,N,M> sourceValue, int quadLaneID);\n";
sb << "\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T QuadSwapX(T localValue);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> QuadSwapX(vector<T,N> localValue);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> QuadSwapX(matrix<T,N,M> localValue);\n";
sb << "\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T QuadSwapY(T localValue);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> QuadSwapY(vector<T,N> localValue);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> QuadSwapY(matrix<T,N,M> localValue);\n";
sb << "\n";
sb << "__generic<T : __BuiltinIntegerType> __intrinsic_op T WaveAllBitAnd(T expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int> __intrinsic_op vector<T,N> WaveAllBitAnd(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllBitAnd(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinIntegerType> __intrinsic_op T WaveAllBitOr(T expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int> __intrinsic_op vector<T,N> WaveAllBitOr(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllBitOr(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinIntegerType> __intrinsic_op T WaveAllBitXor(T expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int> __intrinsic_op vector<T,N> WaveAllBitXor(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinIntegerType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllBitXor(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WaveAllMax(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WaveAllMax(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllMax(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WaveAllMin(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WaveAllMin(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllMin(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WaveAllProduct(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WaveAllProduct(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllProduct(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WaveAllSum(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WaveAllSum(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveAllSum(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__intrinsic_op bool WaveAllEqual(bool expr);\n";
sb << "__intrinsic_op bool WaveAllTrue(bool expr);\n";
sb << "__intrinsic_op bool WaveAnyTrue(bool expr);\n";
sb << "\n";
sb << "uint64_t WaveBallot(bool expr);\n";
sb << "\n";
sb << "uint WaveGetLaneCount();\n";
sb << "uint WaveGetLaneIndex();\n";
sb << "uint WaveGetOrderedIndex();\n";
sb << "\n";
sb << "bool WaveIsHelperLane();\n";
sb << "\n";
sb << "bool WaveOnce();\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WavePrefixProduct(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WavePrefixProduct(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WavePrefixProduct(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinArithmeticType> __intrinsic_op T WavePrefixSum(T expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op vector<T,N> WavePrefixSum(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinArithmeticType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WavePrefixSum(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T WaveReadFirstLane(T expr);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> WaveReadFirstLane(vector<T,N> expr);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveReadFirstLane(matrix<T,N,M> expr);\n";
sb << "\n";
sb << "__generic<T : __BuiltinType> __intrinsic_op T WaveReadLaneAt(T expr, int laneIndex);\n";
sb << "__generic<T : __BuiltinType, let N : int> __intrinsic_op vector<T,N> WaveReadLaneAt(vector<T,N> expr, int laneIndex);\n";
sb << "__generic<T : __BuiltinType, let N : int, let M : int> __intrinsic_op matrix<T,N,M> WaveReadLaneAt(matrix<T,N,M> expr, int laneIndex);\n";
sb << "\n";
sb << "// `typedef`s to help with the fact that HLSL has been sorta-kinda case insensitive at various points\n";
sb << "typedef Texture2D texture2D;\n";
sb << "\n";
sb << "";
// Component-wise multiplication ops
for(auto op : binaryOps)
{
switch (op.opCode)
{
default:
continue;
case kIROp_Mul:
case kIRPseudoOp_MulAssign:
break;
}
for (auto type : kBaseTypes)
{
if ((type.flags & op.flags) == 0)
continue;
char const* leftType = type.name;
char const* rightType = leftType;
char const* resultType = leftType;
char const* leftQual = "";
if(op.flags & ASSIGNMENT) leftQual = "in out ";
sb << "__generic<let N : int, let M : int> ";
sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, matrix<" << rightType << ",N,M> right);\n";
}
}
//
// Buffer types
static const struct {
char const* name;
SlangResourceAccess access;
} kBaseBufferAccessLevels[] = {
{ "", SLANG_RESOURCE_ACCESS_READ },
{ "RW", SLANG_RESOURCE_ACCESS_READ_WRITE },
{ "RasterizerOrdered", SLANG_RESOURCE_ACCESS_RASTER_ORDERED },
};
static const int kBaseBufferAccessLevelCount = sizeof(kBaseBufferAccessLevels) / sizeof(kBaseBufferAccessLevels[0]);
for (int aa = 0; aa < kBaseBufferAccessLevelCount; ++aa)
{
sb << "__generic<T> __magic_type(Texture, ";
sb << ResourceType::makeFlavor(ResourceType::Shape::ShapeBuffer, kBaseBufferAccessLevels[aa].access);
sb << ") struct ";
sb << kBaseBufferAccessLevels[aa].name;
sb << "Buffer {\n";
sb << "__intrinsic_op void GetDimensions(out uint dim);\n";
sb << "__target_intrinsic(glsl, \"texelFetch($P, $0)$z\")\n";
sb << "__intrinsic_op T Load(int location);\n";
sb << "__intrinsic_op T Load(int location, out uint status);\n";
sb << "__target_intrinsic(glsl, \"texelFetch($P, int($0))$z\")\n";
sb << "__intrinsic_op __subscript(uint index) -> T";
if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ)
{
sb << " { get; set; }\n";
}
else
{
sb << ";\n";
}
sb << "};\n";
}
sb << "";
|