1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-19 05:52:11 +01:00

[d3d11] Fix reference counting for state objects

Fixes various wine test failures. Also, state objects are now
allocated in the hash map itself rather than a wrapped COM object.
This commit is contained in:
Philip Rebohle 2019-10-14 01:27:59 +02:00
parent accbc8828c
commit 9c6209fbf5
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
9 changed files with 98 additions and 8 deletions

View File

@ -36,6 +36,22 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE D3D11BlendState::AddRef() {
ULONG refCount = m_refCount++;
if (!refCount)
m_device->AddRef();
return refCount;
}
ULONG STDMETHODCALLTYPE D3D11BlendState::Release() {
ULONG refCount = --m_refCount;
if (!refCount)
m_device->Release();
return refCount;
}
HRESULT STDMETHODCALLTYPE D3D11BlendState::QueryInterface(REFIID riid, void** ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;

View File

@ -22,6 +22,10 @@ namespace dxvk {
const D3D11_BLEND_DESC1& desc);
~D3D11BlendState();
ULONG STDMETHODCALLTYPE AddRef() final;
ULONG STDMETHODCALLTYPE Release() final;
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
@ -61,6 +65,8 @@ namespace dxvk {
DxvkLogicOpState m_loState;
D3D10BlendState m_d3d10;
std::atomic<uint32_t> m_refCount = { 0u };
static DxvkBlendMode DecodeBlendMode(
const D3D11_RENDER_TARGET_BLEND_DESC1& BlendDesc);

View File

@ -21,6 +21,22 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE D3D11DepthStencilState::AddRef() {
ULONG refCount = m_refCount++;
if (!refCount)
m_device->AddRef();
return refCount;
}
ULONG STDMETHODCALLTYPE D3D11DepthStencilState::Release() {
ULONG refCount = --m_refCount;
if (!refCount)
m_device->Release();
return refCount;
}
HRESULT STDMETHODCALLTYPE D3D11DepthStencilState::QueryInterface(REFIID riid, void** ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;

View File

@ -22,6 +22,10 @@ namespace dxvk {
const D3D11_DEPTH_STENCIL_DESC& desc);
~D3D11DepthStencilState();
ULONG STDMETHODCALLTYPE AddRef() final;
ULONG STDMETHODCALLTYPE Release() final;
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
@ -50,6 +54,8 @@ namespace dxvk {
D3D11_DEPTH_STENCIL_DESC m_desc;
DxvkDepthStencilState m_state;
D3D10DepthStencilState m_d3d10;
std::atomic<uint32_t> m_refCount = { 0u };
VkStencilOpState DecodeStencilOpState(
const D3D11_DEPTH_STENCILOP_DESC& StencilDesc,

View File

@ -50,6 +50,22 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE D3D11RasterizerState::AddRef() {
ULONG refCount = m_refCount++;
if (!refCount)
m_device->AddRef();
return refCount;
}
ULONG STDMETHODCALLTYPE D3D11RasterizerState::Release() {
ULONG refCount = --m_refCount;
if (!refCount)
m_device->Release();
return refCount;
}
HRESULT STDMETHODCALLTYPE D3D11RasterizerState::QueryInterface(REFIID riid, void** ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;

View File

@ -20,7 +20,11 @@ namespace dxvk {
D3D11Device* device,
const D3D11_RASTERIZER_DESC2& desc);
~D3D11RasterizerState();
ULONG STDMETHODCALLTYPE AddRef() final;
ULONG STDMETHODCALLTYPE Release() final;
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
@ -66,6 +70,8 @@ namespace dxvk {
DxvkRasterizerState m_state;
DxvkDepthBias m_depthBias;
D3D10RasterizerState m_d3d10;
std::atomic<uint32_t> m_refCount = { 0u };
};

View File

@ -59,6 +59,22 @@ namespace dxvk {
}
ULONG STDMETHODCALLTYPE D3D11SamplerState::AddRef() {
ULONG refCount = m_refCount++;
if (!refCount)
m_device->AddRef();
return refCount;
}
ULONG STDMETHODCALLTYPE D3D11SamplerState::Release() {
ULONG refCount = --m_refCount;
if (!refCount)
m_device->Release();
return refCount;
}
HRESULT STDMETHODCALLTYPE D3D11SamplerState::QueryInterface(REFIID riid, void** ppvObject) {
if (ppvObject == nullptr)
return E_POINTER;

View File

@ -21,6 +21,10 @@ namespace dxvk {
const D3D11_SAMPLER_DESC& desc);
~D3D11SamplerState();
ULONG STDMETHODCALLTYPE AddRef() final;
ULONG STDMETHODCALLTYPE Release() final;
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID riid,
void** ppvObject) final;
@ -49,6 +53,8 @@ namespace dxvk {
Rc<DxvkSampler> m_sampler;
D3D10SamplerState m_d3d10;
std::atomic<uint32_t> m_refCount = { 0u };
static bool ValidateAddressMode(
D3D11_TEXTURE_ADDRESS_MODE Mode);

View File

@ -56,20 +56,22 @@ namespace dxvk {
T* Create(D3D11Device* device, const DescType& desc) {
std::lock_guard<std::mutex> lock(m_mutex);
auto pair = m_objects.find(desc);
auto entry = m_objects.find(desc);
if (pair != m_objects.end())
return pair->second.ref();
if (entry != m_objects.end())
return ref(&entry->second);
Com<T> result = new T(device, desc);
m_objects.insert({ desc, result });
return result.ref();
auto result = m_objects.emplace(
std::piecewise_construct,
std::tuple(desc),
std::tuple(device, desc));
return ref(&result.first->second);
}
private:
std::mutex m_mutex;
std::unordered_map<DescType, Com<T>,
std::unordered_map<DescType, T,
D3D11StateDescHash, D3D11StateDescEqual> m_objects;
};