mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
vulkan: fill buffer with initial data if supplied
This commit is contained in:
@@ -59,6 +59,7 @@ Buffer::Buffer(love::graphics::Graphics *gfx, const Settings &settings, const st
|
|||||||
, usageFlags(settings.usageFlags)
|
, usageFlags(settings.usageFlags)
|
||||||
, vgfx(dynamic_cast<Graphics*>(gfx))
|
, vgfx(dynamic_cast<Graphics*>(gfx))
|
||||||
, zeroInitialize(settings.zeroInitialize)
|
, zeroInitialize(settings.zeroInitialize)
|
||||||
|
, initialData(data)
|
||||||
{
|
{
|
||||||
loadVolatile();
|
loadVolatile();
|
||||||
}
|
}
|
||||||
@@ -86,6 +87,9 @@ bool Buffer::loadVolatile()
|
|||||||
if (zeroInitialize)
|
if (zeroInitialize)
|
||||||
vkCmdFillBuffer(vgfx->getCommandBufferForDataTransfer(), buffer, 0, VK_WHOLE_SIZE, 0);
|
vkCmdFillBuffer(vgfx->getCommandBufferForDataTransfer(), buffer, 0, VK_WHOLE_SIZE, 0);
|
||||||
|
|
||||||
|
if (initialData)
|
||||||
|
fill(0, size, initialData);
|
||||||
|
|
||||||
if (usageFlags & BUFFERUSAGEFLAG_TEXEL)
|
if (usageFlags & BUFFERUSAGEFLAG_TEXEL)
|
||||||
{
|
{
|
||||||
VkBufferViewCreateInfo bufferViewInfo{};
|
VkBufferViewCreateInfo bufferViewInfo{};
|
||||||
@@ -156,6 +160,8 @@ void *Buffer::map(MapType map, size_t offset, size_t size)
|
|||||||
if (vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &stagingBuffer, &stagingAllocation, &stagingAllocInfo) != VK_SUCCESS)
|
if (vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &stagingBuffer, &stagingAllocation, &stagingAllocInfo) != VK_SUCCESS)
|
||||||
throw love::Exception("failed to create staging buffer");
|
throw love::Exception("failed to create staging buffer");
|
||||||
|
|
||||||
|
mappedRange = Range(offset, size);
|
||||||
|
|
||||||
return stagingAllocInfo.pMappedData;
|
return stagingAllocInfo.pMappedData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,7 +194,8 @@ bool Buffer::fill(size_t offset, size_t size, const void *data)
|
|||||||
memcpy(fillAllocInfo.pMappedData, data, size);
|
memcpy(fillAllocInfo.pMappedData, data, size);
|
||||||
|
|
||||||
VkBufferCopy bufferCopy{};
|
VkBufferCopy bufferCopy{};
|
||||||
bufferCopy.srcOffset = offset;
|
bufferCopy.srcOffset = 0;
|
||||||
|
bufferCopy.dstOffset = offset;
|
||||||
bufferCopy.size = size;
|
bufferCopy.size = size;
|
||||||
|
|
||||||
vkCmdCopyBuffer(vgfx->getCommandBufferForDataTransfer(), fillBuffer, buffer, 1, &bufferCopy);
|
vkCmdCopyBuffer(vgfx->getCommandBufferForDataTransfer(), fillBuffer, buffer, 1, &bufferCopy);
|
||||||
@@ -205,7 +212,8 @@ void Buffer::unmap(size_t usedoffset, size_t usedsize)
|
|||||||
if (dataUsage != BUFFERDATAUSAGE_READBACK)
|
if (dataUsage != BUFFERDATAUSAGE_READBACK)
|
||||||
{
|
{
|
||||||
VkBufferCopy bufferCopy{};
|
VkBufferCopy bufferCopy{};
|
||||||
bufferCopy.srcOffset = usedoffset;
|
bufferCopy.srcOffset = usedoffset - mappedRange.getOffset();
|
||||||
|
bufferCopy.dstOffset = usedoffset;
|
||||||
bufferCopy.size = usedsize;
|
bufferCopy.size = usedsize;
|
||||||
|
|
||||||
vkCmdCopyBuffer(vgfx->getCommandBufferForDataTransfer(), stagingBuffer, buffer, 1, &bufferCopy);
|
vkCmdCopyBuffer(vgfx->getCommandBufferForDataTransfer(), stagingBuffer, buffer, 1, &bufferCopy);
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/Range.h"
|
||||||
|
|
||||||
#include "graphics/Buffer.h"
|
#include "graphics/Buffer.h"
|
||||||
#include "graphics/Volatile.h"
|
#include "graphics/Volatile.h"
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool zeroInitialize;
|
bool zeroInitialize;
|
||||||
|
const void *initialData;
|
||||||
VkBuffer buffer = VK_NULL_HANDLE;
|
VkBuffer buffer = VK_NULL_HANDLE;
|
||||||
VkBuffer stagingBuffer = VK_NULL_HANDLE;
|
VkBuffer stagingBuffer = VK_NULL_HANDLE;
|
||||||
VkBufferView bufferView = VK_NULL_HANDLE;
|
VkBufferView bufferView = VK_NULL_HANDLE;
|
||||||
@@ -65,6 +68,7 @@ private:
|
|||||||
VmaAllocationInfo allocInfo;
|
VmaAllocationInfo allocInfo;
|
||||||
VmaAllocationInfo stagingAllocInfo;
|
VmaAllocationInfo stagingAllocInfo;
|
||||||
BufferUsageFlags usageFlags;
|
BufferUsageFlags usageFlags;
|
||||||
|
Range mappedRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // vulkan
|
} // vulkan
|
||||||
|
|||||||
Reference in New Issue
Block a user