[Mesa-dev] [PATCH v2 1/2] i965: Use helper function for modifier -> tiling
Daniel Stone
daniels at collabora.com
Thu May 4 09:14:32 UTC 2017
Use a helper function and struct to convert between a modifier and
tiling mode, so we can use it later for a tiling -> modifier lookup.
Signed-off-by: Daniel Stone <daniels at collabora.com>
Cc: Ben Widawsky <ben at bwidawsk.net>
---
src/mesa/drivers/dri/i965/intel_screen.c | 49 +++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 17 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index 34a5f18af2..e43f9a5c3a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -290,6 +290,28 @@ static struct intel_image_format intel_image_formats[] = {
{ 0, 1, 0, __DRI_IMAGE_FORMAT_ARGB8888, 4 } } }
};
+static const struct {
+ uint32_t tiling;
+ uint64_t modifier;
+} tiling_modifier_map[] = {
+ { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR },
+ { .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED },
+ { .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED },
+};
+
+static uint32_t
+modifier_to_tiling(uint64_t modifier)
+{
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
+ if (tiling_modifier_map[i].modifier == modifier)
+ return tiling_modifier_map[i].tiling;
+ }
+
+ return I915_TILING_NONE;
+}
+
static void
intel_image_warn_if_unaligned(__DRIimage *image, const char *func)
{
@@ -568,10 +590,7 @@ intel_create_image_common(__DRIscreen *dri_screen,
{
__DRIimage *image;
struct intel_screen *screen = dri_screen->driverPrivate;
- /* Historically, X-tiled was the default, and so lack of modifier means
- * X-tiled.
- */
- uint32_t tiling = I915_TILING_X;
+ uint32_t tiling;
int cpp;
/* Callers of this may specify a modifier, or a dri usage, but not both. The
@@ -581,21 +600,17 @@ intel_create_image_common(__DRIscreen *dri_screen,
assert(!(use && count));
uint64_t modifier = select_best_modifier(&screen->devinfo, modifiers, count);
- switch (modifier) {
- case I915_FORMAT_MOD_X_TILED:
- assert(tiling == I915_TILING_X);
- break;
- case DRM_FORMAT_MOD_LINEAR:
- tiling = I915_TILING_NONE;
- break;
- case I915_FORMAT_MOD_Y_TILED:
- tiling = I915_TILING_Y;
- break;
- case DRM_FORMAT_MOD_INVALID:
+ if (modifier == DRM_FORMAT_MOD_INVALID) {
+ /* User requested specific modifiers, none of which work */
if (modifiers)
return NULL;
- default:
- break;
+
+ /* Historically, X-tiled was the default, and so lack of modifier means
+ * X-tiled.
+ */
+ tiling = I915_TILING_X;
+ } else {
+ tiling = modifier_to_tiling(modifier);
}
if (use & __DRI_IMAGE_USE_CURSOR) {
--
2.12.2
More information about the mesa-dev
mailing list