From 4ebcf0252951670efa0493528047bbbb5907a4cf Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 08:24:30 -0800 Subject: [PATCH] An A8Unorm texture that only reads is held in red where A8's DRM_FORMAT_MOD_LINEAR modifier lacks what R8's has red_held_alpha asked only the linear tiling: where A8_UNORM's linear image lacks what its optimal one does and R8_UNORM's lacks nothing. The RTX 3090 (620.70.06) reports A8's linear tiling complete but lists no DRM_FORMAT_MOD_LINEAR modifier for A8 at all, so an A8 texture at any pitch but the driver's linear image's (128-byte multiples) was a shadow there, where an R8 texture over the same bytes takes an image with an explicit plane at the buffer's pitch. Now a read-only A8 texture is held in red where its plan's image lacks something in either tiling a texture over a buffer takes (linear, and DRM_FORMAT_MOD_LINEAR where the device makes such images: vkGetPhysicalDeviceFormatProperties2's VkDrmFormatModifierPropertiesListEXT, Device::modifier_features, now visible to the texture module) and the R8 plan's image lacks nothing in either. Reads go through (0,0,0,R) as before. Verified: cargo fmt; device runs follow (tests::a8_over_buffers holds the A8 texture to the R8 one's shadows). --- crates/metal2vulkan-runtime/src/dma_buf.rs | 2 +- crates/metal2vulkan-runtime/src/texture.rs | 2 +- .../src/texture/red_held_alpha.rs | 48 ++++++++++++------- .../metal2vulkan-runtime/src/texture/route.rs | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/dma_buf.rs b/crates/metal2vulkan-runtime/src/dma_buf.rs index 265a9bcd9..3c8ed6459 100644 --- a/crates/metal2vulkan-runtime/src/dma_buf.rs +++ b/crates/metal2vulkan-runtime/src/dma_buf.rs @@ -2012,7 +2012,7 @@ impl Device { /// writable texture would always lack them. Asked of the driver once per format and kept /// (`TextureState::modifier_features`): a physical device's answer does not change, and ANV's /// took most of the making of a texture over host pages at Metal's row pitch. - fn modifier_features(&self, format: Format) -> FormatFeatureFlags2 { + pub(super) fn modifier_features(&self, format: Format) -> FormatFeatureFlags2 { let kept = &self.shared().textures.modifier_features; if let Some(&features) = lock(kept).get(&format) { return features; diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 1fa93a1a1..f8b102f96 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -2463,7 +2463,7 @@ impl Device { .shared() .textures .facts(self.compile_device().profile()); - let storage = match red_held_alpha::red_held_alpha(descriptor, layout, &facts) { + let storage = match red_held_alpha::red_held_alpha(self, descriptor, layout, &facts) { Some(held) => { let storage = self.storage_over_buffer(call, over, &held.descriptor, &held.layout)?; diff --git a/crates/metal2vulkan-runtime/src/texture/red_held_alpha.rs b/crates/metal2vulkan-runtime/src/texture/red_held_alpha.rs index a37193d3d..d05a38e19 100644 --- a/crates/metal2vulkan-runtime/src/texture/red_held_alpha.rs +++ b/crates/metal2vulkan-runtime/src/texture/red_held_alpha.rs @@ -1,15 +1,17 @@ //! An `A8Unorm` texture over a buffer's bytes whose image is an `R8Unorm` texture's, read -//! through `(Zero, Zero, Zero, Red)`: where the device's linear `A8_UNORM` image lacks what its -//! optimal image does for the texture's usage, and its linear `R8_UNORM` image lacks nothing. +//! through `(Zero, Zero, Zero, Red)`: where the device's `A8_UNORM` image in a tiling a texture +//! over a buffer takes (linear, or `DRM_FORMAT_MOD_LINEAR`) lacks what its optimal image does for +//! the texture's usage, and its `R8_UNORM` image in neither lacks anything. //! //! - **Why.** A texture over a buffer's bytes is a linear image over them where the device makes -//! one that does all its optimal image does (`linear_plan::linear_lack`), else a shadow the -//! encoders copy the bytes into and back (`shadow.rs`). NVIDIA's drivers report `A8_UNORM`'s -//! optimal tiling with sampling, linear filtering and transfers, and its linear tiling (and its -//! `DRM_FORMAT_MOD_LINEAR` modifier) with none of them, where `R8_UNORM`'s linear tiling has -//! them all (`vkGetPhysicalDeviceFormatProperties2`'s `linearTilingFeatures` and -//! `optimalTilingFeatures`): every glyph-sized `A8Unorm` texture over a guest's `Shared` -//! buffers was a shadow there. +//! one that does all its optimal image does at the buffer's pitch (`linear_plan::linear_lack`), +//! or else a `DRM_FORMAT_MOD_LINEAR` image with its one plane at that pitch where the modifier's +//! features do the same (`dma_buf.rs`'s `modifier_features`), else a shadow the encoders copy +//! the bytes into and back (`shadow.rs`). The RTX 3090 (620.70.06) lists no +//! `DRM_FORMAT_MOD_LINEAR` modifier for `A8_UNORM` at all, and lists it for `R8_UNORM` with +//! sampling, filtering and transfers (`vkGetPhysicalDeviceFormatProperties2`'s +//! `VkDrmFormatModifierPropertiesListEXT`): an `A8Unorm` texture over a buffer whose rows lie +//! at another pitch than the driver's linear image's was a shadow there. //! - **What.** The texture's storage is the one an `R8Unorm` texture of the same descriptor makes //! over the same bytes (`Device::storage_over_buffer`): the image in place over host pages, an //! image aliasing the buffer's memory, or a shadow where that texture would be one. Its record @@ -29,9 +31,10 @@ //! `A8Unorm` texture in `R8_UNORM` (`metal::format::alpha_in_red`), and its plan lacks nothing //! here. -use super::super::image_plan::{plan_image, ImageFacts}; -use super::super::linear_plan::linear_lack; +use super::super::image_plan::{plan_image, ImageFacts, ImagePlan}; +use super::super::linear_plan::{linear_lack, tiling_lack}; use super::super::texture_descriptor::{texture_usage, TextureDescriptor, TextureLayout}; +use crate::Device; use metal2vulkan::metal::format::{alpha_in_red_format, direct_format, swizzle_over}; use metal2vulkan::metal::{PixelFormat, TextureSwizzleChannels, TextureType, TextureUsage}; @@ -50,9 +53,11 @@ const WRITES: TextureUsage = TextureUsage::RENDER_TARGET .union(TextureUsage::BLOCK_WRITES_ONLY); /// Whether a texture of `descriptor` (checked as `layout`) over a buffer's bytes is made as the -/// format its alpha is held in the red of (the module docs), on the device of `facts`: that -/// texture's descriptor and layout and the read it takes; `None` where it keeps its own route. +/// format its alpha is held in the red of (the module docs), on `device`, whose image facts are +/// `facts`: that texture's descriptor and layout and the read it takes; `None` where it keeps its +/// own route. pub(super) fn red_held_alpha( + device: &Device, descriptor: &TextureDescriptor, layout: &TextureLayout, facts: &ImageFacts<'_>, @@ -69,16 +74,25 @@ pub(super) fn red_held_alpha( } let own = (PixelFormat::ALL.iter().copied()).find(|&other| direct_format(other) == Some(red))?; - // The texture's own plan's linear image lacks what its optimal one does, and the red - // format's lacks nothing. + // Whether a plan's image lacks anything in a tiling a texture over a buffer takes: linear, + // and `DRM_FORMAT_MOD_LINEAR` where the device makes such images. + let modifiers = device.makes_modifier_images(); + let lacks = |plan: &ImagePlan| { + linear_lack(plan, facts).is_some() + || (modifiers + && tiling_lack(plan, facts, |format| device.modifier_features(format)).is_some()) + }; + // The texture's own plan's image lacks something in one, and the red format's in neither. let asked = plan_image(layout, usage, false, facts).ok()?; - linear_lack(&asked, facts)?; + if !lacks(&asked) { + return None; + } let held = TextureLayout { pixel_format: own, ..*layout }; let plan = plan_image(&held, usage, false, facts).ok()?; - if linear_lack(&plan, facts).is_some() { + if lacks(&plan) { return None; } let over = swizzle_over(pf, descriptor.swizzle, own, facts.profile)?; diff --git a/crates/metal2vulkan-runtime/src/texture/route.rs b/crates/metal2vulkan-runtime/src/texture/route.rs index 30322f60b..6b4d6800f 100644 --- a/crates/metal2vulkan-runtime/src/texture/route.rs +++ b/crates/metal2vulkan-runtime/src/texture/route.rs @@ -97,7 +97,7 @@ impl Device { .facts(self.compile_device().profile()); // An `A8Unorm` texture made as an `R8Unorm` texture's storage takes that texture's route // (`texture/red_held_alpha.rs`). - let held = super::red_held_alpha::red_held_alpha(descriptor, layout, &facts); + let held = super::red_held_alpha::red_held_alpha(self, descriptor, layout, &facts); let (descriptor, layout) = match &held { Some(held) => (&held.descriptor, &held.layout), None => (descriptor, layout),