radeonsi: add support for tgsi ATOMDEC_WRAP / ATOMINC_WRAP opcodes
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 12 Jul 2019 13:57:54 +0000 (15:57 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 6 Aug 2019 21:41:04 +0000 (17:41 -0400)
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c

index 6fca1d86847d3b63b33bc96953edf074c374bbaf..4a4ba43780a818d3d32ce51ed272f3cf9ce844a8 100644 (file)
@@ -827,6 +827,19 @@ static void atomic_emit(
 
        args.data[num_data++] =
                ac_to_integer(&ctx->ac, lp_build_emit_fetch(bld_base, inst, 2, 0));
+
+       if (inst->Instruction.Opcode == TGSI_OPCODE_ATOMINC_WRAP) {
+               /* ATOMIC_INC instruction does:
+                *      value = (value + 1) % (data + 1)
+                * but we want:
+                *      value = (value + 1) % data
+                * So replace 'data' by 'data - 1'.
+                */
+               args.data[0] = LLVMBuildSub(ctx->ac.builder,
+                                           args.data[0],
+                                           ctx->ac.i32_1, "");
+       }
+
        args.cache_policy = get_cache_policy(ctx, inst, true, false, false);
 
        if (inst->Src[0].Register.File == TGSI_FILE_BUFFER) {
@@ -902,6 +915,12 @@ static void atomic_emit(
                        case TGSI_OPCODE_ATOMUMAX: args.atomic = ac_atomic_umax; break;
                        case TGSI_OPCODE_ATOMIMIN: args.atomic = ac_atomic_smin; break;
                        case TGSI_OPCODE_ATOMIMAX: args.atomic = ac_atomic_smax; break;
+                       case TGSI_OPCODE_ATOMINC_WRAP:
+                               args.atomic = ac_atomic_inc_wrap;
+                               break;
+                       case TGSI_OPCODE_ATOMDEC_WRAP:
+                               args.atomic = ac_atomic_dec_wrap;
+                               break;
                        default: unreachable("unhandled image atomic");
                        }
                }
@@ -1821,4 +1840,8 @@ void si_shader_context_init_mem(struct si_shader_context *ctx)
        bld_base->op_actions[TGSI_OPCODE_ATOMIMIN].intr_name = "smin";
        bld_base->op_actions[TGSI_OPCODE_ATOMIMAX].emit = atomic_emit;
        bld_base->op_actions[TGSI_OPCODE_ATOMIMAX].intr_name = "smax";
+       bld_base->op_actions[TGSI_OPCODE_ATOMINC_WRAP].emit = atomic_emit;
+       bld_base->op_actions[TGSI_OPCODE_ATOMINC_WRAP].intr_name = "inc";
+       bld_base->op_actions[TGSI_OPCODE_ATOMDEC_WRAP].emit = atomic_emit;
+       bld_base->op_actions[TGSI_OPCODE_ATOMDEC_WRAP].intr_name = "dec";
 }