mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-01 10:54:14 +01:00
[d3d11] Optimized buffer mapping on deferred contexts
This commit is contained in:
parent
5cc3afcf30
commit
425a5bca2e
@ -92,7 +92,7 @@ namespace dxvk {
|
|||||||
m_mappedResources.push_back(entry);
|
m_mappedResources.push_back(entry);
|
||||||
|
|
||||||
// Fill mapped resource structure
|
// Fill mapped resource structure
|
||||||
pMappedResource->pData = entry.DataSlice.ptr();
|
pMappedResource->pData = entry.MapPointer;
|
||||||
pMappedResource->RowPitch = entry.RowPitch;
|
pMappedResource->RowPitch = entry.RowPitch;
|
||||||
pMappedResource->DepthPitch = entry.DepthPitch;
|
pMappedResource->DepthPitch = entry.DepthPitch;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -107,7 +107,7 @@ namespace dxvk {
|
|||||||
// Return same memory region as earlier
|
// Return same memory region as earlier
|
||||||
entry->MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
entry->MapType = D3D11_MAP_WRITE_NO_OVERWRITE;
|
||||||
|
|
||||||
pMappedResource->pData = entry->DataSlice.ptr();
|
pMappedResource->pData = entry->MapPointer;
|
||||||
pMappedResource->RowPitch = entry->RowPitch;
|
pMappedResource->RowPitch = entry->RowPitch;
|
||||||
pMappedResource->DepthPitch = entry->DepthPitch;
|
pMappedResource->DepthPitch = entry->DepthPitch;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
@ -145,9 +145,12 @@ namespace dxvk {
|
|||||||
D3D11_MAP MapType,
|
D3D11_MAP MapType,
|
||||||
UINT MapFlags,
|
UINT MapFlags,
|
||||||
D3D11DeferredContextMapEntry* pMapEntry) {
|
D3D11DeferredContextMapEntry* pMapEntry) {
|
||||||
const D3D11Buffer* pBuffer = static_cast<D3D11Buffer*>(pResource);
|
D3D11Buffer* pBuffer = static_cast<D3D11Buffer*>(pResource);
|
||||||
const Rc<DxvkBuffer> buffer = pBuffer->GetBuffer();
|
const Rc<DxvkBuffer> buffer = pBuffer->GetBuffer();
|
||||||
|
|
||||||
|
D3D11_BUFFER_DESC bufferDesc;
|
||||||
|
pBuffer->GetDesc(&bufferDesc);
|
||||||
|
|
||||||
if (!(buffer->memFlags() & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) {
|
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;
|
||||||
@ -158,7 +161,20 @@ namespace dxvk {
|
|||||||
pMapEntry->MapType = D3D11_MAP_WRITE_DISCARD;
|
pMapEntry->MapType = D3D11_MAP_WRITE_DISCARD;
|
||||||
pMapEntry->RowPitch = pBuffer->GetSize();
|
pMapEntry->RowPitch = pBuffer->GetSize();
|
||||||
pMapEntry->DepthPitch = pBuffer->GetSize();
|
pMapEntry->DepthPitch = pBuffer->GetSize();
|
||||||
pMapEntry->DataSlice = AllocUpdateBufferSlice(pBuffer->GetSize());
|
|
||||||
|
if (bufferDesc.Usage == D3D11_USAGE_DYNAMIC) {
|
||||||
|
// For resources that cannot be written by the GPU,
|
||||||
|
// we may write to the buffer resource directly and
|
||||||
|
// just swap in the physical buffer slice as needed.
|
||||||
|
pMapEntry->BufferSlice = buffer->allocPhysicalSlice();
|
||||||
|
pMapEntry->MapPointer = pMapEntry->BufferSlice.mapPtr(0);
|
||||||
|
} else {
|
||||||
|
// For GPU-writable resources, we need a data slice
|
||||||
|
// to perform the update operation at execution time.
|
||||||
|
pMapEntry->DataSlice = AllocUpdateBufferSlice(pBuffer->GetSize());
|
||||||
|
pMapEntry->MapPointer = pMapEntry->DataSlice.ptr();
|
||||||
|
}
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,6 +219,7 @@ namespace dxvk {
|
|||||||
pMapEntry->RowPitch = xSize;
|
pMapEntry->RowPitch = xSize;
|
||||||
pMapEntry->DepthPitch = ySize;
|
pMapEntry->DepthPitch = ySize;
|
||||||
pMapEntry->DataSlice = AllocUpdateBufferSlice(zSize);
|
pMapEntry->DataSlice = AllocUpdateBufferSlice(zSize);
|
||||||
|
pMapEntry->MapPointer = pMapEntry->DataSlice.ptr();
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,14 +229,26 @@ namespace dxvk {
|
|||||||
const D3D11DeferredContextMapEntry* pMapEntry) {
|
const D3D11DeferredContextMapEntry* pMapEntry) {
|
||||||
D3D11Buffer* pBuffer = static_cast<D3D11Buffer*>(pResource);
|
D3D11Buffer* pBuffer = static_cast<D3D11Buffer*>(pResource);
|
||||||
|
|
||||||
EmitCs([
|
D3D11_BUFFER_DESC bufferDesc;
|
||||||
cDstBuffer = pBuffer->GetBuffer(),
|
pBuffer->GetDesc(&bufferDesc);
|
||||||
cDataSlice = pMapEntry->DataSlice
|
|
||||||
] (DxvkContext* ctx) {
|
if (bufferDesc.Usage == D3D11_USAGE_DYNAMIC) {
|
||||||
DxvkPhysicalBufferSlice slice = cDstBuffer->allocPhysicalSlice();
|
EmitCs([
|
||||||
std::memcpy(slice.mapPtr(0), cDataSlice.ptr(), cDataSlice.length());
|
cDstBuffer = pBuffer->GetBuffer(),
|
||||||
ctx->invalidateBuffer(cDstBuffer, slice);
|
cPhysSlice = pMapEntry->BufferSlice
|
||||||
});
|
] (DxvkContext* ctx) {
|
||||||
|
ctx->invalidateBuffer(cDstBuffer, cPhysSlice);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
EmitCs([
|
||||||
|
cDstBuffer = pBuffer->GetBuffer(),
|
||||||
|
cDataSlice = pMapEntry->DataSlice
|
||||||
|
] (DxvkContext* ctx) {
|
||||||
|
DxvkPhysicalBufferSlice slice = cDstBuffer->allocPhysicalSlice();
|
||||||
|
std::memcpy(slice.mapPtr(0), cDataSlice.ptr(), cDataSlice.length());
|
||||||
|
ctx->invalidateBuffer(cDstBuffer, slice);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@
|
|||||||
namespace dxvk {
|
namespace dxvk {
|
||||||
|
|
||||||
struct D3D11DeferredContextMapEntry {
|
struct D3D11DeferredContextMapEntry {
|
||||||
Com<ID3D11Resource> pResource;
|
Com<ID3D11Resource> pResource;
|
||||||
UINT Subresource;
|
UINT Subresource;
|
||||||
D3D11_MAP MapType;
|
D3D11_MAP MapType;
|
||||||
UINT RowPitch;
|
UINT RowPitch;
|
||||||
UINT DepthPitch;
|
UINT DepthPitch;
|
||||||
DxvkDataSlice DataSlice;
|
DxvkDataSlice DataSlice;
|
||||||
|
DxvkPhysicalBufferSlice BufferSlice;
|
||||||
|
void* MapPointer;
|
||||||
};
|
};
|
||||||
|
|
||||||
class D3D11DeferredContext : public D3D11DeviceContext {
|
class D3D11DeferredContext : public D3D11DeviceContext {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user