gallium, windows: Use HANDLE instead of FD for external objects

Reviewed-by: Emma Anholt <emma@anholt.net>
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13054>
This commit is contained in:
Jesse Natalie 2021-09-22 12:06:58 -07:00 committed by Marge Bot
parent 5bfbf4bec9
commit 2771fd4a3f
5 changed files with 21 additions and 2 deletions

View file

@ -1103,7 +1103,7 @@ llvmpipe_resource_get_param(struct pipe_screen *screen,
if (!llvmpipe_resource_get_handle(screen, context, resource, &whandle, handle_usage)) if (!llvmpipe_resource_get_handle(screen, context, resource, &whandle, handle_usage))
return false; return false;
*value = whandle.handle; *value = (uint64_t)whandle.handle;
return true; return true;
default: default:
break; break;

View file

@ -668,6 +668,7 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
mai.pNext = &emai; mai.pNext = &emai;
} }
#ifdef ZINK_USE_DMABUF
VkImportMemoryFdInfoKHR imfi = { VkImportMemoryFdInfoKHR imfi = {
VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR, VK_STRUCTURE_TYPE_IMPORT_MEMORY_FD_INFO_KHR,
NULL, NULL,
@ -685,6 +686,7 @@ resource_object_create(struct zink_screen *screen, const struct pipe_resource *t
imfi.pNext = mai.pNext; imfi.pNext = mai.pNext;
mai.pNext = &imfi; mai.pNext = &imfi;
} }
#endif
struct wsi_memory_allocate_info memory_wsi_info = { struct wsi_memory_allocate_info memory_wsi_info = {
VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA, VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA,
@ -931,6 +933,7 @@ zink_resource_get_param(struct pipe_screen *pscreen, struct pipe_context *pctx,
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED: case PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED:
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS: case PIPE_RESOURCE_PARAM_HANDLE_TYPE_KMS:
case PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD: { case PIPE_RESOURCE_PARAM_HANDLE_TYPE_FD: {
#ifdef ZINK_USE_DMABUF
memset(&whandle, 0, sizeof(whandle)); memset(&whandle, 0, sizeof(whandle));
if (param == PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED) if (param == PIPE_RESOURCE_PARAM_HANDLE_TYPE_SHARED)
whandle.type = WINSYS_HANDLE_TYPE_SHARED; whandle.type = WINSYS_HANDLE_TYPE_SHARED;
@ -944,6 +947,10 @@ zink_resource_get_param(struct pipe_screen *pscreen, struct pipe_context *pctx,
*value = whandle.handle; *value = whandle.handle;
break; break;
#else
(void)whandle;
return false;
#endif
} }
} }
return true; return true;

View file

@ -2,6 +2,10 @@
#ifndef _WINSYS_HANDLE_H_ #ifndef _WINSYS_HANDLE_H_
#define _WINSYS_HANDLE_H_ #define _WINSYS_HANDLE_H_
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -9,6 +13,8 @@ extern "C" {
#define WINSYS_HANDLE_TYPE_SHARED 0 #define WINSYS_HANDLE_TYPE_SHARED 0
#define WINSYS_HANDLE_TYPE_KMS 1 #define WINSYS_HANDLE_TYPE_KMS 1
#define WINSYS_HANDLE_TYPE_FD 2 #define WINSYS_HANDLE_TYPE_FD 2
/* Win32 handles serve the same purpose as FD, just on Windows, so alias the value */
#define WINSYS_HANDLE_TYPE_WIN32_HANDLE WINSYS_HANDLE_TYPE_FD
#define WINSYS_HANDLE_TYPE_SHMID 3 #define WINSYS_HANDLE_TYPE_SHMID 3
#define WINSYS_HANDLE_TYPE_D3D12_RES 4 #define WINSYS_HANDLE_TYPE_D3D12_RES 4
@ -38,7 +44,11 @@ struct winsys_handle
* Input to texture_from_handle. * Input to texture_from_handle.
* Output for texture_get_handle. * Output for texture_get_handle.
*/ */
#ifdef _WIN32
HANDLE handle;
#else
unsigned handle; unsigned handle;
#endif
/** /**
* Input to texture_from_handle. * Input to texture_from_handle.
* Output for texture_get_handle. * Output for texture_get_handle.

View file

@ -70,6 +70,7 @@ st_import_memoryobj_fd(struct gl_context *ctx,
GLuint64 size, GLuint64 size,
int fd) int fd)
{ {
#if !defined(_WIN32)
struct st_memory_object *st_obj = st_memory_object(obj); struct st_memory_object *st_obj = st_memory_object(obj);
struct st_context *st = st_context(ctx); struct st_context *st = st_context(ctx);
struct pipe_screen *screen = st->screen; struct pipe_screen *screen = st->screen;
@ -85,7 +86,6 @@ st_import_memoryobj_fd(struct gl_context *ctx,
&whandle, &whandle,
obj->Dedicated); obj->Dedicated);
#if !defined(_WIN32)
/* We own fd, but we no longer need it. So get rid of it */ /* We own fd, but we no longer need it. So get rid of it */
close(fd); close(fd);
#endif #endif

View file

@ -844,7 +844,9 @@ void st_init_extensions(struct pipe_screen *screen,
{ o(EXT_disjoint_timer_query), PIPE_CAP_QUERY_TIMESTAMP }, { o(EXT_disjoint_timer_query), PIPE_CAP_QUERY_TIMESTAMP },
{ o(EXT_draw_buffers2), PIPE_CAP_INDEP_BLEND_ENABLE }, { o(EXT_draw_buffers2), PIPE_CAP_INDEP_BLEND_ENABLE },
{ o(EXT_memory_object), PIPE_CAP_MEMOBJ }, { o(EXT_memory_object), PIPE_CAP_MEMOBJ },
#ifndef _WIN32
{ o(EXT_memory_object_fd), PIPE_CAP_MEMOBJ }, { o(EXT_memory_object_fd), PIPE_CAP_MEMOBJ },
#endif
{ o(EXT_multisampled_render_to_texture), PIPE_CAP_SURFACE_SAMPLE_COUNT }, { o(EXT_multisampled_render_to_texture), PIPE_CAP_SURFACE_SAMPLE_COUNT },
{ o(EXT_semaphore), PIPE_CAP_FENCE_SIGNAL }, { o(EXT_semaphore), PIPE_CAP_FENCE_SIGNAL },
{ o(EXT_semaphore_fd), PIPE_CAP_FENCE_SIGNAL }, { o(EXT_semaphore_fd), PIPE_CAP_FENCE_SIGNAL },