From 5fbdca48b58f54567f967782fbeb0a9debcd596a Mon Sep 17 00:00:00 2001 From: Iouri Tarassov Date: Thu, 28 Oct 2021 14:16:22 -0700 Subject: [PATCH] Added APIs to share object with host and creation of sync files --- include/d3dkmthk.h | 29 ++++++++++++++++++++++++++++- src/d3dkmt-wsl.cpp | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/d3dkmthk.h b/include/d3dkmthk.h index c658d83..d44977a 100644 --- a/include/d3dkmthk.h +++ b/include/d3dkmthk.h @@ -4978,6 +4978,28 @@ typedef struct _D3DKMT_SHAREOBJECTS { D3DKMT_PTR(HANDLE*, pSharedNtHandle); // out } D3DKMT_SHAREOBJECTS; +typedef struct _D3DKMT_SHAREOBJECTWITHHOST +{ + D3DKMT_HANDLE hDevice; // in + D3DKMT_HANDLE hObject; // in + D3DKMT_ALIGN64 UINT64 Reserved; // in Must be zero. Reserved for future use + D3DKMT_ALIGN64 UINT64 hVailProcessNtHandle; // out +} D3DKMT_SHAREOBJECTWITHHOST; + +// +// This API is used to support sync_file in Android. +// A sync_file is a wrapper around the given monitored fence and the fence value. +// When a sync_file is created, a wait for sync object on CPU is issued +// and a file descriptor (FD) it returned to the app. The app can wait on the FD, +// which will be unblocked when the sync object with this fence value is signaled. +// +typedef struct _D3DKMT_CREATESYNCFILE +{ + D3DKMT_HANDLE hDevice; // in: Device owner of the monitored fence. + D3DKMT_HANDLE hMonitoredFence; // in: Monitored fence object + D3DKMT_ALIGN64 UINT64 FenceValue; // in: Fence value to wait for + D3DKMT_ALIGN64 UINT64 hSyncFile; // out: File descriptor on Android or a NT handle on Windows (when implemented) +} D3DKMT_CREATESYNCFILE; typedef struct _D3DKMT_TRIMNOTIFICATION { @@ -5625,9 +5647,14 @@ typedef _Check_return_ NTSTATUS (APIENTRY *PFND3DKMT_DISPLAYPORT_OPERATION)(_Ino typedef _Check_return_ NTSTATUS (APIENTRY *PFND3DKMT_CANCELPRESENTS)(_In_ D3DKMT_CANCEL_PRESENTS*); - #endif +EXTERN_C _Check_return_ NTSTATUS APIENTRY D3DKMTShareObjectWithHost(_Inout_ D3DKMT_SHAREOBJECTWITHHOST*); +EXTERN_C _Check_return_ NTSTATUS APIENTRY D3DKMTCreateSyncFile(_Inout_ D3DKMT_CREATESYNCFILE*); + +// Used in WSL to close the internal file descriptor to /dev/dxg +EXTERN_C VOID APIENTRY D3DKMTCloseDxCoreDevice(); + #if !defined(D3DKMDT_SPECIAL_MULTIPLATFORM_TOOL) #ifdef __cplusplus diff --git a/src/d3dkmt-wsl.cpp b/src/d3dkmt-wsl.cpp index 9414b62..e17f809 100644 --- a/src/d3dkmt-wsl.cpp +++ b/src/d3dkmt-wsl.cpp @@ -144,6 +144,8 @@ DEFINE_KMT(OpenSyncObjectFromNtHandle2, D3DKMT_OPENSYNCOBJECTFROMNTHANDLE2, 0x40 DEFINE_KMT(QueryResourceInfoFromNtHandle, D3DKMT_QUERYRESOURCEINFOFROMNTHANDLE, 0x41, NONCONST) DEFINE_KMT(OpenResourceFromNtHandle, D3DKMT_OPENRESOURCEFROMNTHANDLE, 0x42, NONCONST) DEFINE_KMT(QueryStatistics, D3DKMT_QUERYSTATISTICS, 0x43, CONST) +DEFINE_KMT(ShareObjectWithHost, D3DKMT_SHAREOBJECTWITHHOST, 0x44, NONCONST) +DEFINE_KMT(CreateSyncFile, D3DKMT_CREATESYNCFILE, 0x45, NONCONST) // Not-implemented thunks (NT handles, or not in the compute interface subset we're using) DEFINE_KMT_NOT_IMPL(GetMultisampleMethodList, D3DKMT_GETMULTISAMPLEMETHODLIST, NONCONST)