1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00

[d3d9] Improve naming of buffer flags and ranges

This commit is contained in:
Robin Kertels 2021-03-17 22:02:00 +01:00 committed by Joshie
parent cf4ff820be
commit 6f139791d2
2 changed files with 31 additions and 23 deletions

View File

@ -139,11 +139,25 @@ namespace dxvk {
static HRESULT ValidateBufferProperties(const D3D9_BUFFER_DESC* pDesc); 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 IncrementLockCount() { return ++m_lockCount; }
uint32_t DecrementLockCount() { uint32_t DecrementLockCount() {
@ -158,12 +172,6 @@ namespace dxvk {
void MarkNeedsUpload() { m_needsUpload = true; } void MarkNeedsUpload() { m_needsUpload = true; }
bool NeedsUpload() const { return m_needsUpload; } bool NeedsUpload() const { return m_needsUpload; }
bool MarkLocked() {
bool locked = m_readLocked;
m_readLocked = true;
return locked;
}
void PreLoad(); void PreLoad();
private: private:
@ -186,15 +194,15 @@ namespace dxvk {
D3D9DeviceEx* m_parent; D3D9DeviceEx* m_parent;
const D3D9_BUFFER_DESC m_desc; const D3D9_BUFFER_DESC m_desc;
DWORD m_mapFlags; DWORD m_mapFlags;
bool m_readLocked = false; bool m_wasWrittenByGPU = false;
Rc<DxvkBuffer> m_buffer; Rc<DxvkBuffer> m_buffer;
Rc<DxvkBuffer> m_stagingBuffer; Rc<DxvkBuffer> m_stagingBuffer;
DxvkBufferSliceHandle m_sliceHandle; DxvkBufferSliceHandle m_sliceHandle;
D3D9Range m_lockRange;
D3D9Range m_dirtyRange; D3D9Range m_dirtyRange;
D3D9Range m_gpuReadingRange;
uint32_t m_lockCount = 0; uint32_t m_lockCount = 0;

View File

@ -2579,7 +2579,7 @@ namespace dxvk {
}); });
} }
dst->SetReadLocked(true); dst->SetWrittenByGPU(true);
return D3D_OK; return D3D_OK;
} }
@ -4368,7 +4368,7 @@ namespace dxvk {
// D3D9 does not do region tracking for READONLY locks // D3D9 does not do region tracking for READONLY locks
// But lets also account for whether we get readback from ProcessVertices // 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; const bool boundsCheck = desc.Pool != D3DPOOL_DEFAULT && !quickRead;
if (boundsCheck) { if (boundsCheck) {
@ -4382,7 +4382,7 @@ namespace dxvk {
uint32_t offset = respectUserBounds ? OffsetToLock : 0; uint32_t offset = respectUserBounds ? OffsetToLock : 0;
uint32_t size = respectUserBounds ? SizeToLock : desc.Size; uint32_t size = respectUserBounds ? SizeToLock : desc.Size;
pResource->LockRange().Conjoin(D3D9Range(offset, offset + size)); pResource->DirtyRange().Conjoin(D3D9Range(offset, offset + size));
} }
Rc<DxvkBuffer> mappingBuffer = pResource->GetBuffer<D3D9_COMMON_BUFFER_TYPE_MAPPING>(); Rc<DxvkBuffer> mappingBuffer = pResource->GetBuffer<D3D9_COMMON_BUFFER_TYPE_MAPPING>();
@ -4402,8 +4402,8 @@ namespace dxvk {
ctx->invalidateBuffer(cBuffer, cBufferSlice); ctx->invalidateBuffer(cBuffer, cBufferSlice);
}); });
pResource->SetReadLocked(false); pResource->SetWrittenByGPU(false);
pResource->DirtyRange().Clear(); pResource->GPUReadingRange().Clear();
} }
else { else {
// Use map pointer from previous map operation. This // 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. // of our bounds, otherwise we just ignore this and go for it all the time.
const bool skipWait = (Flags & D3DLOCK_NOOVERWRITE) || const bool skipWait = (Flags & D3DLOCK_NOOVERWRITE) ||
quickRead || quickRead ||
(boundsCheck && !pResource->DirtyRange().Overlaps(pResource->LockRange())); (boundsCheck && !pResource->GPUReadingRange().Overlaps(pResource->DirtyRange()));
if (!skipWait) { if (!skipWait) {
const bool backed = pResource->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER; const bool backed = pResource->GetMapMode() == D3D9_COMMON_BUFFER_MAP_MODE_BUFFER;
const bool doNotWait = Flags & D3DLOCK_DONOTWAIT; 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; doImplicitDiscard = doImplicitDiscard && m_d3d9Options.allowImplicitDiscard;
@ -4447,8 +4447,8 @@ namespace dxvk {
return D3DERR_WASSTILLDRAWING; return D3DERR_WASSTILLDRAWING;
} }
pResource->SetReadLocked(false); pResource->SetWrittenByGPU(false);
pResource->DirtyRange().Clear(); pResource->GPUReadingRange().Clear();
} }
} }
@ -4493,8 +4493,8 @@ namespace dxvk {
cSrcSlice.length()); cSrcSlice.length());
}); });
pResource->DirtyRange().Conjoin(pResource->LockRange()); pResource->GPUReadingRange().Conjoin(pResource->DirtyRange());
pResource->LockRange().Clear(); pResource->DirtyRange().Clear();
pResource->MarkUploaded(); pResource->MarkUploaded();
return D3D_OK; return D3D_OK;