Skip to content

Commit

Permalink
webgpu: Update to wgpu 0.20 (#32173)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
sagudev committed May 8, 2024
1 parent 5298ccb commit c4f8599
Show file tree
Hide file tree
Showing 21 changed files with 2,122 additions and 1,422 deletions.
55 changes: 38 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion components/script/dom/gpubuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
10 changes: 8 additions & 2 deletions components/script/dom/gpucanvascontext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/gpucommandencoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 7 additions & 10 deletions components/script/dom/gpucomputepassencoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
)
};
wgpu_comp::wgpu_compute_pass_set_bind_group(
compute_pass,
index,
bind_group.id().0,
&dynamic_offsets,
)
}
}

Expand Down
14 changes: 11 additions & 3 deletions components/script/dom/gpudevice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 8 additions & 17 deletions components/script/dom/gpurenderpassencoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
)
};
wgpu_render::wgpu_render_pass_set_bind_group(
render_pass,
index,
bind_group.id().0,
&dynamic_offsets,
)
}
}

Expand Down Expand Up @@ -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)
}
}
}
1 change: 1 addition & 0 deletions components/script/dom/webidls/WebGPU.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion components/script/script_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit c4f8599

Please sign in to comment.