From d7bc037c0164de1431e24bc470f45e0242dce1a0 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 14 Oct 2024 17:46:55 -0700 Subject: [PATCH] DynamicTextureAtlas: added growth factor parameter --- Graphics/GraphicsTools/interface/DynamicTextureAtlas.h | 9 ++++++--- Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Graphics/GraphicsTools/interface/DynamicTextureAtlas.h b/Graphics/GraphicsTools/interface/DynamicTextureAtlas.h index f1e805c16..7b88b0ee3 100644 --- a/Graphics/GraphicsTools/interface/DynamicTextureAtlas.h +++ b/Graphics/GraphicsTools/interface/DynamicTextureAtlas.h @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -224,10 +224,13 @@ struct DynamicTextureAtlasCreateInfo /// The number of extra slices. /// When non-zero, the array will be expanded by the specified number of slices every time - /// there is insufficient space. If zero, the array size will be doubled when - /// more space is needed. + /// there is insufficient space. If zero, the array size will be expanded by the growth factor. Uint32 ExtraSliceCount = 0; + /// Growth factor. + + /// If ExtraSliceCount is zero, defines the factor by which the array size will be expanded. + float GrowthFactor = 2.0f; /// Maximum number of slices in texture array. Uint32 MaxSliceCount = 2048; diff --git a/Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp b/Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp index 075e776da..313e5fbeb 100644 --- a/Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp +++ b/Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2019-2023 Diligent Graphics LLC + * Copyright 2019-2024 Diligent Graphics LLC * Copyright 2015-2019 Egor Yusov * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -384,6 +384,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase // clang-format off m_MinAlignment {CreateInfo.MinAlignment}, m_ExtraSliceCount {CreateInfo.ExtraSliceCount}, + m_GrowthFactor {clamp(CreateInfo.GrowthFactor, 1.f, 2.f)}, m_MaxSliceCount {CreateInfo.Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY ? std::min(CreateInfo.MaxSliceCount, Uint32{2048}) : 1}, m_Silent {CreateInfo.Silent}, m_SuballocationsAllocator @@ -688,7 +689,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase { const auto ExtraSliceCount = m_ExtraSliceCount != 0 ? m_ExtraSliceCount : - std::max(m_TexArraySize.load(), 1u); + std::max(static_cast(static_cast(m_TexArraySize.load()) * m_GrowthFactor), 1u); m_TexArraySize.store(std::min(m_TexArraySize + ExtraSliceCount, m_MaxSliceCount)); } @@ -721,6 +722,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase const Uint32 m_MinAlignment; const Uint32 m_ExtraSliceCount; + const float m_GrowthFactor; const Uint32 m_MaxSliceCount; const bool m_Silent;