Merge branch 'gpu_drm35' into 'main'

Couple of GPU buffer improvements

See merge request redox-os/base!198
This commit is contained in:
Jeremy Soller
2026-03-23 07:23:21 -06:00
4 changed files with 35 additions and 43 deletions
+9 -11
View File
@@ -94,7 +94,7 @@ pub trait GraphicsAdapter: Sized + Debug {
fn probe_connector(&mut self, objects: &mut KmsObjects<Self>, id: KmsObjectId);
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> Self::Buffer;
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> (Self::Buffer, u32);
fn map_dumb_buffer(&mut self, buffer: &Self::Buffer) -> *mut u8;
fn create_framebuffer(&mut self, buffer: &Self::Buffer) -> Self::Framebuffer;
@@ -112,8 +112,7 @@ pub trait GraphicsAdapter: Sized + Debug {
}
pub trait Buffer: Debug {
fn width(&self) -> u32;
fn height(&self) -> u32;
fn size(&self) -> usize;
}
pub trait Framebuffer: Debug {}
@@ -843,17 +842,19 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
Ok(0)
}),
ipc::MODE_CREATE_DUMB => ipc::DrmModeCreateDumb::with(payload, |mut data| {
if data.bpp() != 32 {
if data.bpp() != 32 || data.flags() != 0 {
return Err(Error::new(EINVAL));
}
let buffer = self.adapter.create_dumb_buffer(data.width(), data.height());
let (buffer, pitch) =
self.adapter.create_dumb_buffer(data.width(), data.height());
data.set_pitch(pitch);
data.set_size(buffer.size() as u64);
*next_id += 1;
buffers.insert(*next_id, Arc::new(buffer));
data.set_handle(*next_id as u32);
data.set_pitch(data.width() * 4);
data.set_size(u64::from(data.width()) * u64::from(data.height()) * 4);
Ok(0)
}),
ipc::MODE_MAP_DUMB => ipc::DrmModeMapDumb::with(payload, |mut data| {
@@ -868,10 +869,7 @@ impl<T: GraphicsAdapter> SchemeSync for GraphicsSchemeInner<T> {
}
// FIXME use a better scheme for creating map offsets
assert!(
((buffers[&buffer_id].width() * buffers[&buffer_id].height() * 4) as usize)
< MAP_FAKE_OFFSET_MULTIPLIER
);
assert!(buffers[&buffer_id].size() < MAP_FAKE_OFFSET_MULTIPLIER);
data.set_offset((buffer_id as usize * MAP_FAKE_OFFSET_MULTIPLIER) as u64);
+4 -8
View File
@@ -75,8 +75,8 @@ impl GraphicsAdapter for Device {
// FIXME fetch EDID
}
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> Self::Buffer {
DumbFb::new(width as usize, height as usize)
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> (Self::Buffer, u32) {
(DumbFb::new(width as usize, height as usize), width * 4)
}
fn map_dumb_buffer(&mut self, framebuffer: &Self::Buffer) -> *mut u8 {
@@ -175,12 +175,8 @@ impl Drop for DumbFb {
}
impl Buffer for DumbFb {
fn width(&self) -> u32 {
self.width as u32
}
fn height(&self) -> u32 {
self.height as u32
fn size(&self) -> usize {
self.width * self.height * 4
}
}
+7 -8
View File
@@ -80,8 +80,11 @@ impl GraphicsAdapter for FbAdapter {
connector.update_from_size(connector.driver_data.width, connector.driver_data.height);
}
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> Self::Buffer {
GraphicScreen::new(width as usize, height as usize)
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> (Self::Buffer, u32) {
(
GraphicScreen::new(width as usize, height as usize),
width * 4,
)
}
fn map_dumb_buffer(&mut self, framebuffer: &Self::Buffer) -> *mut u8 {
@@ -239,12 +242,8 @@ impl Drop for GraphicScreen {
}
impl Buffer for GraphicScreen {
fn width(&self) -> u32 {
self.width as u32
}
fn height(&self) -> u32 {
self.height as u32
fn size(&self) -> usize {
self.width * self.height * 4
}
}
+15 -16
View File
@@ -57,12 +57,8 @@ impl<'a> fmt::Debug for VirtGpuFramebuffer<'a> {
}
impl DrmBuffer for VirtGpuFramebuffer<'_> {
fn width(&self) -> u32 {
self.width
}
fn height(&self) -> u32 {
self.height
fn size(&self) -> usize {
(self.width * self.height * 4) as usize
}
}
@@ -251,12 +247,12 @@ impl VirtGpuAdapter<'_> {
fn disable_cursor(&mut self) {
if self.hidden_cursor.is_none() {
let (width, height) = self.hw_cursor_size().unwrap();
let cursor = self.create_dumb_buffer(width, height);
let (cursor, stride) = self.create_dumb_buffer(width, height);
unsafe {
core::ptr::write_bytes(
cursor.sgl.as_ptr() as *mut u8,
0,
(width * height * 4) as usize,
(stride * height) as usize,
);
}
self.hidden_cursor = Some(Arc::new(cursor));
@@ -336,7 +332,7 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
});
}
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> Self::Buffer {
fn create_dumb_buffer(&mut self, width: u32, height: u32) -> (Self::Buffer, u32) {
futures::executor::block_on(async {
let bpp = 32;
let fb_size = width as usize * height as usize * bpp / 8;
@@ -385,13 +381,16 @@ impl<'a> GraphicsAdapter for VirtGpuAdapter<'a> {
self.control_queue.send(command).await;
assert_eq!(header.ty, CommandTy::RespOkNodata);
VirtGpuFramebuffer {
queue: self.control_queue.clone(),
id: res_id,
sgl,
width,
height,
}
(
VirtGpuFramebuffer {
queue: self.control_queue.clone(),
id: res_id,
sgl,
width,
height,
},
width * 4,
)
})
}