rt test: a device that places the pool's allocations off 16 hands out no block there (red)

What: a device-test answer, DeviceOptions::placed_past (cfg test with a device cfg), adds bytes
to the device address each pool allocation reads from vkGetBufferDeviceAddress, as a device that
places its memory there would answer. every_device_hands_out_no_block_at_an_address_off_16 opens
each device with 4 and asks that no Private or Shared block a take hands out has its first byte
off a multiple of 16.

Why (L84): a block's buffers take their allocation's address as their base. The blocks hold
images bound at memory offsets beside buffers reached by address, so no offset of ours can put
both on their alignment where Vulkan places the allocation off 16, which it may (it promises the
largest of the buffer's memory requirements' alignment and its usages' offset alignments, none
bounded below 16). Metal's offset rule for a device buffer (Apple's setBuffer(_:offset:index:):
the offset aligned to the data type's size, at most 16) asks a base at a multiple of 16. The fix
refuses such an allocation, typed.

How verified: expected red at this commit (the take hands out a block at 4 past 16); the fix
follows.
This commit is contained in:
Anees Iqbal committed 2026-12-02 06:51:00 -08:00
1 parent a4001735fb
commit a4a9d232c8
3 files changed
+45

No files matched your search

+10
View File
@@ -334,6 +334,9 @@ pub(crate) struct Core {
/// ([`DeviceOptions::maker`]).
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) maker_test: memory::MakerTest,
/// For the device tests: [`DeviceOptions::placed_past`].
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) placed_past: u64,
pub(crate) pool: Pool,
/// The runtime's `vkQueueSubmit2` calls inside the driver, which the block-maker thread waits
/// out after each of its memory calls.
@@ -490,6 +493,11 @@ pub struct DeviceOptions {
/// from its first work on.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) maker: memory::MakerTest,
/// For the device tests: bytes added to the device address each allocation of the pool reads
/// (`vkGetBufferDeviceAddress`), as a device that places its memory there would answer; 0
/// for the device's own answer.
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
pub(crate) placed_past: u64,
/// For the device tests: the device's description as the translator is to read it, in place
/// of the device's own answers (a device that answers otherwise); the Vulkan device is the
/// same.
@@ -890,6 +898,8 @@ impl Device {
park_region: Mutex::new(None),
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
maker_test: options.maker,
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
placed_past: options.placed_past,
pool,
submit_calls,
imports,
@@ -2122,6 +2122,10 @@ fn make_allocation(
let of = vk::BufferDeviceAddressInfo::default().buffer(buffer);
// SAFETY: the buffer has device-address usage and is bound.
allocation.address = unsafe { device.get_buffer_device_address(&of) };
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
{
allocation.address += core.placed_past;
}
(core.spans).made(
buffer,
allocation.address,
@@ -269,6 +269,37 @@ fn every_device_of_the_cfgs_kind_opens_presents_and_tears_down_to_zero() {
drop(watch);
}
/// A device that places the pool's allocations off a multiple of 16 (4 bytes past the address
/// Vulkan gives, the test answer `DeviceOptions::placed_past`, as a device whose buffers'
/// memory requirements and offset alignments are all 4 may) hands out no block there, of either
/// class: no buffer a consumer places at a block's first byte lies off 16.
#[cfg(any(m2v_gpu, m2v_cpu_icd))]
#[test]
fn every_device_hands_out_no_block_at_an_address_off_16() {
use crate::tests::command::on_device::each_device_with;
let placed_off = || DeviceOptions {
placed_past: 4,
..DeviceOptions::default()
};
each_device_with("placed_off_16", placed_off, |name, _, device| {
for class in [crate::MemoryClass::Private, crate::MemoryClass::Shared] {
match device.take_block(class, 64 << 10) {
Ok(block) => {
let buffer = (device.new_buffer(block.id, 0, 16, None))
.unwrap_or_else(|error| panic!("{name}: {class:?}: {error}"));
let address = buffer.gpu_address();
assert_eq!(
address % 16,
0,
"{name}: a {class:?} block handed out at {address:#x}"
);
}
Err(error) => println!("{name}: a {class:?} block off 16 refused: {error}"),
}
}
});
}
/// A device torn down while its cache directory's removal thread runs waits for it: opened on a
/// directory with two dead generations, its removal paused 200 ms (the test seam
/// `cache::REMOVAL_PAUSE`), and dropped at once, the device's every gauge reads zero,