1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 07:08:50 +01:00

[d3d11] Minor map optimization on immediate contexts

We should make the fast path as fast as possible.
This commit is contained in:
Philip Rebohle 2019-02-04 10:24:04 +01:00
parent 01a7e06ad7
commit 8d493d9445
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 21 additions and 8 deletions

View File

@ -13,6 +13,15 @@ namespace dxvk {
class D3D11DeviceContext; 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 * \brief Stream output buffer offset
* *
@ -59,6 +68,12 @@ namespace dxvk {
return &m_desc; 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<DxvkBuffer> GetBuffer() const { Rc<DxvkBuffer> GetBuffer() const {
return m_buffer; return m_buffer;
} }

View File

@ -183,7 +183,7 @@ namespace dxvk {
pMappedResource); pMappedResource);
} }
if (FAILED(hr)) { if (unlikely(FAILED(hr))) {
pMappedResource->pData = nullptr; pMappedResource->pData = nullptr;
pMappedResource->RowPitch = 0; pMappedResource->RowPitch = 0;
pMappedResource->DepthPitch = 0; pMappedResource->DepthPitch = 0;
@ -340,9 +340,7 @@ namespace dxvk {
D3D11_MAP MapType, D3D11_MAP MapType,
UINT MapFlags, UINT MapFlags,
D3D11_MAPPED_SUBRESOURCE* pMappedResource) { D3D11_MAPPED_SUBRESOURCE* pMappedResource) {
Rc<DxvkBuffer> buffer = pResource->GetBuffer(); if (unlikely(pResource->GetMapMode() == D3D11_COMMON_BUFFER_MAP_MODE_NONE)) {
if (!(buffer->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) {
Logger::err("D3D11: Cannot map a device-local buffer"); Logger::err("D3D11: Cannot map a device-local buffer");
return E_INVALIDARG; return E_INVALIDARG;
} }
@ -357,8 +355,8 @@ namespace dxvk {
pMappedResource->DepthPitch = pResource->Desc()->ByteWidth; pMappedResource->DepthPitch = pResource->Desc()->ByteWidth;
EmitCs([ EmitCs([
cBuffer = std::move(buffer), cBuffer = pResource->GetBuffer(),
cBufferSlice = std::move(physSlice) cBufferSlice = physSlice
] (DxvkContext* ctx) { ] (DxvkContext* ctx) {
ctx->invalidateBuffer(cBuffer, cBufferSlice); ctx->invalidateBuffer(cBuffer, cBufferSlice);
}); });
@ -367,7 +365,7 @@ namespace dxvk {
} else { } else {
// Wait until the resource is no longer in use // Wait until the resource is no longer in use
if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) { if (MapType != D3D11_MAP_WRITE_NO_OVERWRITE) {
if (!WaitForResource(buffer, MapFlags)) if (!WaitForResource(pResource->GetBuffer(), MapFlags))
return DXGI_ERROR_WAS_STILL_DRAWING; return DXGI_ERROR_WAS_STILL_DRAWING;
} }
@ -393,7 +391,7 @@ namespace dxvk {
const Rc<DxvkImage> mappedImage = pResource->GetImage(); const Rc<DxvkImage> mappedImage = pResource->GetImage();
const Rc<DxvkBuffer> mappedBuffer = pResource->GetMappedBuffer(); const Rc<DxvkBuffer> 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"); Logger::err("D3D11: Cannot map a device-local image");
return E_INVALIDARG; return E_INVALIDARG;
} }