Skip to content

GPU: How can the framebuffer be reused? #188

Description

@tpdenk

// SAFETY: `Dma::new` guarantees that the pointer returned from
// `raw_slice` is non-null, aligned, and the allocation is zeroed. We
// store the `Dma` object in `self.frame_buffer_dma`, which prevents the
// allocation from being freed while `self` exists. The returned ptr
// borrows `self` mutably, which prevents other code from getting
// another reference to `frame_buffer_dma` while the returned slice is
// still in use.

This is accurate, but this also prevents me from reusing the framebuffer that was set up. From the example:

    let fb = gpu.setup_framebuffer().expect("failed to get fb");
    for y in 0..height {
        for x in 0..width {
            let idx = (y * width + x) * 4;
            fb[idx] = x as u8;
            fb[idx + 1] = y as u8;
            fb[idx + 2] = (x + y) as u8;
        }
    }
    gpu.flush().expect("failed to flush");

I can't update the framebuffer once I've flushed, but the only way to get another framebuffer is to call setup_framebuffer again, which does a full framebuffer allocation again.

(so the following wouldn't compile)

let fb = gpu.setup_framebuffer()?;
fb.fill(0xaa);
gpu.flush()?;
fb.fill(0xbb);
gpu.flush()?;

How was the framebuffer intended to be used? Am I missing something? Do I need to manually track the allocations from the Hal?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions