- VMA_MEMORY_USAGE_CPU_TO_GPU does not require VK_MEMORY_PROPERTY_HOST_COHERENT_BIT to bet set. Current implementation requires this flag as vkFlushMappedMemoryRanges is never called.

This commit is contained in:
Magnus Norddahl 2019-05-02 01:35:04 +02:00
parent ea9be6c225
commit d1554aed37
3 changed files with 41 additions and 3 deletions

View file

@ -76,7 +76,10 @@ void VKBuffer::SetData(size_t size, const void *data, bool staticdata)
mPersistent = screen->BuffersArePersistent();
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU, mPersistent ? VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT : 0);
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, mPersistent ? VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT : 0);
builder.setMemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
builder.setSize(size);
mBuffer = builder.create(fb->device);
@ -127,7 +130,10 @@ void VKBuffer::Resize(size_t newsize)
// Create new buffer
BufferBuilder builder;
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_CPU_TO_GPU, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
builder.setUsage(mBufferType, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
builder.setMemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
builder.setSize(newsize);
mBuffer = builder.create(fb->device);
buffersize = newsize;

View file

@ -42,11 +42,13 @@ public:
void setSamples(VkSampleCountFlagBits samples);
void setFormat(VkFormat format);
void setUsage(VkImageUsageFlags imageUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY, VmaAllocationCreateFlags allocFlags = 0);
void setMemoryType(VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags preferredFlags, uint32_t memoryTypeBits = 0);
void setLinearTiling();
bool isFormatSupported(VulkanDevice *device);
std::unique_ptr<VulkanImage> create(VulkanDevice *device);
std::unique_ptr<VulkanImage> tryCreate(VulkanDevice *device);
private:
VkImageCreateInfo imageInfo = {};
@ -92,6 +94,7 @@ public:
void setSize(size_t size);
void setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsage memoryUsage = VMA_MEMORY_USAGE_GPU_ONLY, VmaAllocationCreateFlags allocFlags = 0);
void setMemoryType(VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags preferredFlags, uint32_t memoryTypeBits = 0);
std::unique_ptr<VulkanBuffer> create(VulkanDevice *device);
@ -400,6 +403,13 @@ inline void ImageBuilder::setUsage(VkImageUsageFlags usage, VmaMemoryUsage memor
allocInfo.flags = allocFlags;
}
inline void ImageBuilder::setMemoryType(VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags preferredFlags, uint32_t memoryTypeBits)
{
allocInfo.requiredFlags = requiredFlags;
allocInfo.preferredFlags = preferredFlags;
allocInfo.memoryTypeBits = memoryTypeBits;
}
inline bool ImageBuilder::isFormatSupported(VulkanDevice *device)
{
VkImageFormatProperties properties = { };
@ -426,6 +436,18 @@ inline std::unique_ptr<VulkanImage> ImageBuilder::create(VulkanDevice *device)
return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels);
}
inline std::unique_ptr<VulkanImage> ImageBuilder::tryCreate(VulkanDevice *device)
{
VkImage image;
VmaAllocation allocation;
VkResult result = vmaCreateImage(device->allocator, &imageInfo, &allocInfo, &image, &allocation, nullptr);
if (result != VK_SUCCESS)
return nullptr;
return std::make_unique<VulkanImage>(device, image, allocation, imageInfo.extent.width, imageInfo.extent.height, imageInfo.mipLevels);
}
/////////////////////////////////////////////////////////////////////////////
inline ImageViewBuilder::ImageViewBuilder()
@ -547,6 +569,13 @@ inline void BufferBuilder::setUsage(VkBufferUsageFlags bufferUsage, VmaMemoryUsa
allocInfo.flags = allocFlags;
}
inline void BufferBuilder::setMemoryType(VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags preferredFlags, uint32_t memoryTypeBits)
{
allocInfo.requiredFlags = requiredFlags;
allocInfo.preferredFlags = preferredFlags;
allocInfo.memoryTypeBits = memoryTypeBits;
}
inline std::unique_ptr<VulkanBuffer> BufferBuilder::create(VulkanDevice *device)
{
VkBuffer buffer;

View file

@ -337,8 +337,11 @@ void VkHardwareTexture::AllocateBuffer(int w, int h, int texelsize)
ImageBuilder imgbuilder;
imgbuilder.setFormat(format);
imgbuilder.setSize(w, h);
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT, VMA_MEMORY_USAGE_CPU_TO_GPU, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
imgbuilder.setLinearTiling();
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT, VMA_MEMORY_USAGE_UNKNOWN, VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT | VMA_ALLOCATION_CREATE_MAPPED_BIT);
imgbuilder.setMemoryType(
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
mImage = imgbuilder.create(fb->device);
mImage->SetDebugName("VkHardwareTexture.mImage");
mImageLayout = VK_IMAGE_LAYOUT_GENERAL;