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

[d3d11] Implement suballocation from staging buffer for small updates

This commit is contained in:
Philip Rebohle 2022-02-06 18:19:37 +01:00
parent 7cf78a2c75
commit b746e1352b
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 37 additions and 5 deletions

View File

@ -4398,7 +4398,7 @@ namespace dxvk {
DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
constexpr size_t UpdateBufferSize = 16 * 1024 * 1024;
constexpr size_t UpdateBufferSize = 1 * 1024 * 1024;
if (Size >= UpdateBufferSize) {
Rc<DxvkDataBuffer> buffer = new DxvkDataBuffer(Size);
@ -4421,6 +4421,8 @@ namespace dxvk {
DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer(
VkDeviceSize Size) {
constexpr VkDeviceSize StagingBufferSize = 4 * 1024 * 1024;
DxvkBufferCreateInfo info;
info.size = Size;
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
@ -4432,8 +4434,32 @@ namespace dxvk {
info.access = VK_ACCESS_TRANSFER_READ_BIT
| VK_ACCESS_SHADER_READ_BIT;
return DxvkBufferSlice(m_device->createBuffer(info,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
// Create a dedicated buffer for large allocations
VkDeviceSize alignedSize = align(Size, 256);
if (alignedSize >= StagingBufferSize) {
return DxvkBufferSlice(m_device->createBuffer(info,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
}
// Otherwise, try to suballocate from an existing buffer
if (m_stagingOffset + alignedSize > StagingBufferSize || m_stagingBuffer == nullptr) {
info.size = StagingBufferSize;
m_stagingBuffer = m_device->createBuffer(info,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT);
m_stagingOffset = 0;
}
DxvkBufferSlice slice(m_stagingBuffer, m_stagingOffset, Size);
m_stagingOffset += alignedSize;
return slice;
}
void D3D11DeviceContext::ResetStagingBuffer() {
m_stagingBuffer = nullptr;
m_stagingOffset = 0;
}

View File

@ -712,7 +712,10 @@ namespace dxvk {
Rc<DxvkDevice> m_device;
Rc<DxvkDataBuffer> m_updateBuffer;
Rc<DxvkBuffer> m_stagingBuffer;
VkDeviceSize m_stagingOffset = 0ull;
DxvkCsChunkFlags m_csFlags;
DxvkCsChunkRef m_csChunk;
@ -927,7 +930,9 @@ namespace dxvk {
DxvkBufferSlice AllocStagingBuffer(
VkDeviceSize Size);
void ResetStagingBuffer();
DxvkCsChunkRef AllocCsChunk();
static void InitDefaultPrimitiveTopology(

View File

@ -175,6 +175,7 @@ namespace dxvk {
ClearState();
m_mappedResources.clear();
ResetStagingBuffer();
return S_OK;
}