From 6f139791d243c46084f0285160261f70244a65ca Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Wed, 17 Mar 2021 22:02:00 +0100 Subject: [PATCH] [d3d9] Improve naming of buffer flags and ranges --- src/d3d9/d3d9_common_buffer.h | 32 ++++++++++++++++++++------------ src/d3d9/d3d9_device.cpp | 22 +++++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/d3d9/d3d9_common_buffer.h b/src/d3d9/d3d9_common_buffer.h index 71d4329f..7ea1c8a8 100644 --- a/src/d3d9/d3d9_common_buffer.h +++ b/src/d3d9/d3d9_common_buffer.h @@ -139,11 +139,25 @@ namespace dxvk { static HRESULT ValidateBufferProperties(const D3D9_BUFFER_DESC* pDesc); - D3D9Range& LockRange() { return m_lockRange; } - D3D9Range& DirtyRange() { return m_dirtyRange; } + /** + * \brief The range of the buffer that was changed using Lock calls + */ + D3D9Range& DirtyRange() { return m_dirtyRange; } - bool GetReadLocked() const { return m_readLocked; } - void SetReadLocked(bool state) { m_readLocked = state; } + /** + * \brief The range of the buffer that might currently be read by the GPU + */ + D3D9Range& GPUReadingRange() { return m_gpuReadingRange; } + + /** + * \brief Whether or not the buffer was written to by the GPU (in IDirect3DDevice9::ProcessVertices) + */ + bool WasWrittenByGPU() const { return m_wasWrittenByGPU; } + + /** + * \brief Sets whether or not the buffer was written to by the GPU + */ + void SetWrittenByGPU(bool state) { m_wasWrittenByGPU = state; } uint32_t IncrementLockCount() { return ++m_lockCount; } uint32_t DecrementLockCount() { @@ -158,12 +172,6 @@ namespace dxvk { void MarkNeedsUpload() { m_needsUpload = true; } bool NeedsUpload() const { return m_needsUpload; } - bool MarkLocked() { - bool locked = m_readLocked; - m_readLocked = true; - return locked; - } - void PreLoad(); private: @@ -186,15 +194,15 @@ namespace dxvk { D3D9DeviceEx* m_parent; const D3D9_BUFFER_DESC m_desc; DWORD m_mapFlags; - bool m_readLocked = false; + bool m_wasWrittenByGPU = false; Rc m_buffer; Rc m_stagingBuffer; DxvkBufferSliceHandle m_sliceHandle; - D3D9Range m_lockRange; D3D9Range m_dirtyRange; + D3D9Range m_gpuReadingRange; uint32_t m_lockCount = 0; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index e37e852a..a318076c 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -2579,7 +2579,7 @@ namespace dxvk { }); } - dst->SetReadLocked(true); + dst->SetWrittenByGPU(true); return D3D_OK; } @@ -4368,7 +4368,7 @@ namespace dxvk { // D3D9 does not do region tracking for READONLY locks // But lets also account for whether we get readback from ProcessVertices - const bool quickRead = ((Flags & D3DLOCK_READONLY) && !pResource->GetReadLocked()); + const bool quickRead = ((Flags & D3DLOCK_READONLY) && !pResource->WasWrittenByGPU()); const bool boundsCheck = desc.Pool != D3DPOOL_DEFAULT && !quickRead; if (boundsCheck) { @@ -4382,7 +4382,7 @@ namespace dxvk { uint32_t offset = respectUserBounds ? OffsetToLock : 0; uint32_t size = respectUserBounds ? SizeToLock : desc.Size; - pResource->LockRange().Conjoin(D3D9Range(offset, offset + size)); + pResource->DirtyRange().Conjoin(D3D9Range(offset, offset + size)); } Rc mappingBuffer = pResource->GetBuffer(); @@ -4402,8 +4402,8 @@ namespace dxvk { ctx->invalidateBuffer(cBuffer, cBufferSlice); }); - pResource->SetReadLocked(false); - pResource->DirtyRange().Clear(); + pResource->SetWrittenByGPU(false); + pResource->GPUReadingRange().Clear(); } else { // Use map pointer from previous map operation. This @@ -4419,12 +4419,12 @@ namespace dxvk { // of our bounds, otherwise we just ignore this and go for it all the time. const bool skipWait = (Flags & D3DLOCK_NOOVERWRITE) || quickRead || - (boundsCheck && !pResource->DirtyRange().Overlaps(pResource->LockRange())); + (boundsCheck && !pResource->GPUReadingRange().Overlaps(pResource->DirtyRange())); if (!skipWait) { const bool backed = pResource->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER; const bool doNotWait = Flags & D3DLOCK_DONOTWAIT; - bool doImplicitDiscard = backed && !doNotWait && pResource->GetLockCount() == 0 && !pResource->GetReadLocked(); + bool doImplicitDiscard = backed && !doNotWait && pResource->GetLockCount() == 0 && !pResource->WasWrittenByGPU(); doImplicitDiscard = doImplicitDiscard && m_d3d9Options.allowImplicitDiscard; @@ -4447,8 +4447,8 @@ namespace dxvk { return D3DERR_WASSTILLDRAWING; } - pResource->SetReadLocked(false); - pResource->DirtyRange().Clear(); + pResource->SetWrittenByGPU(false); + pResource->GPUReadingRange().Clear(); } } @@ -4493,8 +4493,8 @@ namespace dxvk { cSrcSlice.length()); }); - pResource->DirtyRange().Conjoin(pResource->LockRange()); - pResource->LockRange().Clear(); + pResource->GPUReadingRange().Conjoin(pResource->DirtyRange()); + pResource->DirtyRange().Clear(); pResource->MarkUploaded(); return D3D_OK;