Skip to content

Commit aaf6db6

Browse files
authored
Vendor WebGPU Bindings from web_sys (gfx-rs#5325)
1 parent a5c0181 commit aaf6db6

File tree

143 files changed

+13705
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+13705
-460
lines changed

.cargo/config.toml

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,2 @@
11
[alias]
2-
xtask = "run --manifest-path xtask/Cargo.toml"
3-
4-
[build]
5-
rustflags = [
6-
"--cfg=web_sys_unstable_apis"
7-
]
8-
rustdocflags = [
9-
"--cfg=web_sys_unstable_apis"
10-
]
2+
xtask = "run --manifest-path xtask/Cargo.toml --"

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.mtl binary
22
*.obj binary
3+
wgpu/src/backend/webgpu/webgpu_sys/** linguist-generated=true

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ env:
5555
RUST_LOG: info
5656
RUST_BACKTRACE: full
5757
PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work
58-
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
59-
RUSTDOCFLAGS: --cfg=web_sys_unstable_apis -D warnings
58+
RUSTFLAGS: -D warnings
59+
RUSTDOCFLAGS: -D warnings
6060
WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes
6161
CACHE_SUFFIX: c # cache busting
6262

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ env:
1212
CARGO_INCREMENTAL: false
1313
CARGO_TERM_COLOR: always
1414
RUST_BACKTRACE: full
15-
RUSTFLAGS: --cfg=web_sys_unstable_apis
15+
RUSTFLAGS:
1616

1717
jobs:
1818
publish:

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ cts/
3131

3232
# Cached GPU config
3333
.gpuconfig
34+
35+
# Temporary clone location for wasm-bindgen mirroring
36+
wgpu/src/backend/webgpu/webgpu_sys/wasm_bindgen_clone_tmp

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ Bottom level categories:
3939

4040
## Unreleased
4141

42+
### Major Changes
43+
44+
#### Vendored WebGPU Bindings from `web_sys`
45+
46+
**`--cfg=web_sys_unstable_apis` is no longer needed in your `RUSTFLAGS` to compile for WebGPU!!!**
47+
48+
While WebGPU's javascript api is stable in the browsers, the `web_sys` bindings for WebGPU are still improving. As such they are hidden behind the special cfg `--cfg=web_sys_unstable_apis` and are not available by default. Everyone who wanted to use our WebGPU backend needed to enable this cfg in their `RUSTFLAGS`. This was very inconvenient and made it hard to use WebGPU, especially when WebGPU is enabled by default. Additionally, the unstable APIs don't adhere to semver, so there were repeated breakages.
49+
50+
To combat this problem we have decided to vendor the `web_sys` bindings for WebGPU within the crate. Notably we are not forking the bindings, merely vendoring, so any improvements we make to the bindings will be contributed directly to upstream `web_sys`.
51+
52+
By @cwfitzgerald in [#5325](https://github.com/gfx-rs/wgpu/pull/5325).
53+
4254
### Documentation
4355

4456
- Document Wayland specific behavior related to `SurfaceTexture::present`. By @i509VCB in [#5092](https://github.com/gfx-rs/wgpu/pull/5092).

wgpu/Cargo.toml

+4-119
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ exclude = ["Cargo.lock"]
1313

1414
[package.metadata.docs.rs]
1515
all-features = true
16-
rustdoc-args = ["--cfg", "docsrs", "--cfg", "web_sys_unstable_apis"]
16+
rustdoc-args = ["--cfg", "docsrs"]
1717
targets = [
1818
"x86_64-unknown-linux-gnu",
1919
"x86_64-apple-darwin",
@@ -194,131 +194,16 @@ web-sys = { workspace = true, features = [
194194
"Navigator",
195195
"Node",
196196
"NodeList",
197-
"Gpu",
198-
"GpuAdapter",
199-
"GpuAddressMode",
200-
"GpuAutoLayoutMode",
201-
"GpuBindGroup",
202-
"GpuBindGroupDescriptor",
203-
"GpuBindGroupEntry",
204-
"GpuBindGroupLayout",
205-
"GpuBindGroupLayoutDescriptor",
206-
"GpuBindGroupLayoutEntry",
207-
"GpuBlendComponent",
208-
"GpuBlendFactor",
209-
"GpuBlendOperation",
210-
"GpuBlendState",
211-
"GpuBuffer",
212-
"GpuBufferBinding",
213-
"GpuBufferBindingLayout",
214-
"GpuBufferBindingType",
215-
"GpuBufferDescriptor",
216-
"GpuCanvasAlphaMode",
217-
"GpuCanvasContext",
218-
"GpuCanvasConfiguration",
219-
"GpuColorDict",
220-
"GpuColorTargetState",
221-
"GpuCommandBuffer",
222-
"GpuCommandBufferDescriptor",
223-
"GpuCommandEncoder",
224-
"GpuCommandEncoderDescriptor",
225-
"GpuCompareFunction",
226-
"GpuCompilationInfo",
227-
"GpuCompilationMessage",
228-
"GpuCompilationMessageType",
229-
"GpuComputePassDescriptor",
230-
"GpuComputePassEncoder",
231-
"GpuComputePassTimestampWrites",
232-
"GpuComputePipeline",
233-
"GpuComputePipelineDescriptor",
234-
"GpuCullMode",
235-
"GpuDepthStencilState",
236-
"GpuDevice",
237-
"GpuDeviceDescriptor",
238-
"GpuDeviceLostInfo",
239-
"GpuDeviceLostReason",
240-
"GpuError",
241-
"GpuErrorFilter",
242-
# "GpuExtent2dDict", Not yet implemented in web_sys
243-
"GpuExtent3dDict",
244-
"GpuFeatureName",
245-
"GpuFilterMode",
246-
"GpuFragmentState",
247-
"GpuFrontFace",
248-
"GpuImageCopyBuffer",
249-
"GpuImageCopyExternalImage",
250-
"GpuImageCopyTexture",
251-
"GpuImageCopyTextureTagged",
252-
"GpuImageDataLayout",
253-
"GpuIndexFormat",
254-
"GpuLoadOp",
255-
"gpu_map_mode",
256-
"GpuMipmapFilterMode",
257-
"GpuMultisampleState",
258-
"GpuObjectDescriptorBase",
259-
"GpuOrigin2dDict",
260-
"GpuOrigin3dDict",
261-
"GpuOutOfMemoryError",
262-
"GpuPipelineDescriptorBase",
263-
"GpuPipelineLayout",
264-
"GpuPipelineLayoutDescriptor",
265-
"GpuPowerPreference",
266-
"GpuPrimitiveState",
267-
"GpuPrimitiveTopology",
268-
"GpuProgrammableStage",
269-
"GpuQuerySet",
270-
"GpuQuerySetDescriptor",
271-
"GpuQueryType",
272-
"GpuQueue",
273-
"GpuRenderBundle",
274-
"GpuRenderBundleDescriptor",
275-
"GpuRenderBundleEncoder",
276-
"GpuRenderBundleEncoderDescriptor",
277-
"GpuRenderPassColorAttachment",
278-
"GpuRenderPassDepthStencilAttachment",
279-
"GpuRenderPassDescriptor",
280-
"GpuRenderPassEncoder",
281-
"GpuRenderPipeline",
282-
"GpuRenderPipelineDescriptor",
283-
"GpuRequestAdapterOptions",
284-
"GpuSampler",
285-
"GpuSamplerBindingLayout",
286-
"GpuSamplerBindingType",
287-
"GpuSamplerDescriptor",
288-
"GpuShaderModule",
289-
"GpuShaderModuleDescriptor",
290-
"GpuStencilFaceState",
291-
"GpuStencilOperation",
292-
"GpuStorageTextureAccess",
293-
"GpuStorageTextureBindingLayout",
294-
"GpuStoreOp",
295-
"GpuSupportedFeatures",
296-
"GpuSupportedLimits",
297-
"GpuTexture",
298-
"GpuTextureAspect",
299-
"GpuTextureBindingLayout",
300-
"GpuTextureDescriptor",
301-
"GpuTextureDimension",
302-
"GpuTextureFormat",
303-
"GpuTextureSampleType",
304-
"GpuTextureView",
305-
"GpuTextureViewDescriptor",
306-
"GpuTextureViewDimension",
307-
"GpuUncapturedErrorEvent",
308-
"GpuUncapturedErrorEventInit",
309-
"GpuValidationError",
310-
"GpuVertexAttribute",
311-
"GpuVertexBufferLayout",
312-
"GpuVertexFormat",
313-
"GpuVertexState",
314-
"GpuVertexStepMode",
315197
"HtmlCanvasElement",
316198
"OffscreenCanvas",
317199
"ImageBitmap",
318200
"ImageBitmapRenderingContext",
319201
"Window",
320202
"WorkerGlobalScope",
321203
"WorkerNavigator",
204+
# Needed by webgpu_sys
205+
"Event",
206+
"EventTarget",
322207
] }
323208
wasm-bindgen.workspace = true
324209
js-sys.workspace = true

wgpu/src/backend/mod.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
#[cfg(all(webgpu, web_sys_unstable_apis))]
1+
#[cfg(webgpu)]
22
mod webgpu;
3-
#[cfg(all(webgpu, web_sys_unstable_apis))]
3+
#[cfg(webgpu)]
44
pub(crate) use webgpu::{get_browser_gpu_property, ContextWebGpu};
55

6-
#[cfg(all(webgpu, not(web_sys_unstable_apis)))]
7-
compile_error!(
8-
"webgpu feature used without web_sys_unstable_apis config:
9-
Here are some ways to resolve this:
10-
* If you wish to use webgpu backend, create a .cargo/config.toml in the root of the repo containing:
11-
[build]
12-
rustflags = [ \"--cfg=web_sys_unstable_apis\" ]
13-
rustdocflags = [ \"--cfg=web_sys_unstable_apis\" ]
14-
* If you wish to disable webgpu backend and instead use webgl backend, change your wgpu Cargo.toml entry to:
15-
wgpu = { version = \"\", default-features = false, features = [\"webgl\"] }
16-
"
17-
);
18-
196
#[cfg(wgpu_core)]
207
mod wgpu_core;
218

0 commit comments

Comments
 (0)