Module: Mesa Branch: main Commit: b8bd186788f361c184a4346c52359286e476599f URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b8bd186788f361c184a4346c52359286e476599f
Author: Qiang Yu <[email protected]> Date: Fri Mar 3 12:06:16 2023 +0800 radeonsi: add si_nir_emit_polygon_stipple Ported from si_llvm_emit_polygon_stipple(). Reviewed-by: Marek Olšák <[email protected]> Signed-off-by: Qiang Yu <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21683> --- src/gallium/drivers/radeonsi/si_shader.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index d538900eca2..67e98f9bfa4 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,
