forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slang-gfx.h
2686 lines (2346 loc) · 86.6 KB
/
slang-gfx.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
// render.h
#pragma once
#include <float.h>
#include <assert.h>
#include "slang.h"
#include "slang-com-ptr.h"
#if defined(SLANG_GFX_DYNAMIC)
# if defined(_MSC_VER)
# ifdef SLANG_GFX_DYNAMIC_EXPORT
# define SLANG_GFX_API SLANG_DLL_EXPORT
# else
# define SLANG_GFX_API __declspec(dllimport)
# endif
# else
// TODO: need to consider compiler capabilities
//# ifdef SLANG_DYNAMIC_EXPORT
# define SLANG_GFX_API SLANG_DLL_EXPORT
//# endif
# endif
#endif
#ifndef SLANG_GFX_API
# define SLANG_GFX_API
#endif
// Needed for building on cygwin with gcc
#undef Always
#undef None
// GLOBAL TODO: doc comments
// GLOBAL TODO: Rationalize integer types (not a smush of uint/int/Uint/Int/etc)
// - need typedefs in gfx namespace for Count, Index, Size, Offset (ex. DeviceAddress)
// - Index and Count are for arrays, and indexing into array - like things(XY coordinates of pixels, etc.)
// - Count is also for anything where we need to measure how many of something there are. This includes things like extents.
// - Offset and Size are almost always for bytes and things measured in bytes.
namespace gfx {
using Slang::ComPtr;
typedef SlangResult Result;
// Had to move here, because Options needs types defined here
typedef SlangInt Int;
typedef SlangUInt UInt;
typedef uint64_t DeviceAddress;
typedef int GfxIndex;
typedef int GfxCount;
typedef size_t Size;
typedef size_t Offset;
const uint64_t kTimeoutInfinite = 0xFFFFFFFFFFFFFFFF;
enum class StructType
{
D3D12DeviceExtendedDesc, D3D12ExperimentalFeaturesDesc
};
// TODO: Rename to Stage
enum class StageType
{
Unknown,
Vertex,
Hull,
Domain,
Geometry,
Fragment,
Compute,
RayGeneration,
Intersection,
AnyHit,
ClosestHit,
Miss,
Callable,
Amplification,
Mesh,
CountOf,
};
// TODO: Implementation or backend or something else?
enum class DeviceType
{
Unknown,
Default,
DirectX11,
DirectX12,
OpenGl,
Vulkan,
CPU,
CUDA,
CountOf,
};
// TODO: Why does this exist it should go poof
enum class ProjectionStyle
{
Unknown,
OpenGl,
DirectX,
Vulkan,
CountOf,
};
// TODO: This should also go poof
/// The style of the binding
enum class BindingStyle
{
Unknown,
DirectX,
OpenGl,
Vulkan,
CPU,
CUDA,
CountOf,
};
// TODO: Is this actually a flag when there are no bit fields?
enum class AccessFlag
{
None,
Read,
Write,
};
// TODO: Needed? Shouldn't be hard-coded if so
const GfxCount kMaxRenderTargetCount = 8;
class ITransientResourceHeap;
enum class ShaderModuleSourceType
{
SlangSource, // a slang source string in memory.
SlangModuleBinary, // a slang module binary code in memory.
SlangSourceFile, // a slang source from file.
SlangModuleBinaryFile, // a slang module binary code from file.
};
class IShaderProgram: public ISlangUnknown
{
public:
// Defines how linking should be performed for a shader program.
enum class LinkingStyle
{
// Compose all entry-points in a single program, then compile all entry-points together with the same
// set of root shader arguments.
SingleProgram,
// Link and compile each entry-point individually, potentially with different specializations.
SeparateEntryPointCompilation
};
struct Desc
{
// TODO: Tess doesn't like this but doesn't know what to do about it
// The linking style of this program.
LinkingStyle linkingStyle = LinkingStyle::SingleProgram;
// The global scope or a Slang composite component that represents the entire program.
slang::IComponentType* slangGlobalScope;
// Number of separate entry point components in the `slangEntryPoints` array to link in.
// If set to 0, then `slangGlobalScope` must contain Slang EntryPoint components.
// If not 0, then `slangGlobalScope` must not contain any EntryPoint components.
GfxCount entryPointCount = 0;
// An array of Slang entry points. The size of the array must be `entryPointCount`.
// Each element must define only 1 Slang EntryPoint.
slang::IComponentType** slangEntryPoints = nullptr;
};
struct CreateDesc2
{
ShaderModuleSourceType sourceType;
void* sourceData;
Size sourceDataSize;
// Number of entry points to include in the shader program. 0 means include all entry points
// defined in the module.
GfxCount entryPointCount = 0;
// Names of entry points to include in the shader program. The size of the array must be
// `entryPointCount`.
const char** entryPointNames = nullptr;
};
virtual SLANG_NO_THROW slang::TypeReflection* SLANG_MCALL findTypeByName(const char* name) = 0;
};
#define SLANG_UUID_IShaderProgram \
{ \
0x9d32d0ad, 0x915c, 0x4ffd, { 0x91, 0xe2, 0x50, 0x85, 0x54, 0xa0, 0x4a, 0x76 } \
}
// TODO: Confirm with Yong that we really want this naming convention
// TODO: Rename to what?
// Dont' change without keeping in sync with Format
#define GFX_FORMAT(x) \
x( Unknown, 0, 0) \
\
x(R32G32B32A32_TYPELESS, 16, 1) \
x(R32G32B32_TYPELESS, 12, 1) \
x(R32G32_TYPELESS, 8, 1) \
x(R32_TYPELESS, 4, 1) \
\
x(R16G16B16A16_TYPELESS, 8, 1) \
x(R16G16_TYPELESS, 4, 1) \
x(R16_TYPELESS, 2, 1) \
\
x(R8G8B8A8_TYPELESS, 4, 1) \
x(R8G8_TYPELESS, 2, 1) \
x(R8_TYPELESS, 1, 1) \
x(B8G8R8A8_TYPELESS, 4, 1) \
\
x(R32G32B32A32_FLOAT, 16, 1) \
x(R32G32B32_FLOAT, 12, 1) \
x(R32G32_FLOAT, 8, 1) \
x(R32_FLOAT, 4, 1) \
\
x(R16G16B16A16_FLOAT, 8, 1) \
x(R16G16_FLOAT, 4, 1) \
x(R16_FLOAT, 2, 1) \
\
x(R32G32B32A32_UINT, 16, 1) \
x(R32G32B32_UINT, 12, 1) \
x(R32G32_UINT, 8, 1) \
x(R32_UINT, 4, 1) \
\
x(R16G16B16A16_UINT, 8, 1) \
x(R16G16_UINT, 4, 1) \
x(R16_UINT, 2, 1) \
\
x(R8G8B8A8_UINT, 4, 1) \
x(R8G8_UINT, 2, 1) \
x(R8_UINT, 1, 1) \
\
x(R32G32B32A32_SINT, 16, 1) \
x(R32G32B32_SINT, 12, 1) \
x(R32G32_SINT, 8, 1) \
x(R32_SINT, 4, 1) \
\
x(R16G16B16A16_SINT, 8, 1) \
x(R16G16_SINT, 4, 1) \
x(R16_SINT, 2, 1) \
\
x(R8G8B8A8_SINT, 4, 1) \
x(R8G8_SINT, 2, 1) \
x(R8_SINT, 1, 1) \
\
x(R16G16B16A16_UNORM, 8, 1) \
x(R16G16_UNORM, 4, 1) \
x(R16_UNORM, 2, 1) \
\
x(R8G8B8A8_UNORM, 4, 1) \
x(R8G8B8A8_UNORM_SRGB, 4, 1) \
x(R8G8_UNORM, 2, 1) \
x(R8_UNORM, 1, 1) \
x(B8G8R8A8_UNORM, 4, 1) \
x(B8G8R8A8_UNORM_SRGB, 4, 1) \
x(B8G8R8X8_UNORM, 4, 1) \
x(B8G8R8X8_UNORM_SRGB, 4, 1) \
\
x(R16G16B16A16_SNORM, 8, 1) \
x(R16G16_SNORM, 4, 1) \
x(R16_SNORM, 2, 1) \
\
x(R8G8B8A8_SNORM, 4, 1) \
x(R8G8_SNORM, 2, 1) \
x(R8_SNORM, 1, 1) \
\
x(D32_FLOAT, 4, 1) \
x(D16_UNORM, 2, 1) \
\
x(B4G4R4A4_UNORM, 2, 1) \
x(B5G6R5_UNORM, 2, 1) \
x(B5G5R5A1_UNORM, 2, 1) \
\
x(R9G9B9E5_SHAREDEXP, 4, 1) \
x(R10G10B10A2_TYPELESS, 4, 1) \
x(R10G10B10A2_UNORM, 4, 1) \
x(R10G10B10A2_UINT, 4, 1) \
x(R11G11B10_FLOAT, 4, 1) \
\
x(BC1_UNORM, 8, 16) \
x(BC1_UNORM_SRGB, 8, 16) \
x(BC2_UNORM, 16, 16) \
x(BC2_UNORM_SRGB, 16, 16) \
x(BC3_UNORM, 16, 16) \
x(BC3_UNORM_SRGB, 16, 16) \
x(BC4_UNORM, 8, 16) \
x(BC4_SNORM, 8, 16) \
x(BC5_UNORM, 16, 16) \
x(BC5_SNORM, 16, 16) \
x(BC6H_UF16, 16, 16) \
x(BC6H_SF16, 16, 16) \
x(BC7_UNORM, 16, 16) \
x(BC7_UNORM_SRGB, 16, 16)
// TODO: This should be generated from above
// TODO: enum class should be explicitly uint32_t or whatever's appropriate
/// Different formats of things like pixels or elements of vertices
/// NOTE! Any change to this type (adding, removing, changing order) - must also be reflected in changes GFX_FORMAT
enum class Format
{
// D3D formats omitted: 19-22, 44-47, 65-66, 68-70, 73, 76, 79, 82, 88-89, 92-94, 97, 100-114
// These formats are omitted due to lack of a corresponding Vulkan format. D24_UNORM_S8_UINT (DXGI_FORMAT 45)
// has a matching Vulkan format but is also omitted as it is only supported by Nvidia.
Unknown,
R32G32B32A32_TYPELESS,
R32G32B32_TYPELESS,
R32G32_TYPELESS,
R32_TYPELESS,
R16G16B16A16_TYPELESS,
R16G16_TYPELESS,
R16_TYPELESS,
R8G8B8A8_TYPELESS,
R8G8_TYPELESS,
R8_TYPELESS,
B8G8R8A8_TYPELESS,
R32G32B32A32_FLOAT,
R32G32B32_FLOAT,
R32G32_FLOAT,
R32_FLOAT,
R16G16B16A16_FLOAT,
R16G16_FLOAT,
R16_FLOAT,
R32G32B32A32_UINT,
R32G32B32_UINT,
R32G32_UINT,
R32_UINT,
R16G16B16A16_UINT,
R16G16_UINT,
R16_UINT,
R8G8B8A8_UINT,
R8G8_UINT,
R8_UINT,
R32G32B32A32_SINT,
R32G32B32_SINT,
R32G32_SINT,
R32_SINT,
R16G16B16A16_SINT,
R16G16_SINT,
R16_SINT,
R8G8B8A8_SINT,
R8G8_SINT,
R8_SINT,
R16G16B16A16_UNORM,
R16G16_UNORM,
R16_UNORM,
R8G8B8A8_UNORM,
R8G8B8A8_UNORM_SRGB,
R8G8_UNORM,
R8_UNORM,
B8G8R8A8_UNORM,
B8G8R8A8_UNORM_SRGB,
B8G8R8X8_UNORM,
B8G8R8X8_UNORM_SRGB,
R16G16B16A16_SNORM,
R16G16_SNORM,
R16_SNORM,
R8G8B8A8_SNORM,
R8G8_SNORM,
R8_SNORM,
D32_FLOAT,
D16_UNORM,
B4G4R4A4_UNORM,
B5G6R5_UNORM,
B5G5R5A1_UNORM,
R9G9B9E5_SHAREDEXP,
R10G10B10A2_TYPELESS,
R10G10B10A2_UNORM,
R10G10B10A2_UINT,
R11G11B10_FLOAT,
BC1_UNORM,
BC1_UNORM_SRGB,
BC2_UNORM,
BC2_UNORM_SRGB,
BC3_UNORM,
BC3_UNORM_SRGB,
BC4_UNORM,
BC4_SNORM,
BC5_UNORM,
BC5_SNORM,
BC6H_UF16,
BC6H_SF16,
BC7_UNORM,
BC7_UNORM_SRGB,
_Count,
};
// TODO: Aspect = Color, Depth, Stencil, etc.
// TODO: Channel = R, G, B, A, D, S, etc.
// TODO: Pick : pixel or texel
// TODO: Block is a good term for what it is
// TODO: Width/Height/Depth/whatever should not be used. We should use extentX, extentY, etc.
struct FormatInfo
{
GfxCount channelCount; ///< The amount of channels in the format. Only set if the channelType is set
uint8_t channelType; ///< One of SlangScalarType None if type isn't made up of elements of type. TODO: Change to uint32_t?
Size blockSizeInBytes; ///< The size of a block in bytes.
GfxCount pixelsPerBlock; ///< The number of pixels contained in a block.
GfxCount blockWidth; ///< The width of a block in pixels.
GfxCount blockHeight; ///< The height of a block in pixels.
};
enum class InputSlotClass
{
PerVertex, PerInstance
};
struct InputElementDesc
{
char const* semanticName; ///< The name of the corresponding parameter in shader code.
GfxIndex semanticIndex; ///< The index of the corresponding parameter in shader code. Only needed if multiple parameters share a semantic name.
Format format; ///< The format of the data being fetched for this element.
Offset offset; ///< The offset in bytes of this element from the start of the corresponding chunk of vertex stream data.
GfxIndex bufferSlotIndex; ///< The index of the vertex stream to fetch this element's data from.
};
struct VertexStreamDesc
{
Size stride; ///< The stride in bytes for this vertex stream.
InputSlotClass slotClass; ///< Whether the stream contains per-vertex or per-instance data.
GfxCount instanceDataStepRate; ///< How many instances to draw per chunk of data.
};
enum class PrimitiveType
{
Point, Line, Triangle, Patch
};
enum class PrimitiveTopology
{
TriangleList, TriangleStrip, PointList, LineList, LineStrip
};
enum class ResourceState
{
Undefined,
General,
PreInitialized,
VertexBuffer,
IndexBuffer,
ConstantBuffer,
StreamOutput,
ShaderResource,
UnorderedAccess,
RenderTarget,
DepthRead,
DepthWrite,
Present,
IndirectArgument,
CopySource,
CopyDestination,
ResolveSource,
ResolveDestination,
AccelerationStructure,
AccelerationStructureBuildInput,
PixelShaderResource,
NonPixelShaderResource,
_Count
};
struct ResourceStateSet
{
public:
void add(ResourceState state) { m_bitFields |= (1LL << (uint32_t)state); }
template <typename... TResourceState> void add(ResourceState s, TResourceState... states)
{
add(s);
add(states...);
}
bool contains(ResourceState state) const { return (m_bitFields & (1LL << (uint32_t)state)) != 0; }
ResourceStateSet()
: m_bitFields(0)
{}
ResourceStateSet(const ResourceStateSet& other) = default;
ResourceStateSet(ResourceState state) { add(state); }
template <typename... TResourceState> ResourceStateSet(TResourceState... states)
{
add(states...);
}
ResourceStateSet operator&(const ResourceStateSet& that) const
{
ResourceStateSet result;
result.m_bitFields = this->m_bitFields & that.m_bitFields;
return result;
}
private:
uint64_t m_bitFields = 0;
void add() {}
};
/// Describes how memory for the resource should be allocated for CPU access.
enum class MemoryType
{
DeviceLocal,
Upload,
ReadBack,
};
enum class InteropHandleAPI
{
Unknown,
D3D12, // A D3D12 object pointer.
Vulkan, // A general Vulkan object handle.
CUDA, // A general CUDA object handle.
Win32, // A general Win32 HANDLE.
FileDescriptor, // A file descriptor.
DeviceAddress, // A device address.
D3D12CpuDescriptorHandle, // A D3D12_CPU_DESCRIPTOR_HANDLE value.
};
struct InteropHandle
{
InteropHandleAPI api = InteropHandleAPI::Unknown;
uint64_t handleValue = 0;
};
// Declare opaque type
class IInputLayout : public ISlangUnknown
{
public:
struct Desc
{
InputElementDesc const* inputElements = nullptr;
GfxCount inputElementCount = 0;
VertexStreamDesc const* vertexStreams = nullptr;
GfxCount vertexStreamCount = 0;
};
};
#define SLANG_UUID_IInputLayout \
{ \
0x45223711, 0xa84b, 0x455c, { 0xbe, 0xfa, 0x49, 0x37, 0x42, 0x1e, 0x8e, 0x2e } \
}
class IResource: public ISlangUnknown
{
public:
/// The type of resource.
/// NOTE! The order needs to be such that all texture types are at or after Texture1D (otherwise isTexture won't work correctly)
enum class Type
{
Unknown, ///< Unknown
Buffer, ///< A buffer (like a constant/index/vertex buffer)
Texture1D, ///< A 1d texture
Texture2D, ///< A 2d texture
Texture3D, ///< A 3d texture
TextureCube, ///< A cubemap consists of 6 Texture2D like faces
_Count,
};
/// Base class for Descs
struct DescBase
{
Type type = Type::Unknown;
ResourceState defaultState = ResourceState::Undefined;
ResourceStateSet allowedStates = ResourceStateSet();
MemoryType memoryType = MemoryType::DeviceLocal;
InteropHandle existingHandle = {};
bool isShared = false;
};
virtual SLANG_NO_THROW Type SLANG_MCALL getType() = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeResourceHandle(InteropHandle* outHandle) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL getSharedHandle(InteropHandle* outHandle) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL setDebugName(const char* name) = 0;
virtual SLANG_NO_THROW const char* SLANG_MCALL getDebugName() = 0;
};
#define SLANG_UUID_IResource \
{ \
0xa0e39f34, 0x8398, 0x4522, { 0x95, 0xc2, 0xeb, 0xc0, 0xf9, 0x84, 0xef, 0x3f } \
}
struct MemoryRange
{
// TODO: Change to Offset/Size?
uint64_t offset;
uint64_t size;
};
class IBufferResource: public IResource
{
public:
struct Desc: public DescBase
{
Size sizeInBytes = 0; ///< Total size in bytes
Size elementSize = 0; ///< Get the element stride. If > 0, this is a structured buffer
Format format = Format::Unknown;
};
virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() = 0;
virtual SLANG_NO_THROW DeviceAddress SLANG_MCALL getDeviceAddress() = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL map(MemoryRange* rangeToRead, void** outPointer) = 0;
virtual SLANG_NO_THROW Result SLANG_MCALL unmap(MemoryRange* writtenRange) = 0;
};
#define SLANG_UUID_IBufferResource \
{ \
0x1b274efe, 0x5e37, 0x492b, { 0x82, 0x6e, 0x7e, 0xe7, 0xe8, 0xf5, 0xa4, 0x9b } \
}
struct DepthStencilClearValue
{
float depth = 1.0f;
uint32_t stencil = 0;
};
union ColorClearValue
{
float floatValues[4];
uint32_t uintValues[4];
};
struct ClearValue
{
ColorClearValue color = {{0.0f, 0.0f, 0.0f, 0.0f}};
DepthStencilClearValue depthStencil;
};
struct BufferRange
{
// TODO: Change to Index and Count?
uint64_t firstElement;
uint64_t elementCount;
};
enum class TextureAspect : uint32_t
{
Default = 0,
Color = 0x00000001,
Depth = 0x00000002,
Stencil = 0x00000004,
MetaData = 0x00000008,
Plane0 = 0x00000010,
Plane1 = 0x00000020,
Plane2 = 0x00000040,
DepthStencil = Depth | Stencil,
};
struct SubresourceRange
{
TextureAspect aspectMask;
GfxIndex mipLevel;
GfxCount mipLevelCount;
GfxIndex baseArrayLayer; // For Texture3D, this is WSlice.
GfxCount layerCount; // For cube maps, this is a multiple of 6.
};
class ITextureResource: public IResource
{
public:
static const Size kRemainingTextureSize = 0xFFFFFFFF;
struct Offset3D
{
GfxIndex x = 0;
GfxIndex y = 0;
GfxIndex z = 0;
Offset3D() = default;
Offset3D(GfxIndex _x, GfxIndex _y, GfxIndex _z) :x(_x), y(_y), z(_z) {}
};
struct SampleDesc
{
GfxCount numSamples = 1; ///< Number of samples per pixel
int quality = 0; ///< The quality measure for the samples
};
struct Extents
{
GfxCount width = 0; ///< Width in pixels
GfxCount height = 0; ///< Height in pixels (if 2d or 3d)
GfxCount depth = 0; ///< Depth (if 3d)
};
struct Desc: public DescBase
{
Extents size;
GfxCount arraySize = 0; ///< Array size
GfxCount numMipLevels = 0; ///< Number of mip levels - if 0 will create all mip levels
Format format; ///< The resources format
SampleDesc sampleDesc; ///< How the resource is sampled
ClearValue* optimalClearValue = nullptr;
};
/// Data for a single subresource of a texture.
///
/// Each subresource is a tensor with `1 <= rank <= 3`,
/// where the rank is deterined by the base shape of the
/// texture (Buffer, 1D, 2D, 3D, or Cube). For the common
/// case of a 2D texture, `rank == 2` and each subresource
/// is a 2D image.
///
/// Subresource tensors must be stored in a row-major layout,
/// so that the X axis strides over texels, the Y axis strides
/// over 1D rows of texels, and the Z axis strides over 2D
/// "layers" of texels.
///
/// For a texture with multiple mip levels or array elements,
/// each mip level and array element is stores as a distinct
/// subresource. When indexing into an array of subresources,
/// the index of a subresoruce for mip level `m` and array
/// index `a` is `m + a*mipLevelCount`.
///
struct SubresourceData
{
/// Pointer to texel data for the subresource tensor.
void const* data;
/// Stride in bytes between rows of the subresource tensor.
///
/// This is the number of bytes to add to a pointer to a texel
/// at (X,Y,Z) to get to a texel at (X,Y+1,Z).
///
/// Devices may not support all possible values for `strideY`.
/// In particular, they may only support strictly positive strides.
///
gfx::Size strideY;
/// Stride in bytes between layers of the subresource tensor.
///
/// This is the number of bytes to add to a pointer to a texel
/// at (X,Y,Z) to get to a texel at (X,Y,Z+1).
///
/// Devices may not support all possible values for `strideZ`.
/// In particular, they may only support strictly positive strides.
///
gfx::Size strideZ;
};
virtual SLANG_NO_THROW Desc* SLANG_MCALL getDesc() = 0;
};
#define SLANG_UUID_ITextureResource \
{ \
0xcf88a31c, 0x6187, 0x46c5, { 0xa4, 0xb7, 0xeb, 0x58, 0xc7, 0x33, 0x40, 0x17 } \
}
enum class ComparisonFunc : uint8_t
{
Never = 0x0,
Less = 0x1,
Equal = 0x2,
LessEqual = 0x3,
Greater = 0x4,
NotEqual = 0x5,
GreaterEqual = 0x6,
Always = 0x7,
};
enum class TextureFilteringMode
{
Point,
Linear,
};
enum class TextureAddressingMode
{
Wrap,
ClampToEdge,
ClampToBorder,
MirrorRepeat,
MirrorOnce,
};
enum class TextureReductionOp
{
Average,
Comparison,
Minimum,
Maximum,
};
class ISamplerState : public ISlangUnknown
{
public:
struct Desc
{
TextureFilteringMode minFilter = TextureFilteringMode::Linear;
TextureFilteringMode magFilter = TextureFilteringMode::Linear;
TextureFilteringMode mipFilter = TextureFilteringMode::Linear;
TextureReductionOp reductionOp = TextureReductionOp::Average;
TextureAddressingMode addressU = TextureAddressingMode::Wrap;
TextureAddressingMode addressV = TextureAddressingMode::Wrap;
TextureAddressingMode addressW = TextureAddressingMode::Wrap;
float mipLODBias = 0.0f;
uint32_t maxAnisotropy = 1;
ComparisonFunc comparisonFunc = ComparisonFunc::Never;
float borderColor[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
float minLOD = -FLT_MAX;
float maxLOD = FLT_MAX;
};
/// Returns a native API handle representing this sampler state object.
/// When using D3D12, this will be a D3D12_CPU_DESCRIPTOR_HANDLE.
/// When using Vulkan, this will be a VkSampler.
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) = 0;
};
#define SLANG_UUID_ISamplerState \
{ \
0x8b8055df, 0x9377, 0x401d, { 0x91, 0xff, 0x3f, 0xa3, 0xbf, 0x66, 0x64, 0xf4 } \
}
class IResourceView : public ISlangUnknown
{
public:
enum class Type
{
Unknown,
RenderTarget,
DepthStencil,
ShaderResource,
UnorderedAccess,
AccelerationStructure,
CountOf_,
};
struct RenderTargetDesc
{
// The resource shape of this render target view.
IResource::Type shape;
};
struct Desc
{
Type type;
Format format;
// Required fields for `RenderTarget` and `DepthStencil` views.
RenderTargetDesc renderTarget;
// Specifies the range of a texture resource for a ShaderRsource/UnorderedAccess/RenderTarget/DepthStencil view.
SubresourceRange subresourceRange;
// Specifies the range of a buffer resource for a ShaderResource/UnorderedAccess view.
BufferRange bufferRange;
// Specifies the element size in bytes of a structured buffer. Pass 0 for a raw buffer view.
Size bufferElementSize;
};
virtual SLANG_NO_THROW Desc* SLANG_MCALL getViewDesc() = 0;
/// Returns a native API handle representing this resource view object.
/// When using D3D12, this will be a D3D12_CPU_DESCRIPTOR_HANDLE or a buffer device address depending
/// on the type of the resource view.
/// When using Vulkan, this will be a VkImageView, VkBufferView, VkAccelerationStructure or a VkBuffer
/// depending on the type of the resource view.
virtual SLANG_NO_THROW Result SLANG_MCALL getNativeHandle(InteropHandle* outNativeHandle) = 0;
};
#define SLANG_UUID_IResourceView \
{ \
0x7b6c4926, 0x884, 0x408c, { 0xad, 0x8a, 0x50, 0x3a, 0x8e, 0x23, 0x98, 0xa4 } \
}
class IAccelerationStructure : public IResourceView
{
public:
enum class Kind
{
TopLevel,
BottomLevel
};
struct BuildFlags
{
// The enum values are intentionally consistent with
// D3D12_RAYTRACING_ACCELERATION_STRUCTURE_BUILD_FLAGS.
enum Enum
{
None,
AllowUpdate = 1,
AllowCompaction = 2,
PreferFastTrace = 4,
PreferFastBuild = 8,
MinimizeMemory = 16,
PerformUpdate = 32
};
};
enum class GeometryType
{
Triangles, ProcedurePrimitives
};
struct GeometryFlags
{
// The enum values are intentionally consistent with
// D3D12_RAYTRACING_GEOMETRY_FLAGS.
enum Enum
{
None,
Opaque = 1,
NoDuplicateAnyHitInvocation = 2
};
};
struct TriangleDesc
{
DeviceAddress transform3x4;
Format indexFormat;
Format vertexFormat;
GfxCount indexCount;
GfxCount vertexCount;
DeviceAddress indexData;
DeviceAddress vertexData;
Size vertexStride;
};
struct ProceduralAABB
{
float minX;
float minY;
float minZ;
float maxX;
float maxY;
float maxZ;
};
struct ProceduralAABBDesc
{
/// Number of AABBs.
GfxCount count;
/// Pointer to an array of `ProceduralAABB` values in device memory.
DeviceAddress data;
/// Stride in bytes of the AABB values array.
Size stride;
};
struct GeometryDesc
{
GeometryType type;
GeometryFlags::Enum flags;
union
{
TriangleDesc triangles;
ProceduralAABBDesc proceduralAABBs;
} content;
};
struct GeometryInstanceFlags
{
// The enum values are kept consistent with D3D12_RAYTRACING_INSTANCE_FLAGS
// and VkGeometryInstanceFlagBitsKHR.
enum Enum : uint32_t
{
None = 0,
TriangleFacingCullDisable = 0x00000001,
TriangleFrontCounterClockwise = 0x00000002,
ForceOpaque = 0x00000004,
NoOpaque = 0x00000008
};
};
// TODO: Should any of these be changed?
// The layout of this struct is intentionally consistent with D3D12_RAYTRACING_INSTANCE_DESC
// and VkAccelerationStructureInstanceKHR.
struct InstanceDesc
{
float transform[3][4];
uint32_t instanceID : 24;
uint32_t instanceMask : 8;
uint32_t instanceContributionToHitGroupIndex : 24;
uint32_t flags : 8; // Combination of GeometryInstanceFlags::Enum values.
DeviceAddress accelerationStructure;
};
struct PrebuildInfo
{
Size resultDataMaxSize;
Size scratchDataSize;
Size updateScratchDataSize;
};