mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
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>
This commit is contained in:
parent
4814cbdb1f
commit
1c9f486f88
15 changed files with 221 additions and 263 deletions
|
@ -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,
|
||||
|
|
|
@ -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>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue