swrast: Use util_format_write_4/4ub for the scattered pixel writes.
authorEric Anholt <eric@anholt.net>
Fri, 15 Jan 2021 20:33:45 +0000 (12:33 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 19 Jan 2021 20:02:51 +0000 (20:02 +0000)
This was the only code using the "get a pack-a-pixel function pointer"
generated code, switch it over to using util/format's.

This does mean some more format desc lookups in the loop, but this code is
only accessible from classic driver swrast fallbacks at this point, where
GPU read perf completely dominates the profile anyway.

basically no change to driver size.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8532>

src/mesa/main/format_pack.h
src/mesa/main/format_pack.py
src/mesa/swrast/s_span.c

index 43871e3..ea3ae17 100644 (file)
@@ -34,12 +34,6 @@ extern "C" {
 #endif
 
 
-/** Pack a uint8_t rgba[4] color to dest address */
-typedef void (*mesa_pack_ubyte_rgba_func)(const uint8_t src[4], void *dst);
-
-/** Pack a float rgba[4] color to dest address */
-typedef void (*mesa_pack_float_rgba_func)(const float src[4], void *dst);
-
 /** Pack a float Z value to dest address */
 typedef void (*mesa_pack_float_z_func)(const float *src, void *dst);
 
@@ -52,14 +46,6 @@ typedef void (*mesa_pack_ubyte_stencil_func)(const uint8_t *src, void *dst);
 
 
 
-extern mesa_pack_ubyte_rgba_func
-_mesa_get_pack_ubyte_rgba_function(mesa_format format);
-
-
-extern mesa_pack_float_rgba_func
-_mesa_get_pack_float_rgba_function(mesa_format format);
-
-
 extern mesa_pack_float_z_func
 _mesa_get_pack_float_z_func(mesa_format format);
 
index 05aee02..30b8057 100644 (file)
@@ -293,47 +293,6 @@ pack_float_r11g11b10_float(const float src[4], void *dst)
    *d = float3_to_r11g11b10f(src);
 }
 
-/**
- * Return a function that can pack a uint8_t rgba[4] color.
- */
-mesa_pack_ubyte_rgba_func
-_mesa_get_pack_ubyte_rgba_function(mesa_format format)
-{
-   switch (format) {
-%for f in rgb_formats:
-   %if f.is_compressed():
-      <% continue %>
-   %endif
-
-   case ${f.name}:
-      return pack_ubyte_${f.short_name()};
-%endfor
-   default:
-      return NULL;
-   }
-}
-
-/**
- * Return a function that can pack a float rgba[4] color.
- */
-mesa_pack_float_rgba_func
-_mesa_get_pack_float_rgba_function(mesa_format format)
-{
-   switch (format) {
-%for f in rgb_formats:
-   %if f.is_compressed():
-      <% continue %>
-   %elif f.is_int() and not f.is_normalized():
-      <% continue %>
-   %endif
-
-   case ${f.name}:
-      return pack_float_${f.short_name()};
-%endfor
-   default:
-      return NULL;
-   }
-}
 
 /**
  * Pack a row of uint8_t rgba[4] values to the destination.
index d1933e3..d20cea5 100644 (file)
@@ -1041,25 +1041,23 @@ put_values(struct gl_context *ctx, struct gl_renderbuffer *rb,
            GLuint count, const GLint x[], const GLint y[],
            const void *values, const GLubyte *mask)
 {
-   mesa_pack_ubyte_rgba_func pack_ubyte = NULL;
-   mesa_pack_float_rgba_func pack_float = NULL;
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
    GLuint i;
 
-   if (datatype == GL_UNSIGNED_BYTE)
-      pack_ubyte = _mesa_get_pack_ubyte_rgba_function(rb->Format);
-   else
-      pack_float = _mesa_get_pack_float_rgba_function(rb->Format);
-
    for (i = 0; i < count; i++) {
       if (mask[i]) {
-         GLubyte *dst = _swrast_pixel_address(rb, x[i], y[i]);
-
          if (datatype == GL_UNSIGNED_BYTE) {
-            pack_ubyte((const GLubyte *) values + 4 * i, dst);
+            util_format_write_4ub(rb->Format,
+                                  (uint8_t *)values + 4 * i, 0,
+                                  srb->Map, srb->RowStride,
+                                  x[i], y[i], 1, 1);
          }
          else {
             assert(datatype == GL_FLOAT);
-            pack_float((const GLfloat *) values + 4 * i, dst);
+            util_format_write_4(rb->Format,
+                                (float *)values + 4 * i, 0,
+                                srb->Map, srb->RowStride,
+                                x[i], y[i], 1, 1);
          }
       }
    }