forked from emscripten-core/emscripten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebgpu_cpp.h
More file actions
1487 lines (1281 loc) · 48.7 KB
/
webgpu_cpp.h
File metadata and controls
1487 lines (1281 loc) · 48.7 KB
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 WEBGPU_CPP_H_
#define WEBGPU_CPP_H_
#include "webgpu/webgpu.h"
#include <type_traits>
namespace wgpu {
template <typename T>
struct IsDawnBitmask {
static constexpr bool enable = false;
};
template <typename T, typename Enable = void>
struct LowerBitmask {
static constexpr bool enable = false;
};
template <typename T>
struct LowerBitmask<T, typename std::enable_if<IsDawnBitmask<T>::enable>::type> {
static constexpr bool enable = true;
using type = T;
constexpr static T Lower(T t) {
return t;
}
};
template <typename T>
struct BoolConvertible {
using Integral = typename std::underlying_type<T>::type;
constexpr BoolConvertible(Integral value) : value(value) {
}
constexpr operator bool() const {
return value != 0;
}
constexpr operator T() const {
return static_cast<T>(value);
}
Integral value;
};
template <typename T>
struct LowerBitmask<BoolConvertible<T>> {
static constexpr bool enable = true;
using type = T;
static constexpr type Lower(BoolConvertible<T> t) {
return t;
}
};
template <typename T1,
typename T2,
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator|(T1 left, T2 right) {
using T = typename LowerBitmask<T1>::type;
using Integral = typename std::underlying_type<T>::type;
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) |
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
}
template <typename T1,
typename T2,
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator&(T1 left, T2 right) {
using T = typename LowerBitmask<T1>::type;
using Integral = typename std::underlying_type<T>::type;
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) &
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
}
template <typename T1,
typename T2,
typename = typename std::enable_if<LowerBitmask<T1>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator^(T1 left, T2 right) {
using T = typename LowerBitmask<T1>::type;
using Integral = typename std::underlying_type<T>::type;
return static_cast<Integral>(LowerBitmask<T1>::Lower(left)) ^
static_cast<Integral>(LowerBitmask<T2>::Lower(right));
}
template <typename T1>
constexpr BoolConvertible<typename LowerBitmask<T1>::type> operator~(T1 t) {
using T = typename LowerBitmask<T1>::type;
using Integral = typename std::underlying_type<T>::type;
return ~static_cast<Integral>(LowerBitmask<T1>::Lower(t));
}
template <typename T,
typename T2,
typename = typename std::enable_if<IsDawnBitmask<T>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr T& operator&=(T& l, T2 right) {
T r = LowerBitmask<T2>::Lower(right);
l = l & r;
return l;
}
template <typename T,
typename T2,
typename = typename std::enable_if<IsDawnBitmask<T>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr T& operator|=(T& l, T2 right) {
T r = LowerBitmask<T2>::Lower(right);
l = l | r;
return l;
}
template <typename T,
typename T2,
typename = typename std::enable_if<IsDawnBitmask<T>::enable &&
LowerBitmask<T2>::enable>::type>
constexpr T& operator^=(T& l, T2 right) {
T r = LowerBitmask<T2>::Lower(right);
l = l ^ r;
return l;
}
template <typename T>
constexpr bool HasZeroOrOneBits(T value) {
using Integral = typename std::underlying_type<T>::type;
return (static_cast<Integral>(value) & (static_cast<Integral>(value) - 1)) == 0;
}
static constexpr uint64_t kWholeSize = WGPU_WHOLE_SIZE;
// TODO(crbug.com/520): Remove kStrideUndefined in favor of kCopyStrideUndefined.
static constexpr uint32_t kStrideUndefined = WGPU_STRIDE_UNDEFINED;
static constexpr uint32_t kCopyStrideUndefined = WGPU_COPY_STRIDE_UNDEFINED;
enum class AdapterType : uint32_t {
DiscreteGPU = 0x00000000,
IntegratedGPU = 0x00000001,
CPU = 0x00000002,
Unknown = 0x00000003,
};
enum class AddressMode : uint32_t {
Repeat = 0x00000000,
MirrorRepeat = 0x00000001,
ClampToEdge = 0x00000002,
};
enum class BackendType : uint32_t {
Null = 0x00000000,
D3D11 = 0x00000001,
D3D12 = 0x00000002,
Metal = 0x00000003,
Vulkan = 0x00000004,
OpenGL = 0x00000005,
OpenGLES = 0x00000006,
};
enum class BlendFactor : uint32_t {
Zero = 0x00000000,
One = 0x00000001,
Src = 0x00000002,
OneMinusSrc = 0x00000003,
SrcAlpha = 0x00000004,
OneMinusSrcAlpha = 0x00000005,
Dst = 0x00000006,
OneMinusDst = 0x00000007,
DstAlpha = 0x00000008,
OneMinusDstAlpha = 0x00000009,
SrcAlphaSaturated = 0x0000000A,
Constant = 0x0000000B,
OneMinusConstant = 0x0000000C,
};
enum class BlendOperation : uint32_t {
Add = 0x00000000,
Subtract = 0x00000001,
ReverseSubtract = 0x00000002,
Min = 0x00000003,
Max = 0x00000004,
};
enum class BufferBindingType : uint32_t {
Undefined = 0x00000000,
Uniform = 0x00000001,
Storage = 0x00000002,
ReadOnlyStorage = 0x00000003,
};
enum class BufferMapAsyncStatus : uint32_t {
Success = 0x00000000,
Error = 0x00000001,
Unknown = 0x00000002,
DeviceLost = 0x00000003,
DestroyedBeforeCallback = 0x00000004,
UnmappedBeforeCallback = 0x00000005,
};
enum class CompareFunction : uint32_t {
Undefined = 0x00000000,
Never = 0x00000001,
Less = 0x00000002,
LessEqual = 0x00000003,
Greater = 0x00000004,
GreaterEqual = 0x00000005,
Equal = 0x00000006,
NotEqual = 0x00000007,
Always = 0x00000008,
};
enum class CreatePipelineAsyncStatus : uint32_t {
Success = 0x00000000,
Error = 0x00000001,
DeviceLost = 0x00000002,
DeviceDestroyed = 0x00000003,
Unknown = 0x00000004,
};
enum class CullMode : uint32_t {
None = 0x00000000,
Front = 0x00000001,
Back = 0x00000002,
};
enum class ErrorFilter : uint32_t {
None = 0x00000000,
Validation = 0x00000001,
OutOfMemory = 0x00000002,
};
enum class ErrorType : uint32_t {
NoError = 0x00000000,
Validation = 0x00000001,
OutOfMemory = 0x00000002,
Unknown = 0x00000003,
DeviceLost = 0x00000004,
};
enum class FilterMode : uint32_t {
Nearest = 0x00000000,
Linear = 0x00000001,
};
enum class FrontFace : uint32_t {
CCW = 0x00000000,
CW = 0x00000001,
};
enum class IndexFormat : uint32_t {
Undefined = 0x00000000,
Uint16 = 0x00000001,
Uint32 = 0x00000002,
};
enum class InputStepMode : uint32_t {
Vertex = 0x00000000,
Instance = 0x00000001,
};
enum class LoadOp : uint32_t {
Clear = 0x00000000,
Load = 0x00000001,
};
enum class PipelineStatisticName : uint32_t {
VertexShaderInvocations = 0x00000000,
ClipperInvocations = 0x00000001,
ClipperPrimitivesOut = 0x00000002,
FragmentShaderInvocations = 0x00000003,
ComputeShaderInvocations = 0x00000004,
};
enum class PresentMode : uint32_t {
Immediate = 0x00000000,
Mailbox = 0x00000001,
Fifo = 0x00000002,
};
enum class PrimitiveTopology : uint32_t {
PointList = 0x00000000,
LineList = 0x00000001,
LineStrip = 0x00000002,
TriangleList = 0x00000003,
TriangleStrip = 0x00000004,
};
enum class QueryType : uint32_t {
Occlusion = 0x00000000,
PipelineStatistics = 0x00000001,
Timestamp = 0x00000002,
};
enum class QueueWorkDoneStatus : uint32_t {
Success = 0x00000000,
Error = 0x00000001,
Unknown = 0x00000002,
DeviceLost = 0x00000003,
};
enum class SType : uint32_t {
Invalid = 0x00000000,
SurfaceDescriptorFromMetalLayer = 0x00000001,
SurfaceDescriptorFromWindowsHWND = 0x00000002,
SurfaceDescriptorFromXlib = 0x00000003,
SurfaceDescriptorFromCanvasHTMLSelector = 0x00000004,
ShaderModuleSPIRVDescriptor = 0x00000005,
ShaderModuleWGSLDescriptor = 0x00000006,
PrimitiveDepthClampingState = 0x00000007,
};
enum class SamplerBindingType : uint32_t {
Undefined = 0x00000000,
Filtering = 0x00000001,
NonFiltering = 0x00000002,
Comparison = 0x00000003,
};
enum class StencilOperation : uint32_t {
Keep = 0x00000000,
Zero = 0x00000001,
Replace = 0x00000002,
Invert = 0x00000003,
IncrementClamp = 0x00000004,
DecrementClamp = 0x00000005,
IncrementWrap = 0x00000006,
DecrementWrap = 0x00000007,
};
enum class StorageTextureAccess : uint32_t {
Undefined = 0x00000000,
ReadOnly = 0x00000001,
WriteOnly = 0x00000002,
};
enum class StoreOp : uint32_t {
Store = 0x00000000,
Clear = 0x00000001,
};
enum class TextureAspect : uint32_t {
All = 0x00000000,
StencilOnly = 0x00000001,
DepthOnly = 0x00000002,
};
enum class TextureComponentType : uint32_t {
Float = 0x00000000,
Sint = 0x00000001,
Uint = 0x00000002,
DepthComparison = 0x00000003,
};
enum class TextureDimension : uint32_t {
e1D = 0x00000000,
e2D = 0x00000001,
e3D = 0x00000002,
};
enum class TextureFormat : uint32_t {
Undefined = 0x00000000,
R8Unorm = 0x00000001,
R8Snorm = 0x00000002,
R8Uint = 0x00000003,
R8Sint = 0x00000004,
R16Uint = 0x00000005,
R16Sint = 0x00000006,
R16Float = 0x00000007,
RG8Unorm = 0x00000008,
RG8Snorm = 0x00000009,
RG8Uint = 0x0000000A,
RG8Sint = 0x0000000B,
R32Float = 0x0000000C,
R32Uint = 0x0000000D,
R32Sint = 0x0000000E,
RG16Uint = 0x0000000F,
RG16Sint = 0x00000010,
RG16Float = 0x00000011,
RGBA8Unorm = 0x00000012,
RGBA8UnormSrgb = 0x00000013,
RGBA8Snorm = 0x00000014,
RGBA8Uint = 0x00000015,
RGBA8Sint = 0x00000016,
BGRA8Unorm = 0x00000017,
BGRA8UnormSrgb = 0x00000018,
RGB10A2Unorm = 0x00000019,
RG11B10Ufloat = 0x0000001A,
RGB9E5Ufloat = 0x0000001B,
RG32Float = 0x0000001C,
RG32Uint = 0x0000001D,
RG32Sint = 0x0000001E,
RGBA16Uint = 0x0000001F,
RGBA16Sint = 0x00000020,
RGBA16Float = 0x00000021,
RGBA32Float = 0x00000022,
RGBA32Uint = 0x00000023,
RGBA32Sint = 0x00000024,
Depth32Float = 0x00000025,
Depth24Plus = 0x00000026,
Stencil8 = 0x00000027,
Depth24PlusStencil8 = 0x00000028,
BC1RGBAUnorm = 0x00000029,
BC1RGBAUnormSrgb = 0x0000002A,
BC2RGBAUnorm = 0x0000002B,
BC2RGBAUnormSrgb = 0x0000002C,
BC3RGBAUnorm = 0x0000002D,
BC3RGBAUnormSrgb = 0x0000002E,
BC4RUnorm = 0x0000002F,
BC4RSnorm = 0x00000030,
BC5RGUnorm = 0x00000031,
BC5RGSnorm = 0x00000032,
BC6HRGBUfloat = 0x00000033,
BC6HRGBFloat = 0x00000034,
BC7RGBAUnorm = 0x00000035,
BC7RGBAUnormSrgb = 0x00000036,
};
enum class TextureSampleType : uint32_t {
Undefined = 0x00000000,
Float = 0x00000001,
UnfilterableFloat = 0x00000002,
Depth = 0x00000003,
Sint = 0x00000004,
Uint = 0x00000005,
};
enum class TextureViewDimension : uint32_t {
Undefined = 0x00000000,
e1D = 0x00000001,
e2D = 0x00000002,
e2DArray = 0x00000003,
Cube = 0x00000004,
CubeArray = 0x00000005,
e3D = 0x00000006,
};
enum class VertexFormat : uint32_t {
Undefined = 0x00000000,
Uint8x2 = 0x00000001,
Uint8x4 = 0x00000002,
Sint8x2 = 0x00000003,
Sint8x4 = 0x00000004,
Unorm8x2 = 0x00000005,
Unorm8x4 = 0x00000006,
Snorm8x2 = 0x00000007,
Snorm8x4 = 0x00000008,
Uint16x2 = 0x00000009,
Uint16x4 = 0x0000000A,
Sint16x2 = 0x0000000B,
Sint16x4 = 0x0000000C,
Unorm16x2 = 0x0000000D,
Unorm16x4 = 0x0000000E,
Snorm16x2 = 0x0000000F,
Snorm16x4 = 0x00000010,
Float16x2 = 0x00000011,
Float16x4 = 0x00000012,
Float32 = 0x00000013,
Float32x2 = 0x00000014,
Float32x3 = 0x00000015,
Float32x4 = 0x00000016,
Uint32 = 0x00000017,
Uint32x2 = 0x00000018,
Uint32x3 = 0x00000019,
Uint32x4 = 0x0000001A,
Sint32 = 0x0000001B,
Sint32x2 = 0x0000001C,
Sint32x3 = 0x0000001D,
Sint32x4 = 0x0000001E,
};
enum class BufferUsage : uint32_t {
None = 0x00000000,
MapRead = 0x00000001,
MapWrite = 0x00000002,
CopySrc = 0x00000004,
CopyDst = 0x00000008,
Index = 0x00000010,
Vertex = 0x00000020,
Uniform = 0x00000040,
Storage = 0x00000080,
Indirect = 0x00000100,
QueryResolve = 0x00000200,
};
enum class ColorWriteMask : uint32_t {
None = 0x00000000,
Red = 0x00000001,
Green = 0x00000002,
Blue = 0x00000004,
Alpha = 0x00000008,
All = 0x0000000F,
};
enum class MapMode : uint32_t {
None = 0x00000000,
Read = 0x00000001,
Write = 0x00000002,
};
enum class ShaderStage : uint32_t {
None = 0x00000000,
Vertex = 0x00000001,
Fragment = 0x00000002,
Compute = 0x00000004,
};
enum class TextureUsage : uint32_t {
None = 0x00000000,
CopySrc = 0x00000001,
CopyDst = 0x00000002,
Sampled = 0x00000004,
Storage = 0x00000008,
OutputAttachment = 0x00000010,
RenderAttachment = 0x00000010,
};
template<>
struct IsDawnBitmask<BufferUsage> {
static constexpr bool enable = true;
};
template<>
struct IsDawnBitmask<ColorWriteMask> {
static constexpr bool enable = true;
};
template<>
struct IsDawnBitmask<MapMode> {
static constexpr bool enable = true;
};
template<>
struct IsDawnBitmask<ShaderStage> {
static constexpr bool enable = true;
};
template<>
struct IsDawnBitmask<TextureUsage> {
static constexpr bool enable = true;
};
using Proc = WGPUProc;
using BufferMapCallback = WGPUBufferMapCallback;
using CreateComputePipelineAsyncCallback = WGPUCreateComputePipelineAsyncCallback;
using CreateRenderPipelineAsyncCallback = WGPUCreateRenderPipelineAsyncCallback;
using DeviceLostCallback = WGPUDeviceLostCallback;
using ErrorCallback = WGPUErrorCallback;
using QueueWorkDoneCallback = WGPUQueueWorkDoneCallback;
class BindGroup;
class BindGroupLayout;
class Buffer;
class CommandBuffer;
class CommandEncoder;
class ComputePassEncoder;
class ComputePipeline;
class Device;
class Instance;
class PipelineLayout;
class QuerySet;
class Queue;
class RenderBundle;
class RenderBundleEncoder;
class RenderPassEncoder;
class RenderPipeline;
class Sampler;
class ShaderModule;
class Surface;
class SwapChain;
class Texture;
class TextureView;
struct AdapterProperties;
struct BindGroupEntry;
struct BlendComponent;
struct BufferBindingLayout;
struct BufferDescriptor;
struct Color;
struct CommandBufferDescriptor;
struct CommandEncoderDescriptor;
struct ComputePassDescriptor;
struct Extent3D;
struct InstanceDescriptor;
struct MultisampleState;
struct Origin3D;
struct PipelineLayoutDescriptor;
struct PrimitiveDepthClampingState;
struct PrimitiveState;
struct ProgrammableStageDescriptor;
struct QuerySetDescriptor;
struct RenderBundleDescriptor;
struct RenderBundleEncoderDescriptor;
struct RenderPassDepthStencilAttachment;
struct SamplerBindingLayout;
struct SamplerDescriptor;
struct ShaderModuleDescriptor;
struct ShaderModuleSPIRVDescriptor;
struct ShaderModuleWGSLDescriptor;
struct StencilFaceState;
struct StorageTextureBindingLayout;
struct SurfaceDescriptor;
struct SurfaceDescriptorFromCanvasHTMLSelector;
struct SurfaceDescriptorFromMetalLayer;
struct SurfaceDescriptorFromWindowsHWND;
struct SurfaceDescriptorFromXlib;
struct SwapChainDescriptor;
struct TextureBindingLayout;
struct TextureDataLayout;
struct TextureViewDescriptor;
struct VertexAttribute;
struct BindGroupDescriptor;
struct BindGroupLayoutEntry;
struct BlendState;
struct ComputePipelineDescriptor;
struct DepthStencilState;
struct ImageCopyBuffer;
struct ImageCopyTexture;
struct RenderPassColorAttachment;
struct TextureDescriptor;
struct VertexBufferLayout;
struct BindGroupLayoutDescriptor;
struct ColorTargetState;
struct RenderPassDescriptor;
struct VertexState;
struct FragmentState;
struct RenderPipelineDescriptor2;
template<typename Derived, typename CType>
class ObjectBase {
public:
ObjectBase() = default;
ObjectBase(CType handle): mHandle(handle) {
if (mHandle) Derived::WGPUReference(mHandle);
}
~ObjectBase() {
if (mHandle) Derived::WGPURelease(mHandle);
}
ObjectBase(ObjectBase const& other)
: ObjectBase(other.Get()) {
}
Derived& operator=(ObjectBase const& other) {
if (&other != this) {
if (mHandle) Derived::WGPURelease(mHandle);
mHandle = other.mHandle;
if (mHandle) Derived::WGPUReference(mHandle);
}
return static_cast<Derived&>(*this);
}
ObjectBase(ObjectBase&& other) {
mHandle = other.mHandle;
other.mHandle = 0;
}
Derived& operator=(ObjectBase&& other) {
if (&other != this) {
if (mHandle) Derived::WGPURelease(mHandle);
mHandle = other.mHandle;
other.mHandle = 0;
}
return static_cast<Derived&>(*this);
}
ObjectBase(std::nullptr_t) {}
Derived& operator=(std::nullptr_t) {
if (mHandle != nullptr) {
Derived::WGPURelease(mHandle);
mHandle = nullptr;
}
return static_cast<Derived&>(*this);
}
bool operator==(std::nullptr_t) const {
return mHandle == nullptr;
}
bool operator!=(std::nullptr_t) const {
return mHandle != nullptr;
}
explicit operator bool() const {
return mHandle != nullptr;
}
CType Get() const {
return mHandle;
}
CType Release() {
CType result = mHandle;
mHandle = 0;
return result;
}
static Derived Acquire(CType handle) {
Derived result;
result.mHandle = handle;
return result;
}
protected:
CType mHandle = nullptr;
};
class BindGroup : public ObjectBase<BindGroup, WGPUBindGroup> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<BindGroup, WGPUBindGroup>;
static void WGPUReference(WGPUBindGroup handle);
static void WGPURelease(WGPUBindGroup handle);
};
class BindGroupLayout : public ObjectBase<BindGroupLayout, WGPUBindGroupLayout> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<BindGroupLayout, WGPUBindGroupLayout>;
static void WGPUReference(WGPUBindGroupLayout handle);
static void WGPURelease(WGPUBindGroupLayout handle);
};
class Buffer : public ObjectBase<Buffer, WGPUBuffer> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void Destroy() const;
void const * GetConstMappedRange(size_t offset = 0, size_t size = 0) const;
void * GetMappedRange(size_t offset = 0, size_t size = 0) const;
void MapAsync(MapMode mode, size_t offset, size_t size, BufferMapCallback callback, void * userdata) const;
void Unmap() const;
private:
friend ObjectBase<Buffer, WGPUBuffer>;
static void WGPUReference(WGPUBuffer handle);
static void WGPURelease(WGPUBuffer handle);
};
class CommandBuffer : public ObjectBase<CommandBuffer, WGPUCommandBuffer> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<CommandBuffer, WGPUCommandBuffer>;
static void WGPUReference(WGPUCommandBuffer handle);
static void WGPURelease(WGPUCommandBuffer handle);
};
class CommandEncoder : public ObjectBase<CommandEncoder, WGPUCommandEncoder> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
ComputePassEncoder BeginComputePass(ComputePassDescriptor const * descriptor = nullptr) const;
RenderPassEncoder BeginRenderPass(RenderPassDescriptor const * descriptor) const;
void CopyBufferToBuffer(Buffer const& source, uint64_t sourceOffset, Buffer const& destination, uint64_t destinationOffset, uint64_t size) const;
void CopyBufferToTexture(ImageCopyBuffer const * source, ImageCopyTexture const * destination, Extent3D const * copySize) const;
void CopyTextureToBuffer(ImageCopyTexture const * source, ImageCopyBuffer const * destination, Extent3D const * copySize) const;
void CopyTextureToTexture(ImageCopyTexture const * source, ImageCopyTexture const * destination, Extent3D const * copySize) const;
CommandBuffer Finish(CommandBufferDescriptor const * descriptor = nullptr) const;
void InsertDebugMarker(char const * markerLabel) const;
void PopDebugGroup() const;
void PushDebugGroup(char const * groupLabel) const;
void ResolveQuerySet(QuerySet const& querySet, uint32_t firstQuery, uint32_t queryCount, Buffer const& destination, uint64_t destinationOffset) const;
void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
private:
friend ObjectBase<CommandEncoder, WGPUCommandEncoder>;
static void WGPUReference(WGPUCommandEncoder handle);
static void WGPURelease(WGPUCommandEncoder handle);
};
class ComputePassEncoder : public ObjectBase<ComputePassEncoder, WGPUComputePassEncoder> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void Dispatch(uint32_t x, uint32_t y = 1, uint32_t z = 1) const;
void DispatchIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
void EndPass() const;
void InsertDebugMarker(char const * markerLabel) const;
void PopDebugGroup() const;
void PushDebugGroup(char const * groupLabel) const;
void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
void SetPipeline(ComputePipeline const& pipeline) const;
void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
private:
friend ObjectBase<ComputePassEncoder, WGPUComputePassEncoder>;
static void WGPUReference(WGPUComputePassEncoder handle);
static void WGPURelease(WGPUComputePassEncoder handle);
};
class ComputePipeline : public ObjectBase<ComputePipeline, WGPUComputePipeline> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
BindGroupLayout GetBindGroupLayout(uint32_t groupIndex) const;
private:
friend ObjectBase<ComputePipeline, WGPUComputePipeline>;
static void WGPUReference(WGPUComputePipeline handle);
static void WGPURelease(WGPUComputePipeline handle);
};
class Device : public ObjectBase<Device, WGPUDevice> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
BindGroup CreateBindGroup(BindGroupDescriptor const * descriptor) const;
BindGroupLayout CreateBindGroupLayout(BindGroupLayoutDescriptor const * descriptor) const;
Buffer CreateBuffer(BufferDescriptor const * descriptor) const;
CommandEncoder CreateCommandEncoder(CommandEncoderDescriptor const * descriptor = nullptr) const;
ComputePipeline CreateComputePipeline(ComputePipelineDescriptor const * descriptor) const;
void CreateComputePipelineAsync(ComputePipelineDescriptor const * descriptor, CreateComputePipelineAsyncCallback callback, void * userdata) const;
PipelineLayout CreatePipelineLayout(PipelineLayoutDescriptor const * descriptor) const;
QuerySet CreateQuerySet(QuerySetDescriptor const * descriptor) const;
RenderBundleEncoder CreateRenderBundleEncoder(RenderBundleEncoderDescriptor const * descriptor) const;
RenderPipeline CreateRenderPipeline2(RenderPipelineDescriptor2 const * descriptor) const;
void CreateRenderPipelineAsync(RenderPipelineDescriptor2 const * descriptor, CreateRenderPipelineAsyncCallback callback, void * userdata) const;
Sampler CreateSampler(SamplerDescriptor const * descriptor = nullptr) const;
ShaderModule CreateShaderModule(ShaderModuleDescriptor const * descriptor) const;
SwapChain CreateSwapChain(Surface const& surface, SwapChainDescriptor const * descriptor) const;
Texture CreateTexture(TextureDescriptor const * descriptor) const;
Queue GetQueue() const;
bool PopErrorScope(ErrorCallback callback, void * userdata) const;
void PushErrorScope(ErrorFilter filter) const;
void SetDeviceLostCallback(DeviceLostCallback callback, void * userdata) const;
void SetUncapturedErrorCallback(ErrorCallback callback, void * userdata) const;
private:
friend ObjectBase<Device, WGPUDevice>;
static void WGPUReference(WGPUDevice handle);
static void WGPURelease(WGPUDevice handle);
};
class Instance : public ObjectBase<Instance, WGPUInstance> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
Surface CreateSurface(SurfaceDescriptor const * descriptor) const;
private:
friend ObjectBase<Instance, WGPUInstance>;
static void WGPUReference(WGPUInstance handle);
static void WGPURelease(WGPUInstance handle);
};
class PipelineLayout : public ObjectBase<PipelineLayout, WGPUPipelineLayout> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<PipelineLayout, WGPUPipelineLayout>;
static void WGPUReference(WGPUPipelineLayout handle);
static void WGPURelease(WGPUPipelineLayout handle);
};
class QuerySet : public ObjectBase<QuerySet, WGPUQuerySet> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void Destroy() const;
private:
friend ObjectBase<QuerySet, WGPUQuerySet>;
static void WGPUReference(WGPUQuerySet handle);
static void WGPURelease(WGPUQuerySet handle);
};
class Queue : public ObjectBase<Queue, WGPUQueue> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void OnSubmittedWorkDone(uint64_t signalValue, QueueWorkDoneCallback callback, void * userdata) const;
void Submit(uint32_t commandCount, CommandBuffer const * commands) const;
void WriteBuffer(Buffer const& buffer, uint64_t bufferOffset, void const * data, size_t size) const;
void WriteTexture(ImageCopyTexture const * destination, void const * data, size_t dataSize, TextureDataLayout const * dataLayout, Extent3D const * writeSize) const;
private:
friend ObjectBase<Queue, WGPUQueue>;
static void WGPUReference(WGPUQueue handle);
static void WGPURelease(WGPUQueue handle);
};
class RenderBundle : public ObjectBase<RenderBundle, WGPURenderBundle> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<RenderBundle, WGPURenderBundle>;
static void WGPUReference(WGPURenderBundle handle);
static void WGPURelease(WGPURenderBundle handle);
};
class RenderBundleEncoder : public ObjectBase<RenderBundleEncoder, WGPURenderBundleEncoder> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t firstVertex = 0, uint32_t firstInstance = 0) const;
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t firstIndex = 0, int32_t baseVertex = 0, uint32_t firstInstance = 0) const;
void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
RenderBundle Finish(RenderBundleDescriptor const * descriptor = nullptr) const;
void InsertDebugMarker(char const * markerLabel) const;
void PopDebugGroup() const;
void PushDebugGroup(char const * groupLabel) const;
void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
void SetPipeline(RenderPipeline const& pipeline) const;
void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
private:
friend ObjectBase<RenderBundleEncoder, WGPURenderBundleEncoder>;
static void WGPUReference(WGPURenderBundleEncoder handle);
static void WGPURelease(WGPURenderBundleEncoder handle);
};
class RenderPassEncoder : public ObjectBase<RenderPassEncoder, WGPURenderPassEncoder> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
void BeginOcclusionQuery(uint32_t queryIndex) const;
void Draw(uint32_t vertexCount, uint32_t instanceCount = 1, uint32_t firstVertex = 0, uint32_t firstInstance = 0) const;
void DrawIndexed(uint32_t indexCount, uint32_t instanceCount = 1, uint32_t firstIndex = 0, int32_t baseVertex = 0, uint32_t firstInstance = 0) const;
void DrawIndexedIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
void DrawIndirect(Buffer const& indirectBuffer, uint64_t indirectOffset) const;
void EndOcclusionQuery() const;
void EndPass() const;
void ExecuteBundles(uint32_t bundlesCount, RenderBundle const * bundles) const;
void InsertDebugMarker(char const * markerLabel) const;
void PopDebugGroup() const;
void PushDebugGroup(char const * groupLabel) const;
void SetBindGroup(uint32_t groupIndex, BindGroup const& group, uint32_t dynamicOffsetCount = 0, uint32_t const * dynamicOffsets = nullptr) const;
void SetBlendConstant(Color const * color) const;
void SetIndexBuffer(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
void SetIndexBufferWithFormat(Buffer const& buffer, IndexFormat format, uint64_t offset = 0, uint64_t size = 0) const;
void SetPipeline(RenderPipeline const& pipeline) const;
void SetScissorRect(uint32_t x, uint32_t y, uint32_t width, uint32_t height) const;
void SetStencilReference(uint32_t reference) const;
void SetVertexBuffer(uint32_t slot, Buffer const& buffer, uint64_t offset = 0, uint64_t size = 0) const;
void SetViewport(float x, float y, float width, float height, float minDepth, float maxDepth) const;
void WriteTimestamp(QuerySet const& querySet, uint32_t queryIndex) const;
private:
friend ObjectBase<RenderPassEncoder, WGPURenderPassEncoder>;
static void WGPUReference(WGPURenderPassEncoder handle);
static void WGPURelease(WGPURenderPassEncoder handle);
};
class RenderPipeline : public ObjectBase<RenderPipeline, WGPURenderPipeline> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
BindGroupLayout GetBindGroupLayout(uint32_t groupIndex) const;
private:
friend ObjectBase<RenderPipeline, WGPURenderPipeline>;
static void WGPUReference(WGPURenderPipeline handle);
static void WGPURelease(WGPURenderPipeline handle);
};
class Sampler : public ObjectBase<Sampler, WGPUSampler> {
public:
using ObjectBase::ObjectBase;
using ObjectBase::operator=;
private:
friend ObjectBase<Sampler, WGPUSampler>;
static void WGPUReference(WGPUSampler handle);
static void WGPURelease(WGPUSampler handle);
};
class ShaderModule : public ObjectBase<ShaderModule, WGPUShaderModule> {
public:
using ObjectBase::ObjectBase;