1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-15 07:29:17 +01:00

[d3d11] Optimize Unmap on immediate contexts

This commit is contained in:
Philip Rebohle 2022-02-10 04:34:50 +01:00
parent 5a6711ed1d
commit 0364a79eb0
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 21 additions and 10 deletions

View File

@ -273,14 +273,19 @@ namespace dxvk {
void STDMETHODCALLTYPE D3D11ImmediateContext::Unmap( void STDMETHODCALLTYPE D3D11ImmediateContext::Unmap(
ID3D11Resource* pResource, ID3D11Resource* pResource,
UINT Subresource) { UINT Subresource) {
// Since it is very uncommon for images to be mapped compared
// to buffers, we count the currently mapped images in order
// to avoid a virtual method call in the common case.
if (unlikely(m_mappedImageCount > 0)) {
D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN;
pResource->GetType(&resourceDim); pResource->GetType(&resourceDim);
if (unlikely(resourceDim != D3D11_RESOURCE_DIMENSION_BUFFER)) { if (resourceDim != D3D11_RESOURCE_DIMENSION_BUFFER) {
D3D10DeviceLock lock = LockContext(); D3D10DeviceLock lock = LockContext();
UnmapImage(GetCommonTexture(pResource), Subresource); UnmapImage(GetCommonTexture(pResource), Subresource);
} }
} }
}
void STDMETHODCALLTYPE D3D11ImmediateContext::UpdateSubresource( void STDMETHODCALLTYPE D3D11ImmediateContext::UpdateSubresource(
ID3D11Resource* pDstResource, ID3D11Resource* pDstResource,
@ -467,6 +472,7 @@ namespace dxvk {
pMappedResource->DepthPitch = layout.DepthPitch; pMappedResource->DepthPitch = layout.DepthPitch;
} }
m_mappedImageCount += 1;
return S_OK; return S_OK;
} }
@ -477,11 +483,15 @@ namespace dxvk {
D3D11_MAP mapType = pResource->GetMapType(Subresource); D3D11_MAP mapType = pResource->GetMapType(Subresource);
pResource->SetMapType(Subresource, D3D11_MAP(~0u)); pResource->SetMapType(Subresource, D3D11_MAP(~0u));
if (mapType == D3D11_MAP(~0u) if (mapType == D3D11_MAP(~0u))
|| mapType == D3D11_MAP_READ)
return; return;
if (pResource->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER) { // Decrement mapped image counter only after making sure
// the given subresource is actually mapped right now
m_mappedImageCount -= 1;
if ((mapType != D3D11_MAP_READ) &&
(pResource->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_BUFFER)) {
// Now that data has been written into the buffer, // Now that data has been written into the buffer,
// we need to copy its contents into the image // we need to copy its contents into the image
VkImageAspectFlags aspectMask = imageFormatInfo(pResource->GetPackedFormat())->aspectMask; VkImageAspectFlags aspectMask = imageFormatInfo(pResource->GetPackedFormat())->aspectMask;

View File

@ -123,6 +123,7 @@ namespace dxvk {
Rc<sync::CallbackFence> m_eventSignal; Rc<sync::CallbackFence> m_eventSignal;
uint64_t m_eventCount = 0ull; uint64_t m_eventCount = 0ull;
uint32_t m_mappedImageCount = 0u;
dxvk::high_resolution_clock::time_point m_lastFlush dxvk::high_resolution_clock::time_point m_lastFlush