unread_attribute: compare the drawn codes within one code of Metal's

The test compared the 8-bit codes exactly. The RTX 5080 Laptop GPU (615.71.09) drew `shade`
as [64, 127, 191, 255], where the M3 Max stores [64, 128, 191, 255]. `shade`'s green is 0.5,
which scales to 127.5, a tie. Vulkan 1.4, 3.10.2 lets the float-to-unorm conversion return
either of the two codes nearest f x (2^b - 1) and only asks it to round to nearest. The fragment
module records `PrecisionNote::DeviceColorConversion`, whose documentation names this exact case:
NVIDIA's 615.71.09 stores 0.5 as 0x7f where Metal stores 0x80. Under owner rule 1 the device's
conversion stands, so a test that expects Metal's bits there is wrong.

Each channel is now compared within one code of Metal's answer, for both the gated-off and the
gated-on draws. The test still proves what it is for: `shade` (64, 128, 191, 255) and `color`
(191, 64, 64, 191) lie 127 codes apart in red, so a gated-off state that read the attribute
still fails.

Verified: the 5080 run of this commit (named in the tip report).
This commit is contained in:
Anees Iqbal committed 2026-11-16 16:18:34 -08:00
1 parent 9090e8a58f
commit 8e9c144ccb
1 file changed
+19 -3
@@ -10,7 +10,10 @@
//! with the constant false a descriptor of attribute 0 alone makes the state and the target reads
//! `shade`, `(64, 128, 191, 255)`; with it true that descriptor is refused, and one of both
//! attributes draws `color`, attribute 1's `(1, 0, 0, 1)` scaled by 0.5 and biased by 0.25:
//! `(191, 64, 64, 191)`.
//! `(191, 64, 64, 191)`. Each channel is compared within one code of Metal's: near a tie the
//! device may store the other of the two codes nearest the channel's scaled value (Vulkan 1.4,
//! 3.10.2), as the fragment module records (`PrecisionNote::DeviceColorConversion`; NVIDIA's
//! 615.71.09 stores `shade`'s 0.5 as 127). The two answers lie far more than a code apart.
//!
//! A device test: compiled only under the GPU safety cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind
//! of device the cfg selects (`llvm-as`).
@@ -143,6 +146,13 @@ fn draw(device: &Device, state: &RenderPipelineState) -> [u8; 4] {
words_of(&back)[(SIDE + 1) as usize].to_le_bytes()
}
/// Whether each channel of `got` lies within one code of Metal's `metal` (the module docs).
fn metal_s_codes(got: [u8; 4], metal: [u8; 4]) -> bool {
got.iter()
.zip(metal)
.all(|(&code, m)| code.abs_diff(m) <= 1)
}
/// Gated off, the state is made without attribute 1 and draws `shade`; gated on, it is refused
/// without attribute 1, and with it draws `color` (the module docs).
#[test]
@@ -157,7 +167,10 @@ fn a_state_without_an_attribute_only_a_gated_off_varying_reads_draws_metal_s_pix
"UNREAD-ATTRIBUTE: {} gated off draws {shade:?}",
device.name()
);
assert_eq!(shade, [64, 128, 191, 255], "gated off: Metal's shade");
assert!(
metal_s_codes(shade, [64, 128, 191, 255]),
"gated off: Metal's shade (64, 128, 191, 255), drew {shade:?}"
);
match state(&device, &library, true, 1) {
Err(Error::Compile(CompileError::InvalidDescriptor(
DescriptorError::VertexAttribute { attribute: 1 },
@@ -171,5 +184,8 @@ fn a_state_without_an_attribute_only_a_gated_off_varying_reads_draws_metal_s_pix
"UNREAD-ATTRIBUTE: {} gated on draws {color:?}",
device.name()
);
assert_eq!(color, [191, 64, 64, 191], "gated on: Metal's color");
assert!(
metal_s_codes(color, [191, 64, 64, 191]),
"gated on: Metal's color (191, 64, 64, 191), drew {color:?}"
);
}