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`