1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 10:24:10 +01:00

[d3d11] Always export correct shared handle type from ::GetSharedHandle and ::CreateSharedHandle

Before we just assumed that the calls here would match the corresponding flag value (D3D11_RESOURCE_MISC_SHARED -> ::GetSharedHandle, D3D11_RESOURCE_MISC_SHARED_NTHANDLE -> ::CreateSharedHandle), but it turns out that its possible to set both flags and use both methods.  Now we always tell Vulkan to export a KMT handle if D3D11_RESOURCE_MISC_SHARED is present, and use openKmtHandle to get an NT handle when needed.
This commit is contained in:
Derek Lesho 2022-03-28 11:46:47 -04:00 committed by Philip Rebohle
parent 1c3736da8c
commit d11f0ac77b

View File

@ -2,6 +2,8 @@
#include "d3d11_texture.h"
#include "d3d11_resource.h"
#include "../util/util_shared_res.h"
namespace dxvk {
D3D11DXGIResource::D3D11DXGIResource(
@ -82,7 +84,7 @@ namespace dxvk {
HRESULT STDMETHODCALLTYPE D3D11DXGIResource::GetSharedHandle(
HANDLE* pSharedHandle) {
auto texture = GetCommonTexture(m_resource);
if (texture == nullptr || pSharedHandle == nullptr)
if (texture == nullptr || pSharedHandle == nullptr || !(texture->Desc()->MiscFlags & D3D11_RESOURCE_MISC_SHARED))
return E_INVALIDARG;
HANDLE kmtHandle = texture->GetImage()->sharedHandle();
@ -141,7 +143,8 @@ namespace dxvk {
LPCWSTR lpName,
HANDLE* pHandle) {
auto texture = GetCommonTexture(m_resource);
if (texture == nullptr || pHandle == nullptr)
if (texture == nullptr || pHandle == nullptr ||
!(texture->Desc()->MiscFlags & (D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE)))
return E_INVALIDARG;
if (lpName)
@ -152,6 +155,9 @@ namespace dxvk {
if (handle == INVALID_HANDLE_VALUE)
return E_INVALIDARG;
if (texture->Desc()->MiscFlags & D3D11_RESOURCE_MISC_SHARED)
handle = openKmtHandle( handle );
*pHandle = handle;
return S_OK;
}