1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-21 22:54:16 +01:00

[d3d9] Clean up texture locking

We had two code paths that largely did the same.
This commit is contained in:
Robin Kertels 2022-02-14 20:04:36 +01:00 committed by Joshie
parent dde83717f1
commit b163a99bde

View File

@ -4147,12 +4147,7 @@ namespace dxvk {
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->invalidateBuffer(cImageBuffer, cBufferSlice); ctx->invalidateBuffer(cImageBuffer, cBufferSlice);
}); });
} } else {
else if ((managed && !m_d3d9Options.evictManagedOnUnlock) || scratch || systemmem) {
// Managed and scratch resources
// are meant to be able to provide readback without waiting.
// We always keep a copy of them in system memory for this reason.
// No need to wait as its not in use.
physSlice = pResource->GetMappedSlice(Subresource); physSlice = pResource->GetMappedSlice(Subresource);
// We do not need to wait for the resource in the event the // We do not need to wait for the resource in the event the
@ -4160,24 +4155,13 @@ namespace dxvk {
// or is reading. Remember! This will only trigger for MANAGED resources // or is reading. Remember! This will only trigger for MANAGED resources
// that cannot get affected by GPU, therefore readonly is A-OK for NOT waiting. // that cannot get affected by GPU, therefore readonly is A-OK for NOT waiting.
const bool usesStagingBuffer = pResource->DoesStagingBufferUploads(Subresource); const bool usesStagingBuffer = pResource->DoesStagingBufferUploads(Subresource);
const bool skipWait = (scratch || managed || (systemmem && !needsReadback)) const bool skipWait = (scratch || managed || systemmem) && !needsReadback
&& (usesStagingBuffer || readOnly); && (usesStagingBuffer || readOnly);
if (alloced) { if (alloced && !needsReadback) {
std::memset(physSlice.mapPtr, 0, physSlice.length); std::memset(physSlice.mapPtr, 0, physSlice.length);
} }
else if (!skipWait) { else if (!skipWait) {
if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), D3DLOCK_DONOTWAIT))
pResource->EnableStagingBufferUploads(Subresource);
if (!WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), Flags))
return D3DERR_WASSTILLDRAWING;
}
}
else {
physSlice = pResource->GetMappedSlice(Subresource);
if (!alloced || needsReadback) {
if (unlikely(needsReadback)) { if (unlikely(needsReadback)) {
Rc<DxvkImage> resourceImage = pResource->GetImage(); Rc<DxvkImage> resourceImage = pResource->GetImage();
@ -4247,16 +4231,12 @@ namespace dxvk {
cPackedFormat); cPackedFormat);
} }
}); });
} else if (!(Flags & D3DLOCK_DONOTWAIT) && !WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), D3DLOCK_DONOTWAIT)) {
pResource->EnableStagingBufferUploads(Subresource);
} }
if (!WaitForResource(mappedBuffer, DxvkCsThread::SynchronizeAll, Flags)) if (!WaitForResource(mappedBuffer, pResource->GetMappingBufferSequenceNumber(Subresource), Flags))
return D3DERR_WASSTILLDRAWING; return D3DERR_WASSTILLDRAWING;
} else {
// If we are a new alloc, and we weren't written by the GPU
// that means that we are a newly initialized
// texture, and hence can just memset -> 0 and
// avoid a wait here.
std::memset(physSlice.mapPtr, 0, physSlice.length);
} }
} }