diff --git a/.vscode/launch.json b/.vscode/launch.json index 3ca231a..60de4f3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Engine Debug (Linux)", "type": "cppdbg", "request": "launch", - "program": "${workspaceRoot}/bin/Debug/SeeleEngine", + "program": "${workspaceRoot}/bin/Debug/Engine", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}/bin/Debug", @@ -27,7 +27,7 @@ "name": "Engine Debug", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceRoot}/bin/Debug/SeeleEngine.exe", + "program": "${workspaceRoot}/bin/Debug/Engine.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}/bin/Debug", @@ -47,7 +47,7 @@ "name": "Engine Release", "type": "cppvsdbg", "request": "launch", - "program": "${workspaceRoot}/bin/Release/SeeleEngine.exe", + "program": "${workspaceRoot}/bin/Release/Engine.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}/bin/Release", diff --git a/.vscode/settings.json b/.vscode/settings.json index b19ea0a..f0d45b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -134,5 +134,6 @@ }, "git.ignoreSubmodules": true, "cmake.configureOnOpen": true, + "cmake.parallelJobs": 0, "C_Cpp.intelliSenseEngineFallback": "Enabled" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d56a10a..881c1a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,19 +77,19 @@ if(CMAKE_DEBUG_POSTFIX) add_compile_definitions(ENABLE_VALIDATION) add_compile_definitions(SEELE_DEBUG) endif() -add_executable(SeeleEngine "") -target_link_libraries(SeeleEngine ${Vulkan_LIBRARY}) -target_link_libraries(SeeleEngine ${Boost_LIBRARIES}) -target_link_libraries(SeeleEngine ${GLFW_LIBRARIES}) -target_link_libraries(SeeleEngine ${SLANG_LIBRARIES}) -target_link_libraries(SeeleEngine ${ASSIMP_LIBRARIES}) -target_link_libraries(SeeleEngine ${NSAM_LIBRARIES}) -target_link_libraries(SeeleEngine ${KTX_LIBRARIES}) +add_executable(Engine "") +target_link_libraries(Engine ${Vulkan_LIBRARY}) +target_link_libraries(Engine ${Boost_LIBRARIES}) +target_link_libraries(Engine ${GLFW_LIBRARIES}) +target_link_libraries(Engine ${SLANG_LIBRARIES}) +target_link_libraries(Engine ${ASSIMP_LIBRARIES}) +target_link_libraries(Engine ${NSAM_LIBRARIES}) +target_link_libraries(Engine ${KTX_LIBRARIES}) if(UNIX) - target_link_libraries(SeeleEngine Threads::Threads) - target_link_libraries(SeeleEngine dl) + target_link_libraries(Engine Threads::Threads) + target_link_libraries(Engine dl) endif() -target_precompile_headers(SeeleEngine +target_precompile_headers(Engine PRIVATE @@ -111,9 +111,9 @@ add_subdirectory(src/) if(MSVC) set(_CRT_SECURE_NO_WARNINGS) - target_compile_options(SeeleEngine PRIVATE /Zi) + target_compile_options(Engine PRIVATE /Zi /MP) else() - target_compile_options(SeeleEngine PRIVATE -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) + target_compile_options(Engine PRIVATE -g -Wall -Wextra -Wno-delete-incomplete -pedantic -fcoroutines) endif() add_executable(Seele_unit_tests "") @@ -121,19 +121,19 @@ add_subdirectory(test/) if(WIN32) add_custom_target(copy-binaries ALL - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_GLSLANG} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLFW_BINARY} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ASSIMP_BINARY} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_LLVM} $ - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${KTX_BINARIES} $) + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_BINARIES} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SLANG_GLSLANG} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${GLFW_BINARY} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ASSIMP_BINARY} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_BINARIES} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${NSAM_LLVM} $ + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${KTX_BINARIES} $) else() add_custom_target(copy-binaries ALL COMMAND "") endif() -add_custom_target(copy-runtime-files ALL - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $ - DEPENDS SeeleEngine copy-binaries) +add_custom_target(SeeleEngine ALL + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/res $ + DEPENDS Engine copy-binaries) \ No newline at end of file diff --git a/Seele.natvis b/Seele.natvis index 75c87c3..dbac7bc 100644 --- a/Seele.natvis +++ b/Seele.natvis @@ -23,21 +23,42 @@ + + [{key}, {value}] + + key + value + + {{size={_size}} _size comp - nodeContainer.arraySize + _size nodeContainer._data + + empty + [{nodeContainer._data[node].pair}] + + nodeContainer._data[node].pair + + - RefPtr {*object->handle} {object->refCount.load()} references + empty + RefPtr {*object->handle} {object->refCount} references object->handle + + UniquePtr {*handle} + + handle + + diff --git a/res/shaders/LightCulling.slang b/res/shaders/LightCulling.slang index 1f1f32d..08131c3 100644 --- a/res/shaders/LightCulling.slang +++ b/res/shaders/LightCulling.slang @@ -23,19 +23,26 @@ layout(set = INDEX_VIEW_PARAMS, binding = 3) StructuredBuffer frustums; layout(set = INDEX_VIEW_PARAMS, binding = 4) -RWStructuredBuffer oLightIndexCounter; +globallycoherent RWStructuredBuffer oLightIndexCounter; layout(set = INDEX_VIEW_PARAMS, binding = 5) -RWStructuredBuffer tLightIndexCounter; +globallycoherent RWStructuredBuffer tLightIndexCounter; layout(set = INDEX_VIEW_PARAMS, binding = 6) RWStructuredBuffer oLightIndexList; layout(set = INDEX_VIEW_PARAMS, binding = 7) RWStructuredBuffer tLightIndexList; + layout(set = INDEX_VIEW_PARAMS, binding = 8) RWTexture2D oLightGrid; layout(set = INDEX_VIEW_PARAMS, binding = 9) RWTexture2D tLightGrid; +// Debug +//layout(set = INDEX_VIEW_PARAMS, binding = 10) +//Texture2D lightCountHeatMap; +//layout(set = INDEX_VIEW_PARAMS, binding = 11) +//RWTexture2D debugTexture; + groupshared uint uMinDepth; groupshared uint uMaxDepth; @@ -74,8 +81,8 @@ void tAppendLight(uint lightIndex) [shader("compute")] void cullLights(ComputeShaderInput in) { - int3 texCoord = int3(in.dispatchThreadID.xy, 0); - float fDepth = depthTextureVS.Load(texCoord).r; + int2 texCoord = in.dispatchThreadID.xy; + float fDepth = depthTextureVS.Load(int3(texCoord, 0)).r; uint uDepth = asuint(fDepth); if(in.groupIndex == 0) @@ -88,6 +95,7 @@ void cullLights(ComputeShaderInput in) } GroupMemoryBarrierWithGroupSync(); + InterlockedMin(uMinDepth, uDepth); InterlockedMax(uMaxDepth, uDepth); @@ -120,22 +128,24 @@ void cullLights(ComputeShaderInput in) if(in.groupIndex == 0) { - InterlockedAdd(oLightIndexCounter[0], (uint)oLightCount, oLightIndexStartOffset); + InterlockedAdd(oLightIndexCounter[0], oLightCount, oLightIndexStartOffset); oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount); - InterlockedAdd(tLightIndexCounter[0], (uint)tLightCount, tLightIndexStartOffset); + InterlockedAdd(tLightIndexCounter[0], tLightCount, tLightIndexStartOffset); tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount); } GroupMemoryBarrierWithGroupSync(); - for (uint j = in.groupIndex; j < (uint)oLightCount; j += BLOCK_SIZE * BLOCK_SIZE) + for (uint j = in.groupIndex; j < oLightCount; j += BLOCK_SIZE * BLOCK_SIZE) { oLightIndexList[oLightIndexStartOffset + j] = oLightList[j]; } // For transparent geometry. - for ( uint k = in.groupIndex; k < (uint)tLightCount; k += BLOCK_SIZE * BLOCK_SIZE ) + for ( uint k = in.groupIndex; k < tLightCount; k += BLOCK_SIZE * BLOCK_SIZE ) { tLightIndexList[tLightIndexStartOffset + k] = tLightList[k]; } + + } diff --git a/res/shaders/lib/Common.slang b/res/shaders/lib/Common.slang index 3fda9fe..4f7244e 100644 --- a/res/shaders/lib/Common.slang +++ b/res/shaders/lib/Common.slang @@ -1,14 +1,14 @@ const static float PI = 3.1415926535897932f; const static uint MAX_PARTICLES = 65536; -const static uint BLOCK_SIZE = 8; +const static uint BLOCK_SIZE = 32; struct ViewParameter { float4x4 viewMatrix; float4x4 projectionMatrix; - float4x4 inverseProjection; + float4x4 inverseProjection; float4 cameraPos_WS; - float2 screenDimensions; + float2 screenDimensions; } layout(set = INDEX_VIEW_PARAMS, binding = 0, std430) ConstantBuffer gViewParams; @@ -31,37 +31,31 @@ float4 screenToView( float4 screen ) float2 texCoord = screen.xy / gViewParams.screenDimensions; // Convert to clip space - float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); + float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w ); return clipToView( clip ); } struct Plane { - float3 n; - float d; - float3 p0; - float3 p1; - float3 p2; + float3 n; + float d; }; struct Frustum { - Plane planes[4]; + Plane planes[4]; }; Plane computePlane(float3 p0, float3 p1, float3 p2) { - Plane plane; + Plane plane; - float3 v0 = p2 - p0; - float3 v2 = p1 - p0; + float3 v0 = p1 - p0; + float3 v2 = p2 - p0; - plane.n = normalize(cross(v0, v2)); + plane.n = normalize(cross(v0, v2)); - plane.d = dot(plane.n, p0); - plane.p0 = p0; - plane.p1 = p1; - plane.p2 = p2; + plane.d = dot(plane.n, p0); - return plane; + return plane; } diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index 72670e7..09d75af 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -22,7 +22,6 @@ struct DirectionalLight : ILightEnv struct PointLight : ILightEnv { float4 positionWS; - float4 positionVS; float4 colorRange; float3 illuminate(MaterialFragmentParameter input, B brdf, float3 viewDir) @@ -36,14 +35,14 @@ struct PointLight : ILightEnv bool insidePlane(Plane plane) { - return dot(plane.n, positionVS.xyz) - plane.d < -colorRange.w; + return dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w; } bool insideFrustum(Frustum frustum, float zNear, float zFar) { bool result = true; - if(positionVS.z - colorRange.w > zNear || positionVS.z + colorRange.w < zFar) + if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar) { result = false; } @@ -56,6 +55,10 @@ struct PointLight : ILightEnv } return result; } + float3 getViewPos() + { + return mul(gViewParams.viewMatrix, positionWS).xyz; + } }; layout(set = INDEX_LIGHT_ENV, binding = 0, std430) diff --git a/src/Engine/Asset/CMakeLists.txt b/src/Engine/Asset/CMakeLists.txt index b7305e3..c5c7eae 100644 --- a/src/Engine/Asset/CMakeLists.txt +++ b/src/Engine/Asset/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Asset.h Asset.cpp diff --git a/src/Engine/Asset/MaterialLoader.cpp b/src/Engine/Asset/MaterialLoader.cpp index 3651146..f50d881 100644 --- a/src/Engine/Asset/MaterialLoader.cpp +++ b/src/Engine/Asset/MaterialLoader.cpp @@ -27,12 +27,12 @@ void MaterialLoader::importAsset(const std::filesystem::path& name) import(name, asset); } -Job MaterialLoader::import(std::filesystem::path, PMaterialAsset asset) +void MaterialLoader::import(std::filesystem::path, PMaterialAsset asset) { asset->load(); graphics->getShaderCompiler()->registerMaterial(asset); AssetRegistry::get().registerMaterial(asset); - co_return; + //co_return; } PMaterialAsset MaterialLoader::getPlaceHolderMaterial() diff --git a/src/Engine/Asset/MaterialLoader.h b/src/Engine/Asset/MaterialLoader.h index 99cac01..7deb336 100644 --- a/src/Engine/Asset/MaterialLoader.h +++ b/src/Engine/Asset/MaterialLoader.h @@ -18,7 +18,7 @@ public: void importAsset(const std::filesystem::path& name); PMaterialAsset getPlaceHolderMaterial(); private: - Job import(std::filesystem::path filePath, PMaterialAsset asset); + void import(std::filesystem::path filePath, PMaterialAsset asset); Gfx::PGraphics graphics; List> futures; PMaterialAsset placeholderMaterial; diff --git a/src/Engine/Asset/TextureLoader.cpp b/src/Engine/Asset/TextureLoader.cpp index d030cd6..df4911c 100644 --- a/src/Engine/Asset/TextureLoader.cpp +++ b/src/Engine/Asset/TextureLoader.cpp @@ -38,7 +38,7 @@ PTextureAsset TextureLoader::getPlaceholderTexture() return placeholderAsset; } -Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset) +void TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset) { int x, y, n; unsigned char* data = stbi_load(path.string().c_str(), &x, &y, &n, 4); @@ -70,5 +70,5 @@ Job TextureLoader::import(std::filesystem::path path, PTextureAsset textureAsset textureAsset->load(); textureAsset->setStatus(Asset::Status::Ready); - co_return; + //co_return; } \ No newline at end of file diff --git a/src/Engine/Asset/TextureLoader.h b/src/Engine/Asset/TextureLoader.h index c268869..c49145f 100644 --- a/src/Engine/Asset/TextureLoader.h +++ b/src/Engine/Asset/TextureLoader.h @@ -19,7 +19,7 @@ public: void importAsset(const std::filesystem::path& filePath); PTextureAsset getPlaceholderTexture(); private: - Job import(std::filesystem::path path, PTextureAsset asset); + void import(std::filesystem::path path, PTextureAsset asset); Gfx::PGraphics graphics; List> futures; PTextureAsset placeholderAsset; diff --git a/src/Engine/CMakeLists.txt b/src/Engine/CMakeLists.txt index e13933a..0b39d31 100644 --- a/src/Engine/CMakeLists.txt +++ b/src/Engine/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE EngineTypes.h MinimalEngine.h diff --git a/src/Engine/Containers/Array.h b/src/Engine/Containers/Array.h index 1afc34d..8642ef5 100644 --- a/src/Engine/Containers/Array.h +++ b/src/Engine/Containers/Array.h @@ -320,7 +320,7 @@ public: { remove(it - beginIt, keepOrder); } - constexpr void remove(int index, bool keepOrder = true) + constexpr void remove(size_type index, bool keepOrder = true) { if (keepOrder) { @@ -333,7 +333,7 @@ public: { _data[index] = std::move(_data[arraySize - 1]); } - arraySize--; + std::allocator_traits::destroy(allocator, &_data[--arraySize]); markIteratorDirty(); } constexpr void resize(size_type newSize) diff --git a/src/Engine/Containers/CMakeLists.txt b/src/Engine/Containers/CMakeLists.txt index 93a7932..9e81f08 100644 --- a/src/Engine/Containers/CMakeLists.txt +++ b/src/Engine/Containers/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Array.h Map.h diff --git a/src/Engine/Graphics/CMakeLists.txt b/src/Engine/Graphics/CMakeLists.txt index 07b9db9..608fc3b 100644 --- a/src/Engine/Graphics/CMakeLists.txt +++ b/src/Engine/Graphics/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE GraphicsResources.h GraphicsResources.cpp diff --git a/src/Engine/Graphics/RenderPass/BasePass.cpp b/src/Engine/Graphics/RenderPass/BasePass.cpp index 5fbd58c..dc1393e 100644 --- a/src/Engine/Graphics/RenderPass/BasePass.cpp +++ b/src/Engine/Graphics/RenderPass/BasePass.cpp @@ -134,6 +134,7 @@ MainJob BasePass::beginFrame() descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); + //std::cout << "BasePass beginFrame()" << std::endl; co_return; } @@ -163,11 +164,13 @@ MainJob BasePass::render() //co_await Job::all(jobs); graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); + //std::cout << "BasePass render()" << std::endl; co_return; } MainJob BasePass::endFrame() { + //std::cout << "BasePass endFrame()" << std::endl; co_return; } diff --git a/src/Engine/Graphics/RenderPass/CMakeLists.txt b/src/Engine/Graphics/RenderPass/CMakeLists.txt index 91a07fb..944ec7d 100644 --- a/src/Engine/Graphics/RenderPass/CMakeLists.txt +++ b/src/Engine/Graphics/RenderPass/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE BasePass.h BasePass.cpp diff --git a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp index a4bc161..5243a39 100644 --- a/src/Engine/Graphics/RenderPass/DepthPrepass.cpp +++ b/src/Engine/Graphics/RenderPass/DepthPrepass.cpp @@ -115,6 +115,7 @@ MainJob DepthPrepass::beginFrame() descriptorSets[INDEX_VIEW_PARAMS] = viewLayout->allocateDescriptorSet(); descriptorSets[INDEX_VIEW_PARAMS]->updateBuffer(0, viewParamBuffer); descriptorSets[INDEX_VIEW_PARAMS]->writeChanges(); + //std::cout << "DepthPrepass beginFrame()" << std::endl; co_return; } @@ -134,11 +135,13 @@ MainJob DepthPrepass::render() //co_await Job::all(jobs); graphics->executeCommands(processor->getRenderCommands()); graphics->endRenderPass(); + //std::cout << "DepthPrepass render()" << std::endl; co_return; } MainJob DepthPrepass::endFrame() { + //std::cout << "DepthPrepass endFrame()" << std::endl; co_return; } diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp index b05764d..1f20035 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.cpp +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.cpp @@ -75,7 +75,7 @@ MainJob LightCullingPass::beginFrame() lightEnvDescriptorSet->updateBuffer(2, pointLightBuffer); lightEnvDescriptorSet->updateBuffer(3, numPointLightBuffer); lightEnvDescriptorSet->writeChanges(); - //std::cout << "Finished light culling beginFrame()" << std::endl; + //std::cout << "LightCulling beginFrame()" << std::endl; co_return; } @@ -103,11 +103,13 @@ MainJob LightCullingPass::render() graphics->executeCommands(commands); depthAttachment->changeLayout(Gfx::SE_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); depthAttachment->transferOwnership(Gfx::QueueType::GRAPHICS); + //std::cout << "LightCulling render()" << std::endl; co_return; } MainJob LightCullingPass::endFrame() { + //std::cout << "LightCulling endFrame()" << std::endl; co_return; } diff --git a/src/Engine/Graphics/RenderPass/LightCullingPass.h b/src/Engine/Graphics/RenderPass/LightCullingPass.h index 1d8ea7f..a0ceef6 100644 --- a/src/Engine/Graphics/RenderPass/LightCullingPass.h +++ b/src/Engine/Graphics/RenderPass/LightCullingPass.h @@ -26,7 +26,7 @@ public: static void modifyRenderPassMacros(Map& defines); private: void setupFrustums(); - static constexpr uint32 BLOCK_SIZE = 8; + static constexpr uint32 BLOCK_SIZE = 32; static constexpr uint32 INDEX_LIGHT_ENV = 1; struct DispatchParams { @@ -39,9 +39,6 @@ private: { Vector n; float d; - Vector p0; - Vector p1; - Vector p2; }; struct Frustum { diff --git a/src/Engine/Graphics/Vulkan/CMakeLists.txt b/src/Engine/Graphics/Vulkan/CMakeLists.txt index c151a8b..bf2f494 100644 --- a/src/Engine/Graphics/Vulkan/CMakeLists.txt +++ b/src/Engine/Graphics/Vulkan/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE NsightAftermathGpuCrashTracker.h NsightAftermathGpuCrashTracker.cpp diff --git a/src/Engine/Graphics/Vulkan/VulkanAllocator.h b/src/Engine/Graphics/Vulkan/VulkanAllocator.h index b23eb8d..2c911a6 100644 --- a/src/Engine/Graphics/Vulkan/VulkanAllocator.h +++ b/src/Engine/Graphics/Vulkan/VulkanAllocator.h @@ -146,7 +146,7 @@ public: private: enum { - MemoryBlockSize = 64 * 1024 * 1024 // 64MB + MemoryBlockSize = 16 * 1024 * 1024 // 16MB }; struct HeapInfo { diff --git a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp index 9096b7e..003eb7b 100644 --- a/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp +++ b/src/Engine/Graphics/Vulkan/VulkanGraphics.cpp @@ -332,7 +332,7 @@ PCommandBufferManager Graphics::getTransferCommands() } PCommandBufferManager Graphics::getDedicatedTransferCommands() { - if(dedicatedTransferCommands == dedicatedTransferCommands) + if(dedicatedTransferCommands == nullptr) { dedicatedTransferCommands = new CommandBufferManager(this, dedicatedTransferQueue); } diff --git a/src/Engine/Material/CMakeLists.txt b/src/Engine/Material/CMakeLists.txt index fa0ad1a..34244ca 100644 --- a/src/Engine/Material/CMakeLists.txt +++ b/src/Engine/Material/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE BRDF.h BRDF.cpp diff --git a/src/Engine/Math/CMakeLists.txt b/src/Engine/Math/CMakeLists.txt index dc535d0..9d34470 100644 --- a/src/Engine/Math/CMakeLists.txt +++ b/src/Engine/Math/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Math.h Matrix.h diff --git a/src/Engine/Scene/Actor/CMakeLists.txt b/src/Engine/Scene/Actor/CMakeLists.txt index 85f3357..abb8a77 100644 --- a/src/Engine/Scene/Actor/CMakeLists.txt +++ b/src/Engine/Scene/Actor/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Actor.cpp Actor.h diff --git a/src/Engine/Scene/CMakeLists.txt b/src/Engine/Scene/CMakeLists.txt index 1d102c6..d03c311 100644 --- a/src/Engine/Scene/CMakeLists.txt +++ b/src/Engine/Scene/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Util.h Scene.cpp diff --git a/src/Engine/Scene/Components/CMakeLists.txt b/src/Engine/Scene/Components/CMakeLists.txt index 15bd041..af9b210 100644 --- a/src/Engine/Scene/Components/CMakeLists.txt +++ b/src/Engine/Scene/Components/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE CameraComponent.h CameraComponent.cpp diff --git a/src/Engine/Scene/Components/MyOtherComponent.cpp b/src/Engine/Scene/Components/MyOtherComponent.cpp index e930585..3337028 100644 --- a/src/Engine/Scene/Components/MyOtherComponent.cpp +++ b/src/Engine/Scene/Components/MyOtherComponent.cpp @@ -4,7 +4,7 @@ using namespace Seele; Job MyOtherComponent::tick(float deltaTime) const { - std::cout << *data << std::endl; + //std::cout << *data << std::endl; co_return; } diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index 3cacb64..82680c9 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -19,13 +19,13 @@ Scene::Scene(Gfx::PGraphics graphics) lightEnv.directionalLights[0].intensity = Vector4(1, 1, 1, 1); lightEnv.numDirectionalLights = 1; srand((unsigned int)time(NULL)); - for(uint32 i = 0; i < 16; ++i) + for(uint32 i = 0; i < 256; ++i) { - lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 30); + lightEnv.pointLights[i].colorRange = Vector4(frand(), frand(), frand(), frand() * 300); lightEnv.pointLights[i].positionWS = Vector4(frand() * 100-50, frand(), frand() * 100-50, 1); } - lightEnv.numPointLights = 16; - lightEnv.pointLights[0].colorRange = Vector4(1, 1, 1, 1000); + lightEnv.numPointLights = 256; + lightEnv.pointLights[0].colorRange = Vector4(1, 0, 1, 1000); lightEnv.pointLights[0].positionWS = Vector4(0, 10, 0, 1); } diff --git a/src/Engine/Scene/Scene.h b/src/Engine/Scene/Scene.h index cdd491e..25749e7 100644 --- a/src/Engine/Scene/Scene.h +++ b/src/Engine/Scene/Scene.h @@ -19,7 +19,6 @@ struct DirectionalLight struct PointLight { Vector4 positionWS; - Vector4 positionVS; Vector4 colorRange; }; @@ -46,7 +45,7 @@ public: const std::vector& getPrimitives() const { return primitives; } const std::vector& getStaticMeshes() const { return staticMeshes; } - const LightEnv& getLightBuffer() const { return lightEnv; } + LightEnv& getLightBuffer() { return lightEnv; } private: std::vector staticMeshes; std::vector rootActors; diff --git a/src/Engine/ThreadPool.h b/src/Engine/ThreadPool.h index fa74056..5e36630 100644 --- a/src/Engine/ThreadPool.h +++ b/src/Engine/ThreadPool.h @@ -4,6 +4,7 @@ #include "MinimalEngine.h" #include "Containers/List.h" #include "Concepts.h" +#include namespace Seele { @@ -66,11 +67,11 @@ struct JobPromiseBase EXECUTING, DONE }; - JobPromiseBase() + JobPromiseBase(const std::source_location& location = std::source_location::current()) { handle = std::coroutine_handle>::from_promise(*this); id = globalCounter++; - finishedEvent = Event(std::format("Job {}", id)); + finishedEvent = Event(std::string(location.file_name()).append(": ").append(location.function_name())); } ~JobPromiseBase() {} @@ -101,6 +102,7 @@ struct JobPromiseBase finishedEvent.raise(); if(continuation) { + std::scoped_lock lock(continuation->promiseLock); getGlobalThreadPool().scheduleJob(continuation); continuation->removeRef(); } @@ -108,6 +110,7 @@ struct JobPromiseBase void setContinuation(JobPromiseBase* cont) { std::scoped_lock lock(promiseLock, cont->promiseLock); + assert(cont->ready()); continuation = cont; cont->state = State::SCHEDULED; cont->addRef(); @@ -148,12 +151,12 @@ struct JobPromiseBase } void schedule() { - //dont lock here, as it is already locked from outside std::scoped_lock lock(promiseLock); if(!handle || done() || !ready()) { return; } + state = State::SCHEDULED; getGlobalThreadPool().scheduleJob(this); } void addRef() @@ -243,6 +246,7 @@ public: JobBase&& then(JobBase&& continuation) { promise->setContinuation(continuation.promise); + promise->schedule(); return std::move(continuation); } bool done() @@ -253,19 +257,12 @@ public: { promise->finalize(); } - Event operator co_await() + Event operator co_await() const { - Event result = promise->finishedEvent; - // if we schedule the promise now, it might finish and self destruct - // but there is no way for us to know that - // but as the co_await operator keeps a reference to this, we it won't + // the co_await operator keeps a reference to this, we it won't // be scheduled from the destructor promise->schedule(); - // so we reset the promise so we don't schedule it when this destructs - promise->removeRef(); - promise = nullptr; - // but we still have to provide with the event, so we get that first - return result; + return promise->finishedEvent; } static JobBase all() = delete; template diff --git a/src/Engine/UI/CMakeLists.txt b/src/Engine/UI/CMakeLists.txt index 749ede4..c1bb37c 100644 --- a/src/Engine/UI/CMakeLists.txt +++ b/src/Engine/UI/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE HorizontalLayout.h HorizontalLayout.cpp diff --git a/src/Engine/UI/Elements/CMakeLists.txt b/src/Engine/UI/Elements/CMakeLists.txt index aba5a85..cf0bd4f 100644 --- a/src/Engine/UI/Elements/CMakeLists.txt +++ b/src/Engine/UI/Elements/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE Element.h Element.cpp) \ No newline at end of file diff --git a/src/Engine/Window/CMakeLists.txt b/src/Engine/Window/CMakeLists.txt index 1e58520..c45a567 100644 --- a/src/Engine/Window/CMakeLists.txt +++ b/src/Engine/Window/CMakeLists.txt @@ -1,4 +1,4 @@ -target_sources(SeeleEngine +target_sources(Engine PRIVATE InspectorView.h InspectorView.cpp diff --git a/src/Engine/Window/InspectorView.cpp b/src/Engine/Window/InspectorView.cpp index 4f954bb..aaa4df9 100644 --- a/src/Engine/Window/InspectorView.cpp +++ b/src/Engine/Window/InspectorView.cpp @@ -41,11 +41,9 @@ void InspectorView::prepareRender() MainJob InspectorView::render() { - co_await uiPass.beginFrame(); - co_await uiPass.render(); - co_await uiPass.endFrame(); - renderFinishedEvent.raise(); - co_return; + return uiPass.beginFrame() + .then(uiPass.render()) + .then(uiPass.endFrame()); } void InspectorView::keyCallback(KeyCode, InputAction, KeyModifier) diff --git a/src/Engine/Window/SceneView.cpp b/src/Engine/Window/SceneView.cpp index c59ca9b..dce72ce 100644 --- a/src/Engine/Window/SceneView.cpp +++ b/src/Engine/Window/SceneView.cpp @@ -34,7 +34,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); ayaka->addWorldTranslation(Vector(0, 0, 0)); ayaka->setWorldScale(Vector(10, 10, 10)); - scene->addPrimitiveComponent(ayaka); + //scene->addPrimitiveComponent(ayaka); PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane")); plane->setWorldScale(Vector(100, 100, 100)); @@ -97,17 +97,19 @@ void SceneView::prepareRender() MainJob SceneView::render() { - co_await depthPrepass.beginFrame(); - co_await lightCullingPass.beginFrame(); - co_await basePass.beginFrame(); - co_await depthPrepass.render(); - co_await lightCullingPass.render(); - co_await basePass.render(); - co_await depthPrepass.endFrame(); - co_await lightCullingPass.endFrame(); - co_await basePass.endFrame(); - renderFinishedEvent.raise(); - co_return; + return MainJob::all( + depthPrepass.beginFrame(), + lightCullingPass.beginFrame(), + basePass.beginFrame()) + .then(depthPrepass.render()) + .then(lightCullingPass.render()) + .then(basePass.render()) + .then( + MainJob::all( + depthPrepass.endFrame(), + lightCullingPass.endFrame(), + basePass.endFrame()) + ); } void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier) diff --git a/src/Engine/Window/View.cpp b/src/Engine/Window/View.cpp index be8fa24..e2c9b81 100644 --- a/src/Engine/Window/View.cpp +++ b/src/Engine/Window/View.cpp @@ -8,7 +8,6 @@ View::View(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo &vi : graphics(graphics) , owner(window) , name(name) - , renderFinishedEvent(std::format("{}RenderFinished", name)) { viewport = graphics->createViewport(owner->getGfxHandle(), viewportInfo); } diff --git a/src/Engine/Window/View.h b/src/Engine/Window/View.h index 79eb0ad..948f908 100644 --- a/src/Engine/Window/View.h +++ b/src/Engine/Window/View.h @@ -24,15 +24,12 @@ public: virtual MainJob render() = 0; void applyArea(URect area); void setFocused(); - Event renderFinished() { return renderFinishedEvent; } - void resetRender() { renderFinishedEvent.reset(); } protected: Gfx::PGraphics graphics; Gfx::PViewport viewport; PWindow owner; std::string name; - Event renderFinishedEvent; virtual void keyCallback(KeyCode code, InputAction action, KeyModifier modifier) = 0; virtual void mouseMoveCallback(double xPos, double yPos) = 0; diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index 1719101..49775ef 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -27,21 +27,16 @@ void Window::addView(PView view) MainJob Window::render() { gfxHandle->beginFrame(); + Array jobs; for(auto& windowView : views) { - co_await windowView->updateFinished; - windowView->updateFinished.reset(); { std::scoped_lock lock(windowView->workerMutex); windowView->view->prepareRender(); } - windowView->view->render(); - } - for(auto& windowView : views) - { - co_await windowView->view->renderFinished(); - windowView->view->resetRender(); + jobs.add(windowView->view->render()); } + co_await MainJob::all(jobs); gfxHandle->endFrame(); if(owner->isActive()) { @@ -82,8 +77,11 @@ Job Window::viewWorker(size_t viewIndex) windowView->view->commitUpdate(); } //std::cout << "Update completed" << std::endl; - windowView->updateFinished.raise(); + //windowView->updateFinished.raise(); // enqueue next frame update - viewWorker(viewIndex); + if(owner->isActive()) + { + viewWorker(viewIndex); + } co_return; } diff --git a/src/Engine/Window/WindowManager.cpp b/src/Engine/Window/WindowManager.cpp index 57447e8..762184f 100644 --- a/src/Engine/Window/WindowManager.cpp +++ b/src/Engine/Window/WindowManager.cpp @@ -41,7 +41,6 @@ void WindowManager::notifyWindowClosed(PWindow window) windows.remove(windows.find(window)); if(windows.empty()) { - std::scoped_lock lock(windowsLock); - windowsCV.notify_all(); + getGlobalThreadPool().cleanup(); } } diff --git a/src/Engine/Window/WindowManager.h b/src/Engine/Window/WindowManager.h index 83014b8..e0de7f1 100644 --- a/src/Engine/Window/WindowManager.h +++ b/src/Engine/Window/WindowManager.h @@ -22,16 +22,9 @@ public: { return windows.size(); } - void waitForCompletion() - { - std::unique_lock lock(windowsLock); - windowsCV.wait(lock); - } private: Array windows; - std::mutex windowsLock; - std::condition_variable windowsCV; static Gfx::PGraphics graphics; }; DEFINE_REF(WindowManager) diff --git a/test/Engine/ThreadPool.cpp b/test/Engine/ThreadPool.cpp index bc72248..e3c9d7b 100644 --- a/test/Engine/ThreadPool.cpp +++ b/test/Engine/ThreadPool.cpp @@ -93,18 +93,15 @@ uint64 basicAllState2 = 0; Job basicAllFirst() { basicAllState1 = 10; - std::cout << "AllFirst" << std::endl; co_return; } Job basicAllSecond() { basicAllState2 = 10; - std::cout << "AllSecond" << std::endl; co_return; } Job basicAllThen() { - std::cout << "AllThen" << std::endl; BOOST_REQUIRE_EQUAL(basicAllState1, 10); BOOST_REQUIRE_EQUAL(basicAllState2, 10); co_return; @@ -129,7 +126,6 @@ BOOST_AUTO_TEST_CASE(basic_callable) .then([=]() -> Job { BOOST_REQUIRE_EQUAL(basicCallable, 10); - std::cout << "callable" << std::endl; co_return; }); }