forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slang.h
1125 lines (915 loc) · 35.7 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
#if defined(SLANG_DYNAMIC_EXPORT)
#if !defined(SLANG_DYNAMIC)
#define SLANG_DYNAMIC
#endif
#endif
#if defined(SLANG_DYNAMIC)
#if defined(_MSC_VER)
#ifdef SLANG_DYNAMIC_EXPORT
#define SLANG_API __declspec(dllexport)
#else
#define SLANG_API __declspec(dllimport)
#endif
#else
// TODO: need to consider compiler capabilities
// #ifdef SLANG_DYNAMIC_EXPORT
#define SLANG_API __attribute__((__visibility__("default")))
// #endif
#endif
#endif
#ifndef SLANG_API
#define SLANG_API
#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 intptr_t SlangInt;
typedef uintptr_t SlangUInt;
/*!
@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 SlangSeverity;
enum
{
SLANG_SEVERITY_NOTE = 0, /**< 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 SlangBindableResourceType;
enum
{
SLANG_NON_BINDABLE = 0,
SLANG_TEXTURE,
SLANG_SAMPLER,
SLANG_UNIFORM_BUFFER,
SLANG_STORAGE_BUFFER,
};
typedef int SlangCompileTarget;
enum
{
SLANG_TARGET_UNKNOWN,
SLANG_TARGET_NONE,
SLANG_GLSL,
SLANG_GLSL_VULKAN,
SLANG_GLSL_VULKAN_ONE_DESC,
SLANG_HLSL,
SLANG_SPIRV,
SLANG_SPIRV_ASM,
SLANG_DXBC,
SLANG_DXBC_ASM,
SLANG_DXIL,
SLANG_DXIL_ASM,
};
/* 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 SlangContainerFormat;
enum
{
/* 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 SlangPassThrough;
enum
{
SLANG_PASS_THROUGH_NONE,
SLANG_PASS_THROUGH_FXC,
SLANG_PASS_THROUGH_DXC,
SLANG_PASS_THROUGH_GLSLANG,
};
/*!
Flags to control compilation behavior.
*/
typedef unsigned int SlangCompileFlags;
enum
{
/** Disable semantic checking as much as possible. */
SLANG_COMPILE_FLAG_NO_CHECKING = 1 << 0,
/* Split apart types that contain a mix of resource and non-resource data */
SLANG_COMPILE_FLAG_SPLIT_MIXED_TYPES = 1 << 1,
/* Use new IR-based code generation path (unstable pre-release feature)*/
SLANG_COMPILE_FLAG_USE_IR = 1 << 2,
/* Do as little mangling of names as possible, to try to preserve original names */
SLANG_COMPILE_FLAG_NO_MANGLING = 1 << 3,
};
/*!
@brief Options to control emission of `#line` directives
*/
typedef unsigned int SlangLineDirectiveMode;
enum
{
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 */
};
typedef int SlangSourceLanguage;
enum
{
SLANG_SOURCE_LANGUAGE_UNKNOWN,
SLANG_SOURCE_LANGUAGE_SLANG,
SLANG_SOURCE_LANGUAGE_HLSL,
SLANG_SOURCE_LANGUAGE_GLSL,
};
typedef unsigned int SlangProfileID;
enum
{
SLANG_PROFILE_UNKNOWN,
};
//#define SLANG_LAYOUT_UNIFORM 0
//#define SLANG_LAYOUT_PACKED 1
//#define SLANG_LAYOUT_STORAGE 2
#define SLANG_ERROR_INSUFFICIENT_BUFFER -1
#define SLANG_ERROR_INVALID_PARAMETER -2
/*!
@brief An instance of the Slang library.
*/
typedef struct SlangSession SlangSession;
/*!
@bref A request for one or more compilation actions to be performed.
*/
typedef struct SlangCompileRequest SlangCompileRequest;
/*!
@brief Initialize an instance of the Slang library.
@param cacheDir The directory used to store cached compilation results. Pass NULL to disable caching.
*/
SLANG_API SlangSession* spCreateSession(const char * cacheDir);
/*!
@brief Clean up after an instance of the Slang library.
*/
SLANG_API void spDestroySession(
SlangSession* session);
/*!
@brief Add new builtin declarations to be used in subsequent compiles.
*/
SLANG_API void spAddBuiltins(
SlangSession* session,
char const* sourcePath,
char const* sourceString);
/*!
@brief Create a compile request.
*/
SLANG_API SlangCompileRequest* spCreateCompileRequest(
SlangSession* session);
/*!
@brief Destroy a compile request.
*/
SLANG_API void spDestroyCompileRequest(
SlangCompileRequest* request);
/*!
@brief Set flags to be used for compilation.
*/
SLANG_API void spSetCompileFlags(
SlangCompileRequest* request,
SlangCompileFlags flags);
/*!
@brief Set whether to dump intermediate results (for debugging) or not.
*/
SLANG_API void spSetDumpIntermediates(
SlangCompileRequest* request,
int enable);
/*!
@brief Set whether (and how) `#line` directives hsould be output.
*/
SLANG_API void spSetLineDirectiveMode(
SlangCompileRequest* request,
SlangLineDirectiveMode mode);
/*!
@brief Sets the target for code generation.
@param ctx The compilation context.
@param target The code generation target. Possible values are:
- SLANG_GLSL. Generates GLSL code.
- SLANG_HLSL. Generates HLSL code.
- SLANG_SPIRV. Generates SPIR-V code.
*/
SLANG_API void spSetCodeGenTarget(
SlangCompileRequest* request,
int target);
/*!
@brief Add a code-generation target to be used.
*/
SLANG_API void spAddCodeGenTarget(
SlangCompileRequest* request,
SlangCompileTarget target);
/*!
@brief Set the container format to be used for binary output.
*/
SLANG_API void spSetOutputContainerFormat(
SlangCompileRequest* request,
SlangContainerFormat format);
SLANG_API void spSetPassThrough(
SlangCompileRequest* request,
SlangPassThrough passThrough);
typedef void(*SlangDiagnosticCallback)(
char const* message,
void* userData);
SLANG_API void spSetDiagnosticCallback(
SlangCompileRequest* request,
SlangDiagnosticCallback callback,
void const* userData);
/*!
@brief Add a path to use when searching for referenced files.
This will be used for both `#include` directives and also for explicit `__import` declarations.
@param ctx The compilation context.
@param searchDir The additional search directory.
*/
SLANG_API void spAddSearchPath(
SlangCompileRequest* request,
const char* searchDir);
/*!
@brief Add a macro definition to be used during preprocessing.
@param key The name of the macro to define.
@param value The value of the macro to define.
*/
SLANG_API void spAddPreprocessorDefine(
SlangCompileRequest* request,
const char* key,
const char* value);
/*!
@brief Set options using arguments as if specified via command line.
*/
SLANG_API int spProcessCommandLineArguments(
SlangCompileRequest* request,
char const* const* args,
int argCount);
/** Add a distinct translation unit to the compilation request
`name` is optional.
Returns the zero-based index of the translation unit created.
*/
SLANG_API int spAddTranslationUnit(
SlangCompileRequest* request,
SlangSourceLanguage language,
char const* name);
/** Add a preprocessor definition that is scoped to a single translation unit.
@param translationUnitIndex The index of the translation unit to get the definition.
@param key The name of the macro to define.
@param value The value of the macro to define.
*/
SLANG_API void spTranslationUnit_addPreprocessorDefine(
SlangCompileRequest* request,
int translationUnitIndex,
const char* key,
const char* value);
/** Add a source file to the given translation unit
*/
SLANG_API void spAddTranslationUnitSourceFile(
SlangCompileRequest* request,
int translationUnitIndex,
char const* path);
/** Add a source string to the given translation unit
The `path` will be used in any diagnostic output.
*/
SLANG_API void spAddTranslationUnitSourceString(
SlangCompileRequest* request,
int translationUnitIndex,
char const* path,
char const* source);
/** Look up a compilation profile by name.
For example, one could look up the string `"ps_5_0"` to find the corresponding target ID.
*/
SLANG_API SlangProfileID spFindProfile(
SlangSession* session,
char const* name);
/** Add an entry point in a particular translation unit
*/
SLANG_API int spAddEntryPoint(
SlangCompileRequest* request,
int translationUnitIndex,
char const* name,
SlangProfileID profile);
/** Execute the compilation request.
Returns zero on success, non-zero on failure.
*/
SLANG_API int spCompile(
SlangCompileRequest* request);
/** Get any diagnostic messages reported by the compiler.
*/
SLANG_API char const* spGetDiagnosticOutput(
SlangCompileRequest* request);
/** Get the number of files that this compilation depended on.
This includes both the explicit source files, as well as any
additional files that were transitively referenced (e.g., via
a `#include` directive).
*/
SLANG_API int
spGetDependencyFileCount(
SlangCompileRequest* request);
/** Get the path to a file this compilation dependend on.
*/
SLANG_API char const*
spGetDependencyFilePath(
SlangCompileRequest* request,
int index);
/** Get the number of tranlsation units associated with the compilation request
*/
SLANG_API int
spGetTranslationUnitCount(
SlangCompileRequest* request);
/** Get the output code associated with a specific translation unit.
The lifetime of the output pointer is the same as `request`.
*/
SLANG_API char const* spGetTranslationUnitSource(
SlangCompileRequest* request,
int translationUnitIndex);
/** Get the output source code associated with a specific entry point.
The lifetime of the output pointer is the same as `request`.
*/
SLANG_API char const* spGetEntryPointSource(
SlangCompileRequest* request,
int entryPointIndex);
/** Get the output bytecode associated with a specific entry point.
The lifetime of the output pointer is the same as `request`.
*/
SLANG_API void const* spGetEntryPointCode(
SlangCompileRequest* request,
int entryPointIndex,
size_t* outSize);
/** Get the output bytecode associated with an entire compile request.
The lifetime of the output pointer is the same as `request`.
*/
SLANG_API void const* spGetCompileRequestCode(
SlangCompileRequest* request,
size_t* outSize);
typedef struct SlangVM SlangVM;
typedef struct SlangVMModule SlangVMModule;
typedef struct SlangVMFunc SlangVMFunc;
typedef struct SlangVMThread SlangVMThread;
SLANG_API SlangVM* SlangVM_create();
SLANG_API SlangVMModule* SlangVMModule_load(
SlangVM* vm,
void const* bytecode,
size_t bytecodeSize);
SLANG_API void* SlangVMModule_findGlobalSymbolPtr(
SlangVMModule* module,
char const* name);
SLANG_API SlangVMThread* SlangVMThread_create(
SlangVM* vm);
SLANG_API void SlangVMThread_beginCall(
SlangVMThread* thread,
SlangVMFunc* func);
SLANG_API void SlangVMThread_setArg(
SlangVMThread* thread,
SlangUInt argIndex,
void const* data,
size_t size);
SLANG_API void SlangVMThread_resume(
SlangVMThread* thread);
/* Note(tfoley): working on new reflection interface...
*/
typedef struct SlangReflection SlangReflection;
typedef struct SlangReflectionEntryPoint SlangReflectionEntryPoint;
typedef struct SlangReflectionType SlangReflectionType;
typedef struct SlangReflectionTypeLayout SlangReflectionTypeLayout;
typedef struct SlangReflectionVariable SlangReflectionVariable;
typedef struct SlangReflectionVariableLayout SlangReflectionVariableLayout;
// get reflection data from a compilation request
SLANG_API SlangReflection* spGetReflection(
SlangCompileRequest* request);
// type reflection
typedef unsigned int SlangTypeKind;
enum
{
SLANG_TYPE_KIND_NONE,
SLANG_TYPE_KIND_STRUCT,
SLANG_TYPE_KIND_ARRAY,
SLANG_TYPE_KIND_MATRIX,
SLANG_TYPE_KIND_VECTOR,
SLANG_TYPE_KIND_SCALAR,
SLANG_TYPE_KIND_CONSTANT_BUFFER,
SLANG_TYPE_KIND_RESOURCE,
SLANG_TYPE_KIND_SAMPLER_STATE,
SLANG_TYPE_KIND_TEXTURE_BUFFER,
SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER,
SLANG_TYPE_KIND_COUNT,
};
typedef unsigned int SlangScalarType;
enum
{
SLANG_SCALAR_TYPE_NONE,
SLANG_SCALAR_TYPE_VOID,
SLANG_SCALAR_TYPE_BOOL,
SLANG_SCALAR_TYPE_INT32,
SLANG_SCALAR_TYPE_UINT32,
SLANG_SCALAR_TYPE_INT64,
SLANG_SCALAR_TYPE_UINT64,
SLANG_SCALAR_TYPE_FLOAT16,
SLANG_SCALAR_TYPE_FLOAT32,
SLANG_SCALAR_TYPE_FLOAT64,
};
typedef unsigned int SlangResourceShape;
enum
{
SLANG_RESOURCE_BASE_SHAPE_MASK = 0x0F,
SLANG_RESOURCE_NONE = 0x00,
SLANG_TEXTURE_1D = 0x01,
SLANG_TEXTURE_2D = 0x02,
SLANG_TEXTURE_3D = 0x03,
SLANG_TEXTURE_CUBE = 0x04,
SLANG_TEXTURE_BUFFER = 0x05,
SLANG_STRUCTURED_BUFFER = 0x06,
SLANG_BYTE_ADDRESS_BUFFER = 0x07,
SLANG_RESOURCE_UNKNOWN = 0x08,
SLANG_RESOURCE_EXT_SHAPE_MASK = 0xF0,
SLANG_TEXTURE_ARRAY_FLAG = 0x40,
SLANG_TEXTURE_MULTISAMPLE_FLAG = 0x80,
SLANG_TEXTURE_1D_ARRAY = SLANG_TEXTURE_1D | SLANG_TEXTURE_ARRAY_FLAG,
SLANG_TEXTURE_2D_ARRAY = SLANG_TEXTURE_2D | SLANG_TEXTURE_ARRAY_FLAG,
SLANG_TEXTURE_CUBE_ARRAY = SLANG_TEXTURE_CUBE | SLANG_TEXTURE_ARRAY_FLAG,
SLANG_TEXTURE_2D_MULTISAMPLE = SLANG_TEXTURE_2D | SLANG_TEXTURE_MULTISAMPLE_FLAG,
SLANG_TEXTURE_2D_MULTISAMPLE_ARRAY = SLANG_TEXTURE_2D | SLANG_TEXTURE_MULTISAMPLE_FLAG | SLANG_TEXTURE_ARRAY_FLAG,
};
typedef unsigned int SlangResourceAccess;
enum
{
SLANG_RESOURCE_ACCESS_NONE,
SLANG_RESOURCE_ACCESS_READ,
SLANG_RESOURCE_ACCESS_READ_WRITE,
SLANG_RESOURCE_ACCESS_RASTER_ORDERED,
SLANG_RESOURCE_ACCESS_APPEND,
SLANG_RESOURCE_ACCESS_CONSUME,
};
typedef unsigned int SlangParameterCategory;
enum
{
SLANG_PARAMETER_CATEGORY_NONE,
SLANG_PARAMETER_CATEGORY_MIXED,
SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER,
SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE,
SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS,
SLANG_PARAMETER_CATEGORY_VERTEX_INPUT,
SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT,
SLANG_PARAMETER_CATEGORY_SAMPLER_STATE,
SLANG_PARAMETER_CATEGORY_UNIFORM,
SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT,
SLANG_PARAMETER_CATEGORY_SPECIALIZATION_CONSTANT,
SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER,
SLANG_PAREMTER_CATEGORY_PARAMETER_BLOCK,
//
SLANG_PARAMETER_CATEGORY_COUNT,
};
typedef SlangUInt32 SlangStage;
enum
{
SLANG_STAGE_NONE,
SLANG_STAGE_VERTEX,
SLANG_STAGE_HULL,
SLANG_STAGE_DOMAIN,
SLANG_STAGE_GEOMETRY,
SLANG_STAGE_FRAGMENT,
SLANG_STAGE_COMPUTE,
SLANG_STAGE_PIXEL = SLANG_STAGE_FRAGMENT,
};
// Type Reflection
SLANG_API SlangTypeKind spReflectionType_GetKind(SlangReflectionType* type);
SLANG_API unsigned int spReflectionType_GetFieldCount(SlangReflectionType* type);
SLANG_API SlangReflectionVariable* spReflectionType_GetFieldByIndex(SlangReflectionType* type, unsigned index);
SLANG_API size_t spReflectionType_GetElementCount(SlangReflectionType* type);
SLANG_API SlangReflectionType* spReflectionType_GetElementType(SlangReflectionType* type);
SLANG_API unsigned int spReflectionType_GetRowCount(SlangReflectionType* type);
SLANG_API unsigned int spReflectionType_GetColumnCount(SlangReflectionType* type);
SLANG_API SlangScalarType spReflectionType_GetScalarType(SlangReflectionType* type);
SLANG_API SlangResourceShape spReflectionType_GetResourceShape(SlangReflectionType* type);
SLANG_API SlangResourceAccess spReflectionType_GetResourceAccess(SlangReflectionType* type);
SLANG_API SlangReflectionType* spReflectionType_GetResourceResultType(SlangReflectionType* type);
SLANG_API char const* spReflectionType_GetName(SlangReflectionType* type);
// Type Layout Reflection
SLANG_API SlangReflectionType* spReflectionTypeLayout_GetType(SlangReflectionTypeLayout* type);
SLANG_API size_t spReflectionTypeLayout_GetSize(SlangReflectionTypeLayout* type, SlangParameterCategory category);
SLANG_API SlangReflectionVariableLayout* spReflectionTypeLayout_GetFieldByIndex(SlangReflectionTypeLayout* type, unsigned index);
SLANG_API size_t spReflectionTypeLayout_GetElementStride(SlangReflectionTypeLayout* type, SlangParameterCategory category);
SLANG_API SlangReflectionTypeLayout* spReflectionTypeLayout_GetElementTypeLayout(SlangReflectionTypeLayout* type);
SLANG_API SlangParameterCategory spReflectionTypeLayout_GetParameterCategory(SlangReflectionTypeLayout* type);
SLANG_API unsigned spReflectionTypeLayout_GetCategoryCount(SlangReflectionTypeLayout* type);
SLANG_API SlangParameterCategory spReflectionTypeLayout_GetCategoryByIndex(SlangReflectionTypeLayout* type, unsigned index);
// Variable Reflection
SLANG_API char const* spReflectionVariable_GetName(SlangReflectionVariable* var);
SLANG_API SlangReflectionType* spReflectionVariable_GetType(SlangReflectionVariable* var);
// Variable Layout Reflection
SLANG_API SlangReflectionVariable* spReflectionVariableLayout_GetVariable(SlangReflectionVariableLayout* var);
SLANG_API SlangReflectionTypeLayout* spReflectionVariableLayout_GetTypeLayout(SlangReflectionVariableLayout* var);
SLANG_API size_t spReflectionVariableLayout_GetOffset(SlangReflectionVariableLayout* var, SlangParameterCategory category);
SLANG_API size_t spReflectionVariableLayout_GetSpace(SlangReflectionVariableLayout* var, SlangParameterCategory category);
SLANG_API char const* spReflectionVariableLayout_GetSemanticName(SlangReflectionVariableLayout* var);
SLANG_API size_t spReflectionVariableLayout_GetSemanticIndex(SlangReflectionVariableLayout* var);
// Shader Parameter Reflection
typedef SlangReflectionVariableLayout SlangReflectionParameter;
SLANG_API unsigned spReflectionParameter_GetBindingIndex(SlangReflectionParameter* parameter);
SLANG_API unsigned spReflectionParameter_GetBindingSpace(SlangReflectionParameter* parameter);
// Entry Point Reflection
SLANG_API char const* spReflectionEntryPoint_getName(
SlangReflectionEntryPoint* entryPoint);
SLANG_API unsigned spReflectionEntryPoint_getParameterCount(
SlangReflectionEntryPoint* entryPoint);
SLANG_API SlangReflectionVariableLayout* spReflectionEntryPoint_getParameterByIndex(
SlangReflectionEntryPoint* entryPoint,
unsigned index);
SLANG_API SlangStage spReflectionEntryPoint_getStage(SlangReflectionEntryPoint* entryPoint);
SLANG_API void spReflectionEntryPoint_getComputeThreadGroupSize(
SlangReflectionEntryPoint* entryPoint,
SlangUInt axisCount,
SlangUInt* outSizeAlongAxis);
SLANG_API int spReflectionEntryPoint_usesAnySampleRateInput(
SlangReflectionEntryPoint* entryPoint);
// Shader Reflection
SLANG_API unsigned spReflection_GetParameterCount(SlangReflection* reflection);
SLANG_API SlangReflectionParameter* spReflection_GetParameterByIndex(SlangReflection* reflection, unsigned index);
SLANG_API SlangUInt spReflection_getEntryPointCount(SlangReflection* reflection);
SLANG_API SlangReflectionEntryPoint* spReflection_getEntryPointByIndex(SlangReflection* reflection, SlangUInt index);
#ifdef __cplusplus
}
/* Helper interfaces for C++ users */
namespace slang
{
#define SLANG_SAFE_BOOL(expr) \
operator bool() const { return expr; }
struct BufferReflection;
struct TypeLayoutReflection;
struct TypeReflection;
struct VariableLayoutReflection;
struct VariableReflection;
struct TypeReflection
{
enum class Kind
{
None = SLANG_TYPE_KIND_NONE,
Struct = SLANG_TYPE_KIND_STRUCT,
Array = SLANG_TYPE_KIND_ARRAY,
Matrix = SLANG_TYPE_KIND_MATRIX,
Vector = SLANG_TYPE_KIND_VECTOR,
Scalar = SLANG_TYPE_KIND_SCALAR,
ConstantBuffer = SLANG_TYPE_KIND_CONSTANT_BUFFER,
Resource = SLANG_TYPE_KIND_RESOURCE,
SamplerState = SLANG_TYPE_KIND_SAMPLER_STATE,
TextureBuffer = SLANG_TYPE_KIND_TEXTURE_BUFFER,
ShaderStorageBuffer = SLANG_TYPE_KIND_SHADER_STORAGE_BUFFER,
};
enum ScalarType : SlangScalarType
{
None = SLANG_SCALAR_TYPE_NONE,
Void = SLANG_SCALAR_TYPE_VOID,
Bool = SLANG_SCALAR_TYPE_BOOL,
Int32 = SLANG_SCALAR_TYPE_INT32,
UInt32 = SLANG_SCALAR_TYPE_UINT32,
Int64 = SLANG_SCALAR_TYPE_INT64,
UInt64 = SLANG_SCALAR_TYPE_UINT64,
Float16 = SLANG_SCALAR_TYPE_FLOAT16,
Float32 = SLANG_SCALAR_TYPE_FLOAT32,
Float64 = SLANG_SCALAR_TYPE_FLOAT64,
};
Kind getKind()
{
return (Kind) spReflectionType_GetKind((SlangReflectionType*) this);
}
// only useful if `getKind() == Kind::Struct`
unsigned int getFieldCount()
{
return spReflectionType_GetFieldCount((SlangReflectionType*) this);
}
VariableReflection* getFieldByIndex(unsigned int index)
{
return (VariableReflection*) spReflectionType_GetFieldByIndex((SlangReflectionType*) this, index);
}
bool isArray() { return getKind() == TypeReflection::Kind::Array; }
TypeReflection* unwrapArray()
{
TypeReflection* type = this;
while( type->isArray() )
{
type = type->getElementType();
}
return type;
}
// only useful if `getKind() == Kind::Array`
size_t getElementCount()
{
return spReflectionType_GetElementCount((SlangReflectionType*) this);
}
size_t getTotalArrayElementCount()
{
if(!isArray()) return 0;
size_t result = 1;
TypeReflection* type = this;
for(;;)
{
if(!type->isArray())
return result;
result *= type->getElementCount();
type = type->getElementType();
}
}
TypeReflection* getElementType()
{
return (TypeReflection*) spReflectionType_GetElementType((SlangReflectionType*) this);
}
unsigned getRowCount()
{
return spReflectionType_GetRowCount((SlangReflectionType*) this);
}
unsigned getColumnCount()
{
return spReflectionType_GetColumnCount((SlangReflectionType*) this);
}
ScalarType getScalarType()
{
return (ScalarType) spReflectionType_GetScalarType((SlangReflectionType*) this);
}
TypeReflection* getResourceResultType()
{
return (TypeReflection*) spReflectionType_GetResourceResultType((SlangReflectionType*) this);
}
SlangResourceShape getResourceShape()
{
return spReflectionType_GetResourceShape((SlangReflectionType*) this);
}
SlangResourceAccess getResourceAccess()
{
return spReflectionType_GetResourceAccess((SlangReflectionType*) this);
}
char const* getName()
{
return spReflectionType_GetName((SlangReflectionType*) this);
}
};
enum ParameterCategory : SlangParameterCategory
{
// TODO: these aren't scoped...
None = SLANG_PARAMETER_CATEGORY_NONE,
Mixed = SLANG_PARAMETER_CATEGORY_MIXED,
ConstantBuffer = SLANG_PARAMETER_CATEGORY_CONSTANT_BUFFER,
ShaderResource = SLANG_PARAMETER_CATEGORY_SHADER_RESOURCE,
UnorderedAccess = SLANG_PARAMETER_CATEGORY_UNORDERED_ACCESS,
VertexInput = SLANG_PARAMETER_CATEGORY_VERTEX_INPUT,
FragmentOutput = SLANG_PARAMETER_CATEGORY_FRAGMENT_OUTPUT,
SamplerState = SLANG_PARAMETER_CATEGORY_SAMPLER_STATE,
Uniform = SLANG_PARAMETER_CATEGORY_UNIFORM,
DescriptorTableSlot = SLANG_PARAMETER_CATEGORY_DESCRIPTOR_TABLE_SLOT,
SpecializationConstant = SLANG_PARAMETER_CATEGORY_SPECIALIZATION_CONSTANT,
PushConstantBuffer = SLANG_PARAMETER_CATEGORY_PUSH_CONSTANT_BUFFER,
ParameterBlock = SLANG_PAREMTER_CATEGORY_PARAMETER_BLOCK,
};
struct TypeLayoutReflection
{
TypeReflection* getType()
{
return (TypeReflection*) spReflectionTypeLayout_GetType((SlangReflectionTypeLayout*) this);
}
TypeReflection::Kind getKind() { return getType()->getKind(); }
size_t getSize(SlangParameterCategory category = SLANG_PARAMETER_CATEGORY_UNIFORM)
{
return spReflectionTypeLayout_GetSize((SlangReflectionTypeLayout*) this, category);
}
unsigned int getFieldCount()
{
return getType()->getFieldCount();
}
VariableLayoutReflection* getFieldByIndex(unsigned int index)
{
return (VariableLayoutReflection*) spReflectionTypeLayout_GetFieldByIndex((SlangReflectionTypeLayout*) this, index);
}
bool isArray() { return getType()->isArray(); }
TypeLayoutReflection* unwrapArray()
{
TypeLayoutReflection* typeLayout = this;
while( typeLayout->isArray() )
{
typeLayout = typeLayout->getElementTypeLayout();
}
return typeLayout;
}
// only useful if `getKind() == Kind::Array`
size_t getElementCount()
{
return getType()->getElementCount();
}
size_t getTotalArrayElementCount()
{
return getType()->getTotalArrayElementCount();
}
size_t getElementStride(SlangParameterCategory category)
{
return spReflectionTypeLayout_GetElementStride((SlangReflectionTypeLayout*) this, category);
}
TypeLayoutReflection* getElementTypeLayout()
{
return (TypeLayoutReflection*) spReflectionTypeLayout_GetElementTypeLayout((SlangReflectionTypeLayout*) this);
}
// How is this type supposed to be bound?
ParameterCategory getParameterCategory()
{
return (ParameterCategory) spReflectionTypeLayout_GetParameterCategory((SlangReflectionTypeLayout*) this);
}
unsigned int getCategoryCount()
{
return spReflectionTypeLayout_GetCategoryCount((SlangReflectionTypeLayout*) this);
}
ParameterCategory getCategoryByIndex(unsigned int index)
{
return (ParameterCategory) spReflectionTypeLayout_GetCategoryByIndex((SlangReflectionTypeLayout*) this, index);
}
unsigned getRowCount()
{
return getType()->getRowCount();
}
unsigned getColumnCount()
{
return getType()->getColumnCount();
}
TypeReflection::ScalarType getScalarType()
{
return getType()->getScalarType();
}
TypeReflection* getResourceResultType()
{
return getType()->getResourceResultType();
}
SlangResourceShape getResourceShape()
{
return getType()->getResourceShape();
}
SlangResourceAccess getResourceAccess()
{
return getType()->getResourceAccess();
}
char const* getName()
{
return getType()->getName();
}
};
struct VariableReflection
{
char const* getName()
{
return spReflectionVariable_GetName((SlangReflectionVariable*) this);
}
TypeReflection* getType()
{
return (TypeReflection*) spReflectionVariable_GetType((SlangReflectionVariable*) this);
}
};
struct VariableLayoutReflection
{
VariableReflection* getVariable()
{
return (VariableReflection*) spReflectionVariableLayout_GetVariable((SlangReflectionVariableLayout*) this);
}
char const* getName()
{
return getVariable()->getName();
}
TypeLayoutReflection* getTypeLayout()
{
return (TypeLayoutReflection*) spReflectionVariableLayout_GetTypeLayout((SlangReflectionVariableLayout*) this);
}
ParameterCategory getCategory()
{
return getTypeLayout()->getParameterCategory();
}
unsigned int getCategoryCount()
{
return getTypeLayout()->getCategoryCount();
}
ParameterCategory getCategoryByIndex(unsigned int index)
{
return getTypeLayout()->getCategoryByIndex(index);
}
size_t getOffset(SlangParameterCategory category = SLANG_PARAMETER_CATEGORY_UNIFORM)
{
return spReflectionVariableLayout_GetOffset((SlangReflectionVariableLayout*) this, category);
}
TypeReflection* getType()
{
return getVariable()->getType();
}
unsigned getBindingIndex()
{
return spReflectionParameter_GetBindingIndex((SlangReflectionVariableLayout*) this);
}