radeonsi/nir: implement FBFETCH for KHR_blend_equation_advanced
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Jul 2019 23:32:50 +0000 (19:32 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 31 Jul 2019 02:06:23 +0000 (22:06 -0400)
src/amd/common/ac_nir_to_llvm.c
src/amd/common/ac_shader_abi.h
src/gallium/drivers/radeonsi/si_shader.c
src/gallium/drivers/radeonsi/si_shader_internal.h
src/gallium/drivers/radeonsi/si_shader_tgsi_mem.c

index 780712979713adea472ccf5f59c7f51de81e282b..826a63773238097027f8c7edd1ba058e812a7f21 100644 (file)
@@ -2053,6 +2053,11 @@ static LLVMValueRef visit_load_var(struct ac_nir_context *ctx,
                        return load_tess_varyings(ctx, instr, false);
                }
 
+               if (ctx->stage == MESA_SHADER_FRAGMENT &&
+                   var->data.fb_fetch_output &&
+                   ctx->abi->emit_fbfetch)
+                       return ctx->abi->emit_fbfetch(ctx->abi);
+
                for (unsigned chan = comp; chan < ve + comp; chan++) {
                        if (indir_index) {
                                unsigned count = glsl_count_attribute_slots(
index 083ab6c2298bae7b943d192c6d717c3204fb5a63..d8572d124e9aa2a230d32d26cb6a08ea92dc8544 100644 (file)
@@ -198,6 +198,8 @@ struct ac_shader_abi {
 
        LLVMValueRef (*load_base_vertex)(struct ac_shader_abi *abi);
 
+       LLVMValueRef (*emit_fbfetch)(struct ac_shader_abi *abi);
+
        /* Whether to clamp the shadow reference value to [0,1]on GFX8. Radeonsi currently
         * uses it due to promoting D16 to D32, but radv needs it off. */
        bool clamp_shadow_reference;
index 679fa4edabd3281ed84028b0ace7c0c9388a3ed1..650195b01bfd1b9dfda1dcfeea70a10c84df8153 100644 (file)
@@ -6118,6 +6118,7 @@ static bool si_compile_tgsi_main(struct si_shader_context *ctx)
                ctx->abi.lookup_interp_param = si_nir_lookup_interp_param;
                ctx->abi.load_sample_position = load_sample_position;
                ctx->abi.load_sample_mask_in = load_sample_mask_in;
+               ctx->abi.emit_fbfetch = si_nir_emit_fbfetch;
                ctx->abi.emit_kill = si_llvm_emit_kill;
                break;
        case PIPE_SHADER_COMPUTE:
index aa4e083ec1a2d9dc41ae255ee5430dc1a4064ef1..b4bee5e22e236238d2742a0a33f43c3720587698 100644 (file)
@@ -350,6 +350,7 @@ LLVMValueRef si_load_image_desc(struct si_shader_context *ctx,
                                LLVMValueRef list, LLVMValueRef index,
                                enum ac_descriptor_type desc_type,
                                bool uses_store, bool bindless);
+LLVMValueRef si_nir_emit_fbfetch(struct ac_shader_abi *abi);
 
 void si_load_system_value(struct si_shader_context *ctx,
                          unsigned index,
index 6181332ec019e08e26f65ed92da08b06596d9c07..6fca1d86847d3b63b33bc96953edf074c374bbaf 100644 (file)
@@ -1698,11 +1698,8 @@ static void si_llvm_emit_txqs(
        emit_data->output[emit_data->chan] = samples;
 }
 
-static void si_llvm_emit_fbfetch(const struct lp_build_tgsi_action *action,
-                                struct lp_build_tgsi_context *bld_base,
-                                struct lp_build_emit_data *emit_data)
+static LLVMValueRef si_llvm_emit_fbfetch(struct si_shader_context *ctx)
 {
-       struct si_shader_context *ctx = si_shader_context(bld_base);
        struct ac_image_args args = {};
        LLVMValueRef ptr, image, fmask;
 
@@ -1756,8 +1753,23 @@ static void si_llvm_emit_fbfetch(const struct lp_build_tgsi_action *action,
                args.dim = ctx->shader->key.mono.u.ps.fbfetch_layered ?
                        ac_image_2darray : ac_image_2d;
 
-       emit_data->output[emit_data->chan] =
-               ac_build_image_opcode(&ctx->ac, &args);
+       return ac_build_image_opcode(&ctx->ac, &args);
+}
+
+static void si_tgsi_emit_fbfetch(const struct lp_build_tgsi_action *action,
+                                struct lp_build_tgsi_context *bld_base,
+                                struct lp_build_emit_data *emit_data)
+{
+       struct si_shader_context *ctx = si_shader_context(bld_base);
+
+       emit_data->output[emit_data->chan] = si_llvm_emit_fbfetch(ctx);
+}
+
+LLVMValueRef si_nir_emit_fbfetch(struct ac_shader_abi *abi)
+{
+       struct si_shader_context *ctx = si_shader_context_from_abi(abi);
+
+       return si_llvm_emit_fbfetch(ctx);
 }
 
 /**
@@ -1783,7 +1795,7 @@ void si_shader_context_init_mem(struct si_shader_context *ctx)
        bld_base->op_actions[TGSI_OPCODE_LODQ].emit = build_tex_intrinsic;
        bld_base->op_actions[TGSI_OPCODE_TXQS].emit = si_llvm_emit_txqs;
 
-       bld_base->op_actions[TGSI_OPCODE_FBFETCH].emit = si_llvm_emit_fbfetch;
+       bld_base->op_actions[TGSI_OPCODE_FBFETCH].emit = si_tgsi_emit_fbfetch;
 
        bld_base->op_actions[TGSI_OPCODE_LOAD].emit = load_emit;
        bld_base->op_actions[TGSI_OPCODE_STORE].emit = store_emit;