-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppgpu.hpp
3802 lines (3221 loc) · 113 KB
/
ppgpu.hpp
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
#pragma once
#include <exception>
#include <iostream>
#include <sstream>
#include <utility>
#include <future>
#define WGPU_TARGET_MACOS 1
#define WGPU_TARGET_LINUX_X11 2
#define WGPU_TARGET_WINDOWS 3
#define WGPU_TARGET_WAYLAND 4
#if defined(_WIN32)
#define WGPU_TARGET WGPU_TARGET_WINDOWS
#elif defined(__APPLE__)
#define WGPU_TARGET WGPU_TARGET_MACOS
#else
#define WGPU_TARGET WGPU_TARGET_LINUX_X11
#endif
using CStr = char const*;
namespace wgpu {
#define END };
static constexpr auto ARRAY_LAYER_COUNT_UNDEFINED = 0xffffffffUL;
static constexpr auto COPY_STRIDE_UNDEFINED = 0xffffffffUL;
static constexpr auto LIMIT_U32_UNDEFINED = 0xffffffffUL;
static constexpr auto LIMIT_U64_UNDEFINED = 0xffffffffffffffffULL;
static constexpr auto MIP_LEVEL_COUNT_UNDEFINED = 0xffffffffUL;
static constexpr auto WHOLE_MAP_SIZE = SIZE_MAX;
static constexpr auto WHOLE_SIZE = 0xffffffffffffffffULL;
using Flags = uint32_t;
// STRUCTURE FORWARD DECLARATIONS
struct AdapterProperties;
struct BindGroupEntry;
struct BlendComponent;
struct BufferBindingLayout;
struct BufferDescriptor;
struct Color;
struct CommandBufferDescriptor;
struct CommandEncoderDescriptor;
struct CompilationMessage;
struct ComputePassTimestampWrite;
struct ConstantEntry;
struct Extent3D;
struct InstanceDescriptor;
struct Limits;
struct MultisampleState;
struct Origin3D;
struct PipelineLayoutDescriptor;
struct PrimitiveDepthClipControl;
struct PrimitiveState;
struct QuerySetDescriptor;
struct QueueDescriptor;;
struct RenderBundleDescriptor;
struct RenderBundleEncoderDescriptor;
struct RenderPassDepthStencilAttachment;
struct RenderPassDescriptorMaxDrawCount;
struct RenderPassTimestampWrite;
struct RequestAdapterOptions;
struct SamplerBindingLayout;
struct SamplerDescriptor;
struct ShaderModuleCompilationHint;
struct ShaderModuleSPIRVDescriptor;
struct ShaderModuleWGSLDescriptor;
struct StencilFaceState;
struct StorageTextureBindingLayout;
struct SurfaceDescriptor;
struct SurfaceDescriptorFromAndroidNativeWindow;
struct SurfaceDescriptorFromCanvasHTMLSelector;
struct SurfaceDescriptorFromMetalLayer;
struct SurfaceDescriptorFromWaylandSurface;
struct SurfaceDescriptorFromWindowsHWND;
struct SurfaceDescriptorFromXcbWindow;
struct SurfaceDescriptorFromXlibWindow;
struct SwapChainDescriptor;
struct TextureBindingLayout;
struct TextureDataLayout;
struct TextureViewDescriptor;
struct VertextAttribute;
struct BindGroupDescriptor;
struct BindGroupLayoutEntry;
struct BlendState;
struct CompilationInfo;
struct ComputePassDescriptor;
struct DepthStencilState;
struct ImageCopyBuffer;
struct ImageCopyTexture;
struct ProgrammableStageDescriptor;
struct RenderPassColorAttachment;
struct RequiredLimits;
struct ShaderModuleDescriptor;
struct SupportedLimits;
struct TextureDescriptor;
struct VertexBufferLayout;
struct BindGroupLayoutDescriptor;
struct ColorTargetState;
struct ComputePipelineDescriptor;
struct DeviceDescriptor;
struct RenderPassDescriptor;
struct VertexState;
struct RenderPipelineDescriptor;
namespace impl {
using Adapter = struct WGPUAdapterImpl*;
using BindGroup = struct WGPUBindGroupImpl*;
using BindGroupLayout = struct WGPUBindGroupLayoutImpl*;
using Buffer = struct WGPUBufferImpl*;
using CommandBuffer = struct WGPUCommandBufferImpl*;
using CommandEncoder = struct WGPUCommandEncoderImpl*;
using ComputePassEncoder = struct WGPUComputePassEncoderImpl*;
using ComputePipeline = struct WGPUComputePipelineImpl*;
using Device = struct WGPUDeviceImpl*;
using Instance = struct WGPUInstanceImpl*;
using PipelineLayout = struct WGPUPipelineLayoutImpl*;
using QuerySet = struct WGPUQuerySetImpl*;
using Queue = struct WGPUQueueImpl*;
using RenderBundle = struct WGPURenderBundleImpl*;
using RenderBundleEncoder = struct WGPURenderBundleEncoderImpl*;
using RenderPassEncoder = struct WGPURenderPassEncoderImpl*;
using RenderPipeline = struct WGPURenderPipelineImpl*;
using Sampler = struct WGPUSamplerImpl*;
using ShaderModule = struct WGPUShaderModuleImpl*;
using Surface = struct WGPUSurfaceImpl*;
using SwapChain = struct WGPUSwapChainImpl*;
using Texture = struct WGPUTextureImpl*;
using TextureView = struct WGPUTextureViewImpl*;
} // namespace impl
// ENUMERATIONS
#define ENUM(Name) enum class Name : int32_t {
#define ENUM_FORCE32 Force32 = 0x7FFFFFFF
ENUM(AdapterType)
DiscreteGPU = 0x0000'0000,
IntegratedGPU = 0x0000'0001,
CPU = 0x0000'0002,
Unknown = 0x0000'0003,
ENUM_FORCE32
END
ENUM(AddressMode)
Repeat,
MirrorRepeat,
ClampToEdge,
ENUM_FORCE32
END
ENUM(BackendType)
Null = 0x0000'0000,
WebGPU = 0x0000'0001,
D3D11 = 0x0000'0002,
D3D12 = 0x0000'0003,
Metal = 0x0000'0004,
Vulkan = 0x0000'0005,
OpenGL = 0x0000'0006,
OpenGLES = 0x0000'0007,
ENUM_FORCE32
END
ENUM(BlendFactor)
Zero = 0x0000'0000,
One = 0x0000'0001,
Src = 0x0000'0002,
OneMinusSrc = 0x0000'0003,
SrcAlpha = 0x0000'0004,
OneMinusSrcAlpha = 0x0000'0005,
Dst = 0x0000'000006,
OneMinusDst = 0x0000'0007,
DstAlpha = 0x0000'0008,
OneMinusDstAlpha = 0x0000'0009,
SrcAlphaSaturated = 0x0000'000A,
Constant = 0x0000'0000B,
OneMinusConstant = 0x0000'000C,
ENUM_FORCE32
END
ENUM(BlendOperation)
Add,
Sub,
ReverseSub,
Min,
Max,
ENUM_FORCE32
END
ENUM(BufferBindingType)
Undefined,
Uniform,
Storage,
ReadOnlyStorage,
ENUM_FORCE32
END
ENUM(BufferMapAsyncStatus)
Success,
ValidationError,
Unknown,
DeviceLost,
DestroyedBeforeCallback,
UnmappedBeforeCallback,
MappingAlreadyPending,
OffsetOutOfRange,
SizeOutOfRange,
ENUM_FORCE32
END
ENUM(BufferMapState)
Unmapped,
Pending,
Mapped,
ENUM_FORCE32
END
ENUM(CompareFunction)
Undefined,
Never,
Less,
LessEqual,
Greater,
GreaterEqual,
Equal,
NotEqual,
Always,
ENUM_FORCE32
END
ENUM(CompilationInfoRequestStatus)
Success,
Error,
DeviceLost,
Unknown,
ENUM_FORCE32
END
ENUM(CompilationMessageType)
Error,
Warning,
Info,
ENUM_FORCE32
END
ENUM(ComputePassTimestampLocation)
Beginning,
End,
ENUM_FORCE32
END
ENUM(CreatePipelineAsyncStatus)
Success,
ValidationError,
InternalError,
DeviceLost,
DeviceDestroyed,
Unknown,
ENUM_FORCE32
END
ENUM(CullMode)
None,
Front,
Back,
ENUM_FORCE32
END
ENUM(DeviceLostReason)
Undefined,
Destroyed,
END
ENUM(ErrorFilter)
Validation,
OutOfMemory,
Internal,
END
ENUM(ErrorType)
NoError,
Validation,
OutOfMemory,
Internal,
Unknown,
DeviceLost,
ENUM_FORCE32
END
ENUM(FeatureName)
Undefined,
DepthClipControl,
Depth32FloatStencil8,
TimestampQuery,
PipelineStatisticsQuery,
TextureCompressionBC,
TextureCompressionETC2,
TextureCompressionASTC,
IndirectFirstInstance,
ShaderF16,
RG11B10UfloatRenderable,
BGRA8UnormStorage,
Float32Filterable,
ENUM_FORCE32
END
ENUM(FilterMode)
Nearest,
Linear,
ENUM_FORCE32
END
ENUM(FrontFace)
CCW,
CW,
ENUM_FORCE32
END
ENUM(IndexFormat)
Undefined,
Uint16,
Uint32,
ENUM_FORCE32
END
ENUM(LoadOp)
Undefined,
Clear,
Load,
ENUM_FORCE32
END
ENUM(MipmapFilterMode)
Nearest,
Linear,
ENUM_FORCE32
END
ENUM(PipelineStatisticsName)
VertexShaderInvocations,
ClipperInvocations,
ClipperPrimitivesOut,
FragmentShaderInvocations,
ComputeShaderInvocations,
ENUM_FORCE32
END
ENUM(PowerPreference)
Undefined,
LowPower,
HighPerformance,
ENUM_FORCE32
END
ENUM(PresentMode)
Immediate,
Mailbox,
Fifo,
ENUM_FORCE32
END
ENUM(PrimitiveTopology)
PointList,
LineList,
LineStrip,
TriangleList,
TriangleStrip,
ENUM_FORCE32
END
ENUM(QueryType)
Occlusion,
PipelineStatistics,
Timestamp,
ENUM_FORCE32
END
ENUM(QueueWorkDoneStatus)
Success,
Error,
Unknown,
DeviceLost,
ENUM_FORCE32
END
ENUM(RenderPassTimestampLocation)
Beginning,
End,
ENUM_FORCE32
END
ENUM(RequestAdapterStatus)
Success = 0x0000'0000,
Unavailable = 0x000'00001,
Error = 0x0000'0002,
Unknown = 0x0000'0003,
ENUM_FORCE32
END
ENUM(RequestDeviceAsyncStatus)
Success,
Error,
Unknown,
ENUM_FORCE32
END
ENUM(SType)
Invalid = 0x0000'0000,
SurfaceDescriptorFromMetalLayer = 0x0000'0001,
SurfaceDescriptorFromWindowsHWND = 0x0000'0002,
SurfaceDescriptorFromXlibWindow = 0x0000'0003,
SurfaceDescriptorFromCanvasHTMLSelector = 0x0000'0004,
ShaderModuleSPIRVDescriptor = 0x0000'0005,
ShaderModuleWGSLDescriptor = 0x0000'0006,
PrimitiveDepthClipControl = 0x0000'0007,
SurfaceDescriptorFromWaylandSurface = 0x0000'00008,
SurfaceDescriptorFromAndroidNativeWindow = 0x0000'0009,
SurfaceDescriptorFromXcbWindow = 0x0000'000A,
RenderPassDescriptorMaxDrawCount = 0x0000'000F,
ENUM_FORCE32
END
ENUM(SamplerBindingType)
Undefined,
Filtering,
NonFiltering,
Comparison,
ENUM_FORCE32
END
ENUM(StencilOperation)
Keep,
Zero,
Replace,
Invert,
IncrementClamp,
DecrementClamp,
IncrementWrap,
DecrementWrap,
ENUM_FORCE32
END
ENUM(StorageTextureAccess)
Undefined,
WriteOnly,
ENUM_FORCE32
END
ENUM(StoreOp)
Undefined,
Store,
Discard,
ENUM_FORCE32
END
ENUM(TextureAspect)
All,
StencilOnly,
DepthOnly,
ENUM_FORCE32
END
ENUM(TextureDimension)
D1,
D2,
D3,
ENUM_FORCE32
END
ENUM(TextureFormat)
Undefined,
R8Unorm,
R8Snorm,
R8Uint,
R8Sint,
R16Uint,
R16Sint,
R16Float,
RG8Unorm,
RG8Snorm,
RG8Uint,
RG8Sint,
R32Float,
R32Uint,
R32Sint,
RG16Uint,
RG16Sint,
RG16Float,
RGBA8Unorm,
RGBA8UnormSrgb,
RGBA8Snorm,
RGBA8Uint,
RGBA8Sint,
BGRA8Unorm,
BGRA8UnormSrgb,
RGB10A2Unorm,
RG11B10Ufloat,
RGB9E5Ufloat,
RG32Float,
RG32Uint,
RG32Sint,
RGBA16Uint,
RGBA16Sint,
RGBA16Float,
RGBA32Float,
RGBA32Uint,
RGBA32Sint,
Stencil8,
Depth16Unorm,
Depth24Plus,
Depth24PlusStencil8,
Depth32Float,
Depth32FloatStencil8,
BC1RGBAUnorm,
BC1RGBAUnormSrgb,
BC2RGBAUnorm,
BC2RGBAUnormSrgb,
BC3RGBAUnorm,
BC3RGBAUnormSrgb,
BC4RUnorm,
BC4RSnorm,
BC5RGUnorm,
BC5RGSnorm,
BC6HRGBUfloat,
BC6HRGBFloat,
BC7RGBAUnorm,
BC7RGBAUnormSrgb,
ETC2RGB8Unorm,
ETC2RGB8UnormSrgb,
ETC2RGB8A1Unorm,
ETC2RGB8A1UnormSrgb,
ETC2RGBA8Unorm,
ETC2RGBA8UnormSrgb,
EACR11Unorm,
EACR11Snorm,
EACRG11Unorm,
EACRG11Snorm,
ASTC4x4Unorm,
ASTC4x4UnormSrgb,
ASTC5x4Unorm,
ASTC5x4UnormSrgb,
ASTC5x5Unorm,
ASTC5x5UnormSrgb,
ASTC6x5Unorm,
ASTC6x5UnormSrgb,
ASTC6x6Unorm,
ASTC6x6UnormSrgb,
ASTC8x5Unorm,
ASTC8x5UnormSrgb,
ASTC8x6Unorm,
ASTC8x6UnormSrgb,
ASTC8x8Unorm,
ASTC8x8UnormSrgb,
ASTC10x5Unorm,
ASTC10x5UnormSrgb,
ASTC10x6Unorm,
ASTC10x6UnormSrgb,
ASTC10x8Unorm,
ASTC10x8UnormSrgb,
ASTC10x10Unorm,
ASTC10x10UnormSrgb,
ASTC12x10Unorm,
ASTC12x10UnormSrgb,
ASTC12x12Unorm,
ASTC12x12UnormSrgb,
ENUM_FORCE32
END
ENUM(TextureSampleType)
Undefined,
Float,
UnfilterableFloat,
Depth,
Sint,
Uint,
ENUM_FORCE32
END
ENUM(TextureViewDimension)
Undefined,
D1,
D2,
D2Array,
Cube,
CubeArray,
D3,
ENUM_FORCE32
END
ENUM(VertexFormat)
Undefined,
Uint8x2,
Uint8x4,
Sint8x2,
Sint8x4,
Unorm8x2,
Unorm8x4,
Snorm8x2,
Snorm8x4,
Uint16x2,
Uint16x4,
Sint16x2,
Sint16x4,
Unorm16x2,
Unorm16x4,
Snorm16x2,
Snorm16x4,
Float16x2,
Float16x4,
Float32,
Float32x2,
Float32x3,
Float32x4,
Uint32,
Uint32x2,
Uint32x3,
Uint32x4,
Sint32,
Sint32x2,
Sint32x3,
Sint32x4,
ENUM_FORCE32
END
ENUM(VertexStepMode)
Vertex = 0x00000000,
Instance = 0x00000001,
VertexBufferNotUsed = 0x00000002,
ENUM_FORCE32
END
ENUM(BufferUsage)
None = 0x0000'0000,
MapRead = 0x0000'0001,
MapWrite = 0x0000'0002,
CopySrc = 0x0000'0004,
CopyDst = 0x0000'0008,
Index = 0x0000'0010,
Vertex = 0x0000'0020,
Uniform = 0x0000'0040,
Storage = 0x0000'0080,
Indirect = 0x0000'0100,
QueryResolve = 0x0000'0200,
ENUM_FORCE32
END
ENUM(BufferUsageFlags)
END
ENUM(ColorWriteMask)
None = 0x0000'0000,
Red = 0x0000'0001,
Green = 0x0000'0002,
Blue = 0x0000'0004,
Alpha = 0x0000'0008,
All = 0x0000'0010,
ENUM_FORCE32
END
ENUM(ColorWriteMaskFlags)
END
ENUM(MapMode)
None,
Read,
Write,
ENUM_FORCE32
END
ENUM(MapModeFlags)
END
ENUM(ShaderStage)
None = 0x00000000,
Vertex = 0x00000001,
Fragment = 0x00000002,
Compute = 0x00000004,
ENUM_FORCE32
END
ENUM(ShaderStageFlags)
END
ENUM(TextureUsage)
None = 0x00000000,
CopySrc = 0x00000001,
CopyDst = 0x00000002,
TextureBinding = 0x00000004,
StorageBinding = 0x00000008,
RenderAttachment = 0x00000010,
ENUM_FORCE32
END
ENUM(TextureUsageFlags)
END
ENUM(NativeSType)
DeviceExtras = 0x60000001,
AdapterExtras = 0x60000002,
RequiredLimitsExtras = 0x60000003,
PipelineLimitsExtras = 0x60000004,
ShaderModuleGLSLDescriptor = 0x60000005,
SupportedLimitsExtras = 0x60000003,
InstanceExtras = 0x60000006,
SwapChainDeviceDescriptorExtras = 0x60000007,
ENUM_FORCE32
END
ENUM(NativeFeature)
PushConstants = 0x60000001,
TextureAdapterSpecificFormatFeatures = 0x60000002,
MultiDrawIndirect = 0x60000003,
MultiDrawIndirectCount = 0x60000004,
VertexWritableStorage = 0x60000005,
ENUM_FORCE32
END
ENUM(LogLevel)
Off,
Error,
Warn,
Info,
Debug,
Trace,
ENUM_FORCE32
END
ENUM(InstanceBackend)
Vulkan = 1,
GL = 1,
Metal = 1,
DX12 = 1,
DX11 = 1,
BrowserWebGPU = 1,
Primary = InstanceBackend::Vulkan,
Secondary = InstanceBackend::GL,
None = 0,
ENUM_FORCE32
END
ENUM(DX12Compiler)
Undefined,
Fxc,
Dxc,
ENUM_FORCE32
END
ENUM(CompositeAlphaMode)
Auto,
Opaque,
PreMultiplied,
PostMultiplied,
Inherit,
ENUM_FORCE32
END
// PLATFORM DEFAULTS
// TODO: Expand platform defaults
template <typename T>
static constexpr T PlatformDefault;
template <>
static constexpr auto PlatformDefault<BackendType> = (
#if WGPU_TARGET == WGPU_TARGET_MACOS
BackendType::Metal
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
BackendType::D3D12
#else
BackendType::Vulkan
#endif
);
template <>
static constexpr auto PlatformDefault<SType> = (
#if WGPU_TARGET == WGPU_TARGET_MACOS
SType::SurfaceDescriptorFromMetalLayer
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
SType::SurfaceDescriptorFromWindowsHWND
#elif WGPU_TARGET == WGPU_TARGET_LINUX_X11
SType::SurfaceDescriptorFromXlibWindow
#elif WGPU_TARGET == WGPU_TARGET_WAYLAND
SType::SurfaceSurfaceDescriptorFromWaylandSurface
#else
SType::Invalid
#endif
);
template<>
static constexpr auto PlatformDefault<InstanceBackend> = (
#if WGPU_TARGET == WGPU_TARGET_MACOS
InstanceBackend::Metal
#elif WGPU_TARGET == WGPU_TARGET_WINDOWS
InstanceBackend::Windows
#else
InstanceBackend::Vulkan
#endif
);
// STRUCTURES
#ifdef _WGPU_H_COMPAT
template <typename To, typename From>
concept NonAggregateWGPUCompatible =
std::is_standard_layout_v<To> &&
std::is_standard_layout_v<From> &&
sizeof(To) == sizeof(From);
template <typename To, typename From>
concept WGPUCompatible =
NonAggregateWGPUCompatible<To, From> &&
std::is_trivial_v<To>;
template <typename T>
using RawType = std::remove_cv_t<std::remove_pointer_t<std::remove_reference_t<T>>>;
struct DefaultWGPUCast {
template <typename To, typename From>
static inline auto cast(From val) -> To {
static_assert(WGPUCompatible<RawType<To>, RawType<From>>);
return reinterpret_cast<To>(val);
}
};
#define STRUCT_CAST_IMPL(Name, Cast) \
struct Name { \
using WSelf = WGPU ## Name; \
inline operator WSelf*() noexcept { return Cast::template cast<WSelf*>(this); } \
inline operator WSelf const*() const noexcept { return Cast::template cast<WSelf const*>(this); }
#else // _WGPU_H_COMPAT
#define STRUCT_CAST_IMPL(Name, _) struct Name {
#endif // _WGPU_H_COMPAT
#define STRUCT(Name) STRUCT_CAST_IMPL(Name, DefaultWGPUCast)
STRUCT(ChainedStruct)
ChainedStruct const* next {};
SType s_type{};
END
STRUCT(ChainedStructOut)
ChainedStructOut* next {};
SType s_type {};
END
STRUCT(BlendComponent)
BlendOperation operation = BlendOperation::Add;
BlendFactor src_factor = BlendFactor::One;
BlendFactor dst_factor = BlendFactor::Zero;
END
STRUCT(Color)
double r {};
double g {};
double b {};
double a = 1.0;
END
STRUCT(ComputePassTimestampWrite)
impl::QuerySet query_set {};
uint32_t query_idx {};
ComputePassTimestampLocation location {};
END
STRUCT(Extent3D)
uint32_t width {};
uint32_t height = 1;
uint32_t depth_or_array_layers = 1;
END
STRUCT(Limits)
uint32_t max_texture_dimension_1D {};
uint32_t max_texture_dimension_2D {};
uint32_t max_texture_dimension_3D {};
uint32_t max_texture_array_layers {};
uint32_t max_bind_groups {};
uint32_t max_bindings_per_bind_group {};
uint32_t max_dynamic_uniform_buffers_per_pipeline_layout {};
uint32_t max_dynamic_storage_buffers_per_pipeline_layout {};
uint32_t max_sampled_textures_per_shader_stage {};
uint32_t max_samplers_per_shader_stage {};
uint32_t max_storage_buffers_per_shader_stage {};
uint32_t max_storage_textures_per_shader_stage {};
uint32_t max_uniform_buffers_per_shader_stage {};
uint64_t max_uniform_buffer_binding_size {};
uint64_t max_storage_buffer_binding_size {};
uint32_t min_uniform_buffer_offset_alignment = 64;
uint32_t min_storage_buffer_offset_alignment = 16;
uint32_t max_vertex_buffers {};
uint64_t max_buffer_size {};
uint32_t max_vertex_attributes {};
uint32_t max_vertex_buffer_array_stride {};
uint32_t max_inter_stage_shader_components {};
uint32_t max_inter_stage_shader_variables {};
uint32_t max_color_attachments {};
uint32_t max_color_attachment_bytes_per_sample {};
uint32_t max_compute_workgroup_storage_size {};
uint32_t max_compute_invocations_per_workgroup {};
uint32_t max_compute_workgroup_size_x {};
uint32_t max_compute_workgroup_size_y {};
uint32_t max_compute_workgroup_size_z {};
uint32_t max_compute_workgroups_per_dimension {};
END
STRUCT(Origin3D)
uint32_t x {};
uint32_t y {};
uint32_t z {};
END
STRUCT(PrimitiveDepthClipControl)
ChainedStruct chain = { .s_type = SType::PrimitiveDepthClipControl };
bool unclipped_depth {};
END
STRUCT(RenderPassDepthStencilAttachment)
impl::TextureView view {};
LoadOp depth_load_op = LoadOp::Undefined;
StoreOp depth_store_op = StoreOp::Undefined;
float depth_clear_value {};
bool depth_read_only = {};
LoadOp stencil_load_op = LoadOp::Undefined;
StoreOp stencil_store_op = StoreOp::Undefined;
uint32_t stencil_clear_value {};
bool stencil_read_only = {};
END
STRUCT(RenderPassDescriptorMaxDrawCount)
ChainedStruct chain = { .s_type = SType::RenderPassDescriptorMaxDrawCount };
uint64_t max_draw_count;
END
STRUCT(RenderPassTimestampWrite)
impl::QuerySet query_set {};
uint32_t query_idx {};
RenderPassTimestampLocation location {};
END
STRUCT(ShaderModuleSPIRVDescriptor)
ChainedStruct chain = { .s_type = SType::ShaderModuleSPIRVDescriptor };
uint32_t code_size {};
uint32_t const* code {};
END
STRUCT(ShaderModuleWGSLDescriptor)
ChainedStruct chain = { .s_type = SType::ShaderModuleWGSLDescriptor };
CStr code;
END
STRUCT(StencilFaceState)
CompareFunction compare = CompareFunction::Always;
StencilOperation fail_op = StencilOperation::Keep;
StencilOperation depth_fail_op = StencilOperation::Keep;
StencilOperation pass_op = StencilOperation::Keep;
END
STRUCT(SurfaceDescriptorFromAndroidNativeWindow)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromAndroidNativeWindow };
void* window {};
END
STRUCT(SurfaceDescriptorFromCanvasHTMLSelector)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromCanvasHTMLSelector };
CStr selector {};
END
STRUCT(SurfaceDescriptorFromMetalLayer)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromMetalLayer };
void* layer {};
END
STRUCT(SurfaceDescriptorFromWaylandSurface)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromWaylandSurface };
void* display {};
void* surface {};
END
STRUCT(SurfaceDescriptorFromWindowsHWND)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromWindowsHWND };
void* hinstance {};
void* hwnd {};
END
STRUCT(SurfaceDescriptorFromXcbWindow)
ChainedStruct chain = { .s_type = SType::SurfaceDescriptorFromXcbWindow };
void* connection {};
uint32_t window {};
END
STRUCT(VertexAttribute)
VertexFormat format = VertexFormat::Undefined;
uint64_t offset {};
uint32_t shader_location {};
END