ac: handle subgroup intrinsics
authorDaniel Schürmann <daniel.schuermann@campus.tu-berlin.de>
Tue, 6 Mar 2018 14:04:29 +0000 (15:04 +0100)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Fri, 13 Apr 2018 23:03:15 +0000 (01:03 +0200)
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/common/ac_nir_to_llvm.c

index 7c2bd5c0cca5d87219432cb6acef51e4dd282c8d..3a3aa72988e98c280da6c0e29e2c48f0d9933f89 100644 (file)
@@ -2805,36 +2805,12 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
                result = ac_build_ballot(&ctx->ac, get_src(ctx, instr->src[0]));
                break;
        case nir_intrinsic_read_invocation:
-       case nir_intrinsic_read_first_invocation: {
-               LLVMValueRef args[2];
-
-               /* Value */
-               args[0] = get_src(ctx, instr->src[0]);
-
-               unsigned num_args;
-               const char *intr_name;
-               if (instr->intrinsic == nir_intrinsic_read_invocation) {
-                       num_args = 2;
-                       intr_name = "llvm.amdgcn.readlane";
-
-                       /* Invocation */
-                       args[1] = get_src(ctx, instr->src[1]);
-               } else {
-                       num_args = 1;
-                       intr_name = "llvm.amdgcn.readfirstlane";
-               }
-
-               /* We currently have no other way to prevent LLVM from lifting the icmp
-                * calls to a dominating basic block.
-                */
-               ac_build_optimization_barrier(&ctx->ac, &args[0]);
-
-               result = ac_build_intrinsic(&ctx->ac, intr_name,
-                                           ctx->ac.i32, args, num_args,
-                                           AC_FUNC_ATTR_READNONE |
-                                           AC_FUNC_ATTR_CONVERGENT);
+               result = ac_build_readlane(&ctx->ac, get_src(ctx, instr->src[0]),
+                               get_src(ctx, instr->src[1]));
+               break;
+       case nir_intrinsic_read_first_invocation:
+               result = ac_build_readlane(&ctx->ac, get_src(ctx, instr->src[0]), NULL);
                break;
-       }
        case nir_intrinsic_load_subgroup_invocation:
                result = ac_get_thread_id(&ctx->ac);
                break;
@@ -3088,6 +3064,41 @@ static void visit_intrinsic(struct ac_nir_context *ctx,
                result = LLVMBuildSExt(ctx->ac.builder, tmp, ctx->ac.i32, "");
                break;
        }
+       case nir_intrinsic_shuffle:
+               result = ac_build_shuffle(&ctx->ac, get_src(ctx, instr->src[0]),
+                               get_src(ctx, instr->src[1]));
+               break;
+       case nir_intrinsic_reduce:
+               result = ac_build_reduce(&ctx->ac,
+                               get_src(ctx, instr->src[0]),
+                               instr->const_index[0],
+                               instr->const_index[1]);
+               break;
+       case nir_intrinsic_inclusive_scan:
+               result = ac_build_inclusive_scan(&ctx->ac,
+                               get_src(ctx, instr->src[0]),
+                               instr->const_index[0]);
+               break;
+       case nir_intrinsic_exclusive_scan:
+               result = ac_build_exclusive_scan(&ctx->ac,
+                               get_src(ctx, instr->src[0]),
+                               instr->const_index[0]);
+               break;
+       case nir_intrinsic_quad_broadcast: {
+               unsigned lane = nir_src_as_const_value(instr->src[1])->u32[0];
+               result = ac_build_quad_swizzle(&ctx->ac, get_src(ctx, instr->src[0]),
+                               lane, lane, lane, lane);
+               break;
+       }
+       case nir_intrinsic_quad_swap_horizontal:
+               result = ac_build_quad_swizzle(&ctx->ac, get_src(ctx, instr->src[0]), 1, 0, 3 ,2);
+               break;
+       case nir_intrinsic_quad_swap_vertical:
+               result = ac_build_quad_swizzle(&ctx->ac, get_src(ctx, instr->src[0]), 2, 3, 0 ,1);
+               break;
+       case nir_intrinsic_quad_swap_diagonal:
+               result = ac_build_quad_swizzle(&ctx->ac, get_src(ctx, instr->src[0]), 3, 2, 1 ,0);
+               break;
        default:
                fprintf(stderr, "Unknown intrinsic: ");
                nir_print_instr(&instr->instr, stderr);