-static unsigned
-panfrost_sfbd_format_for_surface(struct pipe_surface *surf)
-{
- /* TODO */
- return 0xb84e0281; /* RGB32, no MSAA */
-}
-
-static struct mali_rt_format
-panfrost_mfbd_format_for_surface(struct pipe_surface *surf)
-{
- /* Explode details on the format */
-
- const struct util_format_description *desc =
- util_format_description(surf->texture->format);
-
- /* Fill in accordingly */
-
- struct mali_rt_format fmt = {
- .unk1 = 0x4000000,
- .unk2 = 0x1,
- .nr_channels = MALI_POSITIVE(desc->nr_channels),
- .flags = 0x444,
- .swizzle = panfrost_translate_swizzle_4(desc->swizzle),
- .unk4 = 0x8
- };
-
- return fmt;
-}
-
-static bool panfrost_is_scanout(struct panfrost_context *ctx);
-
-/* These routines link a fragment job with the bound surface, accounting for the
- * BO layout. This routine runs per-frame */
-
-static void
-panfrost_set_fragment_target_cbuf(
- struct panfrost_context *ctx,
- struct pipe_surface *surf,
- unsigned cb)
-{
- struct panfrost_resource *rsrc = pan_resource(surf->texture);
-
- signed stride =
- util_format_get_stride(surf->format, surf->texture->width0);
-
- /* First, we set the format bits */
-
- if (ctx->require_sfbd) {
- ctx->fragment_sfbd.format =
- panfrost_sfbd_format_for_surface(surf);
- } else {
- ctx->fragment_rts[cb].format =
- panfrost_mfbd_format_for_surface(surf);
- }
-
- /* Now, we set the layout specific pieces */
-
- if (rsrc->bo->layout == PAN_LINEAR) {
- mali_ptr framebuffer = rsrc->bo->gpu[0];
-
- /* The default is upside down from OpenGL's perspective. */
- if (panfrost_is_scanout(ctx)) {
- framebuffer += stride * (surf->texture->height0 - 1);
- stride = -stride;
- }
-
- if (ctx->require_sfbd) {
- ctx->fragment_sfbd.framebuffer = framebuffer;
- ctx->fragment_sfbd.stride = stride;
- } else {
- /* MFBD specifies stride in tiles */
- ctx->fragment_rts[cb].framebuffer = framebuffer;
- ctx->fragment_rts[cb].framebuffer_stride = stride / 16;
- }
- } else if (rsrc->bo->layout == PAN_AFBC) {
- /* TODO: AFBC on SFBD */
- assert(!ctx->require_sfbd);
-
- /* Enable AFBC for the render target */
- ctx->fragment_rts[cb].afbc.metadata = rsrc->bo->afbc_slab.gpu;
- ctx->fragment_rts[cb].afbc.stride = 0;
- ctx->fragment_rts[cb].afbc.unk = 0x30009;
-
- ctx->fragment_rts[cb].format.flags |= MALI_MFBD_FORMAT_AFBC;
-
- mali_ptr afbc_main = rsrc->bo->afbc_slab.gpu + rsrc->bo->afbc_metadata_size;
- ctx->fragment_rts[cb].framebuffer = afbc_main;
-
- /* TODO: Investigate shift */
- ctx->fragment_rts[cb].framebuffer_stride = stride << 1;
- } else {
- fprintf(stderr, "Invalid render layout (cbuf %d)", cb);
- assert(0);
- }
-}
-
-static void
-panfrost_set_fragment_target(struct panfrost_context *ctx)
-{
- for (int cb = 0; cb < ctx->pipe_framebuffer.nr_cbufs; ++cb) {
- struct pipe_surface *surf = ctx->pipe_framebuffer.cbufs[cb];
- panfrost_set_fragment_target_cbuf(ctx, surf, cb);
- }
-
- /* Enable depth/stencil AFBC for the framebuffer (not the render target) */
- if (ctx->pipe_framebuffer.zsbuf) {
- struct panfrost_resource *rsrc = (struct panfrost_resource *) ctx->pipe_framebuffer.zsbuf->texture;
-
- if (rsrc->bo->layout == PAN_AFBC) {
- if (ctx->require_sfbd) {
- DBG("Depth AFBC not supported on SFBD\n");
- assert(0);
- }
-
- ctx->fragment_mfbd.unk3 |= MALI_MFBD_EXTRA;
-
- ctx->fragment_extra.flags =
- MALI_EXTRA_PRESENT |
- MALI_EXTRA_AFBC |
- MALI_EXTRA_AFBC_ZS |
- MALI_EXTRA_ZS |
- 0x1; /* unknown */
-
- ctx->fragment_extra.ds_afbc.depth_stencil_afbc_metadata = rsrc->bo->afbc_slab.gpu;
- ctx->fragment_extra.ds_afbc.depth_stencil_afbc_stride = 0;
-
- ctx->fragment_extra.ds_afbc.depth_stencil = rsrc->bo->afbc_slab.gpu + rsrc->bo->afbc_metadata_size;
-
- ctx->fragment_extra.ds_afbc.zero1 = 0x10009;
- ctx->fragment_extra.ds_afbc.padding = 0x1000;
-
- ctx->fragment_mfbd.unk3 |= MALI_MFBD_DEPTH_WRITE;
- }
- }
-
- /* For the special case of a depth-only FBO, we need to attach a dummy render target */
-
- if (ctx->pipe_framebuffer.nr_cbufs == 0) {
- if (ctx->require_sfbd) {
- DBG("Depth-only FBO not supported on SFBD\n");
- assert(0);
- }
-
- struct mali_rt_format null_rt = {
- .unk1 = 0x4000000,
- .unk4 = 0x8
- };
-
- ctx->fragment_rts[0].format = null_rt;
- ctx->fragment_rts[0].framebuffer = 0;
- ctx->fragment_rts[0].framebuffer_stride = 0;
- }
-}
-