diff --git a/crates/metal2vulkan-runtime/src/device.rs b/crates/metal2vulkan-runtime/src/device.rs index 14ff7cc0d..17b40027f 100644 --- a/crates/metal2vulkan-runtime/src/device.rs +++ b/crates/metal2vulkan-runtime/src/device.rs @@ -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, diff --git a/crates/metal2vulkan-runtime/src/memory.rs b/crates/metal2vulkan-runtime/src/memory.rs index fc68bc5e0..77d74aa26 100644 --- a/crates/metal2vulkan-runtime/src/memory.rs +++ b/crates/metal2vulkan-runtime/src/memory.rs @@ -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, diff --git a/crates/metal2vulkan-runtime/src/tests/device.rs b/crates/metal2vulkan-runtime/src/tests/device.rs index d7b2a7b4b..123ce20e7 100644 --- a/crates/metal2vulkan-runtime/src/tests/device.rs +++ b/crates/metal2vulkan-runtime/src/tests/device.rs @@ -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,