Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine.h
Go to the documentation of this file.
1#pragma once
2
8
12#include <vector>
13#include <vulkan/vulkan_core.h>
14#include <future>
15#include <atomic>
18
19namespace Input
20{
21 class InputManager;
22 class XrRig;
23}
24
25namespace Engine {
26
27 namespace Debug::UI
28 {
29 class ImGuiManager;
30 } // namespace Debug::UI
31 class GameModule;
32
33 namespace Rendering
34 {
35 class MirrorView;
36 }
37
38 class EngineKern {
39 public:
40 EngineKern() = default;
42
47
51 void run(std::unique_ptr<GameModule> module);
52
56 const std::unique_ptr<Core::AssetManager>& getAssetManager() const;
57
58 private:
59 double gameTime = 0.0f;
60 public:
61
67
73
78 [[nodiscard]] Core::ApplicationContext * getContext() const { return applicationContext; }
79
80 private:
82
83 std::unique_ptr<Core::AssetManager> assetManager;
84
85 // Game reference
86 std::unique_ptr<GameModule> module;
87
88 // debug messenger for vulkan debug layer
89 VkDebugUtilsMessengerEXT debugMessenger = nullptr;
90
93 Input::XrRig* xrRig = nullptr;
94 uint64_t frameCounter = 0;
96 public:
101 [[nodiscard]] uint32_t getRenderableSceneObjectCount() const;
102
107 [[nodiscard]] Rendering::Renderer * getRenderer() const;
108
113 [[nodiscard]] Input::XrInputHandler* getXrInputHandler() const { return xrInputHandler; }
114
119 [[nodiscard]] Input::InputManager* getInputManager() const { return inputManager; }
120
125 [[nodiscard]] Input::XrRig* getXrRig() const { return xrRig; }
126
131 [[nodiscard]] Rendering::Headset * getHeadset() const { return headset; }
132
133 [[nodiscard]] World::WindField& getWindField() { return windField_; }
134 [[nodiscard]] const World::WindField& getWindField() const { return windField_; }
135 private:
136
138
139 // command pool for all commands
140
141 std::vector<VkCommandBuffer> commandBuffers;
142
143 // frame time counter
144 uint32_t currentFrame = 0;
145
146 uint32_t textureCount = 0;
147 uint32_t meshCount = 0;
148
149 // virtual reality
150 bool isXrSessionRunning = false;
151
152 // function
154
155 PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr;
157
158 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo);
159
160 static VkBool32 debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
161 VkDebugUtilsMessageTypeFlagsEXT messageType,
162 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
163
165
167 Rendering::MirrorView * mirrorView = nullptr;
170 Debug::UI::ImGuiManager * imguiManager_ = nullptr;
171
172 // Async frame completion for pipelined rendering
173 // This allows xrWaitFrame(N+1) to overlap with GPU work from frame N
174 std::future<void> frameCompletionFuture_;
175 std::atomic<bool> previousFrameXrComplete_{true};
176
177 // After a headset sleep/wake state transition, force several frames to
178 // complete synchronously (endXrFrame on the main thread). This prevents
179 // the engine from rapid-firing frames that saturate the XR compositor
180 // queue and cause xrEndFrame to block indefinitely while the main thread
181 // deadlocks at frameCompletionFuture_.wait().
183
184 // Named thread pool for XR frame operations (shows up properly in Tracy)
185 std::unique_ptr<NamedThreadPool> xrFrameThreadPool_;
186
194 void completeFrameAsync(VkFence graphicsFence, bool presentMirror);
195
199 void createStartupScene() const;
200
205
211
212#ifdef ENABLE_TRACY
213 Debug::Tracy::TracyVkContextManager tracyContextManager_;
214#endif
215
216
217 public:
222
223 const std::unique_ptr<Core::SceneManager>& getSceneManager() const { return sceneManager; }
224 private:
225
226 void calculateFrameTime( double& lastTime );
232 void fixLoadingAssets() const;
238 void update( double & gameTime );
239
245
249 void mainLoop();
250
254 void cleanup();
255
257
259
260 public:
266 template <typename T>
267 void loadScene() {
268 sceneManager->loadScene<T>();
269 }
270
275 [[nodiscard]] Core::PhysicsEngine * getPhysicsEngine() const { return physicsEngine; }
276
281 [[nodiscard]] Core::AudioEngine* getAudioEngine() const { return audioEngine_; }
282
283 private:
284 std::unique_ptr<Core::SceneManager> sceneManager;
285
287
289
294
299
301 };
302
307 public:
308 virtual ~EngineManager() = default;
309
316
323
327 void setEngine(EngineKern* engineInstance);
328
329 protected:
331
332 EngineManager() = default;
333 EngineManager(const EngineManager&) = delete;
335 };
336
337
338}
The application context is the core class which stores the basic openxr and vulkan objects.
Owns the miniaudio engine and provides the playback API.
Definition AudioEngine.h:32
The physics engine manages creating and destroying physics objects for the physics simulation.
const std::unique_ptr< Core::AssetManager > & getAssetManager() const
Getter.
void calculateFrameTime(double &lastTime)
void mainLoop()
Main engine loop where the rendering and game steps happen.
std::atomic< bool > previousFrameXrComplete_
Definition Engine.h:175
void update(double &gameTime)
World::WindField windField_
Definition Engine.h:300
std::vector< VkCommandBuffer > commandBuffers
Definition Engine.h:141
VkDebugUtilsMessengerEXT debugMessenger
Definition Engine.h:89
double getGlobalTimeSeconds()
Gets the time since the beginning of the simulation (sum of all delta times)
uint32_t getRenderableSceneObjectCount() const
Counts the amount of entities which have renderable components.
void initVulkan()
Initialisation of all vulkan related resources.
Rendering::Renderer * renderer
Definition Engine.h:169
Input::XrRig * getXrRig() const
Getter for the resolved XR rig poses.
Definition Engine.h:125
Core::PhysicsEngine * physicsEngine
Definition Engine.h:293
void createStartupScene() const
Creates the initial scene the engine loads before an actual level is loaded.
Core::AudioEngine * audioEngine_
Definition Engine.h:298
World::WindField & getWindField()
Definition Engine.h:133
Input::XrInputHandler * getXrInputHandler() const
Getter for the XR input handler.
Definition Engine.h:113
const std::unique_ptr< Core::SceneManager > & getSceneManager() const
Definition Engine.h:223
void processMirrorWindowEvents()
processes glfw window events like key presses or window events
void captureRenderdocFrame()
Captures a frame for render doc if the define RENDERDOC_ENABLED is set.
uint64_t frameCounter
Definition Engine.h:94
Rendering::Headset * headset
Definition Engine.h:168
std::unique_ptr< GameModule > module
Definition Engine.h:86
void createPhysicsWorld()
PHYSICS.
EngineKern()=default
double gameTime
Definition Engine.h:59
Input::XrRig * xrRig
Definition Engine.h:93
void createVulkanDebugMessenger()
void loadScene()
Triggers the load of a new scene. Will be executed once the current frame has finished processing.
Definition Engine.h:267
const World::WindField & getWindField() const
Definition Engine.h:134
void completeFrameAsync(VkFence graphicsFence, bool presentMirror)
Runs on background thread: waits for GPU fence, ends XR frame, presents mirror This allows CPU work t...
uint32_t currentFrame
Definition Engine.h:144
void initializePlogDebugger()
Rendering::MirrorView * mirrorView
Definition Engine.h:167
Rendering::Headset * getHeadset() const
Getter for the VR headset.
Definition Engine.h:131
void tryCreateApplicationContext()
will try to create a window and if there is no openxr runtime detected it will wait 5 seconds and try...
Core::PhysicsEngine * getPhysicsEngine() const
Getter for the pointer to the physics engine.
Definition Engine.h:275
void createAudioEngine()
AUDIO.
void fixLoadingAssets() const
When assets have been requested but are not loaded yet the static mesh data is in a limbo where it ha...
Core::AudioEngine * getAudioEngine() const
Getter for the audio engine.
Definition Engine.h:281
std::future< void > frameCompletionFuture_
Definition Engine.h:174
bool descriptorDataIsDirty
Definition Engine.h:137
std::unique_ptr< Core::SceneManager > sceneManager
Definition Engine.h:284
uint32_t meshCount
Definition Engine.h:147
bool isXrSessionRunning
Definition Engine.h:150
double deltaTimeSeconds
Definition Engine.h:81
double getDeltaTimeSeconds()
gets the time between frames
Input::InputManager * inputManager
Definition Engine.h:92
Core::ApplicationContext * applicationContext
Definition Engine.h:166
int forceSyncFramesRemaining_
Definition Engine.h:182
Input::XrInputHandler * xrInputHandler
Definition Engine.h:91
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
std::unique_ptr< Core::AssetManager > assetManager
Definition Engine.h:83
Debug::UI::ImGuiManager * imguiManager_
Definition Engine.h:170
Rendering::Renderer * getRenderer() const
Getter for the renderer.
void initRenderDoc()
Initialization point for software driven captures.
void processResourceLoadingPipelines()
Collects and processes the pipelines which have finished and dispatches the new steps....
Input::InputManager * getInputManager() const
Getter for the unified input action manager.
Definition Engine.h:119
void cleanup()
Cleanup of pointers for vulkan and subsystems.
static VkBool32 debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData)
uint32_t textureCount
Definition Engine.h:146
void run(std::unique_ptr< GameModule > module)
Runs the engine. Is the entry point for this module.
std::unique_ptr< NamedThreadPool > xrFrameThreadPool_
Definition Engine.h:185
bool checkValidationLayerSupport()
void destroyPhysicsWorld()
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT
Definition Engine.h:155
Core::ApplicationContext * getContext() const
Gets the application context which stores the vulkan instance the device and queues.
Definition Engine.h:78
static EngineManager & getInstance()
gets a reference to the engine manager
virtual ~EngineManager()=default
Engine::EngineKern * engine
Definition Engine.h:330
EngineKern * getEngineModule()
gets the pointer to the engine object
void setEngine(EngineKern *engineInstance)
set the content pointer for this singleton
EngineManager & operator=(const EngineManager &)=delete
EngineManager(const EngineManager &)=delete
The renderer is the main class for rendering. It owns all data which is used any time in any frame....
Definition Renderer.h:71
This is the base class for a wind field. (An area in which a vector field pushes the player glider co...
Definition WindField.h:58
Handles OpenXR input actions and controller state.