Fast color clears simply fill the MCS buffer with 0xff. If the MCS BO is not busy, we can map it without stalling and simply use memset to do that, without having to reprogram the entire GPU, draw rectangles, and invoke pixel shaders. This is presumably cheaper.
This code was swiped from intel_miptree_alloc_mcs, which clears the buffer using memset when allocating the MCS. Improves performance in GpuTest Triangle by 5.09439% +/- 1.27536%. Xonotic, EgyptHD, and many others also hit this path, but I was not able to measure any performance increase in other applications. Signed-off-by: Kenneth Graunke <[email protected]> Concerns I have which hopefully reviewers can address: - Do we need to worry about clipping/scissoring/etc? I think our fast color clear implementation only handles full surface clears, so we should be OK. - Do we need to check if the miptree BO is referenced/busy? Or is checking the MCS really sufficient? --- src/mesa/drivers/dri/i965/brw_meta_fast_clear.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c index b4e75a7..43df2d0 100644 --- a/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c +++ b/src/mesa/drivers/dri/i965/brw_meta_fast_clear.c @@ -503,6 +503,19 @@ brw_meta_fast_clear(struct brw_context *brw, struct gl_framebuffer *fb, if (irb->mt->fast_clear_state == INTEL_FAST_CLEAR_STATE_CLEAR) continue; + /* If the MCS isn't busy, just do a CPU-side memset rather than + * reprogramming the whole GPU. + */ + if (!drm_intel_bo_references(brw->batch.bo, irb->mt->mcs_mt->bo) && + !drm_intel_bo_busy(irb->mt->mcs_mt->bo)) { + void *data = intel_miptree_map_raw(brw, irb->mt->mcs_mt); + memset(data, 0xff, + irb->mt->mcs_mt->total_height * irb->mt->mcs_mt->pitch); + intel_miptree_unmap_raw(brw, irb->mt->mcs_mt); + irb->mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_CLEAR; + continue; + } + /* Set fast_clear_state to RESOLVED so we don't try resolve them when * we draw, in case the mt is also bound as a texture. */ -- 2.1.0 _______________________________________________ mesa-dev mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-dev
