vulkano-rs/vulkano

[vulkano-util] Add option to choose surface by formats

rauba-code opened this issue · 1 comments

  • Version of vulkano: master (d08d9f)

Issue

Hello,

I'd like to raise a problem arising when using vulkano-util with window surface creation. Current implementation takes the first surface from the list when creating Window instance (see: https://github.com/vulkano-rs/vulkano/blob/d08d9f587da6d2bbef2f1857e6685c6ba590d5c5/vulkano-util/src/renderer.rs#L91C1-L95C16) which may not be optimal when rendering R8G8B8A8_UNORM-formatted texels to the screen (requires additional format conversions that may produce suboptimal results, especially with color samplers and more complex graphics pipelines).

The list of available surface formats depends on the device and display manager (X, Wayland or other). I tested on 2 Linux machines and an Apple one. All configurations show different surface formats in the list, the first of them being B8G8R8A8_SRGB, R8B8B8A8_SRGB or even HDR-related for Apple ones.

Thus, I am thinking if a user-defined function would help to choose an available surface format. Alternatives might exist, though. Thank you

EDIT 2024-01-04: I have managed to make a workaround in my project with setting mutable swapchain format where the default one is provided by the window (say, {format}_SRGB and the alternative view is {format}_UNORM, while handling all the possible image formats. The graphics pipeline must be handled in {format}_UNORM for correct rendering. Although it needs an unnecessary khr_swapchain_mutable_format device extension and this issue is still relevant.

You can set the format using the function swapchain_create_info_modify:

    let _id = windows.create_window(
        &event_loop,
        &context,
        &WindowDescriptor::default(),
        |s| {
            s.image_format = YOUR_FORMAT
        },
    );