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
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
|
// Slang HLSL compatibility library
typedef uint UINT;
__generic<T> __magic_type(HLSLAppendStructuredBufferType) struct AppendStructuredBuffer
{
void Append(T value);
void GetDimensions(
out uint numStructs,
out uint stride);
};
__magic_type(HLSLByteAddressBufferType) struct ByteAddressBuffer
{
void GetDimensions(
out uint dim);
uint Load(int location);
uint Load(int location, out uint status);
uint2 Load2(int location);
uint2 Load2(int location, out uint status);
uint3 Load3(int location);
uint3 Load3(int location, out uint status);
uint4 Load4(int location);
uint4 Load4(int location, out uint status);
};
__generic<T>
__magic_type(HLSLStructuredBufferType)
__intrinsic_type(${{
// TODO: we really need a simple way to write an "expression splice"
sb << kIROp_structuredBufferType;
}})
struct StructuredBuffer
{
void GetDimensions(
out uint numStructs,
out uint stride);
T Load(int location);
T Load(int location, out uint status);
__subscript(uint index) -> T { __intrinsic_op(bufferLoad) get; };
};
__generic<T> __magic_type(HLSLConsumeStructuredBufferType) struct ConsumeStructuredBuffer
{
T Consume();
void GetDimensions(
out uint numStructs,
out uint stride);
};
__generic<T, let N : int> __magic_type(HLSLInputPatchType) struct InputPatch
{
__subscript(uint index) -> T;
};
__generic<T, let N : int> __magic_type(HLSLOutputPatchType) struct OutputPatch
{
__subscript(uint index) -> T;
};
__magic_type(HLSLRWByteAddressBufferType) struct RWByteAddressBuffer
{
// Note(tfoley): supports alll operations from `ByteAddressBuffer`
// TODO(tfoley): can this be made a sub-type?
void GetDimensions(
out uint dim);
uint Load(int location);
uint Load(int location, out uint status);
uint2 Load2(int location);
uint2 Load2(int location, out uint status);
uint3 Load3(int location);
uint3 Load3(int location, out uint status);
uint4 Load4(int location);
uint4 Load4(int location, out uint status);
// Added operations:
void InterlockedAdd(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedAdd(
UINT dest,
UINT value);
void InterlockedAnd(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedAnd(
UINT dest,
UINT value);
void InterlockedCompareExchange(
UINT dest,
UINT compare_value,
UINT value,
out UINT original_value);
void InterlockedCompareExchange(
UINT dest,
UINT compare_value,
UINT value);
void InterlockedCompareStore(
UINT dest,
UINT compare_value,
UINT value);
void InterlockedCompareStore(
UINT dest,
UINT compare_value);
void InterlockedExchange(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedExchange(
UINT dest,
UINT value);
void InterlockedMax(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedMax(
UINT dest,
UINT value);
void InterlockedMin(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedMin(
UINT dest,
UINT value);
void InterlockedOr(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedOr(
UINT dest,
UINT value);
void InterlockedXor(
UINT dest,
UINT value,
out UINT original_value);
void InterlockedXor(
UINT dest,
UINT value);
void Store(
uint address,
uint value);
void Store2(
uint address,
uint2 value);
void Store3(
uint address,
uint3 value);
void Store4(
uint address,
uint4 value);
};
__generic<T>
__magic_type(HLSLRWStructuredBufferType)
__intrinsic_type(${{
// TODO: we really need a simple way to write an "expression splice"
sb << kIROp_readWriteStructuredBufferType;
}})
struct RWStructuredBuffer
{
uint DecrementCounter();
void GetDimensions(
out uint numStructs,
out uint stride);
uint IncrementCounter();
T Load(int location);
T Load(int location, out uint status);
__subscript(uint index) -> T
{
__intrinsic_op(bufferElementRef)
ref;
}
};
__generic<T> __magic_type(HLSLPointStreamType) struct PointStream
{
void Append(T value);
void RestartStrip();
};
__generic<T> __magic_type(HLSLLineStreamType) struct LineStream
{
void Append(T value);
void RestartStrip();
};
__generic<T> __magic_type(HLSLTriangleStreamType) struct TriangleStream
{
void Append(T value);
void RestartStrip();
};
// Note(tfoley): Trying to systematically add all the HLSL builtins
// Try to terminate the current draw or dispatch call (HLSL SM 4.0)
void abort();
// Absolute value (HLSL SM 1.0)
__generic<T : __BuiltinSignedArithmeticType> T abs(T x);
__generic<T : __BuiltinSignedArithmeticType, let N : int> vector<T,N> abs(vector<T,N> x);
__generic<T : __BuiltinSignedArithmeticType, let N : int, let M : int> matrix<T,N,M> abs(matrix<T,N,M> x);
// Inverse cosine (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T acos(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> acos(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> acos(matrix<T,N,M> x);
// Test if all components are non-zero (HLSL SM 1.0)
__generic<T : __BuiltinType> bool all(T x);
__generic<T : __BuiltinType, let N : int> bool all(vector<T,N> x);
__generic<T : __BuiltinType, let N : int, let M : int> bool all(matrix<T,N,M> x);
// Barrier for writes to all memory spaces (HLSL SM 5.0)
void AllMemoryBarrier();
// Thread-group sync and barrier for writes to all memory spaces (HLSL SM 5.0)
void AllMemoryBarrierWithGroupSync();
// Test if any components is non-zero (HLSL SM 1.0)
__generic<T : __BuiltinType> bool any(T x);
__generic<T : __BuiltinType, let N : int> bool any(vector<T,N> x);
__generic<T : __BuiltinType, let N : int, let M : int> bool any(matrix<T,N,M> x);
// Reinterpret bits as a double (HLSL SM 5.0)
double asdouble(uint lowbits, uint highbits);
// Reinterpret bits as a float (HLSL SM 4.0)
float asfloat( int x);
float asfloat(uint x);
__generic<let N : int> vector<float,N> asfloat(vector< int,N> x);
__generic<let N : int> vector<float,N> asfloat(vector<uint,N> x);
__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix< int,N,M> x);
__generic<let N : int, let M : int> matrix<float,N,M> asfloat(matrix<uint,N,M> x);
// Inverse sine (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T asin(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> asin(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> asin(matrix<T,N,M> x);
// Reinterpret bits as an int (HLSL SM 4.0)
int asint(float x);
int asint(uint x);
__generic<let N : int> vector<int,N> asint(vector<float,N> x);
__generic<let N : int> vector<int,N> asint(vector<uint,N> x);
__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<float,N,M> x);
__generic<let N : int, let M : int> matrix<int,N,M> asint(matrix<uint,N,M> x);
// Reinterpret bits of double as a uint (HLSL SM 5.0)
void asuint(double value, out uint lowbits, out uint highbits);
// Reinterpret bits as a uint (HLSL SM 4.0)
uint asuint(float x);
uint asuint(int x);
__generic<let N : int> vector<uint,N> asuint(vector<float,N> x);
__generic<let N : int> vector<uint,N> asuint(vector<int,N> x);
__generic<let N : int, let M : int> matrix<uint,N,M> asuint(matrix<float,N,M> x);
__generic<let N : int, let M : int> matrix<uint,N,M> asuint(matrix<int,N,M> x);
// Inverse tangent (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T atan(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> atan(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> atan(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl,"atan($0,$1)")
T atan2(T y, T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl,"atan($0,$1)")
vector<T,N> atan2(vector<T,N> y, vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl,"atan($0,$1)")
matrix<T,N,M> atan2(matrix<T,N,M> y, matrix<T,N,M> x);
// Ceiling (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T ceil(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> ceil(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> ceil(matrix<T,N,M> x);
// Check access status to tiled resource
bool CheckAccessFullyMapped(uint status);
// Clamp (HLSL SM 1.0)
__generic<T : __BuiltinArithmeticType> T clamp(T x, T min, T max);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> clamp(vector<T,N> x, vector<T,N> min, vector<T,N> max);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> clamp(matrix<T,N,M> x, matrix<T,N,M> min, matrix<T,N,M> max);
// Clip (discard) fragment conditionally
__generic<T : __BuiltinFloatingPointType> void clip(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> void clip(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> void clip(matrix<T,N,M> x);
// Cosine
__generic<T : __BuiltinFloatingPointType> T cos(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> cos(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> cos(matrix<T,N,M> x);
// Hyperbolic cosine
__generic<T : __BuiltinFloatingPointType> T cosh(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> cosh(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> cosh(matrix<T,N,M> x);
// Population count
uint countbits(uint value);
// Cross product
__generic<T : __BuiltinArithmeticType> vector<T,3> cross(vector<T,3> x, vector<T,3> y);
// Convert encoded color
int4 D3DCOLORtoUBYTE4(float4 x);
// Partial-difference derivatives
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl, dFdx)
T ddx(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl, dFdx)
vector<T,N> ddx(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, dFdx)
matrix<T,N,M> ddx(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxCoarse)
T ddx_coarse(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxCoarse)
vector<T,N> ddx_coarse(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxCoarse)
matrix<T,N,M> ddx_coarse(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxFine)
T ddx_fine(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxFine)
vector<T,N> ddx_fine(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdxFine)
matrix<T,N,M> ddx_fine(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl, dFdy)
T ddy(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl, dFdy)
vector<T,N> ddy(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, dFdy)
matrix<T,N,M> ddy(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyCoarse)
T ddy_coarse(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyCoarse)
vector<T,N> ddy_coarse(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyCoarse)
matrix<T,N,M> ddy_coarse(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyFine)
T ddy_fine(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyFine)
vector<T,N> ddy_fine(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__glsl_extension(GL_ARB_derivative_control)
__target_intrinsic(glsl, dFdyFine)
matrix<T,N,M> ddy_fine(matrix<T,N,M> x);
// Radians to degrees
__generic<T : __BuiltinFloatingPointType> T degrees(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> degrees(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> degrees(matrix<T,N,M> x);
// Matrix determinant
__generic<T : __BuiltinFloatingPointType, let N : int> T determinant(matrix<T,N,N> m);
// Barrier for device memory
void DeviceMemoryBarrier();
void DeviceMemoryBarrierWithGroupSync();
// Vector distance
__generic<T : __BuiltinFloatingPointType, let N : int> T distance(vector<T,N> x, vector<T,N> y);
// Vector dot product
__generic<T : __BuiltinArithmeticType, let N : int> T dot(vector<T,N> x, vector<T,N> y);
// Helper for computing distance terms for lighting (obsolete)
__generic<T : __BuiltinFloatingPointType> vector<T,4> dst(vector<T,4> x, vector<T,4> y);
// Error message
// void errorf( string format, ... );
// Attribute evaluation
__generic<T : __BuiltinArithmeticType> T EvaluateAttributeAtCentroid(T x);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> EvaluateAttributeAtCentroid(vector<T,N> x);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> EvaluateAttributeAtCentroid(matrix<T,N,M> x);
__generic<T : __BuiltinArithmeticType> T EvaluateAttributeAtSample(T x, uint sampleindex);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> EvaluateAttributeAtSample(vector<T,N> x, uint sampleindex);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> EvaluateAttributeAtSample(matrix<T,N,M> x, uint sampleindex);
__generic<T : __BuiltinArithmeticType> T EvaluateAttributeSnapped(T x, int2 offset);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> EvaluateAttributeSnapped(vector<T,N> x, int2 offset);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> EvaluateAttributeSnapped(matrix<T,N,M> x, int2 offset);
// Base-e exponent
__generic<T : __BuiltinFloatingPointType> T exp(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> exp(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> exp(matrix<T,N,M> x);
// Base-2 exponent
__generic<T : __BuiltinFloatingPointType> T exp2(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> exp2(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> exp2(matrix<T,N,M> x);
// Convert 16-bit float stored in low bits of integer
float f16tof32(uint value);
__generic<let N : int> vector<float,N> f16tof32(vector<uint,N> value);
// Convert to 16-bit float stored in low bits of integer
uint f32tof16(float value);
__generic<let N : int> vector<uint,N> f32tof16(vector<float,N> value);
// Flip surface normal to face forward, if needed
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> faceforward(vector<T,N> n, vector<T,N> i, vector<T,N> ng);
// Find first set bit starting at high bit and working down
int firstbithigh(int value);
__generic<let N : int> vector<int,N> firstbithigh(vector<int,N> value);
uint firstbithigh(uint value);
__generic<let N : int> vector<uint,N> firstbithigh(vector<uint,N> value);
// Find first set bit starting at low bit and working up
int firstbitlow(int value);
__generic<let N : int> vector<int,N> firstbitlow(vector<int,N> value);
uint firstbitlow(uint value);
__generic<let N : int> vector<uint,N> firstbitlow(vector<uint,N> value);
// Floor (HLSL SM 1.0)
__generic<T : __BuiltinFloatingPointType> T floor(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> floor(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> floor(matrix<T,N,M> x);
// Fused multiply-add for doubles
double fma(double a, double b, double c);
__generic<let N : int> vector<double, N> fma(vector<double, N> a, vector<double, N> b, vector<double, N> c);
__generic<let N : int, let M : int> matrix<double,N,M> fma(matrix<double,N,M> a, matrix<double,N,M> b, matrix<double,N,M> c);
// Floating point remainder of x/y
__generic<T : __BuiltinFloatingPointType> T fmod(T x, T y);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> fmod(vector<T,N> x, vector<T,N> y);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> fmod(matrix<T,N,M> x, matrix<T,N,M> y);
// Fractional part
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl, fract)
T frac(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl, fract)
vector<T,N> frac(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, fract)
matrix<T,N,M> frac(matrix<T,N,M> x);
// Split float into mantissa and exponent
__generic<T : __BuiltinFloatingPointType> T frexp(T x, out T exp);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> frexp(vector<T,N> x, out vector<T,N> exp);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> frexp(matrix<T,N,M> x, out matrix<T,N,M> exp);
// Texture filter width
__generic<T : __BuiltinFloatingPointType> T fwidth(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> fwidth(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> fwidth(matrix<T,N,M> x);
// Get number of samples in render target
uint GetRenderTargetSampleCount();
// Get position of given sample
float2 GetRenderTargetSamplePosition(int Index);
// Group memory barrier
void GroupMemoryBarrier();
void GroupMemoryBarrierWithGroupSync();
// Atomics
void InterlockedAdd(in out int dest, int value, out int original_value);
void InterlockedAdd(in out uint dest, uint value, out uint original_value);
void InterlockedAnd(in out int dest, int value, out int original_value);
void InterlockedAnd(in out uint dest, uint value, out uint original_value);
void InterlockedCompareExchange(in out int dest, int compare_value, int value, out int original_value);
void InterlockedCompareExchange(in out uint dest, uint compare_value, uint value, out uint original_value);
void InterlockedCompareStore(in out int dest, int compare_value, int value);
void InterlockedCompareStore(in out uint dest, uint compare_value, uint value);
void InterlockedExchange(in out int dest, int value, out int original_value);
void InterlockedExchange(in out uint dest, uint value, out uint original_value);
void InterlockedMax(in out int dest, int value, out int original_value);
void InterlockedMax(in out uint dest, uint value, out uint original_value);
void InterlockedMin(in out int dest, int value, out int original_value);
void InterlockedMin(in out uint dest, uint value, out uint original_value);
void InterlockedOr(in out int dest, int value, out int original_value);
void InterlockedOr(in out uint dest, uint value, out uint original_value);
void InterlockedXor(in out int dest, int value, out int original_value);
void InterlockedXor(in out uint dest, uint value, out uint original_value);
// Is floating-point value finite?
__generic<T : __BuiltinFloatingPointType> bool isfinite(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<bool,N> isfinite(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<bool,N,M> isfinite(matrix<T,N,M> x);
// Is floating-point value infinite?
__generic<T : __BuiltinFloatingPointType> bool isinf(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<bool,N> isinf(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<bool,N,M> isinf(matrix<T,N,M> x);
// Is floating-point value not-a-number?
__generic<T : __BuiltinFloatingPointType> bool isnan(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<bool,N> isnan(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<bool,N,M> isnan(matrix<T,N,M> x);
// Construct float from mantissa and exponent
__generic<T : __BuiltinFloatingPointType> T ldexp(T x, T exp);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> ldexp(vector<T,N> x, vector<T,N> exp);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> ldexp(matrix<T,N,M> x, matrix<T,N,M> exp);
// Vector length
__generic<T : __BuiltinFloatingPointType, let N : int> T length(vector<T,N> x);
// Linear interpolation
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl, mix)
T lerp(T x, T y, T s);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl, mix)
vector<T,N> lerp(vector<T,N> x, vector<T,N> y, vector<T,N> s);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, mix)
matrix<T,N,M> lerp(matrix<T,N,M> x, matrix<T,N,M> y, matrix<T,N,M> s);
// Legacy lighting function (obsolete)
float4 lit(float n_dot_l, float n_dot_h, float m);
// Base-e logarithm
__generic<T : __BuiltinFloatingPointType> T log(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log(matrix<T,N,M> x);
// Base-10 logarithm
__generic<T : __BuiltinFloatingPointType> T log10(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log10(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log10(matrix<T,N,M> x);
// Base-2 logarithm
__generic<T : __BuiltinFloatingPointType> T log2(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> log2(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> log2(matrix<T,N,M> x);
// multiply-add
__generic<T : __BuiltinArithmeticType> T mad(T mvalue, T avalue, T bvalue);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> mad(vector<T,N> mvalue, vector<T,N> avalue, vector<T,N> bvalue);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> mad(matrix<T,N,M> mvalue, matrix<T,N,M> avalue, matrix<T,N,M> bvalue);
// maximum
__generic<T : __BuiltinArithmeticType> T max(T x, T y);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> max(vector<T,N> x, vector<T,N> y);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> max(matrix<T,N,M> x, matrix<T,N,M> y);
// minimum
__generic<T : __BuiltinArithmeticType> T min(T x, T y);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> min(vector<T,N> x, vector<T,N> y);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> min(matrix<T,N,M> x, matrix<T,N,M> y);
// split into integer and fractional parts (both with same sign)
__generic<T : __BuiltinFloatingPointType> T modf(T x, out T ip);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> modf(vector<T,N> x, out vector<T,N> ip);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> modf(matrix<T,N,M> x, out matrix<T,N,M> ip);
// msad4 (whatever that is)
uint4 msad4(uint reference, uint2 source, uint4 accum);
// General inner products
// scalar-scalar
__generic<T : __BuiltinArithmeticType> T mul(T x, T y);
// scalar-vector and vector-scalar
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> mul(vector<T,N> x, T y);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> mul(T x, vector<T,N> y);
// scalar-matrix and matrix-scalar
__generic<T : __BuiltinArithmeticType, let N : int, let M :int> matrix<T,N,M> mul(matrix<T,N,M> x, T y);
__generic<T : __BuiltinArithmeticType, let N : int, let M :int> matrix<T,N,M> mul(T x, matrix<T,N,M> y);
// vector-vector (dot product)
__generic<T : __BuiltinArithmeticType, let N : int> __intrinsic_op(dot) T mul(vector<T,N> x, vector<T,N> y);
// vector-matrix
__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);
// matrix-vector
__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);
// matrix-matrix
__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);
// noise (deprecated)
float noise(float x);
__generic<let N : int> float noise(vector<float, N> x);
// Normalize a vector
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> normalize(vector<T,N> x);
// Raise to a power
__generic<T : __BuiltinFloatingPointType> T pow(T x, T y);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> pow(vector<T,N> x, vector<T,N> y);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> pow(matrix<T,N,M> x, matrix<T,N,M> y);
// Output message
// void printf( string format, ... );
// Tessellation factor fixup routines
void Process2DQuadTessFactorsAvg(
in float4 RawEdgeFactors,
in float2 InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void Process2DQuadTessFactorsMax(
in float4 RawEdgeFactors,
in float2 InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void Process2DQuadTessFactorsMin(
in float4 RawEdgeFactors,
in float2 InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void ProcessIsolineTessFactors(
in float RawDetailFactor,
in float RawDensityFactor,
out float RoundedDetailFactor,
out float RoundedDensityFactor);
void ProcessQuadTessFactorsAvg(
in float4 RawEdgeFactors,
in float InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void ProcessQuadTessFactorsMax(
in float4 RawEdgeFactors,
in float InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void ProcessQuadTessFactorsMin(
in float4 RawEdgeFactors,
in float InsideScale,
out float4 RoundedEdgeTessFactors,
out float2 RoundedInsideTessFactors,
out float2 UnroundedInsideTessFactors);
void ProcessTriTessFactorsAvg(
in float3 RawEdgeFactors,
in float InsideScale,
out float3 RoundedEdgeTessFactors,
out float RoundedInsideTessFactor,
out float UnroundedInsideTessFactor);
void ProcessTriTessFactorsMax(
in float3 RawEdgeFactors,
in float InsideScale,
out float3 RoundedEdgeTessFactors,
out float RoundedInsideTessFactor,
out float UnroundedInsideTessFactor);
void ProcessTriTessFactorsMin(
in float3 RawEdgeFactors,
in float InsideScale,
out float3 RoundedEdgeTessFactors,
out float RoundedInsideTessFactors,
out float UnroundedInsideTessFactors);
// Degrees to radians
__generic<T : __BuiltinFloatingPointType> T radians(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> radians(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> radians(matrix<T,N,M> x);
// Approximate reciprocal
__generic<T : __BuiltinFloatingPointType> T rcp(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> rcp(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> rcp(matrix<T,N,M> x);
// Reflect incident vector across plane with given normal
__generic<T : __BuiltinFloatingPointType, let N : int>
vector<T,N> reflect(vector<T,N> i, vector<T,N> n);
// Refract incident vector given surface normal and index of refraction
__generic<T : __BuiltinFloatingPointType, let N : int>
vector<T,N> refract(vector<T,N> i, vector<T,N> n, float eta);
// Reverse order of bits
uint reversebits(uint value);
__generic<let N : int> vector<uint,N> reversebits(vector<uint,N> value);
// Round-to-nearest
__generic<T : __BuiltinFloatingPointType> T round(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> round(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> round(matrix<T,N,M> x);
// Reciprocal of square root
__generic<T : __BuiltinFloatingPointType> T rsqrt(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> rsqrt(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> rsqrt(matrix<T,N,M> x);
// Clamp value to [0,1] range
__generic<T : __BuiltinFloatingPointType>
__target_intrinsic(glsl, "clamp($0, 0, 1)")
T saturate(T x);
__generic<T : __BuiltinFloatingPointType, let N : int>
__target_intrinsic(glsl, "clamp($0, 0, 1)")
vector<T,N> saturate(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__target_intrinsic(glsl, "clamp($0, 0, 1)")
matrix<T,N,M> saturate(matrix<T,N,M> x);
__generic<T : __BuiltinFloatingPointType>
__specialized_for_target(glsl)
T saturate(T x)
{
return clamp<T>(x, T(0), T(1));
}
__generic<T : __BuiltinFloatingPointType, let N : int>
__specialized_for_target(glsl)
vector<T,N> saturate(vector<T,N> x)
{
return clamp<T,N>(x,
vector<T,N>(T(0)),
vector<T,N>(T(1)));
}
// HACK: need a helper to turn a scalar into a matrix,
// because GLSL and HLSL disagree on the semantics of
// constructing a matrix from a single scalar.
__generic<T, let N : int, let M : int>
matrix<T,N,M> __scalarToMatrix(T value);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
__specialized_for_target(glsl)
matrix<T,N,M> saturate(matrix<T,N,M> x)
{
return clamp<T,N,M>(x,
__scalarToMatrix<T,N,M>(T(0)),
__scalarToMatrix<T,N,M>(T(1)));
}
// Extract sign of value
__generic<T : __BuiltinSignedArithmeticType> int sign(T x);
__generic<T : __BuiltinSignedArithmeticType, let N : int> vector<int,N> sign(vector<T,N> x);
__generic<T : __BuiltinSignedArithmeticType, let N : int, let M : int> matrix<int,N,M> sign(matrix<T,N,M> x);
// Sine
__generic<T : __BuiltinFloatingPointType> T sin(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> sin(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> sin(matrix<T,N,M> x);
// Sine and cosine
__generic<T : __BuiltinFloatingPointType, let N : int> void sincos(T x, out T s, out T c);
__generic<T : __BuiltinFloatingPointType, let N : int> void sincos(vector<T,N> x, out vector<T,N> s, out vector<T,N> c);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> void sincos(matrix<T,N,M> x, out matrix<T,N,M> s, out matrix<T,N,M> c);
// Hyperbolic Sine
__generic<T : __BuiltinFloatingPointType> T sinh(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> sinh(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> sinh(matrix<T,N,M> x);
// Smooth step (Hermite interpolation)
__generic<T : __BuiltinFloatingPointType> T smoothstep(T min, T max, T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> smoothstep(vector<T,N> min, vector<T,N> max, vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> smoothstep(matrix<T,N,M> min, matrix<T,N,M> max, matrix<T,N,M> x);
// Square root
__generic<T : __BuiltinFloatingPointType> T sqrt(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> sqrt(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> sqrt(matrix<T,N,M> x);
// Step function
__generic<T : __BuiltinFloatingPointType> T step(T y, T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> step(vector<T,N> y, vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> step(matrix<T,N,M> y, matrix<T,N,M> x);
// Tangent
__generic<T : __BuiltinFloatingPointType> T tan(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> tan(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> tan(matrix<T,N,M> x);
// Hyperbolic tangent
__generic<T : __BuiltinFloatingPointType> T tanh(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> tanh(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> tanh(matrix<T,N,M> x);
// Legacy texture-fetch operations
/*
float4 tex1D(sampler1D s, float t);
float4 tex1D(sampler1D s, float t, float ddx, float ddy);
float4 tex1Dbias(sampler1D s, float4 t);
float4 tex1Dgrad(sampler1D s, float t, float ddx, float ddy);
float4 tex1Dlod(sampler1D s, float4 t);
float4 tex1Dproj(sampler1D s, float4 t);
float4 tex2D(sampler2D s, float2 t);
float4 tex2D(sampler2D s, float2 t, float2 ddx, float2 ddy);
float4 tex2Dbias(sampler2D s, float4 t);
float4 tex2Dgrad(sampler2D s, float2 t, float2 ddx, float2 ddy);
float4 tex2Dlod(sampler2D s, float4 t);
float4 tex2Dproj(sampler2D s, float4 t);
float4 tex3D(sampler3D s, float3 t);
float4 tex3D(sampler3D s, float3 t, float3 ddx, float3 ddy);
float4 tex3Dbias(sampler3D s, float4 t);
float4 tex3Dgrad(sampler3D s, float3 t, float3 ddx, float3 ddy);
float4 tex3Dlod(sampler3D s, float4 t);
float4 tex3Dproj(sampler3D s, float4 t);
float4 texCUBE(samplerCUBE s, float3 t);
float4 texCUBE(samplerCUBE s, float3 t, float3 ddx, float3 ddy);
float4 texCUBEbias(samplerCUBE s, float4 t);
float4 texCUBEgrad(samplerCUBE s, float3 t, float3 ddx, float3 ddy);
float4 texCUBElod(samplerCUBE s, float4 t);
float4 texCUBEproj(samplerCUBE s, float4 t);
*/
// Matrix transpose
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,M,N> transpose(matrix<T,N,M> x);
// Truncate to integer
__generic<T : __BuiltinFloatingPointType> T trunc(T x);
__generic<T : __BuiltinFloatingPointType, let N : int> vector<T,N> trunc(vector<T,N> x);
__generic<T : __BuiltinFloatingPointType, let N : int, let M : int> matrix<T,N,M> trunc(matrix<T,N,M> x);
// Shader model 6.0 stuff
uint GlobalOrderedCountIncrement(uint countToAppendForThisLane);
__generic<T : __BuiltinType> T QuadReadLaneAt(T sourceValue, int quadLaneID);
__generic<T : __BuiltinType, let N : int> vector<T,N> QuadReadLaneAt(vector<T,N> sourceValue, int quadLaneID);
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadReadLaneAt(matrix<T,N,M> sourceValue, int quadLaneID);
__generic<T : __BuiltinType> T QuadSwapX(T localValue);
__generic<T : __BuiltinType, let N : int> vector<T,N> QuadSwapX(vector<T,N> localValue);
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadSwapX(matrix<T,N,M> localValue);
__generic<T : __BuiltinType> T QuadSwapY(T localValue);
__generic<T : __BuiltinType, let N : int> vector<T,N> QuadSwapY(vector<T,N> localValue);
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> QuadSwapY(matrix<T,N,M> localValue);
__generic<T : __BuiltinIntegerType> T WaveAllBitAnd(T expr);
__generic<T : __BuiltinIntegerType, let N : int> vector<T,N> WaveAllBitAnd(vector<T,N> expr);
__generic<T : __BuiltinIntegerType, let N : int, let M : int> matrix<T,N,M> WaveAllBitAnd(matrix<T,N,M> expr);
__generic<T : __BuiltinIntegerType> T WaveAllBitOr(T expr);
__generic<T : __BuiltinIntegerType, let N : int> vector<T,N> WaveAllBitOr(vector<T,N> expr);
__generic<T : __BuiltinIntegerType, let N : int, let M : int> matrix<T,N,M> WaveAllBitOr(matrix<T,N,M> expr);
__generic<T : __BuiltinIntegerType> T WaveAllBitXor(T expr);
__generic<T : __BuiltinIntegerType, let N : int> vector<T,N> WaveAllBitXor(vector<T,N> expr);
__generic<T : __BuiltinIntegerType, let N : int, let M : int> matrix<T,N,M> WaveAllBitXor(matrix<T,N,M> expr);
__generic<T : __BuiltinArithmeticType> T WaveAllMax(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WaveAllMax(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WaveAllMax(matrix<T,N,M> expr);
__generic<T : __BuiltinArithmeticType> T WaveAllMin(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WaveAllMin(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WaveAllMin(matrix<T,N,M> expr);
__generic<T : __BuiltinArithmeticType> T WaveAllProduct(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WaveAllProduct(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WaveAllProduct(matrix<T,N,M> expr);
__generic<T : __BuiltinArithmeticType> T WaveAllSum(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WaveAllSum(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WaveAllSum(matrix<T,N,M> expr);
bool WaveAllEqual(bool expr);
bool WaveAllTrue(bool expr);
bool WaveAnyTrue(bool expr);
uint64_t WaveBallot(bool expr);
uint WaveGetLaneCount();
uint WaveGetLaneIndex();
uint WaveGetOrderedIndex();
bool WaveIsHelperLane();
bool WaveOnce();
__generic<T : __BuiltinArithmeticType> T WavePrefixProduct(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WavePrefixProduct(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WavePrefixProduct(matrix<T,N,M> expr);
__generic<T : __BuiltinArithmeticType> T WavePrefixSum(T expr);
__generic<T : __BuiltinArithmeticType, let N : int> vector<T,N> WavePrefixSum(vector<T,N> expr);
__generic<T : __BuiltinArithmeticType, let N : int, let M : int> matrix<T,N,M> WavePrefixSum(matrix<T,N,M> expr);
__generic<T : __BuiltinType> T WaveReadFirstLane(T expr);
__generic<T : __BuiltinType, let N : int> vector<T,N> WaveReadFirstLane(vector<T,N> expr);
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> WaveReadFirstLane(matrix<T,N,M> expr);
__generic<T : __BuiltinType> T WaveReadLaneAt(T expr, int laneIndex);
__generic<T : __BuiltinType, let N : int> vector<T,N> WaveReadLaneAt(vector<T,N> expr, int laneIndex);
__generic<T : __BuiltinType, let N : int, let M : int> matrix<T,N,M> WaveReadLaneAt(matrix<T,N,M> expr, int laneIndex);
// `typedef`s to help with the fact that HLSL has been sorta-kinda case insensitive at various points
typedef Texture2D texture2D;
${{{{
// 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 << "void GetDimensions(out uint dim);\n";
sb << "__target_intrinsic(glsl, \"texelFetch($$P, $1)$$z\")\n";
sb << "T Load(int location);\n";
sb << "T Load(int location, out uint status);\n";
sb << "__target_intrinsic(glsl, \"texelFetch($$P, int($1))$$z\")\n";
sb << "__subscript(uint index) -> T";
if (kBaseBufferAccessLevels[aa].access != SLANG_RESOURCE_ACCESS_READ)
{
sb << " { get; set; }\n";
}
else
{
sb << ";\n";
}
sb << "};\n";
}
}}}}
|