wgl: remove hard limit on pixelformats
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Thu, 17 Jun 2021 11:46:42 +0000 (13:46 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 22 Jun 2021 06:57:03 +0000 (06:57 +0000)
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@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11447>

src/gallium/frontends/wgl/stw_device.c
src/gallium/frontends/wgl/stw_device.h
src/gallium/frontends/wgl/stw_pixelformat.c

index b8cfeb8..b33d9e8 100644 (file)
@@ -228,6 +228,8 @@ stw_cleanup(void)
 
    stw_tls_cleanup();
 
+   util_dynarray_fini(&stw_dev->pixelformats);
+
    stw_dev = NULL;
 }
 
index b3620f1..a0b0419 100644 (file)
 
 #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;
 
index ce4216d..ca2a50c 100644 (file)
@@ -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);
 }