Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
FrameProcessing.h
Go to the documentation of this file.
1#pragma once
2#include <filesystem>
3#include <future>
4
5#include "EcsData.h"
9#include "Engine/Core/Asset.h"
13
14namespace Engine::Assets
15{
16 class Audio;
18 class Model;
19 class ModelAssetManager;
20 class MeshAssetManager;
22 class Texture;
23} // namespace Engine
24
25namespace Engine
26{
27 class EngineKern;
28}
29
30namespace Engine::Core
31{
32 class AudioEngine;
33 class RenderingDataManager;
34}
35
36namespace Engine::Ecs
37{
42 friend class Core::AssetManager;
43 friend class EngineKern;
44
45 public:
47 Assets::TextureAssetManager * textureAssetManager, NamedThreadPool * assetLoaderPool );
48
53 void submitAsset(const std::filesystem::path &asset);
54
59 void tick(bool async = true);
60
65 void setRenderingDataManager( Engine::Core::RenderingDataManager * renderingDataManager) { renderingDataManager_ = renderingDataManager; }
66
71 void setMaxTexturesPerFrame(size_t max) { maxTexturesPerFrame_ = max; }
72
77 size_t getPendingCount() const {
78 return assetQueue_.size() + exrHeaderFutures_.size() + imageFutures_.size() + ktx2LoadFutures_.size();
79 }
80
82
83 private:
84 void requestExrHeaders(bool async = true);
85 void loadImageData(bool async = true);
86 void retrieveImageData(bool async = true);
87 void processKtx2Textures(bool async = true);
88
90 Core::RenderingDataManager * renderingDataManager_ = nullptr;
92
93 std::vector<std::filesystem::path> assetQueue_;
94 std::vector<std::filesystem::path> ktx2Queue_;
95 std::vector<ExrHeaderFuture> exrHeaderFutures_;
96 std::vector<AssetLoadingImage> imageFutures_;
97 std::vector<Ktx2LoadFuture> ktx2LoadFutures_;
98
100 };
101
107 friend class AssetManager;
108 friend class Engine;
109
110 public:
114 Assets::ModelAssetManager * modelAssetManager,
117 Core::AssetManager * assetManager = nullptr
118 );
119
124 void submitAsset(const std::filesystem::path &asset);
125
126 void tick(bool async = true);
127
132 void setRenderingDataManager( Core::RenderingDataManager * renderingDataManager) { renderingDataManager_ = renderingDataManager; }
133
139
146 std::vector<CompletedMeshletGeneration> takePendingMeshletCompletions();
147
153 [[nodiscard]] bool hasPendingWork() const {
154 return
155 !assetQueue_.empty() ||
156 !modelLoadingFutures_.empty() ||
157 !materialResults.empty() ||
158 !primitiveDataFutures.empty() ||
159 !meshletGenerationFutures.empty() ||
161 !pendingKtx2Futures_.empty();
162 }
163
165
166 private:
167 void submitLoadModel(bool async = true);
168 void processModel(bool async = true);
169 void processSkinData(bool async = true);
170 void processMaterial(bool async = true);
171 void processMeshData(bool async = true);
172 void processKtx2Textures(bool async = true);
173
183 void processTextures(Assets::Model* modelAsset,
184 const std::shared_ptr<tinygltf::Model>& model,
185 const std::filesystem::path& modelPath);
186
189 Assets::ModelAssetManager * modelAssetManager = nullptr;
191 Core::RenderingDataManager * renderingDataManager_ = nullptr;
194
195 NamedThreadPool * threadPool_ = new NamedThreadPool( 2, "Gltf loader" );
197
198 std::vector<std::filesystem::path> assetQueue_;
199 std::vector<GltfModelFuture> modelLoadingFutures_;
200 std::vector<MaterialLoadingData> materialResults;
201 std::vector<std::future<PrimitiveDataLoading>> primitiveDataFutures;
202 std::vector<std::future<CompletedMeshletGeneration>> meshletGenerationFutures;
203
204 // Queue for completed meshlet generations waiting to be written to registry
205 std::vector<CompletedMeshletGeneration> pendingMeshletCompletions_;
206
207 // KTX2 texture loads submitted to thread pool, polled each tick()
208 std::vector<Ktx2LoadFuture> pendingKtx2Futures_;
209
211 };
212
220 friend class AssetManager;
221 friend class EngineKern;
222
223 public:
225 Assets::AudioAssetManager * audioAssetManager,
226 NamedThreadPool* assetLoaderPool);
227
232 void submitAsset(const std::filesystem::path& asset);
233
238 void tick(bool async = true);
239
244 void setAudioEngine( Core::AudioEngine * engine) { audioEngine_ = engine; }
245
249 [[nodiscard]] size_t getPendingCount() const {
250 return assetQueue_.size() + loadFutures_.size();
251 }
252
254
255 private:
258
260 std::filesystem::path path;
262 uint64_t generation = 0;
263 std::future<Assets::AudioData> future;
264 };
265
269
270 std::vector<std::filesystem::path> assetQueue_;
271 std::vector<AudioLoadFuture> loadFutures_;
272
274 };
275
276} // namespace Ecs
Manages audio assets by filesystem path, providing dedup and lookup.
Definition AudioAsset.h:70
Holds decoded PCM audio data as an engine asset.
Definition AudioAsset.h:13
Stores mesh data with their primitives.
Definition MeshAsset.h:47
Wrapper for texture data.
Owns the miniaudio engine and provides the playback API.
Definition AudioEngine.h:32
void setAudioEngine(Core::AudioEngine *engine)
Set the AudioEngine to notify when assets finish loading.
std::vector< AudioLoadFuture > loadFutures_
void tick(bool async=true)
Advances the pipeline state machine (call once per frame)
size_t getPendingCount() const
Returns the number of audio assets still pending.
void submitAsset(const std::filesystem::path &asset)
Submit an audio file for async loading.
AudioAssetPipeline(Assets::AudioAssetManager *audioAssetManager, NamedThreadPool *assetLoaderPool)
std::vector< std::filesystem::path > assetQueue_
Assets::AudioAssetManager * audioAssetManager_
void submitAsset(const std::filesystem::path &asset)
Requests the load of a gltf file.
Assets::MeshAssetManager * meshAssetManager
void submitLoadModel(bool async=true)
std::vector< std::future< CompletedMeshletGeneration > > meshletGenerationFutures
void processKtx2Textures(bool async=true)
std::vector< std::future< PrimitiveDataLoading > > primitiveDataFutures
void tick(bool async=true)
Assets::Loaders::GltfLoader * loader
void setTextureAssetPipeline(TextureAssetPipeline *pipeline)
Sets the TextureAssetPipeline for async lightmap loading.
std::vector< std::filesystem::path > assetQueue_
std::vector< GltfModelFuture > modelLoadingFutures_
bool hasPendingWork() const
Check if the pipeline still has in-flight work (loading, meshlet generation, etc.) Used to defer buff...
void processMaterial(bool async=true)
std::vector< MaterialLoadingData > materialResults
std::vector< CompletedMeshletGeneration > pendingMeshletCompletions_
void processMeshData(bool async=true)
void processSkinData(bool async=true)
std::vector< CompletedMeshletGeneration > takePendingMeshletCompletions()
Get and clear pending meshlet completions. Call this at a safe point to retrieve completed meshlet ge...
Assets::TextureAssetManager * textureAssetManager
TextureAssetPipeline * textureAssetPipeline_
For async lightmap loading.
void processTextures(Assets::Model *modelAsset, const std::shared_ptr< tinygltf::Model > &model, const std::filesystem::path &modelPath)
Extracts and registers texture assets from loaded glTF models.
std::vector< Ktx2LoadFuture > pendingKtx2Futures_
Assets::ModelAssetManager * modelAssetManager
ModelAssetPipeline(Assets::MeshAssetManager *meshAssetManager, Assets::MaterialAssetManager *materialAssetManager, Assets::ModelAssetManager *modelAssetManager, Assets::TextureAssetManager *textureAssetManager, NamedThreadPool *assetLoaderPool, Core::AssetManager *assetManager=nullptr)
Assets::MaterialAssetManager * materialAssetManager
void setRenderingDataManager(Core::RenderingDataManager *renderingDataManager)
Sets the RenderingDataManager to notify when meshes/materials are loaded.
Core::AssetManager * assetManager_
For TextureHandleRegistry access.
void processModel(bool async=true)
Core::RenderingDataManager * renderingDataManager_
Infrastructure to load images into the ecs.
std::vector< std::filesystem::path > ktx2Queue_
std::vector< ExrHeaderFuture > exrHeaderFutures_
size_t getPendingCount() const
Returns the number of textures still pending in the pipeline.
std::vector< Ktx2LoadFuture > ktx2LoadFutures_
TextureAssetPipeline(Assets::TextureAssetManager *textureAssetManager, NamedThreadPool *assetLoaderPool)
Core::RenderingDataManager * renderingDataManager_
void setRenderingDataManager(Engine::Core::RenderingDataManager *renderingDataManager)
Sets the RenderingDataManager to notify when textures are loaded.
std::vector< std::filesystem::path > assetQueue_
void processKtx2Textures(bool async=true)
void retrieveImageData(bool async=true)
size_t maxTexturesPerFrame_
Rate limit for texture processing per frame.
std::vector< AssetLoadingImage > imageFutures_
Assets::TextureAssetManager * textureAssetManager_
void tick(bool async=true)
Advances the state machine for the entire pipeline.
void loadImageData(bool async=true)
void submitAsset(const std::filesystem::path &asset)
submit the path to an asset relative from the executable to load
void requestExrHeaders(bool async=true)
void setMaxTexturesPerFrame(size_t max)
Sets the maximum number of textures to process per frame.
Tracy-named thread pool using BS_tracy::tracy_thread_pool.
Asset::Ref< std::filesystem::path, Audio > AudioAssetRef
constexpr size_t MAX_AUDIO_LOADS_PER_FRAME
Maximum audio assets to finalize per frame in the pipeline.
Definition AudioConfig.h:24
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9