radeonsi: silence a Coverity warning
[mesa.git] / src / gallium / drivers / radeonsi / si_blit.c
index 5b533732a4db95b7e60290a9b152027510322ebd..998288dba2fe6f1594a49e3c52307f7334590f6a 100644 (file)
@@ -427,8 +427,7 @@ static void si_blit_decompress_color(struct pipe_context *ctx,
 
                /* disable levels without DCC */
                for (int i = first_level; i <= last_level; i++) {
-                       if (!rtex->dcc_offset ||
-                           i >= rtex->surface.num_dcc_levels)
+                       if (!vi_dcc_enabled(rtex, i))
                                level_mask &= ~(1 << i);
                }
        } else if (rtex->fmask.size) {
@@ -469,6 +468,19 @@ static void si_blit_decompress_color(struct pipe_context *ctx,
        }
 }
 
+static void
+si_decompress_color_texture(struct si_context *sctx, struct r600_texture *tex,
+                           unsigned first_level, unsigned last_level)
+{
+       /* CMASK or DCC can be discarded and we can still end up here. */
+       if (!tex->cmask.size && !tex->fmask.size && !tex->dcc_offset)
+               return;
+
+       si_blit_decompress_color(&sctx->b.b, tex, first_level, last_level, 0,
+                                util_max_layer(&tex->resource.b.b, first_level),
+                                false);
+}
+
 static void
 si_decompress_sampler_color_textures(struct si_context *sctx,
                                     struct si_textures_info *textures)
@@ -486,14 +498,9 @@ si_decompress_sampler_color_textures(struct si_context *sctx,
                assert(view);
 
                tex = (struct r600_texture *)view->texture;
-               /* CMASK or DCC can be discarded and we can still end up here. */
-               if (!tex->cmask.size && !tex->fmask.size && !tex->dcc_offset)
-                       continue;
 
-               si_blit_decompress_color(&sctx->b.b, tex,
-                                        view->u.tex.first_level, view->u.tex.last_level,
-                                        0, util_max_layer(&tex->resource.b.b, view->u.tex.first_level),
-                                        false);
+               si_decompress_color_texture(sctx, tex, view->u.tex.first_level,
+                                           view->u.tex.last_level);
        }
 }
 
@@ -514,14 +521,44 @@ si_decompress_image_color_textures(struct si_context *sctx,
                assert(view->resource->target != PIPE_BUFFER);
 
                tex = (struct r600_texture *)view->resource;
-               if (!tex->cmask.size && !tex->fmask.size && !tex->dcc_offset)
+
+               si_decompress_color_texture(sctx, tex, view->u.tex.level,
+                                           view->u.tex.level);
+       }
+}
+
+static void si_check_render_feedback_texture(struct si_context *sctx,
+                                            struct r600_texture *tex,
+                                            unsigned first_level,
+                                            unsigned last_level,
+                                            unsigned first_layer,
+                                            unsigned last_layer)
+{
+       bool render_feedback = false;
+
+       if (!tex->dcc_offset)
+               return;
+
+       for (unsigned j = 0; j < sctx->framebuffer.state.nr_cbufs; ++j) {
+               struct r600_surface * surf;
+
+               if (!sctx->framebuffer.state.cbufs[j])
                        continue;
 
-               si_blit_decompress_color(&sctx->b.b, tex,
-                                        view->u.tex.level, view->u.tex.level,
-                                        0, util_max_layer(&tex->resource.b.b, view->u.tex.level),
-                                        false);
+               surf = (struct r600_surface*)sctx->framebuffer.state.cbufs[j];
+
+               if (tex == (struct r600_texture *)surf->base.texture &&
+                   surf->base.u.tex.level >= first_level &&
+                   surf->base.u.tex.level <= last_level &&
+                   surf->base.u.tex.first_layer <= last_layer &&
+                   surf->base.u.tex.last_layer >= first_layer) {
+                       render_feedback = true;
+                       break;
+               }
        }
+
+       if (render_feedback)
+               r600_texture_disable_dcc(&sctx->b, tex);
 }
 
 static void si_check_render_feedback_textures(struct si_context *sctx,
@@ -532,7 +569,6 @@ static void si_check_render_feedback_textures(struct si_context *sctx,
        while (mask) {
                const struct pipe_sampler_view *view;
                struct r600_texture *tex;
-               bool render_feedback = false;
 
                unsigned i = u_bit_scan(&mask);
 
@@ -541,27 +577,12 @@ static void si_check_render_feedback_textures(struct si_context *sctx,
                        continue;
 
                tex = (struct r600_texture *)view->texture;
-               if (!tex->dcc_offset)
-                       continue;
-
-               for (unsigned j = 0; j < sctx->framebuffer.state.nr_cbufs; ++j) {
-                       struct r600_surface * surf;
-
-                       if (!sctx->framebuffer.state.cbufs[j])
-                               continue;
-
-                       surf = (struct r600_surface*)sctx->framebuffer.state.cbufs[j];
 
-                       if (tex == (struct r600_texture*)surf->base.texture &&
-                           surf->base.u.tex.level >= view->u.tex.first_level &&
-                           surf->base.u.tex.level <= view->u.tex.last_level &&
-                           surf->base.u.tex.first_layer <= view->u.tex.last_layer &&
-                           surf->base.u.tex.last_layer >= view->u.tex.first_layer)
-                               render_feedback = true;
-               }
-
-               if (render_feedback)
-                       r600_texture_disable_dcc(&sctx->b, tex);
+               si_check_render_feedback_texture(sctx, tex,
+                                                view->u.tex.first_level,
+                                                view->u.tex.last_level,
+                                                view->u.tex.first_layer,
+                                                view->u.tex.last_layer);
        }
 }
 
@@ -573,7 +594,6 @@ static void si_check_render_feedback_images(struct si_context *sctx,
        while (mask) {
                const struct pipe_image_view *view;
                struct r600_texture *tex;
-               bool render_feedback = false;
 
                unsigned i = u_bit_scan(&mask);
 
@@ -582,26 +602,12 @@ static void si_check_render_feedback_images(struct si_context *sctx,
                        continue;
 
                tex = (struct r600_texture *)view->resource;
-               if (!tex->dcc_offset)
-                       continue;
 
-               for (unsigned j = 0; j < sctx->framebuffer.state.nr_cbufs; ++j) {
-                       struct r600_surface * surf;
-
-                       if (!sctx->framebuffer.state.cbufs[j])
-                               continue;
-
-                       surf = (struct r600_surface*)sctx->framebuffer.state.cbufs[j];
-
-                       if (tex == (struct r600_texture*)surf->base.texture &&
-                           surf->base.u.tex.level == view->u.tex.level &&
-                           surf->base.u.tex.first_layer <= view->u.tex.last_layer &&
-                           surf->base.u.tex.last_layer >= view->u.tex.first_layer)
-                               render_feedback = true;
-               }
-
-               if (render_feedback)
-                       r600_texture_disable_dcc(&sctx->b, tex);
+               si_check_render_feedback_texture(sctx, tex,
+                                                view->u.tex.level,
+                                                view->u.tex.level,
+                                                view->u.tex.first_layer,
+                                                view->u.tex.last_layer);
        }
 }
 
@@ -618,10 +624,9 @@ static void si_check_render_feedback(struct si_context *sctx)
        sctx->need_check_render_feedback = false;
 }
 
-static void si_decompress_textures(struct si_context *sctx, int shader_start,
-                                   int shader_end)
+static void si_decompress_textures(struct si_context *sctx, unsigned shader_mask)
 {
-       unsigned compressed_colortex_counter;
+       unsigned compressed_colortex_counter, mask;
 
        if (sctx->blitter->running)
                return;
@@ -633,8 +638,11 @@ static void si_decompress_textures(struct si_context *sctx, int shader_start,
                si_update_compressed_colortex_masks(sctx);
        }
 
-       /* Flush depth textures which need to be flushed. */
-       for (int i = shader_start; i < shader_end; i++) {
+       /* Decompress color & depth textures if needed. */
+       mask = sctx->compressed_tex_shader_mask & shader_mask;
+       while (mask) {
+               unsigned i = u_bit_scan(&mask);
+
                if (sctx->samplers[i].depth_texture_mask) {
                        si_flush_depth_textures(sctx, &sctx->samplers[i]);
                }
@@ -651,12 +659,12 @@ static void si_decompress_textures(struct si_context *sctx, int shader_start,
 
 void si_decompress_graphics_textures(struct si_context *sctx)
 {
-       si_decompress_textures(sctx, 0, SI_NUM_GRAPHICS_SHADERS);
+       si_decompress_textures(sctx, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS));
 }
 
 void si_decompress_compute_textures(struct si_context *sctx)
 {
-       si_decompress_textures(sctx, SI_NUM_GRAPHICS_SHADERS, SI_NUM_SHADERS);
+       si_decompress_textures(sctx, 1 << PIPE_SHADER_COMPUTE);
 }
 
 static void si_clear(struct pipe_context *ctx, unsigned buffers,
@@ -843,7 +851,7 @@ void si_resource_copy_region(struct pipe_context *ctx,
        struct pipe_surface *dst_view, dst_templ;
        struct pipe_sampler_view src_templ, *src_view;
        unsigned dst_width, dst_height, src_width0, src_height0;
-       unsigned src_force_level = 0;
+       unsigned dst_width0, dst_height0, src_force_level = 0;
        struct pipe_box sbox, dstbox;
 
        /* Handle buffers first. */
@@ -861,6 +869,8 @@ void si_resource_copy_region(struct pipe_context *ctx,
 
        dst_width = u_minify(dst->width0, dst_level);
        dst_height = u_minify(dst->height0, dst_level);
+       dst_width0 = dst->width0;
+       dst_height0 = dst->height0;
        src_width0 = src->width0;
        src_height0 = src->height0;
 
@@ -879,6 +889,8 @@ void si_resource_copy_region(struct pipe_context *ctx,
 
                dst_width = util_format_get_nblocksx(dst->format, dst_width);
                dst_height = util_format_get_nblocksy(dst->format, dst_height);
+               dst_width0 = util_format_get_nblocksx(dst->format, dst_width0);
+               dst_height0 = util_format_get_nblocksy(dst->format, dst_height0);
                src_width0 = util_format_get_nblocksx(src->format, src_width0);
                src_height0 = util_format_get_nblocksy(src->format, src_height0);
 
@@ -894,14 +906,13 @@ void si_resource_copy_region(struct pipe_context *ctx,
                src_box = &sbox;
 
                src_force_level = src_level;
-       } else if (!util_blitter_is_copy_supported(sctx->blitter, dst, src) ||
-                  /* also *8_SNORM has precision issues, use UNORM instead */
-                  util_format_is_snorm8(src->format)) {
+       } else if (!util_blitter_is_copy_supported(sctx->blitter, dst, src)) {
                if (util_format_is_subsampled_422(src->format)) {
                        src_templ.format = PIPE_FORMAT_R8G8B8A8_UINT;
                        dst_templ.format = PIPE_FORMAT_R8G8B8A8_UINT;
 
                        dst_width = util_format_get_nblocksx(dst->format, dst_width);
+                       dst_width0 = util_format_get_nblocksx(dst->format, dst_width0);
                        src_width0 = util_format_get_nblocksx(src->format, src_width0);
 
                        dstx = util_format_get_nblocksx(dst->format, dstx);
@@ -942,8 +953,14 @@ void si_resource_copy_region(struct pipe_context *ctx,
                }
        }
 
+       vi_disable_dcc_if_incompatible_format(&sctx->b, dst, dst_level,
+                                             dst_templ.format);
+       vi_disable_dcc_if_incompatible_format(&sctx->b, src, src_level,
+                                             src_templ.format);
+
        /* Initialize the surface. */
        dst_view = r600_create_surface_custom(ctx, dst, &dst_templ,
+                                             dst_width0, dst_height0,
                                              dst_width, dst_height);
 
        /* Initialize the sampler view. */
@@ -1031,8 +1048,12 @@ static bool do_hardware_msaa_resolve(struct pipe_context *ctx,
                 * it's being overwritten anyway, clear it to uncompressed.
                 * This is still the fastest codepath even with this clear.
                 */
-               if (dst->dcc_offset &&
-                   info->dst.level < dst->surface.num_dcc_levels) {
+               if (vi_dcc_enabled(dst, info->dst.level)) {
+                       /* TODO: Implement per-level DCC clears for GFX9. */
+                       if (sctx->b.chip_class >= GFX9 &&
+                           info->dst.resource->last_level != 0)
+                               goto resolve_to_temp;
+
                        vi_dcc_clear_level(&sctx->b, dst, info->dst.level,
                                           0xFFFFFFFF);
                        dst->dirty_level_mask &= ~(1 << info->dst.level);
@@ -1134,10 +1155,10 @@ static void si_blit(struct pipe_context *ctx,
 
        /* The driver doesn't decompress resources automatically while
         * u_blitter is rendering. */
-       vi_dcc_disable_if_incompatible_format(&sctx->b, info->src.resource,
+       vi_disable_dcc_if_incompatible_format(&sctx->b, info->src.resource,
                                              info->src.level,
                                              info->src.format);
-       vi_dcc_disable_if_incompatible_format(&sctx->b, info->dst.resource,
+       vi_disable_dcc_if_incompatible_format(&sctx->b, info->dst.resource,
                                              info->dst.level,
                                              info->dst.format);
        si_decompress_subresource(ctx, info->src.resource, info->mask,
@@ -1169,7 +1190,7 @@ static boolean si_generate_mipmap(struct pipe_context *ctx,
 
        /* The driver doesn't decompress resources automatically while
         * u_blitter is rendering. */
-       vi_dcc_disable_if_incompatible_format(&sctx->b, tex, base_level,
+       vi_disable_dcc_if_incompatible_format(&sctx->b, tex, base_level,
                                              format);
        si_decompress_subresource(ctx, tex, PIPE_MASK_RGBAZS,
                                  base_level, first_layer, last_layer);