webgpu: Update to wgpu 0.20 (#32173)

* Update wgpu to 0.20

* good expectations

* Throw TypeError in configure on unsupported format instead of panic

* Expect

* `into_command_buffer_id`,`into_command_encoder_id`
This commit is contained in:
Samson 2024-05-08 07:38:11 +02:00 committed by GitHub
parent 5298ccb0eb
commit c4f8599404
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 1552 additions and 852 deletions

55
Cargo.lock generated
View file

@ -1134,8 +1134,9 @@ checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
[[package]]
name = "d3d12"
version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=32e70bc1635905c508d408eb1cf22b2aa062ffe1#32e70bc1635905c508d408eb1cf22b2aa062ffe1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b28bfe653d79bd16c77f659305b195b82bb5ce0c0eb2a4846b82ddbd77586813"
dependencies = [
"bitflags 2.5.0",
"libloading 0.8.3",
@ -1348,6 +1349,15 @@ dependencies = [
"libloading 0.8.3",
]
[[package]]
name = "document-features"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5282ad69563b5fc40319526ba27e0e7363d552a896f0297d54f767717f9b95"
dependencies = [
"litrs",
]
[[package]]
name = "dom_struct"
version = "0.0.1"
@ -2226,9 +2236,9 @@ dependencies = [
[[package]]
name = "gpu-descriptor"
version = "0.2.4"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc11df1ace8e7e564511f53af41f3e42ddc95b56fd07b3f4445d2a6048bc682c"
checksum = "9c08c1f623a8d0b722b8b99f821eb0ba672a1618f0d3b16ddbee1cedd2dd8557"
dependencies = [
"bitflags 2.5.0",
"gpu-descriptor-types",
@ -2237,9 +2247,9 @@ dependencies = [
[[package]]
name = "gpu-descriptor-types"
version = "0.1.2"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bf0b36e6f090b7e1d8a4b49c0cb81c1f8376f72198c65dd3ad9ff3556b8b78c"
checksum = "fdf242682df893b86f33a73828fb09ca4b2d3bb6cc95249707fc684d27484b91"
dependencies = [
"bitflags 2.5.0",
]
@ -3537,6 +3547,12 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9d642685b028806386b2b6e75685faadd3eb65a85fff7df711ce18446a422da"
[[package]]
name = "litrs"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ce301924b7887e9d637144fdade93f9dfff9b60981d4ac161db09720d39aa5"
[[package]]
name = "lock_api"
version = "0.4.12"
@ -3714,9 +3730,9 @@ dependencies = [
[[package]]
name = "metal"
version = "0.27.0"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c43f73953f8cbe511f021b58f18c3ce1c3d1ae13fe953293e13345bf83217f25"
checksum = "5637e166ea14be6063a3f8ba5ccb9a4159df7d8f6d61c02fc3d480b1f90dcfcb"
dependencies = [
"bitflags 2.5.0",
"block",
@ -3885,8 +3901,9 @@ checksum = "956787520e75e9bd233246045d19f42fb73242759cc57fba9611d940ae96d4b0"
[[package]]
name = "naga"
version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=32e70bc1635905c508d408eb1cf22b2aa062ffe1#32e70bc1635905c508d408eb1cf22b2aa062ffe1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e536ae46fcab0876853bd4a632ede5df4b1c2527a58f6c5a4150fe86be858231"
dependencies = [
"arrayvec",
"bit-set",
@ -7186,14 +7203,16 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]]
name = "wgpu-core"
version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=32e70bc1635905c508d408eb1cf22b2aa062ffe1#32e70bc1635905c508d408eb1cf22b2aa062ffe1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac6a86eaa5e763e59c73cf9e97d55fffd4dfda69fd8bda19589fcf851ddfef1f"
dependencies = [
"arrayvec",
"bit-vec",
"bitflags 2.5.0",
"cfg_aliases",
"codespan-reporting",
"document-features",
"indexmap 2.2.6",
"log",
"naga",
@ -7212,8 +7231,9 @@ dependencies = [
[[package]]
name = "wgpu-hal"
version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=32e70bc1635905c508d408eb1cf22b2aa062ffe1#32e70bc1635905c508d408eb1cf22b2aa062ffe1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d71c8ae05170583049b65ee562fd839fdc0b3e9ddb84f4e40c9d5f8ea0d4c8c"
dependencies = [
"android_system_properties",
"arrayvec",
@ -7231,7 +7251,7 @@ dependencies = [
"libc",
"libloading 0.8.3",
"log",
"metal 0.27.0",
"metal 0.28.0",
"naga",
"objc",
"once_cell",
@ -7250,8 +7270,9 @@ dependencies = [
[[package]]
name = "wgpu-types"
version = "0.19.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=32e70bc1635905c508d408eb1cf22b2aa062ffe1#32e70bc1635905c508d408eb1cf22b2aa062ffe1"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1353d9a46bff7f955a680577f34c69122628cc2076e1d6f3a9be6ef00ae793ef"
dependencies = [
"bitflags 2.5.0",
"js-sys",

View file

@ -125,8 +125,8 @@ webpki-roots = "0.25"
webrender = { git = "https://github.com/servo/webrender", branch = "0.64", features = ["capture"] }
webrender_api = { git = "https://github.com/servo/webrender", branch = "0.64" }
webrender_traits = { path = "components/shared/webrender" }
wgpu-core = { git = "https://github.com/gfx-rs/wgpu", rev = "32e70bc1635905c508d408eb1cf22b2aa062ffe1" }
wgpu-types = { git = "https://github.com/gfx-rs/wgpu", rev = "32e70bc1635905c508d408eb1cf22b2aa062ffe1" }
wgpu-core = "0.20"
wgpu-types = "0.20"
winapi = "0.3"
xi-unicode = "0.1.0"
xml5ever = "0.18"

View file

@ -268,7 +268,8 @@ impl GPUBufferMethods for GPUBuffer {
buffer_id: self.buffer.0,
device_id: self.device.id().0,
host_map,
map_range: map_range.clone(),
offset,
size: Some(range_size),
},
)) {
warn!(

View file

@ -208,14 +208,19 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-configure>
fn Configure(&self, descriptor: &GPUCanvasConfiguration) {
fn Configure(&self, descriptor: &GPUCanvasConfiguration) -> Fallible<()> {
// Step 1 is let
// Step 2
// TODO: device features
let format = match descriptor.format {
GPUTextureFormat::Rgba8unorm | GPUTextureFormat::Rgba8unorm_srgb => ImageFormat::RGBA8,
GPUTextureFormat::Bgra8unorm | GPUTextureFormat::Bgra8unorm_srgb => ImageFormat::BGRA8,
_ => panic!("SwapChain format({:?}) not supported", descriptor.format), // TODO: Better handling
_ => {
return Err(Error::Type(format!(
"SwapChain format({:?}) not supported",
descriptor.format
)))
},
};
// Step 3
@ -287,6 +292,7 @@ impl GPUCanvasContextMethods for GPUCanvasContext {
.set(Some(&descriptor.device.CreateTexture(&text_desc).unwrap()));
self.webrender_image.set(Some(receiver.recv().unwrap()));
Ok(())
}
/// <https://gpuweb.github.io/gpuweb/#dom-gpucanvascontext-unconfigure>

View file

@ -393,7 +393,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
.expect("Failed to send Finish");
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.transmute());
let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.into_command_buffer_id());
GPUCommandBuffer::new(
&self.global(),
self.channel.clone(),

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use webgpu::wgpu::command::{compute_ffi as wgpu_comp, ComputePass};
use webgpu::wgpu::command::{compute_commands as wgpu_comp, ComputePass};
use webgpu::{WebGPU, WebGPURequest};
use super::bindings::error::Fallible;
@ -120,15 +120,12 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
#[allow(unsafe_code)]
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
if let Some(compute_pass) = self.compute_pass.borrow_mut().as_mut() {
unsafe {
wgpu_comp::wgpu_compute_pass_set_bind_group(
compute_pass,
index,
bind_group.id().0,
dynamic_offsets.as_ptr(),
dynamic_offsets.len(),
&dynamic_offsets,
)
};
}
}

View file

@ -718,7 +718,9 @@ impl GPUDeviceMethods for GPUDevice {
layout,
stage: wgpu_pipe::ProgrammableStageDescriptor {
module: descriptor.compute.module.id().0,
entry_point: Cow::Owned(descriptor.compute.entryPoint.to_string()),
entry_point: Some(Cow::Owned(descriptor.compute.entryPoint.to_string())),
constants: Cow::Owned(HashMap::new()),
zero_initialize_workgroup_memory: true,
},
};
@ -921,7 +923,11 @@ impl GPUDeviceMethods for GPUDevice {
vertex: wgpu_pipe::VertexState {
stage: wgpu_pipe::ProgrammableStageDescriptor {
module: descriptor.vertex.parent.module.id().0,
entry_point: Cow::Owned(descriptor.vertex.parent.entryPoint.to_string()),
entry_point: Some(Cow::Owned(
descriptor.vertex.parent.entryPoint.to_string(),
)),
constants: Cow::Owned(HashMap::new()),
zero_initialize_workgroup_memory: true,
},
buffers: Cow::Owned(
descriptor
@ -955,7 +961,9 @@ impl GPUDeviceMethods for GPUDevice {
.map(|stage| wgpu_pipe::FragmentState {
stage: wgpu_pipe::ProgrammableStageDescriptor {
module: stage.parent.module.id().0,
entry_point: Cow::Owned(stage.parent.entryPoint.to_string()),
entry_point: Some(Cow::Owned(stage.parent.entryPoint.to_string())),
constants: Cow::Owned(HashMap::new()),
zero_initialize_workgroup_memory: true,
},
targets: Cow::Owned(
stage

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct;
use webgpu::wgpu::command::{render_ffi as wgpu_render, RenderPass};
use webgpu::wgpu::command::{render_commands as wgpu_render, RenderPass};
use webgpu::{wgt, WebGPU, WebGPURequest};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat;
@ -86,15 +86,12 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
#[allow(unsafe_code)]
fn SetBindGroup(&self, index: u32, bind_group: &GPUBindGroup, dynamic_offsets: Vec<u32>) {
if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
unsafe {
wgpu_render::wgpu_render_pass_set_bind_group(
render_pass,
index,
bind_group.id().0,
dynamic_offsets.as_ptr(),
dynamic_offsets.len(),
&dynamic_offsets,
)
};
}
}
@ -286,13 +283,7 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
fn ExecuteBundles(&self, bundles: Vec<DomRoot<GPURenderBundle>>) {
let bundle_ids = bundles.iter().map(|b| b.id().0).collect::<Vec<_>>();
if let Some(render_pass) = self.render_pass.borrow_mut().as_mut() {
unsafe {
wgpu_render::wgpu_render_pass_execute_bundles(
render_pass,
bundle_ids.as_ptr(),
bundle_ids.len(),
)
};
wgpu_render::wgpu_render_pass_execute_bundles(render_pass, &bundle_ids)
}
}
}

View file

@ -1048,6 +1048,7 @@ interface GPUCanvasContext {
// Calling configure() a second time invalidates the previous one,
// and all of the textures it's produced.
[Throws]
undefined configure(GPUCanvasConfiguration descriptor);
undefined unconfigure();

View file

@ -2125,7 +2125,7 @@ impl ScriptThread {
WebGPUMsg::FreeCommandBuffer(id) => self
.gpu_id_hub
.lock()
.kill_command_buffer_id(id.transmute()),
.kill_command_buffer_id(id.into_command_encoder_id()),
WebGPUMsg::FreeSampler(id) => self.gpu_id_hub.lock().kill_sampler_id(id),
WebGPUMsg::FreeShaderModule(id) => self.gpu_id_hub.lock().kill_shader_module_id(id),
WebGPUMsg::FreeRenderBundle(id) => self.gpu_id_hub.lock().kill_render_bundle_id(id),

View file

@ -81,7 +81,8 @@ pub enum WebGPURequest {
buffer_id: id::BufferId,
device_id: id::DeviceId,
host_map: HostMap,
map_range: std::ops::Range<u64>,
offset: u64,
size: Option<u64>,
},
CommandEncoderFinish {
command_encoder_id: id::CommandEncoderId,
@ -407,7 +408,8 @@ impl WGPU {
buffer_id,
device_id,
host_map,
map_range,
offset,
size,
} => {
let glob = Arc::clone(&self.global);
let resp_sender = sender.clone();
@ -447,7 +449,12 @@ impl WGPU {
callback: Some(callback),
};
let global = &self.global;
let result = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, map_range, operation));
let result = gfx_select!(buffer_id => global.buffer_map_async(
buffer_id,
offset,
size,
operation
));
if let Err(ref e) = result {
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
warn!("Failed to send BufferMapAsync Response ({:?})", w);
@ -839,7 +846,7 @@ impl WGPU {
WebGPURequest::DropCommandBuffer(id) => {
self.error_command_encoders
.borrow_mut()
.remove(&id.transmute());
.remove(&id.into_command_encoder_id());
let global = &self.global;
gfx_select!(id => global.command_buffer_drop(id));
if let Err(e) = self.script_sender.send(WebGPUMsg::FreeCommandBuffer(id)) {
@ -1004,7 +1011,7 @@ impl WGPU {
let cmd_id = command_buffers.iter().find(|id| {
self.error_command_encoders
.borrow()
.contains_key(&id.transmute())
.contains_key(&id.into_command_encoder_id())
});
let result = if cmd_id.is_some() {
Err(String::from("Invalid command buffer submitted"))
@ -1108,7 +1115,7 @@ impl WGPU {
));
let _ = gfx_select!(queue_id => global.queue_submit(
queue_id,
&[encoder_id.transmute()]
&[encoder_id.into_command_buffer_id()]
));
let glob = Arc::clone(&self.global);
@ -1161,7 +1168,8 @@ impl WGPU {
host: HostMap::Read,
callback: Some(callback),
};
let _ = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, 0..buffer_size, map_op));
let _ = gfx_select!(buffer_id
=> global.buffer_map_async(buffer_id, 0, Some(buffer_size), map_op));
},
WebGPURequest::UnmapBuffer {
buffer_id,
@ -1458,3 +1466,21 @@ pub struct PresentationData {
image_desc: ImageDescriptor,
image_data: ImageData,
}
pub trait Transmute<U: id::Marker> {
fn transmute(self) -> id::Id<U>;
}
impl Transmute<id::markers::Queue> for id::Id<id::markers::Device> {
fn transmute(self) -> id::Id<id::markers::Queue> {
// if this is removed next one should be removed too.
self.into_queue_id()
}
}
impl Transmute<id::markers::Device> for id::Id<id::markers::Queue> {
fn transmute(self) -> id::Id<id::markers::Device> {
// SAFETY: This is safe because queue_id = device_id in wgpu
unsafe { id::Id::from_raw(self.into_raw()) }
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,2 +1,6 @@
[canvas_clear.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_colorspace_rgba16float.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_complex_rgba16float_copy.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_complex_rgba16float_draw.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_complex_rgba16float_store.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_composite_alpha_rgba16float_opaque_copy.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_composite_alpha_rgba16float_opaque_draw.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_composite_alpha_rgba16float_premultiplied_copy.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH

View file

@ -1,2 +1,6 @@
[canvas_composite_alpha_rgba16float_premultiplied_draw.https.html]
expected: CRASH
expected:
if os == "win": CRASH
if os == "linux" and debug: CRASH
if os == "linux" and not debug: TIMEOUT
if os == "mac": CRASH