From: Qiang Yu Date: Fri, 3 Mar 2023 04:06:16 +0000 (+0800) Subject: radeonsi: add si_nir_emit_polygon_stipple X-Git-Tag: upstream/23.3.3~9933 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b8bd186788f361c184a4346c52359286e476599f;p=platform%2Fupstream%2Fmesa.git radeonsi: add si_nir_emit_polygon_stipple Ported from si_llvm_emit_polygon_stipple(). Reviewed-by: Marek Olšák Signed-off-by: Qiang Yu Part-of: --- diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index d538900..67e98f9 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -1943,6 +1943,37 @@ static void si_nir_lower_ps_color_input(nir_shader *nir, struct si_shader *shade colors); } +static void si_nir_emit_polygon_stipple(nir_shader *nir, struct si_shader_args *args) +{ + nir_function_impl *impl = nir_shader_get_entrypoint(nir); + + nir_builder builder; + nir_builder *b = &builder; + nir_builder_init(b, impl); + + b->cursor = nir_before_cf_list(&impl->body); + + /* Load the buffer descriptor. */ + nir_ssa_def *desc = + si_nir_load_internal_binding(b, args, SI_PS_CONST_POLY_STIPPLE, 4); + + /* Use the fixed-point gl_FragCoord input. + * Since the stipple pattern is 32x32 and it repeats, just get 5 bits + * per coordinate to get the repeating effect. + */ + nir_ssa_def *pos_x = ac_nir_unpack_arg(b, &args->ac, args->pos_fixed_pt, 0, 5); + nir_ssa_def *pos_y = ac_nir_unpack_arg(b, &args->ac, args->pos_fixed_pt, 16, 5); + + nir_ssa_def *zero = nir_imm_int(b, 0); + /* The stipple pattern is 32x32, each row has 32 bits. */ + nir_ssa_def *offset = nir_ishl_imm(b, pos_y, 2); + nir_ssa_def *row = nir_load_buffer_amd(b, 1, 32, desc, offset, zero, zero); + nir_ssa_def *bit = nir_ubfe(b, row, pos_x, nir_imm_int(b, 1)); + + nir_ssa_def *pass = nir_i2b(b, bit); + nir_discard_if(b, nir_inot(b, pass)); +} + struct nir_shader *si_get_nir_shader(struct si_shader *shader, struct si_shader_args *args, bool *free_nir,