gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 548 forks source link

confused about swapchain and framebuffers in gfx_hal 0.6 #3600

Closed Kikoman90 closed 3 years ago

Kikoman90 commented 3 years ago

Hi !

I'm using gfx_hal for the first time and im having troubling setting everything up before the actual rendering is done. I have configured the swapchain to hold 3 images and now im trying to create a vector of 3 framebuffers with the corresponding swapchain images as attachments. However the only way i have found to get image views of the swapchain images is to use the acquire_image method in the PresentationSurface trait, but the method expects me to then present the images it seems. Yet all i want right now is just to create the framebuffers, not present anything. So im kind of lost here.

This code shows what i wanted to do:


//...
unsafe { surface.configure_swapchain(&device, swapchain_config.clone()); }
//...
let mut framebuffers: Vec<_> = Vec::with_capacity(image_count as usize);
for _ in 0..image_count {
    let (swapchain_image, _) = unsafe { surface.acquire_image(timeout).unwrap() }; // how else am i supposed to get the swapchain image views for framebuffer creation ?

    let framebuffer = unsafe { device.create_framebuffer(
        &render_pass,
            vec![swapchain_image],
        Extent {
            width: extent.width as u32,
            height: extent.height as u32,
            depth: 1,
        }).unwrap()
    };
    framebuffers.push(framebuffer);
}
kvark commented 3 years ago

You may find a bit of context here - https://gfx-rs.github.io/2019/10/01/update.html (in the "New swapchain model" section). Basically, implementing Vulkan's swapchain straight on other APIs appeared to be too sad of a story. So we tried to change the API to work better for all the backends. If you want to see how it works, best check the examples/quad code.

Most importantly, this story evolved to the next level recently. Have a look at https://github.com/gfx-rs/gfx/pull/3571. We found a very nice middle ground - an API matching Vulkan's image-less framebuffers. My recommendation would be to use the API from gfx-master. We are going to be publishing it to 0.7 shortly after https://github.com/gfx-rs/gfx/pull/3586 goes in (this week, likely!).

Kikoman90 commented 3 years ago

Alright well that clears everything up. Thank you so much and good luck with the new release :)