radeonsi: add and implement load_user_clip_plane abi

This is used by NGG culling for legacy user clip plane clip
which only happens in VS.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17455>
This commit is contained in:
Qiang Yu 2022-07-08 22:26:45 +08:00 committed by Marge Bot
parent 86832964cf
commit 4330313666
3 changed files with 17 additions and 0 deletions

View file

@ -3613,6 +3613,9 @@ static bool visit_intrinsic(struct ac_nir_context *ctx, nir_intrinsic_instr *ins
case nir_intrinsic_load_cull_small_primitives_enabled_amd:
result = ctx->abi->intrinsic_load(ctx->abi, instr->intrinsic);
break;
case nir_intrinsic_load_user_clip_plane:
result = ctx->abi->load_user_clip_plane(ctx->abi, nir_intrinsic_ucp_id(instr));
break;
case nir_intrinsic_load_vertex_id_zero_base:
result = ctx->abi->vertex_id_replaced ? ctx->abi->vertex_id_replaced : ctx->abi->vertex_id;
break;

View file

@ -109,6 +109,8 @@ struct ac_shader_abi {
LLVMValueRef (*load_sample_position)(struct ac_shader_abi *abi, LLVMValueRef sample_id);
LLVMValueRef (*load_user_clip_plane)(struct ac_shader_abi *abi, unsigned ucp_id);
LLVMValueRef (*emit_fbfetch)(struct ac_shader_abi *abi);
LLVMValueRef (*intrinsic_load)(struct ac_shader_abi *abi, nir_intrinsic_op op);

View file

@ -857,6 +857,17 @@ static LLVMValueRef si_llvm_load_intrinsic(struct ac_shader_abi *abi, nir_intrin
}
}
static LLVMValueRef si_llvm_load_user_clip_plane(struct ac_shader_abi *abi, unsigned ucp_id)
{
struct si_shader_context *ctx = si_shader_context_from_abi(abi);
LLVMValueRef ptr = ac_get_arg(&ctx->ac, ctx->internal_bindings);
LLVMValueRef constbuf_index = LLVMConstInt(ctx->ac.i32, SI_VS_CONST_CLIP_PLANES, 0);
LLVMValueRef const_resource = ac_build_load_to_sgpr(&ctx->ac, ptr, constbuf_index);
LLVMValueRef addr = LLVMConstInt(ctx->ac.i32, ucp_id * 16, 0);
return ac_build_buffer_load(&ctx->ac, const_resource, 4, NULL, addr, NULL,
ctx->ac.f32, 0, true, true);
}
bool si_llvm_translate_nir(struct si_shader_context *ctx, struct si_shader *shader,
struct nir_shader *nir, bool free_nir, bool ngg_cull_shader)
{
@ -873,6 +884,7 @@ bool si_llvm_translate_nir(struct si_shader_context *ctx, struct si_shader *shad
ctx->num_images = info->base.num_images;
ctx->abi.intrinsic_load = si_llvm_load_intrinsic;
ctx->abi.load_user_clip_plane = si_llvm_load_user_clip_plane;
si_llvm_init_resource_callbacks(ctx);
si_llvm_create_main_func(ctx, ngg_cull_shader);