atagen

monolith

public
Star0
Watch0

Commit f0e45b059808

tarball

atagen <boss@atagen.co>2026-10-19 07:56 UTC

3 files changed+10-2
render-vk: report sample-only dmabuf imports as unreadable

can_read_texture returned true for any imported dmabuf, but SAMPLE_USAGE has no TRANSFER_SRC so copy_texture would copy from an image the driver never allowed as a source. ImageInner now records its usage.
Modified file: crates/render-vk/src/dmabuf.rs+1 additions
@@ -269,6 +269,7 @@ pub(crate) fn import(
269269 format.code,
270270 size.0,
271271 size.1,
272+ usage,
272273 true,
273274 )
274275 }
Modified file: crates/render-vk/src/image.rs+4 additions−1 deletions
@@ -25,6 +25,7 @@ pub(crate) struct ImageInner {
2525 pub format: vk::Format,
2626 pub width: u32,
2727 pub height: u32,
28+ pub usage: vk::ImageUsageFlags,
2829 pub layout: Mutex<vk::ImageLayout>,
2930 /// Shared with other devices or processes through a dmabuf. Every use
3031 /// acquires the image from the foreign queue family and releases it after.
@@ -117,7 +118,7 @@ impl ImageInner {
117118 Memory::Imported(m) => (*m, 0),
118119 };
119120 Self::finish(
120- shared, image, memory, mem, offset, fourcc, width, height, false,
121+ shared, image, memory, mem, offset, fourcc, width, height, usage, false,
121122 )
122123 }
123124
@@ -133,6 +134,7 @@ impl ImageInner {
133134 fourcc: Fourcc,
134135 width: u32,
135136 height: u32,
137+ usage: vk::ImageUsageFlags,
136138 external: bool,
137139 ) -> Result<Arc<Self>, Error> {
138140 let fmt = vk_format(fourcc).ok_or(Error::UnsupportedFormat(fourcc))?;
@@ -146,6 +148,7 @@ impl ImageInner {
146148 format: fmt.format,
147149 width,
148150 height,
151+ usage,
149152 layout: Mutex::new(if external {
150153 vk::ImageLayout::GENERAL
151154 } else {
Modified file: crates/render-vk/src/renderer/mod.rs+5 additions−1 deletions
@@ -1018,7 +1018,11 @@ impl ExportMem for VulkanRenderer {
10181018 }
10191019
10201020 fn can_read_texture(&mut self, texture: &VulkanTexture) -> Result<bool, Error> {
1021- Ok(texture.0.external || texture.0.layout() != vk::ImageLayout::UNDEFINED)
1021+ let image = &texture.0;
1022+ let written = image.external
1023+ || image.layout() != vk::ImageLayout::UNDEFINED
1024+ || self.uploads.iter().any(|u| Arc::ptr_eq(&u.image, image));
1025+ Ok(written && image.usage.contains(vk::ImageUsageFlags::TRANSFER_SRC))
10221026 }
10231027
10241028 fn map_texture<'a>(&mut self, mapping: &'a VulkanMapping) -> Result<&'a [u8], Error> {