diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index b8eff840..c3db7fec 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -466,11 +466,12 @@ namespace dxvk { void D3D9CommonTexture::PreLoadAll() { - if (IsManaged()) { - auto lock = m_device->LockDevice(); + if (!IsManaged()) + return; - m_device->UploadManagedTexture(this); - } + auto lock = m_device->LockDevice(); + m_device->UploadManagedTexture(this); + m_device->MarkTextureUploaded(this); } @@ -481,6 +482,9 @@ namespace dxvk { if (GetNeedsUpload(Subresource)) { m_device->FlushImage(this, Subresource); SetNeedsUpload(Subresource, false); + + if (!NeedsAnyUpload()) + m_device->MarkTextureUploaded(this); } } } diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 307f65bd..4138e5b9 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -4891,12 +4891,11 @@ namespace dxvk { void D3D9DeviceEx::UploadManagedTexture(D3D9CommonTexture* pResource) { - for (uint32_t i = 0; i < pResource->GetUploadBitmask().dwordCount(); i++) { - for (uint32_t subresources = pResource->GetUploadBitmask().dword(i); subresources; subresources &= subresources - 1) { - uint32_t subresource = i * 32 + bit::tzcnt(subresources); + for (uint32_t subresource = 0; subresource < pResource->CountSubresources(); subresource++) { + if (!pResource->GetNeedsUpload(subresource)) + continue; - this->FlushImage(pResource, subresource); - } + this->FlushImage(pResource, subresource); } pResource->ClearNeedsUpload(); @@ -4958,6 +4957,18 @@ namespace dxvk { } + void D3D9DeviceEx::MarkTextureUploaded(D3D9CommonTexture* pResource) { + for (uint32_t tex = m_activeTextures; tex; tex &= tex - 1) { + // Guaranteed to not be nullptr... + const uint32_t i = bit::tzcnt(tex); + auto texInfo = GetCommonTexture(m_state.textures[i]); + + if (texInfo == pResource) + m_activeTexturesToUpload &= ~(1 << i); + } + } + + template void D3D9DeviceEx::UpdatePointMode() { if constexpr (!Points) { diff --git a/src/d3d9/d3d9_device.h b/src/d3d9/d3d9_device.h index 6f00b503..adb84724 100644 --- a/src/d3d9/d3d9_device.h +++ b/src/d3d9/d3d9_device.h @@ -758,6 +758,8 @@ namespace dxvk { void MarkTextureMipsUnDirty(D3D9CommonTexture* pResource); + void MarkTextureUploaded(D3D9CommonTexture* pResource); + template void UpdatePointMode();