rt: the linear row rounding starts at the texel's bytes, so ANV holds a texture over a buffer in place
Device::minimum_linear_texture_alignment answered the smallest power of two from 16 at which the
device lays every width's linear rows at the row rounded up to it, and 16 where none held. ANV
(Mesa 26.2.6) on the Iris Xe of RPL-P lays each linear row at the row itself, with the image's
memory aligned to the texel. Probe m3-max-44665 (never lands) asked R8Unorm, RGBA8Unorm, R32Float,
RGBA16Float and RGBA32Float at 15 widths from 1 to 1,920 texels under read, read+render and
read+write: every pitch was the row and every memory alignment the texel's bytes. So no power of
two from 16 held for texels under 16 bytes. The answer fell back to 16, and a texture over a
Shared buffer at a pitch the guest rounded to 16 was the counted copy wherever its row was not a
multiple of 16. That is the Iris failure of every_device_holds_a_texture_over_a_buffer_in_place at
width 1 (matrix leg m3-max-44561 at e886ee4c74).
The candidates now start at the format's texel bytes, rounded up to a power of two
(linear_rounding). ANV answers the texel (4 for RGBA8Unorm, 1 for R8Unorm). A guest that rounds
its pitch to the answer gets the device's own layout, and its texture is the linear image on the
buffer's memory. Devices that pad rows to 16 or more answer as before: RADV on the RX 550 still
answers 256 for 1- to 4-byte texels and 512 and 1,024 for 8- and 16-byte ones, in the same probe
(m3-max-44666). Metal on the M3 answers 16 for every format; a smaller answer is the device's, as
RADV's larger one is.
The device test asked an RGBA8Unorm texture at (row + 1) rounded up to the answer. That is the
device's pitch only where the answer is 32 or more, so it now asks the row rounded up to the
answer, which has rows longer than their texels on a device that pads. The test's range check
takes each format's texel bytes as its floor. The docs said a pitch that is any multiple of the
answer is in place; it is the row rounded up to the answer.
Verified: cargo fmt. the_linear_row_rounding_starts_at_the_texel (rt tests::texture, no device)
fails under the old floor of 16 for rows laid at the row itself, and pins RADV's padded answers
and a floored layout's none.
This commit is contained in:
1 parent
22a08e242d
commit
7fd80ec2b4
4 files changed
+83
-40
No files matched your search
@@ -335,18 +335,21 @@ made, with no lock, and never rewritten for layouts.
|
||||
SDK says Managed storage has no effect on Apple silicon; the documented contract, not that
|
||||
answer, is the rule here.
|
||||
- `Device::minimum_linear_texture_alignment(pixel_format)` answers
|
||||
`minimumLinearTextureAlignmentForPixelFormat:` with the device's linear row rounding: the
|
||||
smallest power of two from 16 to 4,096 at which the device lays the rows of a 3-row linear
|
||||
image of each width of 1, 3, 17, 64, 65, 100, 129, 1,000 and 1,920 texels at the row rounded up
|
||||
to it; the largest over shader read, read and render, and read and write, where the device
|
||||
makes such images; 16 where no candidate holds, and a texture of that format over a buffer is
|
||||
then never in place. Each image is made, read and destroyed, never bound, once per format for
|
||||
`minimumLinearTextureAlignmentForPixelFormat:` with the device's linear row rounding: the smallest
|
||||
power of two from the format's texel bytes to 4,096 at which the device lays the rows of a 3-row
|
||||
linear image of each width of 1, 3, 17, 64, 65, 100, 129, 1,000 and 1,920 texels at the row
|
||||
rounded up to it; the largest over shader read, read and render, and read and write, where the
|
||||
device makes such images; 16 where no candidate holds, and a texture of that format over a buffer
|
||||
is then never in place. Each image is made, read and destroyed, never bound, once per format for
|
||||
the device's life. The answer leaves out the image's memory alignment
|
||||
(`VkMemoryRequirements::alignment`): a texture whose pitch is a multiple of the answer is in
|
||||
place, at the widths tried, only where its place in the buffer's memory is a multiple of that
|
||||
alignment too, and copied elsewhere. NVIDIA and
|
||||
AMD give the same number for both; the UHD 630 rounds rows to 64 bytes and aligns its linear
|
||||
images' memory to 4,096. The answer promises nothing for widths not tried.
|
||||
(`VkMemoryRequirements::alignment`): a texture whose pitch is its row rounded up to the answer is
|
||||
in place, at the widths tried, only where its place in the buffer's memory is a multiple of that
|
||||
alignment too, and copied elsewhere. NVIDIA gives the same number for both, as RADV (Mesa 26.2.6)
|
||||
on the RX 550 does for texels of up to 4 bytes (256), where it answers 512 and 1,024 for 8- and
|
||||
16-byte texels over a 256-byte alignment; the UHD 630 rounds rows to 64 bytes and aligns its
|
||||
linear images' memory to 4,096; ANV (Mesa 26.2.6) on the Iris Xe of RPL-P lays each row at the row
|
||||
itself with its memory aligned to the texel, so it answers the texel's bytes (4 for `RGBA8Unorm`,
|
||||
1 for `R8Unorm`), below Metal's 16. The answer promises nothing for widths not tried.
|
||||
- The staging region is 16 MiB of the Shared type in an allocation of its own, made at the first
|
||||
copy, its pages written then, and kept for the device's life, so no copy allocates memory and
|
||||
the host writes resident pages. It is a ring: each copy takes a span at a multiple of 256 bytes,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
//! Textures over a buffer: under a device cfg, on every device of the cfg's kind, the linear
|
||||
//! alignment answer is a power of two from 16 to 4,096, the same when asked again, and the count
|
||||
//! of formats that answer 16 is printed; at each width tried, a texture over a Shared buffer whose
|
||||
//! alignment answer is a power of two from the format's texel bytes to 4,096, the same when asked
|
||||
//! again, and the count of formats that answer 16 is printed; at each width tried, a texture over a Shared buffer whose
|
||||
//! pitch is its row rounded up to the answer, at a place of the linear image's memory alignment,
|
||||
//! is in place; an RGBA8Unorm texture over a Shared buffer at a pitch of the answer, its rows
|
||||
//! longer than their texels, at such a place, is made in place: it allocates nothing (live
|
||||
//! is in place; an RGBA8Unorm texture over a Shared buffer at its row rounded up to the answer
|
||||
//! (longer than its texels where the device pads rows), at such a place, is made in place: it allocates nothing (live
|
||||
//! allocations counted once the block-maker thread holds a ready block of each class, the count
|
||||
//! that a plain texture's allocation moves) and stages nothing, its image's bytes are the host's
|
||||
//! in the buffer as they change, `replace_region` and `get_bytes` write and read the
|
||||
@@ -29,13 +29,13 @@ mod on_device {
|
||||
/// The buffer's offset in its block: a multiple of every answer and memory alignment.
|
||||
const AT: u64 = 65_536;
|
||||
const LEN: u64 = 65_536;
|
||||
/// The formats whose answers are printed.
|
||||
const FORMATS: [PixelFormat; 5] = [
|
||||
PixelFormat::R8Unorm,
|
||||
PixelFormat::RGBA8Unorm,
|
||||
PixelFormat::R32Float,
|
||||
PixelFormat::RGBA16Float,
|
||||
PixelFormat::RGBA32Float,
|
||||
/// The formats whose answers are printed, each with its texel bytes.
|
||||
const FORMATS: [(PixelFormat, u64); 5] = [
|
||||
(PixelFormat::R8Unorm, 1),
|
||||
(PixelFormat::RGBA8Unorm, 4),
|
||||
(PixelFormat::R32Float, 4),
|
||||
(PixelFormat::RGBA16Float, 8),
|
||||
(PixelFormat::RGBA32Float, 16),
|
||||
];
|
||||
|
||||
fn whole() -> Region {
|
||||
@@ -100,11 +100,11 @@ mod on_device {
|
||||
fn every_device_holds_a_texture_over_a_buffer_in_place() {
|
||||
each_device("over", |name, _, device| {
|
||||
let mut answers = Vec::new();
|
||||
for pf in FORMATS {
|
||||
for (pf, texel) in FORMATS {
|
||||
let answer = (device.minimum_linear_texture_alignment(pf))
|
||||
.unwrap_or_else(|error| panic!("{name}: {pf:?}: {error}"));
|
||||
assert!(
|
||||
answer.is_power_of_two() && (16..=4096).contains(&answer),
|
||||
answer.is_power_of_two() && (texel..=4096).contains(&answer),
|
||||
"{name}: {pf:?}: {answer}"
|
||||
);
|
||||
answers.push((pf, answer));
|
||||
@@ -151,7 +151,7 @@ mod on_device {
|
||||
"{name}: width {width} at the answer's pitch is in place"
|
||||
);
|
||||
}
|
||||
let pitch = (ROW + 1).next_multiple_of(align);
|
||||
let pitch = ROW.next_multiple_of(align);
|
||||
// Read and written by shaders, at indices of a grant.
|
||||
(device.grant_indices(IndexClass::StorageTexture, 1, 4)).expect("a grant");
|
||||
let mut d =
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
//! again.
|
||||
//! - A view's components are Metal's swizzle over the format's own mapping: zero and one stay,
|
||||
//! and a channel source reads through the format's mapping.
|
||||
//! - The linear row rounding starts at the texel's bytes: rows laid at the row itself answer the
|
||||
//! texel's bytes, rows padded to a power of two answer it, and rows padded otherwise answer none.
|
||||
//! - Under a device cfg, on every device of the cfg's kind: bytes written with `replace_region`
|
||||
//! read back with `get_bytes`, the same, for a level of a 2D texture, rows apart at a pitch with
|
||||
//! padding, a 3D region two images deep, a slice of an array, a cube's face, a depth texture,
|
||||
@@ -21,7 +23,7 @@
|
||||
|
||||
use crate::arrays::Grants;
|
||||
use crate::error::{Error, Refusal};
|
||||
use crate::texture::{components, shape};
|
||||
use crate::texture::{components, linear_rounding, shape};
|
||||
use crate::{IndexClass, PixelFormat, TextureDescriptor, TextureType};
|
||||
use ash::vk;
|
||||
use metal2vulkan::metal::{TextureSwizzle, TextureSwizzleChannels};
|
||||
@@ -494,3 +496,30 @@ mod on_device {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The linear row rounding of a format of `texel` bytes over the minimum linear texture
|
||||
/// alignment's widths, where the device lays a row of `row` bytes at `pitch(row)`.
|
||||
fn rounding(texel: u64, pitch: impl Fn(u64) -> u64) -> Option<u64> {
|
||||
let rows: Vec<(u64, u64)> = [1, 3, 17, 64, 65, 100, 129, 1000, 1920]
|
||||
.map(|width| {
|
||||
let row = width * texel;
|
||||
(row, pitch(row))
|
||||
})
|
||||
.to_vec();
|
||||
linear_rounding(&rows, texel)
|
||||
}
|
||||
|
||||
/// A device that lays a linear row at the row itself (ANV, Mesa 26.2.6, on the Iris Xe of RPL-P:
|
||||
/// every format and width the over test asks) answers each format's texel bytes, below 16 for all
|
||||
/// but the 16-byte texels; one that pads rows to a power of two (RADV on Polaris: 256 bytes, 512
|
||||
/// for 8-byte texels) answers that power; one whose rows have a floor besides their rounding
|
||||
/// answers none, which the device then reports as 16.
|
||||
#[test]
|
||||
fn the_linear_row_rounding_starts_at_the_texel() {
|
||||
for texel in [1, 2, 4, 8, 16] {
|
||||
assert_eq!(rounding(texel, |row| row), Some(texel), "{texel}");
|
||||
}
|
||||
assert_eq!(rounding(4, |row| row.next_multiple_of(256)), Some(256));
|
||||
assert_eq!(rounding(8, |row| row.next_multiple_of(512)), Some(512));
|
||||
assert_eq!(rounding(4, |row| row.max(64)), None);
|
||||
}
|
||||
@@ -448,16 +448,17 @@ impl Device {
|
||||
}
|
||||
|
||||
/// `minimumLinearTextureAlignmentForPixelFormat:`: the device's linear row rounding, the
|
||||
/// smallest power of two from 16 to 4,096 at which the device lays the rows of a linear image
|
||||
/// of the format, of every width tried, at the row rounded up to it; the largest over reading,
|
||||
/// reading and rendering, and reading and a shader's writes, where the device makes such an
|
||||
/// image; Metal's 16 where no candidate holds, so that a texture of the format over a buffer
|
||||
/// is never in place. The device answers: each image is made, read with
|
||||
/// `vkGetImageSubresourceLayout` and destroyed, never bound, once per format for the device's
|
||||
/// life. The answer differs by device, as Metal's does by GPU.
|
||||
/// smallest power of two from the format's texel bytes to 4,096 at which the device lays the
|
||||
/// rows of a linear image of the format, of every width tried, at the row rounded up to it;
|
||||
/// the largest over reading, reading and rendering, and reading and a shader's writes, where
|
||||
/// the device makes such an image; Metal's 16 where no candidate holds, so that a texture of
|
||||
/// the format over a buffer is never in place. The device answers: each image is made, read
|
||||
/// with `vkGetImageSubresourceLayout` and destroyed, never bound, once per format for the
|
||||
/// device's life. The answer differs by device, as Metal's does by GPU, and is below Metal's 16
|
||||
/// on a device that lays a linear row at the row itself.
|
||||
///
|
||||
/// A texture over a buffer ([`Buffer::new_texture`]) whose pitch is a multiple of the answer
|
||||
/// is in place where its place in the buffer's memory is also a multiple of the linear
|
||||
/// A texture over a buffer ([`Buffer::new_texture`]) whose pitch is its row rounded up to the
|
||||
/// answer is in place where its place in the buffer's memory is also a multiple of the linear
|
||||
/// image's memory alignment (`VkMemoryRequirements::alignment`), which the answer does not
|
||||
/// include; at any other place it is copied.
|
||||
///
|
||||
@@ -480,6 +481,7 @@ impl Device {
|
||||
let mut answer = None;
|
||||
for usage in usages {
|
||||
let mut rows = Vec::with_capacity(WIDTHS.len());
|
||||
let mut texel = 1;
|
||||
for width in WIDTHS {
|
||||
let mut d = TextureDescriptor::new(TextureType::Type2D, pixel_format, width, 3);
|
||||
d.usage = usage;
|
||||
@@ -494,16 +496,13 @@ impl Device {
|
||||
let Some((pitch, _)) = linear_layout(core, &d, &shape, &plan) else {
|
||||
break;
|
||||
};
|
||||
texel = u64::from(unit.bytes);
|
||||
rows.push((u64::from(width * unit.bytes), pitch));
|
||||
}
|
||||
if rows.len() < WIDTHS.len() {
|
||||
continue;
|
||||
}
|
||||
let holds = |candidate: u64| {
|
||||
(rows.iter()).all(|&(row, pitch)| pitch == row.next_multiple_of(candidate))
|
||||
};
|
||||
let found = (4..=12).map(|power| 1u64 << power).find(|&p| holds(p));
|
||||
answer = answer.max(found);
|
||||
answer = answer.max(linear_rounding(&rows, texel));
|
||||
}
|
||||
let answer = answer.unwrap_or(16);
|
||||
lock(&core.linear_alignments).insert(pixel_format, answer);
|
||||
@@ -959,6 +958,18 @@ fn linear_extent(core: &Core, shape: &Shape, plan: &Plan) -> Option<vk::Extent3D
|
||||
|
||||
/// The row pitch and memory alignment of a linear image of `d`, `shape` and `plan`, where the
|
||||
/// device makes one: the image is made, read and destroyed, never bound.
|
||||
/// The smallest power of two from `texel` (a texel's bytes, rounded up to one) to 4,096 at which
|
||||
/// every `(row, pitch)`, a linear image's row bytes and the pitch the device lays it at, has its
|
||||
/// pitch at the row rounded up to it; `None` where none has. A device that lays a row at the row
|
||||
/// itself answers the texel's bytes: a texture over a buffer at any pitch of whole texels is then
|
||||
/// its linear image.
|
||||
pub(crate) fn linear_rounding(rows: &[(u64, u64)], texel: u64) -> Option<u64> {
|
||||
let first = texel.next_power_of_two().trailing_zeros();
|
||||
(first..=12).map(|power| 1u64 << power).find(|&candidate| {
|
||||
(rows.iter()).all(|&(row, pitch)| pitch == row.next_multiple_of(candidate))
|
||||
})
|
||||
}
|
||||
|
||||
fn linear_layout(
|
||||
core: &Core,
|
||||
d: &TextureDescriptor,
|
||||
|
||||
Reference in new issue
Block a user