Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ZEngine/ZEngine/Applications/AppRenderPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ namespace ZEngine::Applications

if (Device->RRM)
static_cast<Rendering::RenderResourceManager*>(Device->RRM)->BeginFrame(swapchain->CurrentFrame->Index);
Managers::AssetManager::FlushTextureReleases();

for (uint8_t thread_idx = 0; thread_idx < Device->CommandBufferMgr->TotalThreadCount; ++thread_idx)
{
Expand Down
18 changes: 17 additions & 1 deletion ZEngine/ZEngine/Core/VFS/Registry/AssetRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ namespace ZEngine::Core::VFS
m_stale_cb = cb;
}

void AssetRegistry::SetOnRemovedCallback(void* ctx, void (*cb)(void*, const uuids::uuid&, Managers::AssetType))
{
m_removed_cb_ctx = ctx;
m_removed_cb = cb;
}

void AssetRegistry::OnAssetModified(const Core::VFS::VFSPath& path)
{
Helpers::Handle<AssetRecord> handle = m_index.FindByPath(path);
Expand Down Expand Up @@ -204,6 +210,16 @@ namespace ZEngine::Core::VFS
if (m_reload_cb && !cascade.empty())
m_reload_cb(m_reload_cb_ctx, std::span<const uuids::uuid>(cascade.data(), cascade.size()));

if (m_removed_cb)
{
for (uint32_t i = 0; i < cascade.size(); ++i)
{
AssetRecord* cascade_rec = FindByUUID(cascade[i]);
if (cascade_rec)
m_removed_cb(m_removed_cb_ctx, cascade[i], cascade_rec->Type);
}
}

Remove(rec->UUID);
}

Expand Down Expand Up @@ -356,7 +372,7 @@ namespace ZEngine::Core::VFS
if (ext.Empty() || !ext.Data)
return Managers::AssetType::MESH;

if (ext.Equals(".png") || ext.Equals(".jpg") || ext.Equals(".jpeg") || ext.Equals(".hdr") || ext.Equals(".ktx") || ext.Equals(".ktx2"))
if (ext.Equals(".png") || ext.Equals(".jpg") || ext.Equals(".jpeg") || ext.Equals(".bmp") || ext.Equals(".tga") || ext.Equals(".gif") || ext.Equals(".psd") || ext.Equals(".pic") || ext.Equals(".hdr") || ext.Equals(".exr") || ext.Equals(".ktx") || ext.Equals(".ktx2"))
return Managers::AssetType::TEXTURE;
if (ext.Equals(".zematerial"))
return Managers::AssetType::MATERIAL;
Expand Down
6 changes: 6 additions & 0 deletions ZEngine/ZEngine/Core/VFS/Registry/AssetRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ namespace ZEngine::Core::VFS
void SetOnReadyCallback(void* ctx, void (*cb)(void*, const uuids::uuid&, Managers::AssetHandle));
void SetOnStaleCallback(void* ctx, void (*cb)(void*, const uuids::uuid&));

/// @brief Register a callback fired once per cascade UUID from OnAssetDeleted,
/// before each record is erased (so it can still read the record's Type).
void SetOnRemovedCallback(void* ctx, void (*cb)(void*, const uuids::uuid&, Managers::AssetType));

void OnAssetModified(const Core::VFS::VFSPath& path);
void OnAssetDeleted(const Core::VFS::VFSPath& path);
void OnAssetRenamed(const Core::VFS::VFSPath& old_path, const Core::VFS::VFSPath& new_path);
Expand Down Expand Up @@ -102,6 +106,8 @@ namespace ZEngine::Core::VFS
void (*m_ready_cb)(void*, const uuids::uuid&, Managers::AssetHandle) = nullptr;
void* m_stale_cb_ctx = nullptr;
void (*m_stale_cb)(void*, const uuids::uuid&) = nullptr;
void* m_removed_cb_ctx = nullptr;
void (*m_removed_cb)(void*, const uuids::uuid&, Managers::AssetType) = nullptr;

Core::Memory::ArenaAllocator m_scratch = {};

Expand Down
6 changes: 5 additions & 1 deletion ZEngine/ZEngine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <ZEngine/Importers/FbxImporter.h>
#include <ZEngine/Importers/GltfImporter.h>
#include <ZEngine/Importers/ImportCoordinator.h>
#include <ZEngine/Importers/TextureImporter.h>
#include <ZEngine/Input/InputManager.h>
#include <ZEngine/Logging/Logger.h>
#include <ZEngine/Logging/LoggerDefinition.h>
Expand Down Expand Up @@ -95,7 +96,7 @@ namespace ZEngine
ECS::Components::RegisterBuiltInComponentReflection();

// ImportPipeline arena: each importer carves its own sub-arena directly from this
// parent (glTF 64 MB + Assimp 128 MB + envmap 32 MB + editor ~414 MB).
// parent (glTF 64 MB + Assimp 128 MB + envmap 32 MB + texture 512 KB + editor ~414 MB).
// Each Import() call ends with Arena.Clear() so the sub-arena is reused, not consumed.
memory->CreateBudgetedArena(memory->Budget.ImportPipeline, &g_engine_ctx->ImportPipelineArena);
memory->CreateBudgetedArena(memory->Budget.UIContext, &g_engine_ctx->UIContextArena);
Expand All @@ -106,14 +107,17 @@ namespace ZEngine
static Importers::FbxImporter s_fbx_importer;
static Importers::AssimpImporter s_assimp_importer;
static Importers::EnvironmentMapImporter s_env_map_importer;
static Importers::TextureImporter s_texture_importer;
s_gltf_importer.Initialize(&g_engine_ctx->ImportPipelineArena);
s_fbx_importer.Initialize(&g_engine_ctx->ImportPipelineArena);
s_assimp_importer.Initialize(&g_engine_ctx->ImportPipelineArena);
s_env_map_importer.Initialize(&g_engine_ctx->ImportPipelineArena);
s_texture_importer.Initialize(&g_engine_ctx->ImportPipelineArena);
g_engine_ctx->ImportCoordinator->RegisterImporter(&s_gltf_importer);
g_engine_ctx->ImportCoordinator->RegisterImporter(&s_fbx_importer);
g_engine_ctx->ImportCoordinator->RegisterImporter(&s_assimp_importer);
g_engine_ctx->ImportCoordinator->RegisterImporter(&s_env_map_importer);
g_engine_ctx->ImportCoordinator->RegisterImporter(&s_texture_importer);

// RenderResourceManager — GPU lifetime authority, bridges asset layer and VulkanDevice
g_engine_ctx->RenderResourceManager = ZPushStructCtor(&g_engine_ctx->AssetArena, Rendering::RenderResourceManager);
Expand Down
24 changes: 17 additions & 7 deletions ZEngine/ZEngine/Hardwares/DeviceSwapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ namespace ZEngine::Hardwares
Device->TextureHandleToUpdates.Enqueue(tex_handle);
break;
}
auto img_buf = Device->Image2DBufferManager.Access(texture->BufferHandle);
auto img_buf = Device->ImageBufferManager.Access(texture->BufferHandle);
const auto& image_info = img_buf->GetDescriptorImageInfo();

auto scratch = ZGetScratch(&Arena);
Expand Down Expand Up @@ -388,19 +388,29 @@ namespace ZEngine::Hardwares
}

{
Textures::TextureHandle tex_to_dispose = {};
while (Device->TextureHandleToDispose.Pop(tex_to_dispose))
uint64_t completed = 0;
vkGetSemaphoreCounterValue(Device->LogicalDevice, RenderTimeline->GetHandle(), &completed);

TextureDisposeEntry entry = {};
while (Device->TextureHandleToDispose.pop(entry))
{
auto texture = Device->GlobalTextures.Access(tex_to_dispose);
if (entry.TimelineValue > completed)
{
// Not yet safe — push back and stop rather than skip past it (mirrors the
// TextureHandleToUpdates pattern above; render-thread-only, so no race).
Device->TextureHandleToDispose.push(entry);
break;
}
auto texture = Device->GlobalTextures.Access(entry.Handle);
if (texture)
{
auto buf = Device->Image2DBufferManager.Access(texture->BufferHandle);
auto buf = Device->ImageBufferManager.Access(texture->BufferHandle);
if (buf)
{
buf->Dispose();
}
Device->Image2DBufferManager.Remove(texture->BufferHandle);
Device->GlobalTextures.Remove(tex_to_dispose);
Device->ImageBufferManager.Remove(texture->BufferHandle);
Device->GlobalTextures.Remove(entry.Handle);
}
}
}
Expand Down
Loading
Loading