forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slang.h
4819 lines (3925 loc) · 197 KB
/
slang.h
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
#ifndef SLANG_H
#define SLANG_H
/** \file slang.h
The Slang API provides services to compile, reflect, and specialize code
written in the Slang shading language.
*/
/*
The following section attempts to detect the compiler and version in use.
If an application defines `SLANG_COMPILER` before including this header,
they take responsibility for setting any compiler-dependent macros
used later in the file.
Most applications should not need to touch this section.
*/
#ifndef SLANG_COMPILER
# define SLANG_COMPILER
/*
Compiler defines, see http://sourceforge.net/p/predef/wiki/Compilers/
NOTE that SLANG_VC holds the compiler version - not just 1 or 0
*/
# if defined(_MSC_VER)
# if _MSC_VER >= 1900
# define SLANG_VC 14
# elif _MSC_VER >= 1800
# define SLANG_VC 12
# elif _MSC_VER >= 1700
# define SLANG_VC 11
# elif _MSC_VER >= 1600
# define SLANG_VC 10
# elif _MSC_VER >= 1500
# define SLANG_VC 9
# else
# error "unknown version of Visual C++ compiler"
# endif
# elif defined(__clang__)
# define SLANG_CLANG 1
# elif defined(__SNC__)
# define SLANG_SNC 1
# elif defined(__ghs__)
# define SLANG_GHS 1
# elif defined(__GNUC__) /* note: __clang__, __SNC__, or __ghs__ imply __GNUC__ */
# define SLANG_GCC 1
# else
# error "unknown compiler"
# endif
/*
Any compilers not detected by the above logic are now now explicitly zeroed out.
*/
# ifndef SLANG_VC
# define SLANG_VC 0
# endif
# ifndef SLANG_CLANG
# define SLANG_CLANG 0
# endif
# ifndef SLANG_SNC
# define SLANG_SNC 0
# endif
# ifndef SLANG_GHS
# define SLANG_GHS 0
# endif
# ifndef SLANG_GCC
# define SLANG_GCC 0
# endif
#endif /* SLANG_COMPILER */
/*
The following section attempts to detect the target platform being compiled for.
If an application defines `SLANG_PLATFORM` before including this header,
they take responsibility for setting any compiler-dependent macros
used later in the file.
Most applications should not need to touch this section.
*/
#ifndef SLANG_PLATFORM
# define SLANG_PLATFORM
/**
Operating system defines, see http://sourceforge.net/p/predef/wiki/OperatingSystems/
*/
# if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_PARTITION_APP
# define SLANG_WINRT 1 /* Windows Runtime, either on Windows RT or Windows 8 */
# elif defined(XBOXONE)
# define SLANG_XBOXONE 1
# elif defined(_WIN64) /* note: XBOXONE implies _WIN64 */
# define SLANG_WIN64 1
# elif defined(_M_PPC)
# define SLANG_X360 1
# elif defined(_WIN32) /* note: _M_PPC implies _WIN32 */
# define SLANG_WIN32 1
# elif defined(__ANDROID__)
# define SLANG_ANDROID 1
# elif defined(__linux__) || defined(__CYGWIN__) /* note: __ANDROID__ implies __linux__ */
# define SLANG_LINUX 1
# elif defined(__APPLE__)
# include "TargetConditionals.h"
# if TARGET_OS_MAC
# define SLANG_OSX 1
# else
# define SLANG_IOS 1
# endif
# elif defined(__CELLOS_LV2__)
# define SLANG_PS3 1
# elif defined(__ORBIS__)
# define SLANG_PS4 1
# elif defined(__SNC__) && defined(__arm__)
# define SLANG_PSP2 1
# elif defined(__ghs__)
# define SLANG_WIIU 1
# else
# error "unknown target platform"
# endif
/*
Any platforms not detected by the above logic are now now explicitly zeroed out.
*/
# ifndef SLANG_WINRT
# define SLANG_WINRT 0
# endif
# ifndef SLANG_XBOXONE
# define SLANG_XBOXONE 0
# endif
# ifndef SLANG_WIN64
# define SLANG_WIN64 0
# endif
# ifndef SLANG_X360
# define SLANG_X360 0
# endif
# ifndef SLANG_WIN32
# define SLANG_WIN32 0
# endif
# ifndef SLANG_ANDROID
# define SLANG_ANDROID 0
# endif
# ifndef SLANG_LINUX
# define SLANG_LINUX 0
# endif
# ifndef SLANG_IOS
# define SLANG_IOS 0
# endif
# ifndef SLANG_OSX
# define SLANG_OSX 0
# endif
# ifndef SLANG_PS3
# define SLANG_PS3 0
# endif
# ifndef SLANG_PS4
# define SLANG_PS4 0
# endif
# ifndef SLANG_PSP2
# define SLANG_PSP2 0
# endif
# ifndef SLANG_WIIU
# define SLANG_WIIU 0
# endif
#endif /* SLANG_PLATFORM */
/* Shorthands for "families" of compilers/platforms */
#define SLANG_GCC_FAMILY (SLANG_CLANG || SLANG_SNC || SLANG_GHS || SLANG_GCC)
#define SLANG_WINDOWS_FAMILY (SLANG_WINRT || SLANG_WIN32 || SLANG_WIN64)
#define SLANG_MICROSOFT_FAMILY (SLANG_XBOXONE || SLANG_X360 || SLANG_WINDOWS_FAMILY)
#define SLANG_LINUX_FAMILY (SLANG_LINUX || SLANG_ANDROID)
#define SLANG_APPLE_FAMILY (SLANG_IOS || SLANG_OSX) /* equivalent to #if __APPLE__ */
#define SLANG_UNIX_FAMILY (SLANG_LINUX_FAMILY || SLANG_APPLE_FAMILY) /* shortcut for unix/posix platforms */
/* Macros concerning DirectX */
#if !defined(SLANG_CONFIG_DX_ON_VK) || !SLANG_CONFIG_DX_ON_VK
# define SLANG_ENABLE_DXVK 0
# define SLANG_ENABLE_VKD3D 0
#else
# define SLANG_ENABLE_DXVK 1
# define SLANG_ENABLE_VKD3D 1
#endif
#if SLANG_WINDOWS_FAMILY
# define SLANG_ENABLE_DIRECTX 1
# define SLANG_ENABLE_DXGI_DEBUG 1
# define SLANG_ENABLE_DXBC_SUPPORT 1
# define SLANG_ENABLE_PIX 1
#elif SLANG_LINUX_FAMILY
# define SLANG_ENABLE_DIRECTX (SLANG_ENABLE_DXVK || SLANG_ENABLE_VKD3D)
# define SLANG_ENABLE_DXGI_DEBUG 0
# define SLANG_ENABLE_DXBC_SUPPORT 0
# define SLANG_ENABLE_PIX 0
#else
# define SLANG_ENABLE_DIRECTX 0
# define SLANG_ENABLE_DXGI_DEBUG 0
# define SLANG_ENABLE_DXBC_SUPPORT 0
# define SLANG_ENABLE_PIX 0
#endif
/* Macro for declaring if a method is no throw. Should be set before the return parameter. */
#ifndef SLANG_NO_THROW
# if SLANG_WINDOWS_FAMILY && !defined(SLANG_DISABLE_EXCEPTIONS)
# define SLANG_NO_THROW __declspec(nothrow)
# endif
#endif
#ifndef SLANG_NO_THROW
# define SLANG_NO_THROW
#endif
/* The `SLANG_STDCALL` and `SLANG_MCALL` defines are used to set the calling
convention for interface methods.
*/
#ifndef SLANG_STDCALL
# if SLANG_MICROSOFT_FAMILY
# define SLANG_STDCALL __stdcall
# else
# define SLANG_STDCALL
# endif
#endif
#ifndef SLANG_MCALL
# define SLANG_MCALL SLANG_STDCALL
#endif
#if !defined(SLANG_STATIC) && !defined(SLANG_DYNAMIC)
#define SLANG_DYNAMIC
#endif
#if defined(_MSC_VER)
# define SLANG_DLL_EXPORT __declspec(dllexport)
#else
# if 0 && __GNUC__ >= 4
// Didn't work on latest gcc on linux.. so disable for now
// https://gcc.gnu.org/wiki/Visibility
# define SLANG_DLL_EXPORT __attribute__ ((dllexport))
# else
# define SLANG_DLL_EXPORT __attribute__((__visibility__("default")))
# endif
#endif
#if defined(SLANG_DYNAMIC)
# if defined(_MSC_VER)
# ifdef SLANG_DYNAMIC_EXPORT
# define SLANG_API SLANG_DLL_EXPORT
# else
# define SLANG_API __declspec(dllimport)
# endif
# else
// TODO: need to consider compiler capabilities
//# ifdef SLANG_DYNAMIC_EXPORT
# define SLANG_API SLANG_DLL_EXPORT
//# endif
# endif
#endif
#ifndef SLANG_API
# define SLANG_API
#endif
// GCC Specific
#if SLANG_GCC_FAMILY
# define SLANG_NO_INLINE __attribute__((noinline))
# define SLANG_FORCE_INLINE inline __attribute__((always_inline))
# define SLANG_BREAKPOINT(id) __builtin_trap();
# define SLANG_ALIGN_OF(T) __alignof__(T)
// Use the builtin directly so we don't need to have an include of stddef.h
# define SLANG_OFFSET_OF(T, ELEMENT) __builtin_offsetof(T, ELEMENT)
#endif // SLANG_GCC_FAMILY
#ifndef SLANG_OFFSET_OF
# define SLANG_OFFSET_OF(T, ELEMENT) (size_t(&((T*)1)->ELEMENT) - 1)
#endif
// Microsoft VC specific
#if SLANG_MICROSOFT_FAMILY
# define SLANG_NO_INLINE __declspec(noinline)
# define SLANG_FORCE_INLINE __forceinline
# define SLANG_BREAKPOINT(id) __debugbreak();
# define SLANG_ALIGN_OF(T) __alignof(T)
# define SLANG_INT64(x) (x##i64)
# define SLANG_UINT64(x) (x##ui64)
#endif // SLANG_MICROSOFT_FAMILY
#ifndef SLANG_FORCE_INLINE
# define SLANG_FORCE_INLINE inline
#endif
#ifndef SLANG_NO_INLINE
# define SLANG_NO_INLINE
#endif
#ifndef SLANG_COMPILE_TIME_ASSERT
# define SLANG_COMPILE_TIME_ASSERT(x) static_assert(x)
#endif
#ifndef SLANG_OFFSET_OF
# define SLANG_OFFSET_OF(X, Y) offsetof(X, Y)
#endif
#ifndef SLANG_BREAKPOINT
// Make it crash with a write to 0!
# define SLANG_BREAKPOINT(id) (*((int*)0) = int(id));
#endif
// Use for getting the amount of members of a standard C array.
// Use 0[x] here to catch the case where x has an overloaded subscript operator
#define SLANG_COUNT_OF(x) (SlangSSizeT(sizeof(x)/sizeof(0[x])))
/// SLANG_INLINE exists to have a way to inline consistent with SLANG_ALWAYS_INLINE
#define SLANG_INLINE inline
// If explicilty disabled and not set, set to not available
#if !defined(SLANG_HAS_EXCEPTIONS) && defined(SLANG_DISABLE_EXCEPTIONS)
# define SLANG_HAS_EXCEPTIONS 0
#endif
// If not set, the default is exceptions are available
#ifndef SLANG_HAS_EXCEPTIONS
# define SLANG_HAS_EXCEPTIONS 1
#endif
// Other defines
#define SLANG_STRINGIZE_HELPER(X) #X
#define SLANG_STRINGIZE(X) SLANG_STRINGIZE_HELPER(X)
#define SLANG_CONCAT_HELPER(X, Y) X##Y
#define SLANG_CONCAT(X, Y) SLANG_CONCAT_HELPER(X, Y)
#ifndef SLANG_UNUSED
# define SLANG_UNUSED(v) (void)v;
#endif
// Used for doing constant literals
#ifndef SLANG_INT64
# define SLANG_INT64(x) (x##ll)
#endif
#ifndef SLANG_UINT64
# define SLANG_UINT64(x) (x##ull)
#endif
#ifdef __cplusplus
# define SLANG_EXTERN_C extern "C"
#else
# define SLANG_EXTERN_C
#endif
#ifdef __cplusplus
// C++ specific macros
// Clang
#if SLANG_CLANG
# if (__clang_major__*10 + __clang_minor__) >= 33
# define SLANG_HAS_MOVE_SEMANTICS 1
# define SLANG_HAS_ENUM_CLASS 1
# define SLANG_OVERRIDE override
# endif
// Gcc
#elif SLANG_GCC_FAMILY
// Check for C++11
# if (__cplusplus >= 201103L)
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
# define SLANG_HAS_MOVE_SEMANTICS 1
# endif
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
# define SLANG_HAS_ENUM_CLASS 1
# endif
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407
# define SLANG_OVERRIDE override
# endif
# endif
// TODO(JS): Not used in previous code. Left here as may be useful on some other version.
// #define SLANG_RETURN_NEVER __attribute__((__noreturn__))
# define SLANG_RETURN_NEVER [[noreturn]]
# endif // SLANG_GCC_FAMILY
// Visual Studio
# if SLANG_VC
// C4481: nonstandard extension used: override specifier 'override'
# if _MSC_VER < 1700
# pragma warning(disable : 4481)
# endif
# define SLANG_OVERRIDE override
# if _MSC_VER >= 1600
# define SLANG_HAS_MOVE_SEMANTICS 1
# endif
# if _MSC_VER >= 1700
# define SLANG_HAS_ENUM_CLASS 1
# endif
# define SLANG_RETURN_NEVER __declspec(noreturn)
# endif // SLANG_VC
// Set non set
# ifndef SLANG_OVERRIDE
# define SLANG_OVERRIDE
# endif
# ifndef SLANG_HAS_ENUM_CLASS
# define SLANG_HAS_ENUM_CLASS 0
# endif
# ifndef SLANG_HAS_MOVE_SEMANTICS
# define SLANG_HAS_MOVE_SEMANTICS 0
# endif
#endif // __cplusplus
#ifndef SLANG_RETURN_NEVER
# define SLANG_RETURN_NEVER [[noreturn]]
#endif // SLANG_RETURN_NEVER
/* Macros for detecting processor */
#if defined(_M_ARM) || defined(__ARM_EABI__)
// This is special case for nVidia tegra
# define SLANG_PROCESSOR_ARM 1
#elif defined(__i386__) || defined(_M_IX86)
# define SLANG_PROCESSOR_X86 1
#elif defined(_M_AMD64) || defined(_M_X64) || defined(__amd64) || defined(__x86_64)
# define SLANG_PROCESSOR_X86_64 1
#elif defined(_PPC_) || defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC)
# if defined(__powerpc64__) || defined(__ppc64__) || defined(__PPC64__) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__)
# define SLANG_PROCESSOR_POWER_PC_64 1
# else
# define SLANG_PROCESSOR_POWER_PC 1
# endif
#elif defined(__arm__)
# define SLANG_PROCESSOR_ARM 1
#elif defined(_M_ARM64) || defined(__aarch64__)
# define SLANG_PROCESSOR_ARM_64 1
#endif
#ifndef SLANG_PROCESSOR_ARM
# define SLANG_PROCESSOR_ARM 0
#endif
#ifndef SLANG_PROCESSOR_ARM_64
# define SLANG_PROCESSOR_ARM_64 0
#endif
#ifndef SLANG_PROCESSOR_X86
# define SLANG_PROCESSOR_X86 0
#endif
#ifndef SLANG_PROCESSOR_X86_64
# define SLANG_PROCESSOR_X86_64 0
#endif
#ifndef SLANG_PROCESSOR_POWER_PC
# define SLANG_PROCESSOR_POWER_PC 0
#endif
#ifndef SLANG_PROCESSOR_POWER_PC_64
# define SLANG_PROCESSOR_POWER_PC_64 0
#endif
// Processor families
#define SLANG_PROCESSOR_FAMILY_X86 (SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_X86)
#define SLANG_PROCESSOR_FAMILY_ARM (SLANG_PROCESSOR_ARM | SLANG_PROCESSOR_ARM_64)
#define SLANG_PROCESSOR_FAMILY_POWER_PC (SLANG_PROCESSOR_POWER_PC_64 | SLANG_PROCESSOR_POWER_PC)
// Pointer size
#define SLANG_PTR_IS_64 (SLANG_PROCESSOR_ARM_64 | SLANG_PROCESSOR_X86_64 | SLANG_PROCESSOR_POWER_PC_64)
#define SLANG_PTR_IS_32 (SLANG_PTR_IS_64 ^ 1)
// Processor features
#if SLANG_PROCESSOR_FAMILY_X86
# define SLANG_LITTLE_ENDIAN 1
# define SLANG_UNALIGNED_ACCESS 1
#elif SLANG_PROCESSOR_FAMILY_ARM
# if defined(__ARMEB__)
# define SLANG_BIG_ENDIAN 1
# else
# define SLANG_LITTLE_ENDIAN 1
# endif
#elif SLANG_PROCESSOR_FAMILY_POWER_PC
# define SLANG_BIG_ENDIAN 1
#endif
#ifndef SLANG_LITTLE_ENDIAN
# define SLANG_LITTLE_ENDIAN 0
#endif
#ifndef SLANG_BIG_ENDIAN
# define SLANG_BIG_ENDIAN 0
#endif
#ifndef SLANG_UNALIGNED_ACCESS
# define SLANG_UNALIGNED_ACCESS 0
#endif
// One endianess must be set
#if ((SLANG_BIG_ENDIAN | SLANG_LITTLE_ENDIAN) == 0)
# error "Couldn't determine endianess"
#endif
#ifndef SLANG_NO_INTTYPES
#include <inttypes.h>
#endif // ! SLANG_NO_INTTYPES
#ifndef SLANG_NO_STDDEF
#include <stddef.h>
#endif // ! SLANG_NO_STDDEF
#ifdef __cplusplus
extern "C"
{
#endif
/*!
@mainpage Introduction
API Reference: slang.h
@file slang.h
*/
typedef uint32_t SlangUInt32;
typedef int32_t SlangInt32;
// Use SLANG_PTR_ macros to determine SlangInt/SlangUInt types.
// This is used over say using size_t/ptrdiff_t/intptr_t/uintptr_t, because on some targets, these types are distinct from
// their uint_t/int_t equivalents and so produce ambiguity with function overloading.
//
// SlangSizeT is helpful as on some compilers size_t is distinct from a regular integer type and so overloading doesn't work.
// Casting to SlangSizeT works around this.
#if SLANG_PTR_IS_64
typedef int64_t SlangInt;
typedef uint64_t SlangUInt;
typedef int64_t SlangSSizeT;
typedef uint64_t SlangSizeT;
#else
typedef int32_t SlangInt;
typedef uint32_t SlangUInt;
typedef int32_t SlangSSizeT;
typedef uint32_t SlangSizeT;
#endif
typedef bool SlangBool;
/*!
@brief Severity of a diagnostic generated by the compiler.
Values come from the enum below, with higher values representing more severe
conditions, and all values >= SLANG_SEVERITY_ERROR indicating compilation
failure.
*/
typedef int SlangSeverityIntegral;
enum SlangSeverity : SlangSeverityIntegral
{
SLANG_SEVERITY_DISABLED = 0, /**< A message that is disabled, filtered out. */
SLANG_SEVERITY_NOTE, /**< An informative message. */
SLANG_SEVERITY_WARNING, /**< A warning, which indicates a possible proble. */
SLANG_SEVERITY_ERROR, /**< An error, indicating that compilation failed. */
SLANG_SEVERITY_FATAL, /**< An unrecoverable error, which forced compilation to abort. */
SLANG_SEVERITY_INTERNAL, /**< An internal error, indicating a logic error in the compiler. */
};
typedef int SlangDiagnosticFlags;
enum
{
SLANG_DIAGNOSTIC_FLAG_VERBOSE_PATHS = 0x01,
SLANG_DIAGNOSTIC_FLAG_TREAT_WARNINGS_AS_ERRORS = 0x02
};
typedef int SlangBindableResourceIntegral;
enum SlangBindableResourceType : SlangBindableResourceIntegral
{
SLANG_NON_BINDABLE = 0,
SLANG_TEXTURE,
SLANG_SAMPLER,
SLANG_UNIFORM_BUFFER,
SLANG_STORAGE_BUFFER,
};
/* NOTE! To keep binary compatibility care is needed with this enum!
* To add value, only add at the bottom (before COUNT_OF)
* To remove a value, add _DEPRECATED as a suffix, but leave in the list
This will make the enum values stable, and compatible with libraries that might not use the latest
enum values.
*/
typedef int SlangCompileTargetIntegral;
enum SlangCompileTarget : SlangCompileTargetIntegral
{
SLANG_TARGET_UNKNOWN,
SLANG_TARGET_NONE,
SLANG_GLSL,
SLANG_GLSL_VULKAN, //< deprecated: just use `SLANG_GLSL`
SLANG_GLSL_VULKAN_ONE_DESC, //< deprecated
SLANG_HLSL,
SLANG_SPIRV,
SLANG_SPIRV_ASM,
SLANG_DXBC,
SLANG_DXBC_ASM,
SLANG_DXIL,
SLANG_DXIL_ASM,
SLANG_C_SOURCE, ///< The C language
SLANG_CPP_SOURCE, ///< C++ code for shader kernels.
SLANG_HOST_EXECUTABLE, ///< Standalone binary executable (for hosting CPU/OS)
SLANG_SHADER_SHARED_LIBRARY, ///< A shared library/Dll for shader kernels (for hosting CPU/OS)
SLANG_SHADER_HOST_CALLABLE, ///< A CPU target that makes the compiled shader code available to be run immediately
SLANG_CUDA_SOURCE, ///< Cuda source
SLANG_PTX, ///< PTX
SLANG_CUDA_OBJECT_CODE, ///< Object code that contains CUDA functions.
SLANG_OBJECT_CODE, ///< Object code that can be used for later linking
SLANG_HOST_CPP_SOURCE, ///< C++ code for host library or executable.
SLANG_HOST_HOST_CALLABLE, ///< Host callable host code (ie non kernel/shader)
SLANG_CPP_PYTORCH_BINDING, ///< C++ PyTorch binding code.
SLANG_TARGET_COUNT_OF,
};
/* A "container format" describes the way that the outputs
for multiple files, entry points, targets, etc. should be
combined into a single artifact for output. */
typedef int SlangContainerFormatIntegral;
enum SlangContainerFormat : SlangContainerFormatIntegral
{
/* Don't generate a container. */
SLANG_CONTAINER_FORMAT_NONE,
/* Generate a container in the `.slang-module` format,
which includes reflection information, compiled kernels, etc. */
SLANG_CONTAINER_FORMAT_SLANG_MODULE,
};
typedef int SlangPassThroughIntegral;
enum SlangPassThrough : SlangPassThroughIntegral
{
SLANG_PASS_THROUGH_NONE,
SLANG_PASS_THROUGH_FXC,
SLANG_PASS_THROUGH_DXC,
SLANG_PASS_THROUGH_GLSLANG,
SLANG_PASS_THROUGH_SPIRV_DIS,
SLANG_PASS_THROUGH_CLANG, ///< Clang C/C++ compiler
SLANG_PASS_THROUGH_VISUAL_STUDIO, ///< Visual studio C/C++ compiler
SLANG_PASS_THROUGH_GCC, ///< GCC C/C++ compiler
SLANG_PASS_THROUGH_GENERIC_C_CPP, ///< Generic C or C++ compiler, which is decided by the source type
SLANG_PASS_THROUGH_NVRTC, ///< NVRTC Cuda compiler
SLANG_PASS_THROUGH_LLVM, ///< LLVM 'compiler' - includes LLVM and Clang
SLANG_PASS_THROUGH_SPIRV_OPT, ///< SPIRV-opt
SLANG_PASS_THROUGH_COUNT_OF,
};
/* Defines an archive type used to holds a 'file system' type structure. */
typedef int SlangArchiveTypeIntegral;
enum SlangArchiveType : SlangArchiveTypeIntegral
{
SLANG_ARCHIVE_TYPE_UNDEFINED,
SLANG_ARCHIVE_TYPE_ZIP,
SLANG_ARCHIVE_TYPE_RIFF, ///< Riff container with no compression
SLANG_ARCHIVE_TYPE_RIFF_DEFLATE,
SLANG_ARCHIVE_TYPE_RIFF_LZ4,
SLANG_ARCHIVE_TYPE_COUNT_OF,
};
/*!
Flags to control compilation behavior.
*/
typedef unsigned int SlangCompileFlags;
enum
{
/* Do as little mangling of names as possible, to try to preserve original names */
SLANG_COMPILE_FLAG_NO_MANGLING = 1 << 3,
/* Skip code generation step, just check the code and generate layout */
SLANG_COMPILE_FLAG_NO_CODEGEN = 1 << 4,
/* Obfuscate shader names on release products */
SLANG_COMPILE_FLAG_OBFUSCATE = 1 << 5,
/* Deprecated flags: kept around to allow existing applications to
compile. Note that the relevant features will still be left in
their default state. */
SLANG_COMPILE_FLAG_NO_CHECKING = 0,
SLANG_COMPILE_FLAG_SPLIT_MIXED_TYPES = 0,
};
/*!
@brief Flags to control code generation behavior of a compilation target */
typedef unsigned int SlangTargetFlags;
enum
{
/* When compiling for a D3D Shader Model 5.1 or higher target, allocate
distinct register spaces for parameter blocks.
@deprecated This behavior is now enabled unconditionally.
*/
SLANG_TARGET_FLAG_PARAMETER_BLOCKS_USE_REGISTER_SPACES = 1 << 4,
/* When set, will generate target code that contains all entrypoints defined
in the input source or specified via the `spAddEntryPoint` function in a
single output module (library/source file).
*/
SLANG_TARGET_FLAG_GENERATE_WHOLE_PROGRAM = 1 << 8,
/* When set, will dump out the IR between intermediate compilation steps.*/
SLANG_TARGET_FLAG_DUMP_IR = 1 << 9,
/* When set, will generate SPIRV directly rather than via glslang. */
SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY = 1 << 10,
};
#if defined(SLANG_CONFIG_DEFAULT_SPIRV_DIRECT)
constexpr static SlangTargetFlags kDefaultTargetFlags = SLANG_TARGET_FLAG_GENERATE_SPIRV_DIRECTLY;
#else
constexpr static SlangTargetFlags kDefaultTargetFlags = 0;
#endif
/*!
@brief Options to control floating-point precision guarantees for a target.
*/
typedef unsigned int SlangFloatingPointModeIntegral;
enum SlangFloatingPointMode : SlangFloatingPointModeIntegral
{
SLANG_FLOATING_POINT_MODE_DEFAULT = 0,
SLANG_FLOATING_POINT_MODE_FAST,
SLANG_FLOATING_POINT_MODE_PRECISE,
};
/*!
@brief Options to control emission of `#line` directives
*/
typedef unsigned int SlangLineDirectiveModeIntegral;
enum SlangLineDirectiveMode : SlangLineDirectiveModeIntegral
{
SLANG_LINE_DIRECTIVE_MODE_DEFAULT = 0, /**< Default behavior: pick behavior base on target. */
SLANG_LINE_DIRECTIVE_MODE_NONE, /**< Don't emit line directives at all. */
SLANG_LINE_DIRECTIVE_MODE_STANDARD, /**< Emit standard C-style `#line` directives. */
SLANG_LINE_DIRECTIVE_MODE_GLSL, /**< Emit GLSL-style directives with file *number* instead of name */
SLANG_LINE_DIRECTIVE_MODE_SOURCE_MAP, /**< Use a source map to track line mappings (ie no #line will appear in emitting source) */
};
typedef int SlangSourceLanguageIntegral;
enum SlangSourceLanguage : SlangSourceLanguageIntegral
{
SLANG_SOURCE_LANGUAGE_UNKNOWN,
SLANG_SOURCE_LANGUAGE_SLANG,
SLANG_SOURCE_LANGUAGE_HLSL,
SLANG_SOURCE_LANGUAGE_GLSL,
SLANG_SOURCE_LANGUAGE_C,
SLANG_SOURCE_LANGUAGE_CPP,
SLANG_SOURCE_LANGUAGE_CUDA,
SLANG_SOURCE_LANGUAGE_SPIRV,
SLANG_SOURCE_LANGUAGE_COUNT_OF,
};
typedef unsigned int SlangProfileIDIntegral;
enum SlangProfileID : SlangProfileIDIntegral
{
SLANG_PROFILE_UNKNOWN,
};
typedef SlangInt32 SlangCapabilityIDIntegral;
enum SlangCapabilityID : SlangCapabilityIDIntegral
{
SLANG_CAPABILITY_UNKNOWN = 0,
};
typedef unsigned int SlangMatrixLayoutModeIntegral;
enum SlangMatrixLayoutMode : SlangMatrixLayoutModeIntegral
{
SLANG_MATRIX_LAYOUT_MODE_UNKNOWN = 0,
SLANG_MATRIX_LAYOUT_ROW_MAJOR,
SLANG_MATRIX_LAYOUT_COLUMN_MAJOR,
};
typedef SlangUInt32 SlangStageIntegral;
enum SlangStage : SlangStageIntegral
{
SLANG_STAGE_NONE,
SLANG_STAGE_VERTEX,
SLANG_STAGE_HULL,
SLANG_STAGE_DOMAIN,
SLANG_STAGE_GEOMETRY,
SLANG_STAGE_FRAGMENT,
SLANG_STAGE_COMPUTE,
SLANG_STAGE_RAY_GENERATION,
SLANG_STAGE_INTERSECTION,
SLANG_STAGE_ANY_HIT,
SLANG_STAGE_CLOSEST_HIT,
SLANG_STAGE_MISS,
SLANG_STAGE_CALLABLE,
SLANG_STAGE_MESH,
SLANG_STAGE_AMPLIFICATION,
// alias:
SLANG_STAGE_PIXEL = SLANG_STAGE_FRAGMENT,
};
typedef SlangUInt32 SlangDebugInfoLevelIntegral;
enum SlangDebugInfoLevel : SlangDebugInfoLevelIntegral
{
SLANG_DEBUG_INFO_LEVEL_NONE = 0, /**< Don't emit debug information at all. */
SLANG_DEBUG_INFO_LEVEL_MINIMAL, /**< Emit as little debug information as possible, while still supporting stack trackes. */
SLANG_DEBUG_INFO_LEVEL_STANDARD, /**< Emit whatever is the standard level of debug information for each target. */
SLANG_DEBUG_INFO_LEVEL_MAXIMAL, /**< Emit as much debug infromation as possible for each target. */
};
/* Describes the debugging information format produced during a compilation. */
typedef SlangUInt32 SlangDebugInfoFormatIntegral;
enum SlangDebugInfoFormat : SlangDebugInfoFormatIntegral
{
SLANG_DEBUG_INFO_FORMAT_DEFAULT, ///< Use the default debugging format for the target
SLANG_DEBUG_INFO_FORMAT_C7, ///< CodeView C7 format (typically means debugging infomation is embedded in the binary)
SLANG_DEBUG_INFO_FORMAT_PDB, ///< Program database
SLANG_DEBUG_INFO_FORMAT_STABS, ///< Stabs
SLANG_DEBUG_INFO_FORMAT_COFF, ///< COFF debug info
SLANG_DEBUG_INFO_FORMAT_DWARF, ///< DWARF debug info (we may want to support specifying the version)
SLANG_DEBUG_INFO_FORMAT_COUNT_OF,
};
typedef SlangUInt32 SlangOptimizationLevelIntegral;
enum SlangOptimizationLevel : SlangOptimizationLevelIntegral
{
SLANG_OPTIMIZATION_LEVEL_NONE = 0, /**< Don't optimize at all. */
SLANG_OPTIMIZATION_LEVEL_DEFAULT, /**< Default optimization level: balance code quality and compilation time. */
SLANG_OPTIMIZATION_LEVEL_HIGH, /**< Optimize aggressively. */
SLANG_OPTIMIZATION_LEVEL_MAXIMAL, /**< Include optimizations that may take a very long time, or may involve severe space-vs-speed tradeoffs */
};
/** A result code for a Slang API operation.
This type is generally compatible with the Windows API `HRESULT` type. In particular, negative values indicate
failure results, while zero or positive results indicate success.
In general, Slang APIs always return a zero result on success, unless documented otherwise. Strictly speaking
a negative value indicates an error, a positive (or 0) value indicates success. This can be tested for with the macros
SLANG_SUCCEEDED(x) or SLANG_FAILED(x).
It can represent if the call was successful or not. It can also specify in an extensible manner what facility
produced the result (as the integral 'facility') as well as what caused it (as an integral 'code').
Under the covers SlangResult is represented as a int32_t.
SlangResult is designed to be compatible with COM HRESULT.
It's layout in bits is as follows
Severity | Facility | Code
---------|----------|-----
31 | 30-16 | 15-0
Severity - 1 fail, 0 is success - as SlangResult is signed 32 bits, means negative number indicates failure.
Facility is where the error originated from. Code is the code specific to the facility.
Result codes have the following styles,
1) SLANG_name
2) SLANG_s_f_name
3) SLANG_s_name
where s is S for success, E for error
f is the short version of the facility name
Style 1 is reserved for SLANG_OK and SLANG_FAIL as they are so commonly used.
It is acceptable to expand 'f' to a longer name to differentiate a name or drop if unique without it.
ie for a facility 'DRIVER' it might make sense to have an error of the form SLANG_E_DRIVER_OUT_OF_MEMORY
*/
typedef int32_t SlangResult;
//! Use to test if a result was failure. Never use result != SLANG_OK to test for failure, as there may be successful codes != SLANG_OK.
#define SLANG_FAILED(status) ((status) < 0)
//! Use to test if a result succeeded. Never use result == SLANG_OK to test for success, as will detect other successful codes as a failure.
#define SLANG_SUCCEEDED(status) ((status) >= 0)
//! Get the facility the result is associated with
#define SLANG_GET_RESULT_FACILITY(r) ((int32_t)(((r) >> 16) & 0x7fff))
//! Get the result code for the facility
#define SLANG_GET_RESULT_CODE(r) ((int32_t)((r) & 0xffff))
#define SLANG_MAKE_ERROR(fac, code) ((((int32_t)(fac)) << 16) | ((int32_t)(code)) | int32_t(0x80000000))
#define SLANG_MAKE_SUCCESS(fac, code) ((((int32_t)(fac)) << 16) | ((int32_t)(code)))
/*************************** Facilities ************************************/
//! Facilities compatible with windows COM - only use if known code is compatible
#define SLANG_FACILITY_WIN_GENERAL 0
#define SLANG_FACILITY_WIN_INTERFACE 4
#define SLANG_FACILITY_WIN_API 7
//! Base facility -> so as to not clash with HRESULT values (values in 0x200 range do not appear used)
#define SLANG_FACILITY_BASE 0x200
/*! Facilities numbers must be unique across a project to make the resulting result a unique number.
It can be useful to have a consistent short name for a facility, as used in the name prefix */
#define SLANG_FACILITY_CORE SLANG_FACILITY_BASE
/* Facility for codes, that are not uniquely defined/protected. Can be used to pass back a specific error without requiring system wide facility uniqueness. Codes
should never be part of a public API. */
#define SLANG_FACILITY_INTERNAL SLANG_FACILITY_BASE + 1
/// Base for external facilities. Facilities should be unique across modules.
#define SLANG_FACILITY_EXTERNAL_BASE 0x210
/* ************************ Win COM compatible Results ******************************/
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa378137(v=vs.85).aspx
//! SLANG_OK indicates success, and is equivalent to SLANG_MAKE_SUCCESS(SLANG_FACILITY_WIN_GENERAL, 0)
#define SLANG_OK 0
//! SLANG_FAIL is the generic failure code - meaning a serious error occurred and the call couldn't complete
#define SLANG_FAIL SLANG_MAKE_ERROR(SLANG_FACILITY_WIN_GENERAL, 0x4005)
#define SLANG_MAKE_WIN_GENERAL_ERROR(code) SLANG_MAKE_ERROR(SLANG_FACILITY_WIN_GENERAL, code)
//! Functionality is not implemented
#define SLANG_E_NOT_IMPLEMENTED SLANG_MAKE_WIN_GENERAL_ERROR(0x4001)
//! Interface not be found
#define SLANG_E_NO_INTERFACE SLANG_MAKE_WIN_GENERAL_ERROR(0x4002)
//! Operation was aborted (did not correctly complete)
#define SLANG_E_ABORT SLANG_MAKE_WIN_GENERAL_ERROR(0x4004)
//! Indicates that a handle passed in as parameter to a method is invalid.
#define SLANG_E_INVALID_HANDLE SLANG_MAKE_ERROR(SLANG_FACILITY_WIN_API, 6)
//! Indicates that an argument passed in as parameter to a method is invalid.
#define SLANG_E_INVALID_ARG SLANG_MAKE_ERROR(SLANG_FACILITY_WIN_API, 0x57)
//! Operation could not complete - ran out of memory
#define SLANG_E_OUT_OF_MEMORY SLANG_MAKE_ERROR(SLANG_FACILITY_WIN_API, 0xe)
/* *************************** other Results **************************************/
#define SLANG_MAKE_CORE_ERROR(code) SLANG_MAKE_ERROR(SLANG_FACILITY_CORE, code)
// Supplied buffer is too small to be able to complete
#define SLANG_E_BUFFER_TOO_SMALL SLANG_MAKE_CORE_ERROR(1)
//! Used to identify a Result that has yet to be initialized.
//! It defaults to failure such that if used incorrectly will fail, as similar in concept to using an uninitialized variable.
#define SLANG_E_UNINITIALIZED SLANG_MAKE_CORE_ERROR(2)
//! Returned from an async method meaning the output is invalid (thus an error), but a result for the request is pending, and will be returned on a subsequent call with the async handle.
#define SLANG_E_PENDING SLANG_MAKE_CORE_ERROR(3)
//! Indicates a file/resource could not be opened
#define SLANG_E_CANNOT_OPEN SLANG_MAKE_CORE_ERROR(4)
//! Indicates a file/resource could not be found
#define SLANG_E_NOT_FOUND SLANG_MAKE_CORE_ERROR(5)
//! An unhandled internal failure (typically from unhandled exception)
#define SLANG_E_INTERNAL_FAIL SLANG_MAKE_CORE_ERROR(6)
//! Could not complete because some underlying feature (hardware or software) was not available
#define SLANG_E_NOT_AVAILABLE SLANG_MAKE_CORE_ERROR(7)
//! Could not complete because the operation times out.
#define SLANG_E_TIME_OUT SLANG_MAKE_CORE_ERROR(8)
/** A "Universally Unique Identifier" (UUID)
The Slang API uses UUIDs to identify interfaces when
using `queryInterface`.
This type is compatible with the `GUID` type defined
by the Component Object Model (COM), but Slang is
not dependent on COM.
*/
struct SlangUUID
{
uint32_t data1;
uint16_t data2;
uint16_t data3;
uint8_t data4[8];
};
// Place at the start of an interface with the guid.
// Guid should be specified as SLANG_COM_INTERFACE(0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 })
// NOTE: it's the typical guid struct definition, without the surrounding {}
// It is not necessary to use the multiple parameters (we can wrap in parens), but this is simple.
#define SLANG_COM_INTERFACE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
public: \
SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \
{ \
return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \
}
// Sometimes it's useful to associate a guid with a class to identify it. This macro can used for this,
// and the guid extracted via the getTypeGuid() function defined in the type
#define SLANG_CLASS_GUID(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
SLANG_FORCE_INLINE constexpr static SlangUUID getTypeGuid() \
{ \
return { a, b, c, d0, d1, d2, d3, d4, d5, d6, d7 }; \
}
// Helper to fill in pairs of GUIDs and return pointers. This ensures that the
// type of the GUID passed matches the pointer type, and that it is derived
// from ISlangUnknown,
// TODO(c++20): would is_derived_from be more appropriate here for private inheritance of ISlangUnknown?
//
// with : void createFoo(SlangUUID, void**);
// Slang::ComPtr<Bar> myBar;
// call with: createFoo(SLANG_IID_PPV_ARGS(myBar.writeRef()))
// to call : createFoo(Bar::getTypeGuid(), (void**)(myBar.writeRef()))
#define SLANG_IID_PPV_ARGS(ppType) \
std::decay_t<decltype(**(ppType))>::getTypeGuid(), \
((void)[]{static_assert(std::is_base_of_v<ISlangUnknown, std::decay_t<decltype(**(ppType))>>);}, reinterpret_cast<void**>(ppType))
/** Base interface for components exchanged through the API.
This interface definition is compatible with the COM `IUnknown`,
and uses the same UUID, but Slang does not require applications
to use or initialize COM.