From 2f5f35ca47280887b32d5ce76100f3d9f0ee17c6 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 2 Dec 2026 01:40:41 -0800 Subject: [PATCH] Translator tests: a constant slot reads exactly at residuals 256 and 4096 above its descriptor base PR 18 (rponeawa) reported that a shared-range uniform descriptor could start far below the bind offset (a residual of 256 on a device with a 64-byte uniform offset alignment), past the fixed array the uniform view declared, so the read left the declared array. Its fix sized the array to the device's uniform range. 5e3477e60a (11-22) has since removed the uniform view: every buffer slot's view is a storage word array whose OpArrayLength is the bound range, with no declared size. So the PR is credited by an empty merge and this test pins its case on the view the tree has: the last byte of a constant window, read with residuals 0, 256 and 4096 on every tested profile, is exact. Verified: run in the merge check at the integrated tip, and with the residual's push word forced to 0 (the read lands in the 0xEE fill) to show it is not vacuous; results in the PR report. --- .../metal2vulkan/src/tests/engine_access.rs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/metal2vulkan/src/tests/engine_access.rs b/crates/metal2vulkan/src/tests/engine_access.rs index 7787c15be..e51218f67 100644 --- a/crates/metal2vulkan/src/tests/engine_access.rs +++ b/crates/metal2vulkan/src/tests/engine_access.rs @@ -271,6 +271,32 @@ fn a_constant_buffer_shorter_than_its_window_is_contained_in_shader() { } } +/// A `constant` slot's descriptor can start far below its bind offset: a range several bind +/// offsets share leaves a residual of hundreds or thousands of bytes. The slot's view is a word +/// array whose length is the bound range, with no declared size, so the window's last byte reads +/// exactly at residuals 256 and 4096 as at 0. +#[test] +fn a_constant_slot_reads_exactly_far_above_its_descriptor_base() { + let Some(bc) = assemble_file("buffer_end_byte_load_constant") else { + return; + }; + let data = [1u8, 2, 3, 4, 5, 0x9C]; + for (what, p) in profiles() { + check_l3(&bc, "buffer_end_byte_load_constant", &p, &what); + let (plan, m) = typed_module(&bc, "buffer_end_byte_load_constant", &p).expect("module"); + for r in [0u32, 256, 4096] { + let res = Resources { + buffers: vec![bound(0, r, &data, 0x44), bound(1, 0, &[0; 4], 0)], + push: push_bytes(&plan, &[(0, r)]), + spec: Default::default(), + }; + let out = + run(&m, &Config::default(), res).unwrap_or_else(|e| panic!("{what} r={r}: {e:?}")); + assert_eq!(out.buffers[1][..4], [0x9C, 0, 0, 0], "{what} r={r}"); + } + } +} + const HEADER: &str = "target datalayout = \"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-n8:16:32\"\ntarget triple = \"air64_v28-apple-macosx26.0.0\"\n\n"; /// The metadata of a kernel `name` with buffers `data` (0, read-write), `out` (1), and `params`