Skip to content

Commit

Permalink
examples/drm: Don't force card{i} enumeration to start at 0
Browse files Browse the repository at this point in the history
On my setup with an AMD RX6800XT GPU (same happens with an Intel Arc
GPU) there is only `card1` and `renderD128`.  The example would fail
with a "File not found" error for `/dev/dri/card0` when it should
instead continue to iterate to find the first valid DRM device.

A more future-proof solution would be to replace the `0..10` range with
a `readdir()`-like iterator over the contents of `/dev/dri` if that's
accepted for an example.
  • Loading branch information
MarijnS95 committed Nov 29, 2024
1 parent 7b68270 commit 579c392
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/drm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ mod imple {
fn find() -> Result<Card, Box<dyn std::error::Error>> {
for i in 0..10 {
let path = format!("/dev/dri/card{i}");
let device = Card::open(path)?;
// Card enumeration may not start at zero, allow failures while opening
let Ok(device) = Card::open(path) else {
continue;
};

// Only use it if it has connectors.
let handles = match device.resource_handles() {
Ok(handles) => handles,
Err(_) => continue,
let Ok(handles) = device.resource_handles() else {
continue;
};

if handles
Expand Down

0 comments on commit 579c392

Please sign in to comment.