Skip to content

Commit

Permalink
Various fixes, related to using too many spot light shadow casters, t…
Browse files Browse the repository at this point in the history
…extures not being released.
  • Loading branch information
Duttenheim committed Nov 20, 2024
1 parent 1183971 commit 787ad26
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 78 deletions.
27 changes: 0 additions & 27 deletions code/foundation/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,6 @@ typedef uintptr PtrT; // the ptr type
typedef ptrdiff PtrDiff;
static const int InvalidIndex = -1;

//------------------------------------------------------------------------------
/**
*/
constexpr uint64
operator"" _KB(const unsigned long long val)
{
return val * 1024;
}

//------------------------------------------------------------------------------
/**
*/
constexpr uint64
operator"" _MB(const unsigned long long val)
{
return val * 1024 * 1024;
}

//------------------------------------------------------------------------------
/**
*/
constexpr uint64
operator"" _GB(const unsigned long long val)
{
return val * 1024 * 1024 * 1024;
}

//------------------------------------------------------------------------------
/**
*/
Expand Down
7 changes: 7 additions & 0 deletions code/foundation/memory/memory.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//------------------------------------------------------------------------------
// memory.cc
// (C) 2024 Individual contributors, see AUTHORS file
//------------------------------------------------------------------------------

thread_local char ThreadLocalMiniHeap[10_MB];
thread_local size_t ThreadLocalMiniHeapIterator = 0;
37 changes: 35 additions & 2 deletions code/foundation/memory/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@
*/
#include "core/config.h"

//------------------------------------------------------------------------------
/**
*/
constexpr uint64_t
operator"" _KB(const unsigned long long val)
{
return val * 1024;
}

//------------------------------------------------------------------------------
/**
*/
constexpr uint64_t
operator"" _MB(const unsigned long long val)
{
return val * 1024 * 1024;
}

//------------------------------------------------------------------------------
/**
*/
constexpr uint64_t
operator"" _GB(const unsigned long long val)
{
return val * 1024 * 1024 * 1024;
}

#if (__WIN32__)
#include "memory/win32/win32memory.h"
#elif ( __OSX__ || __APPLE__ || __linux__ )
Expand All @@ -19,6 +46,9 @@
#error "UNKNOWN PLATFORM"
#endif

extern thread_local char ThreadLocalMiniHeap[];
extern thread_local size_t ThreadLocalMiniHeapIterator;

//------------------------------------------------------------------------------
/**
*/
Expand All @@ -44,7 +74,8 @@ template<typename TYPE>
TYPE*
ArrayAllocStack(size_t size)
{
TYPE* buffer = (TYPE*)StackAlloc(size * sizeof(TYPE));
TYPE* buffer = (TYPE*)(ThreadLocalMiniHeap + ThreadLocalMiniHeapIterator);
ThreadLocalMiniHeapIterator += size * sizeof(TYPE);
if constexpr (!std::is_trivially_constructible<TYPE>::value)
{
for (size_t i = 0; i < size; ++i)
Expand Down Expand Up @@ -79,12 +110,14 @@ template<typename TYPE>
void
ArrayFreeStack(size_t size, TYPE* buffer)
{
char* topPtr = (ThreadLocalMiniHeap + ThreadLocalMiniHeapIterator - size * sizeof(TYPE));
n_assert(buffer == (TYPE*)topPtr);
if constexpr (!std::is_trivially_destructible<TYPE>::value)
{
for (size_t i = 0; i < size; ++i)
{
buffer[i].~TYPE();
}
}
StackFree((void*)buffer);
ThreadLocalMiniHeapIterator -= size * sizeof(TYPE);
}
8 changes: 3 additions & 5 deletions code/render/coregraphics/textureloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ LoadMips(CoreGraphics::CmdBufferId cmdBuf, TextureStreamData* streamData, uint b
void
FinishMips(CoreGraphics::CmdBufferId transferCommands, CoreGraphics::CmdBufferId handoverCommands, TextureStreamData* streamData, uint mipBits, const CoreGraphics::TextureId texture, const char* name)
{
// Finish the mips by handing them over
Util::FixedArray<TextureBarrierInfo> barriers(Util::PopCnt(mipBits) * streamData->numLayers);
// Finish the mips by handing them over
Util::FixedArray<TextureBarrierInfo, true> barriers(Util::PopCnt(mipBits) * streamData->numLayers);

uint mipIndexToLoad = Util::FirstOne(mipBits);
uint barrierCounter = 0;
Expand Down Expand Up @@ -261,10 +261,8 @@ TextureLoader::InitializeResource(const ResourceLoadJob& job, const Ptr<IO::Stre
}
}
}

CoreGraphics::TextureId texture = CoreGraphics::CreateTexture(textureInfo);

TextureIdRelease(texture);
CoreGraphics::TextureId texture = CoreGraphics::CreateTexture(textureInfo);
ret.id = texture;
return ret;
}
Expand Down
14 changes: 8 additions & 6 deletions code/render/coregraphics/vk/vktexture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TextureGetVkImageView(const CoreGraphics::TextureId id)
//------------------------------------------------------------------------------
/**
*/
const VkImageView
const VkImageView
TextureGetVkStencilImageView(const CoreGraphics::TextureId id)
{
Ids::Id32 stencil = textureAllocator.ConstGet<Texture_LoadInfo>(id.id).stencilExtension;
Expand All @@ -55,7 +55,7 @@ TextureGetVkStencilImageView(const CoreGraphics::TextureId id)
//------------------------------------------------------------------------------
/**
*/
const VkDevice
const VkDevice
TextureGetVkDevice(const CoreGraphics::TextureId id)
{
return textureAllocator.ConstGet<Texture_LoadInfo>(id.id).dev;
Expand Down Expand Up @@ -116,7 +116,7 @@ SetupSparse(VkDevice dev, VkImage img, Ids::Id32 sparseExtension, const VkTextur
table.bindCounts[i].Resize(sparseMemoryRequirement.imageMipTailFirstLod);
}

// create sparse bindings,
// create sparse bindings,
for (uint32_t layer = 0; layer < info.layers; layer++)
{
for (SizeT mip = 0; mip < (SizeT)sparseMemoryRequirement.imageMipTailFirstLod; mip++)
Expand Down Expand Up @@ -666,6 +666,8 @@ CreateTexture(const TextureCreateInfo& info)
ObjectSetName(ret, loadInfo.name.Value());
#endif

TextureIdRelease(ret);

return ret;
}

Expand Down Expand Up @@ -1006,7 +1008,7 @@ TextureSparseEvict(const CoreGraphics::TextureId id, IndexT layer, IndexT mip, I

const TextureSparsePageTable& table = textureSparseExtensionAllocator.ConstGet<TextureExtension_SparsePageTable>(sparseExtension);
Util::Array<VkSparseImageMemoryBind>& pageBinds = textureSparseExtensionAllocator.Get<TextureExtension_SparsePendingBinds>(sparseExtension);

// get page and allocate memory
CoreGraphics::TextureSparsePage& page = table.pages[layer][mip][pageIndex];
n_assert(page.alloc.mem != VK_NULL_HANDLE);
Expand Down Expand Up @@ -1173,7 +1175,7 @@ TextureSparseCommitChanges(const CoreGraphics::TextureId id)
if (opaqueBinds.IsEmpty() && pageBinds.IsEmpty())
return;

/* unused?
/* unused?
// setup bind structs
VkSparseImageMemoryBindInfo imageMemoryBindInfo =
{
Expand All @@ -1197,7 +1199,7 @@ TextureSparseCommitChanges(const CoreGraphics::TextureId id)
pageBinds.IsEmpty() ? 0u : 1u, &imageMemoryBindInfo,
0, nullptr
};
*/
*/

// execute sparse bind, the bind call
Vulkan::SparseTextureBind(img, opaqueBinds, pageBinds);
Expand Down
Loading

0 comments on commit 787ad26

Please sign in to comment.