[Mesa-dev] [PATCH 1/2] ac/nir: Handle offset for atomics on shared memory

Alex Smith asmith at feralinteractive.com
Fri Jun 30 10:15:41 UTC 2017


Offset wasn't being added to the pointer, so for arrays the operation
would always have been performed on the first array element.

Signed-off-by: Alex Smith <asmith at feralinteractive.com>
---
Applies on top of my earlier patch:
https://lists.freedesktop.org/archives/mesa-dev/2017-June/161103.html
---
 src/amd/common/ac_nir_to_llvm.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/amd/common/ac_nir_to_llvm.c b/src/amd/common/ac_nir_to_llvm.c
index 5bb7bc6..6845df8 100644
--- a/src/amd/common/ac_nir_to_llvm.c
+++ b/src/amd/common/ac_nir_to_llvm.c
@@ -3572,11 +3572,19 @@ visit_load_local_invocation_index(struct nir_to_llvm_context *ctx)
 static LLVMValueRef visit_var_atomic(struct nir_to_llvm_context *ctx,
 				     const nir_intrinsic_instr *instr)
 {
-	LLVMValueRef ptr, result;
+	LLVMValueRef ptr, result, indir_index;
+	unsigned const_index;
 	int idx = instr->variables[0]->var->data.driver_location;
 	LLVMValueRef src = get_src(ctx, instr->src[0]);
+
 	ptr = get_shared_memory_ptr(ctx, idx, ctx->i32);
 
+	radv_get_deref_offset(ctx, instr->variables[0], false, true,
+			      NULL, NULL, &const_index, &indir_index);
+
+	if (indir_index)
+		ptr = LLVMBuildGEP(ctx->builder, ptr, &indir_index, 1, "");
+
 	if (instr->intrinsic == nir_intrinsic_var_atomic_comp_swap) {
 		LLVMValueRef src1 = get_src(ctx, instr->src[1]);
 		result = LLVMBuildAtomicCmpXchg(ctx->builder,
-- 
2.9.4



More information about the mesa-dev mailing list