[Mesa-dev] [PATCH 10/23] radeonsi: factor out metadata import

Timothy Arceri tarceri at itsqueeze.com
Fri Aug 4 01:54:13 UTC 2017


From: Andres Rodriguez <andresx7 at gmail.com>

Plumbing for importing memobj backed textures.

Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
---
 src/gallium/drivers/radeon/r600_texture.c | 63 ++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 27 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c
index 3aac3c78a9..ca2b37b21a 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -333,20 +333,53 @@ static void r600_texture_init_metadata(struct r600_common_screen *rscreen,
 		metadata->u.legacy.bankw = surface->u.legacy.bankw;
 		metadata->u.legacy.bankh = surface->u.legacy.bankh;
 		metadata->u.legacy.tile_split = surface->u.legacy.tile_split;
 		metadata->u.legacy.mtilea = surface->u.legacy.mtilea;
 		metadata->u.legacy.num_banks = surface->u.legacy.num_banks;
 		metadata->u.legacy.stride = surface->u.legacy.level[0].nblk_x * surface->bpe;
 		metadata->u.legacy.scanout = (surface->flags & RADEON_SURF_SCANOUT) != 0;
 	}
 }
 
+static void r600_surface_import_metadata(struct r600_common_screen *rscreen,
+					 struct radeon_surf *surf,
+					 struct radeon_bo_metadata *metadata,
+					 enum radeon_surf_mode *array_mode,
+					 bool *is_scanout)
+{
+	if (rscreen->chip_class >= GFX9) {
+		if (metadata->u.gfx9.swizzle_mode > 0)
+			*array_mode = RADEON_SURF_MODE_2D;
+		else
+			*array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
+
+		*is_scanout = metadata->u.gfx9.swizzle_mode == 0 ||
+			metadata->u.gfx9.swizzle_mode % 4 == 2;
+	} else {
+		surf->u.legacy.pipe_config = metadata->u.legacy.pipe_config;
+		surf->u.legacy.bankw = metadata->u.legacy.bankw;
+		surf->u.legacy.bankh = metadata->u.legacy.bankh;
+		surf->u.legacy.tile_split = metadata->u.legacy.tile_split;
+		surf->u.legacy.mtilea = metadata->u.legacy.mtilea;
+		surf->u.legacy.num_banks = metadata->u.legacy.num_banks;
+
+		if (metadata->u.legacy.macrotile == RADEON_LAYOUT_TILED)
+			*array_mode = RADEON_SURF_MODE_2D;
+		else if (metadata->u.legacy.microtile == RADEON_LAYOUT_TILED)
+			*array_mode = RADEON_SURF_MODE_1D;
+		else
+			*array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
+
+		*is_scanout = metadata->u.legacy.scanout;
+	}
+}
+
 static void r600_eliminate_fast_color_clear(struct r600_common_context *rctx,
 					    struct r600_texture *rtex)
 {
 	struct r600_common_screen *rscreen = rctx->screen;
 	struct pipe_context *ctx = &rctx->b;
 
 	if (ctx == rscreen->aux_context)
 		mtx_lock(&rscreen->aux_context_lock);
 
 	ctx->flush_resource(ctx, &rtex->resource.b.b);
@@ -1435,63 +1468,39 @@ struct pipe_resource *r600_texture_create(struct pipe_screen *screen,
 }
 
 static struct pipe_resource *r600_texture_from_handle(struct pipe_screen *screen,
 						      const struct pipe_resource *templ,
 						      struct winsys_handle *whandle,
                                                       unsigned usage)
 {
 	struct r600_common_screen *rscreen = (struct r600_common_screen*)screen;
 	struct pb_buffer *buf = NULL;
 	unsigned stride = 0, offset = 0;
-	unsigned array_mode;
+	enum radeon_surf_mode array_mode;
 	struct radeon_surf surface;
 	int r;
 	struct radeon_bo_metadata metadata = {};
 	struct r600_texture *rtex;
 	bool is_scanout;
 
 	/* Support only 2D textures without mipmaps */
 	if ((templ->target != PIPE_TEXTURE_2D && templ->target != PIPE_TEXTURE_RECT) ||
 	      templ->depth0 != 1 || templ->last_level != 0)
 		return NULL;
 
 	buf = rscreen->ws->buffer_from_handle(rscreen->ws, whandle, &stride, &offset);
 	if (!buf)
 		return NULL;
 
 	rscreen->ws->buffer_get_metadata(buf, &metadata);
-
-	if (rscreen->chip_class >= GFX9) {
-		if (metadata.u.gfx9.swizzle_mode > 0)
-			array_mode = RADEON_SURF_MODE_2D;
-		else
-			array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
-
-		is_scanout = metadata.u.gfx9.swizzle_mode == 0 ||
-			     metadata.u.gfx9.swizzle_mode % 4 == 2;
-	} else {
-		surface.u.legacy.pipe_config = metadata.u.legacy.pipe_config;
-		surface.u.legacy.bankw = metadata.u.legacy.bankw;
-		surface.u.legacy.bankh = metadata.u.legacy.bankh;
-		surface.u.legacy.tile_split = metadata.u.legacy.tile_split;
-		surface.u.legacy.mtilea = metadata.u.legacy.mtilea;
-		surface.u.legacy.num_banks = metadata.u.legacy.num_banks;
-
-		if (metadata.u.legacy.macrotile == RADEON_LAYOUT_TILED)
-			array_mode = RADEON_SURF_MODE_2D;
-		else if (metadata.u.legacy.microtile == RADEON_LAYOUT_TILED)
-			array_mode = RADEON_SURF_MODE_1D;
-		else
-			array_mode = RADEON_SURF_MODE_LINEAR_ALIGNED;
-
-		is_scanout = metadata.u.legacy.scanout;
-	}
+	r600_surface_import_metadata(rscreen, &surface, &metadata,
+				     &array_mode, &is_scanout);
 
 	r = r600_init_surface(rscreen, &surface, templ, array_mode, stride,
 			      offset, true, is_scanout, false, false);
 	if (r) {
 		return NULL;
 	}
 
 	rtex = r600_texture_create_object(screen, templ, buf, &surface);
 	if (!rtex)
 		return NULL;
-- 
2.13.3



More information about the mesa-dev mailing list