Skip to content

Commit

Permalink
Merge branch 'master' into opengl-interop-purge-caches
Browse files Browse the repository at this point in the history
  • Loading branch information
WangHoi authored Oct 15, 2024
2 parents 44ac131 + 55500db commit 9271be3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
8 changes: 8 additions & 0 deletions Common/interface/ObjectsRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ class ObjectsRegistry
}
}

/// Removes all objects from the cache.
void Clear()
{
std::lock_guard<std::mutex> Guard{m_CacheMtx};
m_Cache.clear();
m_NumRequestsSinceLastPurge.store(0);
}

private:
class ObjectWrapper
{
Expand Down
4 changes: 3 additions & 1 deletion Common/interface/ThreadPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ RefCntAutoPtr<IAsyncTask> EnqueueAsyncWork(IThreadPool* pThreadPool,

virtual void DILIGENT_CALL_TYPE Run(Uint32 ThreadId) override final
{
ASYNC_TASK_STATUS TaskStatus = m_Handler(ThreadId);
ASYNC_TASK_STATUS TaskStatus = !m_bSafelyCancel.load() ?
m_Handler(ThreadId) :
ASYNC_TASK_STATUS_CANCELLED;
SetStatus(TaskStatus);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,12 @@ inline Uint64 GetStagingTextureSubresourceOffset(const TextureDesc& TexDesc,
return GetStagingTextureLocationOffset(TexDesc, ArraySlice, MipLevel, Alignment, 0, 0, 0);
}

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

/// Information required to perform a copy operation between a buffer and a texture
struct BufferToTextureCopyInfo
Expand Down
2 changes: 1 addition & 1 deletion Graphics/GraphicsEngineOpenGL/src/TextureBaseGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TextureBaseGL::TextureBaseGL(IReferenceCounters* pRefCounters,
StagingBuffName += '\'';
StagingBufferDesc.Name = StagingBuffName.c_str();

StagingBufferDesc.Size = GetStagingTextureSubresourceOffset(m_Desc, m_Desc.GetArraySize(), 0, PBOOffsetAlignment);
StagingBufferDesc.Size = GetStagingTextureDataSize(m_Desc, PBOOffsetAlignment);
StagingBufferDesc.Usage = USAGE_STAGING;
StagingBufferDesc.CPUAccessFlags = TexDesc.CPUAccessFlags;

Expand Down
4 changes: 2 additions & 2 deletions Graphics/GraphicsEngineVulkan/src/TextureVkImpl.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -427,7 +427,7 @@ void TextureVkImpl::CreateStagingTexture(const TextureData* pInitData, const Tex
VkStagingBuffCI.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
VkStagingBuffCI.pNext = nullptr;
VkStagingBuffCI.flags = 0;
VkStagingBuffCI.size = GetStagingTextureSubresourceOffset(m_Desc, m_Desc.GetArraySize(), 0, StagingBufferOffsetAlignment);
VkStagingBuffCI.size = GetStagingTextureDataSize(m_Desc, StagingBufferOffsetAlignment);

// clang-format off
DEV_CHECK_ERR((m_Desc.CPUAccessFlags & (CPU_ACCESS_READ | CPU_ACCESS_WRITE)) == CPU_ACCESS_READ ||
Expand Down
11 changes: 8 additions & 3 deletions Graphics/GraphicsTools/interface/DynamicTextureAtlas.h
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -224,10 +224,15 @@ 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.
/// The factor must be in the range (1, 2]. For example, if the factor is 2.0, the array size
/// will be doubled every time there is insufficient space.
float GrowthFactor = 2.0f;

/// Maximum number of slices in texture array.
Uint32 MaxSliceCount = 2048;
Expand Down
6 changes: 4 additions & 2 deletions Graphics/GraphicsTools/src/DynamicTextureAtlas.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -384,6 +384,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
// clang-format off
m_MinAlignment {CreateInfo.MinAlignment},
m_ExtraSliceCount {CreateInfo.ExtraSliceCount},
m_ExtraSliceFactor{clamp(CreateInfo.GrowthFactor, 1.f, 2.f) - 1.f},
m_MaxSliceCount {CreateInfo.Desc.Type == RESOURCE_DIM_TEX_2D_ARRAY ? std::min(CreateInfo.MaxSliceCount, Uint32{2048}) : 1},
m_Silent {CreateInfo.Silent},
m_SuballocationsAllocator
Expand Down Expand Up @@ -688,7 +689,7 @@ class DynamicTextureAtlasImpl final : public ObjectBase<IDynamicTextureAtlas>
{
const auto ExtraSliceCount = m_ExtraSliceCount != 0 ?
m_ExtraSliceCount :
std::max(m_TexArraySize.load(), 1u);
std::max(static_cast<Uint32>(static_cast<float>(m_TexArraySize.load()) * m_ExtraSliceFactor), 1u);

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

const Uint32 m_MinAlignment;
const Uint32 m_ExtraSliceCount;
const float m_ExtraSliceFactor;
const Uint32 m_MaxSliceCount;
const bool m_Silent;

Expand Down

0 comments on commit 9271be3

Please sign in to comment.