8#include <entt/entt.hpp>
10#include <unordered_map>
11#include <unordered_set>
14#define object_rendering_id uint32_t
15#define primitive_rendering_id uint32_t
16#define meshlet_rendering_id uint32_t
20 class ApplicationContext;
504 std::size_t h1 = std::hash<void*>{}(
static_cast<void*
>(key.
meshAsset));
506 return h1 ^ (h2 << 1);
512 std::unordered_map<GeometryCacheKey, MeshGeometryMapping, GeometryCacheKeyHash>
geometryCache_;
#define primitive_rendering_id
#define meshlet_rendering_id
The application context is the core class which stores the basic openxr and vulkan objects.
the material asset is another wrapper for asset data which is stored in entt. It has the EngineCore::...
The mesh asset stores geometry data and.
A component which can be attached as many times to an actor as one wants. It makes it possible to ren...
AssetManager * injectedAssetManager
uint32_t getInstanceCount() const
Gets the current count of instances in the buffers.
bool defaultTexturesLoading_
True if loadEcsTexture has been called.
std::unordered_map< uint32_t, PipelineNames > primitiveToPipeline
Maps primitive IDs to their pipeline.
std::vector< VkDescriptorImageInfo > generateTextureDescriptorInfos() const
Generate descriptor infos for all GPU-uploaded textures.
size_t committedSingleMeshletGeoCount_
Single-meshlet geometries already on GPU.
std::vector< Texture * > getTexturesToUpload() const
Get the list of textures waiting for GPU upload.
ApplicationContext * context
std::optional< VulkanStagedBuffer > vertexBuffer
Optimized vertex data (Vertex structs)
std::vector< VulkanStagedBufferSyncObjects > & getPendingSyncObjects()
Get pending buffer sync objects for the transfer phase These need to be recorded in the transfer comm...
uint32_t getValidTextureIndex(uint32_t textureIndex, DefaultTextureType defaultType)
void processCompletedMeshletGenerations(std::vector< Ecs::CompletedMeshletGeneration > &&completions)
Process completed meshlet generations and write them to the registry. This should be called at a safe...
void processPendingMeshLoads()
Process pending mesh loads at a safe point in the frame. This should be called BEFORE updateIfDirty()...
bool instancesDirty_
Instance list changed (requires instance buffer update)
std::vector< MeshAsset * > pendingMeshLoads_
bool needsUpdate() const
Check if the rendering data needs to be rebuilt.
uint32_t instanceCount_
Number of instances in buffers.
std::unordered_map< PipelineNames, std::optional< VulkanBuffer > > materialBuffersByPipeline
std::optional< VulkanStagedBuffer > localBoundsBuffer
LocalBoundsData per primitive (static, uploaded once)
bool updatePrimitiveDataInstanced()
Instanced version of updatePrimitiveData using geometry deduplication. Separates geometry upload (onc...
uint32_t getClusterCount() const
void clearPendingSyncObjects()
Clear pending sync objects after they've been recorded.
size_t committedVertexCount_
Vertices already on GPU.
const VulkanBuffer & getSHProbeBuffer() const
Get the SH probe buffer for spherical harmonic lighting.
bool hasTexturesToUpload() const
Check if there are textures waiting to be uploaded to GPU.
uint32_t getUniqueGeometryCount() const
Gets the current count of unique geometries in the buffers.
uint32_t nextMeshletId_
Next meshlet ID to assign.
bool updatePrimitiveData()
Regenerates all buffers and the rendering ids of all objects, primitives and meshlets.
RenderingDataManager & operator=(const RenderingDataManager &)=delete
std::optional< VulkanStagedBuffer > instanceDataBuffer
InstanceData per visible instance.
uint32_t getTextureCount() const
Get the count of textures currently on the GPU.
std::vector< Vertex > workingVertexBuffer_
std::vector< InstanceData > workingInstanceData_
void invalidateGeometryCache()
Clears the geometry cache and marks for full rebuild. Called when meshes are unloaded.
std::unordered_map< PipelineNames, uint32_t > pipelinePrimitiveCounts
Count of primitives per pipeline.
bool instancingEnabled_
Feature flag for instanced rendering.
void clearTexturesToUpload()
Clear the texture upload queue after upload is complete.
void clearDirty()
Clears the dirty flag after update is complete.
std::unordered_map< std::string, uint32_t > materialPathToDiffuseIndex_
const VulkanBuffer & getPerObjectDataBuffer() const
std::vector< VulkanStagedBufferSyncObjects > pendingTransformSyncObjects_
std::unordered_map< GeometryCacheKey, MeshGeometryMapping, GeometryCacheKeyHash > geometryCache_
RenderingDataManager(const RenderingDataManager &)=delete
std::unordered_set< MeshAsset * > renderCycleMeshSnapshot_
bool isDirty
a flag which defers the update of the buffer updates to the end of the frame.
void processPendingDeletions()
Process deferred buffer deletions Call this after all frames have completed and descriptor sets are u...
const VulkanBuffer & getMeshletBuffer() const
std::vector< Texture * > gpuTextures
Textures currently on GPU.
static constexpr const char * DEFAULT_NORMAL_TEXTURE_PATH
void initializeDefaultTextures()
Queue default textures for loading via the texture pipeline.
const VulkanBuffer & getClusterLodDataBuffer() const
void snapshotRenderableMeshes()
Take a snapshot of currently render-ready meshes. Called at the start of update cycle to ensure consi...
void setRenderer(Renderer *renderer)
Set the renderer for pipeline index lookups. Required when Engine is null.
SceneManager * injectedSceneManager
void markDirty()
Flags the Rendering Data Manager as dirty so that all buffers managed by this manager are in need of ...
bool updateTransforms()
Updates only transform-related buffers (world matrices, bounding spheres)
std::optional< VulkanStagedBuffer > clusterGroupDataBuffer_
ClusterGroupData per LOD group.
uint64_t getDataVersion() const
Get the current data version Incremented each time buffers are updated. RenderProcesses use this to k...
std::optional< VulkanStagedBuffer > triangleBuffer
Triangle indices for meshlets.
void setSceneManager(SceneManager *sceneManager)
Set the scene manager for retrieving actors. Required when Engine is null.
std::vector< SingleMeshletGeometryData > workingSingleMeshletGeoData_
std::unordered_map< uint32_t, MeshComponent * > primitiveIdToComponent_
uint32_t clusterGroupCount_
Total cluster groups.
void clearPendingTransformSyncObjects()
Clear pending transform sync objects after they've been recorded.
std::vector< Ecs::PackedTriangle > workingTriangleBuffer_
std::vector< Texture * > texturesToUpload
Textures waiting for GPU upload.
uint32_t clusterCount_
Total clusters across all LOD levels.
const VulkanBuffer & getMeshletBoundsBuffer() const
std::vector< ClusterLodData > workingClusterLodData_
uint32_t multiMeshletGeometryCount_
Geometries with meshletCount > 1 (mesh shader path)
void onMeshLoaded(MeshAsset *asset)
Event hook which executes when an Mesh is loaded.
std::optional< VulkanStagedBuffer > primitiveRenderData
MeshPrimitiveRenderData per primitive (texture/material IDs)
size_t committedGeometryCount_
Geometries already on GPU.
std::vector< PrimitiveMeshletData > workingPrimitiveMeshletBuffer_
bool updateIfDirty()
Triggers an update of all GPU buffers if dirty.
std::vector< GpuDiffuseFlatColorMaterial > workingFlatColorMaterials_
DefaultTextureType
Get a valid texture index, substituting defaults for missing textures.
PipelineNames getPipelineForPrimitive(uint32_t primitiveId) const
Gets the pipeline ID (PipelineNames enum) for a given primitive.
uint32_t getMultiMeshletGeometryCount() const
uint32_t getPrimitiveCount() const
Gets the current count of primitives in the buffers.
Renderer * injectedRenderer
void uploadMaterialBuffers()
Upload material data from MaterialAssets to GPU buffers.
void markMaterialsDirty()
Mark materials as dirty, requiring buffer re-upload.
std::optional< VulkanStagedBuffer > perObjectDataBuffer
mat4 world transform per primitive (matches shader PerObjectData)
std::vector< InstanceCullingData > workingInstanceCullingData_
void onMaterialUnloaded(MaterialAsset *materialAsset)
Event hook for when a material has been unloaded.
uint32_t uniqueGeometryCount_
Number of unique geometries in buffers.
std::unordered_map< std::string, uint32_t > materialPathToFlatColorIndex_
bool hasVertexShaderPath() const
size_t committedVsIndexCount_
VS indices already on GPU.
std::vector< uint32_t > workingVsIndexBuffer_
RenderingDataManager(const Engine *engine, ApplicationContext *context)
std::vector< MeshGeometryData > workingGeometryDataBuffer_
const VulkanBuffer & getTriangleBuffer() const
const VulkanBuffer & getClusterGroupDataBuffer() const
std::vector< glm::mat4 > cachedTransforms_
bool isMeshInSnapshot(MeshAsset *asset) const
Check if a mesh asset is in the current render cycle snapshot.
std::vector< VulkanStagedBufferSyncObjects > pendingSyncObjects_
std::unordered_map< std::string, uint32_t > materialPathToNormalsIndex_
std::vector< glm::mat4 > workingPerObjectData_
bool needsMaterialUpdate() const
Check if material buffers need updating.
std::optional< VulkanStagedBuffer > primitiveCullingData
ObjectCullingData per primitive (unused after GPU transform optimization)
void setInstancingEnabled(bool enabled)
Enable or disable instancing mode.
~RenderingDataManager()
Destructor - cleans up all GPU buffers.
void collectMaterialsFromScene()
Collects all materials from loaded meshes and creates per-pipeline data This builds material-to-pipel...
bool transformCacheValid_
void queueTextureForUpload(Texture *texture)
Queue a texture for GPU upload Called by AssetManager when a new texture is created and needs uploadi...
const VulkanBuffer & getPrimitiveCullingBuffer() const
std::optional< VulkanStagedBuffer > meshletBuffer
UnifiedMeshlet data.
void onRenderableSpawned(MeshComponent *component)
Event hook which is executed when a renderable component gets added to an actor and can thus be rende...
std::vector< ObjectCullingData > workingPrimitiveCullingBuffer_
std::vector< MeshletBounds > workingMeshletBoundsBuffer_
void onRenderableDestroyed(MeshComponent *component)
Event hook which is executed when a renderable component gets removed from an actor and thus has to b...
void initializeSHProbeBuffer()
Initialize default SH probe data Sets up a single default probe with hardcoded coefficients.
uint32_t getMeshletCount() const
Gets the current count of meshlets in the buffers.
std::optional< VulkanStagedBuffer > primitiveMeshletData
PrimitiveMeshletData per primitive.
std::optional< VulkanStagedBuffer > meshGeometryDataBuffer
MeshGeometryData per unique geometry.
uint32_t getSingleMeshletGeometryCount() const
std::optional< VulkanStagedBuffer > instanceCullingDataBuffer
InstanceCullingData per instance.
bool isInstancingEnabled() const
Check if instancing mode is enabled.
void onMaterialLoaded(MaterialAsset *materialAsset)
Event hook for when a material has been loaded.
std::unordered_map< entt::entity, std::vector< uint32_t > > entityToPrimitiveIds_
std::vector< GpuDiffuseShaderMaterial > workingDiffuseMaterials_
std::unordered_map< std::string, uint32_t > materialPathToPbrIndex_
bool geometryDirty_
Unique meshes changed (requires geometry buffer update)
const VulkanBuffer & getPrimitiveMeshletBuffer() const
void onTextureUnloaded(TextureAsset *textureAsset)
Event hook for when a texture has been unloaded.
uint32_t getClusterGroupCount() const
const VulkanBuffer & getSingleMeshletGeometryBuffer() const
std::vector< LocalBoundsData > workingLocalBoundsDataBuffer_
std::vector< VulkanStagedBufferSyncObjects > & getPendingTransformSyncObjects()
Get pending transform sync objects for the transfer phase.
const VulkanBuffer & getVSIndexBuffer() const
std::vector< GpuPbrMaterial > workingPbrMaterials_
std::optional< VulkanStagedBuffer > singleMeshletGeometryBuffer_
SingleMeshletGeometryData per single-meshlet geometry.
std::optional< VulkanStagedBuffer > clusterLodDataBuffer_
ClusterLodData per cluster.
const VulkanBuffer & getVertexBuffer() const
const VulkanBuffer & getMaterialBufferForPipeline(PipelineNames pipelineName) const
Get the material buffer for a specific pipeline type.
static constexpr const char * DEFAULT_BLACK_TEXTURE_PATH
void onMeshUnloaded(MeshAsset *asset)
Event hook which executes when a Mesh is unloaded.
std::optional< VulkanStagedBuffer > vsIndexBuffer_
Contiguous uint32_t indices for vertex shader.
const VulkanBuffer & getMeshGeometryDataBuffer() const
const VulkanBuffer & getLocalBoundsBuffer() const
std::vector< ClusterGroupData > workingClusterGroupData_
std::vector< MeshPrimitiveRenderData > workingPrimitiveRenderData_
size_t committedTriangleCount_
Triangles already on GPU.
bool geometryNeedsFullRebuild_
True on startup or after mesh unload.
std::optional< VulkanStagedBuffer > meshletBoundsData
MeshletBounds for meshlet culling.
std::vector< GpuNormalsMaterial > workingNormalsMaterials_
void initializeMaterialBuffers()
Initialize material buffers for all pipeline types.
void setAssetManager(AssetManager *assetManager)
Set the asset manager for material lookups. Required when Engine is null.
std::vector< UnifiedMeshlet > workingMeshletDataBuffer_
std::vector< SHProbeData > shProbeData_
CPU-side SH probe data.
void onTextureLoaded(TextureAsset *textureAsset, const std::filesystem::path &texturePath)
Event hook for when a texture has been loaded by the asset pipeline. Creates a Vulkan Texture from th...
const VulkanBuffer & getInstanceDataBuffer() const
const VulkanBuffer & getInstanceCullingDataBuffer() const
uint32_t nextGeometryId_
Next geometry ID to assign.
static constexpr const char * DEFAULT_WHITE_TEXTURE_PATH
std::optional< VulkanBuffer > shProbeBuffer_
SHProbeData buffer at binding 18.
uint32_t singleMeshletGeometryCount_
Geometries with meshletCount == 1 (vertex shader path)
size_t committedMeshletCount_
Meshlets already on GPU.
const VulkanBuffer & getPrimitiveRenderDataBuffer() const
Manages game objects within a scene, handling registration, ID allocation, and GPU buffer synchroniza...
Wrapper for texture data.
RAII wrapper for Vulkan buffer and device memory.
Log category system implementation.
std::size_t operator()(const GeometryCacheKey &key) const
Key for geometry cache - uniquely identifies a primitive within a mesh. Uses MeshAsset pointer and pr...
bool operator==(const GeometryCacheKey &other) const