Module: Mesa Branch: master Commit: f74ccde2c767b6e53e43ce9c0e189776301776b8 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=f74ccde2c767b6e53e43ce9c0e189776301776b8
Author: Rob Clark <[email protected]> Date: Tue Mar 2 14:47:48 2021 -0800 freedreno: Factor out common fd_resource init Before adding new things that would need initialization in both paths, refactor out a shared helper. Signed-off-by: Rob Clark <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9323> --- src/gallium/drivers/freedreno/freedreno_resource.c | 46 +++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/gallium/drivers/freedreno/freedreno_resource.c b/src/gallium/drivers/freedreno/freedreno_resource.c index 0e3a8e95cf8..b7b097f5aaf 100644 --- a/src/gallium/drivers/freedreno/freedreno_resource.c +++ b/src/gallium/drivers/freedreno/freedreno_resource.c @@ -929,6 +929,26 @@ fd_resource_layout_init(struct pipe_resource *prsc) layout->cpp_shift = ffs(layout->cpp) - 1; } +static struct fd_resource * +alloc_resource_struct(struct pipe_screen *pscreen, const struct pipe_resource *tmpl) +{ + struct fd_resource *rsc = CALLOC_STRUCT(fd_resource); + + if (!rsc) + return NULL; + + struct pipe_resource *prsc = &rsc->base; + *prsc = *tmpl; + + pipe_reference_init(&prsc->reference, 1); + prsc->screen = pscreen; + + util_range_init(&rsc->valid_buffer_range); + simple_mtx_init(&rsc->lock, mtx_plain); + + return rsc; +} + /** * Helper that allocates a resource and resolves its layout (but doesn't * allocate its bo). @@ -947,13 +967,11 @@ fd_resource_allocate_and_resolve(struct pipe_screen *pscreen, enum pipe_format format = tmpl->format; uint32_t size; - rsc = CALLOC_STRUCT(fd_resource); - prsc = &rsc->base; - + rsc = alloc_resource_struct(pscreen, tmpl); if (!rsc) return NULL; - *prsc = *tmpl; + prsc = &rsc->base; DBG("%"PRSC_FMT, PRSC_ARGS(prsc)); @@ -1003,20 +1021,12 @@ fd_resource_allocate_and_resolve(struct pipe_screen *pscreen, allow_ubwc &= !FD_DBG(NOUBWC); - pipe_reference_init(&prsc->reference, 1); - - prsc->screen = pscreen; - if (screen->tile_mode && (tmpl->target != PIPE_BUFFER) && !linear) { rsc->layout.tile_mode = screen->tile_mode(prsc); } - util_range_init(&rsc->valid_buffer_range); - - simple_mtx_init(&rsc->lock, mtx_plain); - rsc->internal_format = format; rsc->layout.ubwc = rsc->layout.tile_mode && is_a6xx(screen) && allow_ubwc; @@ -1134,7 +1144,7 @@ fd_resource_from_handle(struct pipe_screen *pscreen, struct winsys_handle *handle, unsigned usage) { struct fd_screen *screen = fd_screen(pscreen); - struct fd_resource *rsc = CALLOC_STRUCT(fd_resource); + struct fd_resource *rsc = alloc_resource_struct(pscreen, tmpl); if (!rsc) return NULL; @@ -1142,20 +1152,10 @@ fd_resource_from_handle(struct pipe_screen *pscreen, struct fdl_slice *slice = fd_resource_slice(rsc, 0); struct pipe_resource *prsc = &rsc->base; - *prsc = *tmpl; - DBG("%"PRSC_FMT", modifier=%"PRIx64, PRSC_ARGS(prsc), handle->modifier); fd_resource_layout_init(prsc); - pipe_reference_init(&prsc->reference, 1); - - prsc->screen = pscreen; - - util_range_init(&rsc->valid_buffer_range); - - simple_mtx_init(&rsc->lock, mtx_plain); - struct fd_bo *bo = fd_screen_bo_from_handle(pscreen, handle); if (!bo) goto fail; _______________________________________________ mesa-commit mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/mesa-commit
