Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash in WebGPU when WebGPU is disabled #30888

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions components/constellation/constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2043,42 +2043,37 @@ where
return warn!("Browsing context group not found");
};
let webgpu_chan = match browsing_context_group.webgpus.entry(host) {
Entry::Vacant(v) => v
.insert(
match WebGPU::new(
self.webrender_wgpu.webrender_api.create_sender(),
self.webrender_document,
self.webrender_wgpu.webrender_external_images.clone(),
self.webrender_wgpu.wgpu_image_map.clone(),
) {
Some(webgpu) => {
let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1);
if let Err(e) = source_pipeline.event_loop.send(msg) {
warn!(
"{}: Failed to send SetWebGPUPort to pipeline ({:?})",
source_pipeline_id, e
);
}
webgpu.0
},
None => {
return warn!("Failed to create new WebGPU thread");
},
},
)
.clone(),
Entry::Occupied(o) => o.get().clone(),
Entry::Vacant(v) => WebGPU::new(
self.webrender_wgpu.webrender_api.create_sender(),
self.webrender_document,
self.webrender_wgpu.webrender_external_images.clone(),
self.webrender_wgpu.wgpu_image_map.clone(),
)
.map(|webgpu| {
let msg = ConstellationControlMsg::SetWebGPUPort(webgpu.1);
if let Err(e) = source_pipeline.event_loop.send(msg) {
warn!(
"{}: Failed to send SetWebGPUPort to pipeline ({:?})",
source_pipeline_id, e
);
}
v.insert(webgpu.0).clone()
}),
Entry::Occupied(o) => Some(o.get().clone()),
};
match request {
FromScriptMsg::RequestAdapter(response_sender, options, ids) => {
let adapter_request = WebGPURequest::RequestAdapter {
sender: response_sender,
options,
ids,
};
if webgpu_chan.0.send((None, adapter_request)).is_err() {
return warn!("Failed to send request adapter message on WebGPU channel");
}
FromScriptMsg::RequestAdapter(response_sender, options, ids) => match webgpu_chan {
gterzian marked this conversation as resolved.
Show resolved Hide resolved
None => warn!("Failed to send request adapter message, missing WebGPU channel"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed a follow-up #30895

Some(webgpu_chan) => {
let adapter_request = WebGPURequest::RequestAdapter {
sender: response_sender,
options,
ids,
};
if webgpu_chan.0.send((None, adapter_request)).is_err() {
warn!("Failed to send request adapter message on WebGPU channel");
}
},
},
FromScriptMsg::GetWebGPUChan(response_sender) => {
if response_sender.send(webgpu_chan).is_err() {
Expand Down
14 changes: 9 additions & 5 deletions components/script/dom/htmlcanvaselement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,15 @@ impl HTMLCanvasElement {
.global()
.script_to_constellation_chan()
.send(ScriptMsg::GetWebGPUChan(sender));
let window = window_from_node(self);
let channel = receiver.recv().expect("Failed to get WebGPU channel");
let context = GPUCanvasContext::new(window.upcast::<GlobalScope>(), self, channel);
*self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context)));
Some(context)
receiver
.recv()
.expect("Failed to get WebGPU channel")
.map(|channel| {
let window = window_from_node(self);
let context = GPUCanvasContext::new(window.upcast::<GlobalScope>(), self, channel);
*self.context.borrow_mut() = Some(CanvasContext::WebGPU(Dom::from_ref(&*context)));
context
})
}

/// Gets the base WebGLRenderingContext for WebGL or WebGL 2, if exists.
Expand Down
2 changes: 1 addition & 1 deletion components/shared/script/script_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ pub enum ScriptMsg {
SmallVec<[wgpu::id::AdapterId; 4]>,
),
/// Get WebGPU channel
GetWebGPUChan(IpcSender<WebGPU>),
GetWebGPUChan(IpcSender<Option<WebGPU>>),
/// Notify the constellation of a pipeline's document's title.
TitleChanged(PipelineId, String),
}
Expand Down