summaryrefslogtreecommitdiffstats
path: root/AssetLoader/interface
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-12-05 17:19:28 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-12-05 17:19:28 +0000
commite3bad5a7fcedc170a10aed3ee644310ec8c982fe (patch)
tree1ebedbfb4a1a415bc9615ded4f46fa1e8e694fc6 /AssetLoader/interface
parentGLTF Loader: fixed names of Material::ALPHA_MODE enum members (diff)
downloadDiligentTools-e3bad5a7fcedc170a10aed3ee644310ec8c982fe.tar.gz
DiligentTools-e3bad5a7fcedc170a10aed3ee644310ec8c982fe.zip
GLTF Resource manager: implemented texture array resizing
Diffstat (limited to 'AssetLoader/interface')
-rw-r--r--AssetLoader/interface/GLTFLoader.hpp12
-rw-r--r--AssetLoader/interface/GLTFResourceManager.hpp96
2 files changed, 91 insertions, 17 deletions
diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/interface/GLTFLoader.hpp
index ddf5625..68747c5 100644
--- a/AssetLoader/interface/GLTFLoader.hpp
+++ b/AssetLoader/interface/GLTFLoader.hpp
@@ -61,6 +61,12 @@ struct GLTFCacheInfo
Uint8 IndexBufferIdx = 0;
Uint8 VertexBuffer0Idx = 0;
Uint8 VertexBuffer1Idx = 0;
+
+ TEXTURE_FORMAT BaseColorFormat = TEX_FORMAT_RGBA8_UNORM;
+ TEXTURE_FORMAT PhysicalDescFormat = TEX_FORMAT_RGBA8_UNORM;
+ TEXTURE_FORMAT NormalFormat = TEX_FORMAT_RGBA8_UNORM;
+ TEXTURE_FORMAT OcclusionFormat = TEX_FORMAT_RGBA8_UNORM;
+ TEXTURE_FORMAT EmissiveFormat = TEX_FORMAT_RGBA8_UNORM;
};
struct Material
@@ -388,6 +394,11 @@ struct Model
return Textures[Index].UVScaleBias;
}
+ float GetSlice(Uint32 Index)
+ {
+ return Textures[Index].Slice;
+ }
+
private:
void LoadFromFile(IRenderDevice* pDevice,
IDeviceContext* pContext,
@@ -433,6 +444,7 @@ private:
{
RefCntAutoPtr<ITexture> pTexture;
float4 UVScaleBias{1, 1, 0, 0};
+ float Slice = 0;
RefCntAutoPtr<GLTFResourceManager::TextureAllocation> pCacheAllocation;
diff --git a/AssetLoader/interface/GLTFResourceManager.hpp b/AssetLoader/interface/GLTFResourceManager.hpp
index e0b007d..a6c2a82 100644
--- a/AssetLoader/interface/GLTFResourceManager.hpp
+++ b/AssetLoader/interface/GLTFResourceManager.hpp
@@ -30,6 +30,7 @@
#include <mutex>
#include <vector>
#include <unordered_map>
+#include <atomic>
#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/RenderDevice.h"
#include "../../../DiligentCore/Graphics/GraphicsEngine/interface/DeviceContext.h"
@@ -97,6 +98,7 @@ public:
TextureCache& ParentCache,
Uint32 Width,
Uint32 Height,
+ Uint32 Slice,
DynamicAtlasManager::Region&& Region) :
// clang-format off
ObjectBase<IObject>{pRefCounters},
@@ -104,6 +106,7 @@ public:
m_ParentCache {ParentCache},
m_Width {Width},
m_Height {Height},
+ m_Slice {Slice},
m_Region {std::move(Region)}
// clang-format on
{
@@ -112,7 +115,7 @@ public:
~TextureAllocation()
{
- m_ParentCache.FreeAllocation(std::move(m_Region));
+ m_ParentCache.FreeAllocation(m_Slice, std::move(m_Region));
}
ITexture* GetTexture(IRenderDevice* pDevice, IDeviceContext* pContext) const
@@ -132,19 +135,24 @@ public:
Uint32 GetWidth() const { return m_Width; }
Uint32 GetHeight() const { return m_Height; }
+ Uint32 GetSlice() const { return m_Slice; }
private:
RefCntAutoPtr<GLTFResourceManager> m_pResMgr;
TextureCache& m_ParentCache;
const Uint32 m_Width;
const Uint32 m_Height;
+ const Uint32 m_Slice;
DynamicAtlasManager::Region m_Region;
};
struct TextureCacheAttribs
{
TextureDesc Desc;
- Uint32 Granularity = 128;
+
+ Uint32 Granularity = 128;
+ Uint32 ExtraSliceCount = 2;
+ Uint32 MaxSlices = 2048;
};
struct CreateInfo
{
@@ -153,6 +161,10 @@ public:
const TextureCacheAttribs* Textures = nullptr; // [NumTextures]
Uint32 NumTextures = 0;
+
+ TextureDesc DefaultTexDesc;
+
+ Uint32 DefaultExtraSliceCount = 1;
};
static RefCntAutoPtr<GLTFResourceManager> Create(IRenderDevice* pDevice,
@@ -163,10 +175,32 @@ public:
return m_Buffers[BufferIndex].Allocate(Size, Alignment);
}
- RefCntAutoPtr<TextureAllocation> AllocateTextureSpace(Uint32 TextureIndex, Uint32 Width, Uint32 Height, const char* CacheId = nullptr);
+ RefCntAutoPtr<TextureAllocation> AllocateTextureSpace(TEXTURE_FORMAT Fmt, Uint32 Width, Uint32 Height, const char* CacheId = nullptr);
RefCntAutoPtr<TextureAllocation> FindAllocation(const char* CacheId);
+ Uint32 GetResourceVersion() const
+ {
+ return m_ResourceVersion.load();
+ }
+
+ IBuffer* GetBuffer(Uint32 Index, IRenderDevice* pDevice, IDeviceContext* pContext)
+ {
+ return m_Buffers[Index].GetBuffer(pDevice, pContext);
+ }
+ ITexture* GetTexture(TEXTURE_FORMAT Fmt, IRenderDevice* pDevice, IDeviceContext* pContext)
+ {
+ decltype(m_Textures)::iterator cache_it; // NB: can't initialize it without locking the mutex
+ {
+ std::lock_guard<std::mutex> Lock{m_TexturesMtx};
+ cache_it = m_Textures.find(Fmt);
+ if (cache_it == m_Textures.end())
+ return nullptr;
+ }
+
+ return cache_it->second.GetTexture(pDevice, pContext);
+ }
+
private:
template <typename AllocatorType, typename ObjectType>
friend class MakeNewRCObj;
@@ -227,44 +261,72 @@ private:
TextureCache(TextureCache&& Cache) noexcept :
// clang-format off
- m_Owner {Cache.m_Owner},
- m_TexDesc {m_TexDesc},
- m_TexName {std::move(m_TexName)},
- m_Granularity{Cache.m_Granularity},
- m_Mgr {std::move(Cache.m_Mgr)},
- m_pTexture {std::move(Cache.m_pTexture)}
+ m_Owner {Cache.m_Owner},
+ m_Attribs {Cache.m_Attribs},
+ m_TexName {std::move(m_TexName)},
+ m_Slices {std::move(Cache.m_Slices)},
+ m_pTexture{std::move(Cache.m_pTexture)}
// clang-format on
{
- m_TexDesc.Name = m_TexName.c_str();
+ m_Attribs.Desc.Name = m_TexName.c_str();
}
ITexture* GetTexture(IRenderDevice* pDevice, IDeviceContext* pContext);
const TextureDesc& GetTexDesc() const
{
- return m_TexDesc;
+ return m_Attribs.Desc;
}
RefCntAutoPtr<TextureAllocation> Allocate(Uint32 Width, Uint32 Height);
- void FreeAllocation(DynamicAtlasManager::Region&& Allocation);
+ void FreeAllocation(Uint32 Slice, DynamicAtlasManager::Region&& Allocation);
private:
GLTFResourceManager& m_Owner;
- TextureDesc m_TexDesc;
+ TextureCacheAttribs m_Attribs;
+
std::string m_TexName;
- const Uint32 m_Granularity;
+ struct SliceManager
+ {
+ SliceManager(Uint32 Width, Uint32 Height) :
+ Mgr{Width, Height}
+ {}
+
+ DynamicAtlasManager::Region Allocate(Uint32 Width, Uint32 Height)
+ {
+ std::lock_guard<std::mutex> Lock{Mtx};
+ return Mgr.Allocate(Width, Height);
+ }
+ void Free(DynamicAtlasManager::Region&& Region)
+ {
+ std::lock_guard<std::mutex> Lock{Mtx};
+ Mgr.Free(std::move(Region));
+ }
+
+ private:
+ std::mutex Mtx;
+ DynamicAtlasManager Mgr;
+ };
+ std::mutex m_SlicesMtx;
+ std::vector<std::unique_ptr<SliceManager>> m_Slices;
- std::mutex m_Mtx;
- DynamicAtlasManager m_Mgr;
RefCntAutoPtr<ITexture> m_pTexture;
};
- std::vector<TextureCache> m_Textures;
+
+ TextureDesc m_DefaultTexDesc;
+ const Uint32 m_DefaultExtraSliceCount;
+
+
+ std::mutex m_TexturesMtx;
+ std::unordered_map<TEXTURE_FORMAT, TextureCache> m_Textures;
std::mutex m_AllocationsMtx;
std::unordered_map<std::string, RefCntWeakPtr<TextureAllocation>> m_Allocations;
+
+ std::atomic_uint32_t m_ResourceVersion = {};
};
} // namespace Diligent