From aca495960f8f39cdd9f0c5b231d7279ad4e0303a Mon Sep 17 00:00:00 2001 From: Thraix Date: Sun, 10 Aug 2025 20:18:41 +0200 Subject: [PATCH] Fix varius minor issues - Asset will now generate a uuid if it is not inside the meta file - Device cleanup/idling improved - FileSystem now prints which file failed to open - Renderer header file now has the same parameter names as the source file --- CopiumEngine/src/copium/asset/AssetFile.cpp | 13 +++++++++++-- CopiumEngine/src/copium/asset/AssetFile.h | 2 +- CopiumEngine/src/copium/core/Device.cpp | 18 ++++++++++++------ CopiumEngine/src/copium/core/Device.h | 2 +- CopiumEngine/src/copium/core/Vulkan.cpp | 3 ++- CopiumEngine/src/copium/renderer/Renderer.h | 5 +++-- CopiumEngine/src/copium/util/FileSystem.cpp | 10 +++++----- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/CopiumEngine/src/copium/asset/AssetFile.cpp b/CopiumEngine/src/copium/asset/AssetFile.cpp index 10c7cec..e0fddfd 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.cpp +++ b/CopiumEngine/src/copium/asset/AssetFile.cpp @@ -2,6 +2,8 @@ #include "copium/util/FileSystem.h" +#include + namespace Copium { std::vector AssetFile::assetTypes; @@ -41,9 +43,16 @@ namespace Copium return uuid; } - void AssetFile::Load(const MetaFile& metaFile, const std::string& className) + void AssetFile::Load(MetaFile& metaFile, const std::string& className) { - const MetaFileClass& metaClass = metaFile.GetMetaClass(className); + MetaFileClass& metaClass = metaFile.GetMetaClass(className); + if (!metaClass.HasValue("uuid")) + { + CP_WARN("Asset (%s) has no UUID assigned, generating new one", path.c_str()); + metaClass.AddValue("uuid", Uuid{}.ToString()); + std::fstream file{path}; + file << metaFile; + } uuid = Uuid{metaClass.GetValue("uuid")}; dateModified = FileSystem::DateModified(path); } diff --git a/CopiumEngine/src/copium/asset/AssetFile.h b/CopiumEngine/src/copium/asset/AssetFile.h index 4ffb6e2..e31963b 100644 --- a/CopiumEngine/src/copium/asset/AssetFile.h +++ b/CopiumEngine/src/copium/asset/AssetFile.h @@ -23,7 +23,7 @@ namespace Copium const std::string& GetPath() const; Uuid GetUuid() const; private: - void Load(const MetaFile& metaFile, const std::string& className); + void Load(MetaFile& metaFile, const std::string& className); static void RegisterAssetType(const std::string& assetType); }; } diff --git a/CopiumEngine/src/copium/core/Device.cpp b/CopiumEngine/src/copium/core/Device.cpp index 1c13708..522921d 100644 --- a/CopiumEngine/src/copium/core/Device.cpp +++ b/CopiumEngine/src/copium/core/Device.cpp @@ -12,6 +12,7 @@ namespace Copium InitializeLogicalDevice(); InitializeCommandPool(); } + Device::~Device() { vkDestroyCommandPool(device, commandPool, nullptr); @@ -34,7 +35,7 @@ namespace Copium return graphicsQueue; } - VkQueue Device::GetPresentQueue() const + VkQueue Device::GetPresentQueue() const { return presentQueue; } @@ -69,11 +70,7 @@ namespace Copium void Device::WaitIdle() { vkDeviceWaitIdle(device); - while (!idleCommands.empty()) - { - idleCommands.front()(); - idleCommands.pop(); - } + CleanupIdleQueue(); } void Device::WaitIdleIfCommandQueued() @@ -84,6 +81,15 @@ namespace Copium } } + void Device::CleanupIdleQueue() + { + while (!idleCommands.empty()) + { + idleCommands.front()(); + idleCommands.pop(); + } + } + void Device::QueueIdleCommand(std::function idleCommand) { idleCommands.emplace(idleCommand); diff --git a/CopiumEngine/src/copium/core/Device.h b/CopiumEngine/src/copium/core/Device.h index 8ae9741..f48118a 100644 --- a/CopiumEngine/src/copium/core/Device.h +++ b/CopiumEngine/src/copium/core/Device.h @@ -26,6 +26,7 @@ namespace Copium uint32_t FindMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties); void WaitIdle(); void WaitIdleIfCommandQueued(); + void CleanupIdleQueue(); void QueueIdleCommand(std::function idleCommand); private: @@ -41,7 +42,6 @@ namespace Copium std::queue> idleCommands; // TODO end - private: void SelectPhysicalDevice(); void InitializeLogicalDevice(); diff --git a/CopiumEngine/src/copium/core/Vulkan.cpp b/CopiumEngine/src/copium/core/Vulkan.cpp index 172bb4f..5b53f8e 100644 --- a/CopiumEngine/src/copium/core/Vulkan.cpp +++ b/CopiumEngine/src/copium/core/Vulkan.cpp @@ -55,8 +55,9 @@ namespace Copium AssetManager::UnregisterAssetDir("assets/"); AssetManager::Cleanup(); imGuiInstance.reset(); - swapChain.reset(); device->WaitIdle(); + swapChain.reset(); + device->CleanupIdleQueue(); device.reset(); window.reset(); instance.reset(); diff --git a/CopiumEngine/src/copium/renderer/Renderer.h b/CopiumEngine/src/copium/renderer/Renderer.h index 5b4babc..480dc3a 100644 --- a/CopiumEngine/src/copium/renderer/Renderer.h +++ b/CopiumEngine/src/copium/renderer/Renderer.h @@ -28,11 +28,12 @@ namespace Copium int quadCount; int textureCount; void* mappedVertexBuffer; + std::map> descriptorSets; public: Renderer(const AssetRef& pipeline); - void Quad(const glm::vec2& from, const glm::vec2& to, const glm::vec3& color = glm::vec3{1, 1, 1}); - void Quad(const glm::vec2& from, const glm::vec2& to, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1}); + void Quad(const glm::vec2& pos, const glm::vec2& size, const glm::vec3& color = glm::vec3{1, 1, 1}); + void Quad(const glm::vec2& pos, const glm::vec2& size, const Sampler& sampler, const glm::vec2& texCoord1 = glm::vec2{0, 0}, const glm::vec2& texCoord2 = glm::vec2{1, 1}); // Returns the position where the text rendering ended glm::vec2 Text(const std::string& str, const glm::vec2& position, const Font& font, float size, const glm::vec3& color = glm::vec3(1, 1, 1)); diff --git a/CopiumEngine/src/copium/util/FileSystem.cpp b/CopiumEngine/src/copium/util/FileSystem.cpp index ba46a73..4a5627d 100644 --- a/CopiumEngine/src/copium/util/FileSystem.cpp +++ b/CopiumEngine/src/copium/util/FileSystem.cpp @@ -10,7 +10,7 @@ namespace Copium std::vector FileSystem::ReadFile(const std::string& filename) { std::ifstream file(filename, std::ios::ate | std::ios::binary); - CP_ASSERT(file.is_open(), "Failed to open file"); + CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str()); size_t fileSize = (size_t)file.tellg(); std::vector buffer(fileSize); @@ -24,7 +24,7 @@ namespace Copium std::vector FileSystem::ReadFile32(const std::string& filename) { std::ifstream file(filename, std::ios::ate | std::ios::binary); - CP_ASSERT(file.is_open(), "Failed to open file"); + CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str()); size_t fileSize = (size_t)file.tellg(); CP_ASSERT(fileSize % 4 == 0, "byte size is not divisible by 4"); @@ -39,7 +39,7 @@ namespace Copium std::string FileSystem::ReadFileStr(const std::string& filename) { std::ifstream file(filename, std::ios::ate | std::ios::binary); - CP_ASSERT(file.is_open(), "Failed to open file"); + CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str()); size_t fileSize = (size_t)file.tellg(); std::string buffer; @@ -56,7 +56,7 @@ namespace Copium std::filesystem::path path{filename}; std::filesystem::create_directories(path.parent_path()); std::ofstream file(filename, std::ios::binary); - CP_ASSERT(file.is_open(), "Failed to open file"); + CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str()); file.write(data.c_str(), data.size()); } @@ -66,7 +66,7 @@ namespace Copium std::filesystem::path path{filename}; std::filesystem::create_directories(path.parent_path()); std::ofstream file(filename, std::ios::binary); - CP_ASSERT(file.is_open(), "Failed to open file"); + CP_ASSERT(file.is_open(), "Failed to open file: %s", filename.c_str()); file.write(data, size); }