panfrost: Stop passing screen around for BO operations
Store a screen pointer in panfrost_bo so we don't have to pass a screen object to all functions manipulating the BO. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
This commit is contained in:
parent
10ce751726
commit
e15ab939fd
|
@ -71,7 +71,7 @@ panfrost_allocate_transient(struct panfrost_batch *batch, size_t sz)
|
|||
|
||||
/* Creating a BO adds a reference, and then the job adds a
|
||||
* second one. So we need to pop back one reference */
|
||||
panfrost_bo_unreference(&screen->base, bo);
|
||||
panfrost_bo_unreference(bo);
|
||||
|
||||
if (sz < TRANSIENT_SLAB_SIZE) {
|
||||
batch->transient_bo = bo;
|
||||
|
|
|
@ -278,7 +278,7 @@ panfrost_get_blend_for_context(struct panfrost_context *ctx, unsigned rti)
|
|||
|
||||
/* Pass BO ownership to job */
|
||||
panfrost_batch_add_bo(batch, final.shader.bo);
|
||||
panfrost_bo_unreference(ctx->base.screen, final.shader.bo);
|
||||
panfrost_bo_unreference(final.shader.bo);
|
||||
|
||||
if (shader->patch_index) {
|
||||
/* We have to specialize the blend shader to use constants, so
|
||||
|
|
|
@ -114,7 +114,7 @@ panfrost_bo_cache_fetch(
|
|||
|
||||
ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MADVISE, &madv);
|
||||
if (!ret && !madv.retained) {
|
||||
panfrost_bo_release(screen, entry, false);
|
||||
panfrost_bo_release(entry, false);
|
||||
continue;
|
||||
}
|
||||
/* Let's go! */
|
||||
|
@ -131,10 +131,10 @@ panfrost_bo_cache_fetch(
|
|||
* successful */
|
||||
|
||||
static bool
|
||||
panfrost_bo_cache_put(
|
||||
struct panfrost_screen *screen,
|
||||
struct panfrost_bo *bo)
|
||||
panfrost_bo_cache_put(struct panfrost_bo *bo)
|
||||
{
|
||||
struct panfrost_screen *screen = bo->screen;
|
||||
|
||||
pthread_mutex_lock(&screen->bo_cache_lock);
|
||||
struct list_head *bucket = pan_bucket(screen, bo->size);
|
||||
struct drm_panfrost_madvise madv;
|
||||
|
@ -168,14 +168,14 @@ panfrost_bo_cache_evict_all(
|
|||
|
||||
list_for_each_entry_safe(struct panfrost_bo, entry, bucket, link) {
|
||||
list_del(&entry->link);
|
||||
panfrost_bo_release(screen, entry, false);
|
||||
panfrost_bo_release(entry, false);
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&screen->bo_cache_lock);
|
||||
}
|
||||
|
||||
void
|
||||
panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
|
||||
panfrost_bo_mmap(struct panfrost_bo *bo)
|
||||
{
|
||||
struct drm_panfrost_mmap_bo mmap_bo = { .handle = bo->gem_handle };
|
||||
int ret;
|
||||
|
@ -183,14 +183,14 @@ panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
|
|||
if (bo->cpu)
|
||||
return;
|
||||
|
||||
ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
|
||||
ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PANFROST_MMAP_BO, &mmap_bo);
|
||||
if (ret) {
|
||||
fprintf(stderr, "DRM_IOCTL_PANFROST_MMAP_BO failed: %m\n");
|
||||
assert(0);
|
||||
}
|
||||
|
||||
bo->cpu = os_mmap(NULL, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED,
|
||||
screen->fd, mmap_bo.offset);
|
||||
bo->screen->fd, mmap_bo.offset);
|
||||
if (bo->cpu == MAP_FAILED) {
|
||||
fprintf(stderr, "mmap failed: %p %m\n", bo->cpu);
|
||||
assert(0);
|
||||
|
@ -202,7 +202,7 @@ panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
|
|||
}
|
||||
|
||||
static void
|
||||
panfrost_bo_munmap(struct panfrost_screen *screen, struct panfrost_bo *bo)
|
||||
panfrost_bo_munmap(struct panfrost_bo *bo)
|
||||
{
|
||||
if (!bo->cpu)
|
||||
return;
|
||||
|
@ -277,7 +277,7 @@ panfrost_bo_create(struct panfrost_screen *screen, size_t size,
|
|||
* for GPU-internal use. But we do trace them anyway. */
|
||||
|
||||
if (!(flags & (PAN_BO_INVISIBLE | PAN_BO_DELAY_MMAP)))
|
||||
panfrost_bo_mmap(screen, bo);
|
||||
panfrost_bo_mmap(bo);
|
||||
else if (flags & PAN_BO_INVISIBLE) {
|
||||
if (pan_debug & PAN_DBG_TRACE)
|
||||
pandecode_inject_mmap(bo->gpu, NULL, bo->size, NULL);
|
||||
|
@ -288,8 +288,7 @@ panfrost_bo_create(struct panfrost_screen *screen, size_t size,
|
|||
}
|
||||
|
||||
void
|
||||
panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
|
||||
bool cacheable)
|
||||
panfrost_bo_release(struct panfrost_bo *bo, bool cacheable)
|
||||
{
|
||||
if (!bo)
|
||||
return;
|
||||
|
@ -300,10 +299,10 @@ panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
|
|||
/* Rather than freeing the BO now, we'll cache the BO for later
|
||||
* allocations if we're allowed to */
|
||||
|
||||
panfrost_bo_munmap(screen, bo);
|
||||
panfrost_bo_munmap(bo);
|
||||
|
||||
if (cacheable) {
|
||||
bool cached = panfrost_bo_cache_put(screen, bo);
|
||||
bool cached = panfrost_bo_cache_put(bo);
|
||||
|
||||
if (cached)
|
||||
return;
|
||||
|
@ -311,7 +310,7 @@ panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
|
|||
|
||||
/* Otherwise, if the BO wasn't cached, we'll legitimately free the BO */
|
||||
|
||||
ret = drmIoctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
|
||||
ret = drmIoctl(bo->screen->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
|
||||
if (ret) {
|
||||
fprintf(stderr, "DRM_IOCTL_GEM_CLOSE failed: %m\n");
|
||||
assert(0);
|
||||
|
@ -328,7 +327,7 @@ panfrost_bo_reference(struct panfrost_bo *bo)
|
|||
}
|
||||
|
||||
void
|
||||
panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
|
||||
panfrost_bo_unreference(struct panfrost_bo *bo)
|
||||
{
|
||||
if (!bo)
|
||||
return;
|
||||
|
@ -336,7 +335,7 @@ panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
|
|||
/* When the reference count goes to zero, we need to cleanup */
|
||||
|
||||
if (pipe_reference(&bo->reference, NULL))
|
||||
panfrost_bo_release(pan_screen(screen), bo, true);
|
||||
panfrost_bo_release(bo, true);
|
||||
}
|
||||
|
||||
struct panfrost_bo *
|
||||
|
@ -354,6 +353,7 @@ panfrost_bo_import(struct panfrost_screen *screen, int fd)
|
|||
ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_GET_BO_OFFSET, &get_bo_offset);
|
||||
assert(!ret);
|
||||
|
||||
bo->screen = screen;
|
||||
bo->gem_handle = gem_handle;
|
||||
bo->gpu = (mali_ptr) get_bo_offset.offset;
|
||||
bo->size = lseek(fd, 0, SEEK_END);
|
||||
|
@ -361,19 +361,19 @@ panfrost_bo_import(struct panfrost_screen *screen, int fd)
|
|||
pipe_reference_init(&bo->reference, 1);
|
||||
|
||||
// TODO map and unmap on demand?
|
||||
panfrost_bo_mmap(screen, bo);
|
||||
panfrost_bo_mmap(bo);
|
||||
return bo;
|
||||
}
|
||||
|
||||
int
|
||||
panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo)
|
||||
panfrost_bo_export(struct panfrost_bo *bo)
|
||||
{
|
||||
struct drm_prime_handle args = {
|
||||
.handle = bo->gem_handle,
|
||||
.flags = DRM_CLOEXEC,
|
||||
};
|
||||
|
||||
int ret = drmIoctl(screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
|
||||
int ret = drmIoctl(bo->screen->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &args);
|
||||
if (ret == -1)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -58,6 +58,8 @@ struct panfrost_bo {
|
|||
|
||||
struct pipe_reference reference;
|
||||
|
||||
struct panfrost_screen *screen;
|
||||
|
||||
/* Mapping for the entire object (all levels) */
|
||||
uint8_t *cpu;
|
||||
|
||||
|
@ -75,19 +77,18 @@ struct panfrost_bo {
|
|||
void
|
||||
panfrost_bo_reference(struct panfrost_bo *bo);
|
||||
void
|
||||
panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo);
|
||||
panfrost_bo_unreference(struct panfrost_bo *bo);
|
||||
struct panfrost_bo *
|
||||
panfrost_bo_create(struct panfrost_screen *screen, size_t size,
|
||||
uint32_t flags);
|
||||
void
|
||||
panfrost_bo_mmap(struct panfrost_screen *screen, struct panfrost_bo *bo);
|
||||
panfrost_bo_mmap(struct panfrost_bo *bo);
|
||||
void
|
||||
panfrost_bo_release(struct panfrost_screen *screen, struct panfrost_bo *bo,
|
||||
bool cacheable);
|
||||
panfrost_bo_release(struct panfrost_bo *bo, bool cacheable);
|
||||
struct panfrost_bo *
|
||||
panfrost_bo_import(struct panfrost_screen *screen, int fd);
|
||||
int
|
||||
panfrost_bo_export(struct panfrost_screen *screen, const struct panfrost_bo *bo);
|
||||
panfrost_bo_export(struct panfrost_bo *bo);
|
||||
void
|
||||
panfrost_bo_cache_evict_all(struct panfrost_screen *screen);
|
||||
|
||||
|
|
|
@ -1751,7 +1751,7 @@ panfrost_delete_shader_state(
|
|||
|
||||
for (unsigned i = 0; i < cso->variant_count; ++i) {
|
||||
struct panfrost_shader_state *shader_state = &cso->variants[i];
|
||||
panfrost_bo_unreference(pctx->screen, shader_state->bo);
|
||||
panfrost_bo_unreference(shader_state->bo);
|
||||
shader_state->bo = NULL;
|
||||
}
|
||||
|
||||
|
@ -2418,7 +2418,6 @@ static void
|
|||
panfrost_destroy(struct pipe_context *pipe)
|
||||
{
|
||||
struct panfrost_context *panfrost = pan_context(pipe);
|
||||
struct panfrost_screen *screen = pan_screen(pipe->screen);
|
||||
|
||||
if (panfrost->blitter)
|
||||
util_blitter_destroy(panfrost->blitter);
|
||||
|
@ -2426,9 +2425,9 @@ panfrost_destroy(struct pipe_context *pipe)
|
|||
if (panfrost->blitter_wallpaper)
|
||||
util_blitter_destroy(panfrost->blitter_wallpaper);
|
||||
|
||||
panfrost_bo_release(screen, panfrost->scratchpad, false);
|
||||
panfrost_bo_release(screen, panfrost->tiler_heap, false);
|
||||
panfrost_bo_release(screen, panfrost->tiler_dummy, false);
|
||||
panfrost_bo_release(panfrost->scratchpad, false);
|
||||
panfrost_bo_release(panfrost->tiler_heap, false);
|
||||
panfrost_bo_release(panfrost->tiler_dummy, false);
|
||||
|
||||
ralloc_free(pipe);
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ panfrost_free_batch(struct panfrost_batch *batch)
|
|||
|
||||
set_foreach(batch->bos, entry) {
|
||||
struct panfrost_bo *bo = (struct panfrost_bo *)entry->key;
|
||||
panfrost_bo_unreference(ctx->base.screen, bo);
|
||||
panfrost_bo_unreference(bo);
|
||||
}
|
||||
|
||||
_mesa_hash_table_remove_key(ctx->batches, &batch->key);
|
||||
|
|
|
@ -134,7 +134,7 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen,
|
|||
|
||||
return true;
|
||||
} else {
|
||||
int fd = panfrost_bo_export(screen, rsrc->bo);
|
||||
int fd = panfrost_bo_export(rsrc->bo);
|
||||
|
||||
if (fd < 0)
|
||||
return false;
|
||||
|
@ -533,7 +533,7 @@ panfrost_resource_destroy(struct pipe_screen *screen,
|
|||
renderonly_scanout_destroy(rsrc->scanout, pscreen->ro);
|
||||
|
||||
if (rsrc->bo)
|
||||
panfrost_bo_unreference(screen, rsrc->bo);
|
||||
panfrost_bo_unreference(rsrc->bo);
|
||||
|
||||
util_range_destroy(&rsrc->valid_buffer_range);
|
||||
ralloc_free(rsrc);
|
||||
|
@ -561,7 +561,7 @@ panfrost_transfer_map(struct pipe_context *pctx,
|
|||
*out_transfer = &transfer->base;
|
||||
|
||||
/* If we haven't already mmaped, now's the time */
|
||||
panfrost_bo_mmap(pan_screen(pctx->screen), bo);
|
||||
panfrost_bo_mmap(bo);
|
||||
|
||||
/* Check if we're bound for rendering and this is a read pixels. If so,
|
||||
* we need to flush */
|
||||
|
@ -839,7 +839,7 @@ panfrost_resource_hint_layout(
|
|||
|
||||
/* If we grew in size, reallocate the BO */
|
||||
if (new_size > rsrc->bo->size) {
|
||||
panfrost_bo_release(screen, rsrc->bo, true);
|
||||
panfrost_bo_release(rsrc->bo, true);
|
||||
rsrc->bo = panfrost_bo_create(screen, new_size, PAN_BO_DELAY_MMAP);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue