ilo: allow for device-dependent format translation
authorChia-I Wu <olvaffe@gmail.com>
Thu, 24 Jul 2014 01:32:34 +0000 (09:32 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Thu, 24 Jul 2014 01:33:33 +0000 (09:33 +0800)
Pass ilo_dev_info to all format translation functions.

src/gallium/drivers/ilo/ilo_format.c
src/gallium/drivers/ilo/ilo_format.h
src/gallium/drivers/ilo/ilo_gpe_gen6.c
src/gallium/drivers/ilo/ilo_gpe_gen6.h
src/gallium/drivers/ilo/ilo_gpe_gen7.c

index 953be8d802c404c5cdab27b526fad55915cdb878..033946b466189044943309dc4fed1fa2941053f8 100644 (file)
@@ -297,9 +297,10 @@ static const struct ilo_format_info ilo_format_table[] = {
 #undef FI_INITIALIZER
 
 static const struct ilo_format_info *
-lookup_format_info(enum pipe_format format, unsigned bind)
+lookup_format_info(const struct ilo_dev_info *dev,
+                   enum pipe_format format, unsigned bind)
 {
-   const int surfaceformat = ilo_translate_format(format, bind);
+   const int surfaceformat = ilo_translate_format(dev, format, bind);
 
    return (surfaceformat >= 0 && surfaceformat < Elements(ilo_format_table) &&
            ilo_format_table[surfaceformat].exists) ?
@@ -311,7 +312,8 @@ lookup_format_info(enum pipe_format format, unsigned bind)
  * format.  Return -1 on errors.
  */
 int
-ilo_translate_color_format(enum pipe_format format)
+ilo_translate_color_format(const struct ilo_dev_info *dev,
+                           enum pipe_format format)
 {
    static const int format_mapping[PIPE_FORMAT_COUNT] = {
       [PIPE_FORMAT_NONE]                  = 0,
@@ -581,7 +583,7 @@ ilo_is_format_supported(struct pipe_screen *screen,
                         unsigned bindings)
 {
    struct ilo_screen *is = ilo_screen(screen);
-   const int gen = is->dev.gen;
+   const struct ilo_dev_info *dev = &is->dev;
    const bool is_pure_int = util_format_is_pure_integer(format);
    const struct ilo_format_info *info;
    unsigned bind;
@@ -611,31 +613,31 @@ ilo_is_format_supported(struct pipe_screen *screen,
 
    bind = (bindings & PIPE_BIND_RENDER_TARGET);
    if (bind) {
-      info = lookup_format_info(format, bind);
+      info = lookup_format_info(dev, format, bind);
 
-      if (gen < info->render_target)
+      if (dev->gen < info->render_target)
          return false;
 
-      if (!is_pure_int && gen < info->alpha_blend)
+      if (!is_pure_int && dev->gen < info->alpha_blend)
          return false;
    }
 
    bind = (bindings & PIPE_BIND_SAMPLER_VIEW);
    if (bind) {
-      info = lookup_format_info(format, bind);
+      info = lookup_format_info(dev, format, bind);
 
-      if (gen < info->sampling)
+      if (dev->gen < info->sampling)
          return false;
 
-      if (!is_pure_int && gen < info->filtering)
+      if (!is_pure_int && dev->gen < info->filtering)
          return false;
    }
 
    bind = (bindings & PIPE_BIND_VERTEX_BUFFER);
    if (bind) {
-      info = lookup_format_info(format, bind);
+      info = lookup_format_info(dev, format, bind);
 
-      if (gen < info->input_vb)
+      if (dev->gen < info->input_vb)
          return false;
    }
 
index 2ea7885694e0b99f1e0d04d5431999968dfa325d..7d84c60a95343ff31cd8b05ef0f67820ddefe98a 100644 (file)
@@ -38,17 +38,19 @@ void
 ilo_init_format_functions(struct ilo_screen *is);
 
 int
-ilo_translate_color_format(enum pipe_format format);
+ilo_translate_color_format(const struct ilo_dev_info *dev,
+                           enum pipe_format format);
 
 /**
  * Translate a pipe format to a hardware surface format suitable for
  * the given purpose.  Return -1 on errors.
  *
  * This is an inline function not only for performance reasons.  There are
- * caveats that the callers should that before calling this function.
+ * caveats that the callers should be aware of before calling this function.
  */
 static inline int
-ilo_translate_format(enum pipe_format format, unsigned bind)
+ilo_translate_format(const struct ilo_dev_info *dev,
+                     enum pipe_format format, unsigned bind)
 {
    switch (bind) {
    case PIPE_BIND_RENDER_TARGET:
@@ -61,7 +63,7 @@ ilo_translate_format(enum pipe_format format, unsigned bind)
       case PIPE_FORMAT_B8G8R8X8_UNORM:
          return GEN6_FORMAT_B8G8R8A8_UNORM;
       default:
-         return ilo_translate_color_format(format);
+         return ilo_translate_color_format(dev, format);
       }
       break;
    case PIPE_BIND_SAMPLER_VIEW:
@@ -87,7 +89,7 @@ ilo_translate_format(enum pipe_format format, unsigned bind)
       case PIPE_FORMAT_ETC1_RGB8:
          return GEN6_FORMAT_R8G8B8X8_UNORM;
       default:
-         return ilo_translate_color_format(format);
+         return ilo_translate_color_format(dev, format);
       }
       break;
    case PIPE_BIND_VERTEX_BUFFER:
@@ -110,7 +112,7 @@ ilo_translate_format(enum pipe_format format, unsigned bind)
       case PIPE_FORMAT_R8G8B8_SINT:
          return GEN6_FORMAT_R8G8B8A8_SINT;
       default:
-         return ilo_translate_color_format(format);
+         return ilo_translate_color_format(dev, format);
       }
       break;
    default:
@@ -122,21 +124,24 @@ ilo_translate_format(enum pipe_format format, unsigned bind)
 }
 
 static inline int
-ilo_translate_render_format(enum pipe_format format)
+ilo_translate_render_format(const struct ilo_dev_info *dev,
+                            enum pipe_format format)
 {
-   return ilo_translate_format(format, PIPE_BIND_RENDER_TARGET);
+   return ilo_translate_format(dev, format, PIPE_BIND_RENDER_TARGET);
 }
 
 static inline int
-ilo_translate_texture_format(enum pipe_format format)
+ilo_translate_texture_format(const struct ilo_dev_info *dev,
+                             enum pipe_format format)
 {
-   return ilo_translate_format(format, PIPE_BIND_SAMPLER_VIEW);
+   return ilo_translate_format(dev, format, PIPE_BIND_SAMPLER_VIEW);
 }
 
 static inline int
-ilo_translate_vertex_format(enum pipe_format format)
+ilo_translate_vertex_format(const struct ilo_dev_info *dev,
+                            enum pipe_format format)
 {
-   return ilo_translate_format(format, PIPE_BIND_VERTEX_BUFFER);
+   return ilo_translate_format(dev, format, PIPE_BIND_VERTEX_BUFFER);
 }
 
 #endif /* ILO_FORMAT_H */
index 11972b96897fe696611b45d0971005e5c0dc4a31..0a9fd98152d0f439f0ee2c2e135e966c8c48982e 100644 (file)
@@ -271,7 +271,7 @@ ve_init_cso(const struct ilo_dev_info *dev,
                      GEN6_VFCOMP_STORE_1_FP;
    }
 
-   format = ilo_translate_vertex_format(state->src_format);
+   format = ilo_translate_vertex_format(dev, state->src_format);
 
    STATIC_ASSERT(Elements(cso->payload) >= 2);
    cso->payload[0] =
@@ -1831,7 +1831,7 @@ ilo_gpe_init_view_surface_for_buffer_gen6(const struct ilo_dev_info *dev,
     * structure in a buffer.
     */
 
-   surface_format = ilo_translate_color_format(elem_format);
+   surface_format = ilo_translate_color_format(dev, elem_format);
 
    num_entries = size / struct_size;
    /* see if there is enough space to fit another element */
@@ -1929,9 +1929,9 @@ ilo_gpe_init_view_surface_for_texture_gen6(const struct ilo_dev_info *dev,
       format = PIPE_FORMAT_Z32_FLOAT;
 
    if (is_rt)
-      surface_format = ilo_translate_render_format(format);
+      surface_format = ilo_translate_render_format(dev, format);
    else
-      surface_format = ilo_translate_texture_format(format);
+      surface_format = ilo_translate_texture_format(dev, format);
    assert(surface_format >= 0);
 
    width = tex->base.width0;
index e5647184fd7cf781ec4e67175982c1a8c3613150..8e394ded95fec3bb7cd8623e1c17b1ed9f9bc461 100644 (file)
@@ -2124,7 +2124,7 @@ gen6_emit_BLEND_STATE(const struct ilo_dev_info *dev,
          switch (format_desc->format) {
          case PIPE_FORMAT_B8G8R8X8_UNORM:
             /* force alpha to one when the HW format has alpha */
-            assert(ilo_translate_render_format(PIPE_FORMAT_B8G8R8X8_UNORM)
+            assert(ilo_translate_render_format(dev, PIPE_FORMAT_B8G8R8X8_UNORM)
                   == GEN6_FORMAT_B8G8R8A8_UNORM);
             rt_dst_alpha_forced_one = true;
             break;
index 6d3397f2d62df5b52f8c428b81a63fccf254ef2b..cc666c80953a1586b79f4f52e95eb4683fe4a340 100644 (file)
@@ -319,7 +319,7 @@ ilo_gpe_init_view_surface_for_buffer_gen7(const struct ilo_dev_info *dev,
    surface_type = (structured) ? GEN7_SURFTYPE_STRBUF : GEN6_SURFTYPE_BUFFER;
 
    surface_format = (typed) ?
-      ilo_translate_color_format(elem_format) : GEN6_FORMAT_RAW;
+      ilo_translate_color_format(dev, elem_format) : GEN6_FORMAT_RAW;
 
    num_entries = size / struct_size;
    /* see if there is enough space to fit another element */
@@ -447,9 +447,9 @@ ilo_gpe_init_view_surface_for_texture_gen7(const struct ilo_dev_info *dev,
       format = PIPE_FORMAT_Z32_FLOAT;
 
    if (is_rt)
-      surface_format = ilo_translate_render_format(format);
+      surface_format = ilo_translate_render_format(dev, format);
    else
-      surface_format = ilo_translate_texture_format(format);
+      surface_format = ilo_translate_texture_format(dev, format);
    assert(surface_format >= 0);
 
    width = tex->base.width0;