aco,ac/llvm,radv,radeonsi: handle ps bc optimization in nir for radv
authorQiang Yu <yuq825@gmail.com>
Wed, 29 Mar 2023 07:56:21 +0000 (15:56 +0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 26 Apr 2023 03:27:26 +0000 (03:27 +0000)
The side effect is removing the aco/llvm backend bc optimization code
and linear/persp_centroid variable.

Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22199>

src/amd/compiler/aco_instruction_selection.cpp
src/amd/compiler/aco_instruction_selection.h
src/amd/llvm/ac_nir_to_llvm.c
src/amd/llvm/ac_shader_abi.h
src/amd/vulkan/radv_nir_to_llvm.c
src/amd/vulkan/radv_pipeline.c
src/gallium/drivers/radeonsi/si_shader_llvm.c

index 3cabec8..12c386c 100644 (file)
@@ -8080,7 +8080,7 @@ get_interp_param(isel_context* ctx, nir_intrinsic_op intrin,
        intrin == nir_intrinsic_load_barycentric_at_offset) {
       return get_arg(ctx, linear ? ctx->args->linear_center : ctx->args->persp_center);
    } else if (intrin == nir_intrinsic_load_barycentric_centroid) {
-      return linear ? ctx->linear_centroid : ctx->persp_centroid;
+      return get_arg(ctx, linear ? ctx->args->linear_centroid : ctx->args->persp_centroid);
    } else {
       assert(intrin == nir_intrinsic_load_barycentric_sample);
       return get_arg(ctx, linear ? ctx->args->linear_sample : ctx->args->persp_sample);
@@ -11201,60 +11201,6 @@ split_arguments(isel_context* ctx, Pseudo_instruction* startpgm)
 }
 
 void
-handle_bc_optimize(isel_context* ctx)
-{
-   /* needed when SPI_PS_IN_CONTROL.BC_OPTIMIZE_DISABLE is set to 0 */
-   Builder bld(ctx->program, ctx->block);
-   uint32_t spi_ps_input_ena = ctx->program->config->spi_ps_input_ena;
-   bool uses_center =
-      G_0286CC_PERSP_CENTER_ENA(spi_ps_input_ena) || G_0286CC_LINEAR_CENTER_ENA(spi_ps_input_ena);
-   bool uses_persp_centroid = G_0286CC_PERSP_CENTROID_ENA(spi_ps_input_ena);
-   bool uses_linear_centroid = G_0286CC_LINEAR_CENTROID_ENA(spi_ps_input_ena);
-
-   if (uses_persp_centroid)
-      ctx->persp_centroid = get_arg(ctx, ctx->args->persp_centroid);
-   if (uses_linear_centroid)
-      ctx->linear_centroid = get_arg(ctx, ctx->args->linear_centroid);
-
-   if (uses_center && (uses_persp_centroid || uses_linear_centroid)) {
-      Temp sel = bld.vopc_e64(aco_opcode::v_cmp_lt_i32, bld.def(bld.lm),
-                              get_arg(ctx, ctx->args->prim_mask), Operand::zero());
-
-      if (uses_persp_centroid) {
-         Temp new_coord[2];
-         for (unsigned i = 0; i < 2; i++) {
-            Temp persp_centroid =
-               emit_extract_vector(ctx, get_arg(ctx, ctx->args->persp_centroid), i, v1);
-            Temp persp_center =
-               emit_extract_vector(ctx, get_arg(ctx, ctx->args->persp_center), i, v1);
-            new_coord[i] =
-               bld.vop2(aco_opcode::v_cndmask_b32, bld.def(v1), persp_centroid, persp_center, sel);
-         }
-         ctx->persp_centroid = bld.tmp(v2);
-         bld.pseudo(aco_opcode::p_create_vector, Definition(ctx->persp_centroid),
-                    Operand(new_coord[0]), Operand(new_coord[1]));
-         emit_split_vector(ctx, ctx->persp_centroid, 2);
-      }
-
-      if (uses_linear_centroid) {
-         Temp new_coord[2];
-         for (unsigned i = 0; i < 2; i++) {
-            Temp linear_centroid =
-               emit_extract_vector(ctx, get_arg(ctx, ctx->args->linear_centroid), i, v1);
-            Temp linear_center =
-               emit_extract_vector(ctx, get_arg(ctx, ctx->args->linear_center), i, v1);
-            new_coord[i] = bld.vop2(aco_opcode::v_cndmask_b32, bld.def(v1), linear_centroid,
-                                    linear_center, sel);
-         }
-         ctx->linear_centroid = bld.tmp(v2);
-         bld.pseudo(aco_opcode::p_create_vector, Definition(ctx->linear_centroid),
-                    Operand(new_coord[0]), Operand(new_coord[1]));
-         emit_split_vector(ctx, ctx->linear_centroid, 2);
-      }
-   }
-}
-
-void
 setup_fp_mode(isel_context* ctx, nir_shader* shader)
 {
    Program* program = ctx->program;
@@ -11444,9 +11390,6 @@ select_program(Program* program, unsigned shader_count, struct nir_shader* const
       } else if (ctx.stage == geometry_gs)
          ctx.gs_wave_id = get_arg(&ctx, args->gs_wave_id);
 
-      if (ctx.stage == fragment_fs)
-         handle_bc_optimize(&ctx);
-
       visit_cf_list(&ctx, &func->body);
 
       if (nir->info.stage == MESA_SHADER_GEOMETRY && !ngg_gs) {
index acb2541..65a32a9 100644 (file)
@@ -91,9 +91,6 @@ struct isel_context {
 
    Temp arg_temps[AC_MAX_ARGS];
 
-   /* FS inputs */
-   Temp persp_centroid, linear_centroid;
-
    /* GS inputs */
    Temp gs_wave_id;
 
index 5a36ee5..3a3c7d5 100644 (file)
@@ -3195,7 +3195,7 @@ static LLVMValueRef lookup_interp_param(struct ac_nir_context *ctx, enum glsl_in
       if (location == INTERP_CENTER)
          return ac_get_arg(&ctx->ac, ctx->args->persp_center);
       else if (location == INTERP_CENTROID)
-         return ctx->abi->persp_centroid;
+         return ac_get_arg(&ctx->ac, ctx->args->persp_centroid);
       else if (location == INTERP_SAMPLE)
          return ac_get_arg(&ctx->ac, ctx->args->persp_sample);
       break;
@@ -3203,7 +3203,7 @@ static LLVMValueRef lookup_interp_param(struct ac_nir_context *ctx, enum glsl_in
       if (location == INTERP_CENTER)
          return ac_get_arg(&ctx->ac, ctx->args->linear_center);
       else if (location == INTERP_CENTROID)
-         return ctx->abi->linear_centroid;
+         return ac_get_arg(&ctx->ac, ctx->args->linear_centroid);
       else if (location == INTERP_SAMPLE)
          return ac_get_arg(&ctx->ac, ctx->args->linear_sample);
       break;
index 0369d57..ec37a00 100644 (file)
@@ -46,7 +46,6 @@ struct ac_shader_abi {
    LLVMValueRef vertex_id;
    LLVMValueRef vs_rel_patch_id;
    LLVMValueRef instance_id;
-   LLVMValueRef persp_centroid, linear_centroid;
    LLVMValueRef user_data;
 
    /* replaced registers when culling enabled */
index 7ae308e..0bcbd29 100644 (file)
@@ -254,38 +254,6 @@ radv_get_sampler_desc(struct ac_shader_abi *abi, LLVMValueRef index,
 }
 
 static void
-prepare_interp_optimize(struct radv_shader_context *ctx, struct nir_shader *nir)
-{
-   bool uses_center = false;
-   bool uses_centroid = false;
-   nir_foreach_shader_in_variable (variable, nir) {
-      if (glsl_get_base_type(glsl_without_array(variable->type)) != GLSL_TYPE_FLOAT ||
-          variable->data.sample)
-         continue;
-
-      if (variable->data.centroid)
-         uses_centroid = true;
-      else
-         uses_center = true;
-   }
-
-   ctx->abi.persp_centroid = ac_get_arg(&ctx->ac, ctx->args->ac.persp_centroid);
-   ctx->abi.linear_centroid = ac_get_arg(&ctx->ac, ctx->args->ac.linear_centroid);
-
-   if (uses_center && uses_centroid) {
-      LLVMValueRef sel =
-         LLVMBuildICmp(ctx->ac.builder, LLVMIntSLT, ac_get_arg(&ctx->ac, ctx->args->ac.prim_mask),
-                       ctx->ac.i32_0, "");
-      ctx->abi.persp_centroid =
-         LLVMBuildSelect(ctx->ac.builder, sel, ac_get_arg(&ctx->ac, ctx->args->ac.persp_center),
-                         ctx->abi.persp_centroid, "");
-      ctx->abi.linear_centroid =
-         LLVMBuildSelect(ctx->ac.builder, sel, ac_get_arg(&ctx->ac, ctx->args->ac.linear_center),
-                         ctx->abi.linear_centroid, "");
-   }
-}
-
-static void
 scan_shader_output_decl(struct radv_shader_context *ctx, struct nir_variable *variable,
                         struct nir_shader *shader, gl_shader_stage stage)
 {
@@ -548,9 +516,7 @@ ac_translate_nir_to_llvm(struct ac_llvm_compiler *ac_llvm,
          LLVMPositionBuilderAtEnd(ctx.ac.builder, then_block);
       }
 
-      if (shaders[shader_idx]->info.stage == MESA_SHADER_FRAGMENT)
-         prepare_interp_optimize(&ctx, shaders[shader_idx]);
-      else if (shaders[shader_idx]->info.stage == MESA_SHADER_GEOMETRY && !info->is_ngg)
+      if (shaders[shader_idx]->info.stage == MESA_SHADER_GEOMETRY && !info->is_ngg)
          prepare_gs_input_vgprs(&ctx, shader_count >= 2);
 
       if (!ac_nir_translate(&ctx.ac, &ctx.abi, &args->ac, shaders[shader_idx])) {
index b5322b7..a90a362 100644 (file)
@@ -610,6 +610,11 @@ radv_postprocess_nir(struct radv_device *device, const struct radv_pipeline_layo
 
          .enable_mrt_output_nan_fixup = pipeline_key->ps.epilog.enable_mrt_output_nan_fixup,
          .no_color_export = stage->info.ps.has_epilog,
+
+         .bc_optimize_for_persp =
+            stage->info.ps.reads_persp_center && stage->info.ps.reads_persp_centroid,
+         .bc_optimize_for_linear =
+            stage->info.ps.reads_linear_center && stage->info.ps.reads_linear_centroid,
       };
 
       NIR_PASS_V(stage->nir, ac_nir_lower_ps, &options);
index 583abbd..9625aea 100644 (file)
@@ -250,9 +250,6 @@ void si_llvm_create_main_func(struct si_shader_context *ctx)
        */
       if (shader->is_monolithic && shader->key.ge.part.vs.prolog.ls_vgpr_fix)
          ac_fixup_ls_hs_input_vgprs(&ctx->ac, &ctx->abi, &ctx->args->ac);
-   } else if (ctx->stage == MESA_SHADER_FRAGMENT) {
-      ctx->abi.persp_centroid = ac_get_arg(&ctx->ac, ctx->args->ac.persp_centroid);
-      ctx->abi.linear_centroid = ac_get_arg(&ctx->ac, ctx->args->ac.linear_centroid);
    }
 }