-static unsigned
-brw_find_matching_rb(const struct gl_framebuffer *fb,
- const struct intel_mipmap_tree *mt)
-{
- for (unsigned i = 0; i < fb->_NumColorDrawBuffers; i++) {
- const struct intel_renderbuffer *irb =
- intel_renderbuffer(fb->_ColorDrawBuffers[i]);
-
- if (irb && irb->mt == mt)
- return i;
- }
-
- return fb->_NumColorDrawBuffers;
-}
-
-static inline bool
-brw_texture_view_sane(const struct brw_context *brw,
- const struct intel_mipmap_tree *mt,
- const struct isl_view *view)
-{
- /* There are special cases only for lossless compression. */
- if (!intel_miptree_is_lossless_compressed(brw, mt))
- return true;
-
- if (isl_format_supports_ccs_e(&brw->screen->devinfo, view->format))
- return true;
-
- /* Logic elsewhere needs to take care to resolve the color buffer prior
- * to sampling it as non-compressed.
- */
- if (intel_miptree_has_color_unresolved(mt, view->base_level, view->levels,
- view->base_array_layer,
- view->array_len))
- return false;
-
- const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
- const unsigned rb_index = brw_find_matching_rb(fb, mt);
-
- if (rb_index == fb->_NumColorDrawBuffers)
- return true;
-
- /* Underlying surface is compressed but it is sampled using a format that
- * the sampling engine doesn't support as compressed. Compression must be
- * disabled for both sampling engine and data port in case the same surface
- * is used also as render target.
- */
- return brw->draw_aux_buffer_disabled[rb_index];
-}
-
-static bool
-brw_disable_aux_surface(const struct brw_context *brw,
- const struct intel_mipmap_tree *mt,
- const struct isl_view *view)
-{
- /* Nothing to disable. */
- if (!mt->mcs_buf)
- return false;
-
- const bool is_unresolved = intel_miptree_has_color_unresolved(
- mt, view->base_level, view->levels,
- view->base_array_layer, view->array_len);
-
- /* There are special cases only for lossless compression. */
- if (!intel_miptree_is_lossless_compressed(brw, mt))
- return !is_unresolved;
-
- const struct gl_framebuffer *fb = brw->ctx.DrawBuffer;
- const unsigned rb_index = brw_find_matching_rb(fb, mt);
-
- /* If we are drawing into this with compression enabled, then we must also
- * enable compression when texturing from it regardless of
- * fast_clear_state. If we don't then, after the first draw call with
- * this setup, there will be data in the CCS which won't get picked up by
- * subsequent texturing operations as required by ARB_texture_barrier.
- * Since we don't want to re-emit the binding table or do a resolve
- * operation every draw call, the easiest thing to do is just enable
- * compression on the texturing side. This is completely safe to do
- * since, if compressed texturing weren't allowed, we would have disabled
- * compression of render targets in whatever_that_function_is_called().
- */
- if (rb_index < fb->_NumColorDrawBuffers) {
- if (brw->draw_aux_buffer_disabled[rb_index]) {
- assert(!is_unresolved);
- }
-
- return brw->draw_aux_buffer_disabled[rb_index];
- }
-
- return !is_unresolved;
-}
-
-void
-brw_update_texture_surface(struct gl_context *ctx,