Skip to content

intel/brw: Set appropriate types for 16-bit sampler trailing components

Kenneth Graunke requested to merge kwg/mesa:brw-sampler-16bit-fix into main

What does this MR do and why?

intel/brw: Set appropriate types for 16-bit sampler trailing components

16-bit SIMD8 sampler writeback messages come with a bit of padding in
them, requiring us to emit a LOAD_PAYLOAD to reorganize the data into
the padding-free format expected by NIR.  Additionally, we may reduce
the response length on the sampler messages based on which components
of the (always vec4) NIR destination are actually in use.  When we do
that, dest_size > read_size, and the trailing components are all empty
BAD_FILE registers, indicating the contents are undefined.

Unfortunately, we can't ignore those trailing components entirely.
In the past, we left them default-initialized, giving us a BAD_FILE
register with UD type (which didn't matter, since all sampler returns
were 32-bit).  But with 16-bit, this was confusing the LOAD_PAYLOAD.
For example, writing RGB and skipping A (without sparse) would produce
read_size = 3 and dest_size = 4 and nir_dest[5] containing:

   nir_dest[] = <R:hf, G:hf, B:hf, blank-A:ud, blank-sparse:ud>

We'd then call LOAD_PAYLOAD on the first 4 sources, causing it to see
3 HF's and a UD, and try to copy the full 32-bit value at the end,
instead of 16-bits of pad like we intended.  This meant it would
overflow the destination register's size, triggering validation errors.

Thanks to Ian Romanick for noticing this and writing a test case.

Fixes: 0116430d394 ("intel/brw: Handle 16-bit sampler return payloads")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/11617

Cc @idr @sushmave

Merge request reports