mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-13 16:08:50 +01:00
[d3d11] Implement suballocation from staging buffer for small updates
This commit is contained in:
parent
7cf78a2c75
commit
b746e1352b
@ -4398,7 +4398,7 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
|
DxvkDataSlice D3D11DeviceContext::AllocUpdateBufferSlice(size_t Size) {
|
||||||
constexpr size_t UpdateBufferSize = 16 * 1024 * 1024;
|
constexpr size_t UpdateBufferSize = 1 * 1024 * 1024;
|
||||||
|
|
||||||
if (Size >= UpdateBufferSize) {
|
if (Size >= UpdateBufferSize) {
|
||||||
Rc<DxvkDataBuffer> buffer = new DxvkDataBuffer(Size);
|
Rc<DxvkDataBuffer> buffer = new DxvkDataBuffer(Size);
|
||||||
@ -4421,6 +4421,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer(
|
DxvkBufferSlice D3D11DeviceContext::AllocStagingBuffer(
|
||||||
VkDeviceSize Size) {
|
VkDeviceSize Size) {
|
||||||
|
constexpr VkDeviceSize StagingBufferSize = 4 * 1024 * 1024;
|
||||||
|
|
||||||
DxvkBufferCreateInfo info;
|
DxvkBufferCreateInfo info;
|
||||||
info.size = Size;
|
info.size = Size;
|
||||||
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT
|
||||||
@ -4432,8 +4434,32 @@ namespace dxvk {
|
|||||||
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
info.access = VK_ACCESS_TRANSFER_READ_BIT
|
||||||
| VK_ACCESS_SHADER_READ_BIT;
|
| VK_ACCESS_SHADER_READ_BIT;
|
||||||
|
|
||||||
return DxvkBufferSlice(m_device->createBuffer(info,
|
// Create a dedicated buffer for large allocations
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT));
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -712,7 +712,10 @@ namespace dxvk {
|
|||||||
|
|
||||||
Rc<DxvkDevice> m_device;
|
Rc<DxvkDevice> m_device;
|
||||||
Rc<DxvkDataBuffer> m_updateBuffer;
|
Rc<DxvkDataBuffer> m_updateBuffer;
|
||||||
|
|
||||||
|
Rc<DxvkBuffer> m_stagingBuffer;
|
||||||
|
VkDeviceSize m_stagingOffset = 0ull;
|
||||||
|
|
||||||
DxvkCsChunkFlags m_csFlags;
|
DxvkCsChunkFlags m_csFlags;
|
||||||
DxvkCsChunkRef m_csChunk;
|
DxvkCsChunkRef m_csChunk;
|
||||||
|
|
||||||
@ -927,7 +930,9 @@ namespace dxvk {
|
|||||||
|
|
||||||
DxvkBufferSlice AllocStagingBuffer(
|
DxvkBufferSlice AllocStagingBuffer(
|
||||||
VkDeviceSize Size);
|
VkDeviceSize Size);
|
||||||
|
|
||||||
|
void ResetStagingBuffer();
|
||||||
|
|
||||||
DxvkCsChunkRef AllocCsChunk();
|
DxvkCsChunkRef AllocCsChunk();
|
||||||
|
|
||||||
static void InitDefaultPrimitiveTopology(
|
static void InitDefaultPrimitiveTopology(
|
||||||
|
@ -175,6 +175,7 @@ namespace dxvk {
|
|||||||
ClearState();
|
ClearState();
|
||||||
|
|
||||||
m_mappedResources.clear();
|
m_mappedResources.clear();
|
||||||
|
ResetStagingBuffer();
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user