&paddingY, &halign);
assert(paddingX && paddingY);
- if (templat->bind != PIPE_BUFFER) {
- unsigned min_paddingY = 4 * screen->specs.pixel_pipes;
- if (paddingY < min_paddingY)
- paddingY = min_paddingY;
- }
+ if (templat->target != PIPE_BUFFER)
+ etna_adjust_rs_align(screen->specs.pixel_pipes, NULL, &paddingY);
struct etna_resource *rsc = CALLOC_STRUCT(etna_resource);
struct etna_bo *bo = etna_bo_new(screen->dev, size, flags);
if (unlikely(bo == NULL)) {
BUG("Problem allocating video memory for resource");
- return NULL;
+ goto free_rsc;
}
rsc->bo = bo;
rsc->ts_bo = 0; /* TS is only created when first bound to surface */
- if (templat->bind & PIPE_BIND_SCANOUT)
- rsc->scanout = renderonly_scanout_for_resource(&rsc->base, screen->ro);
+ if (templat->bind & PIPE_BIND_SCANOUT) {
+ struct winsys_handle handle;
+ rsc->scanout = renderonly_scanout_for_resource(&rsc->base, screen->ro,
+ &handle);
+ if (!rsc->scanout)
+ goto free_rsc;
+
+ rsc->external = pscreen->resource_from_handle(pscreen, &rsc->base,
+ &handle,
+ PIPE_HANDLE_USAGE_WRITE);
+ close(handle.handle);
+ if (!rsc->external)
+ goto free_rsc;
+ }
if (DBG_ENABLED(ETNA_DBG_ZERO)) {
void *map = etna_bo_map(bo);
}
return &rsc->base;
+
+free_rsc:
+ FREE(rsc);
+ return NULL;
}
static struct pipe_resource *
{
struct etna_screen *screen = etna_screen(pscreen);
- /* Figure out what tiling to use -- for now, assume that textures cannot be
- * supertiled, and cannot be linear.
- * There is a feature flag SUPERTILED_TEXTURE (not supported on any known hw)
- * that may allow this, as well
- * as LINEAR_TEXTURE_SUPPORT (supported on gc880 and gc2000 at least), but
- * not sure how it works.
+ /* Figure out what tiling 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_LINEAR;
layout = ETNA_LAYOUT_LINEAR;
} else if (templat->target != PIPE_BUFFER) {
bool want_multitiled = false;
- bool want_supertiled = screen->specs.can_supertile && !DBG_ENABLED(ETNA_DBG_NO_SUPERTILE);
+ 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.
{
struct etna_resource *res = etna_resource(prsc);
- /* Make sure texture is older than the imported renderable buffer,
- * so etna_update_sampler_source will copy the pixel data again.
- */
- if (res->texture)
- etna_resource(res->texture)->seqno = res->seqno - 1;
+ res->seqno++;
}
static void
etna_bo_del(rsc->ts_bo);
if (rsc->scanout)
- renderonly_scanout_destroy(rsc->scanout);
+ renderonly_scanout_destroy(rsc->scanout, etna_screen(pscreen)->ro);
list_delinit(&rsc->list);
pipe_resource_reference(&rsc->texture, NULL);
+ pipe_resource_reference(&rsc->external, NULL);
FREE(rsc);
}
struct winsys_handle *handle, unsigned usage)
{
struct etna_screen *screen = etna_screen(pscreen);
- struct etna_resource *rsc = CALLOC_STRUCT(etna_resource);
- struct etna_resource_level *level = &rsc->levels[0];
- struct pipe_resource *prsc = &rsc->base;
+ 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, "
tmpl->height0, tmpl->depth0, tmpl->array_size, tmpl->last_level,
tmpl->nr_samples, tmpl->usage, tmpl->bind, tmpl->flags);
+ rsc = CALLOC_STRUCT(etna_resource);
if (!rsc)
return NULL;
+ level = &rsc->levels[0];
+ prsc = &rsc->base;
+
*prsc = *tmpl;
pipe_reference_init(&prsc->reference, 1);
/* We will be using the RS to copy with this resource, so we must
* ensure that it is appropriately aligned for the RS requirements. */
- unsigned paddingX = ETNA_RS_WIDTH_MASK + 1;
- unsigned paddingY = (ETNA_RS_HEIGHT_MASK + 1) * screen->specs.pixel_pipes;
+ level->padded_width = level->width;
+ level->padded_height = level->height;
+ etna_adjust_rs_align(&level->padded_width, &level->padded_height);
- level->padded_width = align(level->width, paddingX);
- level->padded_height = align(level->height, paddingY);
+ level->layer_stride = level->stride * util_format_get_nblocksy(prsc->format,
+ level->padded_height);
/* The DDX must give us a BO which conforms to our padding size.
* The stride of the BO must be greater or equal to our padded
/* Render targets are linear in Xorg but must be tiled
* here. It would be nice if dri_drawable_get_format()
* set scanout for these buffers too. */
- struct etna_resource *tiled;
ptiled = etna_resource_create(pscreen, tmpl);
if (!ptiled)
goto fail;
- tiled = etna_resource(ptiled);
- tiled->scanout = renderonly_scanout_for_prime(prsc, screen->ro);
- if (!tiled->scanout)
- goto fail;
+ etna_resource(ptiled)->external = prsc;
return ptiled;
}
struct winsys_handle *handle, unsigned usage)
{
struct etna_resource *rsc = etna_resource(prsc);
+ /* 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);
- if (renderonly_get_handle(rsc->scanout, handle))
+ if (handle->type == DRM_API_HANDLE_TYPE_KMS &&
+ renderonly_get_handle(scanout, handle))
return TRUE;
return etna_screen_bo_get_handle(pscreen, rsc->bo, rsc->levels[0].stride,
rsc->pending_ctx = ctx;
}
-void
-etna_resource_wait(struct pipe_context *pctx, struct etna_resource *rsc)
-{
- if (rsc->status & ETNA_PENDING_WRITE) {
- struct pipe_fence_handle *fence;
- struct pipe_screen *pscreen = pctx->screen;
-
- pctx->flush(pctx, &fence, 0);
-
- if (!pscreen->fence_finish(pscreen, pctx, fence, 5000000000ULL))
- BUG("fence timed out (hung GPU?)");
-
- pscreen->fence_reference(pscreen, &fence, NULL);
- }
-}
-
void
etna_resource_screen_init(struct pipe_screen *pscreen)
{