├── .clang-format ├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── CMakeSettings.json ├── Examples ├── CMakeLists.txt └── SoulInfo │ ├── CMakeLists.txt │ └── Source │ ├── CMakeLists.txt │ ├── SoulInfo.cpp │ └── SoulInfo.h ├── Includes ├── Property.h ├── Soul.h ├── SoulApplication.h ├── SoulParameters.h ├── Types.h └── WindowParameters.h ├── LICENSE.txt ├── Modules └── README.md ├── README.md ├── Resources ├── Documents │ └── Wiki │ │ ├── Getting-Started.md │ │ ├── Home.md │ │ ├── How-to-Use.md │ │ ├── Memory-Allocator.md │ │ ├── Roadmap.md │ │ └── _Sidebar.md ├── Images │ └── Tree.png └── Shaders │ ├── compile.bat │ ├── frag.spv │ ├── fragment-shader[Renderer].glsl │ ├── simpleShader.frag │ ├── simpleShader.vert │ ├── vert.spv │ └── vertex-shader[Renderer].glsl ├── Setup.py ├── Source ├── Audio │ ├── AudioManager.cpp │ ├── AudioManager.h │ └── CMakeLists.txt ├── Compute │ ├── CMakeLists.txt │ ├── ComputeBackend.h │ ├── ComputeBuffer.cpp │ ├── ComputeBuffer.h │ ├── ComputeDevice.h │ ├── ComputeModule.cpp │ ├── ComputeModule.h │ ├── ComputePolicy.cpp │ ├── ComputePolicy.h │ ├── DeviceBuffer.cpp │ ├── DeviceBuffer.h │ └── Modules │ │ ├── CMakeLists.txt │ │ ├── CPU │ │ ├── CMakeLists.txt │ │ ├── CPUBackend.cpp │ │ ├── CPUBackend.h │ │ ├── CPUBuffer.cpp │ │ ├── CPUBuffer.h │ │ ├── CPUDevice.cpp │ │ └── CPUDevice.h │ │ ├── CUDA │ │ ├── CMakeLists.txt │ │ ├── CUDABackend.cpp │ │ ├── CUDABackend.h │ │ ├── CUDABuffer.cpp │ │ ├── CUDABuffer.h │ │ ├── CUDADevice.cpp │ │ └── CUDADevice.h │ │ ├── Mock │ │ ├── CMakeLists.txt │ │ ├── MockBackend.cpp │ │ ├── MockBackend.h │ │ ├── MockBuffer.cpp │ │ ├── MockBuffer.h │ │ ├── MockDevice.cpp │ │ └── MockDevice.h │ │ └── OpenCL │ │ ├── CMakeLists.txt │ │ ├── OpenCLBackend.cpp │ │ ├── OpenCLBackend.h │ │ ├── OpenCLBuffer.cpp │ │ ├── OpenCLBuffer.h │ │ ├── OpenCLDevice.cpp │ │ └── OpenCLDevice.h ├── Core │ ├── CMakeLists.txt │ ├── Composition │ │ ├── Component │ │ │ └── Component.h │ │ ├── Entity │ │ │ ├── Entity.cpp │ │ │ ├── Entity.h │ │ │ ├── EntityRegistry.cpp │ │ │ └── EntityRegistry.h │ │ └── Event │ │ │ ├── Event.h │ │ │ ├── EventRegistry.cpp │ │ │ └── EventRegistry.h │ ├── Frame │ │ ├── Frame.cpp │ │ ├── Frame.h │ │ └── FramePipeline.h │ ├── Geometry │ │ ├── BoundingBox.cpp │ │ ├── BoundingBox.h │ │ ├── Face.cpp │ │ ├── Face.h │ │ ├── Tet.cpp │ │ ├── Tet.h │ │ ├── Vertex.cpp │ │ └── Vertex.h │ ├── Interface │ │ ├── Application │ │ │ └── SoulApplication.cpp │ │ ├── Module │ │ │ ├── DESIGN.rst │ │ │ └── Module.h │ │ └── Project │ │ │ ├── Project.cpp │ │ │ └── Project.h │ ├── Material │ │ ├── CUDA │ │ │ ├── ShaderNode.cu │ │ │ └── ShaderNode.cuh │ │ ├── Colour │ │ │ ├── CUDA │ │ │ │ ├── Colour.cu │ │ │ │ └── Colour.cuh │ │ │ └── Colour.h │ │ ├── Material.cpp │ │ ├── Material.h │ │ ├── ShaderNode.h │ │ └── Texture │ │ │ ├── Image.cu │ │ │ └── Image.cuh │ ├── Object │ │ ├── CUDA │ │ │ ├── Object.cu │ │ │ └── Object.cuh │ │ ├── Character │ │ │ ├── Character.cpp │ │ │ └── Character.h │ │ ├── Loader.cpp │ │ ├── Loader.h │ │ ├── Object.cpp │ │ └── Object.h │ ├── Scene │ │ ├── Scene.cpp │ │ ├── Scene.h │ │ ├── Sky.cpp │ │ └── Sky.h │ ├── Soul.cpp │ ├── Structure │ │ ├── Acceleration │ │ │ ├── CUDA │ │ │ │ ├── BVH.cu │ │ │ │ └── BVH.cuh │ │ │ ├── LBVHManager.cpp │ │ │ ├── LBVHManager.h │ │ │ ├── Node.cpp │ │ │ └── Node.h │ │ ├── External │ │ │ └── ExternalBuffer.h │ │ ├── ExternalStructure.h │ │ ├── RingBuffer.h │ │ ├── Span.h │ │ ├── Sparse │ │ │ ├── SparseArray.h │ │ │ ├── SparseBitMap.h │ │ │ ├── SparseHashMap.h │ │ │ ├── SparseHashSet.h │ │ │ └── SparseVector.h │ │ ├── SparseStructure.h │ │ ├── Structure.h │ │ ├── StructureConcepts.h │ │ └── View.h │ ├── System │ │ ├── Compiler.h │ │ └── Platform.h │ └── Utility │ │ ├── Exception │ │ └── Exception.h │ │ ├── Function │ │ ├── function_ref.cpp │ │ └── function_ref.h │ │ ├── HashString │ │ └── HashString.h │ │ ├── ID │ │ ├── ClassID.cpp │ │ ├── ClassID.h │ │ └── TypeID.h │ │ ├── Log │ │ ├── Logger.cpp │ │ └── Logger.h │ │ ├── Morton │ │ ├── CUDA │ │ │ ├── MortonCode.cu │ │ │ └── MortonCode.cuh │ │ └── MortonCode.h │ │ ├── Property │ │ └── Property.cpp │ │ ├── Template │ │ ├── CRTP.h │ │ ├── Optional.h │ │ └── TypeTraits.h │ │ ├── Thread │ │ ├── ThreadLocal.cpp │ │ └── ThreadLocal.h │ │ └── Timer │ │ ├── Timer.cpp │ │ └── Timer.h ├── DESIGN.rst ├── Display │ ├── GUI │ │ ├── CMakeLists.txt │ │ ├── GUIModule.cpp │ │ ├── GUIModule.h │ │ ├── Layout.h │ │ ├── Modules │ │ │ └── Imgui │ │ │ │ ├── EmptyWidget.h │ │ │ │ ├── ImguiBackend.cpp │ │ │ │ ├── ImguiBackend.h │ │ │ │ ├── ImguiConfig.h │ │ │ │ ├── ImguiLayout.cpp │ │ │ │ ├── ImguiLayout.h │ │ │ │ ├── ImguiWidget.cpp │ │ │ │ ├── ImguiWidget.h │ │ │ │ ├── RenderWidget.cu │ │ │ │ ├── RenderWidget.cuh │ │ │ │ ├── RenderWidget.h │ │ │ │ └── SingleLayout.h │ │ └── Widget.h │ ├── Input │ │ ├── Button.cpp │ │ ├── Button.h │ │ ├── CMakeLists.txt │ │ ├── InputModule.cpp │ │ ├── InputModule.h │ │ ├── InputSet.h │ │ └── Modules │ │ │ ├── GLFW │ │ │ ├── GLFWInputBackend.cpp │ │ │ └── GLFWInputBackend.h │ │ │ └── Mock │ │ │ ├── MockInputBackend.cpp │ │ │ └── MockInputBackend.h │ └── Window │ │ ├── CMakeLists.txt │ │ ├── Modules │ │ └── GLFW │ │ │ ├── GLFWMonitor.cpp │ │ │ ├── GLFWMonitor.h │ │ │ ├── GLFWWindow.cpp │ │ │ ├── GLFWWindow.h │ │ │ ├── GLFWWindowBackend.cpp │ │ │ └── GLFWWindowBackend.h │ │ ├── Monitor.h │ │ ├── Window.cpp │ │ ├── Window.h │ │ ├── WindowModule.cpp │ │ └── WindowModule.h ├── Memory │ ├── Allocator.cpp │ ├── Allocator.h │ ├── CMakeLists.txt │ ├── LinearAllocator.cpp │ ├── LinearAllocator.h │ └── TaggedAllocator │ │ ├── TaggedAllocator.cpp │ │ ├── TaggedAllocator.h │ │ ├── TaggedHeap.cpp │ │ └── TaggedHeap.h ├── Network │ ├── AbstractNetworkManager.cpp │ ├── AbstractNetworkManager.h │ ├── CMakeLists.txt │ ├── Client │ │ ├── Client.cpp │ │ └── Client.h │ ├── NetworkManager.cpp │ ├── NetworkManager.h │ └── Server │ │ ├── Server.cpp │ │ └── Server.h ├── Parallelism │ ├── Graph │ │ ├── CMakeLists.txt │ │ ├── Graph.h │ │ ├── GraphTask.h │ │ └── Modules │ │ │ └── EntityGraph │ │ │ ├── Graph.cpp │ │ │ ├── Graph.h │ │ │ ├── GraphNode.cpp │ │ │ ├── GraphNode.h │ │ │ ├── GraphTask.cpp │ │ │ └── GraphTask.h │ └── Scheduler │ │ ├── CMakeLists.txt │ │ ├── Modules │ │ ├── Dispatch │ │ │ ├── DispatchSchedulerBackend.cpp │ │ │ └── DispatchSchedulerBackend.h │ │ └── Fiber │ │ │ ├── FiberProperties.cpp │ │ │ ├── FiberProperties.h │ │ │ ├── FiberSchedulerAlgorithm.cpp │ │ │ ├── FiberSchedulerAlgorithm.h │ │ │ ├── FiberSchedulerBackend.cpp │ │ │ └── FiberSchedulerBackend.h │ │ ├── SchedulerModule.cpp │ │ ├── SchedulerModule.h │ │ ├── TaskParameters.cpp │ │ └── TaskParameters.h ├── Physics │ ├── CMakeLists.txt │ ├── CUDA │ │ ├── PhysicsEngine.cu │ │ └── PhysicsEngine.cuh │ └── PhysicsEngine.h ├── Render │ ├── Raster │ │ ├── CMakeLists.txt │ │ ├── CommandList.cpp │ │ ├── CommandList.h │ │ ├── Modules │ │ │ └── Vulkan │ │ │ │ ├── Buffer │ │ │ │ └── VulkanBuffer.h │ │ │ │ ├── Command │ │ │ │ ├── VulkanCommandBuffer.cpp │ │ │ │ ├── VulkanCommandBuffer.h │ │ │ │ ├── VulkanCommandPool.cpp │ │ │ │ └── VulkanCommandPool.h │ │ │ │ ├── Device │ │ │ │ ├── VulkanDevice.cpp │ │ │ │ ├── VulkanDevice.h │ │ │ │ ├── VulkanPhysicalDevice.cpp │ │ │ │ ├── VulkanPhysicalDevice.h │ │ │ │ ├── VulkanQueue.cpp │ │ │ │ └── VulkanQueue.h │ │ │ │ ├── Pipeline │ │ │ │ ├── VulkanPipeline.cpp │ │ │ │ ├── VulkanPipeline.h │ │ │ │ ├── VulkanPipelineCache.cpp │ │ │ │ ├── VulkanPipelineCache.h │ │ │ │ ├── VulkanPipelineLayout.cpp │ │ │ │ └── VulkanPipelineLayout.h │ │ │ │ ├── Surface │ │ │ │ ├── VulkanFrame.cpp │ │ │ │ ├── VulkanFrame.h │ │ │ │ ├── VulkanSurface.cpp │ │ │ │ ├── VulkanSurface.h │ │ │ │ ├── VulkanSwapChain.cpp │ │ │ │ └── VulkanSwapChain.h │ │ │ │ ├── VulkanFence.cpp │ │ │ │ ├── VulkanFence.h │ │ │ │ ├── VulkanFramebuffer.cpp │ │ │ │ ├── VulkanFramebuffer.h │ │ │ │ ├── VulkanInstance.cpp │ │ │ │ ├── VulkanInstance.h │ │ │ │ ├── VulkanRasterBackend.cpp │ │ │ │ ├── VulkanRasterBackend.h │ │ │ │ ├── VulkanRenderPass.cpp │ │ │ │ ├── VulkanRenderPass.h │ │ │ │ ├── VulkanSemaphore.cpp │ │ │ │ ├── VulkanSemaphore.h │ │ │ │ ├── VulkanShader.cpp │ │ │ │ ├── VulkanShader.h │ │ │ │ ├── VulkanSubPass.cpp │ │ │ │ └── VulkanSubPass.h │ │ ├── RasterDevice.h │ │ ├── RasterModule.cpp │ │ ├── RasterModule.h │ │ ├── RenderCommands.h │ │ ├── RenderResource.h │ │ └── RenderTypes.h │ └── RenderGraph │ │ ├── CMakeLists.txt │ │ ├── Modules │ │ └── Entity │ │ │ ├── EntityRenderGraphBackend.cpp │ │ │ └── EntityRenderGraphBackend.h │ │ ├── RenderGraphBuilder.cpp │ │ ├── RenderGraphBuilder.h │ │ ├── RenderGraphModule.cpp │ │ ├── RenderGraphModule.h │ │ ├── RenderGraphParameters.cpp │ │ └── RenderGraphParameters.h ├── Tracer │ ├── CMakeLists.txt │ ├── Camera │ │ ├── Camera.cpp │ │ ├── Camera.h │ │ ├── Film │ │ │ ├── Film.cpp │ │ │ ├── Film.h │ │ │ └── Filter │ │ │ │ ├── CUDA │ │ │ │ ├── Filter.cu │ │ │ │ └── Filter.cuh │ │ │ │ ├── Filter.cpp │ │ │ │ └── Filter.h │ │ └── Lens │ │ │ ├── CUDA │ │ │ ├── Lens.cu │ │ │ └── Lens.cuh │ │ │ └── Lens.h │ └── Ray │ │ ├── CUDA │ │ ├── RayEngine.cu │ │ └── RayEngine.cuh │ │ ├── OpenCL │ │ ├── CLRay.h │ │ ├── CLRayEngine.h │ │ └── CLRayJob.h │ │ ├── Ray.cpp │ │ ├── Ray.h │ │ ├── RayEngine.cpp │ │ ├── RayEngine.h │ │ ├── RayJob.cpp │ │ └── RayJob.h └── Transput │ └── Resource │ ├── Asset.cpp │ ├── Asset.h │ ├── CMakeLists.txt │ ├── Modules │ └── Shader │ │ ├── CMakeLists.txt │ │ ├── Modules │ │ └── SPIRV │ │ │ ├── SPIRVAsset.cpp │ │ │ ├── SPIRVAsset.h │ │ │ ├── SPIRVLoader.cpp │ │ │ ├── SPIRVLoader.h │ │ │ ├── SPIRVResource.cpp │ │ │ └── SPIRVResource.h │ │ ├── ShaderAsset.cpp │ │ ├── ShaderAsset.h │ │ ├── ShaderLoader.cpp │ │ ├── ShaderLoader.h │ │ ├── ShaderResource.cpp │ │ └── ShaderResource.h │ ├── Resource.cpp │ ├── Resource.h │ └── ResourceLoader.h ├── Tests ├── CMakeLists.txt ├── LinearAllocator │ └── unittest1.cpp ├── Logger │ └── Source.cpp ├── Multithreading │ └── unittest1.cpp ├── Settings │ ├── SettingsTest.cpp │ └── SettingsTest2.cpp └── TaggedAllocator │ └── unittest1.cpp └── Tools ├── Conan ├── Test │ ├── CMakeLists.txt │ ├── PackageTest.cpp │ └── conanfile.py └── conanfile.py └── Python └── GetRelativePaths.py /.gitignore: -------------------------------------------------------------------------------- 1 | #Visual studio meta-data 2 | /.vs 3 | 4 | #Top level directories that should not be in git 5 | Build/* 6 | Libraries/* 7 | Include/* 8 | Modules/* 9 | !Modules/README.md 10 | 11 | #Resources 12 | Resources/Objects/* 13 | Resources/Textures/* 14 | 15 | #Python 16 | Pipfile.lock -------------------------------------------------------------------------------- /CMakeSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "environments": [ 3 | { "BuildDir": "${projectDir}\\Build" } 4 | ], 5 | "configurations": [ 6 | { 7 | "name": "Release", 8 | "generator": "Ninja", 9 | "configurationType": "Release", 10 | "buildRoot": "${env.BuildDir}\\${name}", 11 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 12 | "cmakeCommandArgs": "", 13 | "buildCommandArgs": "", 14 | "ctestCommandArgs": "", 15 | "inheritEnvironments": [ "msvc_x64_x64" ], 16 | "variables": [] 17 | }, 18 | { 19 | "name": "Debug", 20 | "generator": "Ninja", 21 | "configurationType": "Debug", 22 | "buildRoot": "${env.BuildDir}\\${name}", 23 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 24 | "cmakeCommandArgs": "", 25 | "buildCommandArgs": "", 26 | "ctestCommandArgs": "", 27 | "inheritEnvironments": [ "msvc_x64_x64" ], 28 | "variables": [] 29 | }, 30 | { 31 | "name": "RelWithDebInfo", 32 | "generator": "Ninja", 33 | "configurationType": "RelWithDebInfo", 34 | "buildRoot": "${env.BuildDir}\\${name}", 35 | "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", 36 | "cmakeCommandArgs": "", 37 | "buildCommandArgs": "", 38 | "ctestCommandArgs": "", 39 | "inheritEnvironments": [ "msvc_x64_x64" ], 40 | "variables": [] 41 | } 42 | ] 43 | } -------------------------------------------------------------------------------- /Examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1 FATAL_ERROR) 2 | 3 | ############################################## 4 | #CMake delegation 5 | 6 | add_subdirectory("SoulInfo") -------------------------------------------------------------------------------- /Examples/SoulInfo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1 FATAL_ERROR) 2 | 3 | 4 | ############################################## 5 | #Project 6 | 7 | project(SoulInfo) 8 | 9 | ############################################## 10 | #CMake delegation 11 | 12 | add_subdirectory(Source) -------------------------------------------------------------------------------- /Examples/SoulInfo/Source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1 FATAL_ERROR) 2 | 3 | ############################################## 4 | #Project 5 | 6 | project(SoulInfo) 7 | 8 | 9 | ############################################## 10 | #Dependancies 11 | 12 | 13 | ############################################## 14 | #Sources 15 | 16 | file(GLOB_RECURSE PROJECT_HEADERS *.h) 17 | file(GLOB_RECURSE PROJECT_SOURCES *.cpp) 18 | set(PROJECT_FILES 19 | ${PROJECT_HEADERS} 20 | ${PROJECT_SOURCES} 21 | ) 22 | 23 | 24 | ############################################## 25 | #Targets 26 | 27 | add_executable(SoulInfo ${PROJECT_FILES}) 28 | 29 | set_target_properties(SoulInfo 30 | PROPERTIES 31 | LINKER_LANGUAGE CXX 32 | CXX_EXTENSIONS OFF 33 | CXX_STANDARD 17 34 | VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/Build" 35 | ) 36 | 37 | target_include_directories(SoulInfo 38 | PUBLIC 39 | $ 40 | PRIVATE 41 | 42 | ) 43 | 44 | target_link_libraries(SoulInfo 45 | PUBLIC 46 | 47 | INTERFACE 48 | 49 | PRIVATE 50 | synodic::SoulEngine 51 | ) -------------------------------------------------------------------------------- /Examples/SoulInfo/Source/SoulInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "SoulInfo.h" 2 | 3 | SoulInfo::SoulInfo(SoulParameters params) : 4 | SoulApplication(params) { 5 | 6 | } 7 | 8 | int main(int, char*[]) 9 | { 10 | //app params 11 | SoulParameters appParams; 12 | SoulInfo app(appParams); 13 | 14 | //create the window 15 | WindowParameters windowParams; 16 | windowParams.type = WindowType::WINDOWED; 17 | windowParams.title = "Main"; 18 | windowParams.monitor = 0; 19 | windowParams.pixelPosition.x = 0; 20 | windowParams.pixelPosition.y = 0; 21 | windowParams.pixelSize.x = 512; 22 | windowParams.pixelSize.y = 512; 23 | 24 | app.CreateWindow(windowParams); 25 | 26 | app.Run(); 27 | 28 | } -------------------------------------------------------------------------------- /Examples/SoulInfo/Source/SoulInfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SoulApplication.h" 4 | 5 | class SoulInfo : public SoulApplication { 6 | 7 | public: 8 | SoulInfo(SoulParameters = SoulParameters()); 9 | 10 | }; -------------------------------------------------------------------------------- /Includes/Property.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | template 6 | class Property { 7 | 8 | public: 9 | 10 | Property(const T&); 11 | ~Property() = default; 12 | 13 | Property& operator=(const T&); 14 | 15 | operator T() const; 16 | 17 | void AddCallback(const std::function&); 18 | void Update(); 19 | 20 | private: 21 | 22 | T data; 23 | std::vector> callbacks; 24 | 25 | }; 26 | 27 | template 28 | Property::Property(const T& value) { 29 | data = value; 30 | } 31 | 32 | 33 | template 34 | Property& Property::operator=(const T& value){ 35 | 36 | data = value; 37 | Update(); 38 | 39 | return *this; 40 | 41 | } 42 | 43 | template 44 | void Property::Update() { 45 | 46 | for (const auto& callback : callbacks) { 47 | callback(data); 48 | } 49 | 50 | } 51 | 52 | template 53 | Property::operator T() const { 54 | 55 | return data; 56 | 57 | } 58 | 59 | template 60 | void Property::AddCallback(const std::function& fn) { 61 | 62 | callbacks.push_back(fn); 63 | 64 | } -------------------------------------------------------------------------------- /Includes/Soul.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "SoulParameters.h" 4 | 5 | #include 6 | #include 7 | 8 | 9 | class WindowParameters; 10 | class Window; 11 | class Frame; 12 | 13 | class SchedulerModule; 14 | class ComputeModule; 15 | class InputModule; 16 | class WindowModule; 17 | class RasterModule; 18 | class RenderGraphModule; 19 | class GUIModule; 20 | 21 | class EntityRegistry; 22 | class EventRegistry; 23 | 24 | class Implementation; 25 | 26 | class Soul final{ 27 | 28 | public: 29 | 30 | 31 | Soul(SoulParameters&); 32 | ~Soul() = default; 33 | 34 | Soul(const Soul&) = delete; 35 | Soul(Soul&&) noexcept = default; 36 | 37 | Soul& operator=(const Soul&) = delete; 38 | Soul& operator=(Soul&&) noexcept = default; 39 | 40 | void Init(); 41 | void CreateWindow(WindowParameters&); 42 | 43 | 44 | private: 45 | 46 | void Run(); 47 | 48 | //Pipeline Functions 49 | void Process(Frame&, Frame&); 50 | void Update(Frame&, Frame&); 51 | void Render(Frame&, Frame&); 52 | 53 | 54 | //State Functions 55 | 56 | void Warmup(); 57 | 58 | void EarlyFrameUpdate(Frame&, Frame&); 59 | void LateFrameUpdate(Frame&, Frame&); 60 | void EarlyUpdate(Frame&, Frame&); 61 | void LateUpdate(Frame&, Frame&); 62 | 63 | SoulParameters& parameters_; 64 | 65 | std::chrono::nanoseconds frameTime_; 66 | bool active_; 67 | 68 | 69 | //services and modules 70 | std::shared_ptr entityRegistry_; 71 | std::shared_ptr eventRegistry_; 72 | 73 | std::shared_ptr schedulerModule_; 74 | std::shared_ptr computeModule_; 75 | std::shared_ptr inputModule_; 76 | std::shared_ptr windowModule_; 77 | std::shared_ptr rasterModule_; 78 | std::shared_ptr renderGraphModule_; 79 | std::shared_ptr guiModule_; 80 | 81 | 82 | }; 83 | -------------------------------------------------------------------------------- /Includes/SoulApplication.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Soul.h" 4 | #include "SoulParameters.h" 5 | #include "WindowParameters.h" 6 | 7 | class SoulApplication { 8 | 9 | public: 10 | 11 | SoulApplication(SoulParameters = SoulParameters()); 12 | virtual ~SoulApplication() = default; 13 | 14 | void CreateWindow(WindowParameters&); 15 | 16 | void Run(); 17 | 18 | protected: 19 | 20 | bool hasControl; 21 | SoulParameters parameters; 22 | 23 | private: 24 | 25 | void CheckParameters(); 26 | 27 | Soul soul; 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /Includes/SoulParameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Property.h" 6 | #include "Types.h" 7 | 8 | struct SoulParameters { 9 | 10 | SoulParameters() : 11 | engineRefreshRate(144), 12 | threadCount(std::thread::hardware_concurrency()) 13 | { 14 | 15 | //may return 0; see https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency 16 | if (threadCount == 0) { 17 | threadCount = 1; //guaranteed a single thread 18 | } 19 | 20 | } 21 | 22 | Property engineRefreshRate; //the update rate tied to physics and... 23 | Property threadCount; //the amount of threads at the program's disposal 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /Includes/Types.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using uint8 = uint8_t; 9 | using int8 = int8_t; 10 | 11 | using uint16 = uint16_t; 12 | using int16 = int16_t; 13 | 14 | using uint32 = uint32_t; 15 | using int32 = int32_t; 16 | using uint = uint32_t; 17 | 18 | using int64 = int64_t; 19 | using uint64 = uint64_t; 20 | 21 | 22 | class Metrics{ 23 | 24 | }; -------------------------------------------------------------------------------- /Includes/WindowParameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include 6 | 7 | enum class WindowType { WINDOWED, FULLSCREEN, BORDERLESS, EMPTY }; 8 | 9 | class WindowParameters { 10 | 11 | public: 12 | 13 | WindowType type; 14 | std::string title; 15 | glm::uvec2 pixelPosition; 16 | glm::uvec2 pixelSize; 17 | int monitor; 18 | 19 | }; -------------------------------------------------------------------------------- /Modules/README.md: -------------------------------------------------------------------------------- 1 | Place additional engine modules in this folder. -------------------------------------------------------------------------------- /Resources/Documents/Wiki/Home.md: -------------------------------------------------------------------------------- 1 | * [What Is Soul Engine?](#what-is-soul-engine) 2 | * [What Problem Does Soul Engine Solve?](#what-problem-does-soul-engine-solve) 3 | * [What Is Unique About Soul Engine?](#what-is-unique-about-soul-engine) 4 | 5 | ## What Is Soul Engine? 6 | 7 | **TODO** 8 | 9 | ## What Problem Does Soul Engine Solve? 10 | 11 | **TODO** 12 | 13 | ## What Is Unique About Soul Engine? 14 | 15 | **TODO** 16 | -------------------------------------------------------------------------------- /Resources/Documents/Wiki/How-to-Use.md: -------------------------------------------------------------------------------- 1 | **TODO** -------------------------------------------------------------------------------- /Resources/Documents/Wiki/Roadmap.md: -------------------------------------------------------------------------------- 1 | # Alpha Version 1.0 # 2 | 3 | The purpose of this release is to establish a baseline from which all further work on the engine would build upon. With that in mind, the features in this release will be very narrow and will not be anything noteworthy that differentiates the engine from other available software. However, the goal is to provide a uniform interaction of all engine modules such that future releases are hopefully not drastically different. This is not a guarantee as the engine's development is long term and may encompass many reworks, it is a design goal of this release only and will be respected as such. 4 | 5 | ### Engine ### 6 | * **Cross platform support** The engine will have the three main platforms, Linux, Windows, and macOS as targets for creating application. 7 | 8 | ### Development Environment ### 9 | 10 | * **Cross platform support** The engine will have the three main platforms, Linux, Windows, and macOS as development environments for creating application. 11 | 12 | ### Ray Engine ### 13 | * **Naive path tracing** While one of the unique features of this engine is its priority of ray tracing and its derivatives, this release will only contain a preliminary implementation of path tracing. 14 | 15 | 16 | # Alpha Version 1.1 # 17 | -------------------------------------------------------------------------------- /Resources/Documents/Wiki/_Sidebar.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | [[Home]] 3 | 4 | [[Getting Started]] 5 | 6 | [[How to Use]] 7 | 8 | 9 | # Features 10 | 11 | [[Roadmap]] 12 | 13 | -------------------------------------------------------------------------------- /Resources/Images/Tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Resources/Images/Tree.png -------------------------------------------------------------------------------- /Resources/Shaders/compile.bat: -------------------------------------------------------------------------------- 1 | C:/VulkanSDK/1.1.114.0/Bin/glslangValidator.exe -V simpleShader.vert 2 | C:/VulkanSDK/1.1.114.0/Bin/glslangValidator.exe -V simpleShader.frag 3 | pause -------------------------------------------------------------------------------- /Resources/Shaders/frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Resources/Shaders/frag.spv -------------------------------------------------------------------------------- /Resources/Shaders/fragment-shader[Renderer].glsl: -------------------------------------------------------------------------------- 1 | #version 430 2 | 3 | layout( std430, binding=0 ) buffer texB 4 | { 5 | vec4 tex[]; 6 | }; 7 | 8 | in vec2 textureCoord; 9 | 10 | out vec4 fragment; 11 | 12 | uniform uvec2 screen; 13 | 14 | 15 | void main(){ 16 | 17 | uvec2 pos= uvec2(textureCoord.xy*vec2(screen)); 18 | 19 | fragment= tex[pos.x+ screen.x*pos.y]; 20 | 21 | } -------------------------------------------------------------------------------- /Resources/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | layout(location = 0) in vec3 fragColor; 5 | 6 | layout(location = 0) out vec4 outColor; 7 | 8 | void main() { 9 | outColor = vec4(fragColor, 1.0); 10 | } -------------------------------------------------------------------------------- /Resources/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_ARB_separate_shader_objects : enable 3 | 4 | out gl_PerVertex { 5 | vec4 gl_Position; 6 | }; 7 | 8 | layout(location = 0) in vec3 inPosition; 9 | 10 | layout(location = 0) out vec3 fragColor; 11 | 12 | 13 | void main() { 14 | gl_Position = vec4(inPosition.xy, 0.0, 1.0); 15 | fragColor = vec3(0,0.7,1); 16 | } -------------------------------------------------------------------------------- /Resources/Shaders/vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Resources/Shaders/vert.spv -------------------------------------------------------------------------------- /Resources/Shaders/vertex-shader[Renderer].glsl: -------------------------------------------------------------------------------- 1 | #version 430 core 2 | 3 | in vec4 vert_VS_in; 4 | 5 | const vec2 offset = vec2(0.5, 0.5); 6 | 7 | out vec2 textureCoord; 8 | 9 | void main() 10 | { 11 | textureCoord = vert_VS_in.xy*offset + offset; // scale vertex attribute to [0-1] range 12 | gl_Position = vert_VS_in; 13 | } -------------------------------------------------------------------------------- /Setup.py: -------------------------------------------------------------------------------- 1 | import subprocess 2 | import sys 3 | import os 4 | 5 | from pathlib import Path 6 | 7 | 8 | def main(): 9 | 10 | 11 | print("Updating the Python environment") 12 | 13 | #TODO: Use a venv 14 | #subprocess.call(["poetry", "install"]) 15 | 16 | 17 | print("Updating the C++ environment") 18 | 19 | buildPath = Path().absolute() / "Build" 20 | buildPathString = str(buildPath) 21 | 22 | conanFilePath = Path().absolute() / "Tools" / "Conan" 23 | conanFilePathString = str(conanFilePath) 24 | 25 | #Set the conan remote 26 | subprocess.call(["conan", "remote", "add", "--force", "bincrafters", "https://api.bintray.com/conan/bincrafters/public-conan"]) 27 | 28 | #Create build directory if it does not exist 29 | if not os.path.exists(buildPath): 30 | os.makedirs(buildPath) 31 | 32 | #install conan dependencies 33 | subprocess.call(["conan", "install", conanFilePathString, "-if", buildPathString, "-g", "cmake_multi", "-s", "build_type=Debug", "--build=missing"]) 34 | subprocess.call(["conan", "install", conanFilePathString, "-if", buildPathString, "-g", "cmake_multi", "-s", "build_type=Release", "--build=missing"]) 35 | 36 | #set the package to editable, allowing projects to find it globally via Conan and bypass a remote fetch 37 | subprocess.call(["conan", "editable", "add", conanFilePathString, "SoulEngine/0.0.1@synodic/testing"]) 38 | 39 | print("Finished setup!") 40 | 41 | main() -------------------------------------------------------------------------------- /Source/Audio/AudioManager.cpp: -------------------------------------------------------------------------------- 1 | #include "AudioManager.h" -------------------------------------------------------------------------------- /Source/Audio/AudioManager.h: -------------------------------------------------------------------------------- 1 | #pragma once -------------------------------------------------------------------------------- /Source/Audio/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Audio 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | AudioManager.cpp 8 | AudioManager.h 9 | ) -------------------------------------------------------------------------------- /Source/Compute/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Compute 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | ComputeBackend.h 8 | ComputeBuffer.cpp 9 | ComputeBuffer.h 10 | ComputeDevice.h 11 | ComputeModule.cpp 12 | ComputeModule.h 13 | ComputePolicy.cpp 14 | ComputePolicy.h 15 | DeviceBuffer.cpp 16 | DeviceBuffer.h 17 | ) 18 | 19 | add_subdirectory(Modules) -------------------------------------------------------------------------------- /Source/Compute/ComputeBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Utility/Template/CRTP.h" 4 | #include "ComputePolicy.h" 5 | 6 | 7 | template 8 | class ComputeBackend : public CRTP { 9 | 10 | public: 11 | 12 | ComputeBackend() = default; 13 | virtual ~ComputeBackend() = default; 14 | 15 | ComputeBackend(const ComputeBackend&) = delete; 16 | ComputeBackend(ComputeBackend&&) noexcept = default; 17 | 18 | ComputeBackend& operator=(const ComputeBackend&) = delete; 19 | ComputeBackend& operator=(ComputeBackend&&) noexcept = default; 20 | 21 | 22 | template 23 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 24 | 25 | }; 26 | 27 | template 28 | template 29 | void ComputeBackend::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | this->Type()->Launch(policy, kernel, std::forward(parameters)...); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Source/Compute/ComputeBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "ComputeBuffer.h" -------------------------------------------------------------------------------- /Source/Compute/ComputeBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | template 5 | class ComputeBuffer { 6 | 7 | public: 8 | 9 | ComputeBuffer() = default; 10 | virtual ~ComputeBuffer() = default; 11 | 12 | ComputeBuffer(const ComputeBuffer&) = delete; 13 | ComputeBuffer(ComputeBuffer&&) noexcept = default; 14 | 15 | ComputeBuffer& operator=(const ComputeBuffer&) = delete; 16 | ComputeBuffer& operator=(ComputeBuffer&&) noexcept = default; 17 | 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /Source/Compute/ComputeDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ComputePolicy.h" 4 | #include "Core/Utility/Template/CRTP.h" 5 | 6 | 7 | template 8 | class ComputeDevice : public CRTP { 9 | 10 | public: 11 | 12 | ComputeDevice() = default; 13 | virtual ~ComputeDevice() = default; 14 | 15 | ComputeDevice(const ComputeDevice&) = delete; 16 | ComputeDevice(ComputeDevice&&) noexcept = default; 17 | 18 | ComputeDevice& operator=(const ComputeDevice&) = delete; 19 | ComputeDevice& operator=(ComputeDevice&&) noexcept = default; 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | template 28 | template 29 | void ComputeDevice::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | this->Type()->Launch(policy, kernel, std::forward(parameters)...); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Source/Compute/ComputeModule.cpp: -------------------------------------------------------------------------------- 1 | #include "ComputeModule.h" 2 | 3 | 4 | std::shared_ptr ComputeModule::CreateModule() { 5 | 6 | return std::make_shared(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Source/Compute/ComputeModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Interface/Module/Module.h" 4 | #include "ComputePolicy.h" 5 | 6 | #include 7 | #include 8 | 9 | #include "Modules/CPU/CPUBackend.h" 10 | #include "Modules/CUDA/CUDABackend.h" 11 | #include "Modules/OpenCL/OpenCLBackend.h" 12 | 13 | #include "Modules/CPU/CPUDevice.h" 14 | #include "Modules/CUDA/CUDADevice.h" 15 | #include "Modules/OpenCL/OpenCLDevice.h" 16 | 17 | 18 | class ComputeModule : public Module { 19 | 20 | public: 21 | 22 | ComputeModule() = default; 23 | virtual ~ComputeModule() = default; 24 | 25 | ComputeModule(const ComputeModule&) = delete; 26 | ComputeModule(ComputeModule&&) noexcept = default; 27 | 28 | ComputeModule& operator=(const ComputeModule&) = delete; 29 | ComputeModule& operator=(ComputeModule&&) noexcept = default; 30 | 31 | 32 | template 33 | void Launch(const ComputePolicy& policy, 34 | const KernelFunction& kernel, 35 | Args&&... parameters) { 36 | 37 | } 38 | 39 | 40 | //Factory 41 | static std::shared_ptr CreateModule(); 42 | 43 | 44 | private: 45 | 46 | CUDABackend CUDABackend_; 47 | OpenCLBackend OpenCLBackend_; 48 | CPUBackend CPUBackend_; 49 | 50 | std::vector CUDADevices_; 51 | std::vector OpenCLDevices_; 52 | CPUDevice CPUDevice_; 53 | 54 | }; 55 | -------------------------------------------------------------------------------- /Source/Compute/ComputePolicy.cpp: -------------------------------------------------------------------------------- 1 | #include "ComputePolicy.h" 2 | 3 | #define GLM_ENABLE_EXPERIMENTAL 4 | #include "glm/gtx/component_wise.hpp" 5 | 6 | ComputePolicy::ComputePolicy(uint size_, uint blockSize_, int sharedBytes, int stream_) : 7 | gridsize((size_ + blockSize_ - 1) / blockSize_, 1, 1), 8 | blocksize(blockSize_, 1, 1), 9 | sharedMemory(sharedBytes), 10 | stream(stream_) 11 | { 12 | 13 | } 14 | 15 | ComputePolicy::ComputePolicy(glm::uvec3 grid, glm::uvec3 block, int sharedBytes, int stream_) : 16 | gridsize(grid), 17 | blocksize(block), 18 | sharedMemory(sharedBytes), 19 | stream(stream_) 20 | { 21 | 22 | } 23 | 24 | uint ComputePolicy::GetThreadCount() const{ 25 | return glm::compMul(gridsize)*glm::compMul(blocksize); 26 | } 27 | -------------------------------------------------------------------------------- /Source/Compute/ComputePolicy.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Types.h" 5 | 6 | class ComputePolicy { 7 | 8 | public: 9 | 10 | //Constructors + Destructors 11 | ComputePolicy() = default; 12 | ComputePolicy(uint, uint, int, int); 13 | ComputePolicy(glm::uvec3, glm::uvec3, int, int); 14 | 15 | 16 | //Policy Helpers 17 | uint GetThreadCount() const; 18 | 19 | 20 | glm::uvec3 gridsize; 21 | glm::uvec3 blocksize; 22 | int sharedMemory; 23 | int stream; 24 | 25 | }; -------------------------------------------------------------------------------- /Source/Compute/DeviceBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "DeviceBuffer.h" -------------------------------------------------------------------------------- /Source/Compute/DeviceBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | template 5 | class DeviceBuffer { 6 | 7 | public: 8 | 9 | DeviceBuffer() = default; 10 | virtual ~DeviceBuffer() = default; 11 | 12 | DeviceBuffer(const DeviceBuffer&) = delete; 13 | DeviceBuffer(DeviceBuffer&&) noexcept = default; 14 | 15 | DeviceBuffer& operator=(const DeviceBuffer&) = delete; 16 | DeviceBuffer& operator=(DeviceBuffer&&) noexcept = default; 17 | 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /Source/Compute/Modules/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1 FATAL_ERROR) 2 | 3 | ############################################## 4 | #Compute Platforms 5 | 6 | if(BUILD_CPU_COMPUTE) 7 | 8 | add_subdirectory("CPU") 9 | 10 | endif() 11 | 12 | if(BUILD_CUDA_COMPUTE) 13 | 14 | add_subdirectory("Mock") 15 | 16 | endif() 17 | 18 | if(BUILD_CUDA_COMPUTE) 19 | 20 | add_subdirectory("CUDA") 21 | 22 | endif() 23 | 24 | 25 | if(BUILD_CUDA_COMPUTE) 26 | 27 | add_subdirectory("OpenCL") 28 | 29 | endif() 30 | 31 | target_compile_definitions(${PROJECT_NAME} 32 | PRIVATE 33 | CUDA_COMPUTE=BUILD_CUDA_COMPUTE 34 | OPENCL_COMPUTE=BUILD_OPENCL_COMPUTE 35 | ) -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################## 2 | #Compute/CPU 3 | 4 | target_sources(${PROJECT_NAME} 5 | PRIVATE 6 | CPUBackend.cpp 7 | CPUBackend.h 8 | CPUBuffer.cpp 9 | CPUBuffer.h 10 | CPUDevice.cpp 11 | CPUDevice.h 12 | ) -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "CPUBackend.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeBackend.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class CPUBackend : public ComputeBackend { 8 | 9 | public: 10 | 11 | CPUBackend() = default; 12 | virtual ~CPUBackend() = default; 13 | 14 | CPUBackend(const CPUBackend&) = delete; 15 | CPUBackend(CPUBackend&&) noexcept = default; 16 | 17 | CPUBackend& operator=(const CPUBackend&) = delete; 18 | CPUBackend& operator=(CPUBackend&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | template 28 | void CPUBackend::Launch(const ComputePolicy& policy, 29 | const KernelFunction& kernel, 30 | Args&&... parameters) { 31 | 32 | throw NotImplemented(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "CPUBuffer.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/DeviceBuffer.h" 4 | 5 | 6 | template 7 | class CPUBuffer : public DeviceBuffer { 8 | 9 | public: 10 | 11 | CPUBuffer() = default; 12 | virtual ~CPUBuffer() = default; 13 | 14 | CPUBuffer(const CPUBuffer&) = delete; 15 | CPUBuffer(CPUBuffer&&) noexcept = default; 16 | 17 | CPUBuffer& operator=(const CPUBuffer&) = delete; 18 | CPUBuffer& operator=(CPUBuffer&&) noexcept = default; 19 | 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUDevice.cpp: -------------------------------------------------------------------------------- 1 | #include "CPUDevice.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CPU/CPUDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeDevice.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class CPUDevice : public ComputeDevice { 8 | 9 | public: 10 | 11 | CPUDevice() = default; 12 | virtual ~CPUDevice() = default; 13 | 14 | CPUDevice(const CPUDevice&) = delete; 15 | CPUDevice(CPUDevice&&) noexcept = default; 16 | 17 | CPUDevice& operator=(const CPUDevice&) = delete; 18 | CPUDevice& operator=(CPUDevice&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | 28 | template 29 | void CPUDevice::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | throw NotImplemented(); 34 | 35 | } -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################## 2 | #Compute/CUDA 3 | 4 | target_sources(${PROJECT_NAME} 5 | PRIVATE 6 | CUDABackend.cpp 7 | CUDABackend.h 8 | CUDABuffer.cpp 9 | CUDABuffer.h 10 | CUDADevice.cpp 11 | CUDADevice.h 12 | ) -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDABackend.cpp: -------------------------------------------------------------------------------- 1 | #include "CUDABackend.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDABackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeBackend.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class CUDABackend : public ComputeBackend { 8 | 9 | public: 10 | 11 | CUDABackend() = default; 12 | virtual ~CUDABackend() = default; 13 | 14 | CUDABackend(const CUDABackend&) = delete; 15 | CUDABackend(CUDABackend&&) noexcept = default; 16 | 17 | CUDABackend& operator=(const CUDABackend&) = delete; 18 | CUDABackend& operator=(CUDABackend&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | template 28 | void CUDABackend::Launch(const ComputePolicy& policy, 29 | const KernelFunction& kernel, 30 | Args&&... parameters) { 31 | 32 | throw NotImplemented(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDABuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "CUDABuffer.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDABuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/DeviceBuffer.h" 4 | 5 | 6 | template 7 | class CUDABuffer : public DeviceBuffer { 8 | 9 | public: 10 | 11 | CUDABuffer() = default; 12 | virtual ~CUDABuffer() = default; 13 | 14 | CUDABuffer(const CUDABuffer&) = delete; 15 | CUDABuffer(CUDABuffer&&) noexcept = default; 16 | 17 | CUDABuffer& operator=(const CUDABuffer&) = delete; 18 | CUDABuffer& operator=(CUDABuffer&&) noexcept = default; 19 | 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDADevice.cpp: -------------------------------------------------------------------------------- 1 | #include "CUDADevice.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/CUDA/CUDADevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeDevice.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class CUDADevice : public ComputeDevice { 8 | 9 | public: 10 | 11 | CUDADevice() = default; 12 | virtual ~CUDADevice() = default; 13 | 14 | CUDADevice(const CUDADevice&) = delete; 15 | CUDADevice(CUDADevice&&) noexcept = default; 16 | 17 | CUDADevice& operator=(const CUDADevice&) = delete; 18 | CUDADevice& operator=(CUDADevice&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | 28 | template 29 | void CUDADevice::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | throw NotImplemented(); 34 | 35 | } -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################## 2 | #Compute/Mock 3 | 4 | target_sources(${PROJECT_NAME} 5 | PRIVATE 6 | MockBackend.cpp 7 | MockBackend.h 8 | MockBuffer.cpp 9 | MockBuffer.h 10 | MockDevice.cpp 11 | MockDevice.h 12 | ) -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "MockBackend.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeBackend.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class MockBackend : public ComputeBackend { 8 | 9 | public: 10 | 11 | MockBackend() = default; 12 | virtual ~MockBackend() = default; 13 | 14 | MockBackend(const MockBackend&) = delete; 15 | MockBackend(MockBackend&&) noexcept = default; 16 | 17 | MockBackend& operator=(const MockBackend&) = delete; 18 | MockBackend& operator=(MockBackend&&) noexcept = default; 19 | 20 | template 21 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 22 | 23 | 24 | }; 25 | 26 | template 27 | void MockBackend::Launch(const ComputePolicy& policy, 28 | const KernelFunction& kernel, 29 | Args&&... parameters) { 30 | 31 | throw NotImplemented(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "MockBuffer.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/DeviceBuffer.h" 4 | 5 | 6 | template 7 | class MockBuffer : public DeviceBuffer { 8 | 9 | public: 10 | 11 | MockBuffer() = default; 12 | virtual ~MockBuffer() = default; 13 | 14 | MockBuffer(const MockBuffer&) = delete; 15 | MockBuffer(MockBuffer&&) noexcept = default; 16 | 17 | MockBuffer& operator=(const MockBuffer&) = delete; 18 | MockBuffer& operator=(MockBuffer&&) noexcept = default; 19 | 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockDevice.cpp: -------------------------------------------------------------------------------- 1 | #include "MockDevice.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/Mock/MockDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeDevice.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class MockDevice : public ComputeDevice { 8 | 9 | public: 10 | 11 | MockDevice() = default; 12 | virtual ~MockDevice() = default; 13 | 14 | MockDevice(const MockDevice&) = delete; 15 | MockDevice(MockDevice&&) noexcept = default; 16 | 17 | MockDevice& operator=(const MockDevice&) = delete; 18 | MockDevice& operator=(MockDevice&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | 28 | template 29 | void MockDevice::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | throw NotImplemented(); 34 | 35 | } -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ############################################## 2 | #Compute/OpenCL 3 | 4 | target_sources(${PROJECT_NAME} 5 | PRIVATE 6 | OpenCLBackend.cpp 7 | OpenCLBackend.h 8 | OpenCLBuffer.cpp 9 | OpenCLBuffer.h 10 | OpenCLDevice.cpp 11 | OpenCLDevice.h 12 | ) -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "OpenCLBackend.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeBackend.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | class OpenCLBackend : public ComputeBackend { 7 | 8 | public: 9 | 10 | OpenCLBackend() = default; 11 | virtual ~OpenCLBackend() = default; 12 | 13 | OpenCLBackend(const OpenCLBackend&) = delete; 14 | OpenCLBackend(OpenCLBackend&&) noexcept = default; 15 | 16 | OpenCLBackend& operator=(const OpenCLBackend&) = delete; 17 | OpenCLBackend& operator=(OpenCLBackend&&) noexcept = default; 18 | 19 | template 20 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 21 | 22 | }; 23 | 24 | template 25 | void OpenCLBackend::Launch(const ComputePolicy& policy, 26 | const KernelFunction& kernel, 27 | Args&&... parameters) { 28 | 29 | throw NotImplemented(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "OpenCLBuffer.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/DeviceBuffer.h" 4 | 5 | 6 | template 7 | class OpenCLBuffer : public DeviceBuffer { 8 | 9 | public: 10 | 11 | OpenCLBuffer() = default; 12 | virtual ~OpenCLBuffer() = default; 13 | 14 | OpenCLBuffer(const OpenCLBuffer&) = delete; 15 | OpenCLBuffer(OpenCLBuffer&&) noexcept = default; 16 | 17 | OpenCLBuffer& operator=(const OpenCLBuffer&) = delete; 18 | OpenCLBuffer& operator=(OpenCLBuffer&&) noexcept = default; 19 | 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLDevice.cpp: -------------------------------------------------------------------------------- 1 | #include "OpenCLDevice.h" -------------------------------------------------------------------------------- /Source/Compute/Modules/OpenCL/OpenCLDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Compute/ComputeDevice.h" 4 | #include "Core/Utility/Exception/Exception.h" 5 | 6 | 7 | class OpenCLDevice : public ComputeDevice { 8 | 9 | public: 10 | 11 | OpenCLDevice() = default; 12 | virtual ~OpenCLDevice() = default; 13 | 14 | OpenCLDevice(const OpenCLDevice&) = delete; 15 | OpenCLDevice(OpenCLDevice&&) noexcept = default; 16 | 17 | OpenCLDevice& operator=(const OpenCLDevice&) = delete; 18 | OpenCLDevice& operator=(OpenCLDevice&&) noexcept = default; 19 | 20 | 21 | template 22 | void Launch(const ComputePolicy&, const KernelFunction&, Args&&...); 23 | 24 | 25 | }; 26 | 27 | 28 | template 29 | void OpenCLDevice::Launch(const ComputePolicy& policy, 30 | const KernelFunction& kernel, 31 | Args&&... parameters) { 32 | 33 | throw NotImplemented(); 34 | 35 | } -------------------------------------------------------------------------------- /Source/Core/Composition/Component/Component.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Utility/Template/CRTP.h" 4 | 5 | 6 | class EntityManager; 7 | 8 | class Component 9 | { 10 | 11 | public: 12 | 13 | Component() = default; 14 | ~Component() = default; 15 | 16 | Component(const Component&) = delete; 17 | Component(Component&&) noexcept = default; 18 | 19 | Component& operator=(const Component&) = delete; 20 | Component& operator=(Component&&) noexcept = default; 21 | 22 | 23 | }; -------------------------------------------------------------------------------- /Source/Core/Composition/Entity/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity.h" 2 | 3 | Entity::Entity() : 4 | entity_(nullState) 5 | { 6 | } 7 | 8 | Entity::Entity(value_type entity) : 9 | entity_(entity) 10 | { 11 | } 12 | 13 | Entity::Entity(id_type id, version_type version) : 14 | entity_(version) 15 | { 16 | 17 | entity_ <<= entityBitCount; 18 | entity_ |= id; 19 | 20 | } 21 | 22 | bool Entity::IsNull() const{ 23 | return entity_ == nullState; 24 | } 25 | 26 | Entity::operator value_type() const { 27 | return entity_; 28 | } 29 | 30 | Entity::version_type Entity::GetVersion() const{ 31 | return entity_ >> entityBitCount & versionMask; 32 | } 33 | 34 | Entity::id_type Entity::GetId() const { 35 | return entity_ & entityMask; 36 | } 37 | 38 | bool Entity::operator==(const Entity& other) const 39 | { 40 | return entity_ == other.entity_; 41 | } -------------------------------------------------------------------------------- /Source/Core/Composition/Entity/Entity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | class EntityRegistry; 6 | 7 | class Entity 8 | { 9 | 10 | //TODO: Replace with badge/attorney -client 11 | friend class EntityRegistry; 12 | friend struct std::hash; 13 | 14 | using value_type = uint64; 15 | using id_type = uint32; 16 | using version_type = uint32; 17 | 18 | static constexpr auto entityMask = 0xFFFFFFFF; 19 | static constexpr auto versionMask = 0xFFFFFFFF; 20 | static constexpr auto entityBitCount = 32; 21 | static constexpr auto nullState = entityMask; 22 | 23 | 24 | public: 25 | 26 | //construction and assignment 27 | Entity(); 28 | ~Entity() = default; 29 | 30 | Entity(const Entity &) = default; 31 | Entity(Entity &&) noexcept = default; 32 | 33 | Entity& operator=(const Entity &) = default; 34 | Entity& operator=(Entity &&) noexcept = default; 35 | 36 | bool operator==(const Entity&) const; 37 | 38 | //public funcs 39 | bool IsNull() const; 40 | 41 | 42 | private: 43 | 44 | //Valid Entities can only be created by the entity registry 45 | explicit Entity(value_type); 46 | explicit Entity(id_type, version_type); 47 | 48 | explicit operator value_type() const; 49 | 50 | version_type GetVersion() const; 51 | id_type GetId() const; 52 | 53 | value_type entity_; 54 | 55 | }; 56 | 57 | namespace std { 58 | 59 | template<> 60 | struct hash { 61 | std::size_t operator()(const Entity& entity) const 62 | { 63 | return static_cast(entity.GetId()); 64 | } 65 | }; 66 | 67 | } -------------------------------------------------------------------------------- /Source/Core/Composition/Entity/EntityRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "EntityRegistry.h" 2 | 3 | EntityRegistry::EntityRegistry(): availableEntities_(0), nextAvailable_(0) 4 | { 5 | } 6 | 7 | bool EntityRegistry::IsValid(Entity entity) const noexcept 8 | { 9 | const auto id = entity.GetId(); 10 | return id < entities_.size() && entities_[id].entity_ == entity.entity_; 11 | } 12 | 13 | Entity EntityRegistry::CreateEntity() 14 | { 15 | 16 | Entity entityID; 17 | 18 | // if no entities are available for reuse, create a new one 19 | if (availableEntities_) { 20 | 21 | const auto id = nextAvailable_; 22 | nextAvailable_ = entities_[id].GetId(); 23 | const auto version = entities_[id].GetVersion(); 24 | 25 | entityID = Entity(id, version); 26 | entities_[id] = entityID; 27 | --availableEntities_; 28 | 29 | } 30 | else { 31 | 32 | // simply add an entity. No max entity size check, who will ever go past uint32 entities? ;P 33 | entityID = Entity(entities_.size()); 34 | entities_.push_back(entityID); 35 | 36 | } 37 | 38 | return entityID; 39 | } 40 | 41 | //TODO: Reimplement without type info? 42 | //void EntityRegistry::RemoveEntity(Entity entity) 43 | //{ 44 | // 45 | // assert(IsValid(entity)); 46 | // 47 | // for (auto& pool : componentPools_) { 48 | // pool->Erase(entity); 49 | // } 50 | // 51 | // // grab entity data 52 | // const auto id = availableEntities_ ? nextAvailable_ : entity.GetId() + 1; 53 | // const auto version = entity.GetVersion() + 1; 54 | // 55 | // // set the incremented version 56 | // entities_[id] = Entity(id, version); 57 | // nextAvailable_ = id; 58 | // ++availableEntities_; 59 | // 60 | //} -------------------------------------------------------------------------------- /Source/Core/Composition/Event/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include 6 | #include 7 | 8 | 9 | class BaseEvent 10 | { 11 | 12 | public: 13 | 14 | BaseEvent() = default; 15 | virtual ~BaseEvent() = default; 16 | 17 | virtual void Remove(uint64) {} 18 | 19 | }; 20 | 21 | //force specialization 22 | template 23 | class Event; 24 | 25 | template 26 | class Event : public BaseEvent 27 | { 28 | 29 | public: 30 | 31 | using signature = std::function; 32 | 33 | Event() = default; 34 | ~Event() = default; 35 | 36 | Event(const Event &) = delete; 37 | Event(Event &&) = default; 38 | 39 | Event & operator=(const Event &) = delete; 40 | Event & operator=(Event &&) = default; 41 | 42 | //stores the callable with quick lookup enabled by the ID 43 | void Listen(uint64, signature&&); 44 | void Remove(uint64) override; 45 | void RemoveAll() const; 46 | 47 | //calls all stored callables 48 | template 49 | void Emit(Args&&... args); 50 | 51 | private: 52 | 53 | //the hashmap of 54 | mutable std::unordered_map listeners; 55 | 56 | }; 57 | 58 | 59 | template 60 | void Event::Listen(uint64 id, signature&& fn) { 61 | listeners.insert(std::make_pair(id, fn)); 62 | } 63 | 64 | template 65 | void Event::Remove(uint64 id) { 66 | listeners.erase(id); 67 | } 68 | 69 | template 70 | void Event::RemoveAll() const { 71 | listeners.clear(); 72 | } 73 | 74 | template 75 | template 76 | void Event::Emit(Args&&... args) { 77 | for (const auto&[key, value] : listeners) { 78 | std::invoke(value, std::forward(args)...); 79 | } 80 | } -------------------------------------------------------------------------------- /Source/Core/Composition/Event/EventRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "EventRegistry.h" 2 | 3 | EventRegistry::EventRegistry() : 4 | idCounter_(0) 5 | { 6 | } 7 | 8 | void EventRegistry::Remove(HashString::HashType channel, HashString::HashType name, uint64 id) 9 | { 10 | eventMap_[channel][name]->Remove(id); 11 | } 12 | 13 | void EventRegistry::Remove(HashString::HashType channel, HashString::HashType name) { 14 | eventMap_[channel].erase(name); 15 | } 16 | 17 | void EventRegistry::Remove(HashString::HashType channel) { 18 | eventMap_.erase(channel); 19 | } -------------------------------------------------------------------------------- /Source/Core/Frame/Frame.cpp: -------------------------------------------------------------------------------- 1 | #include "Frame.h" 2 | 3 | Frame::Frame() : 4 | id_(0) 5 | { 6 | 7 | } 8 | 9 | Frame::Frame(const Frame& previous, const Frame& host) : 10 | id_(previous.id_ + 1) 11 | { 12 | 13 | Dirty(true); 14 | 15 | } 16 | 17 | bool Frame::Dirty() const { 18 | return flags_[0]; 19 | } 20 | 21 | void Frame::Dirty(const bool on) { 22 | flags_[0] = on; 23 | } -------------------------------------------------------------------------------- /Source/Core/Frame/Frame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class Frame { 7 | 8 | public: 9 | 10 | Frame(); 11 | Frame(const Frame&, const Frame&); 12 | ~Frame() = default; 13 | 14 | Frame(const Frame&) = delete; 15 | Frame(Frame&&) noexcept = default; 16 | 17 | Frame& operator=(const Frame&) = delete; 18 | Frame& operator=(Frame&&) noexcept = default; 19 | 20 | //Gets 21 | bool Dirty() const; //flag 0 22 | 23 | //Sets 24 | void Dirty(bool); 25 | 26 | private: 27 | 28 | std::size_t id_; 29 | 30 | std::bitset<1> flags_; 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /Source/Core/Frame/FramePipeline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Frame.h" 4 | #include "Core/Structure/RingBuffer.h" 5 | #include "Parallelism/Graph/Graph.h" 6 | #include "Parallelism/Scheduler/SchedulerModule.h" 7 | 8 | #include 9 | 10 | class Soul; 11 | 12 | template 13 | class FramePipeline { 14 | 15 | public: 16 | 17 | FramePipeline(std::shared_ptr&, 18 | std::array, N>&&); 19 | ~FramePipeline() = default; 20 | 21 | FramePipeline(const FramePipeline&) = delete; 22 | FramePipeline(FramePipeline&&) noexcept = delete; 23 | 24 | FramePipeline& operator=(const FramePipeline&) = delete; 25 | FramePipeline& operator=(FramePipeline&&) noexcept = delete; 26 | 27 | void Execute(std::chrono::nanoseconds); 28 | 29 | private: 30 | 31 | std::shared_ptr scheduler_; 32 | Graph graph_; 33 | RingBuffer frames_; 34 | 35 | }; 36 | 37 | template 38 | FramePipeline::FramePipeline(std::shared_ptr& scheduler, 39 | std::array, N>&& tasks): 40 | scheduler_(scheduler), 41 | graph_(scheduler) 42 | { 43 | 44 | GraphTask* oldTask = nullptr; 45 | 46 | auto index = 0; 47 | 48 | for (auto& task : tasks) { 49 | 50 | auto voidWrapper = [this, task, index]() mutable 51 | { 52 | //0 is newest 53 | task(frames_[index+1], frames_[index]); 54 | }; 55 | 56 | GraphTask& newTask = graph_.AddTask(voidWrapper); 57 | 58 | if (oldTask) { 59 | newTask.DependsOn(*oldTask); 60 | } 61 | 62 | oldTask = &newTask; 63 | ++index; 64 | 65 | } 66 | 67 | } 68 | 69 | template 70 | void FramePipeline::Execute(std::chrono::nanoseconds frameTime) { 71 | 72 | //iterate the next frame. Index corresponds to pipeline pos 0 == first stage 73 | frames_.Push(Frame()); 74 | 75 | graph_.Execute(frameTime); 76 | 77 | scheduler_->Block(); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /Source/Core/Geometry/BoundingBox.cpp: -------------------------------------------------------------------------------- 1 | #include "BoundingBox.h" -------------------------------------------------------------------------------- /Source/Core/Geometry/BoundingBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Composition/Component/Component.h" 4 | 5 | #include 6 | 7 | class BoundingBox : Component 8 | { 9 | 10 | public: 11 | 12 | BoundingBox() = default; 13 | ~BoundingBox() = default; 14 | 15 | glm::vec3 min; 16 | glm::vec3 max; 17 | 18 | }; -------------------------------------------------------------------------------- /Source/Core/Geometry/Face.cpp: -------------------------------------------------------------------------------- 1 | #include "Face.h" -------------------------------------------------------------------------------- /Source/Core/Geometry/Face.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Composition/Component/Component.h" 4 | 5 | #include 6 | #include "Types.h" 7 | 8 | class Face : Component 9 | { 10 | 11 | public: 12 | 13 | Face() = default; 14 | ~Face() = default; 15 | 16 | glm::uvec3 indices; 17 | uint material; //TODO investigate materials 18 | }; 19 | 20 | 21 | //Moller-Trumbore 22 | //__host__ __device__ __inline__ bool FindTriangleIntersect(const glm::vec3& a, const glm::vec3& b, const glm::vec3& c, 23 | // const glm::vec3& rayO, const glm::vec3& rayD, const glm::vec3& invDir, 24 | // float& t, const float& tMax, float& bary1, float& bary2) 25 | //{ 26 | // 27 | // glm::vec3 edge1 = b - a; 28 | // glm::vec3 edge2 = c - a; 29 | // 30 | // glm::vec3 pvec = glm::cross(rayD, edge2); 31 | // 32 | // float det = glm::dot(edge1, pvec); 33 | // 34 | // if (det == 0.f) { 35 | // return false; 36 | // } 37 | // 38 | // float inv_det = 1.0f / det; 39 | // 40 | // glm::vec3 tvec = rayO - a; 41 | // 42 | // bary1 = glm::dot(tvec, pvec) * inv_det; 43 | // 44 | // glm::vec3 qvec = glm::cross(tvec, edge1); 45 | // 46 | // bary2 = glm::dot(rayD, qvec) * inv_det; 47 | // 48 | // t = glm::dot(edge2, qvec) * inv_det; 49 | // 50 | // return(t > EPSILON &&t < tMax && (bary1 >= 0.0f && bary2 >= 0.0f && (bary1 + bary2) <= 1.0f)); 51 | //} -------------------------------------------------------------------------------- /Source/Core/Geometry/Tet.cpp: -------------------------------------------------------------------------------- 1 | #include "Tet.h" -------------------------------------------------------------------------------- /Source/Core/Geometry/Tet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Composition/Component/Component.h" 4 | 5 | #include "Types.h" 6 | #include 7 | 8 | class Tet : Component 9 | { 10 | 11 | public: 12 | 13 | Tet() = default; 14 | ~Tet() = default; 15 | 16 | 17 | glm::uvec4 indices; 18 | uint material; 19 | uint object; 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Core/Geometry/Vertex.cpp: -------------------------------------------------------------------------------- 1 | #include "Vertex.h" -------------------------------------------------------------------------------- /Source/Core/Geometry/Vertex.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Composition/Component/Component.h" 5 | 6 | #include 7 | 8 | 9 | class Vertex : Component 10 | { 11 | 12 | public: 13 | 14 | Vertex() = default; 15 | ~Vertex() = default; 16 | 17 | 18 | glm::vec3 position; 19 | glm::vec3 normal; 20 | glm::vec2 textureCoord; 21 | glm::vec3 velocity; 22 | 23 | uint object; 24 | 25 | }; 26 | 27 | class GUIVertex : Component { 28 | 29 | public: 30 | 31 | GUIVertex() = default; 32 | ~GUIVertex() = default; 33 | 34 | 35 | glm::vec2 position; 36 | glm::vec2 textureCoord; 37 | uint colour; 38 | 39 | }; -------------------------------------------------------------------------------- /Source/Core/Interface/Application/SoulApplication.cpp: -------------------------------------------------------------------------------- 1 | #include "SoulApplication.h" 2 | #include "Soul.h" 3 | 4 | SoulApplication::SoulApplication(SoulParameters params) : 5 | hasControl(true), 6 | parameters(params), 7 | soul(parameters) 8 | { 9 | } 10 | 11 | void SoulApplication::CreateWindow(WindowParameters& params) { 12 | 13 | soul.CreateWindow(params); 14 | 15 | } 16 | 17 | 18 | void SoulApplication::Run() { 19 | 20 | CheckParameters(); 21 | 22 | //EventManager::Listen("Input", "ESCAPE", [](keyState state) { 23 | // if (state == RELEASE) { 24 | // SoulSignalClose(); 25 | // } 26 | //}); 27 | 28 | soul.Init(); 29 | 30 | } 31 | 32 | void SoulApplication::CheckParameters() { 33 | 34 | //TODO 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Source/Core/Interface/Module/DESIGN.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Core/Interface/Module/DESIGN.rst -------------------------------------------------------------------------------- /Source/Core/Interface/Module/Module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Utility/Template/CRTP.h" 4 | 5 | 6 | //Common interface for modules. 7 | template 8 | class Module : public CRTP { 9 | 10 | public: 11 | 12 | virtual ~Module() = default; 13 | 14 | Module(const Module&) = delete; 15 | Module(Module&&) noexcept = default; 16 | 17 | Module& operator=(const Module&) = delete; 18 | Module& operator=(Module&&) noexcept = default; 19 | 20 | 21 | protected: 22 | 23 | Module() = default; 24 | 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /Source/Core/Interface/Project/Project.cpp: -------------------------------------------------------------------------------- 1 | #include "Project.h" 2 | 3 | Project::Project() { 4 | 5 | } 6 | 7 | 8 | const std::filesystem::path& Project::GetDirectory() const { 9 | 10 | return projectPath_; 11 | 12 | } -------------------------------------------------------------------------------- /Source/Core/Interface/Project/Project.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class Project { 7 | 8 | public: 9 | 10 | Project(); 11 | 12 | const std::filesystem::path& GetDirectory() const; 13 | 14 | 15 | private: 16 | 17 | std::filesystem::path projectPath_; 18 | 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /Source/Core/Material/CUDA/ShaderNode.cu: -------------------------------------------------------------------------------- 1 | #include "ShaderNode.cuh" 2 | 3 | ShaderNode::ShaderNode(){ 4 | 5 | } 6 | ShaderNode::~ShaderNode(){ 7 | 8 | 9 | } -------------------------------------------------------------------------------- /Source/Core/Material/CUDA/ShaderNode.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Material/Texture/Image.cuh" 4 | 5 | 6 | class ShaderNode{ 7 | public: 8 | 9 | __host__ ShaderNode(); 10 | __host__ ~ShaderNode(); 11 | 12 | 13 | 14 | private: 15 | 16 | }; 17 | -------------------------------------------------------------------------------- /Source/Core/Material/Colour/CUDA/Colour.cu: -------------------------------------------------------------------------------- 1 | #include "Colour.cuh" 2 | 3 | Colour::Colour(){ 4 | 5 | } 6 | 7 | Colour::~Colour(){ 8 | 9 | } -------------------------------------------------------------------------------- /Source/Core/Material/Colour/CUDA/Colour.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Colour{ 4 | public: 5 | 6 | 7 | Colour(); 8 | ~Colour(); 9 | private: 10 | 11 | }; -------------------------------------------------------------------------------- /Source/Core/Material/Colour/Colour.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Cuda/Colour.cuh" 4 | 5 | //class Image{ 6 | //public: 7 | // int width; 8 | // int height; 9 | // int format; 10 | // unsigned char* pixels; 11 | // 12 | // cudaTextureObject_t texObj; 13 | // 14 | // 15 | // Image(); 16 | // void LoadFromFile(const char*, bool, bool); 17 | // ~Image(); 18 | //private: 19 | // 20 | //}; -------------------------------------------------------------------------------- /Source/Core/Material/Material.cpp: -------------------------------------------------------------------------------- 1 | #include "Material.h" 2 | //#include "Parallelism/ComputeOld/CUDA/Utility/CudaHelper.cuh" 3 | 4 | Material::Material( std::string texName){ 5 | 6 | 7 | 8 | /*CudaCheck(cudaDeviceSynchronize()); 9 | diffuseImage.LoadFromFile(texName.c_str(),false,true); 10 | CudaCheck(cudaDeviceSynchronize());*/ 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Source/Core/Material/Material.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Core/Material/Texture/Image.cuh" 4 | 5 | #include 6 | #include 7 | 8 | class Material { 9 | public: 10 | 11 | Material(std::string texName = "Resources//Textures//SoulDefault.png"); 12 | 13 | glm::vec4 diffuse; 14 | glm::vec4 emit; 15 | 16 | //Image diffuseImage; 17 | 18 | }; 19 | -------------------------------------------------------------------------------- /Source/Core/Material/ShaderNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "CUDA/ShaderNode.cuh" -------------------------------------------------------------------------------- /Source/Core/Material/Texture/Image.cuh: -------------------------------------------------------------------------------- 1 | //#pragma once 2 | // 3 | //#include 4 | // 5 | //class Image{ 6 | //public: 7 | // 8 | // Image(); 9 | // void LoadFromFile(const char*, bool, bool); 10 | // //~Image(); 11 | // 12 | // int width; 13 | // int height; 14 | // int format; 15 | // 16 | // cudaTextureObject_t texObj; 17 | // 18 | // __host__ __device__ bool operator==(const Image& other) const { 19 | // return 20 | // width == other.width && 21 | // height == other.height && 22 | // format == other.format && 23 | // texObj == other.texObj; 24 | // } 25 | // 26 | // __host__ __device__ friend void swap(Image& a, Image& b) 27 | // { 28 | // 29 | // int temp = a.width; 30 | // a.width = b.width; 31 | // b.width = temp; 32 | // 33 | // temp = a.height; 34 | // a.height = b.height; 35 | // b.height = temp; 36 | // 37 | // temp = a.format; 38 | // a.format = b.format; 39 | // b.format = temp; 40 | // 41 | // cudaTextureObject_t temp1 = a.texObj; 42 | // a.texObj = b.texObj; 43 | // b.texObj = temp1; 44 | // 45 | // } 46 | // __host__ __device__ Image& operator=(Image arg) 47 | // { 48 | // this->width = arg.width; 49 | // this->height = arg.height; 50 | // this->format = arg.format; 51 | // this->texObj = arg.texObj; 52 | // 53 | // return *this; 54 | // } 55 | //private: 56 | // 57 | //}; 58 | // 59 | //unsigned char* DirectLoad(const char*, int*, int*, int*); -------------------------------------------------------------------------------- /Source/Core/Object/CUDA/Object.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Core/Material/Material.h" 4 | //#include "Core/Geometry/Vertex.h" 5 | //#include "Core/Geometry/Face.h" 6 | //#include "Core/Geometry/Tet.h" 7 | #include "Core/Geometry/BoundingBox.h" 8 | //#include "Types.h" 9 | // 10 | //#include 11 | 12 | class Object { 13 | 14 | public: 15 | 16 | Object() = default; 17 | //Object(std::string, Material); 18 | //~Object(); 19 | 20 | //bool requestRemoval; 21 | //bool ready; 22 | //bool isStatic; 23 | 24 | //void AddVertices(Vertex*, uint); 25 | //void AddFaces(Face*, uint); 26 | //void ExtractFromFile(const char*); 27 | 28 | //uint verticeAmount; 29 | //uint faceAmount; 30 | //uint tetAmount; 31 | //uint materialAmount; 32 | 33 | //std::vector vertices; 34 | //std::vector faces; 35 | //std::vector tets; 36 | //std::vector materials; 37 | 38 | BoundingBox box; //in object space 39 | 40 | protected: 41 | 42 | private: 43 | 44 | 45 | }; 46 | -------------------------------------------------------------------------------- /Source/Core/Object/Character/Character.cpp: -------------------------------------------------------------------------------- 1 | #include "Character.h" 2 | 3 | /* Resets the callback information. */ 4 | void Character::ResetCallbackInfo(){ 5 | for (int i = 0; i < CallbackInfo.size(); i++){ 6 | (*CallbackInfo[i])=false; 7 | } 8 | } -------------------------------------------------------------------------------- /Source/Core/Object/Character/Character.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Object/Object.h" 4 | #include 5 | 6 | /* 7 | * Increment time. 8 | * @param parameter1 The first parameter. 9 | */ 10 | 11 | void IncrementTime(float); 12 | 13 | /* A character. */ 14 | class Character : public Object{ 15 | public: 16 | 17 | /* 18 | * tag,distance,size. 19 | * @param parameter1 The first parameter. 20 | */ 21 | 22 | virtual void Update(double)=0; 23 | virtual void Load()=0; 24 | 25 | 26 | 27 | /* Information describing the callback */ 28 | std::vector CallbackInfo; 29 | /* Resets the callback information. */ 30 | void ResetCallbackInfo(); 31 | private: 32 | 33 | }; -------------------------------------------------------------------------------- /Source/Core/Object/Loader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Core/Object/Loader.cpp -------------------------------------------------------------------------------- /Source/Core/Object/Loader.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Core/Object/Loader.h -------------------------------------------------------------------------------- /Source/Core/Object/Object.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | class Object { 6 | 7 | public: 8 | 9 | Object() = default; 10 | //Object(std::string, Material); 11 | //~Object(); 12 | 13 | //bool requestRemoval; 14 | //bool ready; 15 | //bool isStatic; 16 | 17 | //void AddVertices(Vertex*, uint); 18 | //void AddFaces(Face*, uint); 19 | //void ExtractFromFile(const char*); 20 | 21 | uint verticeAmount; 22 | uint faceAmount; 23 | uint tetAmount; 24 | uint materialAmount; 25 | 26 | //std::vector vertices; 27 | //std::vector faces; 28 | //std::vector tets; 29 | //std::vector materials; 30 | 31 | //BoundingBox box; //in object space 32 | 33 | protected: 34 | 35 | private: 36 | 37 | 38 | }; 39 | -------------------------------------------------------------------------------- /Source/Core/Scene/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // #include "Core/Object/Object.h" 4 | // #include "Core/Scene/Sky.h" 5 | // #include "Core/Material/Material.h" 6 | // #include "Core/Scene/Bounding Volume Heirarchy/LBVHManager.h" 7 | // //#include "Parallelism/ComputeOld/ComputeBuffer.h" 8 | // #include "Core/Geometry/Face.h" 9 | // #include "Core/Geometry/Vertex.h" 10 | // #include "Core/Geometry/Tet.h" 11 | // 12 | // class Scene 13 | // { 14 | // public: 15 | // 16 | // Scene(); 17 | // ~Scene() = default; 18 | // 19 | // //adds all inthe queue and cleans all in the queue then builds the bvh 20 | // void Build(double deltaTime); 21 | // 22 | // //signels the scene that an object should be added when the next 'Build()' is called 23 | // //modifies the global scene bounding box, making the 3D spatial calculation less accurate 24 | // void AddObject(Object&); 25 | // 26 | // //signels the scene that an object should be removed when the next 'Build()' is called 27 | // //Does NOT modify the global scene bounding box, meaning 3D spatial accuracy will remain as it was 28 | // void RemoveObject(Object&); 29 | // 30 | // //the bvh data for the scene 31 | // //ComputeBuffer BVH; 32 | // 33 | // //the sky data for the scene 34 | // ComputeBuffer sky; 35 | // 36 | // ComputeBuffer faces; 37 | // ComputeBuffer vertices; 38 | // ComputeBuffer tets; 39 | // ComputeBuffer materials; 40 | // //ComputeBuffer objects; 41 | // ComputeBuffer boxes; 42 | // 43 | // private: 44 | // 45 | // //updates the scene representation based on what is in addList or removeList 46 | // void Compile(); 47 | // 48 | // //scene bounding box 49 | // BoundingBox sceneBox; 50 | // 51 | // //bvh for scene management 52 | // //LBVHManager bvh; 53 | // 54 | // //structures for preparing bvh 55 | // ComputeBuffer mortonCodes; //codes for all the faces 56 | // 57 | // }; 58 | // 59 | -------------------------------------------------------------------------------- /Source/Core/Scene/Sky.cpp: -------------------------------------------------------------------------------- 1 | #include "Sky.h" 2 | 3 | Sky::Sky(std::string texName) { 4 | 5 | //image = new Image(); 6 | 7 | //CudaCheck(cudaDeviceSynchronize()); 8 | //image->LoadFromFile(texName.c_str(),true,false); 9 | //CudaCheck(cudaDeviceSynchronize()); 10 | } 11 | 12 | //__device__ glm::vec3 Sky::ExtractColour(const glm::vec3& direction){ 13 | // 14 | // /*float theta = 0.5f + atan2f(direction.z, direction.x)/(2 * PI); 15 | // float gamma = 0.5f - asinf(direction.y)/ PI; 16 | // float4 col = tex2D(image->texObj, theta, gamma );*/ 17 | // 18 | // 19 | // float normalized = direction.y / 2.0f + 0.5f; 20 | // return glm::mix(glm::vec3(255.0f / 255.0f, 255.0f / 255.0f, 255.0f / 255.0f),glm::vec3(135 / 255.0f, 200 / 255.0f, 240 / 255.0f),normalized/2.0f+0.5f)*0.5f; 21 | //} 22 | -------------------------------------------------------------------------------- /Source/Core/Scene/Sky.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Core/Material/Texture/Image.cuh" 4 | #include 5 | #include 6 | 7 | class Sky 8 | { 9 | 10 | public: 11 | Sky(); 12 | Sky(std::string); 13 | 14 | void UpdateSky(); 15 | 16 | //__device__ glm::vec3 ExtractColour(const glm::vec3& direction); 17 | 18 | //Image* image; 19 | 20 | private: 21 | 22 | 23 | 24 | }; 25 | 26 | 27 | -------------------------------------------------------------------------------- /Source/Core/Structure/Acceleration/LBVHManager.cpp: -------------------------------------------------------------------------------- 1 | #include "LBVHManager.h" 2 | //#include "CUDA/BVH.cuh" 3 | //#include "Parallelism/ComputeOld/ComputeManager.h" 4 | 5 | //LBVHManager::LBVHManager() : 6 | // nodes(S_BEST_DEVICE) 7 | //{ 8 | // 9 | //} 10 | // 11 | //void LBVHManager::Build(int size, ComputeBuffer& data, ComputeBuffer& mortonCodes, ComputeBuffer& boxes) { 12 | // 13 | // if (size > 0) { 14 | // 15 | // const GPUExecutePolicy normalPolicy(size, 64, 0, 0); 16 | // 17 | // nodes.ResizeDevice(size); // size-1 nodes are actually used. 1 is tacked on to remove conditional statements 18 | // 19 | // data[0].leafSize = size; 20 | // data[0].nodes = nodes.DataDevice(); 21 | // data[0].boxes = boxes.DataDevice(); 22 | // data.TransferToDevice(); 23 | // 24 | // ComputeDevice device = S_BEST_DEVICE; 25 | // 26 | // 27 | // device.Launch(normalPolicy, Reset, 28 | // size, 29 | // nodes.DataDevice()); 30 | // 31 | // device.Launch(normalPolicy, BuildTree, 32 | // size, 33 | // data.DataDevice(), 34 | // nodes.DataDevice(), 35 | // mortonCodes.DataDevice(), 36 | // boxes.DataDevice()); 37 | // 38 | // } 39 | //} -------------------------------------------------------------------------------- /Source/Core/Structure/Acceleration/LBVHManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Parallelism/ComputeOld/ComputeBuffer.h" 4 | #include "Core/Geometry/BoundingBox.h" 5 | 6 | //#include "CUDA/BVH.cuh" 7 | 8 | //class LBVHManager { 9 | // 10 | //public: 11 | // 12 | // LBVHManager(); 13 | // 14 | // //void Build(int, ComputeBuffer&, ComputeBuffer&, ComputeBuffer&); 15 | // 16 | // 17 | //private: 18 | // 19 | // //ComputeBuffer nodes; 20 | // 21 | //}; 22 | -------------------------------------------------------------------------------- /Source/Core/Structure/Acceleration/Node.cpp: -------------------------------------------------------------------------------- 1 | #include "Node.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Core/Structure/Acceleration/Node.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Geometry/BoundingBox.h" 4 | #include "Types.h" 5 | 6 | class Node 7 | { 8 | 9 | public: 10 | 11 | BoundingBox box; 12 | 13 | uint childLeft; 14 | uint rangeLeft; 15 | 16 | uint childRight; 17 | uint rangeRight; 18 | 19 | uint atomic; 20 | 21 | }; -------------------------------------------------------------------------------- /Source/Core/Structure/External/ExternalBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Structure/ExternalStructure.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | template 11 | class ExternalBuffer : public ExternalStructure { 12 | 13 | using size_type = size_t; 14 | 15 | public: 16 | 17 | ExternalBuffer() = default; 18 | ~ExternalBuffer() override = default; 19 | 20 | constexpr ExternalBuffer& operator=(const nonstd::span span) noexcept; 21 | 22 | 23 | }; 24 | 25 | template 26 | constexpr ExternalBuffer& ExternalBuffer::operator=(const nonstd::span span) noexcept 27 | { 28 | data = span; 29 | return *this; 30 | } 31 | -------------------------------------------------------------------------------- /Source/Core/Structure/ExternalStructure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Structure.h" 4 | #include "StructureConcepts.h" 5 | #include "Span.h" 6 | 7 | template 8 | class ExternalStructure : public Structure, public Contiguous { 9 | 10 | public: 11 | 12 | ExternalStructure() = default; 13 | virtual ~ExternalStructure() = default; 14 | 15 | constexpr ExternalStructure& operator=(const nonstd::span span); 16 | 17 | protected: 18 | 19 | nonstd::span data; 20 | 21 | }; 22 | 23 | template 24 | constexpr ExternalStructure& ExternalStructure::operator=(const nonstd::span span) 25 | { 26 | data = span; 27 | return *this; 28 | } 29 | -------------------------------------------------------------------------------- /Source/Core/Structure/Sparse/SparseArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Structure/SparseStructure.h" 5 | #include "SparseBitMap.h" 6 | #include "Core/Utility/Exception/Exception.h" 7 | 8 | #include 9 | #include 10 | 11 | template 12 | class SparseArray final : public SparseStructure { 13 | 14 | using size_type = size_t; 15 | 16 | static constexpr size_type blockCount_ = (N + GroupSize - 1) / GroupSize; 17 | 18 | public: 19 | 20 | SparseArray() = default; 21 | ~SparseArray() override = default; 22 | 23 | T& operator[](size_type); 24 | bool Test(size_type) const; 25 | 26 | private: 27 | 28 | std::array, blockCount_> data_; 29 | 30 | 31 | }; 32 | 33 | template 34 | T& SparseArray::operator[](size_type index) 35 | { 36 | 37 | throw NotImplemented(); 38 | 39 | } 40 | 41 | template 42 | bool SparseArray::Test(size_type index) const 43 | { 44 | 45 | throw NotImplemented(); 46 | 47 | } -------------------------------------------------------------------------------- /Source/Core/Structure/Sparse/SparseHashSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Structure/SparseStructure.h" 5 | #include "SparseVector.h" 6 | #include "Core/Utility/Exception/Exception.h" 7 | 8 | #include 9 | #include 10 | 11 | 12 | template> 13 | class SparseHashSet final : public SparseStructure { 14 | 15 | using size_type = size_t; 16 | 17 | static constexpr size_type blockSize_ = 8; 18 | 19 | public: 20 | 21 | SparseHashSet() = default; 22 | ~SparseHashSet() override = default; 23 | 24 | 25 | private: 26 | 27 | SparseVector indirectionTable_; 28 | std::vector keys_; 29 | 30 | 31 | }; -------------------------------------------------------------------------------- /Source/Core/Structure/SparseStructure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Structure.h" 4 | 5 | class SparseStructure : public Structure{ 6 | 7 | public: 8 | 9 | SparseStructure() = default; 10 | virtual ~SparseStructure() = default; 11 | 12 | 13 | }; -------------------------------------------------------------------------------- /Source/Core/Structure/Structure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Structure{ 4 | 5 | public: 6 | 7 | Structure() = default; 8 | virtual ~Structure() = default; 9 | 10 | 11 | }; -------------------------------------------------------------------------------- /Source/Core/Structure/StructureConcepts.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Contiguous { 4 | 5 | public: 6 | 7 | Contiguous() = default; 8 | ~Contiguous() = default; 9 | 10 | 11 | }; -------------------------------------------------------------------------------- /Source/Core/Structure/View.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // TODO: replace with C++20 4 | #include "Span.h" 5 | 6 | #include 7 | #include 8 | 9 | 10 | template 11 | class View { 12 | 13 | using size_type = size_t; 14 | 15 | // TODO: std::unique_function C++20 16 | using function_type = std::function; 17 | 18 | public: 19 | 20 | constexpr View(); 21 | constexpr View(T* ptr, size_type count); 22 | virtual ~View() = default; 23 | 24 | T& operator[](size_type); 25 | 26 | void Map(function_type&& function); 27 | 28 | 29 | private: 30 | 31 | std::optional indexMap_; 32 | 33 | //TODO: replace with std::span C++20 34 | nonstd::span data_; 35 | 36 | 37 | }; 38 | 39 | template 40 | constexpr View::View(): data_(nullptr, size_) 41 | { 42 | } 43 | 44 | template 45 | constexpr View::View(T* ptr, size_type count): data_(ptr, count) 46 | { 47 | } 48 | 49 | template 50 | T& View::operator[](size_type index) 51 | { 52 | if (!indexMap_.has_value()) { 53 | return data_[index]; 54 | } 55 | 56 | return data_[*indexMap_(index)]; 57 | 58 | } 59 | 60 | template 61 | void View::Map(function_type&& function) 62 | { 63 | 64 | indexMap_.emplace(std::move(myFunction)) 65 | 66 | } -------------------------------------------------------------------------------- /Source/Core/System/Compiler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class CompilerID { VisualStudio, GCC, Clang, Emscripten, Unknown }; 4 | 5 | class Compiler { 6 | 7 | public: 8 | 9 | constexpr static CompilerID GetCompiler(); 10 | constexpr static bool Debug(); 11 | 12 | 13 | private: 14 | 15 | #if defined(_MSC_VER) 16 | 17 | constexpr static CompilerID compiler_ = CompilerID::VisualStudio; 18 | 19 | #elif defined(__GNUC__) 20 | 21 | constexpr static CompilerID compiler_ = CompilerID::GCC; 22 | 23 | #elif defined(__clang__) 24 | 25 | constexpr static CompilerID compiler_ = CompilerID::Clang; 26 | 27 | #elif defined(__EMSCRIPTEN__) 28 | 29 | constexpr static CompilerID compiler_ = CompilerID::Emscripten; 30 | 31 | #else 32 | 33 | constexpr static CompilerID compiler_ = CompilerID::Unknown; 34 | 35 | #endif 36 | 37 | //TODO: Update debug macro 38 | #if defined(NDEBUG) 39 | 40 | constexpr static bool debug_ = false; 41 | 42 | #else 43 | 44 | constexpr static bool debug_ = true; 45 | 46 | #endif 47 | 48 | 49 | }; 50 | 51 | constexpr CompilerID Compiler::GetCompiler() { 52 | return compiler_; 53 | } 54 | 55 | constexpr bool Compiler::Debug() { 56 | return debug_; 57 | } -------------------------------------------------------------------------------- /Source/Core/System/Platform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class PlatformID { Windows, OSX, Linux, Android, Unknown }; 4 | 5 | class Platform { 6 | 7 | public: 8 | 9 | constexpr static PlatformID GetPlatform(); 10 | constexpr static bool IsDesktop(); 11 | 12 | private: 13 | 14 | #if defined(__linux__) && !defined(__ANDROID__) 15 | 16 | constexpr static PlatformID platform_ = PlatformID::Linux; 17 | 18 | #elif defined(_WIN64) 19 | 20 | constexpr static PlatformID platform_ = PlatformID::Windows; 21 | 22 | #elif defined(__APPLE__) 23 | 24 | constexpr static PlatformID platform_ = PlatformID::OSX; 25 | 26 | #elif defined(__ANDROID__) 27 | 28 | constexpr static PlatformID platform_ = PlatformID::Android; 29 | 30 | #else 31 | 32 | constexpr static PlatformID platform_ = PlatformID::Unknown; 33 | 34 | #endif 35 | 36 | }; 37 | 38 | constexpr PlatformID Platform::GetPlatform() { 39 | return platform_; 40 | } 41 | 42 | constexpr bool Platform::IsDesktop() { 43 | return platform_ == PlatformID::Linux || 44 | platform_ == PlatformID::Windows || 45 | platform_ == PlatformID::OSX; 46 | } -------------------------------------------------------------------------------- /Source/Core/Utility/Exception/Exception.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class NotImplemented : public std::logic_error 7 | { 8 | 9 | public: 10 | 11 | NotImplemented() : std::logic_error("Function is not yet implemented") { 12 | }; 13 | 14 | }; -------------------------------------------------------------------------------- /Source/Core/Utility/Function/function_ref.cpp: -------------------------------------------------------------------------------- 1 | #include "function_ref.h" 2 | -------------------------------------------------------------------------------- /Source/Core/Utility/Function/function_ref.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class function_ref 4 | { 5 | 6 | public: 7 | 8 | private: 9 | 10 | }; -------------------------------------------------------------------------------- /Source/Core/Utility/HashString/HashString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include 6 | 7 | class HashString final { 8 | 9 | public: 10 | 11 | //typedefs 12 | using HashType = uint64; 13 | 14 | //construction 15 | explicit constexpr HashString(std::string_view); 16 | 17 | //operators 18 | constexpr operator std::string_view() const; 19 | constexpr operator HashType() const; 20 | 21 | constexpr bool operator==(const HashString &other) const; 22 | constexpr bool operator!=(const HashString &other) const; 23 | 24 | private: 25 | 26 | constexpr static HashType Hash(HashType, std::string_view); 27 | 28 | //hash constants 29 | constexpr static HashType offset = 0xcbf29ce484222325; 30 | constexpr static HashType prime = 0x100000001b3; 31 | 32 | const HashType hash_; 33 | std::string_view string_; 34 | 35 | }; 36 | 37 | constexpr HashString::HashString(std::string_view string) : 38 | hash_(Hash(offset, string)), 39 | string_(string) 40 | { 41 | } 42 | 43 | //cast of the data as a readable string 44 | constexpr HashString::operator std::string_view() const { 45 | return string_; 46 | } 47 | 48 | //cast of the data as a numerical value 49 | constexpr HashString::operator HashType() const { 50 | return hash_; 51 | } 52 | 53 | constexpr bool HashString::operator==(const HashString &other) const { 54 | return hash_ == other.hash_; 55 | } 56 | 57 | constexpr bool HashString::operator!=(const HashString &other) const { 58 | return hash_ != other.hash_; 59 | } 60 | 61 | constexpr HashString::HashType HashString::Hash(HashType offset, std::string_view string) { 62 | return !string.empty() ? offset : Hash((offset^string[0])*prime, string.substr(1)); 63 | } 64 | 65 | constexpr HashString operator"" _hashed(const char* str, std::size_t) { 66 | return HashString{ str }; 67 | } -------------------------------------------------------------------------------- /Source/Core/Utility/ID/ClassID.cpp: -------------------------------------------------------------------------------- 1 | #include "ClassID.h" 2 | 3 | std::atomic ClassID::counter_ = 0; 4 | -------------------------------------------------------------------------------- /Source/Core/Utility/ID/ClassID.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class ClassID 7 | { 8 | 9 | public: 10 | 11 | ClassID() = delete; 12 | 13 | template 14 | static size_t ID() noexcept; 15 | 16 | 17 | private: 18 | 19 | static std::atomic counter_; 20 | 21 | template 22 | static size_t GenerateID() noexcept; 23 | 24 | }; 25 | 26 | 27 | template 28 | size_t ClassID::ID() noexcept 29 | { 30 | return GenerateID...>(); 31 | } 32 | 33 | template 34 | size_t ClassID::GenerateID() noexcept { 35 | static const size_t value = counter_.fetch_add(1); 36 | return value; 37 | } 38 | -------------------------------------------------------------------------------- /Source/Core/Utility/ID/TypeID.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include 6 | 7 | template 8 | class TypeID 9 | { 10 | 11 | public: 12 | 13 | TypeID(); 14 | 15 | 16 | protected: 17 | 18 | uint id_; 19 | 20 | private: 21 | 22 | static std::atomic counter_; 23 | 24 | }; 25 | 26 | 27 | template 28 | TypeID::TypeID(): 29 | id_(++counter_) 30 | { 31 | } 32 | 33 | 34 | template 35 | std::atomic TypeID::counter_ = 0; -------------------------------------------------------------------------------- /Source/Core/Utility/Log/Logger.cpp: -------------------------------------------------------------------------------- 1 | #include "Logger.h" 2 | 3 | std::string LogSeverityStrings[4]{ 4 | "TRACE", 5 | "WARNING", 6 | "ERROR", 7 | "FATAL" 8 | }; 9 | 10 | /* The log mut */ 11 | std::mutex logMut; 12 | /* The storage */ 13 | std::deque storage; 14 | 15 | /* 16 | * Writes an information. 17 | * @param [in,out] oss The oss. 18 | * @param file The file. 19 | * @param line The line. 20 | */ 21 | 22 | void WriteInfo(std::ostream& oss, const char* file, int line) { 23 | oss << "File: TODO" << " Line: " << line << " | "; 24 | } 25 | 26 | 27 | /* 28 | * Gets the get. 29 | * @return A std::string. 30 | */ 31 | 32 | std::string Get() { 33 | logMut.lock(); 34 | if (storage.empty() > 0) { 35 | 36 | Logger::LogI temp = storage.front(); 37 | storage.pop_front(); 38 | logMut.unlock(); 39 | 40 | return ("[" + LogSeverityStrings[static_cast(temp.severity)] + "] " + temp.msg + "/n"); 41 | } 42 | else { 43 | logMut.unlock(); 44 | return std::string(); 45 | } 46 | } 47 | 48 | void WriteFile() 49 | { 50 | //TODO 51 | } 52 | -------------------------------------------------------------------------------- /Source/Core/Utility/Morton/CUDA/MortonCode.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Types.h" 4 | //#include "Core/Scene/Bounding Volume Heirarchy/LBVHManager.h" 5 | // 6 | //#include "Core/Geometry/Face.h" 7 | //#include "Core/Geometry/Vertex.h" 8 | 9 | //namespace MortonCode{ 10 | // 11 | // 12 | // __global__ void ComputeGPUFace64(uint n, uint64* mortonCodes, Face* faces, Vertex* vertices); 13 | // 14 | // __global__ void ComputeGPU64(uint n, uint64* mortonCodes, glm::uvec2* data); 15 | // 16 | // 17 | // //given a point in space with the range [-1,1] for each dimension 18 | // __host__ __device__ uint64 Calculate64_3D(const glm::vec3&); 19 | // 20 | // //given a point in space with the range [-1,1] for each dimension 21 | // __host__ __device__ uint64 Calculate64_2D(const glm::vec2&); 22 | // 23 | // //returns a point in space with the range [-1,1] for each dimension 24 | // __host__ __device__ glm::vec3 Decode64_3D(const uint64); 25 | // 26 | // //returns a point in space with the range [-1,1] for each dimension 27 | // __host__ __device__ glm::vec2 Decode64_2D(const uint64); 28 | // 29 | // //given a point in space with the range [0,UINT_MAX] for each dimension NOTICE: only first 21 bits used 30 | // __host__ __device__ uint64 Calculate64_3D(const glm::uvec3&); 31 | // 32 | // //given a point in space with the range [0,UINT_MAX] for each dimension 33 | // __host__ __device__ uint64 Calculate64_2D(const glm::uvec2&); 34 | // 35 | // //returns a point in space with the range [0,UINT_MAX] for each dimension NOTICE: only first 21 bits used 36 | // __host__ __device__ glm::uvec3 Decode64U_3D(const uint64); 37 | // 38 | // //returns a point in space with the range [0,UINT_MAX] for each dimension 39 | // __host__ __device__ glm::uvec2 Decode64U_2D(const uint64); 40 | //} -------------------------------------------------------------------------------- /Source/Core/Utility/Morton/MortonCode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //# if defined(__CUDACC__) 4 | 5 | //#include "CUDA/MortonCode.cuh" 6 | 7 | //# else 8 | // 9 | //#include "OpenCL/MortonCode.h" 10 | // 11 | //#endif -------------------------------------------------------------------------------- /Source/Core/Utility/Property/Property.cpp: -------------------------------------------------------------------------------- 1 | #include "Property.h" 2 | //templated class -------------------------------------------------------------------------------- /Source/Core/Utility/Template/CRTP.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | template class ClassType> 5 | class CRTP 6 | { 7 | 8 | public: 9 | 10 | ~CRTP() = default; //No VTable 11 | 12 | CRTP(const CRTP&) = default; 13 | CRTP(CRTP&&) noexcept = default; 14 | 15 | CRTP& operator=(const CRTP&) = default; 16 | CRTP& operator=(CRTP&&) noexcept = default; 17 | 18 | 19 | //return the derived class 20 | T& Type(); 21 | T const& Type() const; 22 | 23 | 24 | private: 25 | 26 | CRTP() = default; 27 | 28 | friend ClassType; 29 | 30 | 31 | }; 32 | 33 | template class ClassType> 34 | T& CRTP::Type() { 35 | 36 | return static_cast(*this); 37 | 38 | } 39 | 40 | template class ClassType> 41 | T const& CRTP::Type() const { 42 | 43 | return static_cast(*this); 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Source/Core/Utility/Template/Optional.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | //std extensions, so follows same style 6 | template 7 | struct dependent_false : std::false_type {}; 8 | 9 | template 10 | constexpr auto dependent_false_v = dependent_false::value; -------------------------------------------------------------------------------- /Source/Core/Utility/Template/TypeTraits.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | //std extensions, so follows same style 6 | template 7 | struct dependent_false : std::false_type {}; 8 | 9 | template 10 | constexpr auto dependent_false_v = dependent_false::value; -------------------------------------------------------------------------------- /Source/Core/Utility/Thread/ThreadLocal.cpp: -------------------------------------------------------------------------------- 1 | #include "ThreadLocal.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Core/Utility/Thread/ThreadLocal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | //Convenience class masking static memory for thread local storage on a per object basis 6 | template 7 | class ThreadLocal { 8 | 9 | public: 10 | 11 | ThreadLocal(); 12 | ~ThreadLocal(); 13 | 14 | ThreadLocal(const ThreadLocal&) = delete; 15 | ThreadLocal(ThreadLocal&& o) noexcept = default; 16 | 17 | ThreadLocal& operator=(const ThreadLocal&) = delete; 18 | ThreadLocal& operator=(ThreadLocal&& other) noexcept = default; 19 | 20 | ThreadLocal(const T&); 21 | ThreadLocal& operator= (const T&); 22 | operator T&() const; 23 | 24 | 25 | private: 26 | 27 | int id_; 28 | 29 | static int counter_; 30 | static thread_local std::unordered_map objectMap_; 31 | 32 | }; 33 | 34 | template 35 | ThreadLocal::ThreadLocal(): 36 | id_(counter_++) 37 | { 38 | } 39 | 40 | template 41 | ThreadLocal::ThreadLocal(const T& value): 42 | ThreadLocal() 43 | { 44 | 45 | objectMap_[id_] = value; 46 | 47 | } 48 | 49 | template 50 | ThreadLocal::~ThreadLocal() 51 | { 52 | 53 | objectMap_.erase(id_); 54 | 55 | } 56 | 57 | template 58 | ThreadLocal& ThreadLocal::operator= (const T& value) { 59 | 60 | objectMap_[id_] = value; 61 | return *this; 62 | 63 | } 64 | 65 | template 66 | ThreadLocal::operator T&() const { 67 | 68 | return objectMap_[id_]; 69 | 70 | } 71 | 72 | template 73 | int ThreadLocal::counter_ = 0; 74 | 75 | template 76 | thread_local std::unordered_map ThreadLocal::objectMap_; -------------------------------------------------------------------------------- /Source/Core/Utility/Timer/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "Timer.h" 2 | 3 | /* Default constructor. */ 4 | Timer::Timer() { 5 | Reset(); 6 | } 7 | /* Destructor. */ 8 | Timer::~Timer() { 9 | 10 | } 11 | 12 | /* Resets this object. */ 13 | void Timer::Reset() { 14 | 15 | tickHold = Clock::now(); 16 | 17 | } 18 | 19 | /* 20 | * Gets the elapsed. 21 | * @return A double. 22 | */ 23 | 24 | double Timer::Elapsed() { 25 | 26 | std::chrono::duration ms = Clock::now() - tickHold; 27 | return ms.count(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Source/Core/Utility/Timer/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | /* A timer. */ 6 | class Timer { 7 | public: 8 | /* Default constructor. */ 9 | Timer(); 10 | /* Destructor. */ 11 | ~Timer(); 12 | 13 | /* Resets the Timer. */ 14 | void Reset(); 15 | 16 | /* 17 | * returns the elapsed time since the last reset in milliseconds. 18 | * @return The elapsed time in milliseconds. 19 | */ 20 | 21 | double Elapsed(); 22 | 23 | private: 24 | /* Defines an alias representing the clock. */ 25 | typedef std::chrono::high_resolution_clock Clock; 26 | /* Defines an alias representing the timestamp. */ 27 | typedef std::chrono::time_point Timestamp; 28 | 29 | /* The tick hold */ 30 | Timestamp tickHold; 31 | }; -------------------------------------------------------------------------------- /Source/DESIGN.rst: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/DESIGN.rst -------------------------------------------------------------------------------- /Source/Display/GUI/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #GUI 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | GUIModule.cpp 8 | GUIModule.h 9 | Layout.h 10 | Modules/Imgui/EmptyWidget.h 11 | Modules/Imgui/ImguiBackend.cpp 12 | Modules/Imgui/ImguiBackend.h 13 | Modules/Imgui/ImguiConfig.h 14 | Modules/Imgui/ImguiLayout.cpp 15 | Modules/Imgui/ImguiLayout.h 16 | Modules/Imgui/ImguiWidget.cpp 17 | Modules/Imgui/ImguiWidget.h 18 | Modules/Imgui/RenderWidget.h 19 | Modules/Imgui/SingleLayout.h 20 | Widget.h 21 | ) 22 | -------------------------------------------------------------------------------- /Source/Display/GUI/GUIModule.cpp: -------------------------------------------------------------------------------- 1 | #include "GUIModule.h" 2 | 3 | #include "Core/System/Platform.h" 4 | #include "Modules/Imgui/ImguiBackend.h" 5 | 6 | 7 | // TODO: There will only ever be one DisplayModule system per Soul application. This will need to be 8 | // moved to the build system per platform 9 | std::shared_ptr GUIModule::CreateModule(std::shared_ptr& inputModule, 10 | std::shared_ptr& windowModule, 11 | std::shared_ptr& renderGraphModule) 12 | { 13 | 14 | if constexpr (Platform::IsDesktop()) { 15 | return std::make_shared(inputModule, windowModule, renderGraphModule); 16 | } 17 | else { 18 | return nullptr; 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Display/GUI/GUIModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Interface/Module/Module.h" 4 | 5 | #include 6 | #include 7 | 8 | class InputModule; 9 | class WindowModule; 10 | class RenderGraphModule; 11 | 12 | class GUIModule : public Module { 13 | 14 | public: 15 | 16 | GUIModule() = default; 17 | virtual ~GUIModule() = default; 18 | 19 | GUIModule(const GUIModule&) = delete; 20 | GUIModule(GUIModule&&) noexcept = default; 21 | 22 | GUIModule& operator=(const GUIModule&) = delete; 23 | GUIModule& operator=(GUIModule&&) noexcept = default; 24 | 25 | 26 | virtual void Update(std::chrono::nanoseconds) = 0; 27 | 28 | // Factory 29 | static std::shared_ptr CreateModule(std::shared_ptr&, 30 | std::shared_ptr&, 31 | std::shared_ptr&); 32 | 33 | 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /Source/Display/GUI/Layout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Widget.h" 4 | 5 | #include 6 | #include 7 | 8 | class Layout : public Widget 9 | { 10 | 11 | public: 12 | 13 | Layout() = default; 14 | virtual ~Layout() = default; 15 | 16 | Layout(const Layout&) = delete; 17 | Layout(Layout&&) noexcept = default; 18 | 19 | Layout& operator=(const Layout&) = delete; 20 | Layout& operator=(Layout&&) noexcept = default; 21 | 22 | template 23 | T& AddLayout(Args&&...); 24 | 25 | template 26 | T& AddWidget(Args&&...); 27 | 28 | protected: 29 | 30 | std::vector> widgets_; 31 | 32 | }; 33 | 34 | template 35 | T& Layout::AddLayout(Args&&... args) { 36 | widgets_.push_back(std::make_unique(std::forward(args)...)); 37 | return *static_cast(widgets_.back().get()); 38 | } 39 | 40 | template 41 | T& Layout::AddWidget(Args&&... args) { 42 | widgets_.push_back(std::make_unique(std::forward(args)...)); 43 | return *static_cast(widgets_.back().get()); 44 | } 45 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/EmptyWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ImguiWidget.h" 4 | 5 | 6 | class EmptyWidget : public ImguiWidget 7 | { 8 | 9 | public: 10 | 11 | EmptyWidget() = default; 12 | ~EmptyWidget() = default; 13 | 14 | EmptyWidget(const EmptyWidget&) = delete; 15 | EmptyWidget(EmptyWidget&&) noexcept = default; 16 | 17 | EmptyWidget& operator=(const EmptyWidget&) = delete; 18 | EmptyWidget& operator=(EmptyWidget&&) noexcept = default; 19 | 20 | 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/GUI/GUIModule.h" 4 | 5 | class ImguiBackend final : public GUIModule { 6 | 7 | public: 8 | 9 | ImguiBackend(std::shared_ptr&, 10 | std::shared_ptr&, 11 | std::shared_ptr&); 12 | ~ImguiBackend() override; 13 | 14 | ImguiBackend(const ImguiBackend&) = delete; 15 | ImguiBackend(ImguiBackend&&) noexcept = default; 16 | 17 | ImguiBackend& operator=(const ImguiBackend&) = delete; 18 | ImguiBackend& operator=(ImguiBackend&&) noexcept = default; 19 | 20 | 21 | void Update(std::chrono::nanoseconds) override; 22 | 23 | private: 24 | 25 | void ConvertRetained(); 26 | 27 | std::shared_ptr inputModule_; 28 | std::shared_ptr windowModule_; 29 | std::shared_ptr renderGraphModule_; 30 | 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 6 | 7 | #define IM_VEC2_CLASS_EXTRA \ 8 | ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \ 9 | operator glm::vec2() const \ 10 | { \ 11 | return glm::vec2(x, y); \ 12 | } 13 | 14 | #define IM_VEC4_CLASS_EXTRA \ 15 | ImVec4(const glm::vec4& f) \ 16 | { \ 17 | x = f.x; \ 18 | y = f.y; \ 19 | z = f.z; \ 20 | w = f.w; \ 21 | } \ 22 | operator glm::vec4() const \ 23 | { \ 24 | return glm::vec4(x, y, z, w); \ 25 | } 26 | 27 | #define ImDrawIdx uint32 -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "ImguiLayout.h" 2 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiLayout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/GUI/Layout.h" 4 | 5 | 6 | class ImguiLayout : public Layout 7 | { 8 | 9 | public: 10 | 11 | ImguiLayout() = default; 12 | ~ImguiLayout() override = default; 13 | 14 | ImguiLayout(const ImguiLayout&) = delete; 15 | ImguiLayout(ImguiLayout&&) noexcept = default; 16 | 17 | ImguiLayout& operator=(const ImguiLayout&) = delete; 18 | ImguiLayout& operator=(ImguiLayout&&) noexcept = default; 19 | 20 | 21 | }; 22 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "ImguiWidget.h" 2 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/ImguiWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/GUI/Widget.h" 4 | 5 | 6 | class ImguiWidget : public Widget { 7 | 8 | public: 9 | 10 | ImguiWidget() = default; 11 | ~ImguiWidget() override = default; 12 | 13 | ImguiWidget(const ImguiWidget&) = delete; 14 | ImguiWidget(ImguiWidget&&) noexcept = default; 15 | 16 | ImguiWidget& operator=(const ImguiWidget&) = delete; 17 | ImguiWidget& operator=(ImguiWidget&&) noexcept = default; 18 | 19 | 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/RenderWidget.cu: -------------------------------------------------------------------------------- 1 | #include "RenderWidget.cuh" 2 | #include "Parallelism/Compute/CUDA/Utility/CUDAHelper.cuh" 3 | #include "Parallelism/Compute/DeviceAPI.h" 4 | 5 | //static uint allocatedSize = 0; 6 | //static uint* deviceWeights = 0; 7 | // 8 | //__global__ void IntegrateKernal(const uint n, glm::vec4* A, glm::vec4* B, int* mask, uint* weights, const uint counter) { 9 | // 10 | // 11 | // uint index = ThreadIndex1D(); 12 | // 13 | // if (index >= n) { 14 | // return; 15 | // } 16 | // 17 | // if (mask[index] > 0) { 18 | // weights[index]++; 19 | // 20 | // B[index] = glm::mix(B[index], A[index], 1.0f / weights[index]); 21 | // } 22 | // 23 | // A[index] = B[index]; 24 | // 25 | //} 26 | // 27 | // 28 | //__host__ void Integrate(uint size, glm::vec4* A, glm::vec4* B, int* mask, const uint counter) { 29 | // 30 | // if (size > allocatedSize) { 31 | // allocatedSize = size; 32 | // CudaCheck(cudaMalloc((void**)&deviceWeights, size * sizeof(uint))); 33 | // } 34 | // 35 | // //clear b and deviceWeights 36 | // if (counter == 1) { 37 | // cudaMemset(deviceWeights, 0, size * sizeof(uint)); 38 | // cudaMemset(B, 0, size * sizeof(glm::vec4)); 39 | // } 40 | // 41 | // uint blockSize = 64; 42 | // uint gridSize = (size + blockSize - 1) / blockSize; 43 | // 44 | // IntegrateKernal << > > (size, A, B, mask, deviceWeights, counter); 45 | // CudaCheck(cudaPeekAtLastError()); 46 | // CudaCheck(cudaDeviceSynchronize()); 47 | // 48 | //} -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/RenderWidget.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Tracer/RayJob.h" 4 | //#include "glm/glm.hpp" 5 | // 6 | //__host__ void Integrate(uint, glm::vec4*, glm::vec4*, int*,const uint); -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/RenderWidget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ImguiWidget.h" 4 | 5 | 6 | class RenderWidget : public ImguiWidget 7 | { 8 | 9 | public: 10 | 11 | RenderWidget() = default; 12 | ~RenderWidget() override = default; 13 | 14 | RenderWidget(const RenderWidget&) = delete; 15 | RenderWidget(RenderWidget&&) noexcept = default; 16 | 17 | RenderWidget& operator=(const RenderWidget&) = delete; 18 | RenderWidget& operator=(RenderWidget&&) noexcept = default; 19 | 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /Source/Display/GUI/Modules/Imgui/SingleLayout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ImguiLayout.h" 4 | 5 | 6 | //A Layout with a single widget slot, covering its entire screenspace 7 | class SingleLayout : public ImguiLayout 8 | { 9 | 10 | public: 11 | 12 | SingleLayout() = default; 13 | ~SingleLayout() override = default; 14 | 15 | SingleLayout(const SingleLayout&) = delete; 16 | SingleLayout(SingleLayout&&) noexcept = default; 17 | 18 | SingleLayout& operator=(const SingleLayout&) = delete; 19 | SingleLayout& operator=(SingleLayout&&) noexcept = default; 20 | 21 | 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /Source/Display/GUI/Widget.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "glm/glm.hpp" 4 | #include "Core/Composition/Component/Component.h" 5 | 6 | #include 7 | 8 | 9 | class Widget : public Component{ 10 | 11 | public: 12 | 13 | Widget() = default; 14 | virtual ~Widget() = default; 15 | 16 | 17 | protected: 18 | 19 | //sub-pixel values 20 | glm::dvec2 size_; 21 | glm::dvec2 position_; //upper left position 22 | 23 | //Gets 24 | bool DirtyFlag() const; //flag 0 25 | 26 | //Sets 27 | void DirtyFlag(bool); 28 | 29 | 30 | private: 31 | 32 | std::bitset<1> flags_; 33 | 34 | 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /Source/Display/Input/Button.cpp: -------------------------------------------------------------------------------- 1 | #include "Button.h" 2 | 3 | Button::Button(): 4 | timeToRepeat(50.0f), 5 | state(ButtonState::OPEN) 6 | { 7 | } -------------------------------------------------------------------------------- /Source/Display/Input/Button.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Utility/Timer/Timer.h" 4 | 5 | enum class ButtonState { PRESS, REPEAT, RELEASE, OPEN }; 6 | 7 | class Button { 8 | 9 | public: 10 | 11 | Button(); 12 | 13 | float timeToRepeat; //in milliseconds 14 | Timer sincePress; 15 | 16 | 17 | ButtonState state; 18 | 19 | }; 20 | -------------------------------------------------------------------------------- /Source/Display/Input/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Input 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Button.h 8 | Button.cpp 9 | InputModule.h 10 | InputModule.cpp 11 | InputSet.h 12 | Modules/GLFW/GLFWInputBackend.cpp 13 | Modules/GLFW/GLFWInputBackend.h 14 | Modules/Mock/MockInputBackend.cpp 15 | Modules/Mock/MockInputBackend.h 16 | ) 17 | -------------------------------------------------------------------------------- /Source/Display/Input/InputModule.cpp: -------------------------------------------------------------------------------- 1 | #include "InputModule.h" 2 | #include "Core/System/Platform.h" 3 | 4 | #include "Modules/GLFW/GLFWInputBackend.h" 5 | 6 | void InputModule::AddMousePositionCallback(std::function callback) 7 | { 8 | 9 | mousePositionCallbacks_.push_back(callback); 10 | 11 | } 12 | 13 | void InputModule::AddMouseButtonCallback(std::function callback) 14 | { 15 | 16 | mouseButtonCallbacks_.push_back(callback); 17 | 18 | } 19 | 20 | 21 | //TODO: There will only ever be one DisplayModule system per Soul application. This will need to be moved to the build system per platform 22 | std::unique_ptr InputModule::CreateModule() 23 | { 24 | 25 | if constexpr (Platform::IsDesktop()) { 26 | return std::make_unique(); 27 | } 28 | else { 29 | return nullptr; 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /Source/Display/Input/InputModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | #include "Core/Interface/Module/Module.h" 5 | #include "InputSet.h" 6 | #include "Button.h" 7 | 8 | #include 9 | #include 10 | 11 | 12 | class Window; 13 | 14 | 15 | class InputModule : Module { 16 | 17 | public: 18 | 19 | InputModule() = default; 20 | virtual ~InputModule() = default; 21 | 22 | InputModule(const InputModule&) = delete; 23 | InputModule(InputModule&&) noexcept = default; 24 | 25 | InputModule& operator=(const InputModule&) = delete; 26 | InputModule& operator=(InputModule&&) noexcept = default; 27 | 28 | 29 | virtual bool Poll() = 0; 30 | virtual void Listen(Window&) = 0; 31 | 32 | void AddMousePositionCallback(std::function); 33 | void AddMouseButtonCallback(std::function); 34 | 35 | // Factory 36 | static std::unique_ptr CreateModule(); 37 | 38 | protected: 39 | 40 | // TODO: Implement proper InputSet 41 | InputSet globalInputSet_; 42 | 43 | std::vector> mousePositionCallbacks_; 44 | std::vector> mouseButtonCallbacks_; 45 | 46 | }; 47 | -------------------------------------------------------------------------------- /Source/Display/Input/InputSet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Utility/ID/TypeID.h" 4 | 5 | 6 | class InputSet : TypeID { 7 | 8 | public: 9 | 10 | InputSet() = default; 11 | 12 | 13 | }; -------------------------------------------------------------------------------- /Source/Display/Input/Modules/GLFW/GLFWInputBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/Input/Button.h" 4 | #include "Display/Input/InputModule.h" 5 | 6 | #include 7 | 8 | struct GLFWwindow; 9 | 10 | class GLFWInputBackend : public InputModule { 11 | 12 | public: 13 | 14 | GLFWInputBackend(); 15 | ~GLFWInputBackend() override = default; 16 | 17 | GLFWInputBackend(const GLFWInputBackend&) = delete; 18 | GLFWInputBackend(GLFWInputBackend&&) = default; 19 | 20 | GLFWInputBackend& operator=(const GLFWInputBackend&) = delete; 21 | GLFWInputBackend& operator=(GLFWInputBackend&&) noexcept = default; 22 | 23 | 24 | bool Poll() override; 25 | void Listen(Window&) override; 26 | 27 | void KeyCallback(GLFWwindow*, int, int, int, int); 28 | void CharacterCallback(GLFWwindow*, uint); 29 | void ModdedCharacterCallback(GLFWwindow*, uint, int); 30 | void ButtonCallback(GLFWwindow*, int, int, int); 31 | void CursorCallback(GLFWwindow*, double, double); 32 | void CursorEnterCallback(GLFWwindow*, int); 33 | void ScrollCallback(GLFWwindow*, double, double); 34 | 35 | 36 | private: 37 | 38 | std::unordered_map buttonStates_; 39 | 40 | double mouseXPos_; 41 | double mouseYPos_; 42 | 43 | double mouseXOffset_; 44 | double mouseYOffset_; 45 | 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /Source/Display/Input/Modules/Mock/MockInputBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "MockInputBackend.h" 2 | 3 | #include "Core/Utility/Exception/Exception.h" 4 | 5 | 6 | bool MockInputBackend::Poll() 7 | { 8 | 9 | throw NotImplemented(); 10 | 11 | return true; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Source/Display/Input/Modules/Mock/MockInputBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/Input/InputModule.h" 4 | 5 | 6 | class MockInputBackend : public InputModule { 7 | 8 | public: 9 | 10 | MockInputBackend() = default; 11 | ~MockInputBackend() override = default; 12 | 13 | MockInputBackend(const MockInputBackend&) = delete; 14 | MockInputBackend(MockInputBackend&&) = default; 15 | 16 | MockInputBackend& operator=(const MockInputBackend&) = delete; 17 | MockInputBackend& operator=(MockInputBackend&&) noexcept = default; 18 | 19 | 20 | bool Poll() override; 21 | 22 | 23 | }; 24 | -------------------------------------------------------------------------------- /Source/Display/Window/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Window 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | WindowModule.cpp 8 | WindowModule.h 9 | Modules/GLFW/GLFWWindowBackend.cpp 10 | Modules/GLFW/GLFWWindowBackend.h 11 | Modules/GLFW/GLFWWindow.cpp 12 | Modules/GLFW/GLFWWindow.h 13 | Modules/GLFW/GLFWMonitor.cpp 14 | Modules/GLFW/GLFWMonitor.h 15 | Window.cpp 16 | Window.h 17 | Monitor.h 18 | ) 19 | -------------------------------------------------------------------------------- /Source/Display/Window/Modules/GLFW/GLFWMonitor.cpp: -------------------------------------------------------------------------------- 1 | #include "GLFWMonitor.h" 2 | 3 | #include 4 | 5 | GLFWMonitor::GLFWMonitor(GLFWmonitor* monitor) 6 | : monitor_(monitor), 7 | videoMode_(glfwGetVideoMode(monitor)), 8 | name_(glfwGetMonitorName(monitor)) 9 | { 10 | } 11 | 12 | GLFWMonitor::~GLFWMonitor() 13 | { 14 | } 15 | 16 | void GLFWMonitor::Scale(float& xscale, float& yscale) const 17 | { 18 | glfwGetMonitorContentScale(monitor_, &xscale, &yscale); 19 | } 20 | 21 | void GLFWMonitor::Position(int& xpos, int& ypos) const 22 | { 23 | glfwGetMonitorPos(monitor_, &xpos, &ypos); 24 | } 25 | 26 | void GLFWMonitor::Size(int& width, int& height) const 27 | { 28 | width = videoMode_->width; 29 | height = videoMode_->height; 30 | } 31 | 32 | void GLFWMonitor::ColorBits(int& red, int& green, int& blue) const 33 | { 34 | red = videoMode_->redBits; 35 | green = videoMode_->greenBits; 36 | blue = videoMode_->blueBits; 37 | } 38 | 39 | void GLFWMonitor::RefreshRate(int& refreshRate) const 40 | { 41 | refreshRate = videoMode_->refreshRate; 42 | } 43 | 44 | std::string GLFWMonitor::Name() const 45 | { 46 | return std::string(name_); 47 | } 48 | -------------------------------------------------------------------------------- /Source/Display/Window/Modules/GLFW/GLFWMonitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/Window/Monitor.h" 4 | #include "Core/Utility/ID/TypeID.h" 5 | 6 | class GLFWWindow; 7 | struct GLFWmonitor; 8 | struct GLFWvidmode; 9 | 10 | class GLFWMonitor final : public Monitor, TypeID { 11 | 12 | public: 13 | friend class GLFWWindow; 14 | 15 | GLFWMonitor(GLFWmonitor*); 16 | ~GLFWMonitor() override; 17 | 18 | void Scale(float&, float&) const; 19 | 20 | void Position(int&, int&) const; 21 | 22 | void Size(int&, int&) const; 23 | void ColorBits(int&, int&, int&) const; 24 | void RefreshRate(int&) const; 25 | 26 | std::string Name() const; 27 | 28 | private: 29 | 30 | GLFWmonitor* monitor_; 31 | 32 | const GLFWvidmode* videoMode_; 33 | const char* name_; 34 | }; 35 | -------------------------------------------------------------------------------- /Source/Display/Window/Modules/GLFW/GLFWWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/Window/Window.h" 4 | #include "Core/Utility/ID/TypeID.h" 5 | 6 | #include 7 | 8 | struct GLFWmonitor; 9 | struct GLFWwindow; 10 | class GLFWMonitor; 11 | class RasterModule; 12 | class RasterBackend; 13 | 14 | class GLFWWindow final : public Window, TypeID { 15 | 16 | public: 17 | 18 | GLFWWindow(const WindowParameters&, GLFWMonitor&, std::shared_ptr, bool); 19 | ~GLFWWindow() override; 20 | 21 | GLFWWindow(const GLFWWindow &) = delete; 22 | GLFWWindow(GLFWWindow &&) noexcept = default; 23 | 24 | GLFWWindow& operator=(const GLFWWindow &) = delete; 25 | GLFWWindow& operator=(GLFWWindow &&) noexcept = default; 26 | 27 | 28 | void FrameBufferResize(int, int); 29 | 30 | 31 | GLFWwindow* Context() const; 32 | bool Master() const; 33 | 34 | 35 | private: 36 | 37 | std::shared_ptr rasterModule_; 38 | 39 | GLFWwindow* context_; 40 | 41 | bool master_; 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /Source/Display/Window/Modules/GLFW/GLFWWindowBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Display/Window/WindowModule.h" 4 | 5 | #include 6 | 7 | struct GLFWwindow; 8 | class GLFWWindow; 9 | class GLFWMonitor; 10 | class WindowParameters; 11 | class VulkanRasterBackend; 12 | class GLFWInputBackend; 13 | 14 | class GLFWWindowBackend final : public WindowModule { 15 | 16 | public: 17 | 18 | GLFWWindowBackend(std::shared_ptr&); 19 | ~GLFWWindowBackend() override; 20 | 21 | GLFWWindowBackend(const GLFWWindowBackend&) = delete; 22 | GLFWWindowBackend(GLFWWindowBackend&&) noexcept = default; 23 | 24 | GLFWWindowBackend& operator=(const GLFWWindowBackend&) = delete; 25 | GLFWWindowBackend& operator=(GLFWWindowBackend&&) noexcept = default; 26 | 27 | void Update() override; 28 | bool Active() override; 29 | void CreateWindow(const WindowParameters&, std::shared_ptr&) override; 30 | 31 | nonstd::span GetRasterExtensions() override; 32 | 33 | Window& MasterWindow() override; 34 | 35 | void Refresh(); 36 | void Resize(int, int); 37 | void PositionUpdate(int, int); 38 | void FrameBufferResize(GLFWWindow&, int, int); 39 | void Close(GLFWWindow&); 40 | 41 | struct UserPointers { 42 | GLFWWindowBackend* windowBackend; 43 | std::shared_ptr inputBackend; 44 | }; 45 | 46 | private: 47 | 48 | GLFWWindow& GetWindow(GLFWwindow*); 49 | 50 | std::vector monitors_; 51 | std::unordered_map> windows_; 52 | 53 | // Luxery of having the Input system be GLFW 54 | std::shared_ptr inputModule_; 55 | 56 | UserPointers userPointers_; 57 | 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /Source/Display/Window/Monitor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Monitor 6 | { 7 | 8 | public: 9 | 10 | Monitor() {} 11 | virtual ~Monitor() = default; 12 | 13 | Monitor(const Monitor &) = default; 14 | Monitor(Monitor &&) noexcept = default; 15 | 16 | Monitor& operator=(const Monitor &) = delete; 17 | Monitor& operator=(Monitor &&) noexcept = default; 18 | 19 | void Scale(float&, float&) const = delete; 20 | 21 | void Position(int&, int&) const = delete; 22 | 23 | void Size(int&, int&) const = delete; 24 | void ColorBits(int&, int&, int&) const = delete; 25 | void RefreshRate(int&) const = delete; 26 | 27 | std::string Name() const = delete; 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /Source/Display/Window/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "Window.h" 2 | 3 | Window::Window(const WindowParameters& params) : 4 | layout_(), 5 | windowParams_(params) 6 | { 7 | //std::make_unique(); 8 | } 9 | 10 | WindowParameters& Window::Parameters() 11 | { 12 | 13 | return windowParams_; 14 | 15 | } 16 | 17 | Entity Window::Surface() 18 | { 19 | 20 | return surface_; 21 | 22 | } -------------------------------------------------------------------------------- /Source/Display/Window/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "WindowParameters.h" 4 | #include "Core/Composition/Entity/Entity.h" 5 | 6 | 7 | class Window 8 | { 9 | 10 | public: 11 | 12 | Window(const WindowParameters&); 13 | virtual ~Window() = default; 14 | 15 | Window(const Window &) = delete; 16 | Window(Window &&) noexcept = default; 17 | 18 | Window& operator=(const Window &) = delete; 19 | Window& operator=(Window &&) noexcept = default; 20 | 21 | WindowParameters& Parameters(); 22 | Entity Surface(); 23 | 24 | protected: 25 | 26 | Entity layout_; 27 | Entity surface_; 28 | WindowParameters windowParams_; 29 | 30 | }; 31 | -------------------------------------------------------------------------------- /Source/Display/Window/WindowModule.cpp: -------------------------------------------------------------------------------- 1 | #include "WindowModule.h" 2 | #include "Core/System/Platform.h" 3 | 4 | #include "Modules/GLFW/GLFWWindowBackend.h" 5 | #include "Render/Raster/Modules/Vulkan/VulkanRasterBackend.h" 6 | #include "Display/GUI/GUIModule.h" 7 | 8 | 9 | WindowModule::WindowModule(): 10 | active_(true) 11 | { 12 | } 13 | 14 | //TODO: There will only ever be one WindowModule system per Soul application. This will need to be moved to the build system per platform 15 | std::unique_ptr WindowModule::CreateModule(std::shared_ptr& inputModule) 16 | { 17 | 18 | if constexpr (Platform::IsDesktop()) { 19 | return std::make_unique(inputModule); 20 | } 21 | else { 22 | return nullptr; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /Source/Display/Window/WindowModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Interface/Module/Module.h" 4 | #include "WindowParameters.h" 5 | #include "Display/GUI/GUIModule.h" 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | class Window; 12 | class InputModule; 13 | class RasterModule; 14 | 15 | class WindowModule : public Module { 16 | 17 | public: 18 | 19 | WindowModule(); 20 | virtual ~WindowModule() = default; 21 | 22 | WindowModule(const WindowModule&) = delete; 23 | WindowModule(WindowModule&&) noexcept = default; 24 | 25 | WindowModule& operator=(const WindowModule&) = delete; 26 | WindowModule& operator=(WindowModule&&) noexcept = default; 27 | 28 | 29 | virtual void Update() = 0; 30 | virtual bool Active() = 0; 31 | 32 | virtual void CreateWindow(const WindowParameters&, std::shared_ptr&) = 0; 33 | 34 | virtual nonstd::span GetRasterExtensions() = 0; 35 | 36 | virtual Window& MasterWindow() = 0; 37 | 38 | //Factory 39 | static std::unique_ptr CreateModule(std::shared_ptr&); 40 | 41 | 42 | protected: 43 | 44 | bool active_; 45 | 46 | 47 | }; 48 | -------------------------------------------------------------------------------- /Source/Memory/Allocator.cpp: -------------------------------------------------------------------------------- 1 | #include "Allocator.h" 2 | 3 | /*The constructor for the allocator 4 | Arguments: size - the amount of memory to use 5 | start - the begining of the allocated block*/ 6 | 7 | /* 8 | * Constructor. 9 | * @param size The size. 10 | * @param [in,out] start If non-null, the start. 11 | */ 12 | 13 | Allocator::Allocator(size_t size, void* start) { 14 | _start = start; 15 | _capacity = size; 16 | _usedMem = 0; 17 | _numAllocs = 0; 18 | } 19 | 20 | /*Destructor for the allocator*/ 21 | /* Destructor. */ 22 | Allocator::~Allocator() { 23 | _start = nullptr; 24 | _capacity = 0; 25 | } -------------------------------------------------------------------------------- /Source/Memory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Memory 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Allocator.cpp 8 | Allocator.h 9 | LinearAllocator.cpp 10 | LinearAllocator.h 11 | TaggedAllocator/TaggedAllocator.cpp 12 | TaggedAllocator/TaggedAllocator.h 13 | TaggedAllocator/TaggedHeap.cpp 14 | TaggedAllocator/TaggedHeap.h 15 | ) 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/Memory/LinearAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Allocator.h" 3 | #include 4 | 5 | /*This class extends the base allocator class and provides 6 | the allocation logic for the linear allocator*/ 7 | /* A linear allocator. */ 8 | class LinearAllocator : public Allocator { 9 | /*Function declarations*/ 10 | public: 11 | 12 | /* 13 | * Constructor. 14 | * @param size The size. 15 | * @param [in,out] start If non-null, the start. 16 | */ 17 | 18 | LinearAllocator(size_t size, void * start); 19 | /* Destructor. */ 20 | ~LinearAllocator(); 21 | 22 | /* 23 | * Allocates. 24 | * @param size The size. 25 | * @param alignment The alignment. 26 | * @return Null if it fails, else a pointer to a void. 27 | */ 28 | 29 | void* allocate(size_t size, uint8_t alignment); 30 | 31 | /* 32 | * Deallocates the given block. 33 | * @param [in,out] block If non-null, the block. 34 | * @return Null if it fails, else a pointer to a void. 35 | */ 36 | 37 | void* deallocate(void* block); 38 | /* Clears this object to its blank/initial state. */ 39 | void clear(); 40 | 41 | private: 42 | /*The allocator does not need to be copied, so the copy constructor 43 | and assignment operator should be private*/ 44 | 45 | /* 46 | * Copy constructor. 47 | * @param parameter1 The first parameter. 48 | */ 49 | 50 | LinearAllocator(const LinearAllocator&); 51 | 52 | /* 53 | * Assignment operator. 54 | * @param parameter1 The first parameter. 55 | * @return A shallow copy of this object. 56 | */ 57 | 58 | LinearAllocator& operator=(const LinearAllocator&); 59 | /* keep track of next free space */ 60 | void* _currPos; 61 | }; -------------------------------------------------------------------------------- /Source/Memory/TaggedAllocator/TaggedAllocator.cpp: -------------------------------------------------------------------------------- 1 | #include "TaggedAllocator.h" 2 | #include "TaggedHeap.h" 3 | TaggedAllocator::TaggedAllocator(TaggedHeap* heap, const std::string &tag, uint8_t align) : Allocator(heap->getSize(tag), heap->getNextFree(tag)) { 4 | _heap = heap; 5 | _tag = tag; 6 | _blockSize = align; 7 | _numBlocks = 0; 8 | } 9 | 10 | TaggedAllocator::~TaggedAllocator() { 11 | _numBlocks = 0; 12 | } 13 | 14 | void* TaggedAllocator::allocate(size_t size, uint8_t align) { 15 | std::lock_guard l(_mutex); 16 | void* blocks = _heap->requestBlocks(_tag, align, size); 17 | if (blocks == nullptr) { 18 | return nullptr; 19 | } 20 | 21 | _numBlocks += size; 22 | 23 | return blocks; 24 | } 25 | 26 | void* TaggedAllocator::deallocate(void* block) { 27 | return nullptr; 28 | } 29 | 30 | void TaggedAllocator::clear() { 31 | _heap->clearTag(_tag); 32 | } -------------------------------------------------------------------------------- /Source/Memory/TaggedAllocator/TaggedAllocator.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Allocator.h" 3 | class TaggedHeap; 4 | #include 5 | #include 6 | /*Tagged Allocator is an allocator class that utilizes the tagged heap for per-module memory management. 7 | It uses a LinearAllocator under the hood to make the actual allocations, but obtains memory from the TaggedHeap. 8 | Memory allocation happens on a per-thread bases to make this allocator thread-safe*/ 9 | class TaggedAllocator : public Allocator { 10 | mutable std::mutex _mutex; 11 | 12 | private: 13 | // Private variables 14 | TaggedHeap* _heap; 15 | std::string _tag; 16 | size_t _blockSize; 17 | size_t _numBlocks; 18 | 19 | 20 | public: 21 | TaggedAllocator(TaggedHeap* heap, const std::string &tag, uint8_t align=4); 22 | ~TaggedAllocator(); 23 | void* allocate(size_t size, uint8_t align=4); 24 | void* deallocate(void* block); 25 | void clear(); 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /Source/Memory/TaggedAllocator/TaggedHeap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | /* This class allows for used memory to be tagged on a per-module basis 7 | Note: Currently, freeing memory for a given module can leave the heap fragmented. 8 | There is currently no defragmentation procedure in place, but one can be added later */ 9 | 10 | class TaggedHeap { 11 | private: 12 | /*Private variables*/ 13 | void* _heap; 14 | std::map> _tags; // associate module tag with its share of memory 15 | std::map _nextFree; // address of the next free blocks in a tag's part of the heap 16 | size_t _usedSpace; 17 | size_t _capacity; 18 | 19 | public: 20 | TaggedHeap(void*, size_t); // Constructor for creating TaggedHeap 21 | bool CreateTag(std::string tag, size_t size); 22 | void* requestBlocks(std::string tag, size_t size, size_t num); // Request blocks from a specific tag 23 | bool clearTag(std::string tag); // Clear memory from a given tag 24 | void clearAll(); // Clear the entire heap 25 | size_t getCapacity(); // Get the capacity of the TaggedHeap 26 | void* getNextFree(const std::string &tag); 27 | size_t getSize(const std::string &tag); 28 | }; -------------------------------------------------------------------------------- /Source/Network/AbstractNetworkManager.cpp: -------------------------------------------------------------------------------- 1 | #include "AbstractNetworkManager.h" -------------------------------------------------------------------------------- /Source/Network/AbstractNetworkManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class AbstractNetworkManager { 4 | 5 | }; -------------------------------------------------------------------------------- /Source/Network/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Network 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | AbstractNetworkManager.cpp 8 | AbstractNetworkManager.h 9 | Client/Client.cpp 10 | Client/Client.h 11 | NetworkManager.cpp 12 | NetworkManager.h 13 | Server/Server.cpp 14 | Server/Server.h 15 | ) 16 | -------------------------------------------------------------------------------- /Source/Network/Client/Client.cpp: -------------------------------------------------------------------------------- 1 | #include"Client.h" 2 | -------------------------------------------------------------------------------- /Source/Network/Client/Client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Client { 4 | 5 | }; -------------------------------------------------------------------------------- /Source/Network/NetworkManager.cpp: -------------------------------------------------------------------------------- 1 | #include "NetworkManager.h" -------------------------------------------------------------------------------- /Source/Network/NetworkManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "AbstractNetworkManager.h" 4 | 5 | class NetworkManager: public AbstractNetworkManager { 6 | 7 | }; -------------------------------------------------------------------------------- /Source/Network/Server/Server.cpp: -------------------------------------------------------------------------------- 1 | #include "Server.h" -------------------------------------------------------------------------------- /Source/Network/Server/Server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Server { 4 | 5 | }; -------------------------------------------------------------------------------- /Source/Parallelism/Graph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Parallelism 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Modules/EntityGraph/Graph.cpp 8 | Modules/EntityGraph/Graph.h 9 | Modules/EntityGraph/GraphNode.cpp 10 | Modules/EntityGraph/GraphNode.h 11 | Modules/EntityGraph/GraphTask.cpp 12 | Modules/EntityGraph/GraphTask.h 13 | GraphTask.h 14 | Graph.h 15 | ) 16 | 17 | target_compile_definitions(${PROJECT_NAME} 18 | PRIVATE 19 | ENTITY_GRAPH=BUILD_ENTITY_GRAPH 20 | ) -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Graph.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(ENTITY_GRAPH) 4 | 5 | #include "Modules/EntityGraph/Graph.h" 6 | 7 | #endif -------------------------------------------------------------------------------- /Source/Parallelism/Graph/GraphTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(ENTITY_GRAPH) 4 | 5 | #include "Modules/EntityGraph/GraphTask.h" 6 | 7 | #endif -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/Graph.cpp: -------------------------------------------------------------------------------- 1 | #include "Graph.h" 2 | 3 | #include "Parallelism/Scheduler/SchedulerModule.h" 4 | 5 | 6 | Graph::Graph(std::shared_ptr& scheduler): 7 | scheduler_(scheduler) 8 | { 9 | 10 | } 11 | 12 | //Returns after dispatching the graph. 13 | //Call scheduler_->Block() to guarantee completion 14 | void Graph::Execute(std::chrono::nanoseconds targetDuration) { 15 | 16 | for (const auto& child : children_) { 17 | 18 | if (child->Root()) { 19 | 20 | child->Execute(); 21 | 22 | } 23 | 24 | } 25 | 26 | } 27 | 28 | //Create a sub-graph 29 | Graph& Graph::CreateGraph() 30 | { 31 | 32 | return graphs_.emplace_front(scheduler_); 33 | 34 | } -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/Graph.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GraphNode.h" 4 | #include "GraphTask.h" 5 | 6 | #include "Core/Utility/Template/TypeTraits.h" 7 | 8 | #include 9 | 10 | class SchedulerModule; 11 | 12 | class Graph : public GraphNode { 13 | 14 | 15 | public: 16 | 17 | Graph(std::shared_ptr&); 18 | ~Graph() override = default; 19 | 20 | Graph(const Graph&) = delete; 21 | Graph(Graph&&) noexcept = default; 22 | 23 | Graph& operator=(const Graph&) = delete; 24 | Graph& operator=(Graph&&) noexcept = default; 25 | 26 | template 27 | GraphTask& AddTask(Callable&&); 28 | Graph& CreateGraph(); 29 | 30 | void Execute(std::chrono::nanoseconds) override; 31 | 32 | 33 | private: 34 | 35 | std::shared_ptr scheduler_; 36 | 37 | std::forward_list tasks_; 38 | std::forward_list graphs_; 39 | 40 | 41 | }; 42 | 43 | //Create a tasks under this graph's control 44 | template 45 | GraphTask& Graph::AddTask(Callable&& callable) 46 | { 47 | 48 | if constexpr (!std::is_invocable_v) { 49 | 50 | static_assert(dependent_false_v, "The provided parameter is not callable"); 51 | 52 | } 53 | 54 | GraphTask& task = tasks_.emplace_front(scheduler_, std::forward(callable)); 55 | 56 | task.DependsOn(*this); 57 | task.Root(true); 58 | 59 | return task; 60 | 61 | } -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/GraphNode.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphNode.h" 2 | 3 | GraphNode::GraphNode(): 4 | root(false) 5 | { 6 | } 7 | 8 | void GraphNode::DependsOn(GraphNode& other) { 9 | 10 | root = false; 11 | other.AddChild(this); 12 | 13 | } 14 | 15 | bool GraphNode::Root() { 16 | 17 | return root; 18 | 19 | } 20 | 21 | void GraphNode::Root(bool other) { 22 | 23 | root = other; 24 | 25 | } 26 | 27 | void GraphNode::AddChild(GraphNode* child) { 28 | 29 | children_.push_back(child); 30 | 31 | } -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/GraphNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Parallelism/Scheduler/TaskParameters.h" 4 | 5 | #include 6 | #include 7 | 8 | //Handles the topology of the graph 9 | class GraphNode{ 10 | 11 | public: 12 | 13 | GraphNode(); 14 | virtual ~GraphNode() = default; 15 | 16 | GraphNode(const GraphNode&) = delete; 17 | GraphNode(GraphNode&&) noexcept = default; 18 | 19 | GraphNode& operator=(const GraphNode&) = delete; 20 | GraphNode& operator=(GraphNode&&) noexcept = default; 21 | 22 | virtual void Execute(std::chrono::nanoseconds = std::chrono::nanoseconds(0)) = 0; 23 | 24 | void DependsOn(GraphNode&); 25 | 26 | bool Root(); 27 | void Root(bool); 28 | 29 | protected: 30 | 31 | TaskParameters parameters_; 32 | std::vector children_; 33 | 34 | 35 | private: 36 | 37 | void AddChild(GraphNode*); 38 | 39 | bool root; 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/GraphTask.cpp: -------------------------------------------------------------------------------- 1 | #include "GraphTask.h" 2 | 3 | #include "Parallelism/Scheduler/SchedulerModule.h" 4 | 5 | GraphTask::GraphTask(std::shared_ptr& scheduler) noexcept: 6 | scheduler_(scheduler) 7 | { 8 | } 9 | 10 | GraphTask::GraphTask(std::shared_ptr& scheduler, std::function&& callable) noexcept: 11 | scheduler_(scheduler), 12 | callable_(std::forward>(callable)) 13 | { 14 | 15 | } 16 | 17 | void GraphTask::Execute(std::chrono::nanoseconds targetDuration) { 18 | 19 | scheduler_->AddTask(parameters_, [this]() 20 | { 21 | std::invoke(std::forward>(callable_)); 22 | 23 | for (const auto& child : children_) { 24 | 25 | child->Execute(); 26 | 27 | } 28 | 29 | scheduler_->Block(); 30 | }); 31 | 32 | } -------------------------------------------------------------------------------- /Source/Parallelism/Graph/Modules/EntityGraph/GraphTask.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "GraphNode.h" 4 | #include 5 | 6 | class SchedulerModule; 7 | 8 | class GraphTask : public GraphNode { 9 | 10 | public: 11 | 12 | GraphTask(std::shared_ptr&) noexcept; 13 | GraphTask(std::shared_ptr&, std::function&&) noexcept; 14 | 15 | ~GraphTask() override = default; 16 | 17 | GraphTask(const GraphTask&) = delete; 18 | GraphTask(GraphTask&&) = default; 19 | 20 | GraphTask& operator=(const GraphTask&) = delete; 21 | GraphTask& operator=(GraphTask&&) = default; 22 | 23 | void Execute(std::chrono::nanoseconds) override; 24 | 25 | 26 | private: 27 | 28 | std::shared_ptr scheduler_; 29 | std::function callable_; 30 | 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Parallelism 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Modules/Dispatch/DispatchSchedulerBackend.cpp 8 | Modules/Dispatch/DispatchSchedulerBackend.h 9 | Modules/Fiber/FiberProperties.cpp 10 | Modules/Fiber/FiberProperties.h 11 | Modules/Fiber/FiberSchedulerAlgorithm.cpp 12 | Modules/Fiber/FiberSchedulerAlgorithm.h 13 | Modules/Fiber/FiberSchedulerBackend.cpp 14 | Modules/Fiber/FiberSchedulerBackend.h 15 | SchedulerModule.cpp 16 | SchedulerModule.h 17 | TaskParameters.cpp 18 | TaskParameters.h 19 | ) 20 | 21 | target_compile_definitions(${PROJECT_NAME} 22 | PRIVATE 23 | FIBER_SCHEDULER=BUILD_FIBER_SCHEDULER 24 | ) 25 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/Modules/Dispatch/DispatchSchedulerBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "DispatchSchedulerBackend.h" -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/Modules/Dispatch/DispatchSchedulerBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | class DispatchSchedulerBackend { 5 | 6 | public: 7 | 8 | ~DispatchSchedulerBackend() = default; 9 | 10 | DispatchSchedulerBackend(const DispatchSchedulerBackend&) = delete; 11 | DispatchSchedulerBackend(DispatchSchedulerBackend&&) noexcept = default; 12 | 13 | DispatchSchedulerBackend& operator=(const DispatchSchedulerBackend&) = delete; 14 | DispatchSchedulerBackend& operator=(DispatchSchedulerBackend&&) noexcept = default; 15 | 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/Modules/Fiber/FiberProperties.cpp: -------------------------------------------------------------------------------- 1 | #include "FiberProperties.h" 2 | 3 | FiberProperties::FiberProperties(boost::fibers::context* context) : 4 | fiber_properties(context), 5 | priority_(TaskPriority::HIGH), 6 | requiredThread_(-1) 7 | { 8 | } 9 | 10 | TaskPriority FiberProperties::GetPriority() const { 11 | return priority_; 12 | } 13 | 14 | int FiberProperties::RequiredThread() const { 15 | return requiredThread_; 16 | } 17 | 18 | void FiberProperties::SetProperties(TaskPriority p, int m) { 19 | if (p != priority_ || m != requiredThread_) { 20 | priority_ = p; 21 | requiredThread_ = m; 22 | notify(); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/Modules/Fiber/FiberProperties.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "boost/fiber/properties.hpp" 4 | #include "Parallelism/Scheduler/TaskParameters.h" 5 | 6 | class FiberProperties : public boost::fibers::fiber_properties { 7 | 8 | public: 9 | 10 | //Construction 11 | FiberProperties(boost::fibers::context*); 12 | 13 | //Implementation 14 | TaskPriority GetPriority() const; 15 | int RequiredThread() const; 16 | 17 | void SetProperties(TaskPriority, int); 18 | 19 | private: 20 | 21 | TaskPriority priority_; 22 | int requiredThread_; 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/SchedulerModule.cpp: -------------------------------------------------------------------------------- 1 | #include "SchedulerModule.h" 2 | 3 | #include "Modules/Fiber/FiberSchedulerBackend.h" 4 | 5 | 6 | SchedulerModule::SchedulerModule(Property& threadCount): 7 | scheduler_(threadCount) 8 | { 9 | } 10 | 11 | void SchedulerModule::Block() const 12 | { 13 | 14 | scheduler_.Block(); 15 | 16 | } 17 | 18 | void SchedulerModule::Yield() 19 | { 20 | 21 | scheduler_.Yield(); 22 | 23 | } 24 | 25 | //TODO: This needs to instead be runtime loadable from shared libraries or statically linked 26 | std::shared_ptr SchedulerModule::CreateModule(Property& threadCount) 27 | { 28 | 29 | return std::make_shared(threadCount); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/TaskParameters.cpp: -------------------------------------------------------------------------------- 1 | #include "TaskParameters.h" 2 | 3 | TaskParameters::TaskParameters(bool post, 4 | TaskPriority priority, 5 | bool shouldBlock, 6 | int requiredThread): 7 | post_(post), 8 | priority_(priority), 9 | shouldBlock_(shouldBlock), 10 | requiredThread_(requiredThread) 11 | { 12 | 13 | if (!post_) { 14 | shouldBlock_ = true; 15 | requiredThread_ = -1; //if not post, ignored in scheduler 16 | priority_ = TaskPriority::HIGH; 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /Source/Parallelism/Scheduler/TaskParameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum class TaskPriority { 4 | LOW, //A comparative low priority task. 5 | HIGH, //A high priority task. 6 | UX //User Experience. Takes precedence over all. 7 | }; 8 | 9 | class TaskParameters { 10 | 11 | public: 12 | 13 | TaskParameters(bool = true, TaskPriority = TaskPriority::HIGH, bool = true, int = -1); 14 | ~TaskParameters() = default; 15 | 16 | TaskParameters(const TaskParameters&) = default; 17 | TaskParameters(TaskParameters&& o) noexcept = default; 18 | 19 | TaskParameters& operator=(const TaskParameters&) = default; 20 | TaskParameters& operator=(TaskParameters&& other) noexcept = default; 21 | 22 | 23 | bool post_; // the fiber will not execute immediately and instead run when a scheduler picks it up. If not true, the fiber is required to remain on this thread and other parameters dont matter. 24 | TaskPriority priority_; 25 | bool shouldBlock_; //attaches the fiber to its parent. Guaranteed to complete before the parent does and can synchronize with `Block()` 26 | int requiredThread_; //forces the fiber to run on a specified thread, any negative number runs on any thread 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /Source/Physics/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Physics 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | PhysicsEngine.h 8 | ) 9 | -------------------------------------------------------------------------------- /Source/Physics/CUDA/PhysicsEngine.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Parallelism/Compute/ComputeBuffer.h" 4 | //#include "Core/Scene/Scene.h" 5 | 6 | 7 | //__host__ void ProcessScene(ComputeBuffer&); 8 | -------------------------------------------------------------------------------- /Source/Physics/PhysicsEngine.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Scene/Scene.h" 4 | 5 | 6 | ///* . */ 7 | //namespace PhysicsEngine { 8 | // 9 | // /* 10 | // * Process the given parameter1. 11 | // * @param parameter1 The first parameter. 12 | // */ 13 | // 14 | // //void Process(ComputeBuffer&); 15 | // 16 | //} -------------------------------------------------------------------------------- /Source/Render/Raster/CommandList.cpp: -------------------------------------------------------------------------------- 1 | #include "CommandList.h" 2 | #include "Core/Utility/Exception/Exception.h" 3 | 4 | #include "Render/Raster/RasterModule.h" 5 | 6 | CommandList::CommandList(): commands_(5) 7 | { 8 | } 9 | 10 | void CommandList::Draw(DrawCommand& command) 11 | { 12 | 13 | auto pos = drawCommands_.size(); 14 | drawCommands_.push_back(command); 15 | commands_.push_back({CommandType::Draw, pos}); 16 | } 17 | 18 | void CommandList::DrawIndirect(DrawIndirectCommand& command) 19 | { 20 | auto pos = drawIndirectCommands_.size(); 21 | drawIndirectCommands_.push_back(command); 22 | commands_.push_back({CommandType::DrawIndirect, pos}); 23 | } 24 | 25 | void CommandList::UpdateBuffer(UpdateBufferCommand& command) 26 | { 27 | auto pos = updateBufferCommands_.size(); 28 | updateBufferCommands_.push_back(command); 29 | commands_.push_back({CommandType::UpdateBuffer, pos}); 30 | } 31 | 32 | void CommandList::UpdateTexture(UpdateTextureCommand& command) 33 | { 34 | auto pos = updateTextureCommands_.size(); 35 | updateTextureCommands_.push_back(command); 36 | commands_.push_back({CommandType::UpdateTexture, pos}); 37 | } 38 | 39 | void CommandList::CopyBuffer(CopyBufferCommand& command) 40 | { 41 | auto pos = copyBufferCommands_.size(); 42 | copyBufferCommands_.push_back(command); 43 | commands_.push_back({CommandType::CopyBuffer, pos}); 44 | } 45 | 46 | void CommandList::CopyTexture(CopyTextureCommand& command) 47 | { 48 | auto pos = copyTextureCommands_.size(); 49 | copyTextureCommands_.push_back(command); 50 | commands_.push_back({CommandType::CopyTexture, pos}); 51 | } -------------------------------------------------------------------------------- /Source/Render/Raster/CommandList.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/Raster/RenderCommands.h" 4 | 5 | #include "Core/Utility/Thread/ThreadLocal.h" 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | class CommandList { 12 | 13 | public: 14 | 15 | CommandList(); 16 | ~CommandList() = default; 17 | 18 | // Agnostic raster API interface 19 | void Draw(DrawCommand&); 20 | void DrawIndirect(DrawIndirectCommand&); 21 | void UpdateBuffer(UpdateBufferCommand&); 22 | void UpdateTexture(UpdateTextureCommand&); 23 | void CopyBuffer(CopyBufferCommand&); 24 | void CopyTexture(CopyTextureCommand&); 25 | 26 | private: 27 | 28 | std::list> commands_; 29 | 30 | std::vector drawCommands_; 31 | std::vector drawIndirectCommands_; 32 | std::vector updateBufferCommands_; 33 | std::vector updateTextureCommands_; 34 | std::vector copyBufferCommands_; 35 | std::vector copyTextureCommands_; 36 | 37 | 38 | 39 | }; -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Command/VulkanCommandBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanCommandBuffer.h" 2 | 3 | #include "VulkanCommandPool.h" 4 | 5 | #include "Render/Raster/Modules/Vulkan/Device/VulkanDevice.h" 6 | 7 | VulkanCommandBuffer::VulkanCommandBuffer(const vk::CommandPool& commandPool, 8 | const vk::Device& vulkanDevice, 9 | vk::CommandBufferUsageFlagBits usage, 10 | vk::CommandBufferLevel bufferLevel): 11 | commandPool_(commandPool), 12 | device_(vulkanDevice), usage_(usage) 13 | { 14 | 15 | vk::CommandBufferAllocateInfo allocInfo; 16 | allocInfo.level = bufferLevel; 17 | allocInfo.commandPool = commandPool_; 18 | allocInfo.commandBufferCount = 1; 19 | 20 | commandBuffer_ = device_.allocateCommandBuffers(allocInfo).front(); 21 | 22 | } 23 | 24 | VulkanCommandBuffer::~VulkanCommandBuffer() 25 | { 26 | 27 | device_.freeCommandBuffers(commandPool_, commandBuffer_); 28 | 29 | } 30 | 31 | 32 | void VulkanCommandBuffer::Begin() 33 | { 34 | 35 | vk::CommandBufferBeginInfo beginInfo; 36 | beginInfo.flags = usage_; 37 | beginInfo.pInheritanceInfo = nullptr; 38 | 39 | commandBuffer_.begin(beginInfo); 40 | 41 | } 42 | 43 | void VulkanCommandBuffer::End() 44 | { 45 | 46 | commandBuffer_.end(); 47 | 48 | } 49 | 50 | const vk::CommandBuffer& VulkanCommandBuffer::Handle() const 51 | { 52 | 53 | return commandBuffer_; 54 | 55 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Command/VulkanCommandBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class VulkanCommandPool; 7 | class VulkanDevice; 8 | 9 | class VulkanCommandBuffer final { 10 | 11 | public: 12 | 13 | VulkanCommandBuffer(const vk::CommandPool&, 14 | const vk::Device&, 15 | vk::CommandBufferUsageFlagBits, 16 | vk::CommandBufferLevel); 17 | ~VulkanCommandBuffer(); 18 | 19 | VulkanCommandBuffer(const VulkanCommandBuffer&) = delete; 20 | VulkanCommandBuffer(VulkanCommandBuffer&&) noexcept = default; 21 | 22 | VulkanCommandBuffer& operator=(const VulkanCommandBuffer&) = delete; 23 | VulkanCommandBuffer& operator=(VulkanCommandBuffer&&) noexcept = default; 24 | 25 | void Begin(); 26 | void End(); 27 | 28 | const vk::CommandBuffer& Handle() const; 29 | 30 | 31 | private: 32 | 33 | vk::CommandPool commandPool_; 34 | 35 | vk::Device device_; 36 | 37 | 38 | vk::CommandBufferUsageFlagBits usage_; 39 | vk::CommandBuffer commandBuffer_; 40 | 41 | }; 42 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Command/VulkanCommandPool.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanCommandPool.h" 2 | 3 | #include "Parallelism/Scheduler/SchedulerModule.h" 4 | #include "Render/Raster/Modules/Vulkan/Device/VulkanDevice.h" 5 | 6 | VulkanCommandPool::VulkanCommandPool(std::shared_ptr& scheduler, 7 | const VulkanDevice& device) : 8 | scheduler_(scheduler), 9 | device_(device.Logical()) 10 | { 11 | 12 | vk::CommandPoolCreateInfo poolInfo; 13 | poolInfo.flags = vk::CommandPoolCreateFlagBits::eTransient | 14 | vk::CommandPoolCreateFlagBits::eResetCommandBuffer; 15 | poolInfo.queueFamilyIndex = device.HighFamilyIndex(); 16 | 17 | scheduler_->ForEachThread(TaskPriority::UX, [&]() { 18 | commandPool_ = device_.createCommandPool(poolInfo); 19 | }); 20 | 21 | } 22 | 23 | VulkanCommandPool::~VulkanCommandPool() 24 | { 25 | 26 | scheduler_->ForEachThread(TaskPriority::UX, [&]() noexcept { 27 | device_.destroyCommandPool(commandPool_); 28 | }); 29 | 30 | } 31 | 32 | 33 | const vk::CommandPool& VulkanCommandPool::Handle() const 34 | { 35 | 36 | return commandPool_; 37 | 38 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Command/VulkanCommandPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Utility/Thread/ThreadLocal.h" 5 | 6 | #include 7 | #include 8 | 9 | class SchedulerModule; 10 | class VulkanDevice; 11 | 12 | class VulkanCommandPool final { 13 | 14 | public: 15 | 16 | VulkanCommandPool(std::shared_ptr&, const VulkanDevice&); 17 | ~VulkanCommandPool(); 18 | 19 | VulkanCommandPool(const VulkanCommandPool&) = delete; 20 | VulkanCommandPool(VulkanCommandPool&&) noexcept = default; 21 | 22 | VulkanCommandPool& operator=(const VulkanCommandPool&) = delete; 23 | VulkanCommandPool& operator=(VulkanCommandPool&&) noexcept = default; 24 | 25 | const vk::CommandPool& Handle() const; 26 | 27 | 28 | private: 29 | 30 | std::shared_ptr scheduler_; 31 | vk::Device device_; 32 | 33 | ThreadLocal commandPool_; 34 | 35 | 36 | }; 37 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Device/VulkanDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Render/Raster/RasterDevice.h" 5 | #include "Core/Structure/Span.h" 6 | #include "VulkanQueue.h" 7 | #include "Core/Structure/Span.h" 8 | 9 | #include 10 | 11 | class SchedulerModule; 12 | class VulkanQueue; 13 | 14 | class VulkanDevice final: public RasterDevice { 15 | 16 | public: 17 | 18 | VulkanDevice(std::shared_ptr&, 19 | const vk::Instance&, 20 | const vk::PhysicalDevice&, 21 | nonstd::span, 22 | nonstd::span); 23 | ~VulkanDevice() override; 24 | 25 | VulkanDevice(const VulkanDevice &) = delete; 26 | VulkanDevice(VulkanDevice &&) noexcept = default; 27 | 28 | VulkanDevice& operator=(const VulkanDevice &) = delete; 29 | VulkanDevice& operator=(VulkanDevice&&) noexcept = default; 30 | 31 | void Synchronize() override; 32 | 33 | const vk::Device& Logical() const; 34 | const vk::PhysicalDevice& Physical() const; 35 | const vk::DispatchLoaderDynamic& DispatchLoader() const; 36 | 37 | bool SurfaceSupported(vk::SurfaceKHR&); 38 | uint HighFamilyIndex() const; 39 | nonstd::span GraphicsQueues(); 40 | nonstd::span ComputeQueues(); 41 | nonstd::span TransferQueues(); 42 | 43 | private: 44 | 45 | std::shared_ptr scheduler_; 46 | 47 | vk::Device device_; 48 | vk::PhysicalDevice physicalDevice_; 49 | 50 | std::vector graphicsQueues_; 51 | std::vector computeQueues_; 52 | std::vector transferQueues_; 53 | 54 | // Dynamic dispatcher for extensions 55 | vk::DispatchLoaderDynamic dispatcher_; 56 | 57 | 58 | }; 59 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Device/VulkanPhysicalDevice.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanPhysicalDevice.h" 2 | 3 | VulkanPhysicalDevice::VulkanPhysicalDevice(vk::Instance instance, vk::PhysicalDevice device): 4 | instance_(instance), device_(device) 5 | { 6 | } 7 | 8 | const vk::PhysicalDevice& VulkanPhysicalDevice::Handle() 9 | { 10 | 11 | return device_; 12 | 13 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Device/VulkanPhysicalDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | 5 | #include 6 | 7 | 8 | class VulkanPhysicalDevice { 9 | 10 | public: 11 | 12 | VulkanPhysicalDevice(vk::Instance, vk::PhysicalDevice); 13 | ~VulkanPhysicalDevice() = default; 14 | 15 | VulkanPhysicalDevice(const VulkanPhysicalDevice&) = default; 16 | VulkanPhysicalDevice(VulkanPhysicalDevice&&) noexcept = default; 17 | 18 | VulkanPhysicalDevice& operator=(const VulkanPhysicalDevice&) = default; 19 | VulkanPhysicalDevice& operator=(VulkanPhysicalDevice&&) noexcept = default; 20 | 21 | const vk::PhysicalDevice& Handle(); 22 | 23 | private: 24 | 25 | vk::Instance instance_; 26 | vk::PhysicalDevice device_; 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Device/VulkanQueue.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanQueue.h" 2 | 3 | VulkanQueue::VulkanQueue(const vk::Device& device, uint familyIndex, uint index): 4 | device_(device), familyIndex_(familyIndex), index_(index) 5 | { 6 | 7 | queue_ = device_.getQueue(familyIndex_, index_); 8 | } 9 | 10 | bool VulkanQueue::Submit() 11 | { 12 | 13 | return false; 14 | 15 | } 16 | 17 | bool VulkanQueue::Present( 18 | nonstd::span semaphores, 19 | nonstd::span swapChains, 20 | nonstd::span imageIndices) const 21 | { 22 | 23 | assert(swapChains.size() == imageIndices.size()); 24 | 25 | //TODO: Reduce allocation calls 26 | std::vector swapChainResults(swapChains.size()); 27 | 28 | vk::PresentInfoKHR presentInfo; 29 | presentInfo.waitSemaphoreCount = semaphores.size(); 30 | presentInfo.pWaitSemaphores = semaphores.data(); 31 | presentInfo.swapchainCount = swapChains.size(); 32 | presentInfo.pSwapchains = swapChains.data(); 33 | presentInfo.pImageIndices = imageIndices.data(); 34 | presentInfo.pResults = swapChainResults.data(); 35 | 36 | const auto result = queue_.presentKHR(presentInfo); 37 | 38 | bool success = result == vk::Result::eSuccess; 39 | 40 | for (const auto& swapChainResult : swapChainResults) { 41 | 42 | success &= swapChainResult == vk::Result::eSuccess; 43 | 44 | } 45 | 46 | return success; 47 | 48 | } 49 | 50 | const vk::Queue& VulkanQueue::Handle() const 51 | { 52 | 53 | return queue_; 54 | } 55 | 56 | uint VulkanQueue::FamilyIndex() const 57 | { 58 | 59 | return familyIndex_; 60 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Device/VulkanQueue.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Structure/Span.h" 5 | 6 | #include 7 | 8 | 9 | class VulkanQueue { 10 | 11 | public: 12 | 13 | VulkanQueue(const vk::Device& device, uint familyIndex, uint index); 14 | ~VulkanQueue() = default; 15 | 16 | VulkanQueue(const VulkanQueue&) = default; 17 | VulkanQueue(VulkanQueue&&) noexcept = default; 18 | 19 | VulkanQueue& operator=(const VulkanQueue&) = default; 20 | VulkanQueue& operator=(VulkanQueue&&) noexcept = default; 21 | 22 | bool Submit(); 23 | bool Present(nonstd::span semaphores, 24 | nonstd::span swapChains, 25 | nonstd::span imageIndices) const; 26 | 27 | [[nodiscard]] const vk::Queue& Handle() const; 28 | [[nodiscard]] uint FamilyIndex() const; 29 | 30 | private: 31 | 32 | vk::Device device_; 33 | vk::Queue queue_; 34 | 35 | uint familyIndex_; 36 | uint index_; 37 | 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Pipeline/VulkanPipeline.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/Raster/Modules/Vulkan/VulkanRenderPass.h" 4 | #include "Render/Raster/Modules/Vulkan/VulkanShader.h" 5 | #include "VulkanPipelineCache.h" 6 | #include "VulkanPipelineLayout.h" 7 | 8 | #include 9 | 10 | class Resource; 11 | class VulkanDevice; 12 | class Vertex; 13 | 14 | class VulkanPipeline { 15 | 16 | public: 17 | 18 | VulkanPipeline(const vk::Device&, nonstd::span, 19 | const vk::RenderPass&, 20 | uint); 21 | ~VulkanPipeline(); 22 | 23 | VulkanPipeline(const VulkanPipeline&) = delete; 24 | VulkanPipeline(VulkanPipeline&&) noexcept = default; 25 | 26 | VulkanPipeline& operator=(const VulkanPipeline&) = delete; 27 | VulkanPipeline& operator=(VulkanPipeline&&) noexcept = default; 28 | 29 | [[nodiscard]] const vk::Pipeline& Handle() const; 30 | 31 | 32 | private: 33 | 34 | vk::Device device_; 35 | 36 | std::vector stages_; 37 | 38 | VulkanPipelineCache pipelineCache_; 39 | VulkanPipelineLayout pipelineLayout_; 40 | 41 | vk::Pipeline pipeline_; 42 | 43 | 44 | }; 45 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Pipeline/VulkanPipelineCache.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanPipelineCache.h" 2 | 3 | VulkanPipelineCache::VulkanPipelineCache(const vk::Device& device): 4 | device_(device) 5 | { 6 | 7 | vk::PipelineCacheCreateInfo pipelineCreateInfo; 8 | // TODO: pipeline serialization n' such 9 | 10 | pipelineCache_ = device_.createPipelineCache(pipelineCreateInfo); 11 | 12 | } 13 | 14 | VulkanPipelineCache::~VulkanPipelineCache() 15 | { 16 | 17 | device_.destroyPipelineCache(pipelineCache_); 18 | 19 | } 20 | 21 | const vk::PipelineCache& VulkanPipelineCache::Handle() 22 | { 23 | 24 | return pipelineCache_; 25 | 26 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Pipeline/VulkanPipelineCache.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class VulkanPipelineCache { 7 | 8 | public: 9 | 10 | VulkanPipelineCache(const vk::Device& device); 11 | ~VulkanPipelineCache(); 12 | 13 | VulkanPipelineCache(const VulkanPipelineCache&) = delete; 14 | VulkanPipelineCache(VulkanPipelineCache&&) noexcept = default; 15 | 16 | VulkanPipelineCache& operator=(const VulkanPipelineCache&) = delete; 17 | VulkanPipelineCache& operator=(VulkanPipelineCache&&) noexcept = default; 18 | 19 | const vk::PipelineCache& Handle(); 20 | 21 | 22 | private: 23 | 24 | vk::Device device_; 25 | vk::PipelineCache pipelineCache_; 26 | 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Pipeline/VulkanPipelineLayout.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanPipelineLayout.h" 2 | 3 | VulkanPipelineLayout::VulkanPipelineLayout(const vk::Device& device): 4 | device_(device) 5 | { 6 | vk::PipelineLayoutCreateInfo pipelineLayoutInfo; 7 | pipelineLayoutInfo.setLayoutCount = 0; 8 | pipelineLayoutInfo.pushConstantRangeCount = 0; 9 | 10 | 11 | pipelineLayout_ = device_.createPipelineLayout(pipelineLayoutInfo, nullptr); 12 | } 13 | 14 | VulkanPipelineLayout::~VulkanPipelineLayout() 15 | { 16 | 17 | device_.destroyPipelineLayout(pipelineLayout_); 18 | 19 | } 20 | 21 | const vk::PipelineLayout& VulkanPipelineLayout::Handle() 22 | { 23 | 24 | return pipelineLayout_; 25 | 26 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Pipeline/VulkanPipelineLayout.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class VulkanPipelineLayout { 7 | 8 | public: 9 | 10 | VulkanPipelineLayout(const vk::Device& device); 11 | ~VulkanPipelineLayout(); 12 | 13 | VulkanPipelineLayout(const VulkanPipelineLayout&) = delete; 14 | VulkanPipelineLayout(VulkanPipelineLayout&&) noexcept = default; 15 | 16 | VulkanPipelineLayout& operator=(const VulkanPipelineLayout&) = delete; 17 | VulkanPipelineLayout& operator=(VulkanPipelineLayout&&) noexcept = default; 18 | 19 | const vk::PipelineLayout& Handle(); 20 | 21 | private: 22 | 23 | vk::Device device_; 24 | vk::PipelineLayout pipelineLayout_; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Surface/VulkanFrame.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanFrame.h" 2 | 3 | VulkanFrameBuffer& VulkanFrame::Framebuffer() 4 | { 5 | 6 | return framebuffer_.value(); 7 | 8 | } 9 | 10 | VulkanSemaphore& VulkanFrame::RenderSemaphore() 11 | { 12 | 13 | return renderSemaphore_.value(); 14 | 15 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Surface/VulkanFrame.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/Raster/Modules/Vulkan/VulkanFramebuffer.h" 4 | #include "Render/Raster/Modules/Vulkan/VulkanSemaphore.h" 5 | #include "Render/Raster/Modules/Vulkan/VulkanFence.h" 6 | 7 | #include 8 | 9 | class VulkanFrame{ 10 | 11 | public: 12 | 13 | VulkanFrame() = default; 14 | ~VulkanFrame() = default; 15 | 16 | VulkanFrame(const VulkanFrame&) = delete; 17 | VulkanFrame(VulkanFrame&&) noexcept = default; 18 | 19 | VulkanFrame& operator=(const VulkanFrame&) = delete; 20 | VulkanFrame& operator=(VulkanFrame&&) noexcept = default; 21 | 22 | VulkanFrameBuffer& Framebuffer(); 23 | VulkanSemaphore& RenderSemaphore(); 24 | 25 | private: 26 | 27 | std::optional framebuffer_; 28 | std::optional presentSemaphore_; 29 | std::optional renderSemaphore_; 30 | std::optional imageFence_; 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Surface/VulkanSurface.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanSurface.h" 2 | 3 | VulkanSurface::VulkanSurface(const vk::Instance& instance, const vk::SurfaceKHR& surface): 4 | instance_(instance), 5 | surface_(surface), 6 | format_ {vk::Format::eB8G8R8A8Unorm, vk::ColorSpaceKHR::eSrgbNonlinear} 7 | { 8 | } 9 | 10 | VulkanSurface::~VulkanSurface() 11 | { 12 | 13 | instance_.destroySurfaceKHR(surface_); 14 | 15 | } 16 | 17 | vk::SurfaceKHR VulkanSurface::Handle() const 18 | { 19 | 20 | return surface_; 21 | 22 | } 23 | 24 | vk::SurfaceFormatKHR VulkanSurface::UpdateFormat(const VulkanDevice& device) 25 | { 26 | 27 | const auto& physicalDevice = device.Physical(); 28 | 29 | vk::PhysicalDeviceSurfaceInfo2KHR surfaceInfo; 30 | surfaceInfo.surface = surface_; 31 | 32 | const auto formats = 33 | physicalDevice.getSurfaceFormats2KHR(surfaceInfo, device.DispatchLoader()); 34 | 35 | // TODO: pick formats better 36 | if (!formats.empty() && formats.front().surfaceFormat.format == vk::Format::eUndefined) { 37 | return format_; 38 | } 39 | 40 | for (const auto& format : formats) { 41 | 42 | if (format.surfaceFormat.format == vk::Format::eB8G8R8A8Unorm && 43 | format.surfaceFormat.colorSpace == vk::ColorSpaceKHR::eSrgbNonlinear) { 44 | return format_; 45 | } 46 | } 47 | 48 | format_.format = formats.front().surfaceFormat.format; 49 | format_.colorSpace = formats.front().surfaceFormat.colorSpace; 50 | 51 | return format_; 52 | } 53 | 54 | vk::SurfaceFormatKHR VulkanSurface::Format() const 55 | { 56 | 57 | return format_; 58 | 59 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Surface/VulkanSurface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/Raster/Modules/Vulkan/Device/VulkanDevice.h" 4 | 5 | #include 6 | 7 | class VulkanSurface { 8 | 9 | public: 10 | 11 | VulkanSurface(const vk::Instance&, const vk::SurfaceKHR&); 12 | ~VulkanSurface(); 13 | 14 | VulkanSurface(const VulkanSurface&) = delete; 15 | VulkanSurface(VulkanSurface&&) noexcept = default; 16 | 17 | VulkanSurface& operator=(const VulkanSurface&) = delete; 18 | VulkanSurface& operator=(VulkanSurface&&) noexcept = default; 19 | 20 | [[nodiscard]] vk::SurfaceKHR Handle() const; 21 | 22 | [[nodiscard]] vk::SurfaceFormatKHR UpdateFormat(const VulkanDevice& device); 23 | [[nodiscard]] vk::SurfaceFormatKHR Format() const; 24 | 25 | private: 26 | 27 | vk::Instance instance_; 28 | vk::SurfaceKHR surface_; 29 | vk::Extent2D size_; 30 | 31 | vk::SurfaceFormatKHR format_; 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/Surface/VulkanSwapChain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/Raster/Modules/Vulkan/Pipeline/VulkanPipeline.h" 4 | #include "Core/Composition/Component/Component.h" 5 | 6 | #include 7 | 8 | class VulkanDevice; 9 | class VulkanSurface; 10 | 11 | class VulkanSwapChain : Component { 12 | 13 | public: 14 | 15 | VulkanSwapChain(VulkanDevice&, 16 | VulkanSurface&, 17 | bool, 18 | VulkanSwapChain* = nullptr); 19 | ~VulkanSwapChain(); 20 | 21 | VulkanSwapChain(const VulkanSwapChain&) = delete; 22 | VulkanSwapChain(VulkanSwapChain&& o) noexcept = default; 23 | 24 | VulkanSwapChain& operator=(const VulkanSwapChain&) = delete; 25 | VulkanSwapChain& operator=(VulkanSwapChain&& other) noexcept = default; 26 | 27 | nonstd::span Images(); 28 | nonstd::span ImageViews(); 29 | [[nodiscard]] uint ActiveImageIndex() const; 30 | 31 | void AcquireImage(const vk::Semaphore&); 32 | 33 | [[nodiscard]] const vk::Device& Device() const; 34 | [[nodiscard]] vk::Extent2D Size() const; 35 | [[nodiscard]] vk::SwapchainKHR Handle() const; 36 | 37 | 38 | private: 39 | 40 | vk::Device device_; 41 | 42 | std::vector renderImages_; 43 | std::vector renderImageViews_; 44 | 45 | uint activeImageIndex_; 46 | 47 | vk::Extent2D size_; 48 | vk::SwapchainKHR swapChain_; 49 | 50 | 51 | }; 52 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanFence.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanFence.h" 2 | 3 | VulkanFence::VulkanFence(vk::Device device): 4 | device_(device) 5 | { 6 | 7 | vk::FenceCreateInfo fenceInfo; 8 | fenceInfo.flags = vk::FenceCreateFlagBits::eSignaled; 9 | 10 | fence_ = device.createFence(fenceInfo); 11 | 12 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanFence.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class VulkanFence 6 | { 7 | 8 | public: 9 | 10 | VulkanFence(vk::Device); 11 | ~VulkanFence() = default; 12 | 13 | VulkanFence(const VulkanFence&) = delete; 14 | VulkanFence(VulkanFence&&) noexcept = default; 15 | 16 | VulkanFence& operator=(const VulkanFence&) = delete; 17 | VulkanFence& operator=(VulkanFence&&) noexcept = default; 18 | 19 | 20 | private: 21 | 22 | vk::Device device_; 23 | 24 | vk::Fence fence_; 25 | 26 | }; 27 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanFramebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanFramebuffer.h" 2 | 3 | #include "VulkanRenderPass.h" 4 | 5 | VulkanFrameBuffer::VulkanFrameBuffer(const vk::Device& device, 6 | nonstd::span attachments, 7 | VulkanRenderPass& renderPass, 8 | vk::Extent2D& size): 9 | device_(device) 10 | { 11 | 12 | vk::FramebufferCreateInfo framebufferInfo; 13 | framebufferInfo.flags = vk::FramebufferCreateFlags(); 14 | framebufferInfo.renderPass = renderPass.Handle(); 15 | framebufferInfo.attachmentCount = attachments.size(); 16 | framebufferInfo.pAttachments = attachments.data(); 17 | framebufferInfo.width = size.width; 18 | framebufferInfo.height = size.height; 19 | framebufferInfo.layers = 1; 20 | 21 | 22 | frameBuffer_ = device_.createFramebuffer(framebufferInfo); 23 | 24 | } 25 | 26 | VulkanFrameBuffer::~VulkanFrameBuffer() { 27 | 28 | device_.destroyFramebuffer(frameBuffer_); 29 | 30 | } 31 | 32 | const vk::Framebuffer& VulkanFrameBuffer::Handle() const 33 | { 34 | 35 | return frameBuffer_; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanFramebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "Core/Structure/Span.h" 6 | 7 | class VulkanRenderPass; 8 | 9 | class VulkanFrameBuffer{ 10 | 11 | public: 12 | 13 | VulkanFrameBuffer(const vk::Device& device, 14 | nonstd::span, 15 | VulkanRenderPass&, 16 | vk::Extent2D&); 17 | ~VulkanFrameBuffer(); 18 | 19 | VulkanFrameBuffer(const VulkanFrameBuffer&) = delete; 20 | VulkanFrameBuffer(VulkanFrameBuffer&&) noexcept = default; 21 | 22 | VulkanFrameBuffer& operator=(const VulkanFrameBuffer&) = delete; 23 | VulkanFrameBuffer& operator=(VulkanFrameBuffer&&) noexcept = default; 24 | 25 | const vk::Framebuffer& Handle() const; 26 | 27 | private: 28 | 29 | vk::Device device_; 30 | vk::Framebuffer frameBuffer_; 31 | 32 | 33 | }; 34 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanInstance.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Structure/Span.h" 5 | #include "Core/Composition/Entity/Entity.h" 6 | 7 | #include 8 | #include 9 | 10 | class VulkanPhysicalDevice; 11 | 12 | 13 | class VulkanInstance { 14 | 15 | public: 16 | 17 | VulkanInstance(const vk::ApplicationInfo&, 18 | nonstd::span, 19 | nonstd::span); 20 | ~VulkanInstance(); 21 | 22 | VulkanInstance(const VulkanInstance&) = default; 23 | VulkanInstance(VulkanInstance&&) noexcept = default; 24 | 25 | VulkanInstance& operator=(const VulkanInstance&) = default; 26 | VulkanInstance& operator=(VulkanInstance&&) noexcept = default; 27 | 28 | const vk::Instance& Handle() const; 29 | 30 | std::vector EnumeratePhysicalDevices(); 31 | 32 | private: 33 | 34 | vk::Instance instance_; 35 | 36 | 37 | // Dynamic dispatcher for extensions 38 | vk::DispatchLoaderDynamic dispatcher_; 39 | 40 | // Debug state 41 | // TODO: Should be conditionally included when the class is only debug mode. 42 | 43 | static VkBool32 DebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT, 44 | VkDebugUtilsMessageTypeFlagsEXT, 45 | const VkDebugUtilsMessengerCallbackDataEXT*, 46 | void*); 47 | 48 | vk::DebugUtilsMessengerEXT debugMessenger_; 49 | 50 | }; 51 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanRenderPass.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanRenderPass.h" 2 | 3 | VulkanRenderPass::VulkanRenderPass(const VulkanDevice& device, 4 | nonstd::span subPassAttachments, 5 | nonstd::span subPassDescriptions, 6 | nonstd::span subPassDependencies): 7 | device_(device.Logical()) 8 | { 9 | 10 | vk::RenderPassCreateInfo2KHR renderPassInfo; 11 | renderPassInfo.flags = vk::RenderPassCreateFlags(); 12 | renderPassInfo.attachmentCount = static_cast(subPassAttachments.size()); 13 | renderPassInfo.pAttachments = subPassAttachments.data(); 14 | renderPassInfo.subpassCount = static_cast(subPassDescriptions.size()); 15 | renderPassInfo.pSubpasses = subPassDescriptions.data(); 16 | renderPassInfo.dependencyCount = static_cast(subPassDependencies.size()); 17 | renderPassInfo.pDependencies = subPassDependencies.data(); 18 | renderPassInfo.correlatedViewMaskCount = 0; 19 | renderPassInfo.pCorrelatedViewMasks = nullptr; 20 | 21 | renderPass_ = device_.createRenderPass2KHR(renderPassInfo, nullptr, device.DispatchLoader()); 22 | 23 | } 24 | 25 | VulkanRenderPass::~VulkanRenderPass() { 26 | 27 | device_.destroyRenderPass(renderPass_); 28 | 29 | } 30 | 31 | const vk::RenderPass& VulkanRenderPass::Handle() const 32 | { 33 | 34 | return renderPass_; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanRenderPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Device/VulkanDevice.h" 5 | 6 | #include 7 | 8 | class VulkanRenderPass 9 | { 10 | 11 | public: 12 | 13 | VulkanRenderPass(const VulkanDevice&, 14 | nonstd::span subPassAttachments, 15 | nonstd::span subPassDescriptions, 16 | nonstd::span subPassDependencies); 17 | ~VulkanRenderPass(); 18 | 19 | VulkanRenderPass(const VulkanRenderPass&) = delete; 20 | VulkanRenderPass(VulkanRenderPass&&) noexcept = default; 21 | 22 | VulkanRenderPass& operator=(const VulkanRenderPass&) = delete; 23 | VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = default; 24 | 25 | const vk::RenderPass& Handle() const; 26 | 27 | private: 28 | 29 | vk::Device device_; 30 | vk::RenderPass renderPass_; 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanSemaphore.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanSemaphore.h" 2 | 3 | VulkanSemaphore::VulkanSemaphore(vk::Device device) : 4 | device_(device) 5 | { 6 | 7 | vk::SemaphoreCreateInfo semaphoreInfo; 8 | 9 | semaphore_ = device.createSemaphore(semaphoreInfo); 10 | 11 | } 12 | 13 | vk::Semaphore VulkanSemaphore::Handle() const 14 | { 15 | 16 | return semaphore_; 17 | 18 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanSemaphore.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class VulkanSemaphore 6 | { 7 | 8 | public: 9 | 10 | VulkanSemaphore(vk::Device); 11 | ~VulkanSemaphore() = default; 12 | 13 | VulkanSemaphore(const VulkanSemaphore&) = delete; 14 | VulkanSemaphore(VulkanSemaphore&&) noexcept = default; 15 | 16 | VulkanSemaphore& operator=(const VulkanSemaphore&) = delete; 17 | VulkanSemaphore& operator=(VulkanSemaphore&&) noexcept = default; 18 | 19 | [[nodiscard]] vk::Semaphore Handle() const; 20 | 21 | private: 22 | 23 | vk::Device device_; 24 | 25 | vk::Semaphore semaphore_; 26 | 27 | }; 28 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanShader.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanShader.h" 2 | #include "Device/VulkanDevice.h" 3 | #include "Core/Utility/Exception/Exception.h" 4 | #include "Transput/Resource/Resource.h" 5 | 6 | #include 7 | #include 8 | 9 | VulkanShader::VulkanShader(const vk::Device& device, 10 | const vk::ShaderStageFlagBits& shaderType, 11 | const Resource& resource): 12 | device_(device) 13 | { 14 | 15 | const auto& path = resource.Path(); 16 | 17 | if (!std::filesystem::exists(path)) { 18 | throw NotImplemented(); 19 | } 20 | 21 | // TODO: abstract into some sort of loader 22 | std::ifstream file(path.c_str(), std::ifstream::ate | std::ios::binary); 23 | 24 | const size_t fileSize = static_cast(file.tellg()); 25 | std::vector buffer(fileSize); 26 | 27 | file.seekg(0); 28 | file.read(reinterpret_cast(buffer.data()), fileSize); 29 | file.close(); 30 | 31 | vk::ShaderModuleCreateInfo createInfo; 32 | createInfo.codeSize = buffer.size(); 33 | createInfo.pCode = reinterpret_cast(buffer.data()); 34 | 35 | module_ = device.createShaderModule(createInfo, nullptr); 36 | 37 | info_.stage = shaderType; 38 | info_.module = module_; 39 | info_.pName = "main"; 40 | 41 | } 42 | 43 | VulkanShader::~VulkanShader() { 44 | 45 | device_.destroyShaderModule(module_, nullptr); 46 | 47 | } 48 | 49 | const vk::PipelineShaderStageCreateInfo& VulkanShader::PipelineInfo() const 50 | { 51 | 52 | return info_; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanShader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Resource; 6 | class VulkanDevice; 7 | 8 | class VulkanShader { 9 | 10 | public: 11 | 12 | VulkanShader(const vk::Device&, const vk::ShaderStageFlagBits&, const Resource&); 13 | ~VulkanShader(); 14 | 15 | VulkanShader(const VulkanShader&) = delete; 16 | VulkanShader(VulkanShader&& o) noexcept = default; 17 | 18 | VulkanShader& operator=(const VulkanShader&) = delete; 19 | VulkanShader& operator=(VulkanShader&& other) noexcept = default; 20 | 21 | [[nodiscard]] const vk::PipelineShaderStageCreateInfo& PipelineInfo() const; 22 | 23 | 24 | private: 25 | 26 | vk::ShaderModule module_; 27 | vk::PipelineShaderStageCreateInfo info_; 28 | 29 | vk::Device device_; 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanSubPass.cpp: -------------------------------------------------------------------------------- 1 | #include "VulkanSubPass.h" 2 | 3 | VulkanSubPass::VulkanSubPass(const nonstd::span outputAttachmentReferences) 4 | { 5 | 6 | vk::SubpassDescription2KHR& subPass = description_; 7 | subPass.flags = vk::SubpassDescriptionFlags(); 8 | subPass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics; 9 | subPass.viewMask = 0; 10 | subPass.inputAttachmentCount = 0; 11 | subPass.pInputAttachments = nullptr; 12 | subPass.colorAttachmentCount = outputAttachmentReferences.size(); 13 | subPass.pColorAttachments = outputAttachmentReferences.data(); 14 | subPass.pResolveAttachments = nullptr; 15 | subPass.pDepthStencilAttachment = nullptr; 16 | subPass.preserveAttachmentCount = 0; 17 | subPass.pPreserveAttachments = nullptr; 18 | 19 | } 20 | 21 | const vk::SubpassDescription2KHR& VulkanSubPass::Description() const 22 | { 23 | 24 | return description_; 25 | 26 | } -------------------------------------------------------------------------------- /Source/Render/Raster/Modules/Vulkan/VulkanSubPass.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Structure/Span.h" 4 | #include "VulkanShader.h" 5 | 6 | #include 7 | 8 | class VulkanSubPass 9 | { 10 | 11 | public: 12 | 13 | explicit VulkanSubPass(nonstd::span); 14 | ~VulkanSubPass() = default; 15 | 16 | VulkanSubPass(const VulkanSubPass&) = default; 17 | VulkanSubPass(VulkanSubPass&&) noexcept = default; 18 | 19 | VulkanSubPass& operator=(const VulkanSubPass&) = default; 20 | VulkanSubPass& operator=(VulkanSubPass&&) noexcept = default; 21 | 22 | [[nodiscard]] const vk::SubpassDescription2KHR& Description() const; 23 | 24 | private: 25 | 26 | vk::SubpassDescription2KHR description_; 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /Source/Render/Raster/RasterDevice.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class RasterDevice { 6 | 7 | public: 8 | 9 | RasterDevice() = default; 10 | virtual ~RasterDevice() = default; 11 | 12 | RasterDevice(const RasterDevice &) = delete; 13 | RasterDevice(RasterDevice &&) noexcept = default; 14 | 15 | RasterDevice& operator=(const RasterDevice &) = delete; 16 | RasterDevice& operator=(RasterDevice &&) noexcept = default; 17 | 18 | virtual void Synchronize() = 0; 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /Source/Render/Raster/RasterModule.cpp: -------------------------------------------------------------------------------- 1 | #include "RasterModule.h" 2 | 3 | #include "Display/Window/WindowModule.h" 4 | #include "Modules/Vulkan/VulkanRasterBackend.h" 5 | 6 | RasterModule::RasterModule() 7 | { 8 | } 9 | 10 | 11 | //TODO: This needs to instead be runtime loadable from shared libraries or statically linked 12 | std::shared_ptr RasterModule::CreateModule( 13 | std::shared_ptr& scheduler, 14 | std::shared_ptr& entityRegistry, 15 | std::shared_ptr& windowModule) 16 | { 17 | 18 | return std::make_unique(scheduler, entityRegistry, windowModule); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Source/Render/Raster/RasterModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Interface/Module/Module.h" 4 | 5 | #include "Types.h" 6 | #include "RenderCommands.h" 7 | #include "RenderResource.h" 8 | #include "RenderTypes.h" 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | class Scheduler; 15 | class Window; 16 | class RasterDevice; 17 | class WindowParameters; 18 | class SchedulerModule; 19 | class WindowModule; 20 | class CommandList; 21 | 22 | class RasterModule : public Module { 23 | 24 | public: 25 | 26 | RasterModule(); 27 | virtual ~RasterModule() = default; 28 | 29 | RasterModule(const RasterModule &) = delete; 30 | RasterModule(RasterModule &&) noexcept = default; 31 | 32 | RasterModule& operator=(const RasterModule &) = delete; 33 | RasterModule& operator=(RasterModule &&) noexcept = default; 34 | 35 | virtual void Present() = 0; 36 | 37 | virtual Entity CreatePass(const ShaderSet&, std::function) = 0; 38 | virtual Entity CreateSubPass(Entity, const ShaderSet&, std::function) = 0; 39 | virtual void ExecutePass(Entity, Entity, CommandList&) = 0; 40 | 41 | 42 | virtual void CreatePassInput(Entity, Entity, Format) = 0; 43 | virtual void CreatePassOutput(Entity, Entity, Format) = 0; 44 | 45 | virtual Entity CreateSurface(std::any, glm::uvec2) = 0; 46 | virtual void UpdateSurface(Entity, glm::uvec2) = 0; 47 | virtual void RemoveSurface(Entity) = 0; 48 | virtual void AttachSurface(Entity, Entity) = 0; 49 | virtual void DetachSurface(Entity, Entity) = 0; 50 | 51 | // Agnostic raster API interface 52 | virtual void Compile(CommandList&) = 0; 53 | 54 | //Factory 55 | static std::shared_ptr CreateModule(std::shared_ptr&, 56 | std::shared_ptr&, 57 | std::shared_ptr&); 58 | 59 | }; 60 | -------------------------------------------------------------------------------- /Source/Render/Raster/RenderCommands.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include "Core/Composition/Entity/Entity.h" 5 | #include "RenderResource.h" 6 | #include "Core/Structure/External/ExternalBuffer.h" 7 | 8 | enum class CommandType { 9 | Draw, 10 | DrawIndirect, 11 | UpdateBuffer, 12 | UpdateTexture, 13 | CopyBuffer, 14 | CopyTexture 15 | }; 16 | 17 | class RenderCommand{ 18 | 19 | public: 20 | 21 | RenderCommand() = default; 22 | ~RenderCommand() = default; 23 | 24 | }; 25 | 26 | 27 | struct DrawCommand : RenderCommand { 28 | 29 | //draw 30 | uint elementSize; 31 | uint indexOffset; 32 | uint vertexOffset; 33 | 34 | //scissor 35 | glm::uvec2 scissorOffset; 36 | glm::uvec2 scissorExtent; 37 | 38 | //data 39 | Entity vertexBuffer; 40 | Entity indexBuffer; 41 | 42 | }; 43 | 44 | struct DrawIndirectCommand : RenderCommand { 45 | 46 | }; 47 | 48 | struct UpdateBufferCommand : RenderCommand { 49 | 50 | uint offset; 51 | ExternalBuffer data; 52 | Entity buffer; 53 | 54 | }; 55 | 56 | struct UpdateTextureCommand : RenderCommand { 57 | 58 | }; 59 | 60 | struct CopyBufferCommand : RenderCommand { 61 | 62 | }; 63 | 64 | struct CopyTextureCommand : RenderCommand { 65 | 66 | }; -------------------------------------------------------------------------------- /Source/Render/Raster/RenderTypes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | struct ShaderSet 5 | { 6 | 7 | Entity vertex; 8 | 9 | Entity tessellationControl; 10 | 11 | Entity tessellationEvaluation; 12 | 13 | Entity geometry; 14 | 15 | Entity fragment; 16 | 17 | }; 18 | 19 | enum class Format { 20 | 21 | RGBA, 22 | Unknown 23 | 24 | }; -------------------------------------------------------------------------------- /Source/Render/RenderGraph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Rasterer 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Modules/Entity/EntityRenderGraphBackend.cpp 8 | Modules/Entity/EntityRenderGraphBackend.h 9 | RenderGraphParameters.cpp 10 | RenderGraphParameters.h 11 | RenderGraphBuilder.cpp 12 | RenderGraphBuilder.h 13 | RenderGraphModule.cpp 14 | RenderGraphModule.h 15 | ) 16 | -------------------------------------------------------------------------------- /Source/Render/RenderGraph/Modules/Entity/EntityRenderGraphBackend.cpp: -------------------------------------------------------------------------------- 1 | #include "EntityRenderGraphBackend.h" 2 | 3 | #include "Core/Utility/Exception/Exception.h" 4 | #include "Render/Raster/RasterModule.h" 5 | 6 | 7 | EntityRenderGraphBackend::EntityRenderGraphBackend( 8 | std::shared_ptr& rasterModule, 9 | std::shared_ptr& scheduler, 10 | std::shared_ptr& entityRegistry): 11 | RenderGraphModule(rasterModule, scheduler), 12 | rasterModule_(rasterModule), 13 | entityRegistry_(entityRegistry) 14 | { 15 | } 16 | 17 | void EntityRenderGraphBackend::Execute() 18 | { 19 | 20 | for (const auto& [pass, surfaces, callback] : graphTasks_) { 21 | 22 | CommandList commandList; 23 | callback(*entityRegistry_, commandList); 24 | 25 | rasterModule_->Compile(commandList); 26 | 27 | for (const auto& surface : surfaces) { 28 | rasterModule_->ExecutePass(pass, surface, commandList); 29 | } 30 | 31 | } 32 | 33 | } 34 | 35 | 36 | void EntityRenderGraphBackend::CreateRenderPass(RenderTaskParameters& parameters, 37 | std::function(RenderGraphBuilder&)> 38 | passCallback) 39 | { 40 | 41 | std::function callback; 42 | 43 | //Create the renderpass 44 | Entity pass = rasterModule_->CreatePass(parameters.shaders, [&](Entity passID) { 45 | RenderGraphBuilder builder(rasterModule_, entityRegistry_, passID, false); 46 | 47 | // Call the pass construction 48 | callback = passCallback(builder); 49 | 50 | }); 51 | 52 | //Store the execution step for later 53 | graphTasks_.push_back({pass, {}, callback}); 54 | 55 | } -------------------------------------------------------------------------------- /Source/Render/RenderGraph/Modules/Entity/EntityRenderGraphBackend.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Render/RenderGraph/RenderGraphModule.h" 4 | #include 5 | 6 | class RasterModule; 7 | 8 | class EntityRenderGraphBackend final : public RenderGraphModule { 9 | 10 | public: 11 | EntityRenderGraphBackend(std::shared_ptr&, 12 | std::shared_ptr&, 13 | std::shared_ptr&); 14 | ~EntityRenderGraphBackend() override = default; 15 | 16 | EntityRenderGraphBackend(const EntityRenderGraphBackend&) = delete; 17 | EntityRenderGraphBackend(EntityRenderGraphBackend&&) noexcept = default; 18 | 19 | EntityRenderGraphBackend& operator=(const EntityRenderGraphBackend&) = delete; 20 | EntityRenderGraphBackend& operator=(EntityRenderGraphBackend&&) noexcept = default; 21 | 22 | 23 | void Execute() override; 24 | 25 | void CreateRenderPass(RenderTaskParameters&, 26 | std::function( 27 | RenderGraphBuilder&)>) override; 28 | 29 | 30 | private: 31 | 32 | std::shared_ptr rasterModule_; 33 | std::shared_ptr entityRegistry_; 34 | 35 | std::vector, 37 | std::function>> 38 | graphTasks_; 39 | 40 | 41 | }; -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphBuilder.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderGraphBuilder.h" 2 | 3 | RenderGraphBuilder::RenderGraphBuilder(std::shared_ptr& rasterModule, 4 | std::shared_ptr& entityRegistry, 5 | Entity renderPass, 6 | bool subPass): 7 | entityRegistry_(entityRegistry), 8 | rasterModule_(rasterModule), 9 | renderPass_(renderPass), 10 | subPass_(subPass) 11 | { 12 | } 13 | 14 | RenderGraphBuilder::~RenderGraphBuilder() 15 | { 16 | 17 | //When the builder falls out of scope it is done constructing a render pass. 18 | //Provides a great opportunity to validate! 19 | 20 | } 21 | 22 | void RenderGraphBuilder::CreateOutput(RenderGraphOutputParameters& parameters) 23 | { 24 | 25 | rasterModule_->CreatePassOutput(renderPass_, parameters.resource, Format::RGBA); 26 | 27 | } 28 | 29 | void RenderGraphBuilder::CreateInput(RenderGraphInputParameters& parameters) 30 | { 31 | 32 | rasterModule_->CreatePassInput(renderPass_, parameters.resource, Format::RGBA); 33 | 34 | } 35 | 36 | void RenderGraphBuilder::CreateSubpass() 37 | { 38 | 39 | throw NotImplemented(); 40 | 41 | } 42 | 43 | Entity RenderGraphBuilder::View() 44 | { 45 | 46 | Entity returnedEntity = entityRegistry_->CreateEntity(); 47 | entityRegistry_->AttachComponent(returnedEntity); 48 | 49 | return returnedEntity; 50 | } -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphBuilder.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "RenderGraphParameters.h" 4 | #include "Render/Raster/RenderResource.h" 5 | #include "Core/Composition/Entity/EntityRegistry.h" 6 | #include "Render/Raster/RasterModule.h" 7 | 8 | #include 9 | 10 | class RenderGraphBuilder final{ 11 | 12 | public: 13 | 14 | RenderGraphBuilder(std::shared_ptr&, std::shared_ptr&, Entity, bool); 15 | ~RenderGraphBuilder(); 16 | 17 | RenderGraphBuilder(const RenderGraphBuilder &) = delete; 18 | RenderGraphBuilder(RenderGraphBuilder &&) noexcept = default; 19 | 20 | RenderGraphBuilder& operator=(const RenderGraphBuilder &) = delete; 21 | RenderGraphBuilder& operator=(RenderGraphBuilder &&) noexcept = default; 22 | 23 | void CreateOutput(RenderGraphOutputParameters&); 24 | void CreateInput(RenderGraphInputParameters&); 25 | 26 | void CreateSubpass(); 27 | 28 | template 29 | Entity Request(); 30 | 31 | Entity View(); 32 | 33 | 34 | private: 35 | 36 | std::shared_ptr entityRegistry_; 37 | std::shared_ptr rasterModule_; 38 | 39 | Entity renderPass_; 40 | bool subPass_; 41 | 42 | 43 | }; 44 | 45 | template 46 | Entity RenderGraphBuilder::Request() 47 | { 48 | // TODO: C++20 Concepts 49 | static_assert(std::is_base_of::value, 50 | "The type parameter must be a subclass of RenderResource"); 51 | 52 | 53 | Entity returnedEntity = entityRegistry_->CreateEntity(); 54 | entityRegistry_->AttachComponent(returnedEntity); 55 | 56 | return returnedEntity; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphModule.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderGraphModule.h" 2 | 3 | #include "Display/Window/WindowModule.h" 4 | #include "Render/RenderGraph/Modules/Entity/EntityRenderGraphBackend.h" 5 | #include "Render/RenderGraph/RenderGraphModule.h" 6 | 7 | 8 | RenderGraphModule::RenderGraphModule( 9 | std::shared_ptr&, 10 | std::shared_ptr& scheduler): 11 | renderGraph_(scheduler) 12 | { 13 | } 14 | 15 | //TODO: This needs to instead be runtime loadable from shared libraries or statically linked 16 | std::shared_ptr RenderGraphModule::CreateModule( 17 | std::shared_ptr& rasterModule, 18 | std::shared_ptr& scheduler, 19 | std::shared_ptr& entityRegistry) 20 | { 21 | 22 | return std::make_unique(rasterModule, scheduler, entityRegistry); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphModule.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Interface/Module/Module.h" 4 | 5 | #include "Render/Raster/CommandList.h" 6 | #include "Core/Composition/Entity/EntityRegistry.h" 7 | #include "Parallelism/Graph/Graph.h" 8 | #include "RenderGraphParameters.h" 9 | #include "RenderGraphBuilder.h" 10 | #include "Render/Raster/RenderResource.h" 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | class RasterModule; 17 | class SchedulerModule; 18 | 19 | class RenderGraphModule : public Module { 20 | 21 | public: 22 | 23 | RenderGraphModule(std::shared_ptr&, std::shared_ptr&); 24 | virtual ~RenderGraphModule() = default; 25 | 26 | RenderGraphModule(const RenderGraphModule &) = delete; 27 | RenderGraphModule(RenderGraphModule &&) noexcept = default; 28 | 29 | RenderGraphModule& operator=(const RenderGraphModule &) = delete; 30 | RenderGraphModule& operator=(RenderGraphModule &&) noexcept = default; 31 | 32 | 33 | virtual void Execute() = 0; 34 | 35 | virtual void CreateRenderPass(RenderTaskParameters&, 36 | std::function(RenderGraphBuilder&)>) = 0; 37 | 38 | // Factory 39 | static std::shared_ptr CreateModule( 40 | std::shared_ptr&, 41 | std::shared_ptr&, 42 | std::shared_ptr&); 43 | 44 | protected: 45 | 46 | Graph renderGraph_; 47 | 48 | 49 | }; 50 | -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphParameters.cpp: -------------------------------------------------------------------------------- 1 | #include "RenderGraphParameters.h" 2 | -------------------------------------------------------------------------------- /Source/Render/RenderGraph/RenderGraphParameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Core/Composition/Entity/Entity.h" 4 | #include "Render/Raster/RenderTypes.h" 5 | 6 | #include 7 | 8 | struct RenderTaskParameters { 9 | 10 | public: 11 | RenderTaskParameters() = default; 12 | ~RenderTaskParameters() = default; 13 | 14 | std::string name; 15 | 16 | ShaderSet shaders; 17 | 18 | }; 19 | 20 | struct RenderGraphOutputParameters { 21 | 22 | public: 23 | RenderGraphOutputParameters() = default; 24 | ~RenderGraphOutputParameters() = default; 25 | 26 | std::string name; 27 | Entity resource; 28 | 29 | }; 30 | 31 | struct RenderGraphInputParameters { 32 | 33 | public: 34 | RenderGraphInputParameters() = default; 35 | ~RenderGraphInputParameters() = default; 36 | 37 | std::string name; 38 | Entity resource; 39 | 40 | }; 41 | -------------------------------------------------------------------------------- /Source/Tracer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Tracer 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Camera/Camera.cpp 8 | Camera/Camera.h 9 | Camera/Film/Film.cpp 10 | Camera/Film/Film.h 11 | Camera/Film/Filter/Filter.cpp 12 | Camera/Film/Filter/Filter.h 13 | Camera/Lens/Lens.h 14 | Ray/Ray.cpp 15 | Ray/Ray.h 16 | Ray/RayEngine.cpp 17 | Ray/RayEngine.h 18 | Ray/RayJob.cpp 19 | Ray/RayJob.h 20 | ) 21 | 22 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Tracer/Camera/Camera.h" 2 | 3 | #define GLM_ENABLE_EXPERIMENTAL 4 | #include "glm/gtx/rotate_vector.hpp" 5 | 6 | Camera::Camera() : 7 | aspectRatio(0), 8 | position(0.0f, 0.0f, 0.0f), 9 | forward(0.0f, 0.0f, 1.0f), 10 | right(1.0f, 0.0f, 0.0f), 11 | fieldOfView(90.0f, 65.0f), 12 | aperture(0.02f), 13 | focalDistance(0.17f) 14 | { 15 | } 16 | 17 | Camera::~Camera() { 18 | 19 | } 20 | 21 | 22 | //__device__ void Camera::GenerateRay(const uint sampleID, glm::vec3& origin, glm::vec3& direction, curandState& randState) { 23 | // 24 | // glm::vec2 sample = film.GetSample(sampleID, randState); 25 | // 26 | // //float angle = TWO_PI * curand_uniform(&randState); 27 | // //float distance = aperture * sqrt(curand_uniform(&randState)); 28 | // 29 | // /*ALTERNATE aperaturPoint 30 | // + ((cos(angle) * distance) * right) + ((sin(angle) * distance) * verticalAxis)*/ 31 | // 32 | // glm::vec3 aperturePoint = position; 33 | // 34 | // glm::vec3 pointOnPlaneOneUnitAwayFromEye = 35 | // aperturePoint + forward + (2 * sample.x - 1) * xHelper + (2 * sample.y - 1) * yHelper; 36 | // //printf("%f %f/n", xHelper.x, xHelper.y); 37 | // 38 | // origin = glm::vec3(aperturePoint.x, aperturePoint.y, aperturePoint.z); 39 | // glm::vec3 tmp = glm::normalize(position + (pointOnPlaneOneUnitAwayFromEye - position) * focalDistance - aperturePoint); 40 | // direction = glm::vec3(tmp.x, tmp.y, tmp.z); 41 | //} 42 | 43 | void Camera::UpdateVariables() { 44 | verticalAxis = glm::normalize(glm::cross(right, forward)); 45 | 46 | yHelper = verticalAxis * static_cast( tan((glm::radians(-fieldOfView.y * 0.5f)))); 47 | xHelper = right * static_cast( tan(glm::radians(fieldOfView.x * 0.5f))); 48 | } 49 | 50 | void Camera::OffsetOrientation(float x, float y) { 51 | right = glm::normalize(glm::rotateY(right, glm::radians(x))); 52 | forward = glm::normalize(glm::rotateY(forward, glm::radians(x))); 53 | 54 | forward = glm::normalize(glm::rotate(forward, glm::radians(y), right)); 55 | } 56 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Tracer/Camera/Film/Film.h" 4 | //#include 5 | 6 | #include "Types.h" 7 | #include "glm/glm.hpp" 8 | 9 | class Camera { 10 | public: 11 | Camera(); 12 | ~Camera(); 13 | 14 | //Given a positive integer, this function fills in the given ray's values based on the camera's position orientation and lens. 15 | //__device__ void SetupRay(const uint&, Ray&, thrust::default_random_engine&, thrust::uniform_real_distribution&); 16 | //__device__ void GenerateRay(const uint, glm::vec3&, glm::vec3&, curandState&); 17 | 18 | void OffsetOrientation(float x, float y); 19 | 20 | void UpdateVariables(); 21 | 22 | float aspectRatio; 23 | glm::vec3 position; 24 | glm::vec3 forward; 25 | glm::vec3 right; 26 | glm::vec2 fieldOfView; 27 | Film film; 28 | 29 | private: 30 | float aperture; 31 | float focalDistance; 32 | 33 | //VARIABLE PRECALC 34 | glm::vec3 verticalAxis; 35 | glm::vec3 yHelper; 36 | glm::vec3 xHelper; 37 | 38 | 39 | }; 40 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Film/Film.cpp: -------------------------------------------------------------------------------- 1 | #include "Tracer/Camera/Film/Film.h" 2 | #include "stdio.h" 3 | 4 | //results(S_BEST_DEVICE) 5 | Film::Film(){ 6 | resolutionRatio = 1.0f; 7 | } 8 | 9 | Film::~Film() { 10 | 11 | } 12 | 13 | 14 | //__device__ glm::vec2 Film::GetSample(uint id, curandState& randState) { 15 | // 16 | // glm::vec2 parameterization = glm::vec2( 17 | // (curand_uniform(&randState) - 0.5f + id % resolution.x) / (resolution.x - 1), 18 | // (curand_uniform(&randState) - 0.5f + id / resolution.x) / (resolution.y - 1) 19 | // ); 20 | // 21 | // return parameterization; 22 | // 23 | //} 24 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Film/Film.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | 6 | class Film { 7 | 8 | public: 9 | 10 | Film(); 11 | ~Film(); 12 | 13 | /* 14 | * Gets a normalized. 15 | * @param parameter1 The first parameter. 16 | * @return The normalized. 17 | */ 18 | 19 | //__device__ glm::vec2 GetSample(uint, curandState&); 20 | 21 | glm::uvec2 resolutionPrev; 22 | glm::uvec2 resolution; 23 | glm::uvec2 resolutionMax; 24 | 25 | float resolutionRatio; 26 | 27 | glm::vec4* results; 28 | int* hits; 29 | 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Film/Filter/CUDA/Filter.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Parallelism/Compute/CUDA/Utility/CUDAHelper.cuh" 4 | // 5 | //#include 6 | // 7 | //namespace CUDAFilter { 8 | // 9 | // __host__ void HermiteBicubic(glm::vec4* data, glm::uvec2& originalSize, glm::uvec2& desiredSize); 10 | // __host__ void Nearest(glm::vec4* data, const glm::uvec2& originalSize, const glm::uvec2& desiredSize); 11 | //} 12 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Film/Filter/Filter.cpp: -------------------------------------------------------------------------------- 1 | #include "Filter.h" 2 | 3 | //#include "CUDA/Filter.cuh" 4 | 5 | //void Filter::Nearest(glm::vec4* data, glm::uvec2 originalSize, glm::uvec2 desiredSize) { 6 | // CUDAFilter::Nearest(data,originalSize,desiredSize); 7 | //} -------------------------------------------------------------------------------- /Source/Tracer/Camera/Film/Filter/Filter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //#include 3 | // 4 | //namespace Filter { 5 | // 6 | // void IterativeBicubic(glm::vec4* data, glm::uvec2 originalSize, glm::uvec2 desiredSize); 7 | // void Nearest(glm::vec4* data, glm::uvec2 originalSize, glm::uvec2 desiredSize); 8 | //} 9 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Lens/CUDA/Lens.cu: -------------------------------------------------------------------------------- 1 | #include "Lens.cuh" 2 | 3 | Lens::Lens() 4 | { 5 | } 6 | 7 | Lens::~Lens(){ 8 | 9 | } -------------------------------------------------------------------------------- /Source/Tracer/Camera/Lens/CUDA/Lens.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Lens { 4 | public: 5 | Lens(); 6 | ~Lens(); 7 | 8 | 9 | private: 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /Source/Tracer/Camera/Lens/Lens.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //# if defined(__CUDACC__) 4 | 5 | #include "CUDA/Lens.cuh" 6 | 7 | //# else 8 | // 9 | //#include "OpenCL/CLCamera.h" 10 | // 11 | //#endif -------------------------------------------------------------------------------- /Source/Tracer/Ray/CUDA/RayEngine.cuh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include "Tracer/RayJob.h" 4 | //#include "Core/Scene/Scene.h" 5 | //#include "Tracer/Ray.h" 6 | //#include 7 | // 8 | ////class BVH; 9 | //// 10 | ////namespace RayEngineCUDA { 11 | //// 12 | //// __global__ void ExecuteJobs(uint n, Ray* rays, BVH* bvh, Vertex* vertices, Face* faces, BoundingBox*, int* counter); 13 | //// __global__ void ProcessHits(uint n, RayJob* job, int jobSize, Ray* rays, Ray* raysNew, Sky* sky, Face* faces, Vertex* vertices, Material* materials, int * nAtomic, curandState* randomState); 14 | //// __global__ void EngineSetup(uint n, RayJob* jobs, int jobSize); 15 | //// __global__ void RaySetup(uint n, uint jobSize, RayJob* job, Ray* rays, int* nAtomic, curandState* randomState); 16 | //// __global__ void RandomSetup(uint n, curandState* randomState, uint raySeed); 17 | //// 18 | ////} 19 | -------------------------------------------------------------------------------- /Source/Tracer/Ray/OpenCL/CLRay.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Tracer/Ray/OpenCL/CLRay.h -------------------------------------------------------------------------------- /Source/Tracer/Ray/OpenCL/CLRayEngine.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Tracer/Ray/OpenCL/CLRayEngine.h -------------------------------------------------------------------------------- /Source/Tracer/Ray/OpenCL/CLRayJob.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/synodic/Soul-Engine/991f7a40b5ef8bba241479c25d45809be71d10bc/Source/Tracer/Ray/OpenCL/CLRayJob.h -------------------------------------------------------------------------------- /Source/Tracer/Ray/Ray.cpp: -------------------------------------------------------------------------------- 1 | #include "Ray.h" -------------------------------------------------------------------------------- /Source/Tracer/Ray/Ray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | #include 5 | 6 | class Ray 7 | { 8 | 9 | public: 10 | 11 | glm::vec4 storage; 12 | glm::vec4 origin; 13 | glm::vec4 direction; 14 | glm::vec2 bary; 15 | uint currentHit; 16 | uint resultOffset; 17 | char job; 18 | 19 | }; -------------------------------------------------------------------------------- /Source/Tracer/Ray/RayJob.cpp: -------------------------------------------------------------------------------- 1 | #include "RayJob.h" 2 | 3 | static uint counter = 0; 4 | 5 | RayJob::RayJob(rayType whatToGet, bool _canChange, float newSamples) 6 | { 7 | 8 | type = whatToGet; 9 | samples = newSamples; 10 | rayOffset = 0; 11 | canChange = _canChange; 12 | id = counter++; 13 | } -------------------------------------------------------------------------------- /Source/Tracer/Ray/RayJob.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Types.h" 4 | //#include "Parallelism/ComputeOld/CUDA/Utility/CudaHelper.cuh" 5 | #include "Tracer/Camera/Camera.h" 6 | 7 | enum rayType { 8 | RayCOLOUR //RayCOLOUR: A vec3 of RGB values to be displayed 9 | , RayCOLOUR_SPECTRAL //RayCOLOUR_SPECTRAL: Uses additional processing time to perform spectral operations and returns the result in vec3 RGB space. 10 | , RayDISTANCE //RayDISTANCE: A float of the specific ray's distance travelled. 11 | , RayOBJECT_ID //RayOBJECT_ID: A unique ID of the first Object hit in a uint. 12 | , RayNORMAL //RayNORMAL: The normal at the first point hit in a vec3. 13 | , RayUV //RayUV: The UV at the first point hit in a vec2. 14 | }; 15 | 16 | class RayJob 17 | { 18 | public: 19 | 20 | //@param The information to be retreiving from the job. 21 | //@param The number of rays/data-points to be cast into the scene. 22 | //@param The number of samples per ray or point that will be averaged into the result. Is more of a probability than number. 23 | //@param A camera that contains all the information to shoot a ray. 24 | //@param The amount of buffers used for result storage. 25 | RayJob() = default; 26 | RayJob(rayType, bool, float); 27 | 28 | //result variables 29 | 30 | //counting variables 31 | uint rayOffset; 32 | 33 | uint id; 34 | //common variables 35 | Camera camera; 36 | rayType type; 37 | float samples; 38 | bool canChange; 39 | 40 | }; -------------------------------------------------------------------------------- /Source/Transput/Resource/Asset.cpp: -------------------------------------------------------------------------------- 1 | #include "Asset.h" 2 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Asset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Asset { 4 | 5 | public: 6 | 7 | Asset() = default; 8 | ~Asset() = default; 9 | 10 | }; -------------------------------------------------------------------------------- /Source/Transput/Resource/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Resource 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Asset.cpp 8 | Asset.h 9 | Resource.cpp 10 | Resource.h 11 | ResourceLoader.h 12 | ) 13 | 14 | add_subdirectory(Modules/Shader) 15 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | ############################################## 3 | #Resource 4 | 5 | target_sources(${PROJECT_NAME} 6 | PRIVATE 7 | Modules/SPIRV/SPIRVAsset.cpp 8 | Modules/SPIRV/SPIRVAsset.h 9 | Modules/SPIRV/SPIRVResource.cpp 10 | Modules/SPIRV/SPIRVResource.h 11 | Modules/SPIRV/SPIRVLoader.cpp 12 | Modules/SPIRV/SPIRVLoader.h 13 | ShaderAsset.cpp 14 | ShaderAsset.h 15 | ShaderResource.cpp 16 | ShaderResource.h 17 | ShaderLoader.h 18 | ShaderLoader.cpp 19 | ) 20 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVAsset.cpp: -------------------------------------------------------------------------------- 1 | #include "SPIRVAsset.h" 2 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/Modules/Shader/ShaderAsset.h" 4 | 5 | class SPIRVAsset : public ShaderAsset { 6 | 7 | public: 8 | 9 | SPIRVAsset() = default; 10 | ~SPIRVAsset() = default; 11 | 12 | }; 13 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "SPIRVLoader.h" 2 | 3 | #include "Core/Utility/Exception/Exception.h" 4 | 5 | 6 | void SPIRVLoader::Load(const std::string_view& fileName) { 7 | 8 | throw NotImplemented(); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/Modules/Shader/ShaderLoader.h" 4 | 5 | class SPIRVLoader : public ShaderLoader { 6 | 7 | public: 8 | 9 | SPIRVLoader() = default; 10 | ~SPIRVLoader() override = default; 11 | 12 | void Load(const std::string_view&) override; 13 | 14 | 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVResource.cpp: -------------------------------------------------------------------------------- 1 | #include "SPIRVResource.h" 2 | 3 | SPIRVResource::SPIRVResource(const std::string_view resourcePath): 4 | ShaderResource(resourcePath) 5 | { 6 | 7 | } -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/Modules/SPIRV/SPIRVResource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/Modules/Shader/ShaderResource.h" 4 | 5 | class SPIRVResource : public ShaderResource { 6 | 7 | public: 8 | 9 | SPIRVResource(std::string_view); 10 | ~SPIRVResource() = default; 11 | 12 | 13 | private: 14 | 15 | 16 | 17 | }; 18 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderAsset.cpp: -------------------------------------------------------------------------------- 1 | #include "ShaderAsset.h" 2 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderAsset.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/Asset.h" 4 | 5 | class ShaderAsset : public Asset { 6 | 7 | public: 8 | ShaderAsset() = default; 9 | ~ShaderAsset() = default; 10 | 11 | }; 12 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderLoader.cpp: -------------------------------------------------------------------------------- 1 | #include "ShaderLoader.h" 2 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/ResourceLoader.h" 4 | 5 | 6 | class ShaderLoader : public ResourceLoader { 7 | 8 | public: 9 | 10 | ShaderLoader() = default; 11 | ~ShaderLoader() override = default; 12 | 13 | void Load(const std::string_view&) override = 0; 14 | 15 | 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderResource.cpp: -------------------------------------------------------------------------------- 1 | #include "ShaderResource.h" 2 | 3 | ShaderResource::ShaderResource(const std::string_view resourcePath): 4 | Resource(resourcePath) 5 | { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Modules/Shader/ShaderResource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Transput/Resource/Resource.h" 4 | 5 | class ShaderResource : public Resource { 6 | 7 | public: 8 | 9 | ShaderResource(std::string_view); 10 | ~ShaderResource() = default; 11 | 12 | private: 13 | 14 | 15 | }; 16 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Resource.cpp: -------------------------------------------------------------------------------- 1 | #include "Resource.h" 2 | 3 | Resource::Resource(const std::string_view resourcePath) : 4 | path_(resourcePath) 5 | { 6 | 7 | } 8 | 9 | const std::filesystem::path& Resource::Path() const { 10 | 11 | return path_; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Source/Transput/Resource/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Resource { 6 | 7 | public: 8 | 9 | Resource(std::string_view); 10 | ~Resource() = default; 11 | 12 | const std::filesystem::path& Path() const; 13 | 14 | 15 | private: 16 | 17 | std::filesystem::path path_; 18 | 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /Source/Transput/Resource/ResourceLoader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class ResourceLoader { 6 | 7 | public: 8 | 9 | ResourceLoader() = default; 10 | virtual ~ResourceLoader() = default; 11 | 12 | ResourceLoader(const ResourceLoader&) = delete; 13 | ResourceLoader(ResourceLoader&&) noexcept = default; 14 | 15 | ResourceLoader& operator=(const ResourceLoader&) = delete; 16 | ResourceLoader& operator=(ResourceLoader&&) noexcept = default; 17 | 18 | virtual void Load(const std::string_view&) = 0; 19 | 20 | 21 | }; -------------------------------------------------------------------------------- /Tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1 FATAL_ERROR) 2 | 3 | 4 | ############################################## 5 | #Project 6 | 7 | project(SoulEngineTests 8 | VERSION 0.0.1 9 | DESCRIPTION "Real-time simulation and rendering engine." 10 | LANGUAGES CXX 11 | ) 12 | -------------------------------------------------------------------------------- /Tests/Logger/Source.cpp: -------------------------------------------------------------------------------- 1 | #include "..\..\Source Files\Utility\Logger.h" 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | namespace pt = boost::posix_time; 8 | std::string line; 9 | std::string time; 10 | time = pt::to_iso_string(pt::second_clock::universal_time()); 11 | Logger::WriteFile(); 12 | std::ifstream file("Engine.log"); 13 | std::getline(file, line); 14 | assert(line.compare(time) == 0); 15 | std::getline(file, line); 16 | assert(line.compare("File: Engine.log Line: 7 | ") == 0); 17 | file.close(); 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Tools/Conan/Test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | project(PackageTest CXX) 3 | 4 | include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) 5 | conan_basic_setup() 6 | 7 | add_executable(${PROJECT_NAME} PackageTest.cpp) 8 | target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) -------------------------------------------------------------------------------- /Tools/Conan/Test/PackageTest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | std::cout << "<<>>" << std::endl; 6 | return 0; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /Tools/Conan/Test/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, tools 2 | 3 | import os 4 | 5 | 6 | class SoulEngineTest(ConanFile): 7 | settings = "os", "compiler", "build_type", "arch" 8 | generators = "cmake" 9 | 10 | def build(self): 11 | cmake = CMake(self) 12 | cmake.configure() 13 | cmake.build() 14 | 15 | def test(self): 16 | if not tools.cross_building(self.settings): 17 | bin_path = os.path.join("bin", "test_package") 18 | self.run(bin_path, run_environment=True) 19 | -------------------------------------------------------------------------------- /Tools/Conan/conanfile.py: -------------------------------------------------------------------------------- 1 | from conans import ConanFile, CMake, tools 2 | from pathlib import Path 3 | 4 | import os 5 | 6 | class SoulEngine(ConanFile): 7 | 8 | name = "SoulEngine" 9 | version = "0.0.1" 10 | author = "Synodic Software" 11 | license = "GPLv3" 12 | url = "https://github.com/Synodic-Software/Soul-Engine" 13 | description = "Soul Engine is a real-time visualization and simulation engine built on the back of CUDA, OpenCL, and Vulkan." 14 | 15 | settings = "os", "compiler", "build_type", "arch" 16 | options = {"shared": [True, False]} 17 | default_options = {"shared": False} 18 | 19 | generators = "cmake" 20 | 21 | scm = { 22 | "type" : "git", 23 | "url" : "auto", 24 | "subfolder": "../..", 25 | "revision" : "auto" 26 | } 27 | 28 | no_copy_source = True 29 | 30 | requires = ( 31 | "glfw/3.3@bincrafters/stable", 32 | "boost/1.71.0@conan/stable", 33 | "glm/0.9.9.5@g-truc/stable", 34 | "stb/20190512@conan/stable", 35 | "flatbuffers/1.11.0@google/stable", 36 | "imgui/1.69@bincrafters/stable" 37 | ) 38 | 39 | def configureCMake(self): 40 | 41 | cmake = CMake(self) 42 | cmake.configure(source_folder="../..") 43 | 44 | return cmake 45 | 46 | 47 | def build(self): 48 | 49 | cmake = self.configureCMake() 50 | cmake.build() 51 | 52 | 53 | def package(self): 54 | 55 | pass 56 | 57 | 58 | def package_info(self): 59 | 60 | self.cpp_info.libs = ["SoulEngine"] 61 | 62 | projectRoot = Path('.') / ".." / ".." 63 | self.cpp_info.includedirs = [str(projectRoot / "Includes")] 64 | self.cpp_info.resdirs = [str(projectRoot / "Resources")] 65 | 66 | #CMAKE environment variables 67 | self.user_info.ENGINE_PATH = str(projectRoot.absolute()) -------------------------------------------------------------------------------- /Tools/Python/GetRelativePaths.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import os 3 | from pathlib import Path, PurePosixPath, PurePath 4 | 5 | #TODO: Create API for this module if imported 6 | 7 | def _main(): 8 | parser = argparse.ArgumentParser() 9 | 10 | #Commandline arguments 11 | parser.add_argument("path", help="The root path to list relative files and directories for") 12 | parser.add_argument('-i','--ignores', nargs='*', help='List of file names to ignore') 13 | args = parser.parse_args() 14 | 15 | #Find the relative files and directories 16 | relativePaths = set() 17 | 18 | for fileDir, _, files in os.walk(args.path): 19 | for fileName in files: 20 | 21 | if fileName in args.ignores: 22 | continue 23 | 24 | relativeDirectory = Path(os.path.relpath(fileDir, args.path)) 25 | relativeFile = relativeDirectory / fileName 26 | relativePaths.add(PurePosixPath(relativeFile)) 27 | 28 | relativePaths = sorted(relativePaths) 29 | 30 | for path in relativePaths: 31 | print(path) 32 | 33 | 34 | if __name__== "__main__": 35 | _main() --------------------------------------------------------------------------------