asahi: fix UB affecting x86 builds

dEQP-VK.robustness.image_robustness.bind.notemplate.r32f.unroll.nonvolatile.sampled_image.no_fmt_qual.img.samples_1.2d_array.comp

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31532>
This commit is contained in:
Alyssa Rosenzweig 2024-09-22 08:06:43 -04:00 committed by Marge Bot
parent 673f56fcb1
commit bbad4454bf

View file

@ -240,8 +240,15 @@ lower_regular_texture(nir_builder *b, nir_instr *instr, UNUSED void *data)
coord = nir_trim_vector(b, coord, lidx);
/* Round layer to nearest even */
if (!is_txf)
unclamped_layer = nir_f2u32(b, nir_fround_even(b, unclamped_layer));
if (!is_txf) {
unclamped_layer = nir_fround_even(b, unclamped_layer);
/* Explicitly round negative to avoid undefined behaviour when constant
* folding. This is load bearing on x86 builds.
*/
unclamped_layer =
nir_f2u32(b, nir_fmax(b, unclamped_layer, nir_imm_float(b, 0.0f)));
}
/* For a cube array, the layer is zero-indexed component 3 of the
* coordinate but the number of layers is component 2 of the txs result.