<p dir="ltr">On Sep 7, 2016 10:24 AM, "Topi Pohjolainen" <<a href="mailto:topi.pohjolainen@gmail.com">topi.pohjolainen@gmail.com</a>> wrote:<br>
><br>
> v3:<br>
> - Actually set the flags when needed instead of falsely<br>
> overwriting them (Jason).<br>
> - Use more generic name for flag (dropped RENDERBUFFER)<br>
> - Consult also shader images<br>
><br>
> Signed-off-by: Topi Pohjolainen <<a href="mailto:topi.pohjolainen@intel.com">topi.pohjolainen@intel.com</a>><br>
> ---<br>
> src/mesa/drivers/dri/i965/brw_context.c | 32 ++++++++++++++++++++++++<br>
> src/mesa/drivers/dri/i965/brw_context.h | 10 ++++++++<br>
> src/mesa/drivers/dri/i965/brw_wm_surface_state.c | 12 +++++++--<br>
> 3 files changed, 52 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c<br>
> index b880b4f..0379cc0 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_context.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_context.c<br>
> @@ -168,6 +168,24 @@ intel_update_framebuffer(struct gl_context *ctx,<br>
> fb->DefaultGeometry.NumSamples);<br>
> }<br>
><br>
> +static bool<br>
> +intel_disable_rb_aux_buffer(struct brw_context *brw, const drm_intel_bo *bo)<br>
> +{<br>
> + const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;<br>
> + bool found = false;<br>
> +<br>
> + for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {<br>
> + const struct intel_renderbuffer *irb =<br>
> + intel_renderbuffer(fb->_ColorDrawBuffers[i]);<br>
> +<br>
> + if (irb->mt->bo == bo) {<br>
> + found = brw->draw_aux_buffer_disabled[i] = true;</p>
<p dir="ltr">Thanks for not breaking. You could, in theory have two different array slices of the same underlying texture bound as different render targets so we can't assume a one-to-one mapping of miptrees to render target indices.</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>></p>
<p dir="ltr">> + }<br>
> + }<br>
> +<br>
> + return found;<br>
> +}<br>
> +<br>
> /* On Gen9 color buffers may be compressed by the hardware (lossless<br>
> * compression). There are, however, format restrictions and care needs to be<br>
> * taken that the sampler engine is capable for re-interpreting a buffer with<br>
> @@ -197,6 +215,10 @@ intel_texture_view_requires_resolve(struct brw_context *brw,<br>
> _mesa_get_format_name(intel_tex->_Format),<br>
> _mesa_get_format_name(intel_tex->mt->format));<br>
><br>
> + if (intel_disable_rb_aux_buffer(brw, intel_tex->mt->bo))<br>
> + perf_debug("Sampling renderbuffer with non-compressible format - "<br>
> + "turning off compression");<br>
> +<br>
> return true;<br>
> }<br>
><br>
> @@ -220,6 +242,9 @@ intel_update_state(struct gl_context * ctx, GLuint new_state)<br>
> if (depth_irb)<br>
> intel_renderbuffer_resolve_hiz(brw, depth_irb);<br>
><br>
> + memset(brw->draw_aux_buffer_disabled, 0,<br>
> + sizeof(brw->draw_aux_buffer_disabled));<br>
> +<br>
> /* Resolve depth buffer and render cache of each enabled texture. */<br>
> int maxEnabledUnit = ctx->Texture._MaxEnabledTexImageUnit;<br>
> for (int i = 0; i <= maxEnabledUnit; i++) {<br>
> @@ -262,6 +287,13 @@ intel_update_state(struct gl_context * ctx, GLuint new_state)<br>
> * surfaces need to be resolved prior to accessing them.<br>
> */<br>
> intel_miptree_resolve_color(brw, tex_obj->mt, 0);<br>
> +<br>
> + if (brw->gen >= 9 &&<br>
> + intel_disable_rb_aux_buffer(brw, tex_obj->mt->bo)) {<br>
> + perf_debug("Using renderbuffer as shader image - turning "<br>
> + "off compression");<br>
> + }<br>
> +<br>
> brw_render_cache_set_check_flush(brw, tex_obj->mt->bo);<br>
> }<br>
> }<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
> index 12ac8af..074d554 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_context.h<br>
> +++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
> @@ -1333,6 +1333,16 @@ struct brw_context<br>
><br>
> struct brw_fast_clear_state *fast_clear_state;<br>
><br>
> + /* Array of flags telling if auxiliary buffer is disabled for corresponding<br>
> + * renderbuffer. If draw_aux_buffer_disabled[i] is set then use of<br>
> + * auxiliary buffer for gl_framebuffer::_ColorDrawBuffers[i] is<br>
> + * disabled.<br>
> + * This is needed in case the same underlying buffer is also configured<br>
> + * to be sampled but with a format that the sampling engine can't treat<br>
> + * compressed or fast cleared.<br>
> + */<br>
> + bool draw_aux_buffer_disabled[MAX_DRAW_BUFFERS];<br>
> +<br>
> __DRIcontext *driContext;<br>
> struct intel_screen *intelScreen;<br>
> };<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> index 073919e..c1273c5 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c<br>
> @@ -56,6 +56,7 @@<br>
><br>
> enum {<br>
> INTEL_RENDERBUFFER_LAYERED = 1 << 0,<br>
> + INTEL_AUX_BUFFER_DISABLED = 1 << 1,<br>
> };<br>
><br>
> struct surface_state_info {<br>
> @@ -194,6 +195,10 @@ brw_update_renderbuffer_surface(struct brw_context *brw,<br>
> struct intel_renderbuffer *irb = intel_renderbuffer(rb);<br>
> struct intel_mipmap_tree *mt = irb->mt;<br>
><br>
> + if (brw->gen < 9) {<br>
> + assert(!(flags & INTEL_AUX_BUFFER_DISABLED));<br>
> + }<br>
> +<br>
> assert(brw_render_target_supported(brw, rb));<br>
> intel_miptree_used_for_rendering(mt);<br>
><br>
> @@ -885,6 +890,7 @@ gen4_update_renderbuffer_surface(struct brw_context *brw,<br>
> /* BRW_NEW_FS_PROG_DATA */<br>
><br>
> assert(!(flags & INTEL_RENDERBUFFER_LAYERED));<br>
> + assert(!(flags & INTEL_AUX_BUFFER_DISABLED));<br>
><br>
> if (rb->TexImage && !brw->has_surface_tile_offset) {<br>
> intel_renderbuffer_get_tile_offsets(irb, &tile_x, &tile_y);<br>
> @@ -987,8 +993,10 @@ brw_update_renderbuffer_surfaces(struct brw_context *brw,<br>
> if (fb->_NumColorDrawBuffers >= 1) {<br>
> for (i = 0; i < fb->_NumColorDrawBuffers; i++) {<br>
> const uint32_t surf_index = render_target_start + i;<br>
> - const int flags =<br>
> - _mesa_geometric_layers(fb) > 0 ? INTEL_RENDERBUFFER_LAYERED : 0;<br>
> + const int flags = (_mesa_geometric_layers(fb) > 0 ?<br>
> + INTEL_RENDERBUFFER_LAYERED : 0) |<br>
> + (brw->draw_aux_buffer_disabled[i] ?<br>
> + INTEL_AUX_BUFFER_DISABLED : 0);<br>
><br>
> if (intel_renderbuffer(fb->_ColorDrawBuffers[i])) {<br>
> surf_offset[surf_index] =<br>
> --<br>
> 2.5.5<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
><a href="mailto:mesa-dev@lists.freedesktop.org"> mesa-dev@lists.freedesktop.org</a><br>
><a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev"> https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>