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

Submitted by Alex Smith on June 30, 2017, 10:15 a.m.

Details

Message ID 20170630101542.13934-1-asmith@feralinteractive.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alex Smith June 30, 2017, 10:15 a.m.
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@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(-)

Patch hide | download patch | download mbox

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,