[Mesa-dev] [PATCH 1/2] i965: Rework the modifier info map

Jason Ekstrand jason at jlekstrand.net
Mon Jul 17 00:48:22 UTC 2017


This commit splits the mapping in half.  The modifier_infos table now
only contains the modifier and the since_gen field.  The tiling bits
have been moved into a table in modifier_to_tiling as that's the only
place it was ever used.  The modifier_is_supported function now takes a
devinfo and does the since_gen check.
---
 src/mesa/drivers/dri/i965/intel_screen.c | 48 +++++++++++++++++---------------
 1 file changed, 25 insertions(+), 23 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index deec894..148af7a 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -296,26 +296,25 @@ static struct intel_image_format intel_image_formats[] = {
 };
 
 static const struct {
-   uint32_t tiling;
    uint64_t modifier;
    unsigned since_gen;
-} tiling_modifier_map[] = {
-   { .tiling = I915_TILING_NONE, .modifier = DRM_FORMAT_MOD_LINEAR,
-     .since_gen = 1 },
-   { .tiling = I915_TILING_X, .modifier = I915_FORMAT_MOD_X_TILED,
-     .since_gen = 1 },
-   { .tiling = I915_TILING_Y, .modifier = I915_FORMAT_MOD_Y_TILED,
-     .since_gen = 6 },
+} supported_modifiers[] = {
+   { DRM_FORMAT_MOD_LINEAR       , 1 },
+   { I915_FORMAT_MOD_X_TILED     , 1 },
+   { I915_FORMAT_MOD_Y_TILED     , 6 },
 };
 
 static bool
-modifier_is_supported(uint64_t modifier)
+modifier_is_supported(const struct gen_device_info *devinfo,
+                      uint64_t modifier)
 {
    int i;
 
-   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
-      if (tiling_modifier_map[i].modifier == modifier)
-         return true;
+   for (i = 0; i < ARRAY_SIZE(supported_modifiers); i++) {
+      if (supported_modifiers[i].modifier != modifier)
+         continue;
+
+      return supported_modifiers[i].since_gen <= devinfo->gen;
    }
 
    return false;
@@ -324,14 +323,15 @@ modifier_is_supported(uint64_t modifier)
 static uint64_t
 tiling_to_modifier(uint32_t tiling)
 {
-   int i;
+   static const uint64_t map[] = {
+      [I915_TILING_NONE]   = DRM_FORMAT_MOD_LINEAR,
+      [I915_TILING_X]      = I915_FORMAT_MOD_X_TILED,
+      [I915_TILING_Y]      = I915_FORMAT_MOD_Y_TILED,
+   };
 
-   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
-      if (tiling_modifier_map[i].tiling == tiling)
-         return tiling_modifier_map[i].modifier;
-   }
+   assert(tiling < ARRAY_SIZE(map));
 
-   unreachable("tiling_to_modifier received unknown tiling mode");
+   return map[tiling];
 }
 
 static void
@@ -883,8 +883,9 @@ intel_create_image_from_fds_common(__DRIscreen *dri_screen,
    if (f == NULL)
       return NULL;
 
-   if (modifier != DRM_FORMAT_MOD_INVALID && !modifier_is_supported(modifier))
-         return NULL;
+   if (modifier != DRM_FORMAT_MOD_INVALID &&
+       !modifier_is_supported(&screen->devinfo, modifier))
+      return NULL;
 
    if (f->nplanes == 1)
       image = intel_allocate_image(screen, f->planes[0].dri_format,
@@ -1137,15 +1138,16 @@ intel_query_dma_buf_modifiers(__DRIscreen *_screen, int fourcc, int max,
    if (f == NULL)
       return false;
 
-   for (i = 0; i < ARRAY_SIZE(tiling_modifier_map); i++) {
-      if (screen->devinfo.gen < tiling_modifier_map[i].since_gen)
+   for (i = 0; i < ARRAY_SIZE(supported_modifiers); i++) {
+      uint64_t modifier = supported_modifiers[i].modifier;
+      if (!modifier_is_supported(&screen->devinfo, modifier))
          continue;
 
       num_mods++;
       if (max == 0)
          continue;
 
-      modifiers[num_mods - 1] = tiling_modifier_map[i].modifier;
+      modifiers[num_mods - 1] = modifier;
       if (num_mods >= max)
         break;
    }
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list