mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Less nesting in webgpu response (#32799)
* Remove Option wrap of WebGPUResponse Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Replace WebGPUResponseResult with WebGPUResponse Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
1223335547
commit
34eed29037
11 changed files with 196 additions and 214 deletions
|
@ -152,7 +152,7 @@ use servo_config::{opts, pref};
|
||||||
use servo_rand::{random, Rng, ServoRng, SliceRandom};
|
use servo_rand::{random, Rng, ServoRng, SliceRandom};
|
||||||
use servo_url::{Host, ImmutableOrigin, ServoUrl};
|
use servo_url::{Host, ImmutableOrigin, ServoUrl};
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
use webgpu::{self, WebGPU, WebGPURequest};
|
use webgpu::{self, WebGPU, WebGPURequest, WebGPUResponse};
|
||||||
use webrender::{RenderApi, RenderApiSender};
|
use webrender::{RenderApi, RenderApiSender};
|
||||||
use webrender_api::DocumentId;
|
use webrender_api::DocumentId;
|
||||||
use webrender_traits::{WebRenderNetApi, WebRenderScriptApi, WebrenderExternalImageRegistry};
|
use webrender_traits::{WebRenderNetApi, WebRenderScriptApi, WebrenderExternalImageRegistry};
|
||||||
|
@ -2069,7 +2069,7 @@ where
|
||||||
match request {
|
match request {
|
||||||
FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
|
FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
|
||||||
None => {
|
None => {
|
||||||
if let Err(e) = response_sender.send(None) {
|
if let Err(e) = response_sender.send(WebGPUResponse::None) {
|
||||||
warn!("Failed to send request adapter message: {}", e)
|
warn!("Failed to send request adapter message: {}", e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ use ipc_channel::router::ROUTER;
|
||||||
use js::jsapi::Heap;
|
use js::jsapi::Heap;
|
||||||
use script_traits::ScriptMsg;
|
use script_traits::ScriptMsg;
|
||||||
use webgpu::wgt::PowerPreference;
|
use webgpu::wgt::PowerPreference;
|
||||||
use webgpu::{wgc, WebGPUResponse, WebGPUResponseResult};
|
use webgpu::{wgc, WebGPUResponse};
|
||||||
|
|
||||||
use super::bindings::codegen::Bindings::WebGPUBinding::GPUTextureFormat;
|
use super::bindings::codegen::Bindings::WebGPUBinding::GPUTextureFormat;
|
||||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||||
|
@ -45,7 +45,7 @@ impl GPU {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait AsyncWGPUListener {
|
pub trait AsyncWGPUListener {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>);
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WGPUResponse<T: AsyncWGPUListener + DomObject> {
|
struct WGPUResponse<T: AsyncWGPUListener + DomObject> {
|
||||||
|
@ -55,7 +55,7 @@ struct WGPUResponse<T: AsyncWGPUListener + DomObject> {
|
||||||
|
|
||||||
impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
|
impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
|
||||||
#[allow(crown::unrooted_must_root)]
|
#[allow(crown::unrooted_must_root)]
|
||||||
fn response(self, response: Option<WebGPUResponseResult>) {
|
fn response(self, response: WebGPUResponse) {
|
||||||
let promise = self.trusted.root();
|
let promise = self.trusted.root();
|
||||||
self.receiver.root().handle_response(response, &promise);
|
self.receiver.root().handle_response(response, &promise);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
|
||||||
pub fn response_async<T: AsyncWGPUListener + DomObject + 'static>(
|
pub fn response_async<T: AsyncWGPUListener + DomObject + 'static>(
|
||||||
promise: &Rc<Promise>,
|
promise: &Rc<Promise>,
|
||||||
receiver: &T,
|
receiver: &T,
|
||||||
) -> IpcSender<Option<WebGPUResponseResult>> {
|
) -> IpcSender<WebGPUResponse> {
|
||||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||||
let task_source = receiver.global().dom_manipulation_task_source();
|
let task_source = receiver.global().dom_manipulation_task_source();
|
||||||
let canceller = receiver
|
let canceller = receiver
|
||||||
|
@ -139,42 +139,34 @@ impl GPUMethods for GPU {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPU {
|
impl AsyncWGPUListener for GPU {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
match response {
|
match response {
|
||||||
Some(response) => match response {
|
WebGPUResponse::Adapter(Ok(adapter)) => {
|
||||||
Ok(WebGPUResponse::RequestAdapter {
|
|
||||||
adapter_info,
|
|
||||||
adapter_id,
|
|
||||||
features,
|
|
||||||
limits,
|
|
||||||
channel,
|
|
||||||
}) => {
|
|
||||||
let adapter = GPUAdapter::new(
|
let adapter = GPUAdapter::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
channel,
|
adapter.channel,
|
||||||
DOMString::from(format!(
|
DOMString::from(format!(
|
||||||
"{} ({:?})",
|
"{} ({:?})",
|
||||||
adapter_info.name,
|
adapter.adapter_info.name,
|
||||||
adapter_id.0.backend()
|
adapter.adapter_id.0.backend()
|
||||||
)),
|
)),
|
||||||
Heap::default(),
|
Heap::default(),
|
||||||
features,
|
adapter.features,
|
||||||
limits,
|
adapter.limits,
|
||||||
adapter_info,
|
adapter.adapter_info,
|
||||||
adapter_id,
|
adapter.adapter_id,
|
||||||
);
|
);
|
||||||
promise.resolve_native(&adapter);
|
promise.resolve_native(&adapter);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
WebGPUResponse::Adapter(Err(e)) => {
|
||||||
warn!("Could not get GPUAdapter ({:?})", e);
|
warn!("Could not get GPUAdapter ({:?})", e);
|
||||||
promise.resolve_native(&None::<GPUAdapter>);
|
promise.resolve_native(&None::<GPUAdapter>);
|
||||||
},
|
},
|
||||||
Ok(_) => unreachable!("GPU received wrong WebGPUResponse"),
|
WebGPUResponse::None => {
|
||||||
},
|
|
||||||
None => {
|
|
||||||
warn!("Couldn't get a response, because WebGPU is disabled");
|
warn!("Couldn't get a response, because WebGPU is disabled");
|
||||||
promise.resolve_native(&None::<GPUAdapter>);
|
promise.resolve_native(&None::<GPUAdapter>);
|
||||||
},
|
},
|
||||||
|
_ => unreachable!("GPU received wrong WebGPUResponse"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use std::rc::Rc;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use js::jsapi::{Heap, JSObject};
|
use js::jsapi::{Heap, JSObject};
|
||||||
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
|
use webgpu::{wgt, WebGPU, WebGPUAdapter, WebGPURequest, WebGPUResponse};
|
||||||
|
|
||||||
use super::gpusupportedfeatures::GPUSupportedFeatures;
|
use super::gpusupportedfeatures::GPUSupportedFeatures;
|
||||||
use super::types::{GPUAdapterInfo, GPUSupportedLimits};
|
use super::types::{GPUAdapterInfo, GPUSupportedLimits};
|
||||||
|
@ -263,14 +263,10 @@ impl GPUAdapterMethods for GPUAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPUAdapter {
|
impl AsyncWGPUListener for GPUAdapter {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
match response {
|
match response {
|
||||||
Some(response) => match response {
|
WebGPUResponse::Device(Ok(device)) => {
|
||||||
Ok(WebGPUResponse::RequestDevice {
|
let descriptor = device.descriptor;
|
||||||
device_id,
|
|
||||||
queue_id,
|
|
||||||
descriptor,
|
|
||||||
}) => {
|
|
||||||
let device = GPUDevice::new(
|
let device = GPUDevice::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
self.channel.clone(),
|
self.channel.clone(),
|
||||||
|
@ -278,20 +274,19 @@ impl AsyncWGPUListener for GPUAdapter {
|
||||||
Heap::default(),
|
Heap::default(),
|
||||||
descriptor.required_features,
|
descriptor.required_features,
|
||||||
descriptor.required_limits,
|
descriptor.required_limits,
|
||||||
device_id,
|
device.device_id,
|
||||||
queue_id,
|
device.queue_id,
|
||||||
descriptor.label.unwrap_or_default(),
|
descriptor.label.unwrap_or_default(),
|
||||||
);
|
);
|
||||||
self.global().add_gpu_device(&device);
|
self.global().add_gpu_device(&device);
|
||||||
promise.resolve_native(&device);
|
promise.resolve_native(&device);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
WebGPUResponse::Device(Err(e)) => {
|
||||||
warn!("Could not get GPUDevice({:?})", e);
|
warn!("Could not get GPUDevice({:?})", e);
|
||||||
promise.reject_error(Error::Operation);
|
promise.reject_error(Error::Operation);
|
||||||
},
|
},
|
||||||
Ok(_) => unreachable!("GPUAdapter received wrong WebGPUResponse"),
|
WebGPUResponse::None => unreachable!("Failed to get a response for RequestDevice"),
|
||||||
},
|
_ => unreachable!("GPUAdapter received wrong WebGPUResponse"),
|
||||||
None => unreachable!("Failed to get a response for RequestDevice"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc::IpcSharedMemory;
|
use ipc_channel::ipc::IpcSharedMemory;
|
||||||
use js::typedarray::{ArrayBuffer, ArrayBufferU8};
|
use js::typedarray::{ArrayBuffer, ArrayBufferU8};
|
||||||
use webgpu::wgc::device::HostMap;
|
use webgpu::wgc::device::HostMap;
|
||||||
use webgpu::{WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
|
use webgpu::{WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse};
|
||||||
|
|
||||||
use super::bindings::buffer_source::{create_new_external_array_buffer, HeapBufferSource};
|
use super::bindings::buffer_source::{create_new_external_array_buffer, HeapBufferSource};
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
@ -350,10 +350,9 @@ impl GPUBufferMethods for GPUBuffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPUBuffer {
|
impl AsyncWGPUListener for GPUBuffer {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
match response {
|
match response {
|
||||||
Some(response) => match response {
|
WebGPUResponse::BufferMapAsync(Ok(bytes)) => {
|
||||||
Ok(WebGPUResponse::BufferMapAsync(bytes)) => {
|
|
||||||
*self
|
*self
|
||||||
.map_info
|
.map_info
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -366,13 +365,11 @@ impl AsyncWGPUListener for GPUBuffer {
|
||||||
promise.resolve_native(&());
|
promise.resolve_native(&());
|
||||||
self.state.set(GPUBufferState::Mapped);
|
self.state.set(GPUBufferState::Mapped);
|
||||||
},
|
},
|
||||||
Err(e) => {
|
WebGPUResponse::BufferMapAsync(Err(e)) => {
|
||||||
warn!("Could not map buffer({:?})", e);
|
warn!("Could not map buffer({:?})", e);
|
||||||
promise.reject_error(Error::Abort);
|
promise.reject_error(Error::Abort);
|
||||||
},
|
},
|
||||||
Ok(_) => unreachable!("GPUBuffer received wrong WebGPUResponse"),
|
_ => unreachable!("GPUBuffer received wrong WebGPUResponse"),
|
||||||
},
|
|
||||||
None => unreachable!("Failed to get a response for BufferMapAsync"),
|
|
||||||
}
|
}
|
||||||
*self.map_promise.borrow_mut() = None;
|
*self.map_promise.borrow_mut() = None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ use webgpu::wgc::id::{BindGroupLayoutId, PipelineLayoutId};
|
||||||
use webgpu::wgc::{
|
use webgpu::wgc::{
|
||||||
binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res,
|
binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res,
|
||||||
};
|
};
|
||||||
use webgpu::{self, wgt, PopError, WebGPU, WebGPURequest, WebGPUResponse, WebGPUResponseResult};
|
use webgpu::{self, wgt, PopError, WebGPU, WebGPURequest, WebGPUResponse};
|
||||||
|
|
||||||
use super::bindings::codegen::UnionTypes::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
use super::bindings::codegen::UnionTypes::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||||
use super::bindings::error::Fallible;
|
use super::bindings::error::Fallible;
|
||||||
|
@ -1010,9 +1010,9 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPUDevice {
|
impl AsyncWGPUListener for GPUDevice {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
match response {
|
match response {
|
||||||
Some(Ok(WebGPUResponse::PoppedErrorScope(result))) => match result {
|
WebGPUResponse::PoppedErrorScope(result) => match result {
|
||||||
Ok(None) | Err(PopError::Lost) => promise.resolve_native(&None::<Option<GPUError>>),
|
Ok(None) | Err(PopError::Lost) => promise.resolve_native(&None::<Option<GPUError>>),
|
||||||
Err(PopError::Empty) => promise.reject_error(Error::Operation),
|
Err(PopError::Empty) => promise.reject_error(Error::Operation),
|
||||||
Ok(Some(error)) => {
|
Ok(Some(error)) => {
|
||||||
|
|
|
@ -206,13 +206,9 @@ impl GPUQueueMethods for GPUQueue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPUQueue {
|
impl AsyncWGPUListener for GPUQueue {
|
||||||
fn handle_response(
|
fn handle_response(&self, response: webgpu::WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
&self,
|
|
||||||
response: Option<Result<webgpu::WebGPUResponse, String>>,
|
|
||||||
promise: &Rc<Promise>,
|
|
||||||
) {
|
|
||||||
match response {
|
match response {
|
||||||
Some(Ok(WebGPUResponse::SubmittedWorkDone)) => {
|
WebGPUResponse::SubmittedWorkDone => {
|
||||||
promise.resolve_native(&());
|
promise.resolve_native(&());
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUResponseResult, WebGPUShaderModule};
|
use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUShaderModule};
|
||||||
|
|
||||||
use super::gpu::AsyncWGPUListener;
|
use super::gpu::AsyncWGPUListener;
|
||||||
use super::gpucompilationinfo::GPUCompilationInfo;
|
use super::gpucompilationinfo::GPUCompilationInfo;
|
||||||
|
@ -89,9 +89,9 @@ impl GPUShaderModuleMethods for GPUShaderModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncWGPUListener for GPUShaderModule {
|
impl AsyncWGPUListener for GPUShaderModule {
|
||||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||||
match response {
|
match response {
|
||||||
Some(Ok(WebGPUResponse::CompilationInfo(info))) => {
|
WebGPUResponse::CompilationInfo(info) => {
|
||||||
let info = GPUCompilationInfo::from(&self.global(), info);
|
let info = GPUCompilationInfo::from(&self.global(), info);
|
||||||
promise.resolve_native(&info);
|
promise.resolve_native(&info);
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
|
||||||
use servo_url::{ImmutableOrigin, ServoUrl};
|
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use style_traits::CSSPixel;
|
use style_traits::CSSPixel;
|
||||||
use webgpu::{wgc, WebGPU, WebGPUResponseResult};
|
use webgpu::{wgc, WebGPU, WebGPUResponse};
|
||||||
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -257,7 +257,7 @@ pub enum ScriptMsg {
|
||||||
MediaSessionEvent(PipelineId, MediaSessionEvent),
|
MediaSessionEvent(PipelineId, MediaSessionEvent),
|
||||||
/// Create a WebGPU Adapter instance
|
/// Create a WebGPU Adapter instance
|
||||||
RequestAdapter(
|
RequestAdapter(
|
||||||
IpcSender<Option<WebGPUResponseResult>>,
|
IpcSender<WebGPUResponse>,
|
||||||
wgc::instance::RequestAdapterOptions,
|
wgc::instance::RequestAdapterOptions,
|
||||||
SmallVec<[wgc::id::AdapterId; 4]>,
|
SmallVec<[wgc::id::AdapterId; 4]>,
|
||||||
),
|
),
|
||||||
|
|
|
@ -31,12 +31,12 @@ pub use {wgpu_core as wgc, wgpu_types as wgt};
|
||||||
|
|
||||||
use crate::identity::*;
|
use crate::identity::*;
|
||||||
use crate::render_commands::RenderCommand;
|
use crate::render_commands::RenderCommand;
|
||||||
use crate::{Error, ErrorFilter, WebGPUResponseResult, PRESENTATION_BUFFER_COUNT};
|
use crate::{Error, ErrorFilter, WebGPUResponse, PRESENTATION_BUFFER_COUNT};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
pub enum WebGPURequest {
|
pub enum WebGPURequest {
|
||||||
BufferMapAsync {
|
BufferMapAsync {
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
buffer_id: id::BufferId,
|
buffer_id: id::BufferId,
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
host_map: HostMap,
|
host_map: HostMap,
|
||||||
|
@ -126,7 +126,7 @@ pub enum WebGPURequest {
|
||||||
program_id: id::ShaderModuleId,
|
program_id: id::ShaderModuleId,
|
||||||
program: String,
|
program: String,
|
||||||
label: Option<String>,
|
label: Option<String>,
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
},
|
},
|
||||||
CreateSwapChain {
|
CreateSwapChain {
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
|
@ -182,12 +182,12 @@ pub enum WebGPURequest {
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
},
|
},
|
||||||
RequestAdapter {
|
RequestAdapter {
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
options: RequestAdapterOptions,
|
options: RequestAdapterOptions,
|
||||||
ids: SmallVec<[id::AdapterId; 4]>,
|
ids: SmallVec<[id::AdapterId; 4]>,
|
||||||
},
|
},
|
||||||
RequestDevice {
|
RequestDevice {
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
adapter_id: WebGPUAdapter,
|
adapter_id: WebGPUAdapter,
|
||||||
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
|
@ -280,7 +280,7 @@ pub enum WebGPURequest {
|
||||||
data: IpcSharedMemory,
|
data: IpcSharedMemory,
|
||||||
},
|
},
|
||||||
QueueOnSubmittedWorkDone {
|
QueueOnSubmittedWorkDone {
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
queue_id: id::QueueId,
|
queue_id: id::QueueId,
|
||||||
},
|
},
|
||||||
PushErrorScope {
|
PushErrorScope {
|
||||||
|
@ -293,6 +293,6 @@ pub enum WebGPURequest {
|
||||||
},
|
},
|
||||||
PopErrorScope {
|
PopErrorScope {
|
||||||
device_id: id::DeviceId,
|
device_id: id::DeviceId,
|
||||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
sender: IpcSender<WebGPUResponse>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,25 +54,32 @@ impl ShaderCompilationInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Adapter {
|
||||||
|
pub adapter_info: wgt::AdapterInfo,
|
||||||
|
pub adapter_id: WebGPUAdapter,
|
||||||
|
pub features: wgt::Features,
|
||||||
|
pub limits: wgt::Limits,
|
||||||
|
pub channel: WebGPU,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
pub struct Device {
|
||||||
|
pub device_id: WebGPUDevice,
|
||||||
|
pub queue_id: WebGPUQueue,
|
||||||
|
pub descriptor: wgt::DeviceDescriptor<Option<String>>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum WebGPUResponse {
|
pub enum WebGPUResponse {
|
||||||
RequestAdapter {
|
/// WebGPU is disabled
|
||||||
adapter_info: wgt::AdapterInfo,
|
None,
|
||||||
adapter_id: WebGPUAdapter,
|
// TODO: use wgpu errors
|
||||||
features: wgt::Features,
|
Adapter(Result<Adapter, String>),
|
||||||
limits: wgt::Limits,
|
Device(Result<Device, String>),
|
||||||
channel: WebGPU,
|
BufferMapAsync(Result<IpcSharedMemory, String>),
|
||||||
},
|
|
||||||
RequestDevice {
|
|
||||||
device_id: WebGPUDevice,
|
|
||||||
queue_id: WebGPUQueue,
|
|
||||||
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
|
||||||
},
|
|
||||||
BufferMapAsync(IpcSharedMemory),
|
|
||||||
SubmittedWorkDone,
|
SubmittedWorkDone,
|
||||||
PoppedErrorScope(Result<Option<Error>, PopError>),
|
PoppedErrorScope(Result<Option<Error>, PopError>),
|
||||||
CompilationInfo(Option<ShaderCompilationInfo>),
|
CompilationInfo(Option<ShaderCompilationInfo>),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ use wgc::pipeline::ShaderModuleDescriptor;
|
||||||
use wgc::resource::{BufferMapCallback, BufferMapOperation};
|
use wgc::resource::{BufferMapCallback, BufferMapOperation};
|
||||||
use wgc::{gfx_select, id};
|
use wgc::{gfx_select, id};
|
||||||
use wgpu_core::command::RenderPassDescriptor;
|
use wgpu_core::command::RenderPassDescriptor;
|
||||||
|
use wgpu_core::resource::BufferAccessResult;
|
||||||
use wgt::InstanceDescriptor;
|
use wgt::InstanceDescriptor;
|
||||||
pub use {wgpu_core as wgc, wgpu_types as wgt};
|
pub use {wgpu_core as wgc, wgpu_types as wgt};
|
||||||
|
|
||||||
|
@ -36,8 +37,8 @@ use crate::gpu_error::ErrorScope;
|
||||||
use crate::poll_thread::Poller;
|
use crate::poll_thread::Poller;
|
||||||
use crate::render_commands::apply_render_command;
|
use crate::render_commands::apply_render_command;
|
||||||
use crate::{
|
use crate::{
|
||||||
ComputePassId, Error, PopError, PresentationData, RenderPassId, Transmute, WebGPU,
|
Adapter, ComputePassId, Device, Error, PopError, PresentationData, RenderPassId, Transmute,
|
||||||
WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse,
|
WebGPU, WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const PRESENTATION_BUFFER_COUNT: usize = 10;
|
pub const PRESENTATION_BUFFER_COUNT: usize = 10;
|
||||||
|
@ -183,37 +184,33 @@ impl WGPU {
|
||||||
let glob = Arc::clone(&self.global);
|
let glob = Arc::clone(&self.global);
|
||||||
let resp_sender = sender.clone();
|
let resp_sender = sender.clone();
|
||||||
let token = self.poller.token();
|
let token = self.poller.token();
|
||||||
let callback = BufferMapCallback::from_rust(Box::from(move |result| {
|
let callback = BufferMapCallback::from_rust(Box::from(
|
||||||
|
move |result: BufferAccessResult| {
|
||||||
drop(token);
|
drop(token);
|
||||||
match result {
|
let response = result
|
||||||
Ok(()) => {
|
.and_then(|_| {
|
||||||
let global = &glob;
|
let global = &glob;
|
||||||
let (slice_pointer, range_size) = gfx_select!(buffer_id =>
|
let (slice_pointer, range_size) = gfx_select!(buffer_id =>
|
||||||
global.buffer_get_mapped_range(buffer_id, 0, None))
|
global.buffer_get_mapped_range(buffer_id, 0, None))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// SAFETY: guarantee to be safe from wgpu
|
// SAFETY: guarantee to be safe from wgpu
|
||||||
let data = unsafe {
|
let data = unsafe {
|
||||||
slice::from_raw_parts(slice_pointer, range_size as usize)
|
slice::from_raw_parts(
|
||||||
|
slice_pointer,
|
||||||
|
range_size as usize,
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Ok(IpcSharedMemory::from_bytes(data))
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string());
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
resp_sender.send(Some(Ok(WebGPUResponse::BufferMapAsync(
|
resp_sender.send(WebGPUResponse::BufferMapAsync(response))
|
||||||
IpcSharedMemory::from_bytes(data),
|
|
||||||
))))
|
|
||||||
{
|
{
|
||||||
warn!("Could not send BufferMapAsync Response ({})", e);
|
warn!("Could not send BufferMapAsync Response ({})", e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(_) => {
|
));
|
||||||
warn!("Could not map buffer({:?})", buffer_id);
|
|
||||||
if let Err(e) = resp_sender
|
|
||||||
.send(Some(Err(String::from("Failed to map Buffer"))))
|
|
||||||
{
|
|
||||||
warn!("Could not send BufferMapAsync Response ({})", e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}));
|
|
||||||
|
|
||||||
let operation = BufferMapOperation {
|
let operation = BufferMapOperation {
|
||||||
host: host_map,
|
host: host_map,
|
||||||
|
@ -228,7 +225,9 @@ impl WGPU {
|
||||||
));
|
));
|
||||||
self.poller.wake();
|
self.poller.wake();
|
||||||
if let Err(ref e) = result {
|
if let Err(ref e) = result {
|
||||||
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
|
if let Err(w) =
|
||||||
|
sender.send(WebGPUResponse::BufferMapAsync(Err(e.to_string())))
|
||||||
|
{
|
||||||
warn!("Failed to send BufferMapAsync Response ({:?})", w);
|
warn!("Failed to send BufferMapAsync Response ({:?})", w);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -482,11 +481,11 @@ impl WGPU {
|
||||||
};
|
};
|
||||||
let (_, error) = gfx_select!(program_id =>
|
let (_, error) = gfx_select!(program_id =>
|
||||||
global.device_create_shader_module(device_id, &desc, source, Some(program_id)));
|
global.device_create_shader_module(device_id, &desc, source, Some(program_id)));
|
||||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::CompilationInfo(
|
if let Err(e) = sender.send(WebGPUResponse::CompilationInfo(
|
||||||
error
|
error
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|e| crate::ShaderCompilationInfo::from(e, &program)),
|
.map(|e| crate::ShaderCompilationInfo::from(e, &program)),
|
||||||
)))) {
|
)) {
|
||||||
warn!("Failed to send WebGPUResponse::CompilationInfo {e:?}");
|
warn!("Failed to send WebGPUResponse::CompilationInfo {e:?}");
|
||||||
}
|
}
|
||||||
self.maybe_dispatch_wgpu_error(device_id, error);
|
self.maybe_dispatch_wgpu_error(device_id, error);
|
||||||
|
@ -668,38 +667,38 @@ impl WGPU {
|
||||||
options,
|
options,
|
||||||
ids,
|
ids,
|
||||||
} => {
|
} => {
|
||||||
let adapter_id = match self
|
let global = &self.global;
|
||||||
|
let response = self
|
||||||
.global
|
.global
|
||||||
.request_adapter(&options, wgc::instance::AdapterInputs::IdSet(&ids))
|
.request_adapter(&options, wgc::instance::AdapterInputs::IdSet(&ids))
|
||||||
{
|
.and_then(|adapter_id| {
|
||||||
Ok(id) => id,
|
|
||||||
Err(w) => {
|
|
||||||
if let Err(e) = sender.send(Some(Err(format!("{:?}", w)))) {
|
|
||||||
warn!(
|
|
||||||
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
|
||||||
e
|
|
||||||
)
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
let adapter = WebGPUAdapter(adapter_id);
|
let adapter = WebGPUAdapter(adapter_id);
|
||||||
self.adapters.push(adapter);
|
self.adapters.push(adapter);
|
||||||
let global = &self.global;
|
|
||||||
// TODO: can we do this lazily
|
// TODO: can we do this lazily
|
||||||
let info =
|
let info =
|
||||||
gfx_select!(adapter_id => global.adapter_get_info(adapter_id)).unwrap();
|
gfx_select!(adapter_id => global.adapter_get_info(adapter_id))
|
||||||
|
.unwrap();
|
||||||
let limits =
|
let limits =
|
||||||
gfx_select!(adapter_id => global.adapter_limits(adapter_id)).unwrap();
|
gfx_select!(adapter_id => global.adapter_limits(adapter_id))
|
||||||
|
.unwrap();
|
||||||
let features =
|
let features =
|
||||||
gfx_select!(adapter_id => global.adapter_features(adapter_id)).unwrap();
|
gfx_select!(adapter_id => global.adapter_features(adapter_id))
|
||||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestAdapter {
|
.unwrap();
|
||||||
|
Ok(Adapter {
|
||||||
adapter_info: info,
|
adapter_info: info,
|
||||||
adapter_id: adapter,
|
adapter_id: adapter,
|
||||||
features,
|
features,
|
||||||
limits,
|
limits,
|
||||||
channel: WebGPU(self.sender.clone()),
|
channel: WebGPU(self.sender.clone()),
|
||||||
}))) {
|
})
|
||||||
|
})
|
||||||
|
.map_err(|e| e.to_string());
|
||||||
|
|
||||||
|
if response.is_err() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Err(e) = sender.send(WebGPUResponse::Adapter(response)) {
|
||||||
warn!(
|
warn!(
|
||||||
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
||||||
e
|
e
|
||||||
|
@ -719,24 +718,23 @@ impl WGPU {
|
||||||
required_limits: descriptor.required_limits.clone(),
|
required_limits: descriptor.required_limits.clone(),
|
||||||
};
|
};
|
||||||
let global = &self.global;
|
let global = &self.global;
|
||||||
let (device_id, queue_id) = match gfx_select!(device_id => global.adapter_request_device(
|
let (device_id, queue_id, error) = gfx_select!(device_id => global.adapter_request_device(
|
||||||
adapter_id.0,
|
adapter_id.0,
|
||||||
&desc,
|
&desc,
|
||||||
None,
|
None,
|
||||||
Some(device_id),
|
Some(device_id),
|
||||||
Some(device_id.transmute()),
|
Some(device_id.transmute()),
|
||||||
)) {
|
));
|
||||||
(_, _, Some(e)) => {
|
if let Some(e) = error {
|
||||||
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
|
if let Err(e) = sender.send(WebGPUResponse::Device(Err(e.to_string())))
|
||||||
|
{
|
||||||
warn!(
|
warn!(
|
||||||
"Failed to send response to WebGPURequest::RequestDevice ({})",
|
"Failed to send response to WebGPURequest::RequestDevice ({})",
|
||||||
w
|
e
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
},
|
}
|
||||||
(device_id, queue_id, None) => (device_id, queue_id),
|
|
||||||
};
|
|
||||||
let device = WebGPUDevice(device_id);
|
let device = WebGPUDevice(device_id);
|
||||||
let queue = WebGPUQueue(queue_id);
|
let queue = WebGPUQueue(queue_id);
|
||||||
{
|
{
|
||||||
|
@ -782,7 +780,7 @@ impl WGPU {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
gfx_select!(device_id => global.device_set_device_lost_closure(device_id, callback));
|
gfx_select!(device_id => global.device_set_device_lost_closure(device_id, callback));
|
||||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestDevice {
|
if let Err(e) = sender.send(WebGPUResponse::Device(Ok(Device {
|
||||||
device_id: device,
|
device_id: device,
|
||||||
queue_id: queue,
|
queue_id: queue,
|
||||||
descriptor,
|
descriptor,
|
||||||
|
@ -1237,8 +1235,7 @@ impl WGPU {
|
||||||
let token = self.poller.token();
|
let token = self.poller.token();
|
||||||
let callback = SubmittedWorkDoneClosure::from_rust(Box::from(move || {
|
let callback = SubmittedWorkDoneClosure::from_rust(Box::from(move || {
|
||||||
drop(token);
|
drop(token);
|
||||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::SubmittedWorkDone)))
|
if let Err(e) = sender.send(WebGPUResponse::SubmittedWorkDone) {
|
||||||
{
|
|
||||||
warn!("Could not send SubmittedWorkDone Response ({})", e);
|
warn!("Could not send SubmittedWorkDone Response ({})", e);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -1378,27 +1375,25 @@ impl WGPU {
|
||||||
.expect("Device should not be dropped by this point");
|
.expect("Device should not be dropped by this point");
|
||||||
if let Some(error_scope_stack) = &mut device_scope.error_scope_stack {
|
if let Some(error_scope_stack) = &mut device_scope.error_scope_stack {
|
||||||
if let Some(error_scope) = error_scope_stack.pop() {
|
if let Some(error_scope) = error_scope_stack.pop() {
|
||||||
if let Err(e) =
|
if let Err(e) = sender.send(WebGPUResponse::PoppedErrorScope(Ok(
|
||||||
sender.send(Some(Ok(WebGPUResponse::PoppedErrorScope(Ok(
|
|
||||||
// TODO: Do actual selection instead of selecting first error
|
// TODO: Do actual selection instead of selecting first error
|
||||||
error_scope.errors.first().cloned(),
|
error_scope.errors.first().cloned(),
|
||||||
)))))
|
))) {
|
||||||
{
|
|
||||||
warn!(
|
warn!(
|
||||||
"Unable to send {:?} to poperrorscope: {e:?}",
|
"Unable to send {:?} to poperrorscope: {e:?}",
|
||||||
error_scope.errors
|
error_scope.errors
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else if let Err(e) = sender.send(Some(Ok(
|
} else if let Err(e) =
|
||||||
WebGPUResponse::PoppedErrorScope(Err(PopError::Empty)),
|
sender.send(WebGPUResponse::PoppedErrorScope(Err(PopError::Empty)))
|
||||||
))) {
|
{
|
||||||
warn!("Unable to send PopError::Empty: {e:?}");
|
warn!("Unable to send PopError::Empty: {e:?}");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// device lost
|
// device lost
|
||||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::PoppedErrorScope(
|
if let Err(e) =
|
||||||
Err(PopError::Lost),
|
sender.send(WebGPUResponse::PoppedErrorScope(Err(PopError::Lost)))
|
||||||
)))) {
|
{
|
||||||
warn!("Unable to send PopError::Lost due {e:?}");
|
warn!("Unable to send PopError::Lost due {e:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue