Skip to content

Commit

Permalink
[d3d9] Allow locking DEFAULT pool based on texture type
Browse files Browse the repository at this point in the history
  • Loading branch information
K0bin authored and doitsujin committed Nov 10, 2022
1 parent 82685ca commit 8a2e4ef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/d3d9/d3d9_common_texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace dxvk {
bool Discard;
bool IsBackBuffer;
bool IsAttachmentOnly;
bool IsLockable;
};

struct D3D9ColorView {
Expand Down
33 changes: 26 additions & 7 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ namespace dxvk {
desc.MultisampleQuality = 0;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = FALSE;
// Docs:
// Textures placed in the D3DPOOL_DEFAULT pool cannot be locked
// unless they are dynamic textures or they are private, FOURCC, driver formats.
desc.IsLockable = Pool != D3DPOOL_DEFAULT
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -543,6 +549,12 @@ namespace dxvk {
desc.MultisampleQuality = 0;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = FALSE;
// Docs:
// Textures placed in the D3DPOOL_DEFAULT pool cannot be locked
// unless they are dynamic textures or they are private, FOURCC, driver formats.
desc.IsLockable = Pool != D3DPOOL_DEFAULT
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -591,6 +603,12 @@ namespace dxvk {
desc.MultisampleQuality = 0;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = FALSE;
// Docs:
// Textures placed in the D3DPOOL_DEFAULT pool cannot be locked
// unless they are dynamic textures or they are private, FOURCC, driver formats.
desc.IsLockable = Pool != D3DPOOL_DEFAULT
|| (Usage & D3DUSAGE_DYNAMIC)
|| IsVendorFormat(EnumerateFormat(Format));

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -3539,6 +3557,7 @@ namespace dxvk {
desc.MultisampleQuality = MultisampleQuality;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = TRUE;
desc.IsLockable = Lockable;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -3583,6 +3602,8 @@ namespace dxvk {
desc.MultisampleQuality = 0;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = Pool == D3DPOOL_DEFAULT;
// Docs: Off-screen plain surfaces are always lockable, regardless of their pool types.
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -3632,6 +3653,8 @@ namespace dxvk {
desc.MultisampleQuality = MultisampleQuality;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = TRUE;
// Docs don't say anything, so just assume it's lockable.
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_INVALIDCALL;
Expand Down Expand Up @@ -4243,13 +4266,7 @@ namespace dxvk {

auto& desc = *(pResource->Desc());

// MSDN:
// Textures placed in the D3DPOOL_DEFAULT pool cannot be locked
// unless they are dynamic textures or they are private, FOURCC, driver formats.
// Also note that - unlike textures - swap chain back buffers, render targets [..] can be locked
if (unlikely(desc.Pool == D3DPOOL_DEFAULT
&& !(desc.Usage & (D3DUSAGE_DYNAMIC | D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL))
&& !IsFourCCFormat(desc.Format)))
if (unlikely(!desc.IsLockable))
return D3DERR_INVALIDCALL;

auto& formatMapping = pResource->GetFormatMapping();
Expand Down Expand Up @@ -7311,6 +7328,8 @@ namespace dxvk {
desc.MultisampleQuality = pPresentationParameters->MultiSampleQuality;
desc.IsBackBuffer = FALSE;
desc.IsAttachmentOnly = TRUE;
// Docs: Also note that - unlike textures - swap chain back buffers, render targets [..] can be locked
desc.IsLockable = TRUE;

if (FAILED(D3D9CommonTexture::NormalizeTextureProperties(this, &desc)))
return D3DERR_NOTAVAILABLE;
Expand Down
13 changes: 13 additions & 0 deletions src/d3d9/d3d9_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,17 @@ namespace dxvk {
return format > D3D9Format::BINARYBUFFER;
}

inline bool IsVendorFormat(D3D9Format format) {
return IsFourCCFormat(format)
&& format != D3D9Format::MULTI2_ARGB8
&& format != D3D9Format::UYVY
&& format != D3D9Format::R8G8_B8G8
&& format != D3D9Format::G8R8_G8B8
&& format != D3D9Format::DXT1
&& format != D3D9Format::DXT2
&& format != D3D9Format::DXT3
&& format != D3D9Format::DXT4
&& format != D3D9Format::DXT5;
}

}
2 changes: 2 additions & 0 deletions src/d3d9/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ namespace dxvk {
desc.Discard = FALSE;
desc.IsBackBuffer = TRUE;
desc.IsAttachmentOnly = FALSE;
// Docs: Also note that - unlike textures - swap chain back buffers, render targets [..] can be locked
desc.IsLockable = TRUE;

for (uint32_t i = 0; i < m_backBuffers.size(); i++)
m_backBuffers[i] = new D3D9Surface(m_parent, &desc, this, nullptr);
Expand Down

0 comments on commit 8a2e4ef

Please sign in to comment.