From 3c11da8aea7c957c811651c56de2f7d20978fd6e Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Thu, 6 Mar 2025 11:51:09 -0600 Subject: [PATCH] nil: Relax alignment requirements for linear images Compositors sometime try to import BOs with lower alignments than 128B. This seems particularly common in the case of cursor images but it can also happen on other BOs allocated by the old nouveau GL driver. As long as we avoid rendering to them (which NVK will do), the texture/image hardware is fine as long as they're at least 32B-aligned. Panicing in this case isn't very nice to compositors. Backport-to: 25.0 Reviewed-by: Mel Henning Part-of: --- src/nouveau/nil/image.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/nouveau/nil/image.rs b/src/nouveau/nil/image.rs index 477c78ae9a7..f4b09e24c42 100644 --- a/src/nouveau/nil/image.rs +++ b/src/nouveau/nil/image.rs @@ -348,10 +348,12 @@ impl Image { let row_stride_B = if info.explicit_row_stride_B > 0 { assert!(info.modifier == DRM_FORMAT_MOD_LINEAR); - assert!(info.explicit_row_stride_B % 128 == 0); - info.explicit_row_stride_B + // Texture headers require strides to be 32B-aligned + debug_assert!(info.explicit_row_stride_B % 32 == 0); + info.explicit_row_stride_B.next_multiple_of(32) } else { - // Row stride needs to be aligned to 128B for render to work + // If we get to pick the alignment, require 128B so that we + // can render to the image without workarounds. lvl_ext_B.width.next_multiple_of(128) }; @@ -413,8 +415,14 @@ impl Image { image.align_B = std::cmp::max(image.align_B, 1 << 16); } } else { - // Linear images need to be aligned to 128B for render to work - image.align_B = std::cmp::max(image.align_B, 128); + if info.explicit_row_stride_B > 0 { + // Linear images need to be aligned to 32B + image.align_B = std::cmp::max(image.align_B, 32); + } else { + // If we get to pick the alignment, require 128B so that we + // can render to the image without workarounds. + image.align_B = std::cmp::max(image.align_B, 128); + } } image.size_B = image.size_B.next_multiple_of(image.align_B.into());