[Mesa-dev] [PATCH 3/4] radeonsi: add more unlikely() uses into si_draw_vbo

Michel Dänzer michel at daenzer.net
Tue Sep 6 01:54:29 UTC 2016


On 06/09/16 07:46 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>

Did you measure any significant performance boost with this change?
Otherwise, using (un)likely can be bad because it can defeat the CPU's
branch prediction, which tends to be pretty good these days.


> -	if (!sctx->vs_shader.cso) {
> +	if (unlikely(!sctx->vs_shader.cso)) {
>  		assert(0);
>  		return;
>  	}
> -	if (!sctx->ps_shader.cso && (!rs || !rs->rasterizer_discard)) {
> +	if (unlikely(!sctx->ps_shader.cso && (!rs || !rs->rasterizer_discard))) {
>  		assert(0);
>  		return;
>  	}
> -	if (!!sctx->tes_shader.cso != (info->mode == PIPE_PRIM_PATCHES)) {
> +	if (unlikely(!!sctx->tes_shader.cso != (info->mode == PIPE_PRIM_PATCHES))) {
>  		assert(0);
>  		return;
>  	}

These three are no-brainers though, as these conditions are normally
never true.


>  	/* Re-emit the framebuffer state if needed. */
>  	dirty_fb_counter = p_atomic_read(&sctx->b.screen->dirty_fb_counter);
> -	if (dirty_fb_counter != sctx->b.last_dirty_fb_counter) {
> +	if (unlikely(dirty_fb_counter != sctx->b.last_dirty_fb_counter)) {
>  		sctx->b.last_dirty_fb_counter = dirty_fb_counter;
>  		sctx->framebuffer.dirty_cbufs |=
>  			((1 << sctx->framebuffer.state.nr_cbufs) - 1);
>  		sctx->framebuffer.dirty_zsbuf = true;
>  		si_mark_atom_dirty(sctx, &sctx->framebuffer.atom);
>  	}
>  
>  	/* Invalidate & recompute texture descriptors if needed. */
>  	dirty_tex_counter = p_atomic_read(&sctx->b.screen->dirty_tex_descriptor_counter);
> -	if (dirty_tex_counter != sctx->b.last_dirty_tex_descriptor_counter) {
> +	if (unlikely(dirty_tex_counter != sctx->b.last_dirty_tex_descriptor_counter)) {
>  		sctx->b.last_dirty_tex_descriptor_counter = dirty_tex_counter;
>  		si_update_all_texture_descriptors(sctx);
>  	}

But these two might be better left to the CPU's branch prediction.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the mesa-dev mailing list