From 8646e2d9c9655fcffd7e59cb21a671c46183d340 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 18 Nov 2026 10:54:19 -0800 Subject: [PATCH] validation fixtures: oor_texture_reads, read() of a texture out of range (source; companions follow) --- .../public/engine/oor_texture_reads.metal | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.metal diff --git a/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.metal b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.metal new file mode 100644 index 000000000..4a12e8ff4 --- /dev/null +++ b/crates/metal2vulkan-validation/fixtures/public/engine/oor_texture_reads.metal @@ -0,0 +1,26 @@ +// Owned fixture: `read()` of a texture out of range. One thread reads ten texels, each at the +// coordinate and level of `at[i]` (x, y, level), so no coordinate is a constant the compiler sees: +// out[0..6] of `two_levels` (4 x 4 with 2 levels), out[7] of `one_level` (a view of its first +// level alone), out[8..10] of `red` (an R8Unorm texture of 1 level, a format without alpha). +// Metal documents an out-of-range read as zero in every component, alpha 1 for a format without +// alpha; which reads are out of range, and what each answers, is the case's. Loop-free. +#include +using namespace metal; + +kernel void oor_texture_reads(texture2d two_levels [[texture(0)]], + texture2d one_level [[texture(1)]], + texture2d red [[texture(2)]], + constant uint4 *at [[buffer(0)]], + device float4 *out [[buffer(1)]]) { + out[0] = two_levels.read(at[0].xy, at[0].z); + out[1] = two_levels.read(at[1].xy, at[1].z); + out[2] = two_levels.read(at[2].xy, at[2].z); + out[3] = two_levels.read(at[3].xy, at[3].z); + out[4] = two_levels.read(at[4].xy, at[4].z); + out[5] = two_levels.read(at[5].xy, at[5].z); + out[6] = two_levels.read(at[6].xy, at[6].z); + out[7] = one_level.read(at[7].xy, at[7].z); + out[8] = red.read(at[8].xy, at[8].z); + out[9] = red.read(at[9].xy, at[9].z); + out[10] = red.read(at[10].xy, at[10].z); +}