Skip to content

Commit d97e90f

Browse files
committed
feat(webgpu): update to the latest WebGPU spec
1 parent 9669257 commit d97e90f

3 files changed

Lines changed: 149 additions & 9 deletions

File tree

webgpu/generate/webgpu-spec

Submodule webgpu-spec updated 83 files

webgpu/generate/webgpu-transforms.json

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,27 +221,27 @@
221221
{
222222
"operation": {
223223
"remove-variant-case": {
224-
"variant": "gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-view",
224+
"variant": "gpu-buffer-or-gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view",
225225
"case": "gpu-external-texture"
226226
}
227227
}
228228
},
229229
{
230230
"operation": {
231231
"rename-type": {
232-
"from": "gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-view",
233-
"to": "gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-view"
232+
"from": "gpu-buffer-or-gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view",
233+
"to": "gpu-buffer-or-gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view"
234234
}
235235
}
236236
},
237237
{
238238
"operation": {
239239
"replace-type-usages": {
240240
"old": {
241-
"named": "gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-view"
241+
"named": "gpu-buffer-or-gpu-buffer-binding-or-gpu-external-texture-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view"
242242
},
243243
"new": {
244-
"named": "gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-view"
244+
"named": "gpu-buffer-or-gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view"
245245
}
246246
}
247247
}
@@ -525,6 +525,90 @@
525525
}
526526
]
527527
},
528+
{
529+
"reason": "Beautify gpu-command-encoder.copy-buffer-to-buffer, no tuple params. Using the more powerful variant with offsets and making the offsets optional",
530+
"operations": [
531+
{
532+
"vars": {
533+
"$_SOURCE": {
534+
"find-type": {
535+
"variant-case": {
536+
"variant": "gpu-command-encoder-copy-buffer-to-buffer-params",
537+
"case": "source-source-offset-destination-destination-offset-size"
538+
},
539+
"unwrap-t": [
540+
{ "tuple": 0 }
541+
]
542+
}
543+
},
544+
"$_SOURCE_OFFSET": {
545+
"find-type": {
546+
"variant-case": {
547+
"variant": "gpu-command-encoder-copy-buffer-to-buffer-params",
548+
"case": "source-source-offset-destination-destination-offset-size"
549+
},
550+
"unwrap-t": [
551+
{ "tuple": 1 }
552+
]
553+
}
554+
},
555+
"$_DESTINATION": {
556+
"find-type": {
557+
"variant-case": {
558+
"variant": "gpu-command-encoder-copy-buffer-to-buffer-params",
559+
"case": "source-source-offset-destination-destination-offset-size"
560+
},
561+
"unwrap-t": [
562+
{ "tuple": 2 }
563+
]
564+
}
565+
},
566+
"$_DESTINATION_OFFSET": {
567+
"find-type": {
568+
"variant-case": {
569+
"variant": "gpu-command-encoder-copy-buffer-to-buffer-params",
570+
"case": "source-source-offset-destination-destination-offset-size"
571+
},
572+
"unwrap-t": [
573+
{ "tuple": 3 }
574+
]
575+
}
576+
},
577+
"$_SIZE": {
578+
"find-type": {
579+
"variant-case": {
580+
"variant": "gpu-command-encoder-copy-buffer-to-buffer-params",
581+
"case": "source-source-offset-destination-destination-offset-size"
582+
},
583+
"unwrap-t": [
584+
{ "tuple": 4 }
585+
]
586+
}
587+
}
588+
},
589+
"operation": {
590+
"retype-func-params": {
591+
"resource": "gpu-command-encoder",
592+
"func": "copy-buffer-to-buffer",
593+
"new-params": {
594+
"items": [
595+
["source", "$_SOURCE"],
596+
["source-offset", { "option": "$_SOURCE_OFFSET" }],
597+
["destination", "$_DESTINATION"],
598+
["destination-offset", { "option": "$_DESTINATION_OFFSET" }],
599+
["size", "$_SIZE"]
600+
]
601+
}
602+
}
603+
}
604+
},
605+
{
606+
"operation": {
607+
"remove-type": "gpu-command-encoder-copy-buffer-to-buffer-params"
608+
}
609+
}
610+
]
611+
},
528612
{
529613
"reason": "Remove allow-shared-buffer-source as it's web related and temporarily replace it with list<u8>",
530614
"operations": [
@@ -830,7 +914,7 @@
830914
{
831915
"operation": {
832916
"rename-type": {
833-
"from" : "gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-view",
917+
"from" : "gpu-buffer-or-gpu-buffer-binding-or-gpu-sampler-or-gpu-texture-or-gpu-texture-view",
834918
"to" : "gpu-binding-resource"
835919
}
836920
}
@@ -1037,6 +1121,36 @@
10371121
}
10381122
]
10391123
},
1124+
{
1125+
"reason": "Accepting a texture in place of a texture view is just shorthand for texture.createView() (https://www.w3.org/TR/webgpu/#abstract-opdef-get-as-texture-view), so it's unnecessary — callers can call create-view themselves. JS can hide this behind dynamic typing, but in WIT it would require a variant and complicate the API. webgpu.h also disallows it (https://github.com/gpuweb/gpuweb/pull/5228#issuecomment-3046161091).",
1126+
"operations": [
1127+
{
1128+
"vars": {
1129+
"$_VIEW": {
1130+
"find-type": {
1131+
"variant-case": {
1132+
"variant": "gpu-texture-or-gpu-texture-view",
1133+
"case": "gpu-texture-view"
1134+
}
1135+
}
1136+
}
1137+
},
1138+
"operation": {
1139+
"replace-type-usages": {
1140+
"old": {
1141+
"named": "gpu-texture-or-gpu-texture-view"
1142+
},
1143+
"new": "$_VIEW"
1144+
}
1145+
}
1146+
},
1147+
{
1148+
"operation": {
1149+
"remove-type": "gpu-texture-or-gpu-texture-view"
1150+
}
1151+
}
1152+
]
1153+
},
10401154
{
10411155
"reason": "Errors have the message field raised to the top level type so that they don't have to be taken out of the inner error. Important if we allow new error types in the future that the developer has not yet handled. They also get a `kind` to enable detecting the error type. `kind` is a variant and not an enum so that they can have fields inside like `pipeline-error.reason`. Note: not changing gpu-error to a record even though errors added by us are records, because GPUError is an interface in the spec, and might one day gain interface like properties",
10421156
"operations": [

webgpu/webgpu.wit

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ interface webgpu {
3434
features: func() -> gpu-supported-features;
3535
limits: func() -> gpu-supported-limits;
3636
info: func() -> gpu-adapter-info;
37-
is-fallback-adapter: func() -> bool;
3837
request-device: func(descriptor: option<gpu-device-descriptor>) -> future<result<gpu-device, request-device-error>>;
3938
}
4039
resource gpu-adapter-info {
@@ -44,6 +43,7 @@ interface webgpu {
4443
description: func() -> string;
4544
subgroup-min-size: func() -> u32;
4645
subgroup-max-size: func() -> u32;
46+
is-fallback-adapter: func() -> bool;
4747
}
4848
enum gpu-address-mode {
4949
clamp-to-edge,
@@ -80,8 +80,10 @@ interface webgpu {
8080
storage-texture: option<gpu-storage-texture-binding-layout>,
8181
}
8282
variant gpu-binding-resource {
83+
gpu-buffer(borrow<gpu-buffer>),
8384
gpu-buffer-binding(gpu-buffer-binding),
8485
gpu-sampler(borrow<gpu-sampler>),
86+
gpu-texture(borrow<gpu-texture>),
8587
gpu-texture-view(borrow<gpu-texture-view>),
8688
}
8789
record gpu-blend-component {
@@ -235,7 +237,7 @@ interface webgpu {
235237
resource gpu-command-encoder {
236238
begin-render-pass: func(descriptor: gpu-render-pass-descriptor) -> gpu-render-pass-encoder;
237239
begin-compute-pass: func(descriptor: option<gpu-compute-pass-descriptor>) -> gpu-compute-pass-encoder;
238-
copy-buffer-to-buffer: func(source: borrow<gpu-buffer>, source-offset: gpu-size64, destination: borrow<gpu-buffer>, destination-offset: gpu-size64, size: gpu-size64);
240+
copy-buffer-to-buffer: func(source: borrow<gpu-buffer>, source-offset: option<gpu-size64>, destination: borrow<gpu-buffer>, destination-offset: option<gpu-size64>, size: option<gpu-size64>);
239241
copy-buffer-to-texture: func(source: gpu-texel-copy-buffer-info, destination: gpu-texel-copy-texture-info, copy-size: gpu-extent3-d);
240242
copy-texture-to-buffer: func(source: gpu-texel-copy-texture-info, destination: gpu-texel-copy-buffer-info, copy-size: gpu-extent3-d);
241243
copy-texture-to-texture: func(source: gpu-texel-copy-texture-info, destination: gpu-texel-copy-texture-info, copy-size: gpu-extent3-d);
@@ -292,6 +294,7 @@ interface webgpu {
292294
pop-debug-group: func();
293295
insert-debug-marker: func(marker-label: string);
294296
set-bind-group: func(index: gpu-index32, bind-group: option<borrow<gpu-bind-group>>, dynamic-offsets-data: option<list<gpu-buffer-dynamic-offset>>, dynamic-offsets-data-start: option<gpu-size64>, dynamic-offsets-data-length: option<gpu-size32>) -> result<_, set-bind-group-error>;
297+
set-immediates: func(range-offset: gpu-size32, data: list<u8>, data-offset: option<gpu-size64>, data-size: option<gpu-size64>);
295298
}
296299
record gpu-compute-pass-timestamp-writes {
297300
query-set: borrow<gpu-query-set>,
@@ -388,6 +391,7 @@ interface webgpu {
388391
depth-or-array-layers: option<gpu-integer-coordinate>,
389392
}
390393
enum gpu-feature-name {
394+
core-features-and-limits,
391395
depth-clip-control,
392396
depth32float-stencil8,
393397
texture-compression-bc,
@@ -405,6 +409,10 @@ interface webgpu {
405409
clip-distances,
406410
dual-source-blending,
407411
subgroups,
412+
texture-formats-tier1,
413+
texture-formats-tier2,
414+
primitive-index,
415+
texture-component-swizzle,
408416
}
409417
enum gpu-filter-mode {
410418
nearest,
@@ -466,6 +474,7 @@ interface webgpu {
466474
}
467475
record gpu-pipeline-layout-descriptor {
468476
bind-group-layouts: list<option<borrow<gpu-bind-group-layout>>>,
477+
immediate-size: option<gpu-size32>,
469478
label: option<string>,
470479
}
471480
enum gpu-power-preference {
@@ -533,6 +542,7 @@ interface webgpu {
533542
pop-debug-group: func();
534543
insert-debug-marker: func(marker-label: string);
535544
set-bind-group: func(index: gpu-index32, bind-group: option<borrow<gpu-bind-group>>, dynamic-offsets-data: option<list<gpu-buffer-dynamic-offset>>, dynamic-offsets-data-start: option<gpu-size64>, dynamic-offsets-data-length: option<gpu-size32>) -> result<_, set-bind-group-error>;
545+
set-immediates: func(range-offset: gpu-size32, data: list<u8>, data-offset: option<gpu-size64>, data-size: option<gpu-size64>);
536546
set-pipeline: func(pipeline: borrow<gpu-render-pipeline>);
537547
set-index-buffer: func(buffer: borrow<gpu-buffer>, index-format: gpu-index-format, offset: option<gpu-size64>, size: option<gpu-size64>);
538548
set-vertex-buffer: func(slot: gpu-index32, buffer: option<borrow<gpu-buffer>>, offset: option<gpu-size64>, size: option<gpu-size64>);
@@ -591,6 +601,7 @@ interface webgpu {
591601
pop-debug-group: func();
592602
insert-debug-marker: func(marker-label: string);
593603
set-bind-group: func(index: gpu-index32, bind-group: option<borrow<gpu-bind-group>>, dynamic-offsets-data: option<list<gpu-buffer-dynamic-offset>>, dynamic-offsets-data-start: option<gpu-size64>, dynamic-offsets-data-length: option<gpu-size32>) -> result<_, set-bind-group-error>;
604+
set-immediates: func(range-offset: gpu-size32, data: list<u8>, data-offset: option<gpu-size64>, data-size: option<gpu-size64>);
594605
set-pipeline: func(pipeline: borrow<gpu-render-pipeline>);
595606
set-index-buffer: func(buffer: borrow<gpu-buffer>, index-format: gpu-index-format, offset: option<gpu-size64>, size: option<gpu-size64>);
596607
set-vertex-buffer: func(slot: gpu-index32, buffer: option<borrow<gpu-buffer>>, offset: option<gpu-size64>, size: option<gpu-size64>);
@@ -716,13 +727,18 @@ interface webgpu {
716727
max-texture-array-layers: func() -> u32;
717728
max-bind-groups: func() -> u32;
718729
max-bind-groups-plus-vertex-buffers: func() -> u32;
730+
max-immediate-size: func() -> u32;
719731
max-bindings-per-bind-group: func() -> u32;
720732
max-dynamic-uniform-buffers-per-pipeline-layout: func() -> u32;
721733
max-dynamic-storage-buffers-per-pipeline-layout: func() -> u32;
722734
max-sampled-textures-per-shader-stage: func() -> u32;
723735
max-samplers-per-shader-stage: func() -> u32;
724736
max-storage-buffers-per-shader-stage: func() -> u32;
737+
max-storage-buffers-in-vertex-stage: func() -> u32;
738+
max-storage-buffers-in-fragment-stage: func() -> u32;
725739
max-storage-textures-per-shader-stage: func() -> u32;
740+
max-storage-textures-in-vertex-stage: func() -> u32;
741+
max-storage-textures-in-fragment-stage: func() -> u32;
726742
max-uniform-buffers-per-shader-stage: func() -> u32;
727743
max-uniform-buffer-binding-size: func() -> u64;
728744
max-storage-buffer-binding-size: func() -> u64;
@@ -770,6 +786,7 @@ interface webgpu {
770786
dimension: func() -> gpu-texture-dimension;
771787
format: func() -> gpu-texture-format;
772788
usage: func() -> gpu-flags-constant;
789+
texture-binding-view-dimension: func() -> option<gpu-texture-view-dimension>;
773790
label: func() -> string;
774791
set-label: func(label: string);
775792
from-graphics-buffer: static func(buffer: abstract-buffer) -> gpu-texture;
@@ -792,6 +809,7 @@ interface webgpu {
792809
format: gpu-texture-format,
793810
usage: gpu-texture-usage-flags,
794811
view-formats: option<list<gpu-texture-format>>,
812+
texture-binding-view-dimension: option<gpu-texture-view-dimension>,
795813
label: option<string>,
796814
}
797815
enum gpu-texture-dimension {
@@ -804,6 +822,8 @@ interface webgpu {
804822
r8snorm,
805823
r8uint,
806824
r8sint,
825+
r16unorm,
826+
r16snorm,
807827
r16uint,
808828
r16sint,
809829
r16float,
@@ -814,6 +834,8 @@ interface webgpu {
814834
r32uint,
815835
r32sint,
816836
r32float,
837+
rg16unorm,
838+
rg16snorm,
817839
rg16uint,
818840
rg16sint,
819841
rg16float,
@@ -831,6 +853,8 @@ interface webgpu {
831853
rg32uint,
832854
rg32sint,
833855
rg32float,
856+
rgba16unorm,
857+
rgba16snorm,
834858
rgba16uint,
835859
rgba16sint,
836860
rgba16float,
@@ -909,6 +933,7 @@ interface webgpu {
909933
TEXTURE-BINDING: static func() -> gpu-flags-constant;
910934
STORAGE-BINDING: static func() -> gpu-flags-constant;
911935
RENDER-ATTACHMENT: static func() -> gpu-flags-constant;
936+
TRANSIENT-ATTACHMENT: static func() -> gpu-flags-constant;
912937
}
913938
type gpu-texture-usage-flags = u32;
914939
resource gpu-texture-view {
@@ -924,6 +949,7 @@ interface webgpu {
924949
mip-level-count: option<gpu-integer-coordinate>,
925950
base-array-layer: option<gpu-integer-coordinate>,
926951
array-layer-count: option<gpu-integer-coordinate>,
952+
swizzle: option<string>,
927953
label: option<string>,
928954
}
929955
enum gpu-texture-view-dimension {

0 commit comments

Comments
 (0)