Skip to content

Commit

Permalink
[d3d11] Add stub IDXGIKeyedMutex interface. (#3601)
Browse files Browse the repository at this point in the history
Partially based on a patch by Derek Lesho.

Co-authored-by: Paul Gofman <pgofman@codeweavers.com>
  • Loading branch information
gofman and Paul Gofman committed Aug 7, 2023
1 parent 549bd86 commit cbda22a
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 4 deletions.
100 changes: 99 additions & 1 deletion src/d3d11/d3d11_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,97 @@

namespace dxvk {

D3D11DXGIKeyedMutex::D3D11DXGIKeyedMutex(
ID3D11Resource* pResource)
: m_resource(pResource) {

}


D3D11DXGIKeyedMutex::~D3D11DXGIKeyedMutex() {

}


ULONG STDMETHODCALLTYPE D3D11DXGIKeyedMutex::AddRef() {
return m_resource->AddRef();
}


ULONG STDMETHODCALLTYPE D3D11DXGIKeyedMutex::Release() {
return m_resource->Release();
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::QueryInterface(
REFIID riid,
void** ppvObject) {
return m_resource->QueryInterface(riid, ppvObject);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::GetPrivateData(
REFGUID Name,
UINT* pDataSize,
void* pData) {
return m_resource->GetPrivateData(Name, pDataSize, pData);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::SetPrivateData(
REFGUID Name,
UINT DataSize,
const void* pData) {
return m_resource->SetPrivateData(Name, DataSize, pData);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::SetPrivateDataInterface(
REFGUID Name,
const IUnknown* pUnknown) {
return m_resource->SetPrivateDataInterface(Name, pUnknown);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::GetParent(
REFIID riid,
void** ppParent) {
return GetDevice(riid, ppParent);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::GetDevice(
REFIID riid,
void** ppDevice) {
Com<ID3D11Device> device;
m_resource->GetDevice(&device);
return device->QueryInterface(riid, ppDevice);
}


HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::AcquireSync(
UINT64 Key,
DWORD dwMilliseconds) {
if (!m_warned) {
m_warned = true;
Logger::err("D3D11DXGIKeyedMutex::AcquireSync: Stub");
}
return S_OK;
}

HRESULT STDMETHODCALLTYPE D3D11DXGIKeyedMutex::ReleaseSync(
UINT64 Key) {
if (!m_warned) {
m_warned = true;
Logger::err("D3D11DXGIKeyedMutex::AcquireSync: Stub");
}
return S_OK;
}

D3D11DXGIResource::D3D11DXGIResource(
ID3D11Resource* pResource)
: m_resource(pResource) {
: m_resource(pResource),
m_keyedMutex(pResource) {

}

Expand Down Expand Up @@ -176,6 +264,16 @@ namespace dxvk {
}


HRESULT D3D11DXGIResource::GetKeyedMutex(
void **ppvObject) {
auto texture = GetCommonTexture(m_resource);
if (texture == nullptr || !(texture->Desc()->MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX))
return E_NOINTERFACE;
*ppvObject = ref(&m_keyedMutex);
return S_OK;
}


HRESULT GetResource11on12Info(
ID3D11Resource* pResource,
D3D11_ON_12_RESOURCE_INFO* p11on12Info) {
Expand Down
61 changes: 60 additions & 1 deletion src/d3d11/d3d11_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,62 @@ namespace dxvk {
};


/**
* \brief IDXGIKeyedMutex implementation
*/
class D3D11DXGIKeyedMutex : public IDXGIKeyedMutex {

public:

D3D11DXGIKeyedMutex(
ID3D11Resource* pResource);

~D3D11DXGIKeyedMutex();

ULONG STDMETHODCALLTYPE AddRef();

ULONG STDMETHODCALLTYPE Release();

HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject);

HRESULT STDMETHODCALLTYPE GetPrivateData(
REFGUID Name,
UINT* pDataSize,
void* pData);

HRESULT STDMETHODCALLTYPE SetPrivateData(
REFGUID Name,
UINT DataSize,
const void* pData);

HRESULT STDMETHODCALLTYPE SetPrivateDataInterface(
REFGUID Name,
const IUnknown* pUnknown);

HRESULT STDMETHODCALLTYPE GetParent(
REFIID riid,
void** ppParent);

HRESULT STDMETHODCALLTYPE GetDevice(
REFIID riid,
void** ppDevice);

HRESULT STDMETHODCALLTYPE AcquireSync(
UINT64 Key,
DWORD dwMilliseconds);

HRESULT STDMETHODCALLTYPE ReleaseSync(
UINT64 Key);

private:

ID3D11Resource* m_resource;
bool m_warned = false;
};


/**
* \brief IDXGIResource implementation for D3D11 resources
*/
Expand Down Expand Up @@ -86,9 +142,12 @@ namespace dxvk {
UINT index,
IDXGISurface2** ppSurface);

HRESULT GetKeyedMutex(void **ppvObject);

private:

ID3D11Resource* m_resource;
D3D11DXGIKeyedMutex m_keyedMutex;

};

Expand Down Expand Up @@ -272,4 +331,4 @@ namespace dxvk {

};

}
}
13 changes: 11 additions & 2 deletions src/d3d11/d3d11_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,10 @@ namespace dxvk {
*ppvObject = ref(&m_resource);
return S_OK;
}


if (riid == __uuidof(IDXGIKeyedMutex))
return m_resource.GetKeyedMutex(ppvObject);

if (riid == __uuidof(IDXGIVkInteropSurface)) {
*ppvObject = ref(&m_interop);
return S_OK;
Expand Down Expand Up @@ -1307,6 +1310,9 @@ namespace dxvk {
*ppvObject = ref(&m_resource);
return S_OK;
}

if (riid == __uuidof(IDXGIKeyedMutex))
return m_resource.GetKeyedMutex(ppvObject);

if (riid == __uuidof(IDXGIVkInteropSurface)) {
*ppvObject = ref(&m_interop);
Expand Down Expand Up @@ -1418,7 +1424,10 @@ namespace dxvk {
*ppvObject = ref(&m_resource);
return S_OK;
}


if (riid == __uuidof(IDXGIKeyedMutex))
return m_resource.GetKeyedMutex(ppvObject);

if (riid == __uuidof(IDXGIVkInteropSurface)) {
*ppvObject = ref(&m_interop);
return S_OK;
Expand Down

0 comments on commit cbda22a

Please sign in to comment.