forked from juj/wasm_webgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib_webgpu.h
2992 lines (2661 loc) · 110 KB
/
lib_webgpu.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
#pragma once
#ifdef __EMSCRIPTEN__
#include <emscripten/html5.h>
#endif
#ifdef __clang__
// The internal struct member offset layout is extremely important when marshalling structs to JS,
// so never let the compiler add any padding (we manually & explicitly make the fields the right size)
#pragma clang diagnostic push
#elif defined(_MSC_VER)
#pragma warning(push)
#endif
#ifdef __clang__
#pragma clang diagnostic error "-Wpadded"
#endif
#ifdef _MSC_VER
#pragma warning(disable : 4200) // Disable MSVC complaining about zero-sized arrays for copy/move assignment in WGpuCompilationInfo
#endif
#include "lib_webgpu_fwd.h"
// Some WebGPU JS API functions have default parameters so that the user can omit passing them.
// These defaults are carried through to these headers. However C does not support default parameters to
// functions, so enable the default parameters only when called from C++ code.
#ifdef __cplusplus
#define _WGPU_DEFAULT_VALUE(x) = x
#else
#define _WGPU_DEFAULT_VALUE(x)
#endif
#ifdef __GNUC__
#define WGPU_NAN __builtin_nan("")
#define WGPU_INFINITY __builtin_inf()
#else
#include <math.h>
#define WGPU_NAN ((double)NAN)
#define WGPU_INFINITY ((double)INFINITY)
#endif
#ifndef __EMSCRIPTEN__
#define EM_BOOL int
#define EM_TRUE 1
#define EM_FALSE 0
#endif
#ifdef __cplusplus
extern "C" {
#endif
// Returns the number of WebGPU objects referenced by the WebGPU JS library.
uint32_t wgpu_get_num_live_objects(void);
// Calls .destroy() on the given WebGPU object (if it has such a member function) and releases the JS side reference to it. Use this function
// to release memory for all types of WebGPU objects after you are done with them.
// Note that deleting a GPUTexture will also delete all GPUTextureViews that have been created from it.
// Similar to free(), calling wgpu_object_destroy() on null, or an object that has already been destroyed before is safe, and no-op. (so no need to
// do excess "if (wgpuObject) wgpu_object_destroy(wgpuObject);")
void wgpu_object_destroy(WGpuObjectBase wgpuObject);
// Deinitializes all initialized WebGPU objects.
void wgpu_destroy_all_objects(void);
// Acquires a canvas context from a canvas by calling canvas.getCanvasContext().
#ifdef __EMSCRIPTEN__
WGpuCanvasContext wgpu_canvas_get_webgpu_context(const char *canvasSelector NOTNULL);
#elif defined (_WIN32)
WGpuCanvasContext wgpu_canvas_get_webgpu_context(void *hwnd);
#else
#error Targeting currently unsupported platform! (no declaration for wgpu_canvas_get_webgpu_context())
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// The ordering and structure of this remainder of this file follows the official WebGPU WebIDL definitions at https://www.w3.org/TR/webgpu/#idl-index
// This is so that when the official IDL is modified, the modifications can be easily diffed here for updates.
/*
interface mixin GPUObjectBase {
attribute USVString label;
};
*/
// Returns true if the given handle references a valid WebGPU object
EM_BOOL wgpu_is_valid_object(WGpuObjectBase obj);
// Set a human-readable label for the given WebGPU object. Pass an empty string "" to clear a label.
void wgpu_object_set_label(WGpuObjectBase obj, const char *label NOTNULL);
// Gets the human-readable label of a WebGPU object. If dstLabelSize is too short to
// contain the label string, then the label is truncated.
// dstLabelSize: length of dstLabel array in bytes.
// Returns the number of bytes written (excluding null byte at end).
int wgpu_object_get_label(WGpuObjectBase obj, char *dstLabel NOTNULL, uint32_t dstLabelSize);
/*
dictionary GPUObjectDescriptorBase {
USVString label;
};
*/
#define WGPU_OBJECT_LABEL_MAX_LENGTH 256
typedef struct WGpuObjectDescriptorBase // TODO: Currently unused. Actually use this, or remove
{
char label[WGPU_OBJECT_LABEL_MAX_LENGTH];
} WGpuObjectDescriptorBase;
/*
dictionary GPUExtent3DDict {
required GPUIntegerCoordinate width;
GPUIntegerCoordinate height = 1;
GPUIntegerCoordinate depthOrArrayLayers = 1;
};
typedef (sequence<GPUIntegerCoordinate> or GPUExtent3DDict) GPUExtent3D;
*/
typedef struct WGpuExtent3D
{
int width;
int height; // = 1;
int depthOrArrayLayers; // = 1;
} WGpuExtent3D;
extern const WGpuExtent3D WGPU_EXTENT_3D_DEFAULT_INITIALIZER;
/*
[Exposed=(Window, DedicatedWorker)]
interface GPUSupportedLimits {
readonly attribute unsigned long maxTextureDimension1D;
readonly attribute unsigned long maxTextureDimension2D;
readonly attribute unsigned long maxTextureDimension3D;
readonly attribute unsigned long maxTextureArrayLayers;
readonly attribute unsigned long maxBindGroups;
readonly attribute unsigned long maxBindGroupsPlusVertexBuffers;
readonly attribute unsigned long maxBindingsPerBindGroup;
readonly attribute unsigned long maxDynamicUniformBuffersPerPipelineLayout;
readonly attribute unsigned long maxDynamicStorageBuffersPerPipelineLayout;
readonly attribute unsigned long maxSampledTexturesPerShaderStage;
readonly attribute unsigned long maxSamplersPerShaderStage;
readonly attribute unsigned long maxStorageBuffersPerShaderStage;
readonly attribute unsigned long maxStorageTexturesPerShaderStage;
readonly attribute unsigned long maxUniformBuffersPerShaderStage;
readonly attribute unsigned long long maxUniformBufferBindingSize;
readonly attribute unsigned long long maxStorageBufferBindingSize;
readonly attribute unsigned long minUniformBufferOffsetAlignment;
readonly attribute unsigned long minStorageBufferOffsetAlignment;
readonly attribute unsigned long maxVertexBuffers;
readonly attribute unsigned long long maxBufferSize;
readonly attribute unsigned long maxVertexAttributes;
readonly attribute unsigned long maxVertexBufferArrayStride;
readonly attribute unsigned long maxInterStageShaderComponents;
readonly attribute unsigned long maxInterStageShaderVariables;
readonly attribute unsigned long maxColorAttachments;
readonly attribute unsigned long maxColorAttachmentBytesPerSample;
readonly attribute unsigned long maxComputeWorkgroupStorageSize;
readonly attribute unsigned long maxComputeInvocationsPerWorkgroup;
readonly attribute unsigned long maxComputeWorkgroupSizeX;
readonly attribute unsigned long maxComputeWorkgroupSizeY;
readonly attribute unsigned long maxComputeWorkgroupSizeZ;
readonly attribute unsigned long maxComputeWorkgroupsPerDimension;
};
*/
typedef struct WGpuSupportedLimits
{
// See the table in https://www.w3.org/TR/webgpu/#limits for the minimum/maximum
// default values for these limits.
// 64-bit fields must be present first before the 32-bit fields in this struct.
uint64_t maxUniformBufferBindingSize; // required >= 16384
uint64_t maxStorageBufferBindingSize; // required >= 128*1024*1024 (128MB)
uint64_t maxBufferSize; // required >= 256*1024*1024 (256MB)
uint32_t maxTextureDimension1D; // required >= 8192
uint32_t maxTextureDimension2D; // required >= 8192
uint32_t maxTextureDimension3D; // required >= 2048
uint32_t maxTextureArrayLayers; // required >= 2048
uint32_t maxBindGroups; // required >= 4
uint32_t maxBindGroupsPlusVertexBuffers; // required >= 24
uint32_t maxBindingsPerBindGroup; // required >= 640
uint32_t maxDynamicUniformBuffersPerPipelineLayout; // required >= 8
uint32_t maxDynamicStorageBuffersPerPipelineLayout; // required >= 4
uint32_t maxSampledTexturesPerShaderStage; // required >= 16
uint32_t maxSamplersPerShaderStage; // required >= 16
uint32_t maxStorageBuffersPerShaderStage; // required >= 8
uint32_t maxStorageTexturesPerShaderStage; // required >= 8
uint32_t maxUniformBuffersPerShaderStage; // required >= 12
uint32_t minUniformBufferOffsetAlignment; // required >= 256 bytes
uint32_t minStorageBufferOffsetAlignment; // required >= 256 bytes
uint32_t maxVertexBuffers; // required >= 8
uint32_t maxVertexAttributes; // required >= 16
uint32_t maxVertexBufferArrayStride; // required >= 2048
uint32_t maxInterStageShaderComponents; // required >= 60
uint32_t maxInterStageShaderVariables; // required >= 16
uint32_t maxColorAttachments; // required >= 8
uint32_t maxColorAttachmentBytesPerSample; // required >= 32
uint32_t maxComputeWorkgroupStorageSize; // required >= 16384 bytes
uint32_t maxComputeInvocationsPerWorkgroup; // required >= 256
uint32_t maxComputeWorkgroupSizeX; // required >= 256
uint32_t maxComputeWorkgroupSizeY; // required >= 256
uint32_t maxComputeWorkgroupSizeZ; // required >= 64
} WGpuSupportedLimits;
/*
[Exposed=(Window, DedicatedWorker)]
interface GPUSupportedFeatures {
readonly setlike<DOMString>;
};
*/
/*
enum GPUFeatureName {
"depth-clip-control",
"depth32float-stencil8",
"texture-compression-bc",
"texture-compression-etc2",
"texture-compression-astc",
"timestamp-query",
"indirect-first-instance",
"shader-f16",
"rg11b10ufloat-renderable",
"bgra8unorm-storage",
"float32-filterable",
"clip-distances",
};
*/
typedef int WGPU_FEATURES_BITFIELD;
#define WGPU_FEATURE_DEPTH_CLIP_CONTROL 0x01
#define WGPU_FEATURE_DEPTH32FLOAT_STENCIL8 0x02
#define WGPU_FEATURE_TEXTURE_COMPRESSION_BC 0x04
#define WGPU_FEATURE_TEXTURE_COMPRESSION_ETC2 0x08
#define WGPU_FEATURE_TEXTURE_COMPRESSION_ASTC 0x10
#define WGPU_FEATURE_TIMESTAMP_QUERY 0x20
#define WGPU_FEATURE_INDIRECT_FIRST_INSTANCE 0x40
#define WGPU_FEATURE_SHADER_F16 0x80
#define WGPU_FEATURE_RG11B10UFLOAT_RENDERABLE 0x100
#define WGPU_FEATURE_BGRA8UNORM_STORAGE 0x200
#define WGPU_FEATURE_FLOAT32_FILTERABLE 0x400
#define WGPU_FEATURE_CLIP_DISTANCES 0x800
/*
// WebGPU reuses the color space enum from the HTML Canvas specification:
https://html.spec.whatwg.org/multipage/canvas.html#predefinedcolorspace
Because of that reason, it is prefixed here with HTML_ as opposed to WGPU_.
enum PredefinedColorSpace {
"srgb",
"display-p3"
};
*/
typedef int HTML_PREDEFINED_COLOR_SPACE;
#define HTML_PREDEFINED_COLOR_SPACE_INVALID 0
#define HTML_PREDEFINED_COLOR_SPACE_SRGB 1
#define HTML_PREDEFINED_COLOR_SPACE_DISPLAY_P3 2
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUAdapterInfo {
readonly attribute DOMString vendor;
readonly attribute DOMString architecture;
readonly attribute DOMString device;
readonly attribute DOMString description;
};
*/
typedef struct WGpuAdapterInfo
{
char vendor[512];
char architecture[512];
char device[512];
char description[512];
} WGpuAdapterInfo;
/*
interface mixin NavigatorGPU {
[SameObject, SecureContext] readonly attribute GPU gpu;
};
Navigator includes NavigatorGPU;
WorkerNavigator includes NavigatorGPU;
[Exposed=(Window, DedicatedWorker), SecureContext]
interface WGSLLanguageFeatures {
readonly setlike<DOMString>;
};
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPU {
Promise<GPUAdapter?> requestAdapter(optional GPURequestAdapterOptions options = {});
GPUTextureFormat getPreferredCanvasFormat();
[SameObject] readonly attribute WGSLLanguageFeatures wgslLanguageFeatures;
};
*/
// Returns true if the browser is advertising to be WebGPU-aware. This means that the browser in question is shipping with WebGPU available, but does not
// necessarily mean that there would exist any WebGPU adapters or devices that are supported. The only way to know if WebGPU is actually possible will
// be to try to request and adapter and then a device.
EM_BOOL navigator_gpu_available(void);
// This function can be used to remove access to WebGPU API on the current JS page. This can be useful for debugging or sandboxing purposes. Note that
// if the page has already initialized a WebGPU context, then the context is not affected. Amounts to a 'delete navigator.gpu' operation.
// After calling this function navigator_gpu_available() will return false.
void navigator_delete_webgpu_api_access(void);
// Returns the number of currently asyncified synchronous operations that are pending.
// Call this function in requestAnimationFrame() handlers to detect whether a previous asyncified operation is pending, to detect
// if e.g. a previous call to wgpu_buffer_map_sync() has not yet resolved, and skip rendering until the previous call resolves.
// See buffer_map_sync.c for an example.
int wgpu_sync_operations_pending(void);
typedef void (*WGpuRequestAdapterCallback)(WGpuAdapter adapter, void *userData);
// Requests an adapter from the user agent. The user agent chooses whether to return an adapter, and, if so, chooses according to the provided options.
// If WebGPU is not supported by the browser, returns EM_FALSE.
// Otherwise returns EM_TRUE, and the callback will resolve later with an ID handle to the adapter.
// The callback will also be resolved in the event of an initialization failure, but the ID handle
// passed to the callback will then be zero.
// options: may be null to request an adapter without specific options.
// Note: If the current browser is not aware of the WebGPU API, then this function will by design abort execution
// (fail on assert, and throw a JS exception in release builds). To gracefully detect whether the current browser is new enough to be WebGPU API aware,
// call the function navigator_gpu_available() to check.
EM_BOOL navigator_gpu_request_adapter_async(const WGpuRequestAdapterOptions *options NOTNULL, WGpuRequestAdapterCallback adapterCallback, void *userData);
// Requests a WebGPU adapter synchronously. Requires building with -sASYNCIFY=1 linker flag to work.
// options: may be null to request an adapter without specific options.
WGpuAdapter navigator_gpu_request_adapter_sync(const WGpuRequestAdapterOptions *options NOTNULL);
// Like above, but tiny code size without options.
void navigator_gpu_request_adapter_async_simple(WGpuRequestAdapterCallback adapterCallback);
WGpuAdapter navigator_gpu_request_adapter_sync_simple(void);
WGPU_TEXTURE_FORMAT navigator_gpu_get_preferred_canvas_format(void);
// Returns an array of strings representing supported WGSL language features. The array of strings is terminated by a null string.
// If you do not need to enumerate though all supported language features, you can use the simpler navigator_gpu_is_wgsl_language_feature_supported()
// function.
const char * const * navigator_gpu_get_wgsl_language_features(void);
// Tests if the given WGSL language feature is supported. (the given feature string exists in navigator.gpu.wgslLanguageFeatures set).
// If this information is needed often (e.g. in an inner loop of a shader cross-compiler), then it is recommended to cache the return value,
// since the supported WGSL language features will not change during page lifetime.
EM_BOOL navigator_gpu_is_wgsl_language_feature_supported(const char *feature);
/*
dictionary GPURequestAdapterOptions {
GPUPowerPreference powerPreference;
boolean forceFallbackAdapter = false;
};
*/
typedef struct WGpuRequestAdapterOptions
{
// Optionally provides a hint indicating what class of adapter should be selected from the system’s available adapters.
// The value of this hint may influence which adapter is chosen, but it must not influence whether an adapter is returned or not.
// Note: The primary utility of this hint is to influence which GPU is used in a multi-GPU system. For instance, some laptops
// have a low-power integrated GPU and a high-performance discrete GPU.
// Note: Depending on the exact hardware configuration, such as battery status and attached displays or removable GPUs, the user
// agent may select different adapters given the same power preference. Typically, given the same hardware configuration and
// state and powerPreference, the user agent is likely to select the same adapter.
WGPU_POWER_PREFERENCE powerPreference;
EM_BOOL forceFallbackAdapter;
} WGpuRequestAdapterOptions;
extern const WGpuRequestAdapterOptions WGPU_REQUEST_ADAPTER_OPTIONS_DEFAULT_INITIALIZER;
/*
enum GPUPowerPreference {
"low-power",
"high-performance"
};
*/
typedef int WGPU_POWER_PREFERENCE;
#define WGPU_POWER_PREFERENCE_INVALID 0
#define WGPU_POWER_PREFERENCE_LOW_POWER 1
#define WGPU_POWER_PREFERENCE_HIGH_PERFORMANCE 2
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUAdapter {
[SameObject] readonly attribute GPUSupportedFeatures features;
[SameObject] readonly attribute WGpuSupportedLimits limits;
[SameObject] readonly attribute GPUAdapterInfo info;
readonly attribute boolean isFallbackAdapter;
Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
};
*/
typedef WGpuObjectBase WGpuAdapter;
// Returns true if the given handle references a valid GPUAdapter.
EM_BOOL wgpu_is_adapter(WGpuObjectBase object);
// Returns a bitfield of all the supported features on this adapter.
WGPU_FEATURES_BITFIELD wgpu_adapter_or_device_get_features(WGpuAdapter adapter);
#define wgpu_adapter_get_features wgpu_adapter_or_device_get_features
// Returns true if the given feature is supported by this adapter.
EM_BOOL wgpu_adapter_or_device_supports_feature(WGpuAdapter adapter, WGPU_FEATURES_BITFIELD feature);
#define wgpu_adapter_supports_feature wgpu_adapter_or_device_supports_feature
// Populates the adapter.limits field of the given adapter to the provided structure.
void wgpu_adapter_or_device_get_limits(WGpuAdapter adapter, WGpuSupportedLimits *limits NOTNULL);
#define wgpu_adapter_get_limits wgpu_adapter_or_device_get_limits
// Returns the WebGPU adapter 'info' field.
void wgpu_adapter_get_info(WGpuAdapter adapter, WGpuAdapterInfo *adapterInfo NOTNULL);
EM_BOOL wgpu_adapter_is_fallback_adapter(WGpuAdapter adapter);
typedef void (*WGpuRequestDeviceCallback)(WGpuDevice device, void *userData);
void wgpu_adapter_request_device_async(WGpuAdapter adapter, const WGpuDeviceDescriptor *descriptor NOTNULL, WGpuRequestDeviceCallback deviceCallback, void *userData);
// Requests a WebGPU device synchronously. Requires building with -sASYNCIFY=1 linker flag to work.
WGpuDevice wgpu_adapter_request_device_sync(WGpuAdapter adapter, const WGpuDeviceDescriptor *descriptor NOTNULL);
// Like above, but tiny code size without options.
void wgpu_adapter_request_device_async_simple(WGpuAdapter adapter, WGpuRequestDeviceCallback deviceCallback);
WGpuDevice wgpu_adapter_request_device_sync_simple(WGpuAdapter adapter);
/*
dictionary GPUQueueDescriptor : GPUObjectDescriptorBase {
};
*/
typedef struct WGpuQueueDescriptor
{
const char *label;
} WGpuQueueDescriptor;
/*
dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase {
sequence<GPUFeatureName> requiredFeatures = [];
record<DOMString, GPUSize64> requiredLimits = {};
GPUQueueDescriptor defaultQueue = {};
};
*/
typedef struct WGpuDeviceDescriptor
{
WGPU_FEATURES_BITFIELD requiredFeatures;
uint32_t _explicitPaddingFor8BytesAlignedSize; // alignof(WGpuSupportedLimits) is 64-bit, hence explicitly show a padding here.
WGpuSupportedLimits requiredLimits;
WGpuQueueDescriptor defaultQueue;
uint32_t _explicitPaddingFor8BytesAlignedSize2;
} WGpuDeviceDescriptor;
extern const WGpuDeviceDescriptor WGPU_DEVICE_DESCRIPTOR_DEFAULT_INITIALIZER;
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUDevice : EventTarget {
[SameObject] readonly attribute GPUSupportedFeatures features;
[SameObject] readonly attribute GPUSupportedLimits limits;
[SameObject] readonly attribute GPUQueue queue;
undefined destroy();
GPUBuffer createBuffer(GPUBufferDescriptor descriptor);
GPUTexture createTexture(GPUTextureDescriptor descriptor);
GPUSampler createSampler(optional GPUSamplerDescriptor descriptor = {});
GPUExternalTexture importExternalTexture(GPUExternalTextureDescriptor descriptor);
GPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor);
GPUPipelineLayout createPipelineLayout(GPUPipelineLayoutDescriptor descriptor);
GPUBindGroup createBindGroup(GPUBindGroupDescriptor descriptor);
GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
Promise<GPUComputePipeline> createComputePipelineAsync(GPUComputePipelineDescriptor descriptor);
Promise<GPURenderPipeline> createRenderPipelineAsync(GPURenderPipelineDescriptor descriptor);
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
GPUQuerySet createQuerySet(GPUQuerySetDescriptor descriptor);
};
GPUDevice includes GPUObjectBase;
*/
typedef WGpuObjectBase WGpuDevice;
// Returns true if the given handle references a valid GPUDevice.
EM_BOOL wgpu_is_device(WGpuObjectBase object);
#define wgpu_device_get_features wgpu_adapter_or_device_get_features
#define wgpu_device_supports_feature wgpu_adapter_or_device_supports_feature
#define wgpu_device_get_limits wgpu_adapter_or_device_get_limits
WGpuQueue wgpu_device_get_queue(WGpuDevice device);
#ifdef __EMSCRIPTEN__
void wgpu_device_tick(WGpuDevice device) __attribute__((deprecated("The function wgpu_device_tick() is not available when targeting the web. Presentation always occurs when yielding out from browser event loop.")));
#else
void wgpu_device_tick(WGpuDevice device);
#endif
WGpuBuffer wgpu_device_create_buffer(WGpuDevice device, const WGpuBufferDescriptor *bufferDesc NOTNULL);
WGpuTexture wgpu_device_create_texture(WGpuDevice device, const WGpuTextureDescriptor *textureDesc NOTNULL);
WGpuSampler wgpu_device_create_sampler(WGpuDevice device, const WGpuSamplerDescriptor *samplerDesc NOTNULL);
WGpuExternalTexture wgpu_device_import_external_texture(WGpuDevice device, const WGpuExternalTextureDescriptor *externalTextureDesc NOTNULL);
// N.b. not currently using signature WGpuBindGroupLayout wgpu_device_create_bind_group_layout(WGpuDevice device, const WGpuBindGroupLayoutDescriptor *bindGroupLayoutDesc);
// since WGpuBindGroupLayoutDescriptor is a single element struct consisting only of a single array. (if it is expanded in the future, switch to using that signature)
WGpuBindGroupLayout wgpu_device_create_bind_group_layout(WGpuDevice device, const WGpuBindGroupLayoutEntry *bindGroupLayoutEntries, int numEntries);
// N.b. not currently using signature WGpuPipelineLayout wgpu_device_create_pipeline_layout(WGpuDevice device, const WGpuPipelineLayoutDescriptor *pipelineLayoutDesc);
// since WGpuPipelineLayoutDescriptor is a single element struct consisting only of a single array. (if it is expanded in the future, switch to using that signature)
WGpuPipelineLayout wgpu_device_create_pipeline_layout(WGpuDevice device, const WGpuBindGroupLayout *bindGroupLayouts, int numLayouts);
// N.b. not currently using signature WGpuBindGroup wgpu_device_create_bind_group(WGpuDevice device, const WGpuBindGroupDescriptor *bindGroupDesc);
// since WGpuBindGroupDescriptor is a such a light struct. (if it is expanded in the future, switch to using that signature)
WGpuBindGroup wgpu_device_create_bind_group(WGpuDevice device, WGpuBindGroupLayout bindGroupLayout, const WGpuBindGroupEntry *entries, int numEntries);
WGpuShaderModule wgpu_device_create_shader_module(WGpuDevice device, const WGpuShaderModuleDescriptor *shaderModuleDesc NOTNULL);
/*
[Exposed=(Window, DedicatedWorker), SecureContext, Serializable]
interface GPUPipelineError : DOMException {
constructor(optional DOMString message = "", GPUPipelineErrorInit options);
readonly attribute GPUPipelineErrorReason reason;
};
dictionary GPUPipelineErrorInit {
required GPUPipelineErrorReason reason;
};
enum GPUPipelineErrorReason {
"validation",
"internal",
};
*/
typedef struct WGpuPipelineError
{
const char *name; // The name of the DOMException type that represents this error.
const char *message; // A possibly human-readable message or description of the error.
const char *reason; // One of GPUPipelineErrorReason values.
} WGpuPipelineError;
// When this callback fires, on success the 'pipeline' parameter is nonzero.
// On failure, pipeline is 0, and in WEBGPU_DEBUG builds 'error' parameter identifies details about the failure. (in release builds the error parameter will be null)
typedef void (*WGpuCreatePipelineCallback)(WGpuDevice device, WGpuPipelineError *error, WGpuPipelineBase pipeline, void *userData);
// N.b. not currently using signature WGpuComputePipeline wgpu_device_create_compute_pipeline(WGpuDevice device, const WGpuComputePipelineDescriptor *computePipelineDesc);
// since WGpuComputePipelineDescriptor is a such a light struct. (if it is expanded in the future, switch to using that signature)
WGpuComputePipeline wgpu_device_create_compute_pipeline(WGpuDevice device, WGpuShaderModule computeModule, const char *entryPoint, WGpuPipelineLayout layout, const WGpuPipelineConstant *constants, int numConstants);
void wgpu_device_create_compute_pipeline_async(WGpuDevice device, WGpuShaderModule computeModule, const char *entryPoint, WGpuPipelineLayout layout, const WGpuPipelineConstant *constants, int numConstants, WGpuCreatePipelineCallback callback, void *userData);
WGpuRenderPipeline wgpu_device_create_render_pipeline(WGpuDevice device, const WGpuRenderPipelineDescriptor *renderPipelineDesc NOTNULL);
void wgpu_device_create_render_pipeline_async(WGpuDevice device, const WGpuRenderPipelineDescriptor *renderPipelineDesc NOTNULL, WGpuCreatePipelineCallback callback, void *userData);
WGpuCommandEncoder wgpu_device_create_command_encoder(WGpuDevice device, const WGpuCommandEncoderDescriptor *commandEncoderDesc);
// Same as above, but without any descriptor args.
WGpuCommandEncoder wgpu_device_create_command_encoder_simple(WGpuDevice device);
WGpuRenderBundleEncoder wgpu_device_create_render_bundle_encoder(WGpuDevice device, const WGpuRenderBundleEncoderDescriptor *renderBundleEncoderDesc NOTNULL);
WGpuQuerySet wgpu_device_create_query_set(WGpuDevice device, const WGpuQuerySetDescriptor *querySetDesc NOTNULL);
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUBuffer {
readonly attribute GPUSize64Out size;
readonly attribute GPUFlagsConstant usage;
readonly attribute GPUBufferMapState mapState;
Promise<undefined> mapAsync(GPUMapModeFlags mode, optional GPUSize64 offset = 0, optional GPUSize64 size);
ArrayBuffer getMappedRange(optional GPUSize64 offset = 0, optional GPUSize64 size);
undefined unmap();
undefined destroy();
};
GPUBuffer includes GPUObjectBase;
*/
typedef WGpuObjectBase WGpuBuffer;
// Returns true if the given handle references a valid GPUBuffer.
EM_BOOL wgpu_is_buffer(WGpuObjectBase object);
// TODO: Add error status to map callback for when mapAsync() promise rejects.
typedef void (*WGpuBufferMapCallback)(WGpuBuffer buffer, void *userData, WGPU_MAP_MODE_FLAGS mode, double_int53_t offset, double_int53_t size);
#define WGPU_MAX_SIZE -1
void wgpu_buffer_map_async(WGpuBuffer buffer, WGpuBufferMapCallback callback, void *userData, WGPU_MAP_MODE_FLAGS mode, double_int53_t offset _WGPU_DEFAULT_VALUE(0), double_int53_t size _WGPU_DEFAULT_VALUE(WGPU_MAX_SIZE));
// Maps the given WGpuBuffer synchronously. Requires building with -sASYNCIFY=1 linker flag to work.
void wgpu_buffer_map_sync(WGpuBuffer buffer, WGPU_MAP_MODE_FLAGS mode, double_int53_t offset _WGPU_DEFAULT_VALUE(0), double_int53_t size _WGPU_DEFAULT_VALUE(WGPU_MAX_SIZE));
#define WGPU_BUFFER_GET_MAPPED_RANGE_FAILED ((double_int53_t)-1)
// Calls buffer.getMappedRange(). Returns `startOffset`, which is used as an ID token to wgpu_buffer_read/write_mapped_range().
// If .getMappedRange() fails, the value WGPU_BUFFER_GET_MAPPED_RANGE_FAILED (-1) will be returned.
double_int53_t wgpu_buffer_get_mapped_range(WGpuBuffer buffer, double_int53_t startOffset, double_int53_t size _WGPU_DEFAULT_VALUE(WGPU_MAX_SIZE));
void wgpu_buffer_read_mapped_range(WGpuBuffer buffer, double_int53_t startOffset, double_int53_t subOffset, void *dst NOTNULL, double_int53_t size);
void wgpu_buffer_write_mapped_range(WGpuBuffer buffer, double_int53_t startOffset, double_int53_t subOffset, const void *src NOTNULL, double_int53_t size);
void wgpu_buffer_unmap(WGpuBuffer buffer);
// Getters for retrieving buffer properties:
double_int53_t wgpu_buffer_size(WGpuBuffer buffer);
WGPU_BUFFER_USAGE_FLAGS wgpu_buffer_usage(WGpuBuffer buffer);
WGPU_BUFFER_MAP_STATE wgpu_buffer_map_state(WGpuBuffer buffer);
/*
enum GPUBufferMapState {
"unmapped",
"pending",
"mapped"
};
*/
typedef int WGPU_BUFFER_MAP_STATE;
#define WGPU_BUFFER_MAP_STATE_INVALID 0
#define WGPU_BUFFER_MAP_STATE_UNMAPPED 1
#define WGPU_BUFFER_MAP_STATE_PENDING 2
#define WGPU_BUFFER_MAP_STATE_MAPPED 3
/*
dictionary GPUBufferDescriptor : GPUObjectDescriptorBase {
required GPUSize64 size;
required GPUBufferUsageFlags usage;
boolean mappedAtCreation = false;
};
*/
typedef struct WGpuBufferDescriptor
{
uint64_t size;
WGPU_BUFFER_USAGE_FLAGS usage;
EM_BOOL mappedAtCreation; // Note: it is valid to set mappedAtCreation to true without MAP_READ or MAP_WRITE in usage. This can be used to set the buffer’s initial data.
} WGpuBufferDescriptor;
/*
typedef [EnforceRange] unsigned long GPUBufferUsageFlags;
[Exposed=(Window, DedicatedWorker)]
namespace GPUBufferUsage {
const GPUFlagsConstant MAP_READ = 0x0001;
const GPUFlagsConstant MAP_WRITE = 0x0002;
const GPUFlagsConstant COPY_SRC = 0x0004;
const GPUFlagsConstant COPY_DST = 0x0008;
const GPUFlagsConstant INDEX = 0x0010;
const GPUFlagsConstant VERTEX = 0x0020;
const GPUFlagsConstant UNIFORM = 0x0040;
const GPUFlagsConstant STORAGE = 0x0080;
const GPUFlagsConstant INDIRECT = 0x0100;
const GPUFlagsConstant QUERY_RESOLVE = 0x0200;
};
*/
typedef int WGPU_BUFFER_USAGE_FLAGS;
#define WGPU_BUFFER_USAGE_MAP_READ 0x0001
#define WGPU_BUFFER_USAGE_MAP_WRITE 0x0002
#define WGPU_BUFFER_USAGE_COPY_SRC 0x0004
#define WGPU_BUFFER_USAGE_COPY_DST 0x0008
#define WGPU_BUFFER_USAGE_INDEX 0x0010
#define WGPU_BUFFER_USAGE_VERTEX 0x0020
#define WGPU_BUFFER_USAGE_UNIFORM 0x0040
#define WGPU_BUFFER_USAGE_STORAGE 0x0080
#define WGPU_BUFFER_USAGE_INDIRECT 0x0100
#define WGPU_BUFFER_USAGE_QUERY_RESOLVE 0x0200
/*
typedef [EnforceRange] unsigned long GPUMapModeFlags;
[Exposed=(Window, DedicatedWorker)]
namespace GPUMapMode {
const GPUFlagsConstant READ = 0x0001;
const GPUFlagsConstant WRITE = 0x0002;
};
*/
typedef int WGPU_MAP_MODE_FLAGS;
#define WGPU_MAP_MODE_READ 0x1
#define WGPU_MAP_MODE_WRITE 0x2
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUTexture {
GPUTextureView createView(optional GPUTextureViewDescriptor descriptor = {});
undefined destroy();
readonly attribute GPUIntegerCoordinate width;
readonly attribute GPUIntegerCoordinate height;
readonly attribute GPUIntegerCoordinate depthOrArrayLayers;
readonly attribute GPUIntegerCoordinate mipLevelCount;
readonly attribute GPUSize32 sampleCount;
readonly attribute GPUTextureDimension dimension;
readonly attribute GPUTextureFormat format;
readonly attribute GPUFlagsConstant usage;
};
GPUTexture includes GPUObjectBase;
*/
typedef WGpuObjectBase WGpuTexture;
// Returns true if the given handle references a valid GPUTexture.
EM_BOOL wgpu_is_texture(WGpuObjectBase object);
// textureViewDesc: Can be null, in which case a default view is created.
WGpuTextureView wgpu_texture_create_view(WGpuTexture texture, const WGpuTextureViewDescriptor *textureViewDesc _WGPU_DEFAULT_VALUE(0));
// Same as above, but does not take any descriptor args.
WGpuTextureView wgpu_texture_create_view_simple(WGpuTexture texture);
// Getters for retrieving texture properties:
uint32_t wgpu_texture_width(WGpuTexture texture);
uint32_t wgpu_texture_height(WGpuTexture texture);
uint32_t wgpu_texture_depth_or_array_layers(WGpuTexture texture);
uint32_t wgpu_texture_mip_level_count(WGpuTexture texture);
uint32_t wgpu_texture_sample_count(WGpuTexture texture);
WGPU_TEXTURE_DIMENSION wgpu_texture_dimension(WGpuTexture texture);
WGPU_TEXTURE_FORMAT wgpu_texture_format(WGpuTexture texture);
WGPU_TEXTURE_USAGE_FLAGS wgpu_texture_usage(WGpuTexture texture);
/*
dictionary GPUTextureDescriptor : GPUObjectDescriptorBase {
required GPUExtent3D size;
GPUIntegerCoordinate mipLevelCount = 1;
GPUSize32 sampleCount = 1;
GPUTextureDimension dimension = "2d";
required GPUTextureFormat format;
required GPUTextureUsageFlags usage;
sequence<GPUTextureFormat> viewFormats = [];
};
*/
typedef struct WGpuTextureDescriptor
{
uint32_t width;
uint32_t height; // default = 1;
uint32_t depthOrArrayLayers; // default = 1;
uint32_t mipLevelCount; // default = 1;
uint32_t sampleCount; // default = 1;
WGPU_TEXTURE_DIMENSION dimension; // default = WGPU_TEXTURE_DIMENSION_2D
WGPU_TEXTURE_FORMAT format;
WGPU_TEXTURE_USAGE_FLAGS usage;
int numViewFormats;
WGPU_TEXTURE_FORMAT *viewFormats;
} WGpuTextureDescriptor;
extern const WGpuTextureDescriptor WGPU_TEXTURE_DESCRIPTOR_DEFAULT_INITIALIZER;
/*
enum GPUTextureDimension {
"1d",
"2d",
"3d",
};
*/
typedef int WGPU_TEXTURE_DIMENSION;
#define WGPU_TEXTURE_DIMENSION_INVALID 0
#define WGPU_TEXTURE_DIMENSION_1D 1
#define WGPU_TEXTURE_DIMENSION_2D 2
#define WGPU_TEXTURE_DIMENSION_3D 3
/*
typedef [EnforceRange] unsigned long GPUTextureUsageFlags;
[Exposed=(Window, DedicatedWorker)]
namespace GPUTextureUsage {
const GPUFlagsConstant COPY_SRC = 0x01;
const GPUFlagsConstant COPY_DST = 0x02;
const GPUFlagsConstant TEXTURE_BINDING = 0x04;
const GPUFlagsConstant STORAGE_BINDING = 0x08;
const GPUFlagsConstant RENDER_ATTACHMENT = 0x10;
};
*/
typedef int WGPU_TEXTURE_USAGE_FLAGS;
#define WGPU_TEXTURE_USAGE_COPY_SRC 0x01
#define WGPU_TEXTURE_USAGE_COPY_DST 0x02
#define WGPU_TEXTURE_USAGE_TEXTURE_BINDING 0x04
#define WGPU_TEXTURE_USAGE_STORAGE_BINDING 0x08
#define WGPU_TEXTURE_USAGE_RENDER_ATTACHMENT 0x10
/*
[Exposed=(Window, DedicatedWorker), SecureContext]
interface GPUTextureView {
};
GPUTextureView includes GPUObjectBase;
*/
typedef WGpuObjectBase WGpuTextureView;
// Returns true if the given handle references a valid GPUTextureView.
EM_BOOL wgpu_is_texture_view(WGpuObjectBase object);
/*
dictionary GPUTextureViewDescriptor : GPUObjectDescriptorBase {
GPUTextureFormat format;
GPUTextureViewDimension dimension;
GPUTextureAspect aspect = "all";
GPUIntegerCoordinate baseMipLevel = 0;
GPUIntegerCoordinate mipLevelCount;
GPUIntegerCoordinate baseArrayLayer = 0;
GPUIntegerCoordinate arrayLayerCount;
};
*/
typedef struct WGpuTextureViewDescriptor
{
WGPU_TEXTURE_FORMAT format;
WGPU_TEXTURE_VIEW_DIMENSION dimension;
WGPU_TEXTURE_ASPECT aspect; // default = WGPU_TEXTURE_ASPECT_ALL
uint32_t baseMipLevel; // default = 0
uint32_t mipLevelCount;
uint32_t baseArrayLayer; // default = 0
uint32_t arrayLayerCount;
} WGpuTextureViewDescriptor;
extern const WGpuTextureViewDescriptor WGPU_TEXTURE_VIEW_DESCRIPTOR_DEFAULT_INITIALIZER;
/*
enum GPUTextureViewDimension {
"1d",
"2d",
"2d-array",
"cube",
"cube-array",
"3d"
};
*/
typedef int WGPU_TEXTURE_VIEW_DIMENSION;
#define WGPU_TEXTURE_VIEW_DIMENSION_INVALID 0
#define WGPU_TEXTURE_VIEW_DIMENSION_1D 1
#define WGPU_TEXTURE_VIEW_DIMENSION_2D 2
#define WGPU_TEXTURE_VIEW_DIMENSION_2D_ARRAY 3
#define WGPU_TEXTURE_VIEW_DIMENSION_CUBE 4
#define WGPU_TEXTURE_VIEW_DIMENSION_CUBE_ARRAY 5
#define WGPU_TEXTURE_VIEW_DIMENSION_3D 6
/*
enum GPUTextureAspect {
"all",
"stencil-only",
"depth-only"
};
*/
typedef int WGPU_TEXTURE_ASPECT;
#define WGPU_TEXTURE_ASPECT_INVALID 0
#define WGPU_TEXTURE_ASPECT_ALL 1
#define WGPU_TEXTURE_ASPECT_STENCIL_ONLY 2
#define WGPU_TEXTURE_ASPECT_DEPTH_ONLY 3
/*
enum GPUTextureFormat {
// 8-bit formats
"r8unorm",
"r8snorm",
"r8uint",
"r8sint",
// 16-bit formats
"r16uint",
"r16sint",
"r16float",
"rg8unorm",
"rg8snorm",
"rg8uint",
"rg8sint",
// 32-bit formats
"r32uint",
"r32sint",
"r32float",
"rg16uint",
"rg16sint",
"rg16float",
"rgba8unorm",
"rgba8unorm-srgb",
"rgba8snorm",
"rgba8uint",
"rgba8sint",
"bgra8unorm",
"bgra8unorm-srgb",
// Packed 32-bit formats
"rgb9e5ufloat",
"rgb10a2uint",
"rgb10a2unorm",
"rg11b10ufloat",
// 64-bit formats
"rg32uint",
"rg32sint",
"rg32float",
"rgba16uint",
"rgba16sint",
"rgba16float",
// 128-bit formats
"rgba32uint",
"rgba32sint",
"rgba32float",
// Depth/stencil formats
"stencil8",
"depth16unorm",
"depth24plus",
"depth24plus-stencil8",
"depth32float",
// "depth32float-stencil8" feature
"depth32float-stencil8",
// BC compressed formats usable if "texture-compression-bc" is both
// supported by the device/user agent and enabled in requestDevice.
"bc1-rgba-unorm",
"bc1-rgba-unorm-srgb",
"bc2-rgba-unorm",
"bc2-rgba-unorm-srgb",
"bc3-rgba-unorm",
"bc3-rgba-unorm-srgb",
"bc4-r-unorm",
"bc4-r-snorm",
"bc5-rg-unorm",
"bc5-rg-snorm",
"bc6h-rgb-ufloat",
"bc6h-rgb-float",
"bc7-rgba-unorm",
"bc7-rgba-unorm-srgb",
// ETC2 compressed formats usable if "texture-compression-etc2" is both
// supported by the device/user agent and enabled in requestDevice.
"etc2-rgb8unorm",
"etc2-rgb8unorm-srgb",
"etc2-rgb8a1unorm",
"etc2-rgb8a1unorm-srgb",
"etc2-rgba8unorm",
"etc2-rgba8unorm-srgb",
"eac-r11unorm",
"eac-r11snorm",
"eac-rg11unorm",
"eac-rg11snorm",
// ASTC compressed formats usable if "texture-compression-astc" is both
// supported by the device/user agent and enabled in requestDevice.
"astc-4x4-unorm",
"astc-4x4-unorm-srgb",
"astc-5x4-unorm",
"astc-5x4-unorm-srgb",
"astc-5x5-unorm",
"astc-5x5-unorm-srgb",
"astc-6x5-unorm",
"astc-6x5-unorm-srgb",
"astc-6x6-unorm",
"astc-6x6-unorm-srgb",
"astc-8x5-unorm",
"astc-8x5-unorm-srgb",
"astc-8x6-unorm",
"astc-8x6-unorm-srgb",
"astc-8x8-unorm",
"astc-8x8-unorm-srgb",
"astc-10x5-unorm",
"astc-10x5-unorm-srgb",
"astc-10x6-unorm",
"astc-10x6-unorm-srgb",
"astc-10x8-unorm",
"astc-10x8-unorm-srgb",
"astc-10x10-unorm",
"astc-10x10-unorm-srgb",
"astc-12x10-unorm",
"astc-12x10-unorm-srgb",
"astc-12x12-unorm",
"astc-12x12-unorm-srgb"
};
*/
typedef int WGPU_TEXTURE_FORMAT;
#define WGPU_TEXTURE_FORMAT_INVALID 0
// 8-bit formats
#define WGPU_TEXTURE_FORMAT_R8UNORM 1
#define WGPU_TEXTURE_FORMAT_R8SNORM 2
#define WGPU_TEXTURE_FORMAT_R8UINT 3
#define WGPU_TEXTURE_FORMAT_R8SINT 4
// 16-bit formats
#define WGPU_TEXTURE_FORMAT_R16UINT 5
#define WGPU_TEXTURE_FORMAT_R16SINT 6
#define WGPU_TEXTURE_FORMAT_R16FLOAT 7
#define WGPU_TEXTURE_FORMAT_RG8UNORM 8
#define WGPU_TEXTURE_FORMAT_RG8SNORM 9
#define WGPU_TEXTURE_FORMAT_RG8UINT 10
#define WGPU_TEXTURE_FORMAT_RG8SINT 11
// 32-bit formats
#define WGPU_TEXTURE_FORMAT_R32UINT 12
#define WGPU_TEXTURE_FORMAT_R32SINT 13
#define WGPU_TEXTURE_FORMAT_R32FLOAT 14
#define WGPU_TEXTURE_FORMAT_RG16UINT 15
#define WGPU_TEXTURE_FORMAT_RG16SINT 16
#define WGPU_TEXTURE_FORMAT_RG16FLOAT 17
#define WGPU_TEXTURE_FORMAT_RGBA8UNORM 18
#define WGPU_TEXTURE_FORMAT_RGBA8UNORM_SRGB 19
#define WGPU_TEXTURE_FORMAT_RGBA8SNORM 20
#define WGPU_TEXTURE_FORMAT_RGBA8UINT 21
#define WGPU_TEXTURE_FORMAT_RGBA8SINT 22
#define WGPU_TEXTURE_FORMAT_BGRA8UNORM 23
#define WGPU_TEXTURE_FORMAT_BGRA8UNORM_SRGB 24
// Packed 32-bit formats
#define WGPU_TEXTURE_FORMAT_RGB9E5UFLOAT 25
#define WGPU_TEXTURE_FORMAT_RGB10A2UINT 26
#define WGPU_TEXTURE_FORMAT_RGB10A2UNORM 27
#define WGPU_TEXTURE_FORMAT_RG11B10UFLOAT 28
// 64-bit formats
#define WGPU_TEXTURE_FORMAT_RG32UINT 29
#define WGPU_TEXTURE_FORMAT_RG32SINT 30
#define WGPU_TEXTURE_FORMAT_RG32FLOAT 31
#define WGPU_TEXTURE_FORMAT_RGBA16UINT 32
#define WGPU_TEXTURE_FORMAT_RGBA16SINT 33
#define WGPU_TEXTURE_FORMAT_RGBA16FLOAT 34
// 128-bit formats
#define WGPU_TEXTURE_FORMAT_RGBA32UINT 35
#define WGPU_TEXTURE_FORMAT_RGBA32SINT 36
#define WGPU_TEXTURE_FORMAT_RGBA32FLOAT 37
// Depth/stencil formats
#define WGPU_TEXTURE_FORMAT_STENCIL8 38
#define WGPU_TEXTURE_FORMAT_DEPTH16UNORM 39
#define WGPU_TEXTURE_FORMAT_DEPTH24PLUS 40
#define WGPU_TEXTURE_FORMAT_DEPTH24PLUS_STENCIL8 41
#define WGPU_TEXTURE_FORMAT_DEPTH32FLOAT 42
#define WGPU_TEXTURE_FORMAT_DEPTH32FLOAT_STENCIL8 43
// BC compressed formats usable if "texture-compression-bc" is both
// supported by the device/user agent and enabled in requestDevice.
#define WGPU_TEXTURE_FORMAT_BC1_RGBA_UNORM 44
#define WGPU_TEXTURE_FORMAT_BC1_RGBA_UNORM_SRGB 45
#define WGPU_TEXTURE_FORMAT_BC2_RGBA_UNORM 46
#define WGPU_TEXTURE_FORMAT_BC2_RGBA_UNORM_SRGB 47
#define WGPU_TEXTURE_FORMAT_BC3_RGBA_UNORM 48
#define WGPU_TEXTURE_FORMAT_BC3_RGBA_UNORM_SRGB 49
#define WGPU_TEXTURE_FORMAT_BC4_R_UNORM 50
#define WGPU_TEXTURE_FORMAT_BC4_R_SNORM 51
#define WGPU_TEXTURE_FORMAT_BC5_RG_UNORM 52
#define WGPU_TEXTURE_FORMAT_BC5_RG_SNORM 53
#define WGPU_TEXTURE_FORMAT_BC6H_RGB_UFLOAT 54
#define WGPU_TEXTURE_FORMAT_BC6H_RGB_FLOAT 55
#define WGPU_TEXTURE_FORMAT_BC7_RGBA_UNORM 56
#define WGPU_TEXTURE_FORMAT_BC7_RGBA_UNORM_SRGB 57
// ETC2 compressed formats usable if "texture-compression-etc2" is both
// supported by the device/user agent and enabled in requestDevice.
#define WGPU_TEXTURE_FORMAT_ETC2_RGB8UNORM 58
#define WGPU_TEXTURE_FORMAT_ETC2_RGB8UNORM_SRGB 59