diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-12-01 04:36:47 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-12-01 04:36:47 +0000 |
| commit | 2e37306dce0f0c151ba9401d6a5d5e80c36e28cc (patch) | |
| tree | 5b8ca89010fe3a638ebbfebfef9a3953b194d9f5 /AssetLoader/interface | |
| parent | GLTF Loader: updated GPU resource initialization (diff) | |
| download | DiligentTools-2e37306dce0f0c151ba9401d6a5d5e80c36e28cc.tar.gz DiligentTools-2e37306dce0f0c151ba9401d6a5d5e80c36e28cc.zip | |
GLTF Loader: implemented buffer suballocation in cache
Diffstat (limited to 'AssetLoader/interface')
| -rw-r--r-- | AssetLoader/interface/GLTFLoader.hpp | 83 | ||||
| -rw-r--r-- | AssetLoader/interface/GLTFResourceManager.hpp | 13 |
2 files changed, 69 insertions, 27 deletions
diff --git a/AssetLoader/interface/GLTFLoader.hpp b/AssetLoader/interface/GLTFLoader.hpp index a0c887f..8effc2b 100644 --- a/AssetLoader/interface/GLTFLoader.hpp +++ b/AssetLoader/interface/GLTFLoader.hpp @@ -282,12 +282,15 @@ struct Model float4 weight0; }; - RefCntAutoPtr<IBuffer> pVertexBuffer[2]; - RefCntAutoPtr<IBuffer> pIndexBuffer; - Uint32 IndexCount = 0; + enum BUFFER_ID + { + BUFFER_ID_VERTEX0 = 0, + BUFFER_ID_VERTEX1, + BUFFER_ID_INDEX, + BUFFER_ID_NUM_BUFFERS + }; - GLTFResourceManager::BufferAllocation VBAllocations[2]; - GLTFResourceManager::BufferAllocation IBAllocation; + Uint32 IndexCount = 0; /// Transformation matrix that transforms unit cube [0,1]x[0,1]x[0,1] into /// axis-aligned bounding box in model space. @@ -298,22 +301,6 @@ struct Model std::vector<std::unique_ptr<Skin>> Skins; - struct TextureInfo - { - RefCntAutoPtr<ITexture> pTexture; - GLTFResourceManager::TextureAllocation CacheAllocation; - float4 UVScaleBias{1, 1, 0, 0}; - }; - std::vector<TextureInfo> Textures; - - struct ResourceInitData; - std::unique_ptr<ResourceInitData> InitData; - - ITexture* GetTexture(Uint32 Index) - { - return Textures[Index].pTexture; - } - std::vector<RefCntAutoPtr<ISampler>> TextureSamplers; std::vector<Material> Materials; std::vector<Animation> Animations; @@ -355,6 +342,41 @@ struct Model void PrepareGPUResources(IDeviceContext* pCtx); + IBuffer* GetBuffer(BUFFER_ID BuffId, Uint32& Offset) + { + VERIFY_EXPR(BuffId < BUFFER_ID_NUM_BUFFERS); + auto& Buff = Buffers[BuffId]; + if (Buff.pBuffer) + { + Offset = 0; + return Buff.pBuffer; + } + else if (CacheInfo.pResourceMgr != nullptr) + { + Offset = static_cast<Uint32>(Buff.CacheAllocation.Region.UnalignedOffset); + return CacheInfo.pResourceMgr->GetBuffer(Buff.CacheAllocation); + } + + Offset = 0; + return nullptr; + } + + ITexture* GetTexture(Uint32 Index) + { + auto& TexInfo = Textures[Index]; + if (TexInfo.pTexture) + return TexInfo.pTexture; + else if (CacheInfo.pResourceMgr) + return CacheInfo.pResourceMgr->GetTexture(TexInfo.CacheAllocation); + else + return nullptr; + } + + const float4& GetUVScaleBias(Uint32 Index) + { + return Textures[Index].UVScaleBias; + } + private: void LoadFromFile(IRenderDevice* pDevice, IDeviceContext* pContext, @@ -384,6 +406,25 @@ private: Node* NodeFromIndex(uint32_t index); GLTFCacheInfo CacheInfo; + + struct ResourceInitData; + std::unique_ptr<ResourceInitData> InitData; + + struct BufferInfo + { + RefCntAutoPtr<IBuffer> pBuffer; + + GLTFResourceManager::BufferAllocation CacheAllocation; + }; + std::array<BufferInfo, BUFFER_ID_NUM_BUFFERS> Buffers; + + struct TextureInfo + { + RefCntAutoPtr<ITexture> pTexture; + GLTFResourceManager::TextureAllocation CacheAllocation; + float4 UVScaleBias{1, 1, 0, 0}; + }; + std::vector<TextureInfo> Textures; }; } // namespace GLTF diff --git a/AssetLoader/interface/GLTFResourceManager.hpp b/AssetLoader/interface/GLTFResourceManager.hpp index 520a149..9a8fbbe 100644 --- a/AssetLoader/interface/GLTFResourceManager.hpp +++ b/AssetLoader/interface/GLTFResourceManager.hpp @@ -49,7 +49,8 @@ public: struct BufferAllocation { - Uint32 BufferIndex = 0; + Int32 BufferIndex = -1; + VariableSizeAllocationsManager::Allocation Region; bool IsValid() const @@ -59,7 +60,7 @@ public: }; struct TextureAllocation { - Uint32 TextureIndex = 0; + Int32 TextureIndex = -1; DynamicAtlasManager::Region Region; bool IsValid() const @@ -91,18 +92,18 @@ public: void FreeBufferSpace(BufferAllocation&& Allocation); - IBuffer* GetBuffer(Uint32 Idx) + IBuffer* GetBuffer(const BufferAllocation& Allocation) { - return m_Buffers[Idx].pBuffer; + return m_Buffers[Allocation.BufferIndex].pBuffer; } TextureAllocation AllocateTextureSpace(Uint32 TextureIndex, Uint32 Width, Uint32 Height); void FreeTextureSpace(TextureAllocation&& Allocation); - ITexture* GetTexture(Uint32 Idx) + ITexture* GetTexture(const TextureAllocation& Allocation) { - return m_Textures[Idx].pTexture; + return m_Textures[Allocation.TextureIndex].pTexture; } private: |
