diff --git a/Cargo.lock b/Cargo.lock index 5b60536f470..337857c1efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6814,6 +6814,7 @@ dependencies = [ [[package]] name = "wgpu-core" version = "0.5.0" +source = "git+https://github.com/gfx-rs/wgpu#fc4baa31072f96479f691a8d134eaf4ceb418df3" dependencies = [ "arrayvec 0.5.1", "bitflags", @@ -6841,6 +6842,7 @@ dependencies = [ [[package]] name = "wgpu-types" version = "0.5.0" +source = "git+https://github.com/gfx-rs/wgpu#fc4baa31072f96479f691a8d134eaf4ceb418df3" dependencies = [ "bitflags", "serde", diff --git a/Cargo.toml b/Cargo.toml index 9d4825bb93f..d4697cac43f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,3 @@ mio = { git = "https://github.com/servo/mio.git", branch = "servo-mio-0.6.22" } [patch."https://github.com/servo/webrender"] webrender = { git = "https://github.com/jdm/webrender", branch = "crash-backtrace" } webrender_api = { git = "https://github.com/jdm/webrender", branch = "crash-backtrace" } - -[patch."https://github.com/gfx-rs/wgpu"] -wgpu-core = {path="../wgpu/wgpu-core"} -wgpu-types = {path="../wgpu/wgpu-types"} diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs index dc19e160f8a..121e96b4a0e 100644 --- a/components/script/dom/bindings/trace.rs +++ b/components/script/dom/bindings/trace.rs @@ -165,6 +165,7 @@ use time::{Duration, Timespec, Tm}; use uuid::Uuid; use webgpu::{ wgpu::command::{ComputePass, RenderPass}, + wgt::BindGroupLayoutEntry, WebGPU, WebGPUAdapter, WebGPUBindGroup, WebGPUBindGroupLayout, WebGPUBuffer, WebGPUCommandBuffer, WebGPUCommandEncoder, WebGPUComputePipeline, WebGPUDevice, WebGPUPipelineLayout, WebGPUQueue, WebGPURenderPipeline, WebGPUSampler, WebGPUShaderModule, @@ -579,6 +580,7 @@ unsafe_no_jsmanaged_fields!(WebGPUContextId); unsafe_no_jsmanaged_fields!(WebGPUCommandBuffer); unsafe_no_jsmanaged_fields!(WebGPUCommandEncoder); unsafe_no_jsmanaged_fields!(WebGPUDevice); +unsafe_no_jsmanaged_fields!(BindGroupLayoutEntry); unsafe_no_jsmanaged_fields!(Option); unsafe_no_jsmanaged_fields!(Option); unsafe_no_jsmanaged_fields!(GPUBufferState); diff --git a/components/script/dom/gpudevice.rs b/components/script/dom/gpudevice.rs index cda3b5a586d..503360ab649 100644 --- a/components/script/dom/gpudevice.rs +++ b/components/script/dom/gpudevice.rs @@ -95,6 +95,8 @@ pub struct GPUDevice { next_scope_id: Cell, #[ignore_malloc_size_of = "promises are hard"] lost_promise: DomRefCell>>, + #[ignore_malloc_size_of = "defined in webgpu"] + bind_group_layouts: DomRefCell, Dom)>>, } impl GPUDevice { @@ -119,6 +121,7 @@ impl GPUDevice { scope_stack: DomRefCell::new(Vec::new()), next_scope_id: Cell::new(0), lost_promise: DomRefCell::new(None), + bind_group_layouts: DomRefCell::new(Vec::new()), } } @@ -362,6 +365,18 @@ impl GPUDeviceMethods for GPUDevice { warn!("Could not find Error Scope for id {}", s_id); } } + // Check for equivalent GPUBindGroupLayout + { + for (bgl_ent, bgl) in self.bind_group_layouts.borrow().iter() { + if *bgl_ent == entries { + let layout = DomRoot::from_ref(&**bgl); + if let Some(i) = scope_id { + self.handle_server_msg(i, Ok(())); + } + return layout; + } + } + } let bind_group_layout_id = self .global() @@ -373,14 +388,20 @@ impl GPUDeviceMethods for GPUDevice { .send(WebGPURequest::CreateBindGroupLayout { device_id: self.device.0, bind_group_layout_id, - entries, + entries: entries.clone(), scope_id, }) .expect("Failed to create WebGPU BindGroupLayout"); let bgl = webgpu::WebGPUBindGroupLayout(bind_group_layout_id); - GPUBindGroupLayout::new(&self.global(), bgl, true) + let layout = GPUBindGroupLayout::new(&self.global(), bgl, true); + + self.bind_group_layouts + .borrow_mut() + .push((entries, Dom::from_ref(&*layout))); + + layout } /// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createpipelinelayout