Skip to content

Commit

Permalink
[d3d9] Set priority only for D3DPOOL_MANAGED/DEFAULT resources
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Feb 14, 2025
1 parent 6860e1c commit fd98bd0
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 41 deletions.
10 changes: 6 additions & 4 deletions src/d3d9/d3d9_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

}

Expand Down Expand Up @@ -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) {

}

Expand Down
11 changes: 7 additions & 4 deletions src/d3d9/d3d9_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace dxvk {

D3D9Buffer(
D3D9DeviceEx* pDevice,
const D3D9_BUFFER_DESC* pDesc)
: D3D9Resource<Type...> (pDevice),
const D3D9_BUFFER_DESC* pDesc,
const bool Extended)
: D3D9Resource<Type...> (pDevice, pDesc->Pool, Extended ),
m_buffer (pDevice, pDesc) {

}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
18 changes: 9 additions & 9 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ namespace dxvk {
if (pSharedHandle != nullptr && Pool != D3DPOOL_DEFAULT)
return D3DERR_INVALIDCALL;

const Com<D3D9Texture2D> texture = new D3D9Texture2D(this, &desc, pSharedHandle);
const Com<D3D9Texture2D> texture = new D3D9Texture2D(this, &desc, IsExtended(), pSharedHandle);

m_initializer->InitTexture(texture->GetCommonTexture(), initialData);
*ppTexture = texture.ref();
Expand Down Expand Up @@ -717,7 +717,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9Texture3D> texture = new D3D9Texture3D(this, &desc);
const Com<D3D9Texture3D> texture = new D3D9Texture3D(this, &desc, IsExtended());
m_initializer->InitTexture(texture->GetCommonTexture());
*ppVolumeTexture = texture.ref();

Expand Down Expand Up @@ -775,7 +775,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9TextureCube> texture = new D3D9TextureCube(this, &desc);
const Com<D3D9TextureCube> texture = new D3D9TextureCube(this, &desc, IsExtended());
m_initializer->InitTexture(texture->GetCommonTexture());
*ppCubeTexture = texture.ref();

Expand Down Expand Up @@ -819,7 +819,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9VertexBuffer> buffer = new D3D9VertexBuffer(this, &desc);
const Com<D3D9VertexBuffer> buffer = new D3D9VertexBuffer(this, &desc, IsExtended());
m_initializer->InitBuffer(buffer->GetCommonBuffer());
*ppVertexBuffer = buffer.ref();

Expand Down Expand Up @@ -862,7 +862,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9IndexBuffer> buffer = new D3D9IndexBuffer(this, &desc);
const Com<D3D9IndexBuffer> buffer = new D3D9IndexBuffer(this, &desc, IsExtended());
m_initializer->InitBuffer(buffer->GetCommonBuffer());
*ppIndexBuffer = buffer.ref();

Expand Down Expand Up @@ -4126,7 +4126,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle);
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle);
m_initializer->InitTexture(surface->GetCommonTexture());
*ppSurface = surface.ref();
m_losableResourceCounter++;
Expand Down Expand Up @@ -4177,7 +4177,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle);
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle);
m_initializer->InitTexture(surface->GetCommonTexture());
*ppSurface = surface.ref();

Expand Down Expand Up @@ -4228,7 +4228,7 @@ namespace dxvk {
return D3DERR_INVALIDCALL;

try {
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, nullptr, pSharedHandle);
const Com<D3D9Surface> surface = new D3D9Surface(this, &desc, IsExtended(), nullptr, pSharedHandle);
m_initializer->InitTexture(surface->GetCommonTexture());
*ppSurface = surface.ref();
m_losableResourceCounter++;
Expand Down Expand Up @@ -8509,7 +8509,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++;
Expand Down
2 changes: 1 addition & 1 deletion src/d3d9/d3d9_interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ namespace dxvk {
const D3D9_COMMON_TEXTURE_DESC& desc,
IDirect3DResource9** ppResult) {
try {
const Com<ResourceType> texture = new ResourceType(m_device, &desc);
const Com<ResourceType> texture = new ResourceType(m_device, &desc, m_device->IsExtended());
m_device->m_initializer->InitTexture(texture->GetCommonTexture());
*ppResult = texture.ref();

Expand Down
23 changes: 17 additions & 6 deletions src/d3d9/d3d9_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ namespace dxvk {

public:

D3D9Resource(D3D9DeviceEx* pDevice)
D3D9Resource(D3D9DeviceEx* pDevice, D3DPOOL Pool, bool Extended)
: D3D9DeviceChild<Type...>(pDevice)
, m_priority ( 0 ) { }
, m_pool ( Pool )
, m_priority ( 0 )
, m_isExtended ( Extended ) { }

HRESULT STDMETHODCALLTYPE SetPrivateData(
REFGUID refguid,
Expand Down Expand Up @@ -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 ((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() {
Expand All @@ -84,10 +93,12 @@ namespace dxvk {

protected:

DWORD m_priority;
D3DPOOL m_pool;
DWORD m_priority;

private:

bool m_isExtended;
ComPrivateData m_privateData;

};
Expand Down
3 changes: 2 additions & 1 deletion src/d3d9/d3d9_subresource.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ namespace dxvk {

D3D9Subresource(
D3D9DeviceEx* pDevice,
const bool Extended,
D3D9CommonTexture* pTexture,
UINT Face,
UINT MipLevel,
IDirect3DBaseTexture9* pBaseTexture,
IUnknown* pContainer)
: D3D9Resource<Type...>(pDevice),
: D3D9Resource<Type...>(pDevice, pTexture->GetPool(), Extended),
m_container (pContainer),
m_baseTexture (pBaseTexture),
m_texture (pTexture),
Expand Down
8 changes: 7 additions & 1 deletion src/d3d9/d3d9_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,38 @@ 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,
pContainer) { }

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,
Expand Down
5 changes: 4 additions & 1 deletion src/d3d9/d3d9_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 11 additions & 7 deletions src/d3d9/d3d9_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 10 additions & 4 deletions src/d3d9/d3d9_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ namespace dxvk {
D3D9BaseTexture(
D3D9DeviceEx* pDevice,
const D3D9_COMMON_TEXTURE_DESC* pDesc,
const bool Extended,
D3DRESOURCETYPE ResourceType,
HANDLE* pSharedHandle)
: D3D9Resource<Base...> ( pDevice )
: D3D9Resource<Base...> ( pDevice, pDesc->Pool, Extended )
, m_texture ( pDevice, this, pDesc, ResourceType, pSharedHandle )
, m_lod ( 0 ) {
const uint32_t arraySlices = m_texture.Desc()->ArraySize;
Expand All @@ -41,6 +42,7 @@ namespace dxvk {

new (subObj) SubresourceType(
pDevice,
Extended,
&m_texture,
i, j,
this);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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);

Expand Down
Loading

0 comments on commit fd98bd0

Please sign in to comment.