1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-03 04:24:11 +01:00

[d3d9] Clean up resource locking code

This commit is contained in:
Joshua Ashton 2021-02-27 20:15:39 +00:00
parent e8fc7ea23a
commit 8c2ec5d9c9
No known key found for this signature in database
GPG Key ID: C85A08669126BE8D

View File

@ -3999,6 +3999,7 @@ namespace dxvk {
const bool systemmem = desc.Pool == D3DPOOL_SYSTEMMEM; const bool systemmem = desc.Pool == D3DPOOL_SYSTEMMEM;
const bool managed = IsPoolManaged(desc.Pool); const bool managed = IsPoolManaged(desc.Pool);
const bool scratch = desc.Pool == D3DPOOL_SCRATCH; const bool scratch = desc.Pool == D3DPOOL_SCRATCH;
const bool doNotWait = Flags & D3DLOCK_DONOTWAIT;
bool fullResource = pBox == nullptr; bool fullResource = pBox == nullptr;
if (unlikely(!fullResource)) { if (unlikely(!fullResource)) {
@ -4065,26 +4066,32 @@ namespace dxvk {
// 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 skipWait = (readOnly && managed) || scratch || (readOnly && systemmem && !dirty); const bool skipWait = (readOnly && managed) || scratch || (readOnly && systemmem && !dirty);
if (alloced) bool doImplicitDiscard = (managed || (systemmem && !dirty)) && !doNotWait;
doImplicitDiscard = doImplicitDiscard && m_d3d9Options.allowImplicitDiscard;
if (alloced) {
std::memset(physSlice.mapPtr, 0, physSlice.length); std::memset(physSlice.mapPtr, 0, physSlice.length);
else if ((managed || (systemmem && !dirty)) && !(Flags & D3DLOCK_DONOTWAIT) && !skipWait }
&& m_d3d9Options.allowImplicitDiscard) { else if (!skipWait) {
if (!WaitForResource(mappedBuffer, D3DLOCK_DONOTWAIT)) { if (doImplicitDiscard) {
// if the mapped buffer is currently being copied to image if (!WaitForResource(mappedBuffer, D3DLOCK_DONOTWAIT)) {
// we can just avoid a stall by allocating a new slice and copying the existing contents // if the mapped buffer is currently being copied to image
DxvkBufferSliceHandle oldSlice = physSlice; // we can just avoid a stall by allocating a new slice and copying the existing contents
physSlice = pResource->DiscardMapSlice(Subresource); DxvkBufferSliceHandle oldSlice = physSlice;
std::memcpy(physSlice.mapPtr, oldSlice.mapPtr, oldSlice.length); physSlice = pResource->DiscardMapSlice(Subresource);
EmitCs([ std::memcpy(physSlice.mapPtr, oldSlice.mapPtr, oldSlice.length);
cImageBuffer = std::move(mappedBuffer), EmitCs([
cBufferSlice = physSlice cImageBuffer = std::move(mappedBuffer),
] (DxvkContext* ctx) { cBufferSlice = physSlice
ctx->invalidateBuffer(cImageBuffer, cBufferSlice); ] (DxvkContext* ctx) {
}); ctx->invalidateBuffer(cImageBuffer, cBufferSlice);
});
}
} else {
if (!WaitForResource(mappedBuffer, Flags))
return D3DERR_WASSTILLDRAWING;
} }
} else if (!skipWait) {
if (!WaitForResource(mappedBuffer, Flags))
return D3DERR_WASSTILLDRAWING;
} }
} }
else { else {
@ -4414,8 +4421,15 @@ namespace dxvk {
quickRead || quickRead ||
(boundsCheck && !pResource->DirtyRange().Overlaps(pResource->LockRange())); (boundsCheck && !pResource->DirtyRange().Overlaps(pResource->LockRange()));
if (!skipWait) { if (!skipWait) {
if ((IsPoolManaged(desc.Pool) || desc.Pool == D3DPOOL_SYSTEMMEM) && !(Flags & D3DLOCK_DONOTWAIT) && pResource->GetLockCount() == 0 const bool managed = IsPoolManaged(desc.Pool);
&& m_d3d9Options.allowImplicitDiscard) { const bool systemmem = desc.Pool == D3DPOOL_SYSTEMMEM;
const bool doNotWait = Flags & D3DLOCK_DONOTWAIT;
bool doImplicitDiscard = (managed || systemmem) && !doNotWait && pResource->GetLockCount() == 0;
doImplicitDiscard = doImplicitDiscard && m_d3d9Options.allowImplicitDiscard;
if (doImplicitDiscard) {
if (!WaitForResource(mappingBuffer, D3DLOCK_DONOTWAIT)) { if (!WaitForResource(mappingBuffer, D3DLOCK_DONOTWAIT)) {
// if the mapped buffer is currently being copied to the primary buffer // if the mapped buffer is currently being copied to the primary buffer
// we can just avoid a stall by allocating a new slice and copying the existing contents // we can just avoid a stall by allocating a new slice and copying the existing contents