#gpu

drm

Safe, low-level bindings to the Direct Rendering Manager API

17 unstable releases (8 breaking)

Uses old Rust 2015

0.9.0 Mar 24, 2023
0.7.0 Aug 29, 2022
0.6.2 Jan 26, 2022
0.6.1 Dec 28, 2021
0.1.0 Jan 24, 2017

#100 in Unix APIs

Download history 1027/week @ 2023-02-06 1102/week @ 2023-02-13 764/week @ 2023-02-20 654/week @ 2023-02-27 975/week @ 2023-03-06 972/week @ 2023-03-13 992/week @ 2023-03-20 969/week @ 2023-03-27 1003/week @ 2023-04-03 794/week @ 2023-04-10 788/week @ 2023-04-17 839/week @ 2023-04-24 783/week @ 2023-05-01 566/week @ 2023-05-08 732/week @ 2023-05-15 649/week @ 2023-05-22

2,836 downloads per month
Used in 4 crates

MIT license

135KB
3K SLoC

drm-rs

Crates.io docs.rs Build Status

A safe interface to the Direct Rendering Manager.

Direct Rendering Manager

The Direct Rendering Manager is a subsystem found on multiple Unix-based operating systems that provides a userspace API to graphics hardware. See the Wikipedia article for more details.

Usage

Basic

The DRM is accessed using ioctls on a file representing a graphics card. These can normally be found in /dev/dri, but can also be opened in other ways (ex. udev).

This crate does not provide a method of opening these files. Instead, the user program must provide a way to access the file descriptor representing the device through the AsRawFd trait. Here is a basic example using File as a backend:

/// A simple wrapper for a device node.
pub struct Card(std::fs::File);

/// Implementing [`AsFd`] is a prerequisite to implementing the traits found
/// in this crate. Here, we are just calling [`File::as_fd()`] on the inner
/// [`File`].
impl AsFd for Card {
    fn as_fd(&self) -> BorrowedFd<'_> {
        self.0.as_fd()
    }
}

/// Simple helper methods for opening a `Card`.
impl Card {
    pub fn open(path: &str) -> Self {
        let mut options = std::fs::OpenOptions::new();
        options.read(true);
        options.write(true);
        Card(options.open(path).unwrap())
    }
}

Finally, you can implement drm::Device to gain access to the basic DRM functionality:

impl drm::Device for Card {}

fn main() {
    let gpu = Card::open("/dev/dri/card0");
    println!("{:#?}", gpu.get_driver().unwrap());
}

Control (modesetting)

See drm::control::Device as well as our mode-setting examples: atomic_modeset and legacy_modeset

Rendering

Rendering is done by creating and attaching framebuffers to crtcs.

A framebuffer is created from anything implementing Buffer like the always available, but very limited, DumbBuffer.

For faster hardware-backed buffers, checkout gbm.rs.

Dependencies

~3MB
~70K SLoC