From 26a6d16db0f9512f719a40529acf46c0277e877e Mon Sep 17 00:00:00 2001 From: Yonggang Luo Date: Thu, 3 Nov 2022 06:32:23 +0800 Subject: [PATCH] zink: Only #include instead #include in kopper_interface.h It's pulled too much system dependent headers before this commit when #include directly, Signed-off-by: Yonggang Luo Reviewed-by: Adam Jackson Part-of: --- include/kopper_interface.h | 40 ++++++++---------- src/egl/drivers/dri2/platform_wayland.c | 5 ++- src/egl/drivers/dri2/platform_x11.c | 14 ++++--- src/gallium/drivers/zink/zink_kopper.c | 54 ++++++++++++++++--------- src/gallium/frontends/dri/kopper.c | 5 ++- src/gallium/frontends/wgl/stw_st.c | 15 ++++--- src/glx/drisw_glx.c | 14 ++++--- 7 files changed, 88 insertions(+), 59 deletions(-) diff --git a/include/kopper_interface.h b/include/kopper_interface.h index 33826e6ff33..3db53e8d52c 100644 --- a/include/kopper_interface.h +++ b/include/kopper_interface.h @@ -35,17 +35,7 @@ #define KOPPER_INTERFACE_H #include -#include -#ifdef VK_USE_PLATFORM_XCB_KHR -#include -#include -#endif -#ifdef VK_USE_PLATFORM_WAYLAND_KHR -#include -#endif -#ifdef VK_USE_PLATFORM_WIN32_KHR -#include -#endif +#include typedef struct __DRIkopperExtensionRec __DRIkopperExtension; typedef struct __DRIkopperLoaderExtensionRec __DRIkopperLoaderExtension; @@ -80,19 +70,23 @@ struct __DRIkopperExtensionRec { * Kopper loader extension. */ +/** + * struct for storage the union of all platform depdendent + * Vk*SurfaceCreateInfo* type, all platform Vk*SurfaceCreateInfo* contains + * uint32_t flags and at most two extra pointer besides bos header. + * For example: + * VkWin32SurfaceCreateInfoKHR contains flags, hinstance and hwnd besides bos header + */ + +struct kopper_vk_surface_create_storage { + /* First two fields are copied from VkBaseOutStructure for easily access shared properties */ + VkStructureType sType; + struct VkBaseOutStructure *pNext; + intptr_t padding[3]; +}; + struct kopper_loader_info { - union { - VkBaseOutStructure bos; -#ifdef VK_USE_PLATFORM_XCB_KHR - VkXcbSurfaceCreateInfoKHR xcb; -#endif -#ifdef VK_USE_PLATFORM_WAYLAND_KHR - VkWaylandSurfaceCreateInfoKHR wl; -#endif -#ifdef VK_USE_PLATFORM_WIN32_KHR - VkWin32SurfaceCreateInfoKHR win32; -#endif - }; + struct kopper_vk_surface_create_storage bos; int has_alpha; int initial_swap_interval; }; diff --git a/src/egl/drivers/dri2/platform_wayland.c b/src/egl/drivers/dri2/platform_wayland.c index 93bb97c54e0..260eb9c82af 100644 --- a/src/egl/drivers/dri2/platform_wayland.c +++ b/src/egl/drivers/dri2/platform_wayland.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include "drm-uapi/drm_fourcc.h" @@ -2653,12 +2654,14 @@ static const __DRIswrastLoaderExtension swrast_loader_extension = { .putImage2 = dri2_wl_swrast_put_image2, }; +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkWaylandSurfaceCreateInfoKHR), ""); + static void kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *out) { struct dri2_egl_surface *dri2_surf = _draw; struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); - VkWaylandSurfaceCreateInfoKHR *wlsci = &out->wl; + VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&out->bos; wlsci->sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR; wlsci->pNext = NULL; diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c index 77c414823ac..6e050c0928f 100644 --- a/src/egl/drivers/dri2/platform_x11.c +++ b/src/egl/drivers/dri2/platform_x11.c @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef HAVE_LIBDRM #include #endif @@ -1323,19 +1324,22 @@ static const __DRIswrastLoaderExtension swrast_loader_extension = { .getImage = swrastGetImage, }; +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkXcbSurfaceCreateInfoKHR), ""); + static void kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *ci) { struct dri2_egl_surface *dri2_surf = _draw; struct dri2_egl_display *dri2_dpy = dri2_egl_display(dri2_surf->base.Resource.Display); + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&ci->bos; if (dri2_surf->base.Type != EGL_WINDOW_BIT) return; - ci->xcb.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - ci->xcb.pNext = NULL; - ci->xcb.flags = 0; - ci->xcb.connection = dri2_dpy->conn; - ci->xcb.window = dri2_surf->drawable; + xcb->sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + xcb->pNext = NULL; + xcb->flags = 0; + xcb->connection = dri2_dpy->conn; + xcb->window = dri2_surf->drawable; ci->has_alpha = dri2_surf->depth == 32; } diff --git a/src/gallium/drivers/zink/zink_kopper.c b/src/gallium/drivers/zink/zink_kopper.c index f9c0a21ee51..992686cd31e 100644 --- a/src/gallium/drivers/zink/zink_kopper.c +++ b/src/gallium/drivers/zink/zink_kopper.c @@ -85,19 +85,25 @@ kopper_CreateSurface(struct zink_screen *screen, struct kopper_displaytarget *cd VkStructureType type = cdt->info.bos.sType; switch (type) { #ifdef VK_USE_PLATFORM_XCB_KHR - case VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR: - error = VKSCR(CreateXcbSurfaceKHR)(screen->instance, &cdt->info.xcb, NULL, &surface); + case VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR: { + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&cdt->info.bos; + error = VKSCR(CreateXcbSurfaceKHR)(screen->instance, xcb, NULL, &surface); break; + } #endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR - case VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR: - error = VKSCR(CreateWaylandSurfaceKHR)(screen->instance, &cdt->info.wl, NULL, &surface); + case VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR: { + VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&cdt->info.bos; + error = VKSCR(CreateWaylandSurfaceKHR)(screen->instance, wlsci, NULL, &surface); break; + } #endif #ifdef VK_USE_PLATFORM_WIN32_KHR - case VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR: - error = VKSCR(CreateWin32SurfaceKHR)(screen->instance, &cdt->info.win32, NULL, &surface); + case VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR: { + VkWin32SurfaceCreateInfoKHR *win32 = (VkWin32SurfaceCreateInfoKHR *)&cdt->info.bos; + error = VKSCR(CreateWin32SurfaceKHR)(screen->instance, win32, NULL, &surface); break; + } #endif default: unreachable("unsupported!"); @@ -176,19 +182,25 @@ find_dt_entry(struct zink_screen *screen, const struct kopper_displaytarget *cdt struct hash_entry *he = NULL; switch (cdt->type) { #ifdef VK_USE_PLATFORM_XCB_KHR - case KOPPER_X11: - he = _mesa_hash_table_search_pre_hashed(&screen->dts, cdt->info.xcb.window, (void*)(uintptr_t)cdt->info.xcb.window); + case KOPPER_X11: { + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&cdt->info.bos; + he = _mesa_hash_table_search_pre_hashed(&screen->dts, xcb->window, (void*)(uintptr_t)xcb->window); break; + } #endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR - case KOPPER_WAYLAND: - he = _mesa_hash_table_search(&screen->dts, cdt->info.wl.surface); + case KOPPER_WAYLAND: { + VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&cdt->info.bos; + he = _mesa_hash_table_search(&screen->dts, wlsci->surface); break; + } #endif #ifdef VK_USE_PLATFORM_WIN32_KHR - case KOPPER_WIN32: - he = _mesa_hash_table_search(&screen->dts, cdt->info.win32.hwnd); + case KOPPER_WIN32: { + VkWin32SurfaceCreateInfoKHR *win32 = (VkWin32SurfaceCreateInfoKHR *)&cdt->info.bos; + he = _mesa_hash_table_search(&screen->dts, win32->hwnd); break; + } #endif default: unreachable("unsupported!"); @@ -425,19 +437,25 @@ zink_kopper_displaytarget_create(struct zink_screen *screen, unsigned tex_usage, simple_mtx_lock(&screen->dt_lock); switch (cdt->type) { #ifdef VK_USE_PLATFORM_XCB_KHR - case KOPPER_X11: - _mesa_hash_table_insert_pre_hashed(&screen->dts, cdt->info.xcb.window, (void*)(uintptr_t)cdt->info.xcb.window, cdt); + case KOPPER_X11: { + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&cdt->info.bos; + _mesa_hash_table_insert_pre_hashed(&screen->dts, xcb->window, (void*)(uintptr_t)xcb->window, cdt); break; + } #endif #ifdef VK_USE_PLATFORM_WAYLAND_KHR - case KOPPER_WAYLAND: - _mesa_hash_table_insert(&screen->dts, cdt->info.wl.surface, cdt); + case KOPPER_WAYLAND: { + VkWaylandSurfaceCreateInfoKHR *wlsci = (VkWaylandSurfaceCreateInfoKHR *)&cdt->info.bos; + _mesa_hash_table_insert(&screen->dts, wlsci->surface, cdt); break; + } #endif #ifdef VK_USE_PLATFORM_WIN32_KHR - case KOPPER_WIN32: - _mesa_hash_table_insert(&screen->dts, cdt->info.win32.hwnd, cdt); + case KOPPER_WIN32: { + VkWin32SurfaceCreateInfoKHR *win32 = (VkWin32SurfaceCreateInfoKHR *)&cdt->info.bos; + _mesa_hash_table_insert(&screen->dts, win32->hwnd, cdt); break; + } #endif default: unreachable("unsupported!"); diff --git a/src/gallium/frontends/dri/kopper.c b/src/gallium/frontends/dri/kopper.c index 0102e2cf477..1e90eb486a5 100644 --- a/src/gallium/frontends/dri/kopper.c +++ b/src/gallium/frontends/dri/kopper.c @@ -421,8 +421,9 @@ kopper_get_pixmap_buffer(struct kopper_drawable *cdraw, __DRIscreen *cur_screen; struct kopper_loader_info *info = &cdraw->info; assert(info->bos.sType == VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR); - xcb_connection_t *conn = info->xcb.connection; - pixmap = info->xcb.window; + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&info->bos; + xcb_connection_t *conn = xcb->connection; + pixmap = xcb->window; if (cdraw->image) return cdraw->image->texture; diff --git a/src/gallium/frontends/wgl/stw_st.c b/src/gallium/frontends/wgl/stw_st.c index 366b5fd06f7..e7862e4b260 100644 --- a/src/gallium/frontends/wgl/stw_st.c +++ b/src/gallium/frontends/wgl/stw_st.c @@ -37,6 +37,7 @@ #include "stw_winsys.h" #ifdef GALLIUM_ZINK +#include #include "kopper_interface.h" #endif @@ -125,14 +126,18 @@ stw_pipe_blit(struct pipe_context *pipe, } #ifdef GALLIUM_ZINK + +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkWin32SurfaceCreateInfoKHR), ""); + static void stw_st_fill_private_loader_data(struct stw_st_framebuffer *stwfb, struct kopper_loader_info *out) { - out->win32.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; - out->win32.pNext = NULL; - out->win32.flags = 0; - out->win32.hinstance = GetModuleHandle(NULL); - out->win32.hwnd = stwfb->fb->hWnd; + VkWin32SurfaceCreateInfoKHR *win32 = (VkWin32SurfaceCreateInfoKHR *)&out->bos; + win32->sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; + win32->pNext = NULL; + win32->flags = 0; + win32->hinstance = GetModuleHandle(NULL); + win32->hwnd = stwfb->fb->hWnd; out->has_alpha = true; } #endif diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c index c124c62c31e..cc01fcdea1c 100644 --- a/src/glx/drisw_glx.c +++ b/src/glx/drisw_glx.c @@ -33,6 +33,7 @@ #include "drisw_priv.h" #include #include +#include #include "util/u_debug.h" #include "kopper_interface.h" #include "loader_dri_helper.h" @@ -367,16 +368,19 @@ static const __DRIswrastLoaderExtension swrastLoaderExtension = { .getImage2 = swrastGetImage2, }; +static_assert(sizeof(struct kopper_vk_surface_create_storage) >= sizeof(VkXcbSurfaceCreateInfoKHR), ""); + static void kopperSetSurfaceCreateInfo(void *_draw, struct kopper_loader_info *out) { __GLXDRIdrawable *draw = _draw; + VkXcbSurfaceCreateInfoKHR *xcb = (VkXcbSurfaceCreateInfoKHR *)&out->bos; - out->xcb.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; - out->xcb.pNext = NULL; - out->xcb.flags = 0; - out->xcb.connection = XGetXCBConnection(draw->psc->dpy); - out->xcb.window = draw->xDrawable; + xcb->sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR; + xcb->pNext = NULL; + xcb->flags = 0; + xcb->connection = XGetXCBConnection(draw->psc->dpy); + xcb->window = draw->xDrawable; } static const __DRIkopperLoaderExtension kopperLoaderExtension = {