From 274c590ad6f242ee21d8c0a51ce424d7f0fec7e5 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Fri, 14 Feb 2025 01:44:53 +0200 Subject: [PATCH] [d3d9] Set priority only for D3DPOOL_MANAGED/DEFAULT resources --- src/d3d9/d3d9_buffer.cpp | 10 ++++++---- src/d3d9/d3d9_buffer.h | 11 +++++++---- src/d3d9/d3d9_common_texture.h | 2 ++ src/d3d9/d3d9_device.cpp | 18 +++++++++--------- src/d3d9/d3d9_interop.cpp | 2 +- src/d3d9/d3d9_resource.h | 25 ++++++++++++++++++------- src/d3d9/d3d9_subresource.h | 3 ++- src/d3d9/d3d9_surface.cpp | 8 +++++++- src/d3d9/d3d9_surface.h | 5 ++++- src/d3d9/d3d9_swapchain.cpp | 2 +- src/d3d9/d3d9_texture.cpp | 18 +++++++++++------- src/d3d9/d3d9_texture.h | 14 ++++++++++---- src/d3d9/d3d9_volume.cpp | 6 +++++- src/d3d9/d3d9_volume.h | 4 +++- 14 files changed, 86 insertions(+), 42 deletions(-) diff --git a/src/d3d9/d3d9_buffer.cpp b/src/d3d9/d3d9_buffer.cpp index 999844ef1..131c15da9 100644 --- a/src/d3d9/d3d9_buffer.cpp +++ b/src/d3d9/d3d9_buffer.cpp @@ -8,8 +8,9 @@ namespace dxvk { D3D9VertexBuffer::D3D9VertexBuffer( D3D9DeviceEx* pDevice, - const D3D9_BUFFER_DESC* pDesc) - : D3D9VertexBufferBase(pDevice, pDesc) { + const D3D9_BUFFER_DESC* pDesc, + const bool Extended) + : D3D9VertexBufferBase(pDevice, pDesc, Extended) { } @@ -68,8 +69,9 @@ namespace dxvk { D3D9IndexBuffer::D3D9IndexBuffer( D3D9DeviceEx* pDevice, - const D3D9_BUFFER_DESC* pDesc) - : D3D9IndexBufferBase(pDevice, pDesc) { + const D3D9_BUFFER_DESC* pDesc, + const bool Extended) + : D3D9IndexBufferBase(pDevice, pDesc, Extended) { } diff --git a/src/d3d9/d3d9_buffer.h b/src/d3d9/d3d9_buffer.h index 0600334c0..5888eb6d6 100644 --- a/src/d3d9/d3d9_buffer.h +++ b/src/d3d9/d3d9_buffer.h @@ -13,8 +13,9 @@ namespace dxvk { D3D9Buffer( D3D9DeviceEx* pDevice, - const D3D9_BUFFER_DESC* pDesc) - : D3D9Resource (pDevice), + const D3D9_BUFFER_DESC* pDesc, + const bool Extended) + : D3D9Resource (pDevice, pDesc->Pool, Extended ), m_buffer (pDevice, pDesc) { } @@ -57,7 +58,8 @@ namespace dxvk { D3D9VertexBuffer( D3D9DeviceEx* pDevice, - const D3D9_BUFFER_DESC* pDesc); + const D3D9_BUFFER_DESC* pDesc, + const bool Extended); HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, @@ -76,7 +78,8 @@ namespace dxvk { D3D9IndexBuffer( D3D9DeviceEx* pDevice, - const D3D9_BUFFER_DESC* pDesc); + const D3D9_BUFFER_DESC* pDesc, + const bool Extended); HRESULT STDMETHODCALLTYPE QueryInterface( REFIID riid, diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index 9108888b9..bba49d65a 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -325,6 +325,8 @@ namespace dxvk { uint32_t GetPlaneCount() const; + D3DPOOL GetPool() const { return m_desc.Pool; } + const D3D9_VK_FORMAT_MAPPING& GetMapping() { return m_mapping; } void SetLocked(UINT Subresource, bool value) { m_locked.set(Subresource, value); } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 94f1b507e..ae48e54bc 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -657,7 +657,7 @@ namespace dxvk { if (pSharedHandle != nullptr && Pool != D3DPOOL_DEFAULT) return D3DERR_INVALIDCALL; - const Com texture = new D3D9Texture2D(this, &desc, pSharedHandle); + const Com texture = new D3D9Texture2D(this, &desc, IsExtended(), pSharedHandle); m_initializer->InitTexture(texture->GetCommonTexture(), initialData); *ppTexture = texture.ref(); @@ -717,7 +717,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com texture = new D3D9Texture3D(this, &desc); + const Com texture = new D3D9Texture3D(this, &desc, IsExtended()); m_initializer->InitTexture(texture->GetCommonTexture()); *ppVolumeTexture = texture.ref(); @@ -775,7 +775,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com texture = new D3D9TextureCube(this, &desc); + const Com texture = new D3D9TextureCube(this, &desc, IsExtended()); m_initializer->InitTexture(texture->GetCommonTexture()); *ppCubeTexture = texture.ref(); @@ -819,7 +819,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com buffer = new D3D9VertexBuffer(this, &desc); + const Com buffer = new D3D9VertexBuffer(this, &desc, IsExtended()); m_initializer->InitBuffer(buffer->GetCommonBuffer()); *ppVertexBuffer = buffer.ref(); @@ -862,7 +862,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com buffer = new D3D9IndexBuffer(this, &desc); + const Com buffer = new D3D9IndexBuffer(this, &desc, IsExtended()); m_initializer->InitBuffer(buffer->GetCommonBuffer()); *ppIndexBuffer = buffer.ref(); @@ -4126,7 +4126,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle); + const Com surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle); m_initializer->InitTexture(surface->GetCommonTexture()); *ppSurface = surface.ref(); m_losableResourceCounter++; @@ -4177,7 +4177,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle); + const Com surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle); m_initializer->InitTexture(surface->GetCommonTexture()); *ppSurface = surface.ref(); @@ -4228,7 +4228,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; try { - const Com surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle); + const Com surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle); m_initializer->InitTexture(surface->GetCommonTexture()); *ppSurface = surface.ref(); m_losableResourceCounter++; @@ -8510,7 +8510,7 @@ namespace dxvk { if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, D3DRTYPE_SURFACE, &desc))) return D3DERR_NOTAVAILABLE; - m_autoDepthStencil = new D3D9Surface(this, &desc, nullptr, nullptr); + m_autoDepthStencil = new D3D9Surface(this, &desc, IsExtended(), nullptr, nullptr); m_initializer->InitTexture(m_autoDepthStencil->GetCommonTexture()); SetDepthStencilSurface(m_autoDepthStencil.ptr()); m_losableResourceCounter++; diff --git a/src/d3d9/d3d9_interop.cpp b/src/d3d9/d3d9_interop.cpp index 079f2919a..9d833b39a 100644 --- a/src/d3d9/d3d9_interop.cpp +++ b/src/d3d9/d3d9_interop.cpp @@ -349,7 +349,7 @@ namespace dxvk { const D3D9_COMMON_TEXTURE_DESC& desc, IDirect3DResource9** ppResult) { try { - const Com texture = new ResourceType(m_device, &desc); + const Com texture = new ResourceType(m_device, &desc, m_device->IsExtended()); m_device->m_initializer->InitTexture(texture->GetCommonTexture()); *ppResult = texture.ref(); diff --git a/src/d3d9/d3d9_resource.h b/src/d3d9/d3d9_resource.h index 32c1553aa..47e5d6891 100644 --- a/src/d3d9/d3d9_resource.h +++ b/src/d3d9/d3d9_resource.h @@ -11,9 +11,11 @@ namespace dxvk { public: - D3D9Resource(D3D9DeviceEx* pDevice) + D3D9Resource(D3D9DeviceEx* pDevice, D3DPOOL Pool, bool Extended) : D3D9DeviceChild(pDevice) - , m_priority ( 0 ) { } + , m_pool ( Pool ) + , m_priority ( 0 ) + , m_isExtended ( Extended ) { } HRESULT STDMETHODCALLTYPE SetPrivateData( REFGUID refguid, @@ -72,9 +74,16 @@ namespace dxvk { } DWORD STDMETHODCALLTYPE SetPriority(DWORD PriorityNew) { - DWORD oldPriority = m_priority; - m_priority = PriorityNew; - return oldPriority; + // Priority can only be set for D3DPOOL_MANAGED resources on + // D3D9 interfaces, and for D3DPOOL_DEFAULT on D3D9Ex interfaces + if (likely((m_pool == D3DPOOL_MANAGED && !m_isExtended) + || (m_pool == D3DPOOL_DEFAULT && m_isExtended))) { + DWORD oldPriority = m_priority; + m_priority = PriorityNew; + return oldPriority; + } + + return m_priority; } DWORD STDMETHODCALLTYPE GetPriority() { @@ -84,11 +93,13 @@ namespace dxvk { protected: - DWORD m_priority; + const D3DPOOL m_pool; + DWORD m_priority; private: - ComPrivateData m_privateData; + const bool m_isExtended; + ComPrivateData m_privateData; }; diff --git a/src/d3d9/d3d9_subresource.h b/src/d3d9/d3d9_subresource.h index 3431cec47..e2f5b5c84 100644 --- a/src/d3d9/d3d9_subresource.h +++ b/src/d3d9/d3d9_subresource.h @@ -12,12 +12,13 @@ namespace dxvk { D3D9Subresource( D3D9DeviceEx* pDevice, + const bool Extended, D3D9CommonTexture* pTexture, UINT Face, UINT MipLevel, IDirect3DBaseTexture9* pBaseTexture, IUnknown* pContainer) - : D3D9Resource(pDevice), + : D3D9Resource(pDevice, pTexture->GetPool(), Extended), m_container (pContainer), m_baseTexture (pBaseTexture), m_texture (pTexture), diff --git a/src/d3d9/d3d9_surface.cpp b/src/d3d9/d3d9_surface.cpp index 2e9766d5a..14cbd2f0a 100644 --- a/src/d3d9/d3d9_surface.cpp +++ b/src/d3d9/d3d9_surface.cpp @@ -11,10 +11,12 @@ namespace dxvk { D3D9Surface::D3D9Surface( D3D9DeviceEx* pDevice, const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended, IUnknown* pContainer, HANDLE* pSharedHandle) : D3D9SurfaceBase( pDevice, + Extended, new D3D9CommonTexture( pDevice, this, pDesc, D3DRTYPE_SURFACE, pSharedHandle), 0, 0, nullptr, @@ -22,21 +24,25 @@ namespace dxvk { D3D9Surface::D3D9Surface( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc) + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended) : D3D9Surface( pDevice, pDesc, + Extended, nullptr, nullptr) { } D3D9Surface::D3D9Surface( D3D9DeviceEx* pDevice, + const bool Extended, D3D9CommonTexture* pTexture, UINT Face, UINT MipLevel, IDirect3DBaseTexture9* pBaseTexture) : D3D9SurfaceBase( pDevice, + Extended, pTexture, Face, MipLevel, pBaseTexture, diff --git a/src/d3d9/d3d9_surface.h b/src/d3d9/d3d9_surface.h index e6a6e8001..01a08b9a9 100644 --- a/src/d3d9/d3d9_surface.h +++ b/src/d3d9/d3d9_surface.h @@ -20,15 +20,18 @@ namespace dxvk { D3D9Surface( D3D9DeviceEx* pDevice, const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended, IUnknown* pContainer, HANDLE* pSharedHandle); D3D9Surface( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc); + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended); D3D9Surface( D3D9DeviceEx* pDevice, + const bool Extended, D3D9CommonTexture* pTexture, UINT Face, UINT MipLevel, diff --git a/src/d3d9/d3d9_swapchain.cpp b/src/d3d9/d3d9_swapchain.cpp index 0a4c8faae..73218c516 100644 --- a/src/d3d9/d3d9_swapchain.cpp +++ b/src/d3d9/d3d9_swapchain.cpp @@ -1022,7 +1022,7 @@ namespace dxvk { for (uint32_t i = 0; i < NumBuffers; i++) { D3D9Surface* surface; try { - surface = new D3D9Surface(m_parent, &desc, this, nullptr); + surface = new D3D9Surface(m_parent, &desc, m_parent->IsExtended(), this, nullptr); m_parent->IncrementLosableCounter(); } catch (const DxvkError& e) { DestroyBackBuffers(); diff --git a/src/d3d9/d3d9_texture.cpp b/src/d3d9/d3d9_texture.cpp index a0be6e798..b1b783942 100644 --- a/src/d3d9/d3d9_texture.cpp +++ b/src/d3d9/d3d9_texture.cpp @@ -9,13 +9,15 @@ namespace dxvk { D3D9Texture2D::D3D9Texture2D( D3D9DeviceEx* pDevice, const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended, HANDLE* pSharedHandle) - : D3D9Texture2DBase( pDevice, pDesc, D3DRTYPE_TEXTURE, pSharedHandle ) { } + : D3D9Texture2DBase( pDevice, pDesc, Extended, D3DRTYPE_TEXTURE, pSharedHandle ) { } D3D9Texture2D::D3D9Texture2D( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc) - : D3D9Texture2D( pDevice, pDesc, nullptr ) { } + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended) + : D3D9Texture2D( pDevice, pDesc, Extended, nullptr ) { } HRESULT STDMETHODCALLTYPE D3D9Texture2D::QueryInterface(REFIID riid, void** ppvObject) { if (ppvObject == nullptr) @@ -112,8 +114,9 @@ namespace dxvk { D3D9Texture3D::D3D9Texture3D( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc) - : D3D9Texture3DBase( pDevice, pDesc, D3DRTYPE_VOLUMETEXTURE, nullptr ) { } + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended) + : D3D9Texture3DBase( pDevice, pDesc, Extended, D3DRTYPE_VOLUMETEXTURE, nullptr ) { } HRESULT STDMETHODCALLTYPE D3D9Texture3D::QueryInterface(REFIID riid, void** ppvObject) { @@ -205,8 +208,9 @@ namespace dxvk { D3D9TextureCube::D3D9TextureCube( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc) - : D3D9TextureCubeBase( pDevice, pDesc, D3DRTYPE_CUBETEXTURE, nullptr ) { } + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended) + : D3D9TextureCubeBase( pDevice, pDesc, Extended, D3DRTYPE_CUBETEXTURE, nullptr ) { } HRESULT STDMETHODCALLTYPE D3D9TextureCube::QueryInterface(REFIID riid, void** ppvObject) { diff --git a/src/d3d9/d3d9_texture.h b/src/d3d9/d3d9_texture.h index 47354d39b..aefd31341 100644 --- a/src/d3d9/d3d9_texture.h +++ b/src/d3d9/d3d9_texture.h @@ -23,9 +23,10 @@ namespace dxvk { D3D9BaseTexture( D3D9DeviceEx* pDevice, const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended, D3DRESOURCETYPE ResourceType, HANDLE* pSharedHandle) - : D3D9Resource ( pDevice ) + : D3D9Resource ( pDevice, pDesc->Pool, Extended ) , m_texture ( pDevice, this, pDesc, ResourceType, pSharedHandle ) , m_lod ( 0 ) { const uint32_t arraySlices = m_texture.Desc()->ArraySize; @@ -41,6 +42,7 @@ namespace dxvk { new (subObj) SubresourceType( pDevice, + Extended, &m_texture, i, j, this); @@ -132,11 +134,13 @@ namespace dxvk { D3D9Texture2D( D3D9DeviceEx* pDevice, const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended, HANDLE* pSharedHandle); D3D9Texture2D( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc); + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); @@ -162,7 +166,8 @@ namespace dxvk { D3D9Texture3D( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc); + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); @@ -187,7 +192,8 @@ namespace dxvk { D3D9TextureCube( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc); + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject); diff --git a/src/d3d9/d3d9_volume.cpp b/src/d3d9/d3d9_volume.cpp index 7479841e1..48e988725 100644 --- a/src/d3d9/d3d9_volume.cpp +++ b/src/d3d9/d3d9_volume.cpp @@ -7,9 +7,11 @@ namespace dxvk { D3D9Volume::D3D9Volume( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc) + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended) : D3D9VolumeBase( pDevice, + Extended, new D3D9CommonTexture( pDevice, this, pDesc, D3DRTYPE_VOLUMETEXTURE, nullptr ), 0, 0, nullptr, @@ -18,12 +20,14 @@ namespace dxvk { D3D9Volume::D3D9Volume( D3D9DeviceEx* pDevice, + const bool Extended, D3D9CommonTexture* pTexture, UINT Face, UINT MipLevel, IDirect3DBaseTexture9* pContainer) : D3D9VolumeBase( pDevice, + Extended, pTexture, Face, MipLevel, pContainer, diff --git a/src/d3d9/d3d9_volume.h b/src/d3d9/d3d9_volume.h index 9c33a788f..edb20ff77 100644 --- a/src/d3d9/d3d9_volume.h +++ b/src/d3d9/d3d9_volume.h @@ -13,10 +13,12 @@ namespace dxvk { D3D9Volume( D3D9DeviceEx* pDevice, - const D3D9_COMMON_TEXTURE_DESC* pDesc); + const D3D9_COMMON_TEXTURE_DESC* pDesc, + const bool Extended); D3D9Volume( D3D9DeviceEx* pDevice, + const bool Extended, D3D9CommonTexture* pTexture, UINT Face, UINT MipLevel,