mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Fix failed request for adapter when not available (#31002)
Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
This commit is contained in:
parent
dd0149d953
commit
fddc4a430f
6 changed files with 97 additions and 90 deletions
|
@ -2063,7 +2063,11 @@ where
|
|||
};
|
||||
match request {
|
||||
FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
|
||||
None => warn!("Failed to send request adapter message, missing WebGPU channel"),
|
||||
None => {
|
||||
if let Err(e) = response_sender.send(None) {
|
||||
return warn!("Failed to send request adapter message: {}", e);
|
||||
}
|
||||
},
|
||||
Some(webgpu_chan) => {
|
||||
let adapter_request = WebGPURequest::RequestAdapter {
|
||||
sender: response_sender,
|
||||
|
|
|
@ -45,7 +45,7 @@ impl GPU {
|
|||
}
|
||||
|
||||
pub trait AsyncWGPUListener {
|
||||
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>);
|
||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, 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: WebGPUResponseResult) {
|
||||
fn response(self, response: Option<WebGPUResponseResult>) {
|
||||
let promise = self.trusted.root();
|
||||
self.receiver.root().handle_response(response, &promise);
|
||||
}
|
||||
|
@ -64,13 +64,13 @@ impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
|
|||
pub fn response_async<T: AsyncWGPUListener + DomObject + 'static>(
|
||||
promise: &Rc<Promise>,
|
||||
receiver: &T,
|
||||
) -> IpcSender<WebGPUResponseResult> {
|
||||
) -> IpcSender<Option<WebGPUResponseResult>> {
|
||||
let (action_sender, action_receiver) = ipc::channel().unwrap();
|
||||
let task_source = receiver.global().dom_manipulation_task_source();
|
||||
let canceller = receiver
|
||||
.global()
|
||||
.task_canceller(TaskSourceName::DOMManipulation);
|
||||
let mut trusted = Some(TrustedPromise::new(promise.clone()));
|
||||
let mut trusted: Option<TrustedPromise> = Some(TrustedPromise::new(promise.clone()));
|
||||
let trusted_receiver = Trusted::new(receiver);
|
||||
ROUTER.add_route(
|
||||
action_receiver.to_opaque(),
|
||||
|
@ -139,8 +139,9 @@ impl GPUMethods for GPU {
|
|||
}
|
||||
|
||||
impl AsyncWGPUListener for GPU {
|
||||
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
|
||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::RequestAdapter {
|
||||
adapter_info,
|
||||
adapter_id,
|
||||
|
@ -168,9 +169,11 @@ impl AsyncWGPUListener for GPU {
|
|||
warn!("Could not get GPUAdapter ({:?})", e);
|
||||
promise.resolve_native(&None::<GPUAdapter>);
|
||||
},
|
||||
_ => {
|
||||
warn!("GPU received wrong WebGPUResponse");
|
||||
promise.reject_error(Error::Operation);
|
||||
Ok(_) => unreachable!("GPU received wrong WebGPUResponse"),
|
||||
},
|
||||
None => {
|
||||
warn!("Couldn't get a response, because WebGPU is disabled");
|
||||
promise.resolve_native(&None::<GPUAdapter>);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,8 +237,9 @@ impl GPUAdapterMethods for GPUAdapter {
|
|||
}
|
||||
|
||||
impl AsyncWGPUListener for GPUAdapter {
|
||||
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
|
||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::RequestDevice {
|
||||
device_id,
|
||||
queue_id,
|
||||
|
@ -262,10 +263,9 @@ impl AsyncWGPUListener for GPUAdapter {
|
|||
warn!("Could not get GPUDevice({:?})", e);
|
||||
promise.reject_error(Error::Operation);
|
||||
},
|
||||
_ => {
|
||||
warn!("GPUAdapter received wrong WebGPUResponse");
|
||||
promise.reject_error(Error::Operation);
|
||||
Ok(_) => unreachable!("GPUAdapter received wrong WebGPUResponse"),
|
||||
},
|
||||
None => unreachable!("Failed to get a response for RequestDevice"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -346,8 +346,9 @@ impl GPUBufferMethods for GPUBuffer {
|
|||
|
||||
impl AsyncWGPUListener for GPUBuffer {
|
||||
#[allow(unsafe_code)]
|
||||
fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
|
||||
fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
Some(response) => match response {
|
||||
Ok(WebGPUResponse::BufferMapAsync(bytes)) => {
|
||||
*self
|
||||
.map_info
|
||||
|
@ -363,10 +364,9 @@ impl AsyncWGPUListener for GPUBuffer {
|
|||
warn!("Could not map buffer({:?})", e);
|
||||
promise.reject_error(Error::Abort);
|
||||
},
|
||||
_ => {
|
||||
warn!("GPUBuffer received wrong WebGPUResponse");
|
||||
promise.reject_error(Error::Operation);
|
||||
Ok(_) => unreachable!("GPUBuffer received wrong WebGPUResponse"),
|
||||
},
|
||||
None => unreachable!("Failed to get a response for BufferMapAsync"),
|
||||
}
|
||||
*self.map_promise.borrow_mut() = None;
|
||||
if let Err(e) = self
|
||||
|
|
|
@ -258,7 +258,7 @@ pub enum ScriptMsg {
|
|||
MediaSessionEvent(PipelineId, MediaSessionEvent),
|
||||
/// Create a WebGPU Adapter instance
|
||||
RequestAdapter(
|
||||
IpcSender<WebGPUResponseResult>,
|
||||
IpcSender<Option<WebGPUResponseResult>>,
|
||||
wgpu::instance::RequestAdapterOptions,
|
||||
SmallVec<[wgpu::id::AdapterId; 4]>,
|
||||
),
|
||||
|
|
|
@ -75,7 +75,7 @@ pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
|
|||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub enum WebGPURequest {
|
||||
BufferMapAsync {
|
||||
sender: IpcSender<WebGPUResponseResult>,
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
buffer_id: id::BufferId,
|
||||
device_id: id::DeviceId,
|
||||
host_map: HostMap,
|
||||
|
@ -202,12 +202,12 @@ pub enum WebGPURequest {
|
|||
device_id: id::DeviceId,
|
||||
},
|
||||
RequestAdapter {
|
||||
sender: IpcSender<WebGPUResponseResult>,
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
options: RequestAdapterOptions,
|
||||
ids: SmallVec<[id::AdapterId; 4]>,
|
||||
},
|
||||
RequestDevice {
|
||||
sender: IpcSender<WebGPUResponseResult>,
|
||||
sender: IpcSender<Option<WebGPUResponseResult>>,
|
||||
adapter_id: WebGPUAdapter,
|
||||
descriptor: wgt::DeviceDescriptor<Option<String>>,
|
||||
device_id: id::DeviceId,
|
||||
|
@ -340,7 +340,7 @@ struct WGPU<'a> {
|
|||
// Track invalid adapters https://gpuweb.github.io/gpuweb/#invalid
|
||||
_invalid_adapters: Vec<WebGPUAdapter>,
|
||||
// Buffers with pending mapping
|
||||
buffer_maps: HashMap<id::BufferId, Rc<BufferMapInfo<'a, WebGPUResponseResult>>>,
|
||||
buffer_maps: HashMap<id::BufferId, Rc<BufferMapInfo<'a, Option<WebGPUResponseResult>>>>,
|
||||
// Presentation Buffers with pending mapping
|
||||
present_buffer_maps:
|
||||
HashMap<id::BufferId, Rc<BufferMapInfo<'a, (Option<ErrorScopeId>, WebGPURequest)>>>,
|
||||
|
@ -423,7 +423,7 @@ impl<'a> WGPU<'a> {
|
|||
userdata: *mut u8,
|
||||
) {
|
||||
let info = Rc::from_raw(
|
||||
userdata as *const BufferMapInfo<WebGPUResponseResult>,
|
||||
userdata as *const BufferMapInfo<Option<WebGPUResponseResult>>,
|
||||
);
|
||||
let msg = match status {
|
||||
BufferMapAsyncStatus::Success => {
|
||||
|
@ -442,7 +442,7 @@ impl<'a> WGPU<'a> {
|
|||
Err(String::from("Failed to map Buffer"))
|
||||
},
|
||||
};
|
||||
if let Err(e) = info.sender.send(msg) {
|
||||
if let Err(e) = info.sender.send(Some(msg)) {
|
||||
warn!("Could not send BufferMapAsync Response ({})", e);
|
||||
}
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ impl<'a> WGPU<'a> {
|
|||
let global = &self.global;
|
||||
let result = gfx_select!(buffer_id => global.buffer_map_async(buffer_id, map_range, operation));
|
||||
if let Err(ref e) = result {
|
||||
if let Err(w) = sender.send(Err(format!("{:?}", e))) {
|
||||
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
|
||||
warn!("Failed to send BufferMapAsync Response ({:?})", w);
|
||||
}
|
||||
}
|
||||
|
@ -879,7 +879,7 @@ impl<'a> WGPU<'a> {
|
|||
) {
|
||||
Ok(id) => id,
|
||||
Err(w) => {
|
||||
if let Err(e) = sender.send(Err(format!("{:?}", w))) {
|
||||
if let Err(e) = sender.send(Some(Err(format!("{:?}", w)))) {
|
||||
warn!(
|
||||
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
||||
e
|
||||
|
@ -898,13 +898,13 @@ impl<'a> WGPU<'a> {
|
|||
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(Ok(WebGPUResponse::RequestAdapter {
|
||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestAdapter {
|
||||
adapter_info: info,
|
||||
adapter_id: adapter,
|
||||
features,
|
||||
limits,
|
||||
channel: WebGPU(self.sender.clone()),
|
||||
})) {
|
||||
}))) {
|
||||
warn!(
|
||||
"Failed to send response to WebGPURequest::RequestAdapter ({})",
|
||||
e
|
||||
|
@ -934,7 +934,7 @@ impl<'a> WGPU<'a> {
|
|||
) {
|
||||
Ok(id) => id,
|
||||
Err(e) => {
|
||||
if let Err(w) = sender.send(Err(format!("{:?}", e))) {
|
||||
if let Err(w) = sender.send(Some(Err(format!("{:?}", e)))) {
|
||||
warn!(
|
||||
"Failed to send response to WebGPURequest::RequestDevice ({})",
|
||||
w
|
||||
|
@ -948,11 +948,11 @@ impl<'a> WGPU<'a> {
|
|||
// since wgpu-core uses the same id for the device and the queue
|
||||
let queue = WebGPUQueue(id);
|
||||
self.devices.insert(device, pipeline_id);
|
||||
if let Err(e) = sender.send(Ok(WebGPUResponse::RequestDevice {
|
||||
if let Err(e) = sender.send(Some(Ok(WebGPUResponse::RequestDevice {
|
||||
device_id: device,
|
||||
queue_id: queue,
|
||||
descriptor,
|
||||
})) {
|
||||
}))) {
|
||||
warn!(
|
||||
"Failed to send response to WebGPURequest::RequestDevice ({})",
|
||||
e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue