X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fdrivers%2Fetnaviv%2Fetnaviv_resource.c;h=e2ef97f286fa89979139ba39e080e1826d83d19a;hb=60975ebe58ddb05beebbdd3850dc9d866aee5420;hp=996232c94cd284559c0a70a2cae0615acccea1da;hpb=7c7eaaed4a8deb6bb1b0ee34b78b0228630738be;p=mesa.git diff --git a/src/gallium/drivers/etnaviv/etnaviv_resource.c b/src/gallium/drivers/etnaviv/etnaviv_resource.c index 996232c94cd..e2ef97f286f 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_resource.c +++ b/src/gallium/drivers/etnaviv/etnaviv_resource.c @@ -87,10 +87,24 @@ etna_screen_resource_alloc_ts(struct pipe_screen *pscreen, size_t rt_ts_size, ts_layer_stride; size_t ts_bits_per_tile, bytes_per_tile; uint8_t ts_mode = TS_MODE_128B; /* only used by halti5 */ + int8_t ts_compress_fmt; assert(!rsc->ts_bo); + /* pre-v4 compression is largely useless, so disable it when not wanted for MSAA + * v4 compression can be enabled everywhere without any known drawback, + * except that in-place resolve must go through a slower path + */ + ts_compress_fmt = (screen->specs.v4_compression || rsc->base.nr_samples > 1) ? + translate_ts_format(rsc->base.format) : -1; + if (screen->specs.halti >= 5) { + /* enable 256B ts mode with compression, as it improves performance + * the size of the resource might also determine if we want to use it or not + */ + if (ts_compress_fmt >= 0) + ts_mode = TS_MODE_256B; + ts_bits_per_tile = 4; bytes_per_tile = ts_mode == TS_MODE_256B ? 256 : 128; } else { @@ -121,16 +135,17 @@ etna_screen_resource_alloc_ts(struct pipe_screen *pscreen, rsc->levels[0].ts_layer_stride = ts_layer_stride; rsc->levels[0].ts_size = rt_ts_size; rsc->levels[0].ts_mode = ts_mode; + rsc->levels[0].ts_compress_fmt = ts_compress_fmt; return true; } -static boolean +static bool etna_screen_can_create_resource(struct pipe_screen *pscreen, const struct pipe_resource *templat) { struct etna_screen *screen = etna_screen(pscreen); - if (!translate_samples_to_xyscale(templat->nr_samples, NULL, NULL, NULL)) + if (!translate_samples_to_xyscale(templat->nr_samples, NULL, NULL)) return false; /* templat->bind is not set here, so we must use the minimum sizes */ @@ -158,6 +173,7 @@ setup_miptree(struct etna_resource *rsc, unsigned paddingX, unsigned paddingY, mip->width = width; mip->height = height; + mip->depth = depth; mip->padded_width = align(width * msaa_xscale, paddingX); mip->padded_height = align(height * msaa_yscale, paddingY); mip->stride = util_format_get_stride(prsc->format, mip->padded_width); @@ -188,8 +204,7 @@ static bool is_rs_align(struct etna_screen *screen, /* Create a new resource object, using the given template info */ struct pipe_resource * etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, - enum etna_resource_addressing_mode mode, uint64_t modifier, - const struct pipe_resource *templat) + uint64_t modifier, const struct pipe_resource *templat) { struct etna_screen *screen = etna_screen(pscreen); struct etna_resource *rsc; @@ -214,7 +229,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, } int msaa_xscale = 1, msaa_yscale = 1; - if (!translate_samples_to_xyscale(nr_samples, &msaa_xscale, &msaa_yscale, NULL)) { + if (!translate_samples_to_xyscale(nr_samples, &msaa_xscale, &msaa_yscale)) { /* Number of samples not supported */ return NULL; } @@ -238,8 +253,8 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, paddingY = 1; } - if (!screen->specs.use_blt && templat->target != PIPE_BUFFER) - etna_adjust_rs_align(screen->specs.pixel_pipes, NULL, &paddingY); + if (!screen->specs.use_blt && templat->target != PIPE_BUFFER && layout == ETNA_LAYOUT_LINEAR) + paddingY = align(paddingY, ETNA_RS_HEIGHT_MASK + 1); if (templat->bind & PIPE_BIND_SCANOUT && screen->ro->kms_fd >= 0) { struct pipe_resource scanout_templat = *templat; @@ -247,8 +262,10 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, struct winsys_handle handle; /* pad scanout buffer size to be compatible with the RS */ - if (!screen->specs.use_blt && modifier == DRM_FORMAT_MOD_LINEAR) - etna_adjust_rs_align(screen->specs.pixel_pipes, &paddingX, &paddingY); + if (!screen->specs.use_blt && modifier == DRM_FORMAT_MOD_LINEAR) { + paddingX = align(paddingX, ETNA_RS_WIDTH_MASK + 1); + paddingY = align(paddingY, ETNA_RS_HEIGHT_MASK + 1); + } scanout_templat.width0 = align(scanout_templat.width0, paddingX); scanout_templat.height0 = align(scanout_templat.height0, paddingY); @@ -281,9 +298,9 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, rsc->base.nr_samples = nr_samples; rsc->layout = layout; rsc->halign = halign; - rsc->addressing_mode = mode; pipe_reference_init(&rsc->base.reference, 1); + util_range_init(&rsc->valid_buffer_range); size = setup_miptree(rsc, paddingX, paddingY, msaa_xscale, msaa_yscale); @@ -304,6 +321,7 @@ etna_resource_alloc(struct pipe_screen *pscreen, unsigned layout, memset(map, 0, size); } + mtx_init(&rsc->lock, mtx_recursive); rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); if (!rsc->pending_ctx) @@ -321,58 +339,38 @@ etna_resource_create(struct pipe_screen *pscreen, const struct pipe_resource *templat) { struct etna_screen *screen = etna_screen(pscreen); - - /* Figure out what tiling and address mode to use -- for now, assume that - * texture cannot be linear. there is a capability LINEAR_TEXTURE_SUPPORT - * (supported on gc880 and gc2000 at least), but not sure how it works. - * Buffers always have LINEAR layout. + unsigned layout = ETNA_LAYOUT_TILED; + + /* At this point we don't know if the resource will be used as a texture, + * render target, or both, because gallium sets the bits whenever possible + * This matters because on some GPUs (GC2000) there is no tiling that is + * compatible with both TE and PE. + * + * We expect that depth/stencil buffers will always be used by PE (rendering), + * and any other non-scanout resource will be used as a texture at some point, + * So allocate a render-compatible base buffer for scanout/depthstencil buffers, + * and a texture-compatible base buffer in other cases + * */ - unsigned layout = ETNA_LAYOUT_LINEAR; - enum etna_resource_addressing_mode mode = ETNA_ADDRESSING_MODE_TILED; - - if (etna_resource_sampler_only(templat)) { - /* The buffer is only used for texturing, so create something - * directly compatible with the sampler. Such a buffer can - * never be rendered to. */ - layout = ETNA_LAYOUT_TILED; - - if (util_format_is_compressed(templat->format)) - layout = ETNA_LAYOUT_LINEAR; - } else if (templat->target != PIPE_BUFFER) { - bool want_multitiled = false; - bool want_supertiled = screen->specs.can_supertile; - - /* When this GPU supports single-buffer rendering, don't ever enable - * multi-tiling. This replicates the blob behavior on GC3000. - */ - if (!screen->specs.single_buffer) - want_multitiled = screen->specs.pixel_pipes > 1; - - /* Keep single byte blocksized resources as tiled, since we - * are unable to use the RS blit to de-tile them. However, - * if they're used as a render target or depth/stencil, they - * must be multi-tiled for GPUs with multiple pixel pipes. - * Ignore depth/stencil here, but it is an error for a render - * target. - */ - if (util_format_get_blocksize(templat->format) == 1 && - !(templat->bind & PIPE_BIND_DEPTH_STENCIL)) { - assert(!(templat->bind & PIPE_BIND_RENDER_TARGET && want_multitiled)); - want_multitiled = want_supertiled = false; - } - - layout = ETNA_LAYOUT_BIT_TILE; - if (want_multitiled) + if (templat->bind & (PIPE_BIND_SCANOUT | PIPE_BIND_DEPTH_STENCIL)) { + if (screen->specs.pixel_pipes > 1 && !screen->specs.single_buffer) layout |= ETNA_LAYOUT_BIT_MULTI; - if (want_supertiled) + if (screen->specs.can_supertile) layout |= ETNA_LAYOUT_BIT_SUPER; + } else if (VIV_FEATURE(screen, chipMinorFeatures2, SUPERTILED_TEXTURE) && + etna_resource_hw_tileable(screen->specs.use_blt, templat)) { + layout |= ETNA_LAYOUT_BIT_SUPER; } - if (templat->target == PIPE_TEXTURE_3D) + if ((templat->bind & PIPE_BIND_LINEAR) || /* linear base requested */ + templat->target == PIPE_BUFFER || /* buffer always linear */ + /* compressed textures don't use tiling, they have their own "tiles" */ + util_format_is_compressed(templat->format)) { layout = ETNA_LAYOUT_LINEAR; + } /* modifier is only used for scanout surfaces, so safe to use LINEAR here */ - return etna_resource_alloc(pscreen, layout, mode, DRM_FORMAT_MOD_LINEAR, templat); + return etna_resource_alloc(pscreen, layout, DRM_FORMAT_MOD_LINEAR, templat); } enum modifier_priority { @@ -384,7 +382,7 @@ enum modifier_priority { MODIFIER_PRIORITY_SUPER_TILED, }; -const uint64_t priority_to_modifier[] = { +static const uint64_t priority_to_modifier[] = { [MODIFIER_PRIORITY_INVALID] = DRM_FORMAT_MOD_INVALID, [MODIFIER_PRIORITY_LINEAR] = DRM_FORMAT_MOD_LINEAR, [MODIFIER_PRIORITY_SPLIT_TILED] = DRM_FORMAT_MOD_VIVANTE_SPLIT_TILED, @@ -452,31 +450,24 @@ etna_resource_create_modifiers(struct pipe_screen *pscreen, */ tmpl.bind |= PIPE_BIND_SCANOUT; - return etna_resource_alloc(pscreen, modifier_to_layout(modifier), - ETNA_ADDRESSING_MODE_TILED, modifier, &tmpl); + return etna_resource_alloc(pscreen, modifier_to_layout(modifier), modifier, &tmpl); } static void etna_resource_changed(struct pipe_screen *pscreen, struct pipe_resource *prsc) { - struct etna_resource *res = etna_resource(prsc); - - if (res->external) - etna_resource(res->external)->seqno++; - else - res->seqno++; + etna_resource(prsc)->seqno++; } static void etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) { - struct etna_screen *screen = etna_screen(pscreen); struct etna_resource *rsc = etna_resource(prsc); - mtx_lock(&screen->lock); - _mesa_set_remove_key(screen->used_resources, rsc); + mtx_lock(&rsc->lock); + assert(!_mesa_set_next_entry(rsc->pending_ctx, NULL)); _mesa_set_destroy(rsc->pending_ctx, NULL); - mtx_unlock(&screen->lock); + mtx_unlock(&rsc->lock); if (rsc->bo) etna_bo_del(rsc->bo); @@ -487,12 +478,16 @@ etna_resource_destroy(struct pipe_screen *pscreen, struct pipe_resource *prsc) if (rsc->scanout) renderonly_scanout_destroy(rsc->scanout, etna_screen(pscreen)->ro); + util_range_destroy(&rsc->valid_buffer_range); + pipe_resource_reference(&rsc->texture, NULL); - pipe_resource_reference(&rsc->external, NULL); + pipe_resource_reference(&rsc->render, NULL); for (unsigned i = 0; i < ETNA_NUM_LOD; i++) FREE(rsc->levels[i].patch_offsets); + mtx_destroy(&rsc->lock); + FREE(rsc); } @@ -505,7 +500,6 @@ etna_resource_from_handle(struct pipe_screen *pscreen, struct etna_resource *rsc; struct etna_resource_level *level; struct pipe_resource *prsc; - struct pipe_resource *ptiled = NULL; DBG("target=%d, format=%s, %ux%ux%u, array_size=%u, last_level=%u, " "nr_samples=%u, usage=%u, bind=%x, flags=%x", @@ -523,6 +517,7 @@ etna_resource_from_handle(struct pipe_screen *pscreen, *prsc = *tmpl; pipe_reference_init(&prsc->reference, 1); + util_range_init(&rsc->valid_buffer_range); prsc->screen = pscreen; rsc->bo = etna_screen_bo_from_handle(pscreen, handle, &level->stride); @@ -532,11 +527,11 @@ etna_resource_from_handle(struct pipe_screen *pscreen, rsc->seqno = 1; rsc->layout = modifier_to_layout(handle->modifier); rsc->halign = TEXTURE_HALIGN_FOUR; - rsc->addressing_mode = ETNA_ADDRESSING_MODE_TILED; - level->width = tmpl->width0; level->height = tmpl->height0; + level->depth = tmpl->depth0; + level->offset = handle->offset; /* Determine padding of the imported resource. */ unsigned paddingX = 0, paddingY = 0; @@ -544,8 +539,8 @@ etna_resource_from_handle(struct pipe_screen *pscreen, is_rs_align(screen, tmpl), &paddingX, &paddingY, &rsc->halign); - if (!screen->specs.use_blt) - etna_adjust_rs_align(screen->specs.pixel_pipes, NULL, &paddingY); + if (!screen->specs.use_blt && rsc->layout == ETNA_LAYOUT_LINEAR) + paddingY = align(paddingY, ETNA_RS_HEIGHT_MASK + 1); level->padded_width = align(level->width, paddingX); level->padded_height = align(level->height, paddingY); @@ -569,45 +564,21 @@ etna_resource_from_handle(struct pipe_screen *pscreen, goto fail; } + mtx_init(&rsc->lock, mtx_recursive); rsc->pending_ctx = _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); if (!rsc->pending_ctx) goto fail; - if (rsc->layout == ETNA_LAYOUT_LINEAR) { - /* - * Both sampler and pixel pipes can't handle linear, create a compatible - * base resource, where we can attach the imported buffer as an external - * resource. - */ - struct pipe_resource tiled_templat = *tmpl; - - /* - * Remove BIND_SCANOUT to avoid recursion, as etna_resource_create uses - * this function to import the scanout buffer and get a tiled resource. - */ - tiled_templat.bind &= ~PIPE_BIND_SCANOUT; - - ptiled = etna_resource_create(pscreen, &tiled_templat); - if (!ptiled) - goto fail; - - etna_resource(ptiled)->external = prsc; - - return ptiled; - } - return prsc; fail: etna_resource_destroy(pscreen, prsc); - if (ptiled) - etna_resource_destroy(pscreen, ptiled); return NULL; } -static boolean +static bool etna_resource_get_handle(struct pipe_screen *pscreen, struct pipe_context *pctx, struct pipe_resource *prsc, @@ -617,13 +588,6 @@ etna_resource_get_handle(struct pipe_screen *pscreen, /* Scanout is always attached to the base resource */ struct renderonly_scanout *scanout = rsc->scanout; - /* - * External resources are preferred, so a import->export chain of - * render/sampler incompatible buffers yield the same handle. - */ - if (rsc->external) - rsc = etna_resource(rsc->external); - handle->stride = rsc->levels[0].stride; handle->offset = rsc->levels[0].offset; handle->modifier = layout_to_modifier(rsc->layout); @@ -632,16 +596,16 @@ etna_resource_get_handle(struct pipe_screen *pscreen, return etna_bo_get_name(rsc->bo, &handle->handle) == 0; } else if (handle->type == WINSYS_HANDLE_TYPE_KMS) { if (renderonly_get_handle(scanout, handle)) { - return TRUE; + return true; } else { handle->handle = etna_bo_handle(rsc->bo); - return TRUE; + return true; } } else if (handle->type == WINSYS_HANDLE_TYPE_FD) { handle->handle = etna_bo_dmabuf(rsc->bo); - return TRUE; + return true; } else { - return FALSE; + return false; } } @@ -649,47 +613,78 @@ void etna_resource_used(struct etna_context *ctx, struct pipe_resource *prsc, enum etna_resource_status status) { - struct etna_screen *screen = ctx->screen; + struct pipe_resource *referenced = NULL; struct etna_resource *rsc; if (!prsc) return; + mtx_lock(&ctx->lock); + rsc = etna_resource(prsc); +again: + mtx_lock(&rsc->lock); + + set_foreach(rsc->pending_ctx, entry) { + struct etna_context *extctx = (struct etna_context *)entry->key; + struct pipe_context *pctx = &extctx->base; + bool need_flush = false; + + if (mtx_trylock(&extctx->lock) != thrd_success) { + /* + * The other context could be locked in etna_flush() and + * stuck waiting for the resource lock, so release the + * resource lock here, let etna_flush() finish, and try + * again. + */ + mtx_unlock(&rsc->lock); + thrd_yield(); + goto again; + } - mtx_lock(&screen->lock); + set_foreach(extctx->used_resources_read, entry2) { + struct etna_resource *rsc2 = (struct etna_resource *)entry2->key; + if (ctx == extctx || rsc2 != rsc) + continue; - /* - * if we are pending read or write by any other context or - * if reading a resource pending a write, then - * flush all the contexts to maintain coherency - */ - if (((status & ETNA_PENDING_WRITE) && rsc->status) || - ((status & ETNA_PENDING_READ) && (rsc->status & ETNA_PENDING_WRITE))) { - set_foreach(rsc->pending_ctx, entry) { - struct etna_context *extctx = (struct etna_context *)entry->key; - struct pipe_context *pctx = &extctx->base; + if (status & ETNA_PENDING_WRITE) { + need_flush = true; + break; + } + } + + if (need_flush) { + pctx->flush(pctx, NULL, 0); + mtx_unlock(&extctx->lock); + continue; + } - if (extctx == ctx) + set_foreach(extctx->used_resources_write, entry2) { + struct etna_resource *rsc2 = (struct etna_resource *)entry2->key; + if (ctx == extctx || rsc2 != rsc) continue; - pctx->flush(pctx, NULL, 0); - /* It's safe to clear the status here. If we need to flush it means - * either another context had the resource in exclusive (write) use, - * or we transition the resource to exclusive use in our context. - * In both cases the new status accurately reflects the resource use - * after the flush. - */ - rsc->status = 0; + need_flush = true; + break; } + + if (need_flush) + pctx->flush(pctx, NULL, 0); + + mtx_unlock(&extctx->lock); } - rsc->status |= status; + rsc->status = status; - _mesa_set_add(screen->used_resources, rsc); - _mesa_set_add(rsc->pending_ctx, ctx); + if (!_mesa_set_search(rsc->pending_ctx, ctx)) { + pipe_resource_reference(&referenced, prsc); + _mesa_set_add((status & ETNA_PENDING_READ) ? + ctx->used_resources_read : ctx->used_resources_write, rsc); + _mesa_set_add(rsc->pending_ctx, ctx); + } - mtx_unlock(&screen->lock); + mtx_unlock(&rsc->lock); + mtx_unlock(&ctx->lock); } bool