From f85f631c4b6994fa3def2d0e561b70d00f4de923 Mon Sep 17 00:00:00 2001 From: Benau Date: Mon, 10 Oct 2022 10:26:05 +0800 Subject: [PATCH] Return true if buffer resized --- lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp | 11 +++++++---- lib/graphics_engine/src/ge_vulkan_dynamic_buffer.hpp | 8 ++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp b/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp index 642ec3347..6fd69009c 100644 --- a/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp +++ b/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.cpp @@ -137,7 +137,7 @@ void GEVulkanDynamicBuffer::destroy() } // destroy // ---------------------------------------------------------------------------- -void GEVulkanDynamicBuffer::setCurrentData(const std::vector< +bool GEVulkanDynamicBuffer::setCurrentData(const std::vector< std::pair >& data, VkCommandBuffer custom_cmd) { @@ -146,7 +146,7 @@ void GEVulkanDynamicBuffer::setCurrentData(const std::vector< size_t size = 0; for (auto& p : data) size += p.second; - resizeIfNeeded(size); + bool ret = resizeIfNeeded(size); m_real_size = size; unsigned cur_frame = getVKDriver()->getCurrentFrame(); @@ -154,7 +154,7 @@ void GEVulkanDynamicBuffer::setCurrentData(const std::vector< cur_frame = 0; if (size == 0 || m_mapped_addr.empty() || m_mapped_addr[cur_frame] == NULL) - return; + return ret; uint8_t* addr = (uint8_t*)m_mapped_addr[cur_frame]; for (auto& p : data) @@ -176,10 +176,11 @@ void GEVulkanDynamicBuffer::setCurrentData(const std::vector< m_host_buffer[cur_frame], m_local_buffer[cur_local_frame], 1, ©_region); } + return ret; } // setCurrentData // ---------------------------------------------------------------------------- -void GEVulkanDynamicBuffer::resizeIfNeeded(size_t new_size) +bool GEVulkanDynamicBuffer::resizeIfNeeded(size_t new_size) { if (new_size > m_size) { @@ -189,7 +190,9 @@ void GEVulkanDynamicBuffer::resizeIfNeeded(size_t new_size) initHostBuffer(i, m_local_buffer.size() == 0); for (unsigned i = 0; i < m_local_buffer.size(); i++) initLocalBuffer(i); + return true; } + return false; } // resizeIfNeeded // ---------------------------------------------------------------------------- diff --git a/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.hpp b/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.hpp index 16943d8bc..8d33e418d 100644 --- a/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.hpp +++ b/lib/graphics_engine/src/ge_vulkan_dynamic_buffer.hpp @@ -41,16 +41,16 @@ public: // ------------------------------------------------------------------------ ~GEVulkanDynamicBuffer(); // ------------------------------------------------------------------------ - void setCurrentData(const std::vector >& data, + bool setCurrentData(const std::vector >& data, VkCommandBuffer custom_cmd = VK_NULL_HANDLE); // ------------------------------------------------------------------------ - void setCurrentData(void* data, size_t size, + bool setCurrentData(void* data, size_t size, VkCommandBuffer custom_cmd = VK_NULL_HANDLE) - { setCurrentData({{ data, size }}, custom_cmd); } + { return setCurrentData({{ data, size }}, custom_cmd); } // ------------------------------------------------------------------------ VkBuffer getCurrentBuffer() const; // ------------------------------------------------------------------------ - void resizeIfNeeded(size_t new_size); + bool resizeIfNeeded(size_t new_size); // ------------------------------------------------------------------------ size_t getSize() const { return m_size; } // ------------------------------------------------------------------------