kms: Use primary node if no render node is found

It seems this is all that's needed to make cosmic-comp run in a VM
without graphics acceleration.

Fixes https://github.com/pop-os/cosmic-comp/issues/62.
This commit is contained in:
Ian Douglas Scott 2023-03-03 12:22:14 -08:00
parent b1c7f68b6e
commit 5b950a9be7

View file

@ -157,10 +157,11 @@ pub fn init_backend(
{ {
path path
} else { } else {
primary_gpu(session.seat()) let primary_node = primary_gpu(session.seat())
.ok() .ok()
.flatten() .flatten()
.and_then(|x| DrmNode::from_path(x).ok()) .and_then(|x| DrmNode::from_path(x).ok());
primary_node
.and_then(|x| x.node_with_type(NodeType::Render).and_then(Result::ok)) .and_then(|x| x.node_with_type(NodeType::Render).and_then(Result::ok))
.unwrap_or_else(|| { .unwrap_or_else(|| {
for dev in all_gpus(session.seat()).expect("No GPU found") { for dev in all_gpus(session.seat()).expect("No GPU found") {
@ -171,7 +172,12 @@ pub fn init_backend(
return node; return node;
} }
} }
panic!("Failed to initialize any GPU"); // If we find no render nodes, use primary node
if let Some(primary_node) = primary_node {
return primary_node;
} else {
panic!("Failed to initialize any GPU");
}
}) })
}; };
info!("Using {} as primary gpu for rendering.", primary); info!("Using {} as primary gpu for rendering.", primary);