Skip to content

Commit 1ea938b

Browse files
committed
vulkan: add some more format mappings
found in mesa: src/vulkan/wsi/wsi_common_wayland.c
1 parent 542b4f6 commit 1ea938b

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ lazy_static = "~1.5"
2424
xdg = "~2.5"
2525
dbus = "~0.9"
2626
anyhow = "~1.0"
27+
drm-fourcc = "~2.2"
2728

2829
[dev-dependencies]
2930
mockall = "0.13"

src/frame/vulkan.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::frame::compute_perceived_lightness_percent;
22
use crate::frame::object::Object;
33
use ash::khr::external_memory_fd::Device as KHRDevice;
44
use ash::{vk, Device, Entry, Instance};
5+
use drm_fourcc::DrmFourcc;
56
use std::default::Default;
67
use std::error::Error;
78
use std::ffi::CString;
@@ -886,9 +887,23 @@ fn find_memory_type_index(
886887
}
887888

888889
fn map_drm_format(format: u32) -> Result<vk::Format, Box<dyn Error>> {
889-
match format {
890-
875713112 => Ok(vk::Format::B8G8R8A8_UNORM),
891-
808669784 => Ok(vk::Format::A2R10G10B10_UNORM_PACK32),
892-
_ => Err(format!("Frame with formats other than DRM_FORMAT_XRGB8888 or DRM_FORMAT_XRGB2101010 are not supported yet (yours is {format}). If you see this issue, please open a GitHub issue (unless there's one already open) and share your format value").into()),
890+
let drm = DrmFourcc::try_from(format)?;
891+
log::debug!("Processing frame in DRM format {drm}");
892+
893+
match drm {
894+
DrmFourcc::Rgbx4444 => Ok(vk::Format::R4G4B4A4_UNORM_PACK16),
895+
DrmFourcc::Bgrx4444 => Ok(vk::Format::B4G4R4A4_UNORM_PACK16),
896+
DrmFourcc::Rgb565 => Ok(vk::Format::R5G6B5_UNORM_PACK16),
897+
DrmFourcc::Bgr565 => Ok(vk::Format::B5G6R5_UNORM_PACK16),
898+
DrmFourcc::Xrgb1555 => Ok(vk::Format::A1R5G5B5_UNORM_PACK16),
899+
DrmFourcc::Rgbx5551 => Ok(vk::Format::R5G5B5A1_UNORM_PACK16),
900+
DrmFourcc::Bgrx5551 => Ok(vk::Format::B5G5R5A1_UNORM_PACK16),
901+
DrmFourcc::Xrgb2101010 => Ok(vk::Format::A2R10G10B10_UNORM_PACK32),
902+
DrmFourcc::Xbgr2101010 => Ok(vk::Format::A2B10G10R10_UNORM_PACK32),
903+
DrmFourcc::Xbgr16161616f => Ok(vk::Format::R16G16B16A16_SFLOAT),
904+
DrmFourcc::Xbgr8888 => Ok(vk::Format::R8G8B8A8_UNORM),
905+
DrmFourcc::Bgrx8888 => Ok(vk::Format::B8G8R8_UNORM),
906+
DrmFourcc::Xrgb8888 => Ok(vk::Format::B8G8R8A8_UNORM),
907+
_ => Err(format!("Unsupported DRM format: {format}. Please report on GitHub.").into()),
893908
}
894909
}

0 commit comments

Comments
 (0)