From 895bc56899aeb7e8456803bda8ac34e23df03233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Mon, 11 Mar 2024 16:16:50 -0400 Subject: [PATCH] ac/llvm: fix SSBO bounds checking by using raw instead of struct opcodes Setting vindex != NULL (even if it's 0) selects a struct.buffer.load opcode, which causes LLVM to look for "index * stride + offset" in voffset and moves "index" to vindex (i.e. not 0 anymore), but the bounds checking (OOB_SELECT) is set to ignore vindex. Setting vindex = NULL selects a raw.buffer.load opcode. Fixes: 6b573c00c9156 - ac/nir: use ac_build_buffer_load() for SSBO load operations Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10794 Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: (cherry picked from commit e589833ee1e6833f4611c200f2044ff303dd6346) --- .pick_status.json | 2 +- src/amd/llvm/ac_nir_to_llvm.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index e7cfbaedb83..7cabeae61e5 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -634,7 +634,7 @@ "description": "ac/llvm: fix SSBO bounds checking by using raw instead of struct opcodes", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "6b573c00c9156297513a0783ef05a1c5601e6620", "notes": null diff --git a/src/amd/llvm/ac_nir_to_llvm.c b/src/amd/llvm/ac_nir_to_llvm.c index 1d7db8580b0..96242563da0 100644 --- a/src/amd/llvm/ac_nir_to_llvm.c +++ b/src/amd/llvm/ac_nir_to_llvm.c @@ -1935,7 +1935,6 @@ static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx, nir_intrinsic_ LLVMValueRef offset = get_src(ctx, instr->src[1]); LLVMValueRef rsrc = ctx->abi->load_ssbo ? ctx->abi->load_ssbo(ctx->abi, rsrc_base, false, false) : rsrc_base; - LLVMValueRef vindex = ctx->ac.i32_0; LLVMTypeRef def_type = get_def_type(ctx, &instr->def); LLVMTypeRef def_elem_type = num_components > 1 ? LLVMGetElementType(def_type) : def_type; @@ -1964,7 +1963,7 @@ static LLVMValueRef visit_load_buffer(struct ac_nir_context *ctx, nir_intrinsic_ int num_channels = util_next_power_of_two(load_bytes) / 4; bool can_speculate = access & ACCESS_CAN_REORDER; - ret = ac_build_buffer_load(&ctx->ac, rsrc, num_channels, vindex, voffset, ctx->ac.i32_0, + ret = ac_build_buffer_load(&ctx->ac, rsrc, num_channels, NULL, voffset, ctx->ac.i32_0, ctx->ac.f32, access, can_speculate, false); }