Skip to content

Commit

Permalink
Update wgpu to 0.20
Browse files Browse the repository at this point in the history
  • Loading branch information
sagudev committed Apr 29, 2024
1 parent 9599aeb commit 011ee7a
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 58 deletions.
61 changes: 41 additions & 20 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.17"
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
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/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
46 changes: 42 additions & 4 deletions components/webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1458,3 +1466,33 @@ 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()) }
}
}

impl Transmute<id::markers::CommandBuffer> for id::Id<id::markers::CommandEncoder> {
fn transmute(self) -> id::Id<id::markers::CommandBuffer> {
self.into_command_buffer_id()
}
}

impl Transmute<id::markers::CommandEncoder> for id::Id<id::markers::CommandBuffer> {
fn transmute(self) -> id::Id<id::markers::CommandEncoder> {
self.into_command_encoder_id()
}
}

0 comments on commit 011ee7a

Please sign in to comment.