Mesa (main): wgl: remove hard limit on pixelformats

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 22 07:07:12 UTC 2021


Module: Mesa
Branch: main
Commit: 91a1849ff04fc6b7b921a303823a111196ff8559
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=91a1849ff04fc6b7b921a303823a111196ff8559

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Thu Jun 17 13:46:42 2021 +0200

wgl: remove hard limit on pixelformats

Zink on Intel's Windows driver supports more than 256 pixelformats,
triggering asserts. So let's get rid of the hard-coded limit, and
instead use u_dynarray to store the pixelformat info.

Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11447>

---

 src/gallium/frontends/wgl/stw_device.c      |  2 ++
 src/gallium/frontends/wgl/stw_device.h      |  6 ++----
 src/gallium/frontends/wgl/stw_pixelformat.c | 32 ++++++++++++++++-------------
 3 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/src/gallium/frontends/wgl/stw_device.c b/src/gallium/frontends/wgl/stw_device.c
index b8cfeb8ec9f..b33d9e8cdcf 100644
--- a/src/gallium/frontends/wgl/stw_device.c
+++ b/src/gallium/frontends/wgl/stw_device.c
@@ -228,6 +228,8 @@ stw_cleanup(void)
 
    stw_tls_cleanup();
 
+   util_dynarray_fini(&stw_dev->pixelformats);
+
    stw_dev = NULL;
 }
 
diff --git a/src/gallium/frontends/wgl/stw_device.h b/src/gallium/frontends/wgl/stw_device.h
index b3620f1db58..a0b0419e56e 100644
--- a/src/gallium/frontends/wgl/stw_device.h
+++ b/src/gallium/frontends/wgl/stw_device.h
@@ -31,13 +31,12 @@
 
 #include "pipe/p_compiler.h"
 #include "util/u_handle_table.h"
+#include "util/u_dynarray.h"
 #include <GL/gl.h>
 #include "gldrv.h"
 #include "stw_pixelformat.h"
 
 
-#define STW_MAX_PIXELFORMATS   256
-
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -63,9 +62,8 @@ struct stw_device
 
    LUID AdapterLuid;
 
-   struct stw_pixelformat_info pixelformats[STW_MAX_PIXELFORMATS];
+   struct util_dynarray pixelformats;
    unsigned pixelformat_count;
-   unsigned pixelformat_extended_count;
 
    struct WGLCALLBACKS callbacks;
 
diff --git a/src/gallium/frontends/wgl/stw_pixelformat.c b/src/gallium/frontends/wgl/stw_pixelformat.c
index ce4216d2fb0..ca2a50c7713 100644
--- a/src/gallium/frontends/wgl/stw_pixelformat.c
+++ b/src/gallium/frontends/wgl/stw_pixelformat.c
@@ -141,10 +141,6 @@ stw_pixelformat_add(struct stw_device *stw_dev,
 {
    struct stw_pixelformat_info *pfi;
 
-   assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS);
-   if (stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS)
-      return;
-
    assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 0) == color->bits.red);
    assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 1) == color->bits.green);
    assert(util_format_get_component_bits(color->format, UTIL_FORMAT_COLORSPACE_RGB, 2) == color->bits.blue);
@@ -152,7 +148,9 @@ stw_pixelformat_add(struct stw_device *stw_dev,
    assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 0) == depth->bits.depth);
    assert(util_format_get_component_bits(depth->format, UTIL_FORMAT_COLORSPACE_ZS, 1) == depth->bits.stencil);
 
-   pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count];
+   pfi = util_dynarray_grow(&stw_dev->pixelformats,
+                            struct stw_pixelformat_info,
+                            1);
 
    memset(pfi, 0, sizeof *pfi);
 
@@ -223,11 +221,11 @@ stw_pixelformat_add(struct stw_device *stw_dev,
 
    pfi->bindToTextureRGB = TRUE;
 
-   ++stw_dev->pixelformat_extended_count;
-
    if (!extended) {
       ++stw_dev->pixelformat_count;
-      assert(stw_dev->pixelformat_count == stw_dev->pixelformat_extended_count);
+      assert(stw_dev->pixelformat_count ==
+             util_dynarray_num_elements(&stw_dev->pixelformats,
+                                        struct stw_pixelformat_info));
    }
 }
 
@@ -314,7 +312,8 @@ stw_pixelformat_init(void)
    unsigned num_formats;
 
    assert(!stw_dev->pixelformat_count);
-   assert(!stw_dev->pixelformat_extended_count);
+
+   util_dynarray_init(&stw_dev->pixelformats, NULL);
 
    /* normal, displayable formats */
    num_formats = add_color_format_variants(stw_pf_color,
@@ -325,8 +324,9 @@ stw_pixelformat_init(void)
    add_color_format_variants(stw_pf_color_extended,
                              ARRAY_SIZE(stw_pf_color_extended), TRUE);
 
-   assert(stw_dev->pixelformat_count <= stw_dev->pixelformat_extended_count);
-   assert(stw_dev->pixelformat_extended_count <= STW_MAX_PIXELFORMATS);
+   assert(stw_dev->pixelformat_count <=
+          util_dynarray_num_elements(&stw_dev->pixelformats,
+                                     struct stw_pixelformat_info));
 }
 
 
@@ -346,7 +346,8 @@ stw_pixelformat_get_extended_count(HDC hdc)
    if (!stw_init_screen(hdc))
       return 0;
 
-   return stw_dev->pixelformat_extended_count;
+   return util_dynarray_num_elements(&stw_dev->pixelformats,
+                                     struct stw_pixelformat_info);
 }
 
 
@@ -360,11 +361,14 @@ stw_pixelformat_get_info(int iPixelFormat)
    }
 
    index = iPixelFormat - 1;
-   if (index >= stw_dev->pixelformat_extended_count) {
+   if (index >= util_dynarray_num_elements(&stw_dev->pixelformats,
+                                           struct stw_pixelformat_info)) {
       return NULL;
    }
 
-   return &stw_dev->pixelformats[index];
+   return util_dynarray_element(&stw_dev->pixelformats,
+                                struct stw_pixelformat_info,
+                                index);
 }
 
 



More information about the mesa-commit mailing list