diff --git a/src/d3d11/d3d11_buffer.h b/src/d3d11/d3d11_buffer.h index 5f370663..1883aa51 100644 --- a/src/d3d11/d3d11_buffer.h +++ b/src/d3d11/d3d11_buffer.h @@ -13,6 +13,15 @@ namespace dxvk { class D3D11DeviceContext; + /** + * \brief Buffer map mode + */ + enum D3D11_COMMON_BUFFER_MAP_MODE { + D3D11_COMMON_BUFFER_MAP_MODE_NONE, + D3D11_COMMON_BUFFER_MAP_MODE_DIRECT, + }; + + /** * \brief Stream output buffer offset * @@ -59,6 +68,12 @@ namespace dxvk { return &m_desc; } + D3D11_COMMON_BUFFER_MAP_MODE GetMapMode() const { + return (m_buffer->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) + ? D3D11_COMMON_BUFFER_MAP_MODE_DIRECT + : D3D11_COMMON_BUFFER_MAP_MODE_NONE; + } + Rc GetBuffer() const { return m_buffer; } diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 3ac3d0e8..bd3ba714 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -183,7 +183,7 @@ namespace dxvk { pMappedResource); } - if (FAILED(hr)) { + if (unlikely(FAILED(hr))) { pMappedResource->pData = nullptr; pMappedResource->RowPitch = 0; pMappedResource->DepthPitch = 0; @@ -340,9 +340,7 @@ namespace dxvk { D3D11_MAP MapType, UINT MapFlags, D3D11_MAPPED_SUBRESOURCE* pMappedResource) { - Rc buffer = pResource->GetBuffer(); - - if (!(buffer->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) { + if (unlikely(pResource->GetMapMode() == D3D11_COMMON_BUFFER_MAP_MODE_NONE)) { Logger::err("D3D11: Cannot map a device-local buffer"); return E_INVALIDARG; } @@ -357,8 +355,8 @@ namespace dxvk { pMappedResource->DepthPitch = pResource->Desc()->ByteWidth; EmitCs([ - cBuffer = std::move(buffer), - cBufferSlice = std::move(physSlice) + cBuffer = pResource->GetBuffer(), + cBufferSlice = physSlice ] (DxvkContext* ctx) { ctx->invalidateBuffer(cBuffer, cBufferSlice); }); @@ -367,7 +365,7 @@ namespace dxvk { } else { // Wait until the resource is no longer in use if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) { - if (!WaitForResource(buffer, MapFlags)) + if (!WaitForResource(pResource->GetBuffer(), MapFlags)) return DXGI_ERROR_WAS_STILL_DRAWING; } @@ -393,7 +391,7 @@ namespace dxvk { const Rc mappedImage = pResource->GetImage(); const Rc mappedBuffer = pResource->GetMappedBuffer(); - if (pResource->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_NONE) { + if (unlikely(pResource->GetMapMode() == D3D11_COMMON_TEXTURE_MAP_MODE_NONE)) { Logger::err("D3D11: Cannot map a device-local image"); return E_INVALIDARG; }