From 573b2b813a8bc30a98ad09cde13853160611f2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Tue, 30 Apr 2024 03:21:58 -0400 Subject: [PATCH] ac/llvm: improve/simplify/fix load_ssbo Effects: - multi-component subdword handling removed because it's lowered - 3-dword loads selected correctly instead of 4-dword loads - the failure of dEQP-GLES3.functional.buffer.copy.subrange.large_to_small due to LLVM exposed by a future commit is mysteriously fixed by this Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- src/amd/llvm/ac_nir_to_llvm.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 9c6821f867a..797d1c4742d 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -1924,8 +1924,9 @@ static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx, nir_intrinsic_ LLVMValueRef results[4]; for (int i = 0; i < num_components;) { int num_elems = num_components - i; - if (elem_size_bytes < 4 && nir_intrinsic_align(instr) % 4 != 0) - num_elems = 1; + /* Multi-component subdword loads are lowered by ac_nir_lower_subdword_loads. */ + assert(elem_size_bytes >= 4 || num_elems == 1); + if (num_elems * elem_size_bytes > 16) num_elems = 16 / elem_size_bytes; int load_bytes = num_elems * elem_size_bytes; @@ -1942,17 +1943,14 @@ static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx, nir_intrinsic_ ret = ac_build_buffer_load_short(&ctx->ac, rsrc, voffset, ctx->ac.i32_0, access); } else { - int num_channels = util_next_power_of_two(load_bytes) / 4; + assert(elem_size_bytes >= 4); + int num_channels = load_bytes / 4; bool can_speculate = access & ACCESS_CAN_REORDER; ret = ac_build_buffer_load(&ctx->ac, rsrc, num_channels, NULL, voffset, ctx->ac.i32_0, ctx->ac.f32, access, can_speculate, false); } - LLVMTypeRef byte_vec = LLVMVectorType(ctx->ac.i8, ac_get_type_size(LLVMTypeOf(ret))); - ret = LLVMBuildBitCast(ctx->ac.builder, ret, byte_vec, ""); - ret = ac_trim_vector(&ctx->ac, ret, load_bytes); - LLVMTypeRef ret_type = LLVMVectorType(def_elem_type, num_elems); ret = LLVMBuildBitCast(ctx->ac.builder, ret, ret_type, "");