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"
12
13namespace Engine::Assets
14{
15 class Audio;
18 class Model;
19 class ModelAssetManager;
20 class MeshAssetManager;
21 class SkinAssetManager;
23 class Texture;
24} // namespace Engine
25
26namespace Engine
27{
28 class EngineKern;
29}
30
31namespace Engine::Core
32{
33 class AudioEngine;
34 class RenderingDataManager;
35}
36
37namespace Engine::Ecs
38{
43 friend class Core::AssetManager;
44 friend class EngineKern;
45
46 public:
48 Assets::TextureAssetManager * textureAssetManager, NamedThreadPool * assetLoaderPool );
49
54 void submitAsset(const std::filesystem::path &asset);
55
60 void tick(bool async = true);
61
66 void setRenderingDataManager( Engine::Core::RenderingDataManager * renderingDataManager) { renderingDataManager_ = renderingDataManager; }
67
72 void setMaxTexturesPerFrame(size_t max) { maxTexturesPerFrame_ = max; }
73
78 size_t getPendingCount() const {
79 return assetQueue_.size() + exrHeaderFutures_.size() + imageFutures_.size() + ktx2LoadFutures_.size();
80 }
81
83
84 private:
85 void requestExrHeaders(bool async = true);
86 void loadImageData(bool async = true);
87 void retrieveImageData(bool async = true);
88 void processKtx2Textures(bool async = true);
89
91 Core::RenderingDataManager * renderingDataManager_ = nullptr;
93
94 std::vector<std::filesystem::path> assetQueue_;
95 std::vector<std::filesystem::path> ktx2Queue_;
96 std::vector<ExrHeaderFuture> exrHeaderFutures_;
97 std::vector<AssetLoadingImage> imageFutures_;
98 std::vector<Ktx2LoadFuture> ktx2LoadFutures_;
99
101 };
102
108 friend class AssetManager;
109 friend class Engine;
110
111 public:
113 Assets::MeshAssetManager * meshAssetManager,
114 Assets::MaterialAssetManager * materialAssetManager,
115 Assets::ModelAssetManager * modelAssetManager,
116 Assets::SkinAssetManager * skinAssetManager,
117 Assets::AnimationAssetManager * animationAssetManager,
118 Assets::TextureAssetManager * textureAssetManager,
119 NamedThreadPool * assetLoaderPool,
120 Core::AssetManager * assetManager = nullptr
121 );
122
127 void submitAsset(const std::filesystem::path &asset);
128
129 void tick(bool async = true);
130
135 void setRenderingDataManager( Core::RenderingDataManager * renderingDataManager) { renderingDataManager_ = renderingDataManager; }
136
142
149 std::vector<CompletedMeshletGeneration> takePendingMeshletCompletions();
150
156 [[nodiscard]] bool hasPendingWork() const {
157 return
158 !assetQueue_.empty() ||
159 !modelLoadingFutures_.empty() ||
160 !materialResults_.empty() ||
161 !primitiveDataFutures_.empty() ||
162 !meshletGenerationFutures_.empty() ||
164 !pendingKtx2Futures_.empty();
165 }
166
168
169 private:
170 void submitLoadModel(bool async = true);
171 void processModel(bool async = true);
172 void processSkinData(bool async = true);
173 void processMaterial(bool async = true);
174 void processMeshData(bool async = true);
175 void processKtx2Textures(bool async = true);
176
187 void processTextures(Assets::Model* modelAsset,
188 const std::shared_ptr<tinygltf::Model>& gltfModel,
189 const std::filesystem::path& modelPath);
190
193 Assets::ModelAssetManager * modelAssetManager_ = nullptr;
197 Core::RenderingDataManager * renderingDataManager_ = nullptr;
200
201 NamedThreadPool * threadPool_ = new NamedThreadPool( 2, "Gltf loader" );
203
204 std::vector<std::filesystem::path> assetQueue_;
205 std::vector<GltfModelFuture> modelLoadingFutures_;
206 std::vector<MaterialLoadingData> materialResults_;
207 std::vector<std::future<PrimitiveDataLoading>> primitiveDataFutures_;
208 std::vector<std::future<CompletedMeshletGeneration>> meshletGenerationFutures_;
209
210 // Queue for completed meshlet generations waiting to be written to registry
211 std::vector<CompletedMeshletGeneration> pendingMeshletCompletions_;
212
213 // KTX2 texture loads submitted to thread pool, polled each tick()
214 std::vector<Ktx2LoadFuture> pendingKtx2Futures_;
215
217 };
218
226 friend class AssetManager;
227 friend class EngineKern;
228
229 public:
231 Assets::AudioAssetManager * audioAssetManager,
232 NamedThreadPool* assetLoaderPool);
233
238 void submitAsset(const std::filesystem::path& asset);
239
244 void tick(bool async = true);
245
250 void setAudioEngine( Core::AudioEngine * engine) { audioEngine_ = engine; }
251
255 [[nodiscard]] size_t getPendingCount() const {
256 return assetQueue_.size() + loadFutures_.size();
257 }
258
260
261 private:
264
266 std::filesystem::path path;
268 uint64_t generation = 0;
269 std::future<Assets::AudioData> future;
270 };
271
275
276 std::vector<std::filesystem::path> assetQueue_;
277 std::vector<AudioLoadFuture> loadFutures_;
278
280 };
281
282} // namespace Ecs
Manages audio assets by filesystem path, providing dedup and lookup.
Definition AudioAsset.h:72
Holds decoded PCM audio data as an engine asset.
Definition AudioAsset.h:14
Loads glTF files and converts tinygltf data into engine asset data.
Definition GltfLoader.h:38
Asset manager for materials keyed by source file path and material name.
Stores mesh data with their primitives.
Definition MeshAsset.h:47
Asset manager for texture assets keyed by filesystem path.
Wrapper for texture data.
Owns the miniaudio engine and provides the playback API.
Definition AudioEngine.h:29
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.
ModelAssetPipeline(Assets::MeshAssetManager *meshAssetManager, Assets::MaterialAssetManager *materialAssetManager, Assets::ModelAssetManager *modelAssetManager, Assets::SkinAssetManager *skinAssetManager, Assets::AnimationAssetManager *animationAssetManager, Assets::TextureAssetManager *textureAssetManager, NamedThreadPool *assetLoaderPool, Core::AssetManager *assetManager=nullptr)
void submitLoadModel(bool async=true)
void processKtx2Textures(bool async=true)
Assets::Loaders::GltfLoader * loader_
Assets::ModelAssetManager * modelAssetManager_
std::vector< std::future< CompletedMeshletGeneration > > meshletGenerationFutures_
void tick(bool async=true)
void setTextureAssetPipeline(TextureAssetPipeline *pipeline)
Sets the TextureAssetPipeline for async lightmap loading.
Assets::MeshAssetManager * meshAssetManager_
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)
Assets::SkinAssetManager * skinAssetManager_
void processSkinData(bool async=true)
void processTextures(Assets::Model *modelAsset, const std::shared_ptr< tinygltf::Model > &gltfModel, const std::filesystem::path &modelPath)
Extracts and registers texture assets from loaded glTF models.
Assets::TextureAssetManager * textureAssetManager_
std::vector< CompletedMeshletGeneration > takePendingMeshletCompletions()
Get and clear pending meshlet completions. Call this at a safe point to retrieve completed meshlet ge...
TextureAssetPipeline * textureAssetPipeline_
For async lightmap loading.
Assets::AnimationAssetManager * animationAssetManager_
std::vector< Ktx2LoadFuture > pendingKtx2Futures_
std::vector< std::future< PrimitiveDataLoading > > primitiveDataFutures_
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< Asset::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
Manages IBL (Image-Based Lighting) resources for specular reflections.