diff --git a/src/d3d11/d3d11_swapchain.cpp b/src/d3d11/d3d11_swapchain.cpp index 7fbebd61..56c51a7b 100644 --- a/src/d3d11/d3d11_swapchain.cpp +++ b/src/d3d11/d3d11_swapchain.cpp @@ -490,7 +490,7 @@ namespace dxvk { || m_desc.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) dxgiUsage |= DXGI_USAGE_DISCARD_ON_PRESENT; - m_backBuffer = new D3D11Texture2D(m_parent, &desc, dxgiUsage, VK_NULL_HANDLE); + m_backBuffer = new D3D11Texture2D(m_parent, this, &desc, dxgiUsage); m_swapImage = GetCommonTexture(m_backBuffer.ptr())->GetImage(); // Create an image view that allows the diff --git a/src/d3d11/d3d11_texture.cpp b/src/d3d11/d3d11_texture.cpp index e5a542d8..4db9c614 100644 --- a/src/d3d11/d3d11_texture.cpp +++ b/src/d3d11/d3d11_texture.cpp @@ -1097,12 +1097,12 @@ namespace dxvk { const D3D11_COMMON_TEXTURE_DESC* pDesc, HANDLE hSharedHandle) : D3D11DeviceChild(pDevice), - m_texture (this, pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D, 0, VK_NULL_HANDLE, hSharedHandle), - m_interop (this, &m_texture), - m_surface (this, &m_texture), - m_resource(this), - m_d3d10 (this) { - + m_texture (this, pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D, 0, VK_NULL_HANDLE, hSharedHandle), + m_interop (this, &m_texture), + m_surface (this, &m_texture), + m_resource (this), + m_d3d10 (this), + m_swapChain (nullptr) { } @@ -1112,11 +1112,28 @@ namespace dxvk { DXGI_USAGE DxgiUsage, VkImage vkImage) : D3D11DeviceChild(pDevice), - m_texture (this, pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D, DxgiUsage, vkImage, nullptr), - m_interop (this, &m_texture), - m_surface (this, &m_texture), - m_resource(this), - m_d3d10 (this) { + m_texture (this, pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D, DxgiUsage, vkImage, nullptr), + m_interop (this, &m_texture), + m_surface (this, &m_texture), + m_resource (this), + m_d3d10 (this), + m_swapChain (nullptr) { + + } + + + D3D11Texture2D::D3D11Texture2D( + D3D11Device* pDevice, + IUnknown* pSwapChain, + const D3D11_COMMON_TEXTURE_DESC* pDesc, + DXGI_USAGE DxgiUsage) + : D3D11DeviceChild(pDevice), + m_texture (this, pDevice, pDesc, D3D11_RESOURCE_DIMENSION_TEXTURE2D, DxgiUsage, VK_NULL_HANDLE, nullptr), + m_interop (this, &m_texture), + m_surface (this, &m_texture), + m_resource (this), + m_d3d10 (this), + m_swapChain (pSwapChain) { } @@ -1126,6 +1143,34 @@ namespace dxvk { } + ULONG STDMETHODCALLTYPE D3D11Texture2D::AddRef() { + uint32_t refCount = m_refCount++; + + if (unlikely(!refCount)) { + if (m_swapChain) + m_swapChain->AddRef(); + + AddRefPrivate(); + } + + return refCount + 1; + } + + + ULONG STDMETHODCALLTYPE D3D11Texture2D::Release() { + uint32_t refCount = --m_refCount; + + if (unlikely(!refCount)) { + if (m_swapChain) + m_swapChain->Release(); + + ReleasePrivate(); + } + + return refCount; + } + + HRESULT STDMETHODCALLTYPE D3D11Texture2D::QueryInterface(REFIID riid, void** ppvObject) { if (ppvObject == nullptr) return E_POINTER; diff --git a/src/d3d11/d3d11_texture.h b/src/d3d11/d3d11_texture.h index c3e4e3c9..2db2bc0c 100644 --- a/src/d3d11/d3d11_texture.h +++ b/src/d3d11/d3d11_texture.h @@ -613,8 +613,18 @@ namespace dxvk { DXGI_USAGE DxgiUsage, VkImage vkImage); + D3D11Texture2D( + D3D11Device* pDevice, + IUnknown* pSwapChain, + const D3D11_COMMON_TEXTURE_DESC* pDesc, + DXGI_USAGE DxgiUsage); + ~D3D11Texture2D(); + ULONG STDMETHODCALLTYPE AddRef(); + + ULONG STDMETHODCALLTYPE Release(); + HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, void** ppvObject) final; @@ -647,6 +657,7 @@ namespace dxvk { D3D11DXGISurface m_surface; D3D11DXGIResource m_resource; D3D10Texture2D m_d3d10; + IUnknown* m_swapChain; };