Skip to content

Commit

Permalink
Update WebGPU API to draft 2024-10-07 (#4145)
Browse files Browse the repository at this point in the history
  • Loading branch information
daxpedda authored Oct 8, 2024
1 parent 98c5e0b commit e6e098d
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 61 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
* Changed `TextDecoder.decode()` `input` parameter type from `&mut [u8]` to `&[u8]`.
[#4141](https://github.com/rustwasm/wasm-bindgen/pull/4141)

* Updated the WebGPU API to the current draft as of 2024-10-07.
[#4145](https://github.com/rustwasm/wasm-bindgen/pull/4145)

### Fixed

* Fixed linked modules emitting snippet files when not using `--split-linked-modules`.
Expand Down
10 changes: 5 additions & 5 deletions crates/cli/tests/reference/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ export class Test {
}
}

export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
export function __wbg_test2_39fe629b9aa739cf() {
const ret = test2();
return addHeapObject(ret);
};

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

export function __wbg_test2_39fe629b9aa739cf() {
const ret = test2();
return addHeapObject(ret);
export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};

12 changes: 0 additions & 12 deletions crates/web-sys/src/features/gen_GpuAdapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,6 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn is_fallback_adapter(this: &GpuAdapter) -> bool;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (method , structural , js_class = "GPUAdapter" , js_name = requestAdapterInfo)]
#[doc = "The `requestAdapterInfo()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUAdapter/requestAdapterInfo)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuAdapter`*"]
#[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)]
#[doc = "The `requestDevice()` method."]
#[doc = ""]
Expand Down
12 changes: 12 additions & 0 deletions crates/web-sys/src/features/gen_GpuCanvasContext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ extern "C" {
configuration: &GpuCanvasConfiguration,
) -> Result<(), JsValue>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuCanvasConfiguration")]
# [wasm_bindgen (method , structural , js_class = "GPUCanvasContext" , js_name = getConfiguration)]
#[doc = "The `getConfiguration()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUCanvasContext/getConfiguration)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuCanvasConfiguration`, `GpuCanvasContext`*"]
#[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_configuration(this: &GpuCanvasContext) -> Option<GpuCanvasConfiguration>;
#[cfg(web_sys_unstable_apis)]
#[cfg(feature = "GpuTexture")]
# [wasm_bindgen (catch , method , structural , js_class = "GPUCanvasContext" , js_name = getCurrentTexture)]
#[doc = "The `getCurrentTexture()` method."]
Expand Down
4 changes: 2 additions & 2 deletions crates/web-sys/src/features/gen_GpuDevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ extern "C" {
) -> GpuSampler;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "GpuShaderModule", feature = "GpuShaderModuleDescriptor",))]
# [wasm_bindgen (catch , method , structural , js_class = "GPUDevice" , js_name = createShaderModule)]
# [wasm_bindgen (method , structural , js_class = "GPUDevice" , js_name = createShaderModule)]
#[doc = "The `createShaderModule()` method."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUDevice/createShaderModule)"]
Expand All @@ -332,7 +332,7 @@ extern "C" {
pub fn create_shader_module(
this: &GpuDevice,
descriptor: &GpuShaderModuleDescriptor,
) -> Result<GpuShaderModule, JsValue>;
) -> GpuShaderModule;
#[cfg(web_sys_unstable_apis)]
#[cfg(all(feature = "GpuTexture", feature = "GpuTextureDescriptor",))]
# [wasm_bindgen (catch , method , structural , js_class = "GPUDevice" , js_name = createTexture)]
Expand Down
1 change: 1 addition & 0 deletions crates/web-sys/src/features/gen_GpuFeatureName.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum GpuFeatureName {
TextureCompressionBcSliced3d = "texture-compression-bc-sliced-3d",
TextureCompressionEtc2 = "texture-compression-etc2",
TextureCompressionAstc = "texture-compression-astc",
TextureCompressionAstcSliced3d = "texture-compression-astc-sliced-3d",
TimestampQuery = "timestamp-query",
IndirectFirstInstance = "indirect-first-instance",
ShaderF16 = "shader-f16",
Expand Down
24 changes: 24 additions & 0 deletions crates/web-sys/src/features/gen_GpuRequestAdapterOptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub type GpuRequestAdapterOptions;
#[cfg(web_sys_unstable_apis)]
#[doc = "Get the `featureLevel` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuRequestAdapterOptions`*"]
#[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 = "featureLevel")]
pub fn get_feature_level(this: &GpuRequestAdapterOptions) -> Option<String>;
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `featureLevel` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuRequestAdapterOptions`*"]
#[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 = "featureLevel")]
pub fn set_feature_level(this: &GpuRequestAdapterOptions, val: &str);
#[cfg(web_sys_unstable_apis)]
#[doc = "Get the `forceFallbackAdapter` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuRequestAdapterOptions`*"]
Expand Down Expand Up @@ -67,6 +85,12 @@ impl GpuRequestAdapterOptions {
ret
}
#[cfg(web_sys_unstable_apis)]
#[deprecated = "Use `set_feature_level()` instead."]
pub fn feature_level(&mut self, val: &str) -> &mut Self {
self.set_feature_level(val);
self
}
#[cfg(web_sys_unstable_apis)]
#[deprecated = "Use `set_force_fallback_adapter()` instead."]
pub fn force_fallback_adapter(&mut self, val: bool) -> &mut Self {
self.set_force_fallback_adapter(val);
Expand Down
24 changes: 0 additions & 24 deletions crates/web-sys/src/features/gen_GpuShaderModuleDescriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, setter = "compilationHints")]
pub fn set_compilation_hints(this: &GpuShaderModuleDescriptor, val: &::wasm_bindgen::JsValue);
#[cfg(web_sys_unstable_apis)]
#[doc = "Get the `sourceMap` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuShaderModuleDescriptor`*"]
#[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 = "sourceMap")]
pub fn get_source_map(this: &GpuShaderModuleDescriptor) -> Option<::js_sys::Object>;
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `sourceMap` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuShaderModuleDescriptor`*"]
#[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 = "sourceMap")]
pub fn set_source_map(this: &GpuShaderModuleDescriptor, val: &::js_sys::Object);
}
#[cfg(web_sys_unstable_apis)]
impl GpuShaderModuleDescriptor {
Expand Down Expand Up @@ -119,10 +101,4 @@ impl GpuShaderModuleDescriptor {
self.set_compilation_hints(val);
self
}
#[cfg(web_sys_unstable_apis)]
#[deprecated = "Use `set_source_map()` instead."]
pub fn source_map(&mut self, val: &::js_sys::Object) -> &mut Self {
self.set_source_map(val);
self
}
}
11 changes: 0 additions & 11 deletions crates/web-sys/src/features/gen_GpuSupportedLimits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,17 +259,6 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
pub fn max_vertex_buffer_array_stride(this: &GpuSupportedLimits) -> u32;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "GPUSupportedLimits" , js_name = maxInterStageShaderComponents)]
#[doc = "Getter for the `maxInterStageShaderComponents` field of this object."]
#[doc = ""]
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/GPUSupportedLimits/maxInterStageShaderComponents)"]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuSupportedLimits`*"]
#[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 max_inter_stage_shader_components(this: &GpuSupportedLimits) -> u32;
#[cfg(web_sys_unstable_apis)]
# [wasm_bindgen (structural , method , getter , js_class = "GPUSupportedLimits" , js_name = maxInterStageShaderVariables)]
#[doc = "Getter for the `maxInterStageShaderVariables` field of this object."]
#[doc = ""]
Expand Down
24 changes: 24 additions & 0 deletions crates/web-sys/src/features/gen_GpuTextureViewDescriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,24 @@ extern "C" {
#[doc = "[described in the `wasm-bindgen` guide](https://rustwasm.github.io/docs/wasm-bindgen/web-sys/unstable-apis.html)*"]
#[wasm_bindgen(method, setter = "mipLevelCount")]
pub fn set_mip_level_count(this: &GpuTextureViewDescriptor, val: u32);
#[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: `GpuTextureViewDescriptor`*"]
#[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 = "usage")]
pub fn get_usage(this: &GpuTextureViewDescriptor) -> Option<u32>;
#[cfg(web_sys_unstable_apis)]
#[doc = "Change the `usage` field of this object."]
#[doc = ""]
#[doc = "*This API requires the following crate features to be activated: `GpuTextureViewDescriptor`*"]
#[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 = "usage")]
pub fn set_usage(this: &GpuTextureViewDescriptor, val: u32);
}
#[cfg(web_sys_unstable_apis)]
impl GpuTextureViewDescriptor {
Expand Down Expand Up @@ -229,6 +247,12 @@ impl GpuTextureViewDescriptor {
self.set_mip_level_count(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);
self
}
}
#[cfg(web_sys_unstable_apis)]
impl Default for GpuTextureViewDescriptor {
Expand Down
15 changes: 8 additions & 7 deletions crates/web-sys/webidls/unstable/WebGPU.webidl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// https://www.w3.org/TR/2024/WD-webgpu-20241007

interface mixin GPUObjectBase {
attribute USVString label;
};
Expand Down Expand Up @@ -30,7 +32,6 @@ interface GPUSupportedLimits {
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;
Expand Down Expand Up @@ -74,6 +75,7 @@ interface GPU {
};

dictionary GPURequestAdapterOptions {
DOMString featureLevel;
GPUPowerPreference powerPreference;
boolean forceFallbackAdapter = false;
};
Expand All @@ -91,14 +93,12 @@ interface GPUAdapter {
readonly attribute boolean isFallbackAdapter;

Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
[RustDeprecated]
Promise<GPUAdapterInfo> requestAdapterInfo();
};

dictionary GPUDeviceDescriptor
: GPUObjectDescriptorBase {
sequence<GPUFeatureName> requiredFeatures = [];
record<DOMString, GPUSize64> requiredLimits = {};
record<DOMString, (GPUSize64 or undefined)> requiredLimits = {};
GPUQueueDescriptor defaultQueue = {};
};

Expand All @@ -109,6 +109,7 @@ enum GPUFeatureName {
"texture-compression-bc-sliced-3d",
"texture-compression-etc2",
"texture-compression-astc",
"texture-compression-astc-sliced-3d",
"timestamp-query",
"indirect-first-instance",
"shader-f16",
Expand Down Expand Up @@ -141,7 +142,6 @@ interface GPUDevice : EventTarget {
GPUPipelineLayout createPipelineLayout(GPUPipelineLayoutDescriptor descriptor);
GPUBindGroup createBindGroup(GPUBindGroupDescriptor descriptor);

[Throws]
GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
[Throws]
Expand Down Expand Up @@ -263,6 +263,7 @@ dictionary GPUTextureViewDescriptor
: GPUObjectDescriptorBase {
GPUTextureFormat format;
GPUTextureViewDimension dimension;
GPUTextureUsageFlags usage = 0;
GPUTextureAspect aspect = "all";
GPUIntegerCoordinate baseMipLevel = 0;
GPUIntegerCoordinate mipLevelCount;
Expand Down Expand Up @@ -586,7 +587,6 @@ GPUShaderModule includes GPUObjectBase;
dictionary GPUShaderModuleDescriptor
: GPUObjectDescriptorBase {
required USVString code;
object sourceMap;
sequence<GPUShaderModuleCompilationHint> compilationHints = [];
};

Expand Down Expand Up @@ -647,7 +647,7 @@ interface mixin GPUPipelineBase {
dictionary GPUProgrammableStage {
required GPUShaderModule module;
USVString entryPoint;
record<USVString, GPUPipelineConstantValue> constants;
record<USVString, GPUPipelineConstantValue> constants = {};
};

typedef double GPUPipelineConstantValue; // May represent WGSL's bool, f32, i32, u32, and f16 if enabled.
Expand Down Expand Up @@ -1199,6 +1199,7 @@ interface GPUCanvasContext {
undefined configure(GPUCanvasConfiguration configuration);
undefined unconfigure();

GPUCanvasConfiguration? getConfiguration();
[Throws]
GPUTexture getCurrentTexture();
};
Expand Down

0 comments on commit e6e098d

Please sign in to comment.