diff --git a/src/d3d9/d3d9_common_texture.h b/src/d3d9/d3d9_common_texture.h index bad2e9eee..fe046844a 100644 --- a/src/d3d9/d3d9_common_texture.h +++ b/src/d3d9/d3d9_common_texture.h @@ -6,6 +6,8 @@ #include "../dxvk/dxvk_device.h" +#include "../util/util_bit.h" + namespace dxvk { class D3D9DeviceEx; @@ -86,6 +88,8 @@ namespace dxvk { template using D3D9SubresourceArray = std::array; + using D3D9SubresourceBitset = bit::bitset; + class D3D9CommonTexture { public: @@ -204,22 +208,6 @@ namespace dxvk { D3D9DeviceEx* pDevice, D3D9_COMMON_TEXTURE_DESC* pDesc); - /** - * \brief Lock Flags - * Set the lock flags for a given subresource - */ - void SetLockFlags(UINT Subresource, DWORD Flags) { - m_lockFlags[Subresource] = Flags; - } - - /** - * \brief Lock Flags - * \returns The log flags for a given subresource - */ - DWORD GetLockFlags(UINT Subresource) const { - return m_lockFlags[Subresource]; - } - /** * \brief Shadow * \returns Whether the texture is to be depth compared @@ -334,10 +322,15 @@ namespace dxvk { const D3D9_VK_FORMAT_MAPPING& GetMapping() { return m_mapping; } - bool MarkLocked(UINT Subresource, bool value) { return std::exchange(m_locked[Subresource], value); } + bool MarkLocked(UINT Subresource, bool value) { return m_locked.exchange(Subresource, value); } - bool SetDirty(UINT Subresource, bool value) { return std::exchange(m_dirty[Subresource], value); } - void MarkAllDirty() { for (uint32_t i = 0; i < m_dirty.size(); i++) m_dirty[i] = true; } + bool SetDirty(UINT Subresource, bool value) { return m_dirty.exchange(Subresource, value); } + + void MarkAllDirty() { m_dirty.setAll(); } + + void SetReadOnlyLocked(UINT Subresource, bool readOnly) { return m_readOnly.set(Subresource, readOnly); } + + bool GetReadOnlyLocked(UINT Subresource) { return m_readOnly.get(Subresource); } const Rc& GetSampleView(bool srgb) const { return m_sampleView.Pick(srgb && IsSrgbCompatible()); @@ -378,7 +371,6 @@ namespace dxvk { Rc> m_buffers; D3D9SubresourceArray< DxvkBufferSliceHandle> m_mappedSlices; - D3D9SubresourceArray m_lockFlags; D3D9_VK_FORMAT_MAPPING m_mapping; @@ -394,11 +386,11 @@ namespace dxvk { D3D9ColorView m_sampleView; - D3D9SubresourceArray< - bool> m_locked = { }; + D3D9SubresourceBitset m_locked = { }; - D3D9SubresourceArray< - bool> m_dirty = { }; + D3D9SubresourceBitset m_readOnly = { }; + + D3D9SubresourceBitset m_dirty = { }; /** * \brief Mip level diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index dbfbaf21d..e506a6fec 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -3868,7 +3868,7 @@ namespace dxvk { if (desc.Usage & D3DUSAGE_WRITEONLY) Flags &= ~D3DLOCK_READONLY; - pResource->SetLockFlags(Subresource, Flags); + pResource->SetReadOnlyLocked(Subresource, Flags & D3DLOCK_READONLY); bool renderable = desc.Usage & (D3DUSAGE_RENDERTARGET | D3DUSAGE_DEPTHSTENCIL); @@ -4034,7 +4034,7 @@ namespace dxvk { return D3DERR_INVALIDCALL; // Do we have a pending copy? - if (!(pResource->GetLockFlags(Subresource) & D3DLOCK_READONLY)) { + if (!pResource->GetReadOnlyLocked(Subresource)) { // Only flush buffer -> image if we actually have an image if (pResource->GetMapMode() == D3D9_COMMON_TEXTURE_MAP_MODE_BACKED) this->FlushImage(pResource, Subresource);