Implement GEVulkanTexture::getTextureSize correctly

This commit is contained in:
Benau 2022-08-31 13:09:41 +08:00
parent 3db036d67f
commit 089dd025f1
8 changed files with 13 additions and 25 deletions

View File

@ -45,7 +45,6 @@ GEVulkanArrayTexture::GEVulkanArrayTexture(const std::vector<io::path>& list,
m_max_size = m_vk->getDriverAttributes() m_max_size = m_vk->getDriverAttributes()
.getAttributeAsDimension2d("MAX_TEXTURE_SIZE"); .getAttributeAsDimension2d("MAX_TEXTURE_SIZE");
m_internal_format = VK_FORMAT_R8G8B8A8_UNORM; m_internal_format = VK_FORMAT_R8G8B8A8_UNORM;
m_texture_size = 0;
m_size_lock.lock(); m_size_lock.lock();
m_image_view_lock.lock(); m_image_view_lock.lock();

View File

@ -44,8 +44,6 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void regenerateMipMapLevels(void* mipmap_data = NULL) {} virtual void regenerateMipMapLevels(void* mipmap_data = NULL) {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual unsigned int getTextureSize() const { return m_texture_size; }
// ------------------------------------------------------------------------
virtual void reload() {} virtual void reload() {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,

View File

@ -16,7 +16,6 @@ GEVulkanDepthTexture::GEVulkanDepthTexture(GEVulkanDriver* vk,
m_has_mipmaps = false; m_has_mipmaps = false;
m_locked_data = NULL; m_locked_data = NULL;
m_size = m_orig_size = m_max_size = size; m_size = m_orig_size = m_max_size = size;
m_texture_size = m_size.Width * m_size.Height * 4;
std::vector<VkFormat> preferred = std::vector<VkFormat> preferred =
{ {

View File

@ -41,8 +41,6 @@ public:
virtual u64 getTextureHandler() const virtual u64 getTextureHandler() const
{ return (u64)(m_image_view.get()->load()); } { return (u64)(m_image_view.get()->load()); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual unsigned int getTextureSize() const { return m_texture_size; }
// ------------------------------------------------------------------------
virtual void reload() {} virtual void reload() {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,

View File

@ -21,7 +21,6 @@ GEVulkanFBOTexture::GEVulkanFBOTexture(GEVulkanDriver* vk,
m_has_mipmaps = false; m_has_mipmaps = false;
m_locked_data = NULL; m_locked_data = NULL;
m_size = m_orig_size = m_max_size = size; 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; m_internal_format = VK_FORMAT_R8G8B8A8_UNORM;
if (!createImage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | if (!createImage(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |

View File

@ -39,8 +39,6 @@ public:
virtual u64 getTextureHandler() const virtual u64 getTextureHandler() const
{ return (u64)(m_image_view.get()->load()); } { return (u64)(m_image_view.get()->load()); }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual unsigned int getTextureSize() const { return m_texture_size; }
// ------------------------------------------------------------------------
virtual void reload() {} virtual void reload() {}
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format, virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,

View File

@ -29,7 +29,7 @@ GEVulkanTexture::GEVulkanTexture(const std::string& path,
m_locked_data(NULL), m_locked_data(NULL),
m_vulkan_device(getVKDriver()->getDevice()), m_vulkan_device(getVKDriver()->getDevice()),
m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), 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_image_view_type(VK_IMAGE_VIEW_TYPE_2D),
m_disable_reload(false), m_has_mipmaps(true), m_disable_reload(false), m_has_mipmaps(true),
m_ondemand_load(false), m_ondemand_loading(false), 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_locked_data(NULL),
m_vulkan_device(getVKDriver()->getDevice()), m_vulkan_device(getVKDriver()->getDevice()),
m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), 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_image_view_type(VK_IMAGE_VIEW_TYPE_2D),
m_disable_reload(true), m_has_mipmaps(true), m_disable_reload(true), m_has_mipmaps(true),
m_ondemand_load(false), m_ondemand_loading(false), 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), : video::ITexture(name.c_str()), m_image_mani(nullptr),
m_locked_data(NULL), m_vulkan_device(getVKDriver()->getDevice()), m_locked_data(NULL), m_vulkan_device(getVKDriver()->getDevice()),
m_image(VK_NULL_HANDLE), m_vma_allocation(VK_NULL_HANDLE), 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_image_view_type(VK_IMAGE_VIEW_TYPE_2D), m_disable_reload(true),
m_has_mipmaps(true), m_ondemand_load(false), m_has_mipmaps(true), m_ondemand_load(false),
m_ondemand_loading(false), m_internal_format(single_channel ? 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) m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT; image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
m_vma_info = {};
VmaAllocationCreateInfo alloc_info = {}; VmaAllocationCreateInfo alloc_info = {};
alloc_info.usage = VMA_MEMORY_USAGE_AUTO; alloc_info.usage = VMA_MEMORY_USAGE_AUTO;
VkResult result = vmaCreateImage(m_vk->getVmaAllocator(), &image_info, 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) if (result != VK_SUCCESS)
return false; return false;
@ -467,6 +468,7 @@ void GEVulkanTexture::clearVulkanData()
vmaDestroyImage(m_vk->getVmaAllocator(), m_image, m_vma_allocation); vmaDestroyImage(m_vk->getVmaAllocator(), m_image, m_vma_allocation);
m_image = VK_NULL_HANDLE; m_image = VK_NULL_HANDLE;
m_vma_allocation = VK_NULL_HANDLE; m_vma_allocation = VK_NULL_HANDLE;
m_vma_info = {};
} }
} // clearVulkanData } // clearVulkanData
@ -527,7 +529,6 @@ void GEVulkanTexture::upload(uint8_t* data, bool generate_hq_mipmap)
} }
if (!createImageView(VK_IMAGE_ASPECT_COLOR_BIT)) if (!createImageView(VK_IMAGE_ASPECT_COLOR_BIT))
return; return;
m_texture_size = m_size.Width * m_size.Height * (isSingleChannel() ? 1 : 4);
} // upload } // upload
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -35,6 +35,8 @@ protected:
VmaAllocation m_vma_allocation; VmaAllocation m_vma_allocation;
VmaAllocationInfo m_vma_info;
std::shared_ptr<std::atomic<VkImageView> > m_image_view; std::shared_ptr<std::atomic<VkImageView> > m_image_view;
std::shared_ptr<std::atomic<VkImageView> > m_placeholder_view; std::shared_ptr<std::atomic<VkImageView> > m_placeholder_view;
@ -43,8 +45,6 @@ protected:
VkImageViewType m_image_view_type; VkImageViewType m_image_view_type;
unsigned int m_texture_size;
const bool m_disable_reload; const bool m_disable_reload;
bool m_has_mipmaps; bool m_has_mipmaps;
@ -55,7 +55,7 @@ protected:
GESpinLock m_size_lock; GESpinLock m_size_lock;
GESpinLock m_image_view_lock; mutable GESpinLock m_image_view_lock;
GESpinLock m_thread_loading_lock; GESpinLock m_thread_loading_lock;
@ -104,7 +104,7 @@ protected:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
std::shared_ptr<std::atomic<VkImageView> > getImageViewLive() const; std::shared_ptr<std::atomic<VkImageView> > getImageViewLive() const;
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
bool waitImageView() bool waitImageView() const
{ {
if (!m_ondemand_load) if (!m_ondemand_load)
{ {
@ -120,7 +120,7 @@ protected:
return true; 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_image_view_type(VK_IMAGE_VIEW_TYPE_2D),
m_disable_reload(true), m_ondemand_load(false), m_disable_reload(true), m_ondemand_load(false),
m_ondemand_loading(false) {} m_ondemand_loading(false) {}
@ -197,12 +197,8 @@ public:
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual unsigned int getTextureSize() const virtual unsigned int getTextureSize() const
{ {
if (!m_ondemand_load) waitImageView();
{ return (unsigned int)m_vma_info.size;
m_image_view_lock.lock();
m_image_view_lock.unlock();
}
return m_texture_size;
} }
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
virtual void reload(); virtual void reload();