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 <memory>
16#include <atomic>
19
20namespace Input
21{
22 class InputManager;
23 class XrRig;
24}
25
26namespace Engine {
27
28 namespace Debug::UI
29 {
30 class ImGuiManager;
31 } // namespace Debug::UI
32 class GameModule;
33
34 namespace Core
35 {
36 class AssetRegistry;
37 class TimerManager;
38 }
39
40 namespace Rendering
41 {
42 class MirrorView;
43 }
44
45 class EngineKern {
46 public:
47 EngineKern() = default;
49
54
58 void run(std::unique_ptr<GameModule> module);
59
63 const std::unique_ptr<Core::AssetManager>& getAssetManager() const;
64 [[nodiscard]] Core::AssetRegistry* getAssetRegistry() const;
65
66 private:
67 double gameTime = 0.0f;
68 public:
69
75
81
86 [[nodiscard]] Core::ApplicationContext * getContext() const { return applicationContext; }
87
88 private:
90
91 std::unique_ptr<Core::AssetManager> assetManager;
92 std::unique_ptr<Core::AssetRegistry> assetRegistry;
93
94 // Game reference
95 std::unique_ptr<GameModule> module;
96
97 // debug messenger for vulkan debug layer
98 VkDebugUtilsMessengerEXT debugMessenger = nullptr;
99
102 Input::XrRig* xrRig = nullptr;
103 uint64_t frameCounter = 0;
106 public:
111 [[nodiscard]] uint32_t getRenderableSceneObjectCount() const;
112
117 [[nodiscard]] Rendering::Renderer * getRenderer() const;
118
123 [[nodiscard]] Input::XrInputHandler* getXrInputHandler() const { return xrInputHandler; }
124
129 [[nodiscard]] Input::InputManager* getInputManager() const { return inputManager; }
130
135 [[nodiscard]] Input::XrRig* getXrRig() const { return xrRig; }
136
137 [[nodiscard]] Core::TimerManager * getTimerManager() const { return timerManager_.get(); }
138
143 [[nodiscard]] Rendering::Headset * getHeadset() const { return headset; }
144
145 [[nodiscard]] World::WindField& getWindField() { return windField_; }
146 [[nodiscard]] const World::WindField& getWindField() const { return windField_; }
147 private:
148
150
151 // command pool for all commands
152
153 std::vector<VkCommandBuffer> commandBuffers;
154
155 // frame time counter
156 uint32_t currentFrame = 0;
157
158 uint32_t textureCount = 0;
159 uint32_t meshCount = 0;
160
161 // virtual reality
162 bool isXrSessionRunning = false;
163
164 // function
166
167 PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT = nullptr;
169
170 void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo);
171
172 static VkBool32 debugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity,
173 VkDebugUtilsMessageTypeFlagsEXT messageType,
174 const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData);
175
177
179 Rendering::MirrorView * mirrorView = nullptr;
182 Debug::UI::ImGuiManager * imguiManager_ = nullptr;
183
184 // Async frame completion for pipelined rendering
185 // This allows xrWaitFrame(N+1) to overlap with GPU work from frame N
186 std::future<void> frameCompletionFuture_;
187 std::atomic<bool> previousFrameXrComplete_{true};
188
189 // After a headset sleep/wake state transition, force several frames to
190 // complete synchronously (endXrFrame on the main thread). This prevents
191 // the engine from rapid-firing frames that saturate the XR compositor
192 // queue and cause xrEndFrame to block indefinitely while the main thread
193 // deadlocks at frameCompletionFuture_.wait().
195
196 // Named thread pool for XR frame operations (shows up properly in Tracy)
197 std::unique_ptr<NamedThreadPool> xrFrameThreadPool_;
198
199 std::unique_ptr<Core::TimerManager> timerManager_;
200
208 void completeFrameAsync(VkFence graphicsFence, bool presentMirror);
209
213 void createStartupScene() const;
214
219
225
226#ifdef ENABLE_TRACY
227 Debug::Tracy::TracyVkContextManager tracyContextManager_;
228#endif
229
230
231 public:
236
237 const std::unique_ptr<Core::SceneManager>& getSceneManager() const { return sceneManager; }
238 private:
239
240 void calculateFrameTime( double& lastTime );
246 void fixLoadingAssets() const;
252 void update( double & gameTime );
253
259
263 void mainLoop();
264
268 void cleanup();
269
271
273
274 public:
280 template <typename T>
281 void loadScene() {
282 sceneManager->loadScene<T>();
283 }
284
289 [[nodiscard]] Core::PhysicsEngine * getPhysicsEngine() const { return physicsEngine; }
290
295 [[nodiscard]] Core::AudioEngine* getAudioEngine() const { return audioEngine_; }
296
297 private:
298 std::unique_ptr<Core::SceneManager> sceneManager;
299
301
303
308
313
315 };
316
321 public:
322 virtual ~EngineManager() = default;
323
330
337
341 void setEngine(EngineKern* engineInstance);
342
343 protected:
345
346 EngineManager() = default;
347 EngineManager(const EngineManager&) = delete;
349 };
350
351
352}
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:29
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:187
void update(double &gameTime)
World::WindField windField_
Definition Engine.h:314
std::vector< VkCommandBuffer > commandBuffers
Definition Engine.h:153
Core::TimerManager * getTimerManager() const
Definition Engine.h:137
VkDebugUtilsMessengerEXT debugMessenger
Definition Engine.h:98
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:181
Input::XrRig * getXrRig() const
Getter for the resolved XR rig poses.
Definition Engine.h:135
Core::PhysicsEngine * physicsEngine
Definition Engine.h:307
void createStartupScene() const
Creates the initial scene the engine loads before an actual level is loaded.
Core::AudioEngine * audioEngine_
Definition Engine.h:312
World::WindField & getWindField()
Definition Engine.h:145
Core::AssetRegistry * getAssetRegistry() const
Input::XrInputHandler * getXrInputHandler() const
Getter for the XR input handler.
Definition Engine.h:123
const std::unique_ptr< Core::SceneManager > & getSceneManager() const
Definition Engine.h:237
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:103
Rendering::Headset * headset
Definition Engine.h:180
std::unique_ptr< GameModule > module
Definition Engine.h:95
void createPhysicsWorld()
PHYSICS.
EngineKern()=default
double gameTime
Definition Engine.h:67
Input::XrRig * xrRig
Definition Engine.h:102
void createVulkanDebugMessenger()
void loadScene()
Triggers the load of a new scene. Will be executed once the current frame has finished processing.
Definition Engine.h:281
const World::WindField & getWindField() const
Definition Engine.h:146
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:156
void initializePlogDebugger()
Rendering::MirrorView * mirrorView
Definition Engine.h:179
Rendering::Headset * getHeadset() const
Getter for the VR headset.
Definition Engine.h:143
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:289
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:295
std::future< void > frameCompletionFuture_
Definition Engine.h:186
std::unique_ptr< Core::AssetRegistry > assetRegistry
Definition Engine.h:92
bool descriptorDataIsDirty
Definition Engine.h:149
std::unique_ptr< Core::SceneManager > sceneManager
Definition Engine.h:298
uint32_t meshCount
Definition Engine.h:159
bool isXrSessionRunning
Definition Engine.h:162
double deltaTimeSeconds
Definition Engine.h:89
double getDeltaTimeSeconds()
gets the time between frames
Input::InputManager * inputManager
Definition Engine.h:101
Core::ApplicationContext * applicationContext
Definition Engine.h:178
int forceSyncFramesRemaining_
Definition Engine.h:194
Input::XrInputHandler * xrInputHandler
Definition Engine.h:100
void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT &createInfo)
std::unique_ptr< Core::AssetManager > assetManager
Definition Engine.h:91
Debug::UI::ImGuiManager * imguiManager_
Definition Engine.h:182
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:129
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:158
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:197
bool checkValidationLayerSupport()
std::unique_ptr< Core::TimerManager > timerManager_
Definition Engine.h:199
void destroyPhysicsWorld()
PFN_vkDestroyDebugUtilsMessengerEXT vkDestroyDebugUtilsMessengerEXT
Definition Engine.h:167
Core::ApplicationContext * getContext() const
Gets the application context which stores the vulkan instance the device and queues.
Definition Engine.h:86
static EngineManager & getInstance()
gets a reference to the engine manager
virtual ~EngineManager()=default
Engine::EngineKern * engine
Definition Engine.h:344
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:77
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
Action-based input dispatcher for polling providers and invoking callbacks.
Handles OpenXR input actions and controller state.
Resolves raw XR play-space poses into world-space tracked hand poses.
Definition XrRig.h:44
Manages IBL (Image-Based Lighting) resources for specular reflections.