diff --git a/lib/graphics_engine/src/ge_vulkan_array_texture.cpp b/lib/graphics_engine/src/ge_vulkan_array_texture.cpp index 1005c1218..442cb014a 100644 --- a/lib/graphics_engine/src/ge_vulkan_array_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_array_texture.cpp @@ -45,7 +45,6 @@ GEVulkanArrayTexture::GEVulkanArrayTexture(const std::vector& list, m_max_size = m_vk->getDriverAttributes() .getAttributeAsDimension2d("MAX_TEXTURE_SIZE"); m_internal_format = VK_FORMAT_R8G8B8A8_UNORM; - m_texture_size = 0; m_size_lock.lock(); m_image_view_lock.lock(); diff --git a/lib/graphics_engine/src/ge_vulkan_array_texture.hpp b/lib/graphics_engine/src/ge_vulkan_array_texture.hpp index 3a3a419f3..e5c88c696 100644 --- a/lib/graphics_engine/src/ge_vulkan_array_texture.hpp +++ b/lib/graphics_engine/src/ge_vulkan_array_texture.hpp @@ -44,8 +44,6 @@ public: // ------------------------------------------------------------------------ virtual void regenerateMipMapLevels(void* mipmap_data = NULL) {} // ------------------------------------------------------------------------ - virtual unsigned int getTextureSize() const { return m_texture_size; } - // ------------------------------------------------------------------------ virtual void reload() {} // ------------------------------------------------------------------------ virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, diff --git a/lib/graphics_engine/src/ge_vulkan_depth_texture.cpp b/lib/graphics_engine/src/ge_vulkan_depth_texture.cpp index dfac2f8ad..25cb24296 100644 --- a/lib/graphics_engine/src/ge_vulkan_depth_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_depth_texture.cpp @@ -16,7 +16,6 @@ GEVulkanDepthTexture::GEVulkanDepthTexture(GEVulkanDriver* vk, m_has_mipmaps = false; m_locked_data = NULL; m_size = m_orig_size = m_max_size = size; - m_texture_size = m_size.Width * m_size.Height * 4; std::vector preferred = { diff --git a/lib/graphics_engine/src/ge_vulkan_depth_texture.hpp b/lib/graphics_engine/src/ge_vulkan_depth_texture.hpp index 614612e9e..7e82310d7 100644 --- a/lib/graphics_engine/src/ge_vulkan_depth_texture.hpp +++ b/lib/graphics_engine/src/ge_vulkan_depth_texture.hpp @@ -41,8 +41,6 @@ public: virtual u64 getTextureHandler() const { return (u64)(m_image_view.get()->load()); } // ------------------------------------------------------------------------ - virtual unsigned int getTextureSize() const { return m_texture_size; } - // ------------------------------------------------------------------------ virtual void reload() {} // ------------------------------------------------------------------------ virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, diff --git a/lib/graphics_engine/src/ge_vulkan_fbo_texture.cpp b/lib/graphics_engine/src/ge_vulkan_fbo_texture.cpp index 754f66b01..ac1b717bd 100644 --- a/lib/graphics_engine/src/ge_vulkan_fbo_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_fbo_texture.cpp @@ -21,7 +21,6 @@ GEVulkanFBOTexture::GEVulkanFBOTexture(GEVulkanDriver* vk, m_has_mipmaps = false; m_locked_data = NULL; m_size = m_orig_size = m_max_size = size; - m_texture_size = m_size.Width * m_size.Height * 4; m_internal_format = VK_FORMAT_R8G8B8A8_UNORM; if (!createImage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | diff --git a/lib/graphics_engine/src/ge_vulkan_fbo_texture.hpp b/lib/graphics_engine/src/ge_vulkan_fbo_texture.hpp index 7f038c8bd..ffc7fe9f8 100644 --- a/lib/graphics_engine/src/ge_vulkan_fbo_texture.hpp +++ b/lib/graphics_engine/src/ge_vulkan_fbo_texture.hpp @@ -39,8 +39,6 @@ public: virtual u64 getTextureHandler() const { return (u64)(m_image_view.get()->load()); } // ------------------------------------------------------------------------ - virtual unsigned int getTextureSize() const { return m_texture_size; } - // ------------------------------------------------------------------------ virtual void reload() {} // ------------------------------------------------------------------------ virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, diff --git a/lib/graphics_engine/src/ge_vulkan_texture.cpp b/lib/graphics_engine/src/ge_vulkan_texture.cpp index 92a696355..24a20505e 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.cpp @@ -29,7 +29,7 @@ GEVulkanTexture::GEVulkanTexture(const std::string& path, m_locked_data(NULL), m_vulkan_device(getVKDriver()->getDevice()), m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), - m_texture_size(0), m_layer_count(1), + m_vma_info(), m_layer_count(1), m_image_view_type(VK_IMAGE_VIEW_TYPE_2D), m_disable_reload(false), m_has_mipmaps(true), m_ondemand_load(false), m_ondemand_loading(false), @@ -78,7 +78,7 @@ GEVulkanTexture::GEVulkanTexture(video::IImage* img, const std::string& name) m_locked_data(NULL), m_vulkan_device(getVKDriver()->getDevice()), m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), - m_texture_size(0), m_layer_count(1), + m_vma_info(), m_layer_count(1), m_image_view_type(VK_IMAGE_VIEW_TYPE_2D), m_disable_reload(true), m_has_mipmaps(true), m_ondemand_load(false), m_ondemand_loading(false), @@ -106,7 +106,7 @@ GEVulkanTexture::GEVulkanTexture(const std::string& name, unsigned int size, : video::ITexture(name.c_str()), m_image_mani(nullptr), m_locked_data(NULL), m_vulkan_device(getVKDriver()->getDevice()), m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), - m_texture_size(0), m_layer_count(1), + m_vma_info(), m_layer_count(1), m_image_view_type(VK_IMAGE_VIEW_TYPE_2D), m_disable_reload(true), m_has_mipmaps(true), m_ondemand_load(false), m_ondemand_loading(false), m_internal_format(single_channel ? @@ -286,10 +286,11 @@ bool GEVulkanTexture::createImage(VkImageUsageFlags usage) m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; + m_vma_info = {}; VmaAllocationCreateInfo alloc_info = {}; alloc_info.usage = VMA_MEMORY_USAGE_AUTO; VkResult result = vmaCreateImage(m_vk->getVmaAllocator(), &image_info, - &alloc_info, &m_image, &m_vma_allocation, NULL); + &alloc_info, &m_image, &m_vma_allocation, &m_vma_info); if (result != VK_SUCCESS) return false; @@ -467,6 +468,7 @@ void GEVulkanTexture::clearVulkanData() vmaDestroyImage(m_vk->getVmaAllocator(), m_image, m_vma_allocation); m_image = VK_NULL_HANDLE; m_vma_allocation = VK_NULL_HANDLE; + m_vma_info = {}; } } // clearVulkanData @@ -527,7 +529,6 @@ void GEVulkanTexture::upload(uint8_t* data, bool generate_hq_mipmap) } if (!createImageView(VK_IMAGE_ASPECT_COLOR_BIT)) return; - m_texture_size = m_size.Width * m_size.Height * (isSingleChannel() ? 1 : 4); } // upload // ---------------------------------------------------------------------------- diff --git a/lib/graphics_engine/src/ge_vulkan_texture.hpp b/lib/graphics_engine/src/ge_vulkan_texture.hpp index 8a86fc75d..d0a94f674 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.hpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.hpp @@ -35,6 +35,8 @@ protected: VmaAllocation m_vma_allocation; + VmaAllocationInfo m_vma_info; + std::shared_ptr > m_image_view; std::shared_ptr > m_placeholder_view; @@ -43,8 +45,6 @@ protected: VkImageViewType m_image_view_type; - unsigned int m_texture_size; - const bool m_disable_reload; bool m_has_mipmaps; @@ -55,7 +55,7 @@ protected: GESpinLock m_size_lock; - GESpinLock m_image_view_lock; + mutable GESpinLock m_image_view_lock; GESpinLock m_thread_loading_lock; @@ -104,7 +104,7 @@ protected: // ------------------------------------------------------------------------ std::shared_ptr > getImageViewLive() const; // ------------------------------------------------------------------------ - bool waitImageView() + bool waitImageView() const { if (!m_ondemand_load) { @@ -120,7 +120,7 @@ protected: return true; } // ------------------------------------------------------------------------ - GEVulkanTexture() : video::ITexture(""), m_layer_count(1), + GEVulkanTexture() : video::ITexture(""), m_vma_info(), m_layer_count(1), m_image_view_type(VK_IMAGE_VIEW_TYPE_2D), m_disable_reload(true), m_ondemand_load(false), m_ondemand_loading(false) {} @@ -197,12 +197,8 @@ public: // ------------------------------------------------------------------------ virtual unsigned int getTextureSize() const { - if (!m_ondemand_load) - { - m_image_view_lock.lock(); - m_image_view_lock.unlock(); - } - return m_texture_size; + waitImageView(); + return (unsigned int)m_vma_info.size; } // ------------------------------------------------------------------------ virtual void reload();