mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +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_url::{Host, ImmutableOrigin, ServoUrl};
|
||||
use style_traits::CSSPixel;
|
||||
use webgpu::{self, WebGPU, WebGPURequest};
|
||||
use webgpu::{self, WebGPU, WebGPURequest, WebGPUResponse};
|
||||
use webrender::{RenderApi, RenderApiSender};
|
||||
use webrender_api::DocumentId;
|
||||
use webrender_traits::{WebRenderNetApi, WebRenderScriptApi, WebrenderExternalImageRegistry};
|
||||
|
@ -2069,7 +2069,7 @@ where
|
|||
match request {
|
||||
FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
|
||||
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)
|
||||
}
|
||||
},
|
||||
|
|
|
@ -10,7 +10,7 @@ use ipc_channel::router::ROUTER;
|
|||
use js::jsapi::Heap;
|
||||
use script_traits::ScriptMsg;
|
||||
use webgpu::wgt::PowerPreference;
|
||||
use webgpu::{wgc, WebGPUResponse, WebGPUResponseResult};
|
||||
use webgpu::{wgc, WebGPUResponse};
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::GPUTextureFormat;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
|
@ -45,7 +45,7 @@ impl GPU {
|
|||
}
|
||||
|
||||
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> {
|
||||
|
@ -55,7 +55,7 @@ struct WGPUResponse<T: AsyncWGPUListener + DomObject> {
|
|||
|
||||
impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
fn response(self, response: Option<WebGPUResponseResult>) {
|
||||
fn response(self, response: WebGPUResponse) {
|
||||
let promise = self.trusted.root();
|
||||
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>(
|
||||
promise: &Rc<Promise>,
|
||||
receiver: &T,
|
||||
) -> IpcSender<Option<WebGPUResponseResult>> {
|
||||
) -> IpcSender<WebGPUResponse> {
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let task_source = receiver.global().dom_manipulation_task_source();
|
||||
let canceller = receiver
|
||||
|
@ -139,42 +139,34 @@ impl GPUMethods 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 {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::RequestAdapter {
|
||||
adapter_info,
|
||||
adapter_id,
|
||||
features,
|
||||
limits,
|
||||
channel,
|
||||
}) => {
|
||||
let adapter = GPUAdapter::new(
|
||||
&self.global(),
|
||||
channel,
|
||||
DOMString::from(format!(
|
||||
"{} ({:?})",
|
||||
adapter_info.name,
|
||||
adapter_id.0.backend()
|
||||
)),
|
||||
Heap::default(),
|
||||
features,
|
||||
limits,
|
||||
adapter_info,
|
||||
adapter_id,
|
||||
);
|
||||
promise.resolve_native(&adapter);
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Could not get GPUAdapter ({:?})", e);
|
||||
promise.resolve_native(&None::<GPUAdapter>);
|
||||
},
|
||||
Ok(_) => unreachable!("GPU received wrong WebGPUResponse"),
|
||||
WebGPUResponse::Adapter(Ok(adapter)) => {
|
||||
let adapter = GPUAdapter::new(
|
||||
&self.global(),
|
||||
adapter.channel,
|
||||
DOMString::from(format!(
|
||||
"{} ({:?})",
|
||||
adapter.adapter_info.name,
|
||||
adapter.adapter_id.0.backend()
|
||||
)),
|
||||
Heap::default(),
|
||||
adapter.features,
|
||||
adapter.limits,
|
||||
adapter.adapter_info,
|
||||
adapter.adapter_id,
|
||||
);
|
||||
promise.resolve_native(&adapter);
|
||||
},
|
||||
None => {
|
||||
WebGPUResponse::Adapter(Err(e)) => {
|
||||
warn!("Could not get GPUAdapter ({:?})", e);
|
||||
promise.resolve_native(&None::<GPUAdapter>);
|
||||
},
|
||||
WebGPUResponse::None => {
|
||||
warn!("Couldn't get a response, because WebGPU is disabled");
|
||||
promise.resolve_native(&None::<GPUAdapter>);
|
||||
},
|
||||
_ => unreachable!("GPU received wrong WebGPUResponse"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::rc::Rc;
|
|||
|
||||
use dom_struct::dom_struct;
|
||||
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::types::{GPUAdapterInfo, GPUSupportedLimits};
|
||||
|
@ -263,35 +263,30 @@ impl GPUAdapterMethods 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 {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::RequestDevice {
|
||||
device_id,
|
||||
queue_id,
|
||||
descriptor,
|
||||
}) => {
|
||||
let device = GPUDevice::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
self,
|
||||
Heap::default(),
|
||||
descriptor.required_features,
|
||||
descriptor.required_limits,
|
||||
device_id,
|
||||
queue_id,
|
||||
descriptor.label.unwrap_or_default(),
|
||||
);
|
||||
self.global().add_gpu_device(&device);
|
||||
promise.resolve_native(&device);
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Could not get GPUDevice({:?})", e);
|
||||
promise.reject_error(Error::Operation);
|
||||
},
|
||||
Ok(_) => unreachable!("GPUAdapter received wrong WebGPUResponse"),
|
||||
WebGPUResponse::Device(Ok(device)) => {
|
||||
let descriptor = device.descriptor;
|
||||
let device = GPUDevice::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
self,
|
||||
Heap::default(),
|
||||
descriptor.required_features,
|
||||
descriptor.required_limits,
|
||||
device.device_id,
|
||||
device.queue_id,
|
||||
descriptor.label.unwrap_or_default(),
|
||||
);
|
||||
self.global().add_gpu_device(&device);
|
||||
promise.resolve_native(&device);
|
||||
},
|
||||
None => unreachable!("Failed to get a response for RequestDevice"),
|
||||
WebGPUResponse::Device(Err(e)) => {
|
||||
warn!("Could not get GPUDevice({:?})", e);
|
||||
promise.reject_error(Error::Operation);
|
||||
},
|
||||
WebGPUResponse::None => unreachable!("Failed to get a response for RequestDevice"),
|
||||
_ => unreachable!("GPUAdapter received wrong WebGPUResponse"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use dom_struct::dom_struct;
|
|||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use js::typedarray::{ArrayBuffer, ArrayBufferU8};
|
||||
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 crate::dom::bindings::cell::DomRefCell;
|
||||
|
@ -350,29 +350,26 @@ impl GPUBufferMethods 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 {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::BufferMapAsync(bytes)) => {
|
||||
*self
|
||||
.map_info
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.mapping
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_mut() = bytes.to_vec();
|
||||
promise.resolve_native(&());
|
||||
self.state.set(GPUBufferState::Mapped);
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("Could not map buffer({:?})", e);
|
||||
promise.reject_error(Error::Abort);
|
||||
},
|
||||
Ok(_) => unreachable!("GPUBuffer received wrong WebGPUResponse"),
|
||||
WebGPUResponse::BufferMapAsync(Ok(bytes)) => {
|
||||
*self
|
||||
.map_info
|
||||
.borrow_mut()
|
||||
.as_mut()
|
||||
.unwrap()
|
||||
.mapping
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_mut() = bytes.to_vec();
|
||||
promise.resolve_native(&());
|
||||
self.state.set(GPUBufferState::Mapped);
|
||||
},
|
||||
None => unreachable!("Failed to get a response for BufferMapAsync"),
|
||||
WebGPUResponse::BufferMapAsync(Err(e)) => {
|
||||
warn!("Could not map buffer({:?})", e);
|
||||
promise.reject_error(Error::Abort);
|
||||
},
|
||||
_ => unreachable!("GPUBuffer received wrong WebGPUResponse"),
|
||||
}
|
||||
*self.map_promise.borrow_mut() = None;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use webgpu::wgc::id::{BindGroupLayoutId, PipelineLayoutId};
|
|||
use webgpu::wgc::{
|
||||
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::error::Fallible;
|
||||
|
@ -1010,9 +1010,9 @@ impl GPUDeviceMethods 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 {
|
||||
Some(Ok(WebGPUResponse::PoppedErrorScope(result))) => match result {
|
||||
WebGPUResponse::PoppedErrorScope(result) => match result {
|
||||
Ok(None) | Err(PopError::Lost) => promise.resolve_native(&None::<Option<GPUError>>),
|
||||
Err(PopError::Empty) => promise.reject_error(Error::Operation),
|
||||
Ok(Some(error)) => {
|
||||
|
|
|
@ -206,13 +206,9 @@ impl GPUQueueMethods for GPUQueue {
|
|||
}
|
||||
|
||||
impl AsyncWGPUListener for GPUQueue {
|
||||
fn handle_response(
|
||||
&self,
|
||||
response: Option<Result<webgpu::WebGPUResponse, String>>,
|
||||
promise: &Rc<Promise>,
|
||||
) {
|
||||
fn handle_response(&self, response: webgpu::WebGPUResponse, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
Some(Ok(WebGPUResponse::SubmittedWorkDone)) => {
|
||||
WebGPUResponse::SubmittedWorkDone => {
|
||||
promise.resolve_native(&());
|
||||
},
|
||||
_ => {
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUResponseResult, WebGPUShaderModule};
|
||||
use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUShaderModule};
|
||||
|
||||
use super::gpu::AsyncWGPUListener;
|
||||
use super::gpucompilationinfo::GPUCompilationInfo;
|
||||
|
@ -89,9 +89,9 @@ impl GPUShaderModuleMethods 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 {
|
||||
Some(Ok(WebGPUResponse::CompilationInfo(info))) => {
|
||||
WebGPUResponse::CompilationInfo(info) => {
|
||||
let info = GPUCompilationInfo::from(&self.global(), info);
|
||||
promise.resolve_native(&info);
|
||||
},
|
||||
|
|
|
@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
|
|||
use servo_url::{ImmutableOrigin, ServoUrl};
|
||||
use smallvec::SmallVec;
|
||||
use style_traits::CSSPixel;
|
||||
use webgpu::{wgc, WebGPU, WebGPUResponseResult};
|
||||
use webgpu::{wgc, WebGPU, WebGPUResponse};
|
||||
use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
|
||||
|
||||
use crate::{
|
||||
|
@ -257,7 +257,7 @@ pub enum ScriptMsg {
|
|||
MediaSessionEvent(PipelineId, MediaSessionEvent),
|
||||
/// Create a WebGPU Adapter instance
|
||||
RequestAdapter(
|
||||
IpcSender<Option<WebGPUResponseResult>>,
|
||||
IpcSender<WebGPUResponse>,
|
||||
wgc::instance::RequestAdapterOptions,
|
||||
SmallVec<[wgc::id::AdapterId; 4]>,
|
||||
),
|
||||
|
|
|
@ -31,12 +31,12 @@ pub use {wgpu_core as wgc, wgpu_types as wgt};
|
|||
|
||||
use crate::identity::*;
|
||||
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)]
|
||||
pub enum WebGPURequest {
|
||||
BufferMapAsync {
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
sender: IpcSender<WebGPUResponse>,
|
||||
buffer_id: id::BufferId,
|
||||
device_id: id::DeviceId,
|
||||
host_map: HostMap,
|
||||
|
@ -126,7 +126,7 @@ pub enum WebGPURequest {
|
|||
program_id: id::ShaderModuleId,
|
||||
program: String,
|
||||
label: Option<String>,
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
sender: IpcSender<WebGPUResponse>,
|
||||
},
|
||||
CreateSwapChain {
|
||||
device_id: id::DeviceId,
|
||||
|
@ -182,12 +182,12 @@ pub enum WebGPURequest {
|
|||
device_id: id::DeviceId,
|
||||
},
|
||||
RequestAdapter {
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
sender: IpcSender<WebGPUResponse>,
|
||||
options: RequestAdapterOptions,
|
||||
ids: SmallVec<[id::AdapterId; 4]>,
|
||||
},
|
||||
RequestDevice {
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
sender: IpcSender<WebGPUResponse>,
|
||||
adapter_id: WebGPUAdapter,
|
||||
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
||||
device_id: id::DeviceId,
|
||||
|
@ -280,7 +280,7 @@ pub enum WebGPURequest {
|
|||
data: IpcSharedMemory,
|
||||
},
|
||||
QueueOnSubmittedWorkDone {
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
sender: IpcSender<WebGPUResponse>,
|
||||
queue_id: id::QueueId,
|
||||
},
|
||||
PushErrorScope {
|
||||
|
@ -293,6 +293,6 @@ pub enum WebGPURequest {
|
|||
},
|
||||
PopErrorScope {
|
||||
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)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum WebGPUResponse {
|
||||
RequestAdapter {
|
||||
adapter_info: wgt::AdapterInfo,
|
||||
adapter_id: WebGPUAdapter,
|
||||
features: wgt::Features,
|
||||
limits: wgt::Limits,
|
||||
channel: WebGPU,
|
||||
},
|
||||
RequestDevice {
|
||||
device_id: WebGPUDevice,
|
||||
queue_id: WebGPUQueue,
|
||||
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
||||
},
|
||||
BufferMapAsync(IpcSharedMemory),
|
||||
/// WebGPU is disabled
|
||||
None,
|
||||
// TODO: use wgpu errors
|
||||
Adapter(Result<Adapter, String>),
|
||||
Device(Result<Device, String>),
|
||||
BufferMapAsync(Result<IpcSharedMemory, String>),
|
||||
SubmittedWorkDone,
|
||||
PoppedErrorScope(Result<Option<Error>, PopError>),
|
||||
CompilationInfo(Option<ShaderCompilationInfo>),
|
||||
}
|
||||
|
||||
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
|
||||
|
|
|
@ -29,6 +29,7 @@ use wgc::pipeline::ShaderModuleDescriptor;
|
|||
use wgc::resource::{BufferMapCallback, BufferMapOperation};
|
||||
use wgc::{gfx_select, id};
|
||||
use wgpu_core::command::RenderPassDescriptor;
|
||||
use wgpu_core::resource::BufferAccessResult;
|
||||
use wgt::InstanceDescriptor;
|
||||
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::render_commands::apply_render_command;
|
||||
use crate::{
|
||||
ComputePassId, Error, PopError, PresentationData, RenderPassId, Transmute, WebGPU,
|
||||
WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse,
|
||||
Adapter, ComputePassId, Device, Error, PopError, PresentationData, RenderPassId, Transmute,
|
||||
WebGPU, WebGPUAdapter, WebGPUDevice, WebGPUMsg, WebGPUQueue, WebGPURequest, WebGPUResponse,
|
||||
};
|
||||
|
||||
pub const PRESENTATION_BUFFER_COUNT: usize = 10;
|
||||
|
@ -183,37 +184,33 @@ impl WGPU {
|
|||
let glob = Arc::clone(&self.global);
|
||||
let resp_sender = sender.clone();
|
||||
let token = self.poller.token();
|
||||
let callback = BufferMapCallback::from_rust(Box::from(move |result| {
|
||||
drop(token);
|
||||
match result {
|
||||
Ok(()) => {
|
||||
let global = &glob;
|
||||
let (slice_pointer, range_size) = gfx_select!(buffer_id =>
|
||||
global.buffer_get_mapped_range(buffer_id, 0, None))
|
||||
.unwrap();
|
||||
// SAFETY: guarantee to be safe from wgpu
|
||||
let data = unsafe {
|
||||
slice::from_raw_parts(slice_pointer, range_size as usize)
|
||||
};
|
||||
let callback = BufferMapCallback::from_rust(Box::from(
|
||||
move |result: BufferAccessResult| {
|
||||
drop(token);
|
||||
let response = result
|
||||
.and_then(|_| {
|
||||
let global = &glob;
|
||||
let (slice_pointer, range_size) = gfx_select!(buffer_id =>
|
||||
global.buffer_get_mapped_range(buffer_id, 0, None))
|
||||
.unwrap();
|
||||
// SAFETY: guarantee to be safe from wgpu
|
||||
let data = unsafe {
|
||||
slice::from_raw_parts(
|
||||
slice_pointer,
|
||||
range_size as usize,
|
||||
)
|
||||
};
|
||||
|
||||
if let Err(e) =
|
||||
resp_sender.send(Some(Ok(WebGPUResponse::BufferMapAsync(
|
||||
IpcSharedMemory::from_bytes(data),
|
||||
))))
|
||||
{
|
||||
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);
|
||||
}
|
||||
},
|
||||
};
|
||||
}));
|
||||
Ok(IpcSharedMemory::from_bytes(data))
|
||||
})
|
||||
.map_err(|e| e.to_string());
|
||||
if let Err(e) =
|
||||
resp_sender.send(WebGPUResponse::BufferMapAsync(response))
|
||||
{
|
||||
warn!("Could not send BufferMapAsync Response ({})", e);
|
||||
}
|
||||
},
|
||||
));
|
||||
|
||||
let operation = BufferMapOperation {
|
||||
host: host_map,
|
||||
|
@ -228,7 +225,9 @@ impl WGPU {
|
|||
));
|
||||
self.poller.wake();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -482,11 +481,11 @@ impl WGPU {
|
|||
};
|
||||
let (_, error) = gfx_select!(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
|
||||
.as_ref()
|
||||
.map(|e| crate::ShaderCompilationInfo::from(e, &program)),
|
||||
)))) {
|
||||
)) {
|
||||
warn!("Failed to send WebGPUResponse::CompilationInfo {e:?}");
|
||||
}
|
||||
self.maybe_dispatch_wgpu_error(device_id, error);
|
||||
|
@ -668,38 +667,38 @@ impl WGPU {
|
|||
options,
|
||||
ids,
|
||||
} => {
|
||||
let adapter_id = match self
|
||||
let global = &self.global;
|
||||
let response = self
|
||||
.global
|
||||
.request_adapter(&options, wgc::instance::AdapterInputs::IdSet(&ids))
|
||||
{
|
||||
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);
|
||||
self.adapters.push(adapter);
|
||||
let global = &self.global;
|
||||
// TODO: can we do this lazily
|
||||
let info =
|
||||
gfx_select!(adapter_id => global.adapter_get_info(adapter_id)).unwrap();
|
||||
let limits =
|
||||
gfx_select!(adapter_id => global.adapter_limits(adapter_id)).unwrap();
|
||||
let features =
|
||||
gfx_select!(adapter_id => global.adapter_features(adapter_id)).unwrap();
|
||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestAdapter {
|
||||
adapter_info: info,
|
||||
adapter_id: adapter,
|
||||
features,
|
||||
limits,
|
||||
channel: WebGPU(self.sender.clone()),
|
||||
}))) {
|
||||
.and_then(|adapter_id| {
|
||||
let adapter = WebGPUAdapter(adapter_id);
|
||||
self.adapters.push(adapter);
|
||||
// TODO: can we do this lazily
|
||||
let info =
|
||||
gfx_select!(adapter_id => global.adapter_get_info(adapter_id))
|
||||
.unwrap();
|
||||
let limits =
|
||||
gfx_select!(adapter_id => global.adapter_limits(adapter_id))
|
||||
.unwrap();
|
||||
let features =
|
||||
gfx_select!(adapter_id => global.adapter_features(adapter_id))
|
||||
.unwrap();
|
||||
Ok(Adapter {
|
||||
adapter_info: info,
|
||||
adapter_id: adapter,
|
||||
features,
|
||||
limits,
|
||||
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!(
|
||||
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
||||
e
|
||||
|
@ -719,24 +718,23 @@ impl WGPU {
|
|||
required_limits: descriptor.required_limits.clone(),
|
||||
};
|
||||
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,
|
||||
&desc,
|
||||
None,
|
||||
Some(device_id),
|
||||
Some(device_id.transmute()),
|
||||
)) {
|
||||
(_, _, Some(e)) => {
|
||||
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
|
||||
warn!(
|
||||
));
|
||||
if let Some(e) = error {
|
||||
if let Err(e) = sender.send(WebGPUResponse::Device(Err(e.to_string())))
|
||||
{
|
||||
warn!(
|
||||
"Failed to send response to WebGPURequest::RequestDevice ({})",
|
||||
w
|
||||
e
|
||||
)
|
||||
}
|
||||
break;
|
||||
},
|
||||
(device_id, queue_id, None) => (device_id, queue_id),
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
let device = WebGPUDevice(device_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));
|
||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestDevice {
|
||||
if let Err(e) = sender.send(WebGPUResponse::Device(Ok(Device {
|
||||
device_id: device,
|
||||
queue_id: queue,
|
||||
descriptor,
|
||||
|
@ -1237,8 +1235,7 @@ impl WGPU {
|
|||
let token = self.poller.token();
|
||||
let callback = SubmittedWorkDoneClosure::from_rust(Box::from(move || {
|
||||
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);
|
||||
}
|
||||
}));
|
||||
|
@ -1378,27 +1375,25 @@ impl WGPU {
|
|||
.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) = error_scope_stack.pop() {
|
||||
if let Err(e) =
|
||||
sender.send(Some(Ok(WebGPUResponse::PoppedErrorScope(Ok(
|
||||
// TODO: Do actual selection instead of selecting first error
|
||||
error_scope.errors.first().cloned(),
|
||||
)))))
|
||||
{
|
||||
if let Err(e) = sender.send(WebGPUResponse::PoppedErrorScope(Ok(
|
||||
// TODO: Do actual selection instead of selecting first error
|
||||
error_scope.errors.first().cloned(),
|
||||
))) {
|
||||
warn!(
|
||||
"Unable to send {:?} to poperrorscope: {e:?}",
|
||||
error_scope.errors
|
||||
);
|
||||
}
|
||||
} else if let Err(e) = sender.send(Some(Ok(
|
||||
WebGPUResponse::PoppedErrorScope(Err(PopError::Empty)),
|
||||
))) {
|
||||
} else if let Err(e) =
|
||||
sender.send(WebGPUResponse::PoppedErrorScope(Err(PopError::Empty)))
|
||||
{
|
||||
warn!("Unable to send PopError::Empty: {e:?}");
|
||||
}
|
||||
} else {
|
||||
// device lost
|
||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::PoppedErrorScope(
|
||||
Err(PopError::Lost),
|
||||
)))) {
|
||||
if let Err(e) =
|
||||
sender.send(WebGPUResponse::PoppedErrorScope(Err(PopError::Lost)))
|
||||
{
|
||||
warn!("Unable to send PopError::Lost due {e:?}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue