radeonsi: Set PIPE_SHADER_CAP_MAX_SHADER_IMAGES
[mesa.git] / src / gallium / drivers / radeonsi / si_blit.c
index 13d8e6f2a5f26833d60e6f107b07f125202fac33..e0dbec5fb7905ea5545cf67e1cdd3f263f5d4bf3 100644 (file)
@@ -80,7 +80,7 @@ static void si_blitter_begin(struct pipe_context *ctx, enum si_blitter_op op)
        if (op & SI_SAVE_TEXTURES) {
                util_blitter_save_fragment_sampler_states(
                        sctx->blitter, 2,
-                       sctx->samplers[PIPE_SHADER_FRAGMENT].states.saved_states);
+                       sctx->samplers[PIPE_SHADER_FRAGMENT].views.sampler_states);
 
                util_blitter_save_fragment_sampler_views(sctx->blitter, 2,
                        sctx->samplers[PIPE_SHADER_FRAGMENT].views.views);
@@ -241,8 +241,9 @@ static void si_blit_decompress_depth_in_place(struct si_context *sctx,
        si_mark_atom_dirty(sctx, &sctx->db_render_state);
 }
 
-void si_flush_depth_textures(struct si_context *sctx,
-                            struct si_textures_info *textures)
+static void
+si_flush_depth_textures(struct si_context *sctx,
+                       struct si_textures_info *textures)
 {
        unsigned i;
        unsigned mask = textures->depth_texture_mask;
@@ -271,18 +272,29 @@ void si_flush_depth_textures(struct si_context *sctx,
 static void si_blit_decompress_color(struct pipe_context *ctx,
                struct r600_texture *rtex,
                unsigned first_level, unsigned last_level,
-               unsigned first_layer, unsigned last_layer)
+               unsigned first_layer, unsigned last_layer,
+               bool need_dcc_decompress)
 {
        struct si_context *sctx = (struct si_context *)ctx;
        unsigned layer, level, checked_last_layer, max_layer;
 
-       if (!rtex->dirty_level_mask)
+       if (!rtex->dirty_level_mask && !need_dcc_decompress)
                return;
 
        for (level = first_level; level <= last_level; level++) {
-               if (!(rtex->dirty_level_mask & (1 << level)))
+               void* custom_blend;
+
+               if (!(rtex->dirty_level_mask & (1 << level)) && !need_dcc_decompress)
                        continue;
 
+               if (rtex->dcc_offset && need_dcc_decompress) {
+                       custom_blend = sctx->custom_blend_dcc_decompress;
+               } else if (rtex->fmask.size) {
+                       custom_blend = sctx->custom_blend_decompress;
+               } else {
+                       custom_blend = sctx->custom_blend_fastclear;
+               }
+
                /* The smaller the mipmap level, the less layers there are
                 * as far as 3D textures are concerned. */
                max_layer = util_max_layer(&rtex->resource.b.b, level);
@@ -298,9 +310,7 @@ static void si_blit_decompress_color(struct pipe_context *ctx,
                        cbsurf = ctx->create_surface(ctx, &rtex->resource.b.b, &surf_tmpl);
 
                        si_blitter_begin(ctx, SI_DECOMPRESS);
-                       util_blitter_custom_color(sctx->blitter, cbsurf,
-                               rtex->fmask.size ? sctx->custom_blend_decompress :
-                                                  sctx->custom_blend_fastclear);
+                       util_blitter_custom_color(sctx->blitter, cbsurf, custom_blend);
                        si_blitter_end(ctx);
 
                        pipe_surface_reference(&cbsurf, NULL);
@@ -314,8 +324,9 @@ static void si_blit_decompress_color(struct pipe_context *ctx,
        }
 }
 
-void si_decompress_color_textures(struct si_context *sctx,
-                                 struct si_textures_info *textures)
+static void
+si_decompress_sampler_color_textures(struct si_context *sctx,
+                                    struct si_textures_info *textures)
 {
        unsigned i;
        unsigned mask = textures->compressed_colortex_mask;
@@ -330,11 +341,67 @@ void si_decompress_color_textures(struct si_context *sctx,
                assert(view);
 
                tex = (struct r600_texture *)view->texture;
-               assert(tex->cmask.size || tex->fmask.size || tex->dcc_buffer);
+               assert(tex->cmask.size || tex->fmask.size || tex->dcc_offset);
 
                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));
+                                        0, util_max_layer(&tex->resource.b.b, view->u.tex.first_level),
+                                        false);
+       }
+}
+
+static void
+si_decompress_image_color_textures(struct si_context *sctx,
+                                  struct si_images_info *images)
+{
+       unsigned i;
+       unsigned mask = images->compressed_colortex_mask;
+
+       while (mask) {
+               const struct pipe_image_view *view;
+               struct r600_texture *tex;
+
+               i = u_bit_scan(&mask);
+
+               view = &images->views[i];
+               assert(view->resource->target != PIPE_BUFFER);
+
+               tex = (struct r600_texture *)view->resource;
+               if (!tex->cmask.size && !tex->fmask.size && !tex->dcc_offset)
+                       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);
+       }
+}
+
+void si_decompress_textures(struct si_context *sctx)
+{
+       unsigned compressed_colortex_counter;
+
+       if (sctx->blitter->running)
+               return;
+
+       /* Update the compressed_colortex_mask if necessary. */
+       compressed_colortex_counter = p_atomic_read(&sctx->screen->b.compressed_colortex_counter);
+       if (compressed_colortex_counter != sctx->b.last_compressed_colortex_counter) {
+               sctx->b.last_compressed_colortex_counter = compressed_colortex_counter;
+               si_update_compressed_colortex_masks(sctx);
+       }
+
+       /* Flush depth textures which need to be flushed. */
+       for (int i = 0; i < SI_NUM_SHADERS; i++) {
+               if (sctx->samplers[i].depth_texture_mask) {
+                       si_flush_depth_textures(sctx, &sctx->samplers[i]);
+               }
+               if (sctx->samplers[i].compressed_colortex_mask) {
+                       si_decompress_sampler_color_textures(sctx, &sctx->samplers[i]);
+               }
+               if (sctx->images[i].compressed_colortex_mask) {
+                       si_decompress_image_color_textures(sctx, &sctx->images[i]);
+               }
        }
 }
 
@@ -377,22 +444,39 @@ static void si_clear(struct pipe_context *ctx, unsigned buffers,
                }
        }
 
-       if (buffers & PIPE_CLEAR_DEPTH &&
-           zstex && zstex->htile_buffer &&
+       if (zstex && zstex->htile_buffer &&
            zsbuf->u.tex.level == 0 &&
            zsbuf->u.tex.first_layer == 0 &&
            zsbuf->u.tex.last_layer == util_max_layer(&zstex->resource.b.b, 0)) {
-               /* Need to disable EXPCLEAR temporarily if clearing
-                * to a new value. */
-               if (zstex->depth_cleared && zstex->depth_clear_value != depth) {
-                       sctx->db_depth_disable_expclear = true;
+               if (buffers & PIPE_CLEAR_DEPTH) {
+                       /* Need to disable EXPCLEAR temporarily if clearing
+                        * to a new value. */
+                       if (zstex->depth_cleared && zstex->depth_clear_value != depth) {
+                               sctx->db_depth_disable_expclear = true;
+                       }
+
+                       zstex->depth_clear_value = depth;
+                       sctx->framebuffer.dirty_zsbuf = true;
+                       si_mark_atom_dirty(sctx, &sctx->framebuffer.atom); /* updates DB_DEPTH_CLEAR */
+                       sctx->db_depth_clear = true;
+                       si_mark_atom_dirty(sctx, &sctx->db_render_state);
                }
 
-               zstex->depth_clear_value = depth;
-               sctx->framebuffer.dirty_zsbuf = true;
-               si_mark_atom_dirty(sctx, &sctx->framebuffer.atom); /* updates DB_DEPTH_CLEAR */
-               sctx->db_depth_clear = true;
-               si_mark_atom_dirty(sctx, &sctx->db_render_state);
+               if (buffers & PIPE_CLEAR_STENCIL) {
+                       stencil &= 0xff;
+
+                       /* Need to disable EXPCLEAR temporarily if clearing
+                        * to a new value. */
+                       if (zstex->stencil_cleared && zstex->stencil_clear_value != stencil) {
+                               sctx->db_stencil_disable_expclear = true;
+                       }
+
+                       zstex->stencil_clear_value = stencil;
+                       sctx->framebuffer.dirty_zsbuf = true;
+                       si_mark_atom_dirty(sctx, &sctx->framebuffer.atom); /* updates DB_STENCIL_CLEAR */
+                       sctx->db_stencil_clear = true;
+                       si_mark_atom_dirty(sctx, &sctx->db_render_state);
+               }
        }
 
        si_blitter_begin(ctx, SI_CLEAR);
@@ -407,6 +491,13 @@ static void si_clear(struct pipe_context *ctx, unsigned buffers,
                zstex->depth_cleared = true;
                si_mark_atom_dirty(sctx, &sctx->db_render_state);
        }
+
+       if (sctx->db_stencil_clear) {
+               sctx->db_stencil_clear = false;
+               sctx->db_stencil_disable_expclear = false;
+               zstex->stencil_cleared = true;
+               si_mark_atom_dirty(sctx, &sctx->db_render_state);
+       }
 }
 
 static void si_clear_render_target(struct pipe_context *ctx,
@@ -459,9 +550,9 @@ static void si_decompress_subresource(struct pipe_context *ctx,
                        si_blit_decompress_depth_in_place(sctx, rtex, true,
                                                          level, level,
                                                          first_layer, last_layer);
-       } else if (rtex->fmask.size || rtex->cmask.size || rtex->dcc_buffer) {
+       } else if (rtex->fmask.size || rtex->cmask.size || rtex->dcc_offset) {
                si_blit_decompress_color(ctx, rtex, level, level,
-                                        first_layer, last_layer);
+                                        first_layer, last_layer, false);
        }
 }
 
@@ -656,6 +747,14 @@ static bool do_hardware_msaa_resolve(struct pipe_context *ctx,
        enum pipe_format format = int_to_norm_format(info->dst.format);
        unsigned sample_mask = ~0;
 
+       /* Hardware MSAA resolve doesn't work if SPI format = NORM16_ABGR and
+        * the format is R16G16. Use R16A16, which does work.
+        */
+       if (format == PIPE_FORMAT_R16G16_UNORM)
+               format = PIPE_FORMAT_R16A16_UNORM;
+       if (format == PIPE_FORMAT_R16G16_SNORM)
+               format = PIPE_FORMAT_R16A16_SNORM;
+
        if (info->src.resource->nr_samples > 1 &&
            info->dst.resource->nr_samples <= 1 &&
            util_max_layer(info->src.resource, 0) == 0 &&
@@ -680,7 +779,7 @@ static bool do_hardware_msaa_resolve(struct pipe_context *ctx,
            dst->surface.level[info->dst.level].mode >= RADEON_SURF_MODE_1D &&
            !(dst->surface.flags & RADEON_SURF_SCANOUT) &&
            (!dst->cmask.size || !dst->dirty_level_mask) && /* dst cannot be fast-cleared */
-           !dst->dcc_buffer) {
+           !dst->dcc_offset) {
                si_blitter_begin(ctx, SI_COLOR_RESOLVE |
                                 (info->render_condition_enable ? 0 : SI_DISABLE_RENDER_COND));
                util_blitter_custom_resolve_color(sctx->blitter,
@@ -729,12 +828,23 @@ static void si_flush_resource(struct pipe_context *ctx,
 
        assert(res->target != PIPE_BUFFER);
 
-       if (!rtex->is_depth && rtex->cmask.size) {
+       if (!rtex->is_depth && (rtex->cmask.size || rtex->dcc_offset)) {
                si_blit_decompress_color(ctx, rtex, 0, res->last_level,
-                                        0, util_max_layer(res, 0));
+                                        0, util_max_layer(res, 0), false);
        }
 }
 
+static void si_decompress_dcc(struct pipe_context *ctx,
+                             struct r600_texture *rtex)
+{
+       if (!rtex->dcc_offset)
+               return;
+
+       si_blit_decompress_color(ctx, rtex, 0, rtex->resource.b.b.last_level,
+                                0, util_max_layer(&rtex->resource.b.b, 0),
+                                true);
+}
+
 static void si_pipe_clear_buffer(struct pipe_context *ctx,
                                 struct pipe_resource *dst,
                                 unsigned offset, unsigned size,
@@ -804,4 +914,5 @@ void si_init_blit_functions(struct si_context *sctx)
        sctx->b.b.blit = si_blit;
        sctx->b.b.flush_resource = si_flush_resource;
        sctx->b.blit_decompress_depth = si_blit_decompress_depth;
+       sctx->b.decompress_dcc = si_decompress_dcc;
 }