ac/nir: add support for discard_if intrinsic (v2)
authorDave Airlie <airlied@redhat.com>
Wed, 2 Nov 2016 01:21:15 +0000 (01:21 +0000)
committerDave Airlie <airlied@redhat.com>
Wed, 9 Nov 2016 19:46:20 +0000 (05:46 +1000)
We are going to start lowering to this in NIR code,
so prepare radv for it.

v2: handle conversion to kilp properly (nha)

Cc: "13.0" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Dave Airlie <airlied@redhat.com>
src/amd/common/ac_nir_to_llvm.c

index 8d364e68141135cdfa38b108158406ba9d3efc64..1829465cd8524c8531218fc5dbe8245bf74a6122 100644 (file)
@@ -2610,6 +2610,24 @@ static void emit_barrier(struct nir_to_llvm_context *ctx)
                            ctx->voidt, NULL, 0, 0);
 }
 
+static void emit_discard_if(struct nir_to_llvm_context *ctx,
+                           nir_intrinsic_instr *instr)
+{
+       LLVMValueRef cond;
+       ctx->shader_info->fs.can_discard = true;
+
+       cond = LLVMBuildICmp(ctx->builder, LLVMIntNE,
+                            get_src(ctx, instr->src[0]),
+                            ctx->i32zero, "");
+
+       cond = LLVMBuildSelect(ctx->builder, cond,
+                              LLVMConstReal(ctx->f32, -1.0f),
+                              ctx->f32zero, "");
+       emit_llvm_intrinsic(ctx, "llvm.AMDGPU.kill",
+                           LLVMVoidTypeInContext(ctx->context),
+                           &cond, 1, 0);
+}
+
 static LLVMValueRef
 visit_load_local_invocation_index(struct nir_to_llvm_context *ctx)
 {
@@ -2922,6 +2940,9 @@ static void visit_intrinsic(struct nir_to_llvm_context *ctx,
                                    LLVMVoidTypeInContext(ctx->context),
                                    NULL, 0, 0);
                break;
+       case nir_intrinsic_discard_if:
+               emit_discard_if(ctx, instr);
+               break;
        case nir_intrinsic_memory_barrier:
                emit_waitcnt(ctx);
                break;