Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webgpu: Update to wgpu 0.20 #32173

Merged
merged 5 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 39 additions & 18 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 @@ -126,8 +126,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 @@ -8,7 +8,7 @@ use std::collections::HashSet;

use dom_struct::dom_struct;
use webgpu::wgpu::command as wgpu_com;
use webgpu::{self, wgt, WebGPU, WebGPURequest};
use webgpu::{self, wgt, Transmute, WebGPU, WebGPURequest};

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
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
1 change: 1 addition & 0 deletions components/script/script_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ use style::thread_state::{self, ThreadState};
use time::precise_time_ns;
use url::Position;
use webgpu::identity::WebGPUMsg;
use webgpu::Transmute;
use webrender_api::units::LayoutPixel;
use webrender_api::DocumentId;

Expand Down