diff --git a/Nuake/src/FileSystem/File.cpp b/Nuake/src/FileSystem/File.cpp index 6df0fb95..4d7a58cd 100644 --- a/Nuake/src/FileSystem/File.cpp +++ b/Nuake/src/FileSystem/File.cpp @@ -74,7 +74,7 @@ FileType File::GetFileType() const return FileType::Solution; } - if (ext == ".mesh") + if (ext == ".nkmesh") { return FileType::Mesh; } diff --git a/Nuake/src/FileSystem/FileSystem.cpp b/Nuake/src/FileSystem/FileSystem.cpp index 67bde920..5fe21154 100644 --- a/Nuake/src/FileSystem/FileSystem.cpp +++ b/Nuake/src/FileSystem/FileSystem.cpp @@ -17,7 +17,25 @@ std::string FileSystem::Root = ""; Ref FileSystem::RootDirectory; Ref> FileSystem::RootFileWatch; + +void FileSystem::ForeachFile(std::function)> func) +{ + ForeachFile(func, RootDirectory); +} + +void FileSystem::ForeachFile(std::function)> func, Ref dir) +{ + for(auto& file : RootDirectory->Files) + { + func(file); + } + for(auto& dir : RootDirectory->Directories) + { + ForeachFile(func, dir); + } +} + void FileSystem::ScanDirectory(Ref directory) { directory->Files.clear(); diff --git a/Nuake/src/FileSystem/FileSystem.h b/Nuake/src/FileSystem/FileSystem.h index dc218b37..316979a2 100644 --- a/Nuake/src/FileSystem/FileSystem.h +++ b/Nuake/src/FileSystem/FileSystem.h @@ -2,6 +2,8 @@ #include "src/Core/Core.h" #include "FileTypes.h" +#include + namespace filewatch { template @@ -21,7 +23,13 @@ namespace Nuake static Ref> RootFileWatch; static void SetRootDirectory(const std::string path); - + + // Starts from root + static void ForeachFile(std::function)> func); + + // Strats from specified folder + static void ForeachFile(std::function)> func, Ref dir); + static void Scan(); static std::string AbsoluteToRelative(const std::string& path); static std::string RelativeToAbsolute(const std::string& path); diff --git a/Nuake/src/Rendering/Vulkan/VkMesh.cpp b/Nuake/src/Rendering/Vulkan/VkMesh.cpp index bb53eba7..efbccc38 100644 --- a/Nuake/src/Rendering/Vulkan/VkMesh.cpp +++ b/Nuake/src/Rendering/Vulkan/VkMesh.cpp @@ -6,7 +6,8 @@ using namespace Nuake; -VkMesh::VkMesh(const std::vector& vertices, const std::vector& indices) +VkMesh::VkMesh(const std::vector& vertices, const std::vector& indices) : + DescriptorLayout(nullptr) { // First we allocate the buffers on the GPU const size_t vertexBufferSize = vertices.size() * sizeof(Vertex); @@ -55,13 +56,16 @@ void VkMesh::UploadToGPU(const std::vector& vertices, const std::vector< void VkMesh::CreateDescriptorSet() { - DescriptorLayoutBuilder builder; - builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); - auto& vk = VkRenderer::Get(); auto device = vk.GetDevice(); - DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); - DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout); + + if (!DescriptorLayout) + { + DescriptorLayoutBuilder builder; + builder.AddBinding(0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); + DescriptorLayout = builder.Build(device, VK_SHADER_STAGE_ALL_GRAPHICS); + DescriptorSet = vk.GetDescriptorAllocator().Allocate(device, DescriptorLayout); + } VkDescriptorBufferInfo bufferInfo{}; bufferInfo.buffer = GetVertexBuffer()->GetBuffer(); diff --git a/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp b/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp index 39e0426c..51f0807e 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp +++ b/Nuake/src/Rendering/Vulkan/VulkanRenderer.cpp @@ -80,9 +80,9 @@ void VkRenderer::Initialize() // Init global pool std::vector sizes = { - { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 8 }, - { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 }, - { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 50 } + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 4096 }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 4096 }, + { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1024 } }; GlobalDescriptorAllocator.InitPool(Device, 1000, sizes); @@ -883,5 +883,7 @@ VkDescriptorSet DescriptorAllocator::Allocate(VkDevice device, VkDescriptorSetLa VkDescriptorSet ds; VK_CALL(vkAllocateDescriptorSets(device, &allocInfo, &ds)); + NumAllocation++; + return ds; } diff --git a/Nuake/src/Rendering/Vulkan/VulkanRenderer.h b/Nuake/src/Rendering/Vulkan/VulkanRenderer.h index b270f780..4aea8d4c 100644 --- a/Nuake/src/Rendering/Vulkan/VulkanRenderer.h +++ b/Nuake/src/Rendering/Vulkan/VulkanRenderer.h @@ -103,6 +103,7 @@ namespace Nuake struct DescriptorAllocator { + uint32_t NumAllocation = 0; struct PoolSizeRatio { VkDescriptorType type; @@ -244,7 +245,7 @@ namespace Nuake void EndDraw(); - DescriptorAllocator GetDescriptorAllocator() + DescriptorAllocator& GetDescriptorAllocator() { return GlobalDescriptorAllocator; } diff --git a/Nuake/src/Resource/Bakers/AssetBakerManager.h b/Nuake/src/Resource/Bakers/AssetBakerManager.h index 92eb0346..8c3ce417 100644 --- a/Nuake/src/Resource/Bakers/AssetBakerManager.h +++ b/Nuake/src/Resource/Bakers/AssetBakerManager.h @@ -22,7 +22,11 @@ namespace Nuake void RegisterBaker(Ref baker) { - Bakers[baker->GetExtension()] = baker; + // Latest registered baker overwrites previous + for(const auto& extension : baker->GetExtensions()) + { + Bakers[extension] = baker; + } } Ref Bake(const Ref& file) diff --git a/Nuake/src/Resource/Bakers/GLTFBaker.h b/Nuake/src/Resource/Bakers/GLTFBaker.h index ad34ee46..2e8e9dec 100644 --- a/Nuake/src/Resource/Bakers/GLTFBaker.h +++ b/Nuake/src/Resource/Bakers/GLTFBaker.h @@ -30,7 +30,7 @@ namespace Nuake class GLTFBaker : public IAssetBaker { public: - GLTFBaker() : IAssetBaker(".glb") {} + GLTFBaker() : IAssetBaker({".glb", ".gltf", "fbx"}) {} Ref Bake(const Ref& file) override; diff --git a/Nuake/src/Resource/Bakers/IAssetBaker.h b/Nuake/src/Resource/Bakers/IAssetBaker.h index e2ac451b..3e15e1aa 100644 --- a/Nuake/src/Resource/Bakers/IAssetBaker.h +++ b/Nuake/src/Resource/Bakers/IAssetBaker.h @@ -3,6 +3,8 @@ #include "src/Core/Core.h" #include "src/FileSystem/File.h" +#include +#include #include namespace Nuake @@ -10,14 +12,20 @@ namespace Nuake class IAssetBaker { private: - std::string Extension; - + std::set Extensions; + public: - IAssetBaker(const std::string& extension) : Extension(extension) {} + IAssetBaker(const std::string& extension) : Extensions { extension } {} + IAssetBaker(std::initializer_list extension) : Extensions(extension.begin(), extension.end()) {} virtual ~IAssetBaker() = default; - std::string GetExtension() const { return Extension; } - + std::set GetExtensions() const { return Extensions; } + + inline bool CanBakeFile(const Ref& file) const + { + return Extensions.find(file->GetExtension()) != Extensions.end(); + } + public: virtual Ref Bake(const Ref& file) = 0; };