Skip to content

Commit 9271be3

Browse files
authored
Merge branch 'master' into opengl-interop-purge-caches
2 parents 44ac131 + 55500db commit 9271be3

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

Common/interface/ObjectsRegistry.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@ class ObjectsRegistry
264264
}
265265
}
266266

267+
/// Removes all objects from the cache.
268+
void Clear()
269+
{
270+
std::lock_guard<std::mutex> Guard{m_CacheMtx};
271+
m_Cache.clear();
272+
m_NumRequestsSinceLastPurge.store(0);
273+
}
274+
267275
private:
268276
class ObjectWrapper
269277
{

Common/interface/ThreadPool.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ RefCntAutoPtr<IAsyncTask> EnqueueAsyncWork(IThreadPool* pThreadPool,
185185

186186
virtual void DILIGENT_CALL_TYPE Run(Uint32 ThreadId) override final
187187
{
188-
ASYNC_TASK_STATUS TaskStatus = m_Handler(ThreadId);
188+
ASYNC_TASK_STATUS TaskStatus = !m_bSafelyCancel.load() ?
189+
m_Handler(ThreadId) :
190+
ASYNC_TASK_STATUS_CANCELLED;
189191
SetStatus(TaskStatus);
190192
}
191193

Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,12 @@ inline Uint64 GetStagingTextureSubresourceOffset(const TextureDesc& TexDesc,
697697
return GetStagingTextureLocationOffset(TexDesc, ArraySlice, MipLevel, Alignment, 0, 0, 0);
698698
}
699699

700+
/// Returns the total memory size required to store the staging texture data.
701+
inline Uint64 GetStagingTextureDataSize(const TextureDesc& TexDesc,
702+
Uint32 Alignment = 4)
703+
{
704+
return GetStagingTextureSubresourceOffset(TexDesc, TexDesc.GetArraySize(), 0, Alignment);
705+
}
700706

701707
/// Information required to perform a copy operation between a buffer and a texture
702708
struct BufferToTextureCopyInfo

Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TextureBaseGL::TextureBaseGL(IReferenceCounters* pRefCounters,
7575
StagingBuffName += '\'';
7676
StagingBufferDesc.Name = StagingBuffName.c_str();
7777

78-
StagingBufferDesc.Size = GetStagingTextureSubresourceOffset(m_Desc, m_Desc.GetArraySize(), 0, PBOOffsetAlignment);
78+
StagingBufferDesc.Size = GetStagingTextureDataSize(m_Desc, PBOOffsetAlignment);
7979
StagingBufferDesc.Usage = USAGE_STAGING;
8080
StagingBufferDesc.CPUAccessFlags = TexDesc.CPUAccessFlags;
8181

Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -427,7 +427,7 @@ void TextureVkImpl::CreateStagingTexture(const TextureData* pInitData, const Tex
427427
VkStagingBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
428428
VkStagingBuffCI.pNext = nullptr;
429429
VkStagingBuffCI.flags = 0;
430-
VkStagingBuffCI.size = GetStagingTextureSubresourceOffset(m_Desc, m_Desc.GetArraySize(), 0, StagingBufferOffsetAlignment);
430+
VkStagingBuffCI.size = GetStagingTextureDataSize(m_Desc, StagingBufferOffsetAlignment);
431431

432432
// clang-format off
433433
DEV_CHECK_ERR((m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_READ ||

Graphics/GraphicsTools/interface/DynamicTextureAtlas.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -224,10 +224,15 @@ struct DynamicTextureAtlasCreateInfo
224224
/// The number of extra slices.
225225

226226
/// When non-zero, the array will be expanded by the specified number of slices every time
227-
/// there is insufficient space. If zero, the array size will be doubled when
228-
/// more space is needed.
227+
/// there is insufficient space. If zero, the array size will be expanded by the growth factor.
229228
Uint32 ExtraSliceCount = 0;
230229

230+
/// Growth factor.
231+
232+
/// If ExtraSliceCount is zero, defines the factor by which the array size will be expanded.
233+
/// The factor must be in the range (1, 2]. For example, if the factor is 2.0, the array size
234+
/// will be doubled every time there is insufficient space.
235+
float GrowthFactor = 2.0f;
231236

232237
/// Maximum number of slices in texture array.
233238
Uint32 MaxSliceCount = 2048;

Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 Diligent Graphics LLC
2+
* Copyright 2019-2024 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -384,6 +384,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
384384
// clang-format off
385385
m_MinAlignment {CreateInfo.MinAlignment},
386386
m_ExtraSliceCount {CreateInfo.ExtraSliceCount},
387+
m_ExtraSliceFactor{clamp(CreateInfo.GrowthFactor, 1.f, 2.f) - 1.f},
387388
m_MaxSliceCount {CreateInfo.Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY ? std::min(CreateInfo.MaxSliceCount, Uint32{2048}) : 1},
388389
m_Silent {CreateInfo.Silent},
389390
m_SuballocationsAllocator
@@ -688,7 +689,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
688689
{
689690
const auto ExtraSliceCount = m_ExtraSliceCount != 0 ?
690691
m_ExtraSliceCount :
691-
std::max(m_TexArraySize.load(), 1u);
692+
std::max(static_cast<Uint32>(static_cast<float>(m_TexArraySize.load()) * m_ExtraSliceFactor), 1u);
692693

693694
m_TexArraySize.store(std::min(m_TexArraySize + ExtraSliceCount, m_MaxSliceCount));
694695
}
@@ -721,6 +722,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
721722

722723
const Uint32 m_MinAlignment;
723724
const Uint32 m_ExtraSliceCount;
725+
const float m_ExtraSliceFactor;
724726
const Uint32 m_MaxSliceCount;
725727
const bool m_Silent;
726728

0 commit comments

Comments
 (0)