Add srgb image view for vulkan engine
This commit is contained in:
parent
7817e14a5a
commit
6f789164ff
@ -13,6 +13,7 @@ namespace irr
|
||||
#include <atomic>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace GE
|
||||
@ -82,7 +83,8 @@ public:
|
||||
clear();
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
int getTextureID(const irr::video::ITexture** list);
|
||||
int getTextureID(const irr::video::ITexture** list,
|
||||
const std::string& shader = std::string());
|
||||
// ------------------------------------------------------------------------
|
||||
void setSamplerUse(GEVulkanSampler sampler)
|
||||
{
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,
|
||||
u32 w, u32 h, u32 x, u32 y) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView() const
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView(
|
||||
bool srgb = false) const
|
||||
{ return m_image_view; }
|
||||
}; // GEVulkanDepthTexture
|
||||
|
||||
|
@ -413,7 +413,8 @@ start:
|
||||
const irr::video::SMaterial& m = node->getMaterial(0);
|
||||
TexturesList textures = getTexturesList(m);
|
||||
const irr::video::ITexture** list = &textures[0];
|
||||
int material_id = m_texture_descriptor->getTextureID(list);
|
||||
int material_id = m_texture_descriptor->getTextureID(list,
|
||||
getShader(m));
|
||||
ObjectData* data = (ObjectData*)mapped_addr;
|
||||
data->init(node, material_id, -1, 0);
|
||||
m_materials[q.first] = material_id;
|
||||
@ -442,9 +443,11 @@ start:
|
||||
std::unordered_map<uint32_t, uint32_t> offset_map;
|
||||
for (auto& p : visible_nodes)
|
||||
{
|
||||
TexturesList textures = getTexturesList(p.first->getMaterial());
|
||||
const irr::video::SMaterial& m = p.first->getMaterial();
|
||||
TexturesList textures = getTexturesList(m);
|
||||
const irr::video::ITexture** list = &textures[0];
|
||||
int material_id = m_texture_descriptor->getTextureID(list);
|
||||
int material_id = m_texture_descriptor->getTextureID(list,
|
||||
getShader(m));
|
||||
m_materials[p.first] = material_id;
|
||||
|
||||
const bool skinning = p.first->hasSkinning();
|
||||
@ -513,7 +516,8 @@ start:
|
||||
const irr::video::SMaterial& m = node->getMaterial(0);
|
||||
TexturesList textures = getTexturesList(m);
|
||||
const irr::video::ITexture** list = &textures[0];
|
||||
material_id = m_texture_descriptor->getTextureID(list);
|
||||
material_id = m_texture_descriptor->getTextureID(list,
|
||||
getShader(m));
|
||||
}
|
||||
if (r.second == BILLBOARD_NODE)
|
||||
{
|
||||
@ -769,6 +773,12 @@ std::string GEVulkanDrawCall::getShader(irr::scene::ISceneNode* node,
|
||||
int material_id)
|
||||
{
|
||||
irr::video::SMaterial& m = node->getMaterial(material_id);
|
||||
return getShader(m);
|
||||
} // getShader
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
std::string GEVulkanDrawCall::getShader(const irr::video::SMaterial& m)
|
||||
{
|
||||
std::string shader;
|
||||
switch (m.MaterialType)
|
||||
{
|
||||
|
@ -168,6 +168,8 @@ private:
|
||||
// ------------------------------------------------------------------------
|
||||
void createVulkanData();
|
||||
// ------------------------------------------------------------------------
|
||||
std::string getShader(const irr::video::SMaterial& m);
|
||||
// ------------------------------------------------------------------------
|
||||
std::string getShader(irr::scene::ISceneNode* node, int material_id);
|
||||
// ------------------------------------------------------------------------
|
||||
void bindPipeline(VkCommandBuffer cmd, const std::string& name) const
|
||||
|
@ -44,7 +44,8 @@ public:
|
||||
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,
|
||||
u32 w, u32 h, u32 x, u32 y) {}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView() const
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView(
|
||||
bool srgb = false) const
|
||||
{ return m_image_view; }
|
||||
// ------------------------------------------------------------------------
|
||||
void createRTT();
|
||||
|
@ -291,6 +291,8 @@ bool GEVulkanTexture::createImage(VkImageUsageFlags usage)
|
||||
if (m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE ||
|
||||
m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
|
||||
image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
||||
if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM)
|
||||
image_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
|
||||
|
||||
m_vma_info = {};
|
||||
VmaAllocationCreateInfo alloc_info = {};
|
||||
@ -447,6 +449,18 @@ bool GEVulkanTexture::createImageView(VkImageAspectFlags aspect_flags)
|
||||
{
|
||||
image_view.get()->store(view_ptr);
|
||||
m_image_view = image_view;
|
||||
if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM)
|
||||
{
|
||||
image_view = std::make_shared<std::atomic<VkImageView> >();
|
||||
view_info.format = VK_FORMAT_R8G8B8A8_SRGB;
|
||||
view_ptr = VK_NULL_HANDLE;
|
||||
if (vkCreateImageView(m_vulkan_device, &view_info,
|
||||
NULL, &view_ptr) == VK_SUCCESS)
|
||||
{
|
||||
image_view.get()->store(view_ptr);
|
||||
m_image_view_srgb = image_view;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_placeholder_view)
|
||||
m_placeholder_view.get()->store(VK_NULL_HANDLE);
|
||||
@ -468,6 +482,13 @@ void GEVulkanTexture::clearVulkanData()
|
||||
vkDestroyImageView(m_vulkan_device, m_image_view.get()->load(), NULL);
|
||||
m_image_view.get()->store(VK_NULL_HANDLE);
|
||||
m_image_view.reset();
|
||||
if (m_image_view_srgb)
|
||||
{
|
||||
vkDestroyImageView(m_vulkan_device,
|
||||
m_image_view_srgb.get()->load(), NULL);
|
||||
m_image_view_srgb.get()->store(VK_NULL_HANDLE);
|
||||
m_image_view_srgb.reset();
|
||||
}
|
||||
}
|
||||
if (m_image != VK_NULL_HANDLE)
|
||||
{
|
||||
@ -872,13 +893,19 @@ void GEVulkanTexture::setPlaceHolderView()
|
||||
} // setPlaceHolderView
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
std::shared_ptr<std::atomic<VkImageView> > GEVulkanTexture::getImageViewLive() const
|
||||
std::shared_ptr<std::atomic<VkImageView> > GEVulkanTexture::getImageViewLive(
|
||||
bool srgb) const
|
||||
{
|
||||
assert(m_ondemand_load && m_placeholder_view);
|
||||
if (m_ondemand_loading.load() == false)
|
||||
{
|
||||
if (m_image_view)
|
||||
return m_image_view;
|
||||
{
|
||||
if (srgb && m_image_view_srgb)
|
||||
return m_image_view_srgb;
|
||||
else
|
||||
return m_image_view;
|
||||
}
|
||||
else
|
||||
{
|
||||
GEVulkanTexture* tex = const_cast<GEVulkanTexture*>(this);
|
||||
|
@ -39,6 +39,8 @@ protected:
|
||||
|
||||
std::shared_ptr<std::atomic<VkImageView> > m_image_view;
|
||||
|
||||
std::shared_ptr<std::atomic<VkImageView> > m_image_view_srgb;
|
||||
|
||||
std::shared_ptr<std::atomic<VkImageView> > m_placeholder_view;
|
||||
|
||||
unsigned m_layer_count;
|
||||
@ -102,7 +104,8 @@ protected:
|
||||
// ------------------------------------------------------------------------
|
||||
void setPlaceHolderView();
|
||||
// ------------------------------------------------------------------------
|
||||
std::shared_ptr<std::atomic<VkImageView> > getImageViewLive() const;
|
||||
std::shared_ptr<std::atomic<VkImageView> > getImageViewLive(
|
||||
bool srgb = false) const;
|
||||
// ------------------------------------------------------------------------
|
||||
bool waitImageView() const
|
||||
{
|
||||
@ -206,16 +209,20 @@ public:
|
||||
virtual void updateTexture(void* data, irr::video::ECOLOR_FORMAT format,
|
||||
u32 w, u32 h, u32 x, u32 y);
|
||||
// ------------------------------------------------------------------------
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView() const
|
||||
virtual std::shared_ptr<std::atomic<VkImageView> > getImageView(
|
||||
bool srgb = false) const
|
||||
{
|
||||
if (!m_ondemand_load)
|
||||
{
|
||||
m_image_view_lock.lock();
|
||||
m_image_view_lock.unlock();
|
||||
return m_image_view;
|
||||
if (srgb && m_image_view_srgb)
|
||||
return m_image_view_srgb;
|
||||
else
|
||||
return m_image_view;
|
||||
}
|
||||
else
|
||||
return getImageViewLive();
|
||||
return getImageViewLive(srgb);
|
||||
}
|
||||
// ------------------------------------------------------------------------
|
||||
virtual bool useOnDemandLoad() const { return m_ondemand_load; }
|
||||
|
@ -190,7 +190,8 @@ void GEVulkanTextureDescriptor::updateDescriptor()
|
||||
} // updateDescriptor
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int GEVulkanTextureDescriptor::getTextureID(const irr::video::ITexture** list)
|
||||
int GEVulkanTextureDescriptor::getTextureID(const irr::video::ITexture** list,
|
||||
const std::string& shader)
|
||||
{
|
||||
TextureList key =
|
||||
{{
|
||||
@ -205,10 +206,12 @@ int GEVulkanTextureDescriptor::getTextureID(const irr::video::ITexture** list)
|
||||
}};
|
||||
for (unsigned i = 0; i < m_max_layer; i++)
|
||||
{
|
||||
// Assume 0, 1 layer is srgb for pbr enabled currently
|
||||
if (list[i])
|
||||
{
|
||||
key[i] = static_cast<const GEVulkanTexture*>(
|
||||
list[i])->getImageView();
|
||||
list[i])->getImageView(getGEConfig()->m_pbr &&
|
||||
!shader.empty() && i <= 1 ? true : false);
|
||||
}
|
||||
}
|
||||
auto it = m_texture_list.find(key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user