From: Igor Torrente Date: Thu, 10 Aug 2023 16:27:46 +0000 (-0300) Subject: zink: Fix one addicional case when running a compositor X-Git-Tag: upstream/23.3.3~3135 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e595c367d5fe5a72c7731204d2e562fc197b3b80;p=platform%2Fupstream%2Fmesa.git zink: Fix one addicional case when running a compositor Covers the case where the `dri2_init_screen` calls `pipe_loader_create_screen_vk` directly and not sets the device major and minor. Signed-off-by: Igor Torrente Part-of: --- diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c index d09eaf3..5b69599 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c @@ -171,8 +171,6 @@ pipe_loader_create_screen_vk(struct pipe_loader_device *dev, bool sw_vk) pipe_loader_load_options(dev); config.options_info = &dev->option_info; config.options = &dev->option_cache; - config.dev_major = dev->dev_major; - config.dev_minor = dev->dev_minor; return dev->ops->create_screen(dev, &config, sw_vk); } diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.h b/src/gallium/auxiliary/pipe-loader/pipe_loader.h index 12d8396..eb3c691 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.h +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.h @@ -64,8 +64,6 @@ struct pipe_loader_device { } pci; } u; /**< Discriminated by \a type */ - int64_t dev_major; - int64_t dev_minor; char *driver_name; const struct pipe_loader_ops *ops; diff --git a/src/gallium/drivers/zink/zink_screen.c b/src/gallium/drivers/zink/zink_screen.c index d73edd2..11bc6c5 100644 --- a/src/gallium/drivers/zink/zink_screen.c +++ b/src/gallium/drivers/zink/zink_screen.c @@ -50,6 +50,13 @@ #include "util/u_cpu_detect.h" +#ifdef HAVE_LIBDRM +#include +#include +#include +#include +#endif + static int num_screens = 0; bool zink_tracing = false; @@ -2852,7 +2859,7 @@ zink_screen_get_fd(struct pipe_screen *pscreen) } static struct zink_screen * -zink_internal_create_screen(const struct pipe_screen_config *config) +zink_internal_create_screen(const struct pipe_screen_config *config, int64_t dev_major, int64_t dev_minor) { if (getenv("ZINK_USE_LAVAPIPE")) { mesa_loge("ZINK_USE_LAVAPIPE is obsolete. Use LIBGL_ALWAYS_SOFTWARE\n"); @@ -2904,7 +2911,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config) screen->driconf.zink_shader_object_enable = driQueryOptionb(config->options, "zink_shader_object_enable"); } - if (!zink_create_instance(screen, config && config->dev_major > 0 && config->dev_major < 255)) + if (!zink_create_instance(screen, dev_major > 0 && dev_major < 255)) goto fail; if (zink_debug & ZINK_DEBUG_VALIDATION) { @@ -2928,7 +2935,7 @@ zink_internal_create_screen(const struct pipe_screen_config *config) (zink_debug & ZINK_DEBUG_VALIDATION) && !create_debug(screen)) debug_printf("ZINK: failed to setup debug utils\n"); - choose_pdev(screen, config ? config->dev_major : 0, config ? config->dev_minor : 0); + choose_pdev(screen, dev_major, dev_minor); if (screen->pdev == VK_NULL_HANDLE) { mesa_loge("ZINK: failed to choose pdev"); goto fail; @@ -3282,7 +3289,7 @@ fail: struct pipe_screen * zink_create_screen(struct sw_winsys *winsys, const struct pipe_screen_config *config) { - struct zink_screen *ret = zink_internal_create_screen(config); + struct zink_screen *ret = zink_internal_create_screen(config, -1, -1); if (ret) { ret->drm_fd = -1; } @@ -3290,10 +3297,51 @@ zink_create_screen(struct sw_winsys *winsys, const struct pipe_screen_config *co return &ret->base; } +static inline int +zink_render_rdev(int fd, int64_t *dev_major, int64_t *dev_minor) +{ + int ret = 0; + *dev_major = *dev_minor = -1; +#ifdef HAVE_LIBDRM + struct stat stx; + drmDevicePtr dev; + + if (fd == -1) + return 0; + + if (drmGetDevice2(fd, 0, &dev)) + return -1; + + if(!(dev->available_nodes & (1 << DRM_NODE_RENDER))) { + ret = -1; + goto free_device; + } + + if(stat(dev->nodes[DRM_NODE_RENDER], &stx)) { + ret = -1; + goto free_device; + } + + *dev_major = major(stx.st_rdev); + *dev_minor = minor(stx.st_rdev); + +free_device: + drmFreeDevice(&dev); +#endif //HAVE_LIBDRM + + return ret; +} + struct pipe_screen * zink_drm_create_screen(int fd, const struct pipe_screen_config *config) { - struct zink_screen *ret = zink_internal_create_screen(config); + int64_t dev_major, dev_minor; + struct zink_screen *ret; + + if (zink_render_rdev(fd, &dev_major, &dev_minor)) + return NULL; + + ret = zink_internal_create_screen(config, dev_major, dev_minor); if (ret) ret->drm_fd = os_dupfd_cloexec(fd); diff --git a/src/gallium/frontends/dri/kopper.c b/src/gallium/frontends/dri/kopper.c index 27c897f..e831028 100644 --- a/src/gallium/frontends/dri/kopper.c +++ b/src/gallium/frontends/dri/kopper.c @@ -43,13 +43,6 @@ #include -#ifdef HAVE_LIBDRM -#include -#include -#include -#include -#endif - #ifdef VK_USE_PLATFORM_XCB_KHR #include #include @@ -116,43 +109,6 @@ static const __DRIextension *drivk_sw_screen_extensions[] = { NULL }; -static int -kopper_render_rdev(int fd, struct pipe_loader_device *pipe_loader) -{ - int ret = 0; - pipe_loader->dev_major = -1; - pipe_loader->dev_minor = -1; - -#ifdef HAVE_LIBDRM - struct stat stx; - drmDevicePtr dev; - - if (fd == -1) - return 0; - - if (drmGetDevice2(fd, 0, &dev)) - return -1; - - if(!(dev->available_nodes & (1 << DRM_NODE_RENDER))) { - ret = -1; - goto free_device; - } - - if(stat(dev->nodes[DRM_NODE_RENDER], &stx)) { - ret = -1; - goto free_device; - } - - pipe_loader->dev_major = major(stx.st_rdev); - pipe_loader->dev_minor = minor(stx.st_rdev); - -free_device: - drmFreeDevice(&dev); -#endif //HAVE_LIBDRM - - return ret; -} - static const __DRIconfig ** kopper_init_screen(struct dri_screen *screen) { @@ -174,11 +130,8 @@ kopper_init_screen(struct dri_screen *screen) else success = pipe_loader_vk_probe_dri(&screen->dev, NULL); - if (success) { - if (kopper_render_rdev(screen->fd, screen->dev)) - goto fail; + if (success) pscreen = pipe_loader_create_screen(screen->dev); - } if (!pscreen) goto fail; diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h index bdd40fe..0c3c096 100644 --- a/src/gallium/include/pipe/p_screen.h +++ b/src/gallium/include/pipe/p_screen.h @@ -799,8 +799,6 @@ struct pipe_screen { struct pipe_screen_config { struct driOptionCache *options; const struct driOptionCache *options_info; - int64_t dev_major; - int64_t dev_minor; };