From 940ac051377530bf7aa48e4993d4c8dcaa7b028d Mon Sep 17 00:00:00 2001 From: niki Date: Thu, 13 Oct 2022 23:58:31 +0200 Subject: [PATCH] vulkan: call invalidate if mapping is incoherent --- src/modules/graphics/vulkan/Buffer.cpp | 19 +++++++++++++++++-- src/modules/graphics/vulkan/Graphics.cpp | 1 - 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/vulkan/Buffer.cpp b/src/modules/graphics/vulkan/Buffer.cpp index e82b6ed0a..255cf649e 100644 --- a/src/modules/graphics/vulkan/Buffer.cpp +++ b/src/modules/graphics/vulkan/Buffer.cpp @@ -148,8 +148,25 @@ ptrdiff_t Buffer::getTexelBufferHandle() const void *Buffer::map(MapType map, size_t offset, size_t size) { + if (size == 0) + return nullptr; + + if (map == MAP_WRITE_INVALIDATE && (isImmutable() || dataUsage == BUFFERDATAUSAGE_READBACK)) + return nullptr; + + if (map == MAP_READ_ONLY && dataUsage != BUFFERDATAUSAGE_READBACK) + return nullptr; + + mappedRange = Range(offset, size); + + if (!Range(0, getSize()).contains(mappedRange)) + return nullptr; + if (dataUsage == BUFFERDATAUSAGE_READBACK) { + if (!coherent) + vmaInvalidateAllocation(allocator, allocation, offset, size); + char *data = (char*)allocInfo.pMappedData; return (void*) (data + offset); } @@ -167,8 +184,6 @@ void *Buffer::map(MapType map, size_t offset, size_t size) if (vmaCreateBuffer(allocator, &bufferInfo, &allocInfo, &stagingBuffer, &stagingAllocation, &stagingAllocInfo) != VK_SUCCESS) throw love::Exception("failed to create staging buffer"); - mappedRange = Range(offset, size); - return stagingAllocInfo.pMappedData; } } diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 7630d13a3..065add298 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -34,7 +34,6 @@ #include #include #include -#include #include #include