diff options
author | Samson <16504129+sagudev@users.noreply.github.com> | 2024-06-28 06:49:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-28 04:49:35 +0000 |
commit | e9cf4d4971c0ce8ec64da7f09d6e97ae10be5b05 (patch) | |
tree | fb9f0179cfe93744118835c3a34edc8c19672a3e /components/script/dom/gpucommandencoder.rs | |
parent | fced0b49404c02bb5aafa9ddd468f9077ce26c19 (diff) | |
download | servo-e9cf4d4971c0ce8ec64da7f09d6e97ae10be5b05.tar.gz servo-e9cf4d4971c0ce8ec64da7f09d6e97ae10be5b05.zip |
webgpu: Update wgpu and revamp computepass (#32575)
* Do not wait on drop, but rather wake poller thread
* Update wgpu and render stuff
* Set some good expectations
* Update wgpu again
* handle IPC error as warning
* More good expectations
* Some more expectations
CTS does not match the spec: https://github.com/gpuweb/cts/issues/3806
* This expectations are due to other changes in servo
also happening on main
* Explain error_command_encoders and remove RefCell around it
* fixup
* store validness of passes
* More good expectations
* More docs
* this assert is wrong
* This is even more right per CTS/spec
Only Command encoder state errors are allowed here, but wgpu does not exposes them.
* More good expectations
* One bad expectation
* Fix my english
Diffstat (limited to 'components/script/dom/gpucommandencoder.rs')
-rw-r--r-- | components/script/dom/gpucommandencoder.rs | 84 |
1 files changed, 18 insertions, 66 deletions
diff --git a/components/script/dom/gpucommandencoder.rs b/components/script/dom/gpucommandencoder.rs index 799db233a28..5024f9ff9f9 100644 --- a/components/script/dom/gpucommandencoder.rs +++ b/components/script/dom/gpucommandencoder.rs @@ -8,8 +8,9 @@ use std::collections::HashSet; use dom_struct::dom_struct; use webgpu::wgc::command as wgpu_com; -use webgpu::{self, wgt, WebGPU, WebGPURequest}; +use webgpu::{self, wgt, WebGPU, WebGPUComputePass, WebGPURequest}; +use super::gpuconvert::convert_label; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor, GPUExtent3D, @@ -31,16 +32,6 @@ use crate::dom::gpuconvert::{ use crate::dom::gpudevice::GPUDevice; use crate::dom::gpurenderpassencoder::GPURenderPassEncoder; -// TODO(sagudev): this is different now -// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state -#[derive(MallocSizeOf, PartialEq)] -pub enum GPUCommandEncoderState { - Open, - EncodingRenderPass, - EncodingComputePass, - Closed, -} - #[dom_struct] pub struct GPUCommandEncoder { reflector_: Reflector, @@ -51,7 +42,6 @@ pub struct GPUCommandEncoder { #[no_trace] encoder: webgpu::WebGPUCommandEncoder, buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>, - state: DomRefCell<GPUCommandEncoderState>, device: Dom<GPUDevice>, valid: Cell<bool>, } @@ -70,7 +60,6 @@ impl GPUCommandEncoder { device: Dom::from_ref(device), encoder, buffers: DomRefCell::new(HashSet::new()), - state: DomRefCell::new(GPUCommandEncoderState::Open), valid: Cell::new(true), } } @@ -96,13 +85,8 @@ impl GPUCommandEncoder { self.encoder } - pub fn set_state(&self, set: GPUCommandEncoderState, expect: GPUCommandEncoderState) { - if *self.state.borrow() == expect { - *self.state.borrow_mut() = set; - } else { - self.valid.set(false); - *self.state.borrow_mut() = GPUCommandEncoderState::Closed; - } + pub fn device_id(&self) -> webgpu::WebGPUDevice { + self.device.id() } } @@ -122,32 +106,26 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { &self, descriptor: &GPUComputePassDescriptor, ) -> DomRoot<GPUComputePassEncoder> { - self.set_state( - GPUCommandEncoderState::EncodingComputePass, - GPUCommandEncoderState::Open, - ); + let compute_pass_id = self + .global() + .wgpu_id_hub() + .lock() + .create_compute_pass_id(self.device.id().0.backend()); - let compute_pass = if !self.valid.get() { - None - } else { - Some(wgpu_com::ComputePass::new( - self.encoder.0, - &wgpu_com::ComputePassDescriptor { - label: descriptor - .parent - .label - .as_ref() - .map(|l| Cow::Borrowed(&**l)), - timestamp_writes: None, - }, - )) - }; + if let Err(e) = self.channel.0.send(WebGPURequest::BeginComputePass { + command_encoder_id: self.id().0, + compute_pass_id, + label: convert_label(&descriptor.parent), + device_id: self.device.id().0, + }) { + warn!("Failed to send WebGPURequest::BeginComputePass {e:?}"); + } GPUComputePassEncoder::new( &self.global(), self.channel.clone(), self, - compute_pass, + WebGPUComputePass(compute_pass_id), descriptor.parent.label.clone().unwrap_or_default(), ) } @@ -157,11 +135,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { &self, descriptor: &GPURenderPassDescriptor, ) -> DomRoot<GPURenderPassEncoder> { - self.set_state( - GPUCommandEncoderState::EncodingRenderPass, - GPUCommandEncoderState::Open, - ); - let render_pass = if !self.valid.get() { None } else { @@ -259,11 +232,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { destination_offset: GPUSize64, size: GPUSize64, ) { - if !(*self.state.borrow() == GPUCommandEncoderState::Open) { - self.valid.set(false); - return; - } - self.buffers.borrow_mut().insert(DomRoot::from_ref(source)); self.buffers .borrow_mut() @@ -288,11 +256,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { destination: &GPUImageCopyTexture, copy_size: GPUExtent3D, ) { - if !(*self.state.borrow() == GPUCommandEncoderState::Open) { - self.valid.set(false); - return; - } - self.buffers .borrow_mut() .insert(DomRoot::from_ref(&*source.buffer)); @@ -315,11 +278,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { destination: &GPUImageCopyBuffer, copy_size: GPUExtent3D, ) { - if !(*self.state.borrow() == GPUCommandEncoderState::Open) { - self.valid.set(false); - return; - } - self.buffers .borrow_mut() .insert(DomRoot::from_ref(&*destination.buffer)); @@ -342,11 +300,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { destination: &GPUImageCopyTexture, copy_size: GPUExtent3D, ) { - if !(*self.state.borrow() == GPUCommandEncoderState::Open) { - self.valid.set(false); - return; - } - self.channel .0 .send(WebGPURequest::CopyTextureToTexture { @@ -371,7 +324,6 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder { }) .expect("Failed to send Finish"); - *self.state.borrow_mut() = GPUCommandEncoderState::Closed; let buffer = webgpu::WebGPUCommandBuffer(self.encoder.0.into_command_buffer_id()); GPUCommandBuffer::new( &self.global(), |