diff options
author | webbeef <me@webbeef.org> | 2025-03-23 11:52:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-23 18:52:46 +0000 |
commit | 1c9f486f88b23b575317ee0b2462e26fba07c5f4 (patch) | |
tree | 17274d9605e8ea494623bafe6755ce5cccaaf245 /components/webgpu/ipc_messages | |
parent | 4814cbdb1f09e97be70f7c72defee19e67fff473 (diff) | |
download | servo-1c9f486f88b23b575317ee0b2462e26fba07c5f4.tar.gz servo-1c9f486f88b23b575317ee0b2462e26fba07c5f4.zip |
webgpu: leverage routed_promise in calls returning promises (#35859)
Using the RoutedPromiseListener let us define a different
response type for each promise. This removes unreachable branches
that used to exist when they all shared the same WebGPUResponse.
Signed-off-by: webbeef <me@webbeef.org>
Diffstat (limited to 'components/webgpu/ipc_messages')
-rw-r--r-- | components/webgpu/ipc_messages/recv.rs | 23 | ||||
-rw-r--r-- | components/webgpu/ipc_messages/to_dom.rs | 32 |
2 files changed, 25 insertions, 30 deletions
diff --git a/components/webgpu/ipc_messages/recv.rs b/components/webgpu/ipc_messages/recv.rs index 62399d87e21..ce69080760e 100644 --- a/components/webgpu/ipc_messages/recv.rs +++ b/components/webgpu/ipc_messages/recv.rs @@ -32,7 +32,12 @@ pub use {wgpu_core as wgc, wgpu_types as wgt}; use crate::identity::*; use crate::render_commands::RenderCommand; use crate::swapchain::WebGPUContextId; -use crate::{Error, ErrorFilter, Mapping, PRESENTATION_BUFFER_COUNT, WebGPUResponse}; +use crate::wgc::resource::BufferAccessError; +use crate::{ + Error, ErrorFilter, Mapping, PRESENTATION_BUFFER_COUNT, ShaderCompilationInfo, + WebGPUAdapterResponse, WebGPUComputePipelineResponse, WebGPUDeviceResponse, + WebGPUPoppedErrorScopeResponse, WebGPURenderPipelineResponse, +}; #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub struct ContextConfiguration { @@ -45,7 +50,7 @@ pub struct ContextConfiguration { #[derive(Debug, Deserialize, Serialize)] pub enum WebGPURequest { BufferMapAsync { - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<Result<Mapping, BufferAccessError>>, buffer_id: id::BufferId, device_id: id::DeviceId, host_map: HostMap, @@ -109,7 +114,7 @@ pub enum WebGPURequest { descriptor: ComputePipelineDescriptor<'static>, implicit_ids: Option<(id::PipelineLayoutId, Vec<id::BindGroupLayoutId>)>, /// present only on ASYNC versions - async_sender: Option<IpcSender<WebGPUResponse>>, + async_sender: Option<IpcSender<WebGPUComputePipelineResponse>>, }, CreatePipelineLayout { device_id: id::DeviceId, @@ -122,7 +127,7 @@ pub enum WebGPURequest { descriptor: RenderPipelineDescriptor<'static>, implicit_ids: Option<(id::PipelineLayoutId, Vec<id::BindGroupLayoutId>)>, /// present only on ASYNC versions - async_sender: Option<IpcSender<WebGPUResponse>>, + async_sender: Option<IpcSender<WebGPURenderPipelineResponse>>, }, CreateSampler { device_id: id::DeviceId, @@ -134,7 +139,7 @@ pub enum WebGPURequest { program_id: id::ShaderModuleId, program: String, label: Option<String>, - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<Option<ShaderCompilationInfo>>, }, /// Creates context CreateContext { @@ -206,12 +211,12 @@ pub enum WebGPURequest { device_id: id::DeviceId, }, RequestAdapter { - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<WebGPUAdapterResponse>, options: RequestAdapterOptions, adapter_id: AdapterId, }, RequestDevice { - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<WebGPUDeviceResponse>, adapter_id: WebGPUAdapter, descriptor: wgt::DeviceDescriptor<Option<String>>, device_id: id::DeviceId, @@ -300,7 +305,7 @@ pub enum WebGPURequest { data: IpcSharedMemory, }, QueueOnSubmittedWorkDone { - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<()>, queue_id: id::QueueId, }, PushErrorScope { @@ -313,7 +318,7 @@ pub enum WebGPURequest { }, PopErrorScope { device_id: id::DeviceId, - sender: IpcSender<WebGPUResponse>, + sender: IpcSender<WebGPUPoppedErrorScopeResponse>, }, ComputeGetBindGroupLayout { device_id: id::DeviceId, diff --git a/components/webgpu/ipc_messages/to_dom.rs b/components/webgpu/ipc_messages/to_dom.rs index 8525a46d78c..5dfa2e1abca 100644 --- a/components/webgpu/ipc_messages/to_dom.rs +++ b/components/webgpu/ipc_messages/to_dom.rs @@ -12,7 +12,6 @@ use wgc::id; use wgc::pipeline::CreateShaderModuleError; use wgpu_core::device::HostMap; use wgpu_core::instance::{RequestAdapterError, RequestDeviceError}; -use wgpu_core::resource::BufferAccessError; pub use {wgpu_core as wgc, wgpu_types as wgt}; use crate::identity::*; @@ -82,23 +81,14 @@ pub struct Mapping { pub range: Range<u64>, } -#[derive(Debug, Deserialize, Serialize)] -#[allow(clippy::large_enum_variant)] -pub enum WebGPUResponse { - /// WebGPU is disabled - None, - Adapter(Result<Adapter, RequestAdapterError>), - Device( - ( - WebGPUDevice, - WebGPUQueue, - Result<wgt::DeviceDescriptor<Option<String>>, RequestDeviceError>, - ), - ), - BufferMapAsync(Result<Mapping, BufferAccessError>), - SubmittedWorkDone, - PoppedErrorScope(Result<Option<Error>, PopError>), - CompilationInfo(Option<ShaderCompilationInfo>), - RenderPipeline(Result<Pipeline<id::RenderPipelineId>, Error>), - ComputePipeline(Result<Pipeline<id::ComputePipelineId>, Error>), -} +pub type WebGPUDeviceResponse = ( + WebGPUDevice, + WebGPUQueue, + Result<wgt::DeviceDescriptor<Option<String>>, RequestDeviceError>, +); + +pub type WebGPUAdapterResponse = Option<Result<Adapter, RequestAdapterError>>; + +pub type WebGPUPoppedErrorScopeResponse = Result<Option<Error>, PopError>; +pub type WebGPURenderPipelineResponse = Result<Pipeline<id::RenderPipelineId>, Error>; +pub type WebGPUComputePipelineResponse = Result<Pipeline<id::ComputePipelineId>, Error>; |