aco,ac/llvm,radv,radeonsi: handle ps bc optimization in nir for radv
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>
This commit is contained in:
@@ -8080,7 +8080,7 @@ get_interp_param(isel_context* ctx, nir_intrinsic_op intrin,
|
|||||||
intrin == nir_intrinsic_load_barycentric_at_offset) {
|
intrin == nir_intrinsic_load_barycentric_at_offset) {
|
||||||
return get_arg(ctx, linear ? ctx->args->linear_center : ctx->args->persp_center);
|
return get_arg(ctx, linear ? ctx->args->linear_center : ctx->args->persp_center);
|
||||||
} else if (intrin == nir_intrinsic_load_barycentric_centroid) {
|
} 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 {
|
} else {
|
||||||
assert(intrin == nir_intrinsic_load_barycentric_sample);
|
assert(intrin == nir_intrinsic_load_barycentric_sample);
|
||||||
return get_arg(ctx, linear ? ctx->args->linear_sample : ctx->args->persp_sample);
|
return get_arg(ctx, linear ? ctx->args->linear_sample : ctx->args->persp_sample);
|
||||||
@@ -11200,60 +11200,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
|
void
|
||||||
setup_fp_mode(isel_context* ctx, nir_shader* shader)
|
setup_fp_mode(isel_context* ctx, nir_shader* shader)
|
||||||
{
|
{
|
||||||
@@ -11444,9 +11390,6 @@ select_program(Program* program, unsigned shader_count, struct nir_shader* const
|
|||||||
} else if (ctx.stage == geometry_gs)
|
} else if (ctx.stage == geometry_gs)
|
||||||
ctx.gs_wave_id = get_arg(&ctx, args->gs_wave_id);
|
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);
|
visit_cf_list(&ctx, &func->body);
|
||||||
|
|
||||||
if (nir->info.stage == MESA_SHADER_GEOMETRY && !ngg_gs) {
|
if (nir->info.stage == MESA_SHADER_GEOMETRY && !ngg_gs) {
|
||||||
|
@@ -91,9 +91,6 @@ struct isel_context {
|
|||||||
|
|
||||||
Temp arg_temps[AC_MAX_ARGS];
|
Temp arg_temps[AC_MAX_ARGS];
|
||||||
|
|
||||||
/* FS inputs */
|
|
||||||
Temp persp_centroid, linear_centroid;
|
|
||||||
|
|
||||||
/* GS inputs */
|
/* GS inputs */
|
||||||
Temp gs_wave_id;
|
Temp gs_wave_id;
|
||||||
|
|
||||||
|
@@ -3195,7 +3195,7 @@ static LLVMValueRef lookup_interp_param(struct ac_nir_context *ctx, enum glsl_in
|
|||||||
if (location == INTERP_CENTER)
|
if (location == INTERP_CENTER)
|
||||||
return ac_get_arg(&ctx->ac, ctx->args->persp_center);
|
return ac_get_arg(&ctx->ac, ctx->args->persp_center);
|
||||||
else if (location == INTERP_CENTROID)
|
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)
|
else if (location == INTERP_SAMPLE)
|
||||||
return ac_get_arg(&ctx->ac, ctx->args->persp_sample);
|
return ac_get_arg(&ctx->ac, ctx->args->persp_sample);
|
||||||
break;
|
break;
|
||||||
@@ -3203,7 +3203,7 @@ static LLVMValueRef lookup_interp_param(struct ac_nir_context *ctx, enum glsl_in
|
|||||||
if (location == INTERP_CENTER)
|
if (location == INTERP_CENTER)
|
||||||
return ac_get_arg(&ctx->ac, ctx->args->linear_center);
|
return ac_get_arg(&ctx->ac, ctx->args->linear_center);
|
||||||
else if (location == INTERP_CENTROID)
|
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)
|
else if (location == INTERP_SAMPLE)
|
||||||
return ac_get_arg(&ctx->ac, ctx->args->linear_sample);
|
return ac_get_arg(&ctx->ac, ctx->args->linear_sample);
|
||||||
break;
|
break;
|
||||||
|
@@ -46,7 +46,6 @@ struct ac_shader_abi {
|
|||||||
LLVMValueRef vertex_id;
|
LLVMValueRef vertex_id;
|
||||||
LLVMValueRef vs_rel_patch_id;
|
LLVMValueRef vs_rel_patch_id;
|
||||||
LLVMValueRef instance_id;
|
LLVMValueRef instance_id;
|
||||||
LLVMValueRef persp_centroid, linear_centroid;
|
|
||||||
LLVMValueRef user_data;
|
LLVMValueRef user_data;
|
||||||
|
|
||||||
/* replaced registers when culling enabled */
|
/* replaced registers when culling enabled */
|
||||||
|
@@ -253,38 +253,6 @@ radv_get_sampler_desc(struct ac_shader_abi *abi, LLVMValueRef index,
|
|||||||
return radv_load_rsrc(ctx, index, v4 ? ctx->ac.v4i32 : ctx->ac.v8i32);
|
return radv_load_rsrc(ctx, index, v4 ? ctx->ac.v4i32 : ctx->ac.v8i32);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
static void
|
||||||
scan_shader_output_decl(struct radv_shader_context *ctx, struct nir_variable *variable,
|
scan_shader_output_decl(struct radv_shader_context *ctx, struct nir_variable *variable,
|
||||||
struct nir_shader *shader, gl_shader_stage stage)
|
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);
|
LLVMPositionBuilderAtEnd(ctx.ac.builder, then_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shaders[shader_idx]->info.stage == MESA_SHADER_FRAGMENT)
|
if (shaders[shader_idx]->info.stage == MESA_SHADER_GEOMETRY && !info->is_ngg)
|
||||||
prepare_interp_optimize(&ctx, shaders[shader_idx]);
|
|
||||||
else if (shaders[shader_idx]->info.stage == MESA_SHADER_GEOMETRY && !info->is_ngg)
|
|
||||||
prepare_gs_input_vgprs(&ctx, shader_count >= 2);
|
prepare_gs_input_vgprs(&ctx, shader_count >= 2);
|
||||||
|
|
||||||
if (!ac_nir_translate(&ctx.ac, &ctx.abi, &args->ac, shaders[shader_idx])) {
|
if (!ac_nir_translate(&ctx.ac, &ctx.abi, &args->ac, shaders[shader_idx])) {
|
||||||
|
@@ -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,
|
.enable_mrt_output_nan_fixup = pipeline_key->ps.epilog.enable_mrt_output_nan_fixup,
|
||||||
.no_color_export = stage->info.ps.has_epilog,
|
.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);
|
NIR_PASS_V(stage->nir, ac_nir_lower_ps, &options);
|
||||||
|
@@ -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)
|
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);
|
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user