mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +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:
parent
accbc8828c
commit
9c6209fbf5
@ -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) {
|
HRESULT STDMETHODCALLTYPE D3D11BlendState::QueryInterface(REFIID riid, void** ppvObject) {
|
||||||
if (ppvObject == nullptr)
|
if (ppvObject == nullptr)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
@ -22,6 +22,10 @@ namespace dxvk {
|
|||||||
const D3D11_BLEND_DESC1& desc);
|
const D3D11_BLEND_DESC1& desc);
|
||||||
~D3D11BlendState();
|
~D3D11BlendState();
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE AddRef() final;
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE Release() final;
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE QueryInterface(
|
HRESULT STDMETHODCALLTYPE QueryInterface(
|
||||||
REFIID riid,
|
REFIID riid,
|
||||||
void** ppvObject) final;
|
void** ppvObject) final;
|
||||||
@ -61,6 +65,8 @@ namespace dxvk {
|
|||||||
DxvkLogicOpState m_loState;
|
DxvkLogicOpState m_loState;
|
||||||
|
|
||||||
D3D10BlendState m_d3d10;
|
D3D10BlendState m_d3d10;
|
||||||
|
|
||||||
|
std::atomic<uint32_t> m_refCount = { 0u };
|
||||||
|
|
||||||
static DxvkBlendMode DecodeBlendMode(
|
static DxvkBlendMode DecodeBlendMode(
|
||||||
const D3D11_RENDER_TARGET_BLEND_DESC1& BlendDesc);
|
const D3D11_RENDER_TARGET_BLEND_DESC1& BlendDesc);
|
||||||
|
@ -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) {
|
HRESULT STDMETHODCALLTYPE D3D11DepthStencilState::QueryInterface(REFIID riid, void** ppvObject) {
|
||||||
if (ppvObject == nullptr)
|
if (ppvObject == nullptr)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
@ -22,6 +22,10 @@ namespace dxvk {
|
|||||||
const D3D11_DEPTH_STENCIL_DESC& desc);
|
const D3D11_DEPTH_STENCIL_DESC& desc);
|
||||||
~D3D11DepthStencilState();
|
~D3D11DepthStencilState();
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE AddRef() final;
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE Release() final;
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE QueryInterface(
|
HRESULT STDMETHODCALLTYPE QueryInterface(
|
||||||
REFIID riid,
|
REFIID riid,
|
||||||
void** ppvObject) final;
|
void** ppvObject) final;
|
||||||
@ -50,6 +54,8 @@ namespace dxvk {
|
|||||||
D3D11_DEPTH_STENCIL_DESC m_desc;
|
D3D11_DEPTH_STENCIL_DESC m_desc;
|
||||||
DxvkDepthStencilState m_state;
|
DxvkDepthStencilState m_state;
|
||||||
D3D10DepthStencilState m_d3d10;
|
D3D10DepthStencilState m_d3d10;
|
||||||
|
|
||||||
|
std::atomic<uint32_t> m_refCount = { 0u };
|
||||||
|
|
||||||
VkStencilOpState DecodeStencilOpState(
|
VkStencilOpState DecodeStencilOpState(
|
||||||
const D3D11_DEPTH_STENCILOP_DESC& StencilDesc,
|
const D3D11_DEPTH_STENCILOP_DESC& StencilDesc,
|
||||||
|
@ -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) {
|
HRESULT STDMETHODCALLTYPE D3D11RasterizerState::QueryInterface(REFIID riid, void** ppvObject) {
|
||||||
if (ppvObject == nullptr)
|
if (ppvObject == nullptr)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
@ -20,7 +20,11 @@ namespace dxvk {
|
|||||||
D3D11Device* device,
|
D3D11Device* device,
|
||||||
const D3D11_RASTERIZER_DESC2& desc);
|
const D3D11_RASTERIZER_DESC2& desc);
|
||||||
~D3D11RasterizerState();
|
~D3D11RasterizerState();
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE AddRef() final;
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE Release() final;
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE QueryInterface(
|
HRESULT STDMETHODCALLTYPE QueryInterface(
|
||||||
REFIID riid,
|
REFIID riid,
|
||||||
void** ppvObject) final;
|
void** ppvObject) final;
|
||||||
@ -66,6 +70,8 @@ namespace dxvk {
|
|||||||
DxvkRasterizerState m_state;
|
DxvkRasterizerState m_state;
|
||||||
DxvkDepthBias m_depthBias;
|
DxvkDepthBias m_depthBias;
|
||||||
D3D10RasterizerState m_d3d10;
|
D3D10RasterizerState m_d3d10;
|
||||||
|
|
||||||
|
std::atomic<uint32_t> m_refCount = { 0u };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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) {
|
HRESULT STDMETHODCALLTYPE D3D11SamplerState::QueryInterface(REFIID riid, void** ppvObject) {
|
||||||
if (ppvObject == nullptr)
|
if (ppvObject == nullptr)
|
||||||
return E_POINTER;
|
return E_POINTER;
|
||||||
|
@ -21,6 +21,10 @@ namespace dxvk {
|
|||||||
const D3D11_SAMPLER_DESC& desc);
|
const D3D11_SAMPLER_DESC& desc);
|
||||||
~D3D11SamplerState();
|
~D3D11SamplerState();
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE AddRef() final;
|
||||||
|
|
||||||
|
ULONG STDMETHODCALLTYPE Release() final;
|
||||||
|
|
||||||
HRESULT STDMETHODCALLTYPE QueryInterface(
|
HRESULT STDMETHODCALLTYPE QueryInterface(
|
||||||
REFIID riid,
|
REFIID riid,
|
||||||
void** ppvObject) final;
|
void** ppvObject) final;
|
||||||
@ -49,6 +53,8 @@ namespace dxvk {
|
|||||||
Rc<DxvkSampler> m_sampler;
|
Rc<DxvkSampler> m_sampler;
|
||||||
D3D10SamplerState m_d3d10;
|
D3D10SamplerState m_d3d10;
|
||||||
|
|
||||||
|
std::atomic<uint32_t> m_refCount = { 0u };
|
||||||
|
|
||||||
static bool ValidateAddressMode(
|
static bool ValidateAddressMode(
|
||||||
D3D11_TEXTURE_ADDRESS_MODE Mode);
|
D3D11_TEXTURE_ADDRESS_MODE Mode);
|
||||||
|
|
||||||
|
@ -56,20 +56,22 @@ namespace dxvk {
|
|||||||
T* Create(D3D11Device* device, const DescType& desc) {
|
T* Create(D3D11Device* device, const DescType& desc) {
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
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())
|
if (entry != m_objects.end())
|
||||||
return pair->second.ref();
|
return ref(&entry->second);
|
||||||
|
|
||||||
Com<T> result = new T(device, desc);
|
auto result = m_objects.emplace(
|
||||||
m_objects.insert({ desc, result });
|
std::piecewise_construct,
|
||||||
return result.ref();
|
std::tuple(desc),
|
||||||
|
std::tuple(device, desc));
|
||||||
|
return ref(&result.first->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::unordered_map<DescType, Com<T>,
|
std::unordered_map<DescType, T,
|
||||||
D3D11StateDescHash, D3D11StateDescEqual> m_objects;
|
D3D11StateDescHash, D3D11StateDescEqual> m_objects;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user