nir/load_store_vectorize: Skip new bit-sizes that are unaligned with high_offset

Otherwise this would require combining two values to produce a single
(new bit-size) channel, which vectorize_stores() don't handle.  The pass
can still keep trying smaller bit-sizes.

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12946
Fixes: ce9205c03b ("nir: add a load/store vectorization pass")
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34414>
This commit is contained in:
Caio Oliveira 2025-04-07 08:18:14 -07:00 committed by Marge Bot
parent eaf9371fd5
commit 2ed79f80ba
2 changed files with 18 additions and 0 deletions

View file

@ -681,6 +681,10 @@ new_bitsize_acceptable(struct vectorize_ctx *ctx, unsigned new_bit_size,
unsigned high_offset = high->offset_signed - low->offset_signed;
/* This can cause issues when combining store data. */
if (high_offset % (new_bit_size / 8) != 0)
return false;
/* check nir_extract_bits limitations */
unsigned common_bit_size = MIN2(get_bit_size(low), get_bit_size(high));
common_bit_size = MIN2(common_bit_size, new_bit_size);

View file

@ -755,6 +755,20 @@ TEST_F(nir_load_store_vectorize_test, ssbo_store_intersecting)
ASSERT_EQ(nir_const_value_as_uint(cv[2], 32), 0x21);
}
TEST_F(nir_load_store_vectorize_test, gitlab_issue_12946)
{
create_store(nir_var_mem_ssbo, 0, 0, 0x1, 32, 2, 0x3);
create_store(nir_var_mem_ssbo, 0, 3, 0x2, 32, 1, 0x1);
nir_validate_shader(b->shader, NULL);
ASSERT_EQ(count_intrinsics(nir_intrinsic_store_ssbo), 2);
/* The original issue was the crash when running the pass. */
EXPECT_TRUE(run_vectorizer(nir_var_mem_ssbo));
EXPECT_EQ(count_intrinsics(nir_intrinsic_store_ssbo), 2);
}
TEST_F(nir_load_store_vectorize_test, ssbo_store_identical)
{
create_store(nir_var_mem_ssbo, 0, 0, 0x1);