summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Lima Mitev <elima@igalia.com>2020-08-18 10:04:02 +0200
committerMarge Bot <eric+marge@anholt.net>2020-08-18 20:40:40 +0000
commit536ec9d7f5ab3bba904090abf7b3fc58e92eec78 (patch)
treec8368da8fde31d90300e35ba0479d840bd823ffc
parent0eecd3d68466327567df7da468cc2088a652e22f (diff)
freedreno: Refactor fd_resource_create_with_modifiers() into a helper
The helper just allocates and resolves layout, but does not deal with scanout buffers nor allocation of the actual bo. The resolved bo size is returned as an output argument. Reviewed-by: Rob Clark <robdclark@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4565>
-rw-r--r--src/gallium/drivers/freedreno/freedreno_resource.c99
1 files changed, 64 insertions, 35 deletions
diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c
index 1696cb8cc9c..624714718de 100644
--- a/src/gallium/drivers/freedreno/freedreno_resource.c
+++ b/src/gallium/drivers/freedreno/freedreno_resource.c
@@ -833,12 +833,16 @@ fd_resource_layout_init(struct pipe_resource *prsc)
}
/**
- * Create a new texture object, using the given template info.
+ * Helper that allocates a resource and resolves its layout (but doesn't
+ * allocate its bo).
+ *
+ * It returns a pipe_resource (as fd_resource_create_with_modifiers()
+ * would do), and also bo's minimum required size as an output argument.
*/
static struct pipe_resource *
-fd_resource_create_with_modifiers(struct pipe_screen *pscreen,
+fd_resource_allocate_and_resolve(struct pipe_screen *pscreen,
const struct pipe_resource *tmpl,
- const uint64_t *modifiers, int count)
+ const uint64_t *modifiers, int count, uint32_t *psize)
{
struct fd_screen *screen = fd_screen(pscreen);
struct fd_resource *rsc;
@@ -846,38 +850,6 @@ fd_resource_create_with_modifiers(struct pipe_screen *pscreen,
enum pipe_format format = tmpl->format;
uint32_t size;
- /* when using kmsro, scanout buffers are allocated on the display device
- * create_with_modifiers() doesn't give us usage flags, so we have to
- * assume that all calls with modifiers are scanout-possible
- */
- if (screen->ro &&
- ((tmpl->bind & PIPE_BIND_SCANOUT) ||
- !(count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID))) {
- struct pipe_resource scanout_templat = *tmpl;
- struct renderonly_scanout *scanout;
- struct winsys_handle handle;
-
- /* note: alignment is wrong for a6xx */
- scanout_templat.width0 = align(tmpl->width0, screen->gmem_alignw);
-
- scanout = renderonly_scanout_for_resource(&scanout_templat,
- screen->ro, &handle);
- if (!scanout)
- return NULL;
-
- renderonly_scanout_destroy(scanout, screen->ro);
-
- assert(handle.type == WINSYS_HANDLE_TYPE_FD);
- rsc = fd_resource(pscreen->resource_from_handle(pscreen, tmpl,
- &handle,
- PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE));
- close(handle.handle);
- if (!rsc)
- return NULL;
-
- return &rsc->base;
- }
-
rsc = CALLOC_STRUCT(fd_resource);
prsc = &rsc->base;
@@ -964,6 +936,63 @@ fd_resource_create_with_modifiers(struct pipe_screen *pscreen,
if (fd_mesa_debug & FD_DBG_LAYOUT)
fdl_dump_layout(&rsc->layout);
+ /* Hand out the resolved size. */
+ if (psize)
+ *psize = size;
+
+ return prsc;
+}
+
+/**
+ * Create a new texture object, using the given template info.
+ */
+static struct pipe_resource *
+fd_resource_create_with_modifiers(struct pipe_screen *pscreen,
+ const struct pipe_resource *tmpl,
+ const uint64_t *modifiers, int count)
+{
+ struct fd_screen *screen = fd_screen(pscreen);
+ struct fd_resource *rsc;
+ struct pipe_resource *prsc;
+ uint32_t size;
+
+ /* when using kmsro, scanout buffers are allocated on the display device
+ * create_with_modifiers() doesn't give us usage flags, so we have to
+ * assume that all calls with modifiers are scanout-possible
+ */
+ if (screen->ro &&
+ ((tmpl->bind & PIPE_BIND_SCANOUT) ||
+ !(count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID))) {
+ struct pipe_resource scanout_templat = *tmpl;
+ struct renderonly_scanout *scanout;
+ struct winsys_handle handle;
+
+ /* note: alignment is wrong for a6xx */
+ scanout_templat.width0 = align(tmpl->width0, screen->gmem_alignw);
+
+ scanout = renderonly_scanout_for_resource(&scanout_templat,
+ screen->ro, &handle);
+ if (!scanout)
+ return NULL;
+
+ renderonly_scanout_destroy(scanout, screen->ro);
+
+ assert(handle.type == WINSYS_HANDLE_TYPE_FD);
+ rsc = fd_resource(pscreen->resource_from_handle(pscreen, tmpl,
+ &handle,
+ PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE));
+ close(handle.handle);
+ if (!rsc)
+ return NULL;
+
+ return &rsc->base;
+ }
+
+ prsc = fd_resource_allocate_and_resolve(pscreen, tmpl, modifiers, count, &size);
+ if (!prsc)
+ return NULL;
+ rsc = fd_resource(prsc);
+
realloc_bo(rsc, size);
if (!rsc->bo)
goto fail;