From d903f487d479cf5b21927f029f44d6fa6fce932d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=B6gler?= Date: Sat, 26 Mar 2022 16:15:50 +0100 Subject: [PATCH] Linux fixes --- .gitmodules | 5 +- .vscode/launch.json | 2 + external/ktx | 1 - src/Engine/Graphics/GraphicsInitializer.h | 2 +- src/Engine/Graphics/MeshBatch.cpp | 4 +- src/Engine/Scene/Actor/Actor.h | 2 +- .../Scene/Components/CameraComponent.cpp | 2 +- src/Engine/Scene/Components/Component.h | 2 +- src/Engine/Scene/Components/MyComponent.cpp | 2 +- .../Scene/Components/MyOtherComponent.cpp | 2 +- src/Engine/Scene/Util.h | 4 +- src/Engine/ThreadPool.cpp | 14 ++- src/Engine/ThreadPool.h | 119 +++++++++--------- src/Engine/Window/SceneView.cpp | 4 +- test/Engine/EngineTest.h | 2 +- 15 files changed, 87 insertions(+), 80 deletions(-) delete mode 160000 external/ktx diff --git a/.gitmodules b/.gitmodules index 2d2c4a8..06e2d0b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,9 +13,6 @@ [submodule "external/SPIRV-Cross"] path = external/SPIRV-Cross url = https://github.com/KhronosGroup/SPIRV-Cross.git -[submodule "external/ktx"] - path = external/ktx - url = https://github.com/KhronosGroup/KTX-Software [submodule "external/stb"] path = external/stb url = https://github.com/nothings/stb @@ -24,4 +21,4 @@ url = https://github.com/shader-slang/slang.git [submodule "external/boost"] path = external/boost - url = https://github.com/boostorg/boost + url = https://github.com/boostorg/boost \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index 017e737..e1e2380 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,6 +13,7 @@ "stopAtEntry": false, "cwd": "${workspaceRoot}/bin/Debug", "console": "integratedTerminal", + "visualizerFile": "${workspaceRoot}/Seele.natvis", "environment": [], "externalConsole": false, "setupCommands": [ @@ -73,6 +74,7 @@ "console": "integratedTerminal", "cwd": "${workspaceRoot}/bin/Debug", "environment": [], + "visualizerFile": "${workspaceRoot}/Seele.natvis" }, { "name": "Test", diff --git a/external/ktx b/external/ktx deleted file mode 160000 index a2ccc90..0000000 --- a/external/ktx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a2ccc90effc8a5831a271ea033a9e38e26e63a59 diff --git a/src/Engine/Graphics/GraphicsInitializer.h b/src/Engine/Graphics/GraphicsInitializer.h index 1c3c1f3..ba0cab6 100644 --- a/src/Engine/Graphics/GraphicsInitializer.h +++ b/src/Engine/Graphics/GraphicsInitializer.h @@ -23,7 +23,7 @@ struct GraphicsInitializer : applicationName("SeeleEngine") , engineName("SeeleEngine") , windowLayoutFile(nullptr) - , layers{"VK_LAYER_KHRONOS_validation", "VK_LAYER_LUNARG_monitor"} + , layers{} , instanceExtensions{} , deviceExtensions{"VK_KHR_swapchain"} , windowHandle(nullptr) diff --git a/src/Engine/Graphics/MeshBatch.cpp b/src/Engine/Graphics/MeshBatch.cpp index 745dfa0..ce1458d 100644 --- a/src/Engine/Graphics/MeshBatch.cpp +++ b/src/Engine/Graphics/MeshBatch.cpp @@ -17,13 +17,13 @@ MeshBatchElement::MeshBatchElement() , indirectArgsBuffer(nullptr) {} MeshBatch::MeshBatch() - : useReverseCulling(false) + : elements() + , useReverseCulling(false) , isBackfaceCullingDisabled(false) , isCastingShadow(true) , useWireframe(false) , topology(Gfx::SE_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) , vertexInput(nullptr) , material(nullptr) - , elements() { } \ No newline at end of file diff --git a/src/Engine/Scene/Actor/Actor.h b/src/Engine/Scene/Actor/Actor.h index b75164c..e257ab2 100644 --- a/src/Engine/Scene/Actor/Actor.h +++ b/src/Engine/Scene/Actor/Actor.h @@ -16,7 +16,7 @@ public: virtual void launchStart(); virtual void start() {} Array launchTick(float deltaTime) const; - virtual Job tick(float deltaTime) const { co_return; } + virtual Job tick(float) const { co_return; } Array launchUpdate(); virtual Job update() { co_return; } void notifySceneAttach(PScene scene); diff --git a/src/Engine/Scene/Components/CameraComponent.cpp b/src/Engine/Scene/Components/CameraComponent.cpp index 17a4669..d7c98a9 100644 --- a/src/Engine/Scene/Components/CameraComponent.cpp +++ b/src/Engine/Scene/Components/CameraComponent.cpp @@ -10,8 +10,8 @@ CameraComponent::CameraComponent() , fieldOfView(0) , bNeedsViewBuild(true) , bNeedsProjectionBuild(true) - , projectionMatrix(Matrix4()) , viewMatrix(Matrix4()) + , projectionMatrix(Matrix4()) { yaw = 0; pitch = 0; diff --git a/src/Engine/Scene/Components/Component.h b/src/Engine/Scene/Components/Component.h index e157548..c00f660 100644 --- a/src/Engine/Scene/Components/Component.h +++ b/src/Engine/Scene/Components/Component.h @@ -17,7 +17,7 @@ public: void launchStart(); virtual void start() {}; Array launchTick(float deltaTime) const; - virtual Job tick(float deltaTime) const { co_return; } + virtual Job tick(float) const { co_return; } Array launchUpdate(); virtual Job update() { co_return; } PComponent getParent(); diff --git a/src/Engine/Scene/Components/MyComponent.cpp b/src/Engine/Scene/Components/MyComponent.cpp index 5a607b0..5e5cf4c 100644 --- a/src/Engine/Scene/Components/MyComponent.cpp +++ b/src/Engine/Scene/Components/MyComponent.cpp @@ -12,7 +12,7 @@ void MyComponent::start() otherComp.update(); } -Job MyComponent::tick(float deltatime) const +Job MyComponent::tick(float) const { //std::cout << "MyComponent::tick" << std::endl; ++writable; diff --git a/src/Engine/Scene/Components/MyOtherComponent.cpp b/src/Engine/Scene/Components/MyOtherComponent.cpp index 3337028..ba13385 100644 --- a/src/Engine/Scene/Components/MyOtherComponent.cpp +++ b/src/Engine/Scene/Components/MyOtherComponent.cpp @@ -2,7 +2,7 @@ using namespace Seele; -Job MyOtherComponent::tick(float deltaTime) const +Job MyOtherComponent::tick(float) const { //std::cout << *data << std::endl; co_return; diff --git a/src/Engine/Scene/Util.h b/src/Engine/Scene/Util.h index ca47268..cccc89a 100644 --- a/src/Engine/Scene/Util.h +++ b/src/Engine/Scene/Util.h @@ -10,8 +10,8 @@ public: Writable() {} Writable(T initialData) - : data(initialData) - , toBeWritten(initialData) + : toBeWritten(initialData) + , data(initialData) {} Writable(const Writable& other) = delete; Writable(Writable&& other) = default; diff --git a/src/Engine/ThreadPool.cpp b/src/Engine/ThreadPool.cpp index cb2a774..b21086d 100644 --- a/src/Engine/ThreadPool.cpp +++ b/src/Engine/ThreadPool.cpp @@ -13,18 +13,20 @@ Event::Event(nullptr_t) Event::Event(const std::string &name, const std::source_location &location) : name(name) , location(location) + , eventLock(std::make_unique()) { } Event::Event(const std::source_location &location) : name(location.function_name()) , location(location) + , eventLock(std::make_unique()) { } void Event::raise() { - std::scoped_lock lock(eventLock); + std::scoped_lock lock(*eventLock); data = true; if(waitingJobs.size() > 0) { @@ -37,17 +39,17 @@ void Event::raise() } void Event::reset() { - std::scoped_lock lock(eventLock); + std::scoped_lock lock(*eventLock); data = false; } bool Event::await_ready() { - eventLock.lock(); + eventLock->lock(); bool result = data; if(result) { - eventLock.unlock(); + eventLock->unlock(); } return result; } @@ -56,14 +58,14 @@ void Event::await_suspend(std::coroutine_handle> h) { //h.promise().enqueue(this); waitingJobs.add(JobBase(&h.promise())); - eventLock.unlock(); + eventLock->unlock(); } void Event::await_suspend(std::coroutine_handle> h) { //h.promise().enqueue(this); waitingMainJobs.add(JobBase(&h.promise())); - eventLock.unlock(); + eventLock->unlock(); } ThreadPool::ThreadPool(uint32 threadCount) diff --git a/src/Engine/ThreadPool.h b/src/Engine/ThreadPool.h index 997e8f7..765a97a 100644 --- a/src/Engine/ThreadPool.h +++ b/src/Engine/ThreadPool.h @@ -34,7 +34,7 @@ public: } operator bool() { - std::scoped_lock lock(eventLock); + std::scoped_lock lock(*eventLock); return data; } @@ -58,9 +58,9 @@ public: void await_suspend(std::coroutine_handle> h); constexpr void await_resume() {} private: - std::mutex eventLock; std::string name; std::source_location location; + std::unique_ptr eventLock; bool data = false; Array> waitingJobs; Array> waitingMainJobs; @@ -120,16 +120,6 @@ struct JobPromiseBase state = State::EXECUTING; handle.resume(); } - void markDone() - { - state = State::DONE; - finishedEvent.raise(); - if(continuation) - { - getGlobalThreadPool().scheduleJob(JobBase(continuation)); - continuation->removeRef(); - } - } void setContinuation(JobPromiseBase* cont) { assert(cont->ready()); @@ -158,26 +148,8 @@ struct JobPromiseBase { return state == State::READY; } - void enqueue(Event* event) - { - if(!handle || handle.done() || waiting() || scheduled()) - { - return; - } - state = State::WAITING; - waitingFor = event; - getGlobalThreadPool().enqueueWaiting(event, std::move(JobBase(this))); - } - bool schedule() - { - if(!handle || done() || !ready()) - { - return false; - } - state = State::SCHEDULED; - getGlobalThreadPool().scheduleJob(std::move(JobBase(this))); - return true; - } + void enqueue(Event* event); + bool schedule(); void addRef() { numRefs++; @@ -290,15 +262,8 @@ public: } static JobBase all() = delete; template - requires std::same_as, JobBase> - static JobBase all(Iterable collection) - { - getGlobalThreadPool().scheduleBatch(collection); - for(auto it : collection) - { - co_await it; - } - } + requires std::same_as, JobBase> + static JobBase all(Iterable collection); template static JobBase all(Iterable collection) { @@ -314,19 +279,7 @@ public: } template requires std::invocable> - static JobBase launchJobs(JobFunc&& func, Iterable params) - { - Array jobs; - for(auto&& param : params) - { - jobs.add(func(param)); - } - getGlobalThreadPool().scheduleBatch(jobs); - for(auto job : jobs) - { - co_await job; - } - } + static JobBase launchJobs(JobFunc&& func, Iterable params); private: JobPromiseBase* promise; friend class ThreadPool; @@ -407,8 +360,62 @@ inline auto JobPromiseBase::initial_suspend() noexcept template inline auto JobPromiseBase::final_suspend() noexcept { - markDone(); + state = State::DONE; + finishedEvent.raise(); + if(continuation) + { + getGlobalThreadPool().scheduleJob(JobBase(continuation)); + continuation->removeRef(); + } return std::suspend_always{}; } - +//template +//inline void JobPromiseBase::enqueue(Event* event) +//{ +// if(!handle || handle.done() || waiting() || scheduled()) +// { +// return; +// } +// state = State::WAITING; +// waitingFor = event; +// getGlobalThreadPool().enqueueWaiting(event, std::move(JobBase(this))); +//} +template +inline bool JobPromiseBase::schedule() +{ + if(!handle || done() || !ready()) + { + return false; + } + state = State::SCHEDULED; + getGlobalThreadPool().scheduleJob(std::move(JobBase(this))); + return true; +} +template +template +requires std::same_as, JobBase> +inline JobBase JobBase::all(Iterable collection) +{ + getGlobalThreadPool().scheduleBatch(collection); + for(auto it : collection) + { + co_await it; + } +} +template +template +requires std::invocable> +inline JobBase JobBase::launchJobs(JobFunc&& func, Iterable params) +{ + Array> jobs; + for(auto&& param : params) + { + jobs.add(func(param)); + } + getGlobalThreadPool().scheduleBatch(jobs); + for(auto job : jobs) + { + co_await job; + } +} } // namespace Seele diff --git a/src/Engine/Window/SceneView.cpp b/src/Engine/Window/SceneView.cpp index 468f30d..67769a3 100644 --- a/src/Engine/Window/SceneView.cpp +++ b/src/Engine/Window/SceneView.cpp @@ -28,8 +28,8 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo AssetRegistry::importFile("/home/dynamitos/TestSeeleProject/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png"); AssetRegistry::importFile("/home/dynamitos/TestSeeleProject/Assets/Ayaka/Ayaka.fbx"); PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); - ayaka->addWorldTranslation(Vector(0, 0, 0)); - ayaka->setWorldScale(Vector(10, 10, 10)); + ayaka->setRelativeLocation(Vector(0, 0, 0)); + ayaka->setRelativeScale(Vector(10, 10, 10)); scene->addPrimitiveComponent(ayaka); //AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx"); diff --git a/test/Engine/EngineTest.h b/test/Engine/EngineTest.h index 9b55478..e90ce6b 100644 --- a/test/Engine/EngineTest.h +++ b/test/Engine/EngineTest.h @@ -1,5 +1,5 @@ #pragma once -#include +//#include namespace Seele {