Skip to content

Commit

Permalink
Vendor WebGPU Bindings from web_sys (gfx-rs#5325)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Mar 1, 2024
1 parent e0e0532 commit 5f80832
Show file tree
Hide file tree
Showing 143 changed files with 13,704 additions and 460 deletions.
10 changes: 1 addition & 9 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
[alias]
xtask = "run --manifest-path xtask/Cargo.toml"

[build]
rustflags = [
"--cfg=web_sys_unstable_apis"
]
rustdocflags = [
"--cfg=web_sys_unstable_apis"
]
xtask = "run --manifest-path xtask/Cargo.toml --"
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.mtl binary
*.obj binary
wgpu/src/backend/webgpu/webgpu_sys/** linguist-generated=true
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ env:
RUST_LOG: info
RUST_BACKTRACE: full
PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
RUSTDOCFLAGS: --cfg=web_sys_unstable_apis -D warnings
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes
CACHE_SUFFIX: c # cache busting

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ env:
CARGO_INCREMENTAL: false
CARGO_TERM_COLOR: always
RUST_BACKTRACE: full
RUSTFLAGS: --cfg=web_sys_unstable_apis
RUSTFLAGS:

jobs:
publish:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ cts/

# Cached GPU config
.gpuconfig

# Temporary clone location for wasm-bindgen mirroring
wgpu/src/backend/webgpu/webgpu_sys/wasm_bindgen_clone_tmp
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ Bottom level categories:

## v0.19.3 (2024-03-01)

### Major Changes

#### Vendored WebGPU Bindings from `web_sys`

**`--cfg=web_sys_unstable_apis` is no longer needed in your `RUSTFLAGS` to compile for WebGPU!!!**

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.

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`.

By @cwfitzgerald in [#5325](https://github.com/gfx-rs/wgpu/pull/5325).

### Bug Fixes

#### General
Expand Down
123 changes: 4 additions & 119 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exclude = ["Cargo.lock"]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs", "--cfg", "web_sys_unstable_apis"]
rustdoc-args = ["--cfg", "docsrs"]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
Expand Down Expand Up @@ -187,131 +187,16 @@ web-sys = { workspace = true, features = [
"Navigator",
"Node",
"NodeList",
"Gpu",
"GpuAdapter",
"GpuAddressMode",
"GpuAutoLayoutMode",
"GpuBindGroup",
"GpuBindGroupDescriptor",
"GpuBindGroupEntry",
"GpuBindGroupLayout",
"GpuBindGroupLayoutDescriptor",
"GpuBindGroupLayoutEntry",
"GpuBlendComponent",
"GpuBlendFactor",
"GpuBlendOperation",
"GpuBlendState",
"GpuBuffer",
"GpuBufferBinding",
"GpuBufferBindingLayout",
"GpuBufferBindingType",
"GpuBufferDescriptor",
"GpuCanvasAlphaMode",
"GpuCanvasContext",
"GpuCanvasConfiguration",
"GpuColorDict",
"GpuColorTargetState",
"GpuCommandBuffer",
"GpuCommandBufferDescriptor",
"GpuCommandEncoder",
"GpuCommandEncoderDescriptor",
"GpuCompareFunction",
"GpuCompilationInfo",
"GpuCompilationMessage",
"GpuCompilationMessageType",
"GpuComputePassDescriptor",
"GpuComputePassEncoder",
"GpuComputePassTimestampWrites",
"GpuComputePipeline",
"GpuComputePipelineDescriptor",
"GpuCullMode",
"GpuDepthStencilState",
"GpuDevice",
"GpuDeviceDescriptor",
"GpuDeviceLostInfo",
"GpuDeviceLostReason",
"GpuError",
"GpuErrorFilter",
# "GpuExtent2dDict", Not yet implemented in web_sys
"GpuExtent3dDict",
"GpuFeatureName",
"GpuFilterMode",
"GpuFragmentState",
"GpuFrontFace",
"GpuImageCopyBuffer",
"GpuImageCopyExternalImage",
"GpuImageCopyTexture",
"GpuImageCopyTextureTagged",
"GpuImageDataLayout",
"GpuIndexFormat",
"GpuLoadOp",
"gpu_map_mode",
"GpuMipmapFilterMode",
"GpuMultisampleState",
"GpuObjectDescriptorBase",
"GpuOrigin2dDict",
"GpuOrigin3dDict",
"GpuOutOfMemoryError",
"GpuPipelineDescriptorBase",
"GpuPipelineLayout",
"GpuPipelineLayoutDescriptor",
"GpuPowerPreference",
"GpuPrimitiveState",
"GpuPrimitiveTopology",
"GpuProgrammableStage",
"GpuQuerySet",
"GpuQuerySetDescriptor",
"GpuQueryType",
"GpuQueue",
"GpuRenderBundle",
"GpuRenderBundleDescriptor",
"GpuRenderBundleEncoder",
"GpuRenderBundleEncoderDescriptor",
"GpuRenderPassColorAttachment",
"GpuRenderPassDepthStencilAttachment",
"GpuRenderPassDescriptor",
"GpuRenderPassEncoder",
"GpuRenderPipeline",
"GpuRenderPipelineDescriptor",
"GpuRequestAdapterOptions",
"GpuSampler",
"GpuSamplerBindingLayout",
"GpuSamplerBindingType",
"GpuSamplerDescriptor",
"GpuShaderModule",
"GpuShaderModuleDescriptor",
"GpuStencilFaceState",
"GpuStencilOperation",
"GpuStorageTextureAccess",
"GpuStorageTextureBindingLayout",
"GpuStoreOp",
"GpuSupportedFeatures",
"GpuSupportedLimits",
"GpuTexture",
"GpuTextureAspect",
"GpuTextureBindingLayout",
"GpuTextureDescriptor",
"GpuTextureDimension",
"GpuTextureFormat",
"GpuTextureSampleType",
"GpuTextureView",
"GpuTextureViewDescriptor",
"GpuTextureViewDimension",
"GpuUncapturedErrorEvent",
"GpuUncapturedErrorEventInit",
"GpuValidationError",
"GpuVertexAttribute",
"GpuVertexBufferLayout",
"GpuVertexFormat",
"GpuVertexState",
"GpuVertexStepMode",
"HtmlCanvasElement",
"OffscreenCanvas",
"ImageBitmap",
"ImageBitmapRenderingContext",
"Window",
"WorkerGlobalScope",
"WorkerNavigator",
# Needed by webgpu_sys
"Event",
"EventTarget",
] }
wasm-bindgen.workspace = true
js-sys.workspace = true
Expand Down
17 changes: 2 additions & 15 deletions wgpu/src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
#[cfg(all(webgpu, web_sys_unstable_apis))]
#[cfg(webgpu)]
mod webgpu;
#[cfg(all(webgpu, web_sys_unstable_apis))]
#[cfg(webgpu)]
pub(crate) use webgpu::{get_browser_gpu_property, ContextWebGpu};

#[cfg(all(webgpu, not(web_sys_unstable_apis)))]
compile_error!(
"webgpu feature used without web_sys_unstable_apis config:
Here are some ways to resolve this:
* If you wish to use webgpu backend, create a .cargo/config.toml in the root of the repo containing:
[build]
rustflags = [ \"--cfg=web_sys_unstable_apis\" ]
rustdocflags = [ \"--cfg=web_sys_unstable_apis\" ]
* If you wish to disable webgpu backend and instead use webgl backend, change your wgpu Cargo.toml entry to:
wgpu = { version = \"\", default-features = false, features = [\"webgl\"] }
"
);

#[cfg(wgpu_core)]
mod wgpu_core;

Expand Down
Loading

0 comments on commit 5f80832

Please sign in to comment.