From 91a1849ff04fc6b7b921a303823a111196ff8559 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 17 Jun 2021 13:46:42 +0200 Subject: [PATCH] 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 Part-of: --- 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 b8cfeb8..b33d9e8 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 b3620f1..a0b0419 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 #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 ce4216d..ca2a50c 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); } -- 2.7.4