From 6c156d3bc2005c4125156c5f70f762d2274ae8b9 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Sat, 2 Dec 2023 10:55:00 +0100 Subject: [PATCH] Shaders are not compiling anymore... --- external/slang | 2 +- res/shaders/BasePass.slang | 3 +- res/shaders/lib/BRDF.slang | 2 +- res/shaders/lib/Common.slang | 7 +- res/shaders/lib/LightEnv.slang | 2 +- src/Editor/Asset/MeshLoader.cpp | 87 ++++++++++++-------- src/Editor/main.cpp | 36 +++++--- src/Engine/Graphics/Descriptor.cpp | 41 ++------- src/Engine/Graphics/Descriptor.h | 14 ++-- src/Engine/Graphics/Graphics.cpp | 1 - src/Engine/Graphics/Vulkan/Allocator.cpp | 12 +-- src/Engine/Graphics/Vulkan/Command.cpp | 4 + src/Engine/Graphics/Vulkan/Descriptor.cpp | 11 ++- src/Engine/Graphics/Vulkan/Graphics.cpp | 11 +++ src/Engine/Graphics/Vulkan/Graphics.h | 2 +- src/Engine/Graphics/Vulkan/PipelineCache.cpp | 4 +- src/Engine/Graphics/Vulkan/RenderPass.cpp | 5 +- src/Engine/Graphics/Vulkan/Resources.cpp | 30 ++++++- src/Engine/Graphics/Vulkan/Resources.h | 6 ++ src/Engine/Graphics/Vulkan/Shader.cpp | 11 +-- src/Engine/Window/Window.cpp | 19 ++--- src/Engine/Window/WindowManager.cpp | 21 +++-- src/Engine/Window/WindowManager.h | 7 +- 23 files changed, 190 insertions(+), 148 deletions(-) diff --git a/external/slang b/external/slang index 5af36cf..bfd3f39 160000 --- a/external/slang +++ b/external/slang @@ -1 +1 @@ -Subproject commit 5af36cf4ca7a81d91fb03cdf39e40b6b4175fa2d +Subproject commit bfd3f39d04047d7a46e75206cd125ed87b3f3f99 diff --git a/res/shaders/BasePass.slang b/res/shaders/BasePass.slang index 7cb7899..e2a8ce2 100644 --- a/res/shaders/BasePass.slang +++ b/res/shaders/BasePass.slang @@ -17,10 +17,9 @@ ParameterBlock pLightCullingData; [shader("pixel")] float4 fragmentMain(in FragmentParameter params) : SV_Target { - MaterialParameter materialParams = params.getMaterialParameter(); LightingParameter lightingParams = params.getLightingParameter(); - let brdf = pMaterial.prepare(materialParams); + let brdf = pMaterial.prepare(params.getMaterialParameter()); float3 result = float3(0, 0, 0); for(int i = 0; i < pLightEnv.numDirectionalLights; ++i) { diff --git a/res/shaders/lib/BRDF.slang b/res/shaders/lib/BRDF.slang index 5c637c1..f1664e4 100644 --- a/res/shaders/lib/BRDF.slang +++ b/res/shaders/lib/BRDF.slang @@ -30,7 +30,7 @@ struct BlinnPhong : IBRDF float3 h = lightDir_WS + viewDir_WS; float specular = dot(normal_WS, h); - return lightDir_WS * 2 + float3(1, 1, 1);//baseColor * (diffuse + specular) * lightColor; + return baseColor * (diffuse + specular) * lightColor; } }; diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index a856073..f6aa9f0 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -35,14 +35,15 @@ struct Frustum Plane basePlane; bool pointInside(float3 point) { - if (dot(basePlane.n, point) + basePlane.d < 0) + float result = dot(basePlane.n, point) + basePlane.d; + if (0.0f > result) { return false; } for(int p = 0; p < 4; ++p) { - float result = dot(sides[p].n, point) + sides[p].d; - if(result < 0) + result = dot(sides[p].n, point) + sides[p].d; + if(0.0f > result) { return false; } diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 174e74a..03ce8c9 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -28,7 +28,7 @@ struct PointLight : ILightEnv float3 lightDir_WS = position_WS.xyz - params.position_WS; float d = length(lightDir_WS); float illuminance = max(1 - d / colorRange.w, 0); - return brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz); + return illuminance * brdf.evaluate(params.tbn, params.viewDir_WS, normalize(lightDir_WS), colorRange.xyz); } bool insidePlane(Plane plane) diff --git a/src/Editor/Asset/MeshLoader.cpp b/src/Editor/Asset/MeshLoader.cpp index 9d379aa..7fba56e 100644 --- a/src/Editor/Asset/MeshLoader.cpp +++ b/src/Editor/Asset/MeshLoader.cpp @@ -48,48 +48,67 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName { aiMaterial* material = scene->mMaterials[i]; json matCode; - std::string materialName = std::format("{0}{1}", baseName, material->GetName().C_Str()); + std::string materialName = std::format("{0}{1}{2}", baseName, material->GetName().C_Str(), char(i+'a')); materialName.erase(std::remove(materialName.begin(), materialName.end(), '.'), materialName.end()); // dots break adding the .asset extension later matCode["name"] = materialName; matCode["profile"] = "BlinnPhong"; //TODO: other shading models aiString texPath; - //TODO make samplers based on used textures if(material->GetTexture(aiTextureType_DIFFUSE, 0, &texPath) == AI_SUCCESS) { - std::string texFilename = std::filesystem::path(texPath.C_Str()).stem().string(); - matCode["params"]["diffuseTexture"] = - { - {"type", "Texture2D"}, - {"default", texFilename} - }; - matCode["params"]["diffuseSampler"] = + auto texFilename = std::filesystem::path(texPath.C_Str()).stem(); + if (texFilename == "white") { - {"type", "SamplerState"} - }; - matCode["code"].push_back( + matCode["code"].push_back( + { + { "exp", "BRDF" }, + { "profile", "BlinnPhong" }, + { "values", { + {"baseColor", "float3(1, 1, 1)"} + }} + } + ); + } + else + { + AssetImporter::importTexture(TextureImportArgs{ + .filePath = meshDirectory / texPath.C_Str(), + .importPath = importPath, + }); + matCode["params"]["diffuseTexture"] = { - { "exp", "Sample" }, - { "texture", "diffuseTexture" }, - { "sampler", "diffuseSampler" }, - { "coords", "input.texCoords[0]"} - } - ); - matCode["code"].push_back( + {"type", "Texture2D"}, + {"default", texFilename.string()} + }; + matCode["params"]["diffuseSampler"] = { - { "exp", "Swizzle" }, - { "target", 0 }, - { "comp", json::array({0, 1, 2}) }, - } - ); - matCode["code"].push_back( - { - { "exp", "BRDF" }, - { "profile", "BlinnPhong" }, - { "values", { - {"baseColor", 1} - }} - } - ); + {"type", "Sampler"} + }; + matCode["code"].push_back( + { + { "exp", "Sample" }, + { "texture", "diffuseTexture" }, + { "sampler", "diffuseSampler" }, + { "coords", "input.texCoords[0]"} + } + ); + matCode["code"].push_back( + { + { "exp", "Swizzle" }, + { "target", 0 }, + { "comp", json::array({0, 1, 2}) }, + } + ); + matCode["code"].push_back( + { + { "exp", "BRDF" }, + { "profile", "BlinnPhong" }, + { "values", { + {"baseColor", 1} + }} + } + ); + } + } else { @@ -109,7 +128,7 @@ void MeshLoader::loadMaterials(const aiScene* scene, const std::string& baseName if(material->GetTexture(aiTextureType_NORMALS, 0, &texPath) == AI_SUCCESS) { } - std::string outMatFilename = matCode["name"].get().append(".json"); + std::string outMatFilename = materialName.append(".json"); std::ofstream outMatFile = std::ofstream(meshDirectory / outMatFilename); outMatFile << std::setw(4) << matCode; outMatFile.flush(); diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index c9c6e52..3798a38 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -58,6 +58,9 @@ int main() AssetImporter::importMesh(MeshImportArgs{ .filePath= sourcePath / "old_resources/models/cube.fbx", }); + AssetImporter::importMesh(MeshImportArgs{ + .filePath = sourcePath / "old_resources/models/sponza/sponza.gltf", + }); //AssetImporter::importMesh(MeshImportArgs{ // .filePath= sourcePath / "old_resources/models/flameThrower.fbx", // }); @@ -238,21 +241,28 @@ int main() //window->addView(inspectorView); sceneView->setFocused(); - window->render(); - //export game - std::filesystem::create_directories(outputPath); - std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str()); - std::system(std::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str()); - std::system(std::format("cmake --build {}", cmakePath.generic_string()).c_str()); - std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive); - std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive); - std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive); + while (windowManager->isActive()) + { + windowManager->render(); + } + vd->~StaticMeshVertexData(); + //export game + if (false) + { + std::filesystem::create_directories(outputPath); + std::system(std::format("cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DGAME_TITLE=\"{}\" -DGAME_DESTINATION=\"{}\" -DGAME_BINARY=\"{}\" -P ./cmake/ExportProject.cmake", gameName, outputPath.generic_string(), binaryPath.generic_string()).c_str()); + std::system(std::format("cmake -S {} -B {}", cmakePath.generic_string(), cmakePath.generic_string()).c_str()); + std::system(std::format("cmake --build {}", cmakePath.generic_string()).c_str()); + std::filesystem::copy(sourcePath / "Assets", outputPath / "Assets", std::filesystem::copy_options::recursive); + std::filesystem::copy("shaders", outputPath / "shaders", std::filesystem::copy_options::recursive); + std::filesystem::copy("textures", outputPath / "textures", std::filesystem::copy_options::recursive); #ifdef WIN32 - std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll"); - std::filesystem::copy_file("slang.dll", outputPath / "slang.dll"); - std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll"); - std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll"); + std::filesystem::copy_file("assimp-vc143-mt.dll", outputPath / "assimp-vc143-mt.dll"); + std::filesystem::copy_file("slang.dll", outputPath / "slang.dll"); + std::filesystem::copy_file("slang-glslang.dll", outputPath / "slang-glslang.dll"); + std::filesystem::copy_file("slang-llvm.dll", outputPath / "slang-llvm.dll"); #endif + } return 0; } \ No newline at end of file diff --git a/src/Engine/Graphics/Descriptor.cpp b/src/Engine/Graphics/Descriptor.cpp index cc43180..0cf9030 100644 --- a/src/Engine/Graphics/Descriptor.cpp +++ b/src/Engine/Graphics/Descriptor.cpp @@ -3,34 +3,6 @@ using namespace Seele; using namespace Seele::Gfx; -DescriptorBinding::DescriptorBinding() - : binding(0) - , descriptorType(SE_DESCRIPTOR_TYPE_MAX_ENUM) - , descriptorCount(0x7fff) - , shaderStages(SE_SHADER_STAGE_ALL) -{ -} - -DescriptorBinding::DescriptorBinding(const DescriptorBinding& other) - : binding(other.binding) - , descriptorType(other.descriptorType) - , descriptorCount(other.descriptorCount) - , shaderStages(other.shaderStages) -{ -} - -DescriptorBinding& DescriptorBinding::operator=(const DescriptorBinding& other) -{ - if (this != &other) - { - binding = other.binding; - descriptorType = other.descriptorType; - descriptorCount = other.descriptorCount; - shaderStages = other.shaderStages; - } - return *this; -} - DescriptorPool::DescriptorPool() { } @@ -77,12 +49,13 @@ void DescriptorLayout::addDescriptorBinding(uint32 bindingIndex, SeDescriptorTyp { descriptorBindings.resize(bindingIndex + 1); } - DescriptorBinding& binding = descriptorBindings[bindingIndex]; - binding.binding = bindingIndex; - binding.descriptorType = type; - binding.descriptorCount = arrayCount; - binding.bindingFlags = bindingFlags; - binding.shaderStages = shaderStages; + descriptorBindings[bindingIndex] = DescriptorBinding{ + .binding = bindingIndex, + .descriptorType = type, + .descriptorCount = arrayCount, + .bindingFlags = bindingFlags, + .shaderStages = shaderStages, + }; } PDescriptorSet DescriptorLayout::allocateDescriptorSet() diff --git a/src/Engine/Graphics/Descriptor.h b/src/Engine/Graphics/Descriptor.h index 3948bd8..9fdff76 100644 --- a/src/Engine/Graphics/Descriptor.h +++ b/src/Engine/Graphics/Descriptor.h @@ -6,17 +6,13 @@ namespace Seele { namespace Gfx { -class DescriptorBinding +struct DescriptorBinding { -public: - DescriptorBinding(); - DescriptorBinding(const DescriptorBinding& other); - DescriptorBinding& operator=(const DescriptorBinding& other); - uint32 binding; - SeDescriptorType descriptorType; - uint32 descriptorCount; + uint32 binding = 0; + SeDescriptorType descriptorType = SE_DESCRIPTOR_TYPE_MAX_ENUM; + uint32 descriptorCount = 0x7fff; SeDescriptorBindingFlags bindingFlags = 0; - SeShaderStageFlags shaderStages; + SeShaderStageFlags shaderStages = SE_SHADER_STAGE_ALL; }; DEFINE_REF(DescriptorBinding) diff --git a/src/Engine/Graphics/Graphics.cpp b/src/Engine/Graphics/Graphics.cpp index 2090bb4..1ba5ab5 100644 --- a/src/Engine/Graphics/Graphics.cpp +++ b/src/Engine/Graphics/Graphics.cpp @@ -1,6 +1,5 @@ #include "Graphics.h" #include "Shader.h" -#include "Graphics.h" using namespace Seele::Gfx; diff --git a/src/Engine/Graphics/Vulkan/Allocator.cpp b/src/Engine/Graphics/Vulkan/Allocator.cpp index 72699bb..33d5237 100644 --- a/src/Engine/Graphics/Vulkan/Allocator.cpp +++ b/src/Engine/Graphics/Vulkan/Allocator.cpp @@ -66,7 +66,6 @@ Allocation::Allocation(PGraphics graphics, PAllocator pool, VkDeviceSize size, u Allocation::~Allocation() { vkFreeMemory(device, allocatedMemory, nullptr); - assert(bytesUsed == 0); } OSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment) @@ -177,16 +176,6 @@ Allocator::Allocator(PGraphics graphics) Allocator::~Allocator() { - for (auto& heap : heaps) - { - for (auto& alloc : heap.allocations) - { - assert(alloc->activeAllocations.empty()); - assert(alloc->freeRanges.size() == 1); - } - heap.allocations.clear(); - } - graphics = nullptr; } OSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo) @@ -272,6 +261,7 @@ StagingBuffer::~StagingBuffer() graphics->getDedicatedTransferCommands()->getCommands(), buffer); graphics->getDestructionManager()->queueAllocation( graphics->getDedicatedTransferCommands()->getCommands(), std::move(allocation)); + graphics->getDedicatedTransferCommands()->submitCommands(); } void* StagingBuffer::map() diff --git a/src/Engine/Graphics/Vulkan/Command.cpp b/src/Engine/Graphics/Vulkan/Command.cpp index 74d8345..0dc0bc3 100644 --- a/src/Engine/Graphics/Vulkan/Command.cpp +++ b/src/Engine/Graphics/Vulkan/Command.cpp @@ -469,6 +469,10 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue) CommandPool::~CommandPool() { vkDeviceWaitIdle(graphics->getDevice()); + for (auto& command : allocatedBuffers) + { + command->checkFence(); + } allocatedRenderCommands.clear(); allocatedComputeCommands.clear(); allocatedBuffers.clear(); diff --git a/src/Engine/Graphics/Vulkan/Descriptor.cpp b/src/Engine/Graphics/Vulkan/Descriptor.cpp index 189868f..9f51255 100644 --- a/src/Engine/Graphics/Vulkan/Descriptor.cpp +++ b/src/Engine/Graphics/Vulkan/Descriptor.cpp @@ -2,6 +2,7 @@ #include "Graphics.h" #include "Texture.h" #include "Buffer.h" +#include "Command.h" using namespace Seele; using namespace Seele::Vulkan; @@ -345,8 +346,14 @@ DescriptorPool::DescriptorPool(PGraphics graphics, DescriptorLayout &layout) DescriptorPool::~DescriptorPool() { - vkDestroyDescriptorPool(graphics->getDevice(), poolHandle, nullptr); - graphics = nullptr; + for (uint32 setIndex = 0; setIndex < cachedHandles.size(); ++setIndex) + { + if (cachedHandles[setIndex] != nullptr && cachedHandles[setIndex]->setHandle != VK_NULL_HANDLE) + { + graphics->getDestructionManager()->queueDescriptorSet(graphics->getGraphicsCommands()->getCommands(), Pair(cachedHandles[setIndex]->setHandle, poolHandle)); + } + } + graphics->getDestructionManager()->queueDescriptorPool(graphics->getGraphicsCommands()->getCommands(), poolHandle); if(nextAlloc) { delete nextAlloc; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 6044a38..c4d5a37 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -32,6 +32,17 @@ Graphics::Graphics() Graphics::~Graphics() { + vkDeviceWaitIdle(handle); + graphicsCommands = nullptr; + computeCommands = nullptr; + transferCommands = nullptr; + dedicatedTransferCommands = nullptr; + pipelineCache = nullptr; + allocator = nullptr; + destructionManager = nullptr; + stagingManager = nullptr; + allocatedFramebuffers.clear(); + shaderCompiler = nullptr; vkDestroyDevice(handle, nullptr); DestroyDebugReportCallbackEXT(instance, nullptr, callback); vkDestroyInstance(instance, nullptr); diff --git a/src/Engine/Graphics/Vulkan/Graphics.h b/src/Engine/Graphics/Vulkan/Graphics.h index 98e9fd5..0724402 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.h +++ b/src/Engine/Graphics/Vulkan/Graphics.h @@ -85,7 +85,6 @@ protected: OQueue computeQueue; OQueue transferQueue; OQueue dedicatedTransferQueue; - OPipelineCache pipelineCache; thread_local static OCommandPool graphicsCommands; thread_local static OCommandPool computeCommands; thread_local static OCommandPool transferCommands; @@ -96,6 +95,7 @@ protected: VkDebugReportCallbackEXT callback; Map allocatedFramebuffers; OAllocator allocator; + OPipelineCache pipelineCache; OStagingManager stagingManager; ODestructionManager destructionManager; diff --git a/src/Engine/Graphics/Vulkan/PipelineCache.cpp b/src/Engine/Graphics/Vulkan/PipelineCache.cpp index a55301c..b9ae7ec 100644 --- a/src/Engine/Graphics/Vulkan/PipelineCache.cpp +++ b/src/Engine/Graphics/Vulkan/PipelineCache.cpp @@ -37,9 +37,9 @@ PipelineCache::PipelineCache(PGraphics graphics, const std::string& cacheFilePat PipelineCache::~PipelineCache() { VkDeviceSize cacheSize; - vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr); + VK_CHECK(vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, nullptr)); Array cacheData(cacheSize); - vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data()); + VK_CHECK(vkGetPipelineCacheData(graphics->getDevice(), cache, &cacheSize, cacheData.data())); std::ofstream stream(cacheFile, std::ios::binary); stream.write((char*)cacheData.data(), cacheSize); stream.flush(); diff --git a/src/Engine/Graphics/Vulkan/RenderPass.cpp b/src/Engine/Graphics/Vulkan/RenderPass.cpp index f96506d..f4a95cc 100644 --- a/src/Engine/Graphics/Vulkan/RenderPass.cpp +++ b/src/Engine/Graphics/Vulkan/RenderPass.cpp @@ -2,7 +2,8 @@ #include "Graphics.h" #include "Framebuffer.h" #include "Texture.h" -#include "RenderPass.h" +#include "Resources.h" +#include "Command.h" using namespace Seele; using namespace Seele::Vulkan; @@ -125,7 +126,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::ORenderTargetLayout _layout, Gfx RenderPass::~RenderPass() { - vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr); + graphics->getDestructionManager()->queueRenderPass(graphics->getGraphicsCommands()->getCommands(), renderPass); } uint32 RenderPass::getFramebufferHash() diff --git a/src/Engine/Graphics/Vulkan/Resources.cpp b/src/Engine/Graphics/Vulkan/Resources.cpp index 637c9e4..2e413ee 100644 --- a/src/Engine/Graphics/Vulkan/Resources.cpp +++ b/src/Engine/Graphics/Vulkan/Resources.cpp @@ -20,7 +20,7 @@ Semaphore::Semaphore(PGraphics graphics) Semaphore::~Semaphore() { - graphics->getDestructionManager()->queueSemaphore(graphics->getGraphicsCommands()->getCommands(), handle); + vkDestroySemaphore(graphics->getDevice(), handle, nullptr); } Fence::Fence(PGraphics graphics) @@ -114,6 +114,21 @@ void DestructionManager::queueSemaphore(PCommand cmd, VkSemaphore sem) sems[cmd].add(sem); } +void DestructionManager::queueRenderPass(PCommand cmd, VkRenderPass renderPass) +{ + renderPasses[cmd].add(renderPass); +} + +void DestructionManager::queueDescriptorPool(PCommand cmd, VkDescriptorPool pool) +{ + pools[cmd].add(pool); +} + +void DestructionManager::queueDescriptorSet(PCommand cmd, Pair set) +{ + sets[cmd].add(set); +} + void DestructionManager::queueAllocation(PCommand cmd, OSubAllocation alloc) { allocs[cmd].add(std::move(alloc)); @@ -137,9 +152,22 @@ void DestructionManager::notifyCmdComplete(PCommand cmd) { vkDestroySemaphore(graphics->getDevice(), sem, nullptr); } + for (auto [set, pool] : sets[cmd]) + { + vkFreeDescriptorSets(graphics->getDevice(), pool, 1, &set); + } + for (auto pool : pools[cmd]) + { + vkDestroyDescriptorPool(graphics->getDevice(), pool, nullptr); + } + for (auto renderPass : renderPasses[cmd]) + { + vkDestroyRenderPass(graphics->getDevice(), renderPass, nullptr); + } buffers[cmd].clear(); images[cmd].clear(); views[cmd].clear(); sems[cmd].clear(); + renderPasses[cmd].clear(); allocs[cmd].clear(); } diff --git a/src/Engine/Graphics/Vulkan/Resources.h b/src/Engine/Graphics/Vulkan/Resources.h index af6a56e..d70a289 100644 --- a/src/Engine/Graphics/Vulkan/Resources.h +++ b/src/Engine/Graphics/Vulkan/Resources.h @@ -61,6 +61,9 @@ public: void queueImage(PCommand cmd, VkImage image); void queueImageView(PCommand cmd, VkImageView view); void queueSemaphore(PCommand cmd, VkSemaphore sem); + void queueRenderPass(PCommand cmd, VkRenderPass renderPass); + void queueDescriptorPool(PCommand cmd, VkDescriptorPool pool); + void queueDescriptorSet(PCommand cmd, Pair set); void queueAllocation(PCommand cmd, OSubAllocation alloc); void notifyCmdComplete(PCommand cmdbuffer); private: @@ -69,6 +72,9 @@ private: Map> images; Map> views; Map> sems; + Map> renderPasses; + Map> pools; + Map>> sets; Map> allocs; }; DEFINE_REF(DestructionManager) diff --git a/src/Engine/Graphics/Vulkan/Shader.cpp b/src/Engine/Graphics/Vulkan/Shader.cpp index eadb6cb..94aafbd 100644 --- a/src/Engine/Graphics/Vulkan/Shader.cpp +++ b/src/Engine/Graphics/Vulkan/Shader.cpp @@ -55,12 +55,8 @@ void Shader::create(const ShaderCreateInfo& createInfo) slang::TargetDesc vulkan; vulkan.profile = globalSession->findProfile("sm_6_6"); vulkan.format = SLANG_SPIRV; - slang::TargetDesc glsl; - glsl.profile = globalSession->findProfile("sm_6_6"); - glsl.format = SLANG_GLSL; - slang::TargetDesc targets[2] = { vulkan, glsl }; - sessionDesc.targetCount = 2; - sessionDesc.targets = targets; + sessionDesc.targetCount = 1; + sessionDesc.targets = &vulkan; StaticArray searchPaths = {"shaders/", "shaders/lib/", "shaders/generated/"}; sessionDesc.searchPaths = searchPaths.data(); sessionDesc.searchPathCount = searchPaths.size(); @@ -136,7 +132,7 @@ void Shader::create(const ShaderCreateInfo& createInfo) hash = CRC::Calculate(entryPointName.data(), entryPointName.size(), CRC::CRC_32()); hash = CRC::Calculate(kernelBlob->getBufferPointer(), kernelBlob->getBufferSize(), CRC::CRC_32(), hash); - + /* specializedComponent->getEntryPointCode( 0, 1, @@ -147,4 +143,5 @@ void Shader::create(const ShaderCreateInfo& createInfo) std::ofstream shaderStream(createInfo.name + createInfo.entryPoint + ".glsl"); shaderStream << (char*)kernelBlob->getBufferPointer(); shaderStream.close(); + */ } \ No newline at end of file diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index 7471abf..eae0338 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -22,19 +22,16 @@ void Window::addView(PView view) void Window::render() { - while(owner->isActive()) + gfxHandle->beginFrame(); + for(auto& view : views) { - gfxHandle->beginFrame(); - for(auto& view : views) - { - view->beginUpdate(); - view->update(); - view->commitUpdate(); - view->prepareRender(); - view->render(); - } - gfxHandle->endFrame(); + view->beginUpdate(); + view->update(); + view->commitUpdate(); + view->prepareRender(); + view->render(); } + gfxHandle->endFrame(); } Gfx::PWindow Window::getGfxHandle() diff --git a/src/Engine/Window/WindowManager.cpp b/src/Engine/Window/WindowManager.cpp index c7ce8e4..c0c17ae 100644 --- a/src/Engine/Window/WindowManager.cpp +++ b/src/Engine/Window/WindowManager.cpp @@ -11,19 +11,22 @@ WindowManager::~WindowManager() { } -PWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo) +OWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo) { OWindow window = new Window(this, graphics->createWindow(createInfo)); - PWindow ref = window; - windows.add(std::move(window)); - return ref; + windows.add(window); + return window; +} + +void WindowManager::render() +{ + for (auto& window : windows) + { + window->render(); + } } void WindowManager::notifyWindowClosed(PWindow window) { - windows.remove(windows.find([window] (const OWindow& w) { return window == w; })); - if(windows.empty()) - { - exit(0); - } + windows.remove(window); } diff --git a/src/Engine/Window/WindowManager.h b/src/Engine/Window/WindowManager.h index acfca60..263e524 100644 --- a/src/Engine/Window/WindowManager.h +++ b/src/Engine/Window/WindowManager.h @@ -10,15 +10,16 @@ class WindowManager public: WindowManager(); ~WindowManager(); - PWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo); + OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo &createInfo); + void render(); void notifyWindowClosed(PWindow window); - inline bool isActive() const + bool isActive() const { return windows.size(); } private: - Array windows; + Array windows; }; DEFINE_REF(WindowManager) } // namespace Seele \ No newline at end of file