freedreno: update generated headers
[mesa.git] / src / gallium / drivers / radeon / r600_texture.c
index 75e8c77cfd25dc6201ab7a9eb851a4c8984a91d0..4d72b86f4e47fcad460d856771652d1b5a75c19a 100644 (file)
@@ -193,8 +193,8 @@ static unsigned r600_texture_get_offset(struct r600_common_screen *rscreen,
                /* Each texture is an array of slices. Each slice is an array
                 * of mipmap levels. */
                return box->z * rtex->surface.u.gfx9.surf_slice_size +
-                      ((rtex->surface.u.gfx9.surf_ymip_offset[level] +
-                        box->y / rtex->surface.blk_h) *
+                      rtex->surface.u.gfx9.offset[level] +
+                      (box->y / rtex->surface.blk_h *
                        rtex->surface.u.gfx9.surf_pitch +
                        box->x / rtex->surface.blk_w) * rtex->surface.bpe;
        } else {
@@ -389,7 +389,7 @@ static bool r600_can_disable_dcc(struct r600_texture *rtex)
 {
        /* We can't disable DCC if it can be written by another process. */
        return rtex->dcc_offset &&
-              (!rtex->resource.is_shared ||
+              (!rtex->resource.b.is_shared ||
                !(rtex->resource.external_usage & PIPE_HANDLE_USAGE_WRITE));
 }
 
@@ -466,7 +466,7 @@ static void r600_degrade_tile_mode_to_linear(struct r600_common_context *rctx,
        if (rctx->chip_class < SI)
                return;
 
-       if (rtex->resource.is_shared ||
+       if (rtex->resource.b.is_shared ||
            rtex->surface.is_linear)
                return;
 
@@ -530,14 +530,16 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                                        unsigned usage)
 {
        struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
-       struct r600_common_context *rctx = (struct r600_common_context*)
-                                          (ctx ? ctx : rscreen->aux_context);
+       struct r600_common_context *rctx;
        struct r600_resource *res = (struct r600_resource*)resource;
        struct r600_texture *rtex = (struct r600_texture*)resource;
        struct radeon_bo_metadata metadata;
        bool update_metadata = false;
        unsigned stride, offset, slice_size;
 
+       ctx = threaded_context_unwrap_sync(ctx);
+       rctx = (struct r600_common_context*)(ctx ? ctx : rscreen->aux_context);
+
        /* This is not supported now, but it might be required for OpenCL
         * interop in the future.
         */
@@ -568,7 +570,7 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                }
 
                /* Set metadata. */
-               if (!res->is_shared || update_metadata) {
+               if (!res->b.is_shared || update_metadata) {
                        r600_texture_init_metadata(rscreen, rtex, &metadata);
                        if (rscreen->query_opaque_metadata)
                                rscreen->query_opaque_metadata(rscreen, rtex,
@@ -578,7 +580,7 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                }
        }
 
-       if (res->is_shared) {
+       if (res->b.is_shared) {
                /* USAGE_EXPLICIT_FLUSH must be cleared if at least one user
                 * doesn't set it.
                 */
@@ -586,7 +588,7 @@ static boolean r600_texture_get_handle(struct pipe_screen* screen,
                if (!(usage & PIPE_HANDLE_USAGE_EXPLICIT_FLUSH))
                        res->external_usage &= ~PIPE_HANDLE_USAGE_EXPLICIT_FLUSH;
        } else {
-               res->is_shared = true;
+               res->b.is_shared = true;
                res->external_usage = usage;
        }
 
@@ -1430,7 +1432,7 @@ static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
        if (!rtex)
                return NULL;
 
-       rtex->resource.is_shared = true;
+       rtex->resource.b.is_shared = true;
        rtex->resource.external_usage = usage;
 
        if (rscreen->apply_opaque_metadata)
@@ -1438,9 +1440,7 @@ static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen
 
        /* Validate that addrlib arrived at the same surface parameters. */
        if (rscreen->chip_class >= GFX9) {
-               struct gfx9_surf_layout *gfx9 = &surface.u.gfx9;
-
-               assert(metadata.u.gfx9.swizzle_mode == gfx9->surf.swizzle_mode);
+               assert(metadata.u.gfx9.swizzle_mode == surface.u.gfx9.surf.swizzle_mode);
        }
 
        return &rtex->resource.b.b;
@@ -1550,7 +1550,7 @@ static bool r600_can_invalidate_texture(struct r600_common_screen *rscreen,
 {
        /* r600g doesn't react to dirty_tex_descriptor_counter */
        return rscreen->chip_class >= SI &&
-               !rtex->resource.is_shared &&
+               !rtex->resource.b.is_shared &&
                !(transfer_usage & PIPE_TRANSFER_READ) &&
                rtex->resource.b.b.last_level == 0 &&
                util_texrange_covers_whole_level(&rtex->resource.b.b, 0,
@@ -1625,9 +1625,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                 * Use the staging texture for uploads if the underlying BO
                 * is busy.
                 */
-               /* TODO: Linear CPU mipmap addressing is broken on GFX9: */
-               if (!rtex->surface.is_linear ||
-                   (rctx->chip_class == GFX9 && level))
+               if (!rtex->surface.is_linear)
                        use_staging_texture = true;
                else if (usage & PIPE_TRANSFER_READ)
                        use_staging_texture =
@@ -1650,10 +1648,10 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
        trans = CALLOC_STRUCT(r600_transfer);
        if (!trans)
                return NULL;
-       pipe_resource_reference(&trans->transfer.resource, texture);
-       trans->transfer.level = level;
-       trans->transfer.usage = usage;
-       trans->transfer.box = *box;
+       pipe_resource_reference(&trans->b.b.resource, texture);
+       trans->b.b.level = level;
+       trans->b.b.usage = usage;
+       trans->b.b.box = *box;
 
        if (rtex->is_depth) {
                struct r600_texture *staging_depth;
@@ -1695,8 +1693,8 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
 
                        /* Just get the strides. */
                        r600_texture_get_offset(rctx->screen, staging_depth, level, NULL,
-                                               &trans->transfer.stride,
-                                               &trans->transfer.layer_stride);
+                                               &trans->b.b.stride,
+                                               &trans->b.b.layer_stride);
                } else {
                        /* XXX: only readback the rectangle which is being mapped? */
                        /* XXX: when discard is true, no need to read back from depth texture */
@@ -1713,8 +1711,8 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
 
                        offset = r600_texture_get_offset(rctx->screen, staging_depth,
                                                         level, box,
-                                                        &trans->transfer.stride,
-                                                        &trans->transfer.layer_stride);
+                                                        &trans->b.b.stride,
+                                                        &trans->b.b.layer_stride);
                }
 
                trans->staging = (struct r600_resource*)staging_depth;
@@ -1739,8 +1737,8 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
 
                /* Just get the strides. */
                r600_texture_get_offset(rctx->screen, staging, 0, NULL,
-                                       &trans->transfer.stride,
-                                       &trans->transfer.layer_stride);
+                                       &trans->b.b.stride,
+                                       &trans->b.b.layer_stride);
 
                if (usage & PIPE_TRANSFER_READ)
                        r600_copy_to_staging_texture(ctx, trans);
@@ -1751,8 +1749,8 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
        } else {
                /* the resource is mapped directly */
                offset = r600_texture_get_offset(rctx->screen, rtex, level, box,
-                                                &trans->transfer.stride,
-                                                &trans->transfer.layer_stride);
+                                                &trans->b.b.stride,
+                                                &trans->b.b.layer_stride);
                buf = &rtex->resource;
        }
 
@@ -1762,7 +1760,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                return NULL;
        }
 
-       *ptransfer = &trans->transfer;
+       *ptransfer = &trans->b.b;
        return map + offset;
 }
 
@@ -1905,6 +1903,18 @@ bool vi_dcc_formats_compatible(enum pipe_format format1,
               type1 == type2;
 }
 
+bool vi_dcc_formats_are_incompatible(struct pipe_resource *tex,
+                                    unsigned level,
+                                    enum pipe_format view_format)
+{
+       struct r600_texture *rtex = (struct r600_texture *)tex;
+
+       return vi_dcc_enabled(rtex, level) &&
+              !vi_dcc_formats_compatible(tex->format, view_format);
+}
+
+/* This can't be merged with the above function, because
+ * vi_dcc_formats_compatible should be called only when DCC is enabled. */
 void vi_disable_dcc_if_incompatible_format(struct r600_common_context *rctx,
                                           struct pipe_resource *tex,
                                           unsigned level,
@@ -1924,7 +1934,6 @@ struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
                                                unsigned width0, unsigned height0,
                                                unsigned width, unsigned height)
 {
-       struct r600_common_context *rctx = (struct r600_common_context*)pipe;
        struct r600_surface *surface = CALLOC_STRUCT(r600_surface);
 
        if (!surface)
@@ -1944,11 +1953,10 @@ struct pipe_surface *r600_create_surface_custom(struct pipe_context *pipe,
        surface->width0 = width0;
        surface->height0 = height0;
 
-       if (texture->target != PIPE_BUFFER)
-               vi_disable_dcc_if_incompatible_format(rctx, texture,
-                                                     templ->u.tex.level,
-                                                     templ->format);
-
+       surface->dcc_incompatible =
+               texture->target != PIPE_BUFFER &&
+               vi_dcc_formats_are_incompatible(texture, templ->u.tex.level,
+                                               templ->format);
        return &surface->base;
 }
 
@@ -2249,7 +2257,7 @@ static void vi_separate_dcc_try_enable(struct r600_common_context *rctx,
        /* The intent is to use this with shared displayable back buffers,
         * but it's not strictly limited only to them.
         */
-       if (!tex->resource.is_shared ||
+       if (!tex->resource.b.is_shared ||
            !(tex->resource.external_usage & PIPE_HANDLE_USAGE_EXPLICIT_FLUSH) ||
            tex->resource.b.b.target != PIPE_TEXTURE_2D ||
            tex->resource.b.b.last_level > 0 ||
@@ -2516,7 +2524,7 @@ void vi_dcc_clear_level(struct r600_common_context *rctx,
 static void si_set_optimal_micro_tile_mode(struct r600_common_screen *rscreen,
                                           struct r600_texture *rtex)
 {
-       if (rtex->resource.is_shared ||
+       if (rtex->resource.b.is_shared ||
            rtex->resource.b.b.nr_samples <= 1 ||
            rtex->surface.micro_tile_mode == rtex->last_msaa_resolve_target_micro_mode)
                return;
@@ -2633,10 +2641,6 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
        if (rctx->render_cond)
                return;
 
-       /* TODO: fix CMASK and DCC fast clear */
-       if (rctx->chip_class >= GFX9)
-               return;
-
        for (i = 0; i < fb->nr_cbufs; i++) {
                struct r600_texture *tex;
                unsigned clear_bit = PIPE_CLEAR_COLOR0 << i;
@@ -2670,7 +2674,7 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                 * because there is no way to communicate the clear color among
                 * all clients
                 */
-               if (tex->resource.is_shared &&
+               if (tex->resource.b.is_shared &&
                    !(tex->resource.external_usage & PIPE_HANDLE_USAGE_EXPLICIT_FLUSH))
                        continue;
 
@@ -2689,13 +2693,13 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                    !(rctx->screen->debug_flags & DBG_NO_DCC_FB)) {
                        vi_separate_dcc_try_enable(rctx, tex);
 
-                       /* RB+ isn't supported with a CMASK-based clear, so all
-                        * clears are considered to be hypothetically slow
+                       /* RB+ isn't supported with a CMASK clear only on Stoney,
+                        * so all clears are considered to be hypothetically slow
                         * clears, which is weighed when determining whether to
                         * enable separate DCC.
                         */
                        if (tex->dcc_gather_statistics &&
-                           rctx->screen->rbplus_allowed)
+                           rctx->family == CHIP_STONEY)
                                tex->num_slow_clears++;
                }
 
@@ -2704,6 +2708,10 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                        uint32_t reset_value;
                        bool clear_words_needed;
 
+                       /* TODO: fix DCC clear */
+                       if (rctx->chip_class >= GFX9)
+                               continue;
+
                        if (rctx->screen->debug_flags & DBG_NO_DCC_CLEAR)
                                continue;
 
@@ -2714,8 +2722,15 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
 
                        vi_dcc_clear_level(rctx, tex, 0, reset_value);
 
-                       if (clear_words_needed)
-                               tex->dirty_level_mask |= 1 << fb->cbufs[i]->u.tex.level;
+                       unsigned level_bit = 1 << fb->cbufs[i]->u.tex.level;
+                       if (clear_words_needed) {
+                               bool need_compressed_update = !tex->dirty_level_mask;
+
+                               tex->dirty_level_mask |= level_bit;
+
+                               if (need_compressed_update)
+                                       p_atomic_inc(&rctx->screen->compressed_colortex_counter);
+                       }
                        tex->separate_dcc_dirty = true;
                } else {
                        /* 128-bit formats are unusupported */
@@ -2723,8 +2738,8 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                                continue;
                        }
 
-                       /* RB+ doesn't work with CMASK fast clear. */
-                       if (rctx->screen->rbplus_allowed)
+                       /* RB+ doesn't work with CMASK fast clear on Stoney. */
+                       if (rctx->family == CHIP_STONEY)
                                continue;
 
                        /* ensure CMASK is enabled */
@@ -2738,7 +2753,12 @@ void evergreen_do_fast_color_clear(struct r600_common_context *rctx,
                                           tex->cmask.offset, tex->cmask.size, 0,
                                           R600_COHERENCY_CB_META);
 
+                       bool need_compressed_update = !tex->dirty_level_mask;
+
                        tex->dirty_level_mask |= 1 << fb->cbufs[i]->u.tex.level;
+
+                       if (need_compressed_update)
+                               p_atomic_inc(&rctx->screen->compressed_colortex_counter);
                }
 
                /* We can change the micro tile mode before a full clear. */