return false;
}
-/* AFBC is enabled on a per-resource basis (AFBC enabling is theoretically
- * indepdent between color buffers and depth/stencil). To enable, we allocate
- * the AFBC metadata buffer and mark that it is enabled. We do -not- actually
- * edit the fragment job here. This routine should be called ONCE per
- * AFBC-compressed buffer, rather than on every frame. */
-
-void
-panfrost_enable_afbc(struct panfrost_context *ctx, struct panfrost_resource *rsrc, bool ds)
+unsigned
+panfrost_afbc_header_size(unsigned width, unsigned height)
{
- struct pipe_context *gallium = (struct pipe_context *) ctx;
- struct panfrost_screen *screen = pan_screen(gallium->screen);
-
- unsigned width = rsrc->base.width0;
- unsigned height = rsrc->base.height0;
- unsigned bytes_per_pixel = util_format_get_blocksize(rsrc->base.format);
-
/* Align to tile */
unsigned aligned_width = ALIGN(width, AFBC_TILE_WIDTH);
unsigned aligned_height = ALIGN(height, AFBC_TILE_HEIGHT);
unsigned tile_count_y = aligned_height / AFBC_TILE_HEIGHT;
unsigned tile_count = tile_count_x * tile_count_y;
+ /* Multiply to find the header size */
unsigned header_bytes = tile_count * AFBC_HEADER_BYTES_PER_TILE;
- unsigned header_size = ALIGN(header_bytes, AFBC_CACHE_ALIGN);
-
- /* The stride is a normal stride, but aligned */
- unsigned unaligned_stride = aligned_width * bytes_per_pixel;
- unsigned stride = ALIGN(unaligned_stride, AFBC_CACHE_ALIGN);
-
- /* Compute the entire buffer size */
- unsigned body_size = stride * aligned_height;
- unsigned buffer_size = header_size + body_size;
-
- /* Allocate the AFBC slab itself, large enough to hold the above */
- panfrost_drm_allocate_slab(screen, &rsrc->bo->afbc_slab,
- ALIGN(buffer_size, 4096) / 4096,
- true, 0, 0, 0);
-
- /* Compressed textured reads use a tagged pointer to the metadata */
- rsrc->bo->layout = PAN_AFBC;
- rsrc->bo->gpu = rsrc->bo->afbc_slab.gpu | (ds ? 0 : 1);
- rsrc->bo->cpu = rsrc->bo->afbc_slab.cpu;
- rsrc->bo->gem_handle = rsrc->bo->afbc_slab.gem_handle;
- rsrc->bo->afbc_metadata_size = header_size;
+
+ /* Align and go */
+ return ALIGN(header_bytes, AFBC_CACHE_ALIGN);
+
}
unsigned level_offset = rsrc->bo->slices[level].offset;
unsigned face_offset = face * rsrc->bo->cubemap_stride;
- return rsrc->bo->gpu + level_offset + face_offset;
+ /* Lower-bit is set when sampling from colour AFBC */
+ bool is_afbc = rsrc->bo->layout == PAN_AFBC;
+ bool is_zs = rsrc->base.bind & PIPE_BIND_DEPTH_STENCIL;
+ unsigned afbc_bit = (is_afbc && !is_zs) ? 1 : 0;
+
+ return rsrc->bo->gpu + level_offset + face_offset + afbc_bit;
}
ctx->vt_framebuffer_mfbd = panfrost_emit_mfbd(ctx, ~0);
panfrost_attach_vt_framebuffer(ctx);
-
- struct panfrost_resource *tex = ((struct panfrost_resource *) ctx->pipe_framebuffer.cbufs[i]->texture);
- enum pipe_format format = ctx->pipe_framebuffer.cbufs[i]->format;
-
- bool can_afbc = panfrost_format_supports_afbc(format);
- bool is_scanout = panfrost_is_scanout(ctx);
-
- if (!is_scanout && tex->bo->layout != PAN_AFBC && can_afbc)
- panfrost_enable_afbc(ctx, tex, false);
-
- if (!is_scanout && !tex->bo->has_checksum)
- panfrost_enable_checksum(ctx, tex);
}
{
ctx->vt_framebuffer_mfbd = panfrost_emit_mfbd(ctx, ~0);
panfrost_attach_vt_framebuffer(ctx);
-
- struct panfrost_resource *tex = pan_resource(zb->texture);
- bool can_afbc = panfrost_format_supports_afbc(zb->format);
- bool is_scanout = panfrost_is_scanout(ctx);
-
- if (!is_scanout && tex->bo->layout != PAN_AFBC && can_afbc)
- panfrost_enable_afbc(ctx, tex, true);
}
}
}
rt->framebuffer = rsrc->bo->gpu + offset;
rt->framebuffer_stride = stride;
} else if (rsrc->bo->layout == PAN_AFBC) {
- assert(level == 0);
- rt->afbc.metadata = rsrc->bo->afbc_slab.gpu;
- rt->afbc.stride = 0;
- rt->afbc.unk = 0x30009;
-
rt->format.block = MALI_MFBD_BLOCK_AFBC;
- mali_ptr afbc_main = rsrc->bo->afbc_slab.gpu + rsrc->bo->afbc_metadata_size;
- rt->framebuffer = afbc_main;
+ mali_ptr base = rsrc->bo->gpu + offset;
+ unsigned header_size = rsrc->bo->slices[level].header_size;
+
+ rt->framebuffer = base + header_size;
+ rt->afbc.metadata = base;
+ rt->afbc.stride = 0;
+ rt->afbc.unk = 0x30009;
/* TODO: Investigate shift */
rt->framebuffer_stride = stride << 1;
unsigned offset = rsrc->bo->slices[level].offset;
if (rsrc->bo->layout == PAN_AFBC) {
- assert(level == 0);
+ mali_ptr base = rsrc->bo->gpu + offset;
+ unsigned header_size = rsrc->bo->slices[level].header_size;
+
fb->mfbd_flags |= MALI_MFBD_EXTRA;
fbx->flags =
MALI_EXTRA_ZS |
0x1; /* unknown */
- fbx->ds_afbc.depth_stencil_afbc_metadata = rsrc->bo->afbc_slab.gpu;
+ fbx->ds_afbc.depth_stencil = base + header_size;
+ fbx->ds_afbc.depth_stencil_afbc_metadata = base;
fbx->ds_afbc.depth_stencil_afbc_stride = 0;
- fbx->ds_afbc.depth_stencil = rsrc->bo->afbc_slab.gpu + rsrc->bo->afbc_metadata_size;
-
fbx->ds_afbc.zero1 = 0x10009;
fbx->ds_afbc.padding = 0x1000;
} else if (rsrc->bo->layout == PAN_LINEAR) {
bool renderable = tmpl->bind &
(PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
+ bool afbc = bo->layout == PAN_AFBC;
bool tiled = bo->layout == PAN_TILED;
bool should_align = renderable || tiled;
if (l == 0)
size_2d = slice_one_size;
+ /* Compute AFBC sizes if necessary */
+ if (afbc) {
+ slice->header_size =
+ panfrost_afbc_header_size(width, height);
+
+ offset += slice->header_size;
+ }
+
offset += slice_full_size;
width = u_minify(width, 1);
panfrost_setup_slices(template, bo);
- if (bo->layout == PAN_TILED || bo->layout == PAN_LINEAR) {
- struct panfrost_memory mem;
+ struct panfrost_memory mem;
- panfrost_drm_allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
+ panfrost_drm_allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
- bo->cpu = mem.cpu;
- bo->gpu = mem.gpu;
- bo->gem_handle = mem.gem_handle;
- }
+ bo->cpu = mem.cpu;
+ bo->gpu = mem.gpu;
+ bo->gem_handle = mem.gem_handle;
return bo;
}
static void
panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *bo)
{
- if ((bo->layout == PAN_LINEAR || bo->layout == PAN_TILED) &&
- !bo->imported) {
+ if (!bo->imported) {
struct panfrost_memory mem = {
.cpu = bo->cpu,
.gpu = bo->gpu,
panfrost_drm_free_slab(screen, &mem);
}
- if (bo->layout == PAN_AFBC) {
- /* TODO */
- DBG("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size);
- }
-
if (bo->has_checksum) {
struct panfrost_memory mem = {
.cpu = bo->checksum_slab.cpu,
unsigned offset;
unsigned stride;
+ /* If there is a header preceding each slice, how big is that header?
+ * Used for AFBC */
+ unsigned header_size;
+
/* Has anything been written to this slice? */
bool initialized;
};
/* Internal layout (tiled?) */
enum panfrost_memory_layout layout;
- /* If AFBC is enabled for this resource, we lug around an AFBC
- * metadata buffer as well. The actual AFBC resource is also in
- * afbc_slab (only defined for AFBC) at position afbc_main_offset
- */
-
- struct panfrost_memory afbc_slab;
- int afbc_metadata_size;
-
/* If transaciton elimination is enabled, we have a dedicated
* buffer for that as well. */
bool
panfrost_format_supports_afbc(enum pipe_format format);
-void
-panfrost_enable_afbc(struct panfrost_context *ctx, struct panfrost_resource *rsrc, bool ds);
+unsigned
+panfrost_afbc_header_size(unsigned width, unsigned height);
/* Blitting */