Skip to content

Commit

Permalink
Update WebGPU (#4062)
Browse files Browse the repository at this point in the history
- Appropriately mark WebGPU functions with `[Throws]`.
- Add support for `AllowSharedBufferSource`.
- Add support for optional arguments followed by non-optional ones.
  • Loading branch information
daxpedda committed Aug 11, 2024
1 parent 2ea6ab1 commit 9a584e9
Show file tree
Hide file tree
Showing 23 changed files with 546 additions and 274 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
* Removed `impl Deref for JsStatic` when compiling with `cfg(target_feature = "atomics")`, which was unsound.
[#4057](https://github.com/rustwasm/wasm-bindgen/pull/4057)

* Updated the WebGPU WebIDL to the current draft as of 2024-08-05.
[#4062](https://github.com/rustwasm/wasm-bindgen/pull/4062)

### Fixed

* Copy port from headless test server when using `WASM_BINDGEN_TEST_ADDRESS`.
Expand Down
48 changes: 24 additions & 24 deletions crates/cli/tests/reference/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,6 @@ export function __wbg_set_wasm(val) {
}


const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}

const heap = new Array(128).fill(undefined);

heap.push(undefined, null, true, false);
Expand All @@ -45,6 +25,26 @@ function takeObject(idx) {
dropObject(idx);
return ret;
}

const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;

let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });

cachedTextDecoder.decode();

let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}

function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
}
/**
* @param {number} test
* @returns {number}
Expand Down Expand Up @@ -110,11 +110,11 @@ export function __wbg_test2_39fe629b9aa739cf() {
return addHeapObject(ret);
};

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

export function __wbindgen_throw(arg0, arg1) {
throw new Error(getStringFromWasm0(arg0, arg1));
};

2 changes: 2 additions & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,8 @@ GpuBufferMapState = []
GpuCanvasAlphaMode = []
GpuCanvasConfiguration = []
GpuCanvasContext = []
GpuCanvasToneMapping = []
GpuCanvasToneMappingMode = []
GpuColorDict = []
GpuColorTargetState = []
GpuCommandBuffer = []
Expand Down
13 changes: 13 additions & 0 deletions crates/web-sys/src/features/gen_GpuAdapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn limits(this: &GpuAdapter) -> GpuSupportedLimits;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuAdapterInfo")]
# [wasm_bindgen (structural , method , getter , js_class = "GPUAdapter" , js_name = info)]
#[doc = "Getter for the `info` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUAdapter/info)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuAdapter`, `GpuAdapterInfo`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn info(this: &GpuAdapter) -> GpuAdapterInfo;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "GPUAdapter" , js_name = isFallbackAdapter)]
#[doc = "Getter for the `isFallbackAdapter` field of this object."]
#[doc = ""]
Expand All @@ -61,6 +73,7 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[deprecated]
pub fn request_adapter_info(this: &GpuAdapter) -> ::js_sys::Promise;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUAdapter" , js_name = requestDevice)]
Expand Down
4 changes: 4 additions & 0 deletions crates/web-sys/src/features/gen_GpuBlendFactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ pub enum GpuBlendFactor {
SrcAlphaSaturated = "src-alpha-saturated",
Constant = "constant",
OneMinusConstant = "one-minus-constant",
Src1 = "src1",
OneMinusSrc1 = "one-minus-src1",
Src1Alpha = "src1-alpha",
OneMinusSrc1Alpha = "one-minus-src1-alpha",
}
34 changes: 20 additions & 14 deletions crates/web-sys/src/features/gen_GpuBuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn destroy(this: &GpuBuffer);
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -93,9 +93,9 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_mapped_range(this: &GpuBuffer) -> ::js_sys::ArrayBuffer;
pub fn get_mapped_range(this: &GpuBuffer) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -104,9 +104,12 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_mapped_range_with_u32(this: &GpuBuffer, offset: u32) -> ::js_sys::ArrayBuffer;
pub fn get_mapped_range_with_u32(
this: &GpuBuffer,
offset: u32,
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -115,9 +118,12 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_mapped_range_with_f64(this: &GpuBuffer, offset: f64) -> ::js_sys::ArrayBuffer;
pub fn get_mapped_range_with_f64(
this: &GpuBuffer,
offset: f64,
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -130,9 +136,9 @@ extern "C" {
this: &GpuBuffer,
offset: u32,
size: u32,
) -> ::js_sys::ArrayBuffer;
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -145,9 +151,9 @@ extern "C" {
this: &GpuBuffer,
offset: f64,
size: u32,
) -> ::js_sys::ArrayBuffer;
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -160,9 +166,9 @@ extern "C" {
this: &GpuBuffer,
offset: u32,
size: f64,
) -> ::js_sys::ArrayBuffer;
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUBuffer" , js_name = getMappedRange)]
#[doc = "The `getMappedRange()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUBuffer/getMappedRange)"]
Expand All @@ -175,7 +181,7 @@ extern "C" {
this: &GpuBuffer,
offset: f64,
size: f64,
) -> ::js_sys::ArrayBuffer;
) -> Result<::js_sys::ArrayBuffer, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUBuffer" , js_name = mapAsync)]
#[doc = "The `mapAsync()` method."]
Expand Down
27 changes: 27 additions & 0 deletions crates/web-sys/src/features/gen_GpuCanvasConfiguration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ extern "C" {
#[wasm_bindgen(method, setter = "format")]
pub fn set_format(this: &GpuCanvasConfiguration, val: GpuTextureFormat);
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMapping")]
#[doc = "Get the `toneMapping` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasConfiguration`, `GpuCanvasToneMapping`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, getter = "toneMapping")]
pub fn get_tone_mapping(this: &GpuCanvasConfiguration) -> Option<GpuCanvasToneMapping>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMapping")]
#[doc = "Change the `toneMapping` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasConfiguration`, `GpuCanvasToneMapping`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, setter = "toneMapping")]
pub fn set_tone_mapping(this: &GpuCanvasConfiguration, val: &GpuCanvasToneMapping);
#[cfg(web_sys_unstable_apis)]
#[doc = "Get the `usage` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasConfiguration`*"]
Expand Down Expand Up @@ -149,6 +169,13 @@ impl GpuCanvasConfiguration {
self
}
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMapping")]
#[deprecated = "Use `set_tone_mapping()` instead."]
pub fn tone_mapping(&mut self, val: &GpuCanvasToneMapping) -> &mut Self {
self.set_tone_mapping(val);
self
}
#[cfg(web_sys_unstable_apis)]
#[deprecated = "Use `set_usage()` instead."]
pub fn usage(&mut self, val: u32) -> &mut Self {
self.set_usage(val);
Expand Down
11 changes: 7 additions & 4 deletions crates/web-sys/src/features/gen_GpuCanvasContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern "C" {
pub fn canvas(this: &GpuCanvasContext) -> ::js_sys::Object;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasConfiguration")]
# [wasm_bindgen (method , structural , js_class = "GPUCanvasContext" , js_name = configure)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUCanvasContext" , js_name = configure)]
#[doc = "The `configure()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext/configure)"]
Expand All @@ -38,10 +38,13 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn configure(this: &GpuCanvasContext, configuration: &GpuCanvasConfiguration);
pub fn configure(
this: &GpuCanvasContext,
configuration: &GpuCanvasConfiguration,
) -> Result<(), JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuTexture")]
# [wasm_bindgen (method , structural , js_class = "GPUCanvasContext" , js_name = getCurrentTexture)]
# [wasm_bindgen (catch , method , structural , js_class = "GPUCanvasContext" , js_name = getCurrentTexture)]
#[doc = "The `getCurrentTexture()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext/getCurrentTexture)"]
Expand All @@ -50,7 +53,7 @@ extern "C" {
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn get_current_texture(this: &GpuCanvasContext) -> GpuTexture;
pub fn get_current_texture(this: &GpuCanvasContext) -> Result<GpuTexture, JsValue>;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUCanvasContext" , js_name = unconfigure)]
#[doc = "The `unconfigure()` method."]
Expand Down
64 changes: 64 additions & 0 deletions crates/web-sys/src/features/gen_GpuCanvasToneMapping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use super::*;
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
extern "C" {
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = GPUCanvasToneMapping)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[doc = "The `GpuCanvasToneMapping` dictionary."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasToneMapping`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type GpuCanvasToneMapping;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMappingMode")]
#[doc = "Get the `mode` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasToneMapping`, `GpuCanvasToneMappingMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, getter = "mode")]
pub fn get_mode(this: &GpuCanvasToneMapping) -> Option<GpuCanvasToneMappingMode>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMappingMode")]
#[doc = "Change the `mode` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasToneMapping`, `GpuCanvasToneMappingMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, setter = "mode")]
pub fn set_mode(this: &GpuCanvasToneMapping, val: GpuCanvasToneMappingMode);
}
#[cfg(web_sys_unstable_apis)]
impl GpuCanvasToneMapping {
#[doc = "Construct a new `GpuCanvasToneMapping`."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasToneMapping`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn new() -> Self {
#[allow(unused_mut)]
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
ret
}
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasToneMappingMode")]
#[deprecated = "Use `set_mode()` instead."]
pub fn mode(&mut self, val: GpuCanvasToneMappingMode) -> &mut Self {
self.set_mode(val);
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for GpuCanvasToneMapping {
fn default() -> Self {
Self::new()
}
}
16 changes: 16 additions & 0 deletions crates/web-sys/src/features/gen_GpuCanvasToneMappingMode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![allow(unused_imports)]
#![allow(clippy::all)]
use wasm_bindgen::prelude::*;
#[cfg(web_sys_unstable_apis)]
#[wasm_bindgen]
#[doc = "The `GpuCanvasToneMappingMode` enum."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasToneMappingMode`*"]
#[doc = ""]
#[doc = "*This API is unstable and requires `--cfg=web_sys_unstable_apis` to be activated, as"]
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GpuCanvasToneMappingMode {
Standard = "standard",
Extended = "extended",
}
Loading

0 comments on commit 9a584e9

Please sign in to comment.