2#include "DescriptorIndexAllocator.h"
3#include "Engine/Animation/AnimationAsset.h"
4#include "Engine/Animation/AnimationAssetRef.h"
5#include "Engine/Animation/SkinAsset.h"
6#include "Engine/Animation/SkinAssetRef.h"
7#include "Engine/Audio/AudioAsset.h"
8#include "Engine/Audio/AudioAssetRef.h"
9#include "Engine/Core/Settings.h"
10#include "Engine/Ecs/FrameProcessing.h"
11#include "Engine/Logging/TracyMacros.hpp"
12#include "Engine/Material/MaterialAsset.h"
13#include "Engine/Material/MaterialAssetRef.h"
14#include "Engine/Texture/CubemapTexture.h"
15#include "Engine/Texture/Texture.h"
16#include "Engine/Texture/TextureAsset.h"
17#include "Engine/Texture/TextureAssetRef.h"
18#include "Engine/Texture/TextureHandleRegistry.h"
19#include "Engine/Texture/RuntimeTextureDescriptorLease.h"
21#include "MeshAssetRef.h"
23#include <Engine/Math/BidirectionalMap.h>
24#include <Engine/Texture/TextureLoadData.h>
30#include <unordered_map>
31#include <unordered_set>
49 class ModelAssetManager;
58 class RenderingDataManager;
71 std::size_t
operator()(
const std::filesystem::path & p )
const noexcept
73 return std::hash<std::string>{}( p.string() );
100 float x = std::max( -1.0f, std::min( 1.0f, n.x ) );
101 float y = std::max( -1.0f, std::min( 1.0f, n.y ) );
102 float z = std::max( -1.0f, std::min( 1.0f, n.z ) );
105 int32_t ix =
static_cast<int32_t
>( std::round( x * 511.0f ) );
106 int32_t iy =
static_cast<int32_t
>( std::round( y * 511.0f ) );
107 int32_t iz =
static_cast<int32_t
>( std::round( z * 511.0f ) );
111 return (
static_cast<uint32_t
>( iz & 0x3FF ) << 20 ) | (
static_cast<uint32_t
>( iy & 0x3FF ) << 10 ) |
112 (
static_cast<uint32_t
>( ix & 0x3FF ) );
127 float r = std::max( 0.0f, std::min( 1.0f, c.x ) );
128 float g = std::max( 0.0f, std::min( 1.0f, c.y ) );
129 float b = std::max( 0.0f, std::min( 1.0f, c.z ) );
132 uint32_t ur =
static_cast<uint32_t
>( std::round( r * 255.0f ) );
133 uint32_t ug =
static_cast<uint32_t
>( std::round( g * 255.0f ) );
134 uint32_t ub =
static_cast<uint32_t
>( std::round( b * 255.0f ) );
138 return ( ua << 24 ) | ( ub << 16 ) | ( ug << 8 ) | ur;
150 return glm::packHalf2x16( tc );
161 std::shared_ptr<Assets::Texture>
texture =
nullptr;
168 template <
typename T>
171 return index > other.index;
179 template <
typename T>
182 return index < other.index;
197 friend Core::TextureManager;
234 template <
typename AssetClass,
typename Key>
237 if constexpr ( std::is_same_v<AssetClass, Assets::Mesh> )
241 "Mesh assets are keyed by Asset::MeshPath"
248 else if constexpr ( std::is_same_v<AssetClass, Assets::Audio> )
252 std::is_same_v<std::decay_t<Key>, std::filesystem::path>,
253 "Audio assets are keyed by Asset::Path"
258 else if constexpr ( std::is_same_v<AssetClass, Assets::Animation> )
262 "Animation assets are keyed by Asset::MeshPath"
272 else if constexpr ( std::is_same_v<AssetClass, Assets::Material> )
276 "Material assets are keyed by Asset::MeshPath"
281 else if constexpr ( std::is_same_v<AssetClass, Assets::Skin> )
285 "Skin assets are keyed by Asset::MeshPath"
295 else if constexpr ( std::is_same_v<AssetClass, Assets::Texture> )
299 std::is_same_v<std::decay_t<Key>, std::filesystem::path>,
300 "Texture assets are keyed by Asset::Path"
315 std::is_same_v<AssetClass, void>,
"Unsupported asset type for AssetManager::getAsset<T>()"
403 const std::filesystem::path & path,
418 const std::filesystem::path & path,
428 template <Assets::TextureType Type>
430 const std::filesystem::path & path
645 std::unordered_map<std::filesystem::path, std::unique_ptr<Assets::CubemapTexture>,
PathHasher>
649 std::array<std::optional<Assets::RuntimeTexture>, MAX_TEXTURE_COUNT>
textureData;
681 const std::filesystem::path & path,
708 const std::filesystem::path & path,
732 const std::filesystem::path & path,
Maintains a one-to-one mapping that can be queried from either side.
Stores animation clips keyed by their source mesh path.
Manages audio assets by filesystem path, providing dedup and lookup.
Holds decoded PCM audio data as an engine asset.
Owns Vulkan resources for a sampled cubemap texture.
Loads glTF files and converts tinygltf data into engine asset data.
Asset manager for materials keyed by source file path and material name.
the material asset is another wrapper for asset data which is stored in entt. It has the EngineCore::...
Stores mesh data with their primitives.
The mesh asset stores geometry data and.
Move-only ownership of one runtime texture descriptor slot.
Runtime-owned Vulkan texture resource.
Stores skin and skeleton binding data keyed by source mesh path.
Asset manager for texture assets keyed by filesystem path.
Type-erased texture handle for runtime storage.
static constexpr uint32_t INVALID_ID
Sentinel ID for an invalid handle.
Wrapper for texture data.
Central registry for texture handles, providing O(1) descriptor index lookup.
Type-safe texture handle wrapper providing compile-time type safety.
The application context is the core class which stores the basic openxr and vulkan objects.
bool doesTextureAlreadyExist(const std::filesystem::path &path)
Checks whether a texture path has a loaded identity entry.
Ecs::AssetImportPipeline & getAssetImportPipeline()
Gets the master asset import pipeline.
Assets::ModelAssetManager * modelAssetManager
void unloadAllData()
Discards pending work and clears loaded asset manager state.
Assets::Mesh * getMeshAsset(const Asset::MeshPath &asset)
Gets a mesh asset by path or requests its model if it is not loaded.
DescriptorIndexAllocator textureAllocator
void discardSceneLoadingData()
Drops queued or in-flight scene asset loading work.
Assets::TextureAssetRef TextureAssetRef
Legacy asset reference type for texture assets.
AssetManager()
Creates an asset manager without an application context.
Assets::MaterialAssetManager * materialAssetManager
Assets::Textures::TextureHandleRegistry * getTextureHandleRegistry()
Gets the texture handle registry for O(1) descriptor index lookups.
Rendering::Renderer * renderer
std::unordered_map< std::filesystem::path, std::unique_ptr< Assets::CubemapTexture >, PathHasher > cubemapTextures
Assets::SkinAssetManager * skinAssetManager_
Assets::MaterialAssetManager * getMaterialAssetManager() const
Gets the material asset manager for material lookups.
Assets::TextureHandle getOrCreateTextureHandleWithSlot(const std::filesystem::path &path, Assets::TextureType type)
Gets or creates a texture handle and reserves a stable descriptor slot for it.
uint32_t getImageCount() const
Gets the number of registered runtime texture identities.
auto getAsset(const Key &asset)
Gets or creates an asset reference and requests loading when needed.
std::vector< TextureStorage > texturesToUpload
Assets::RuntimeTexture * replaceTextureFromPrepared(const std::filesystem::path &path, Assets::RuntimeTexture texture)
Replaces an already registered texture while preserving its descriptor index.
Assets::AudioAssetRef AudioAssetRef
Legacy asset reference type for audio assets.
Assets::MeshAssetRef MeshAssetRef
Legacy asset reference type for mesh assets.
void setRenderingDataManager(RenderingDataManager *renderingDataManager)
Sets the rendering data manager used by asset pipelines.
Assets::Textures::TextureHandleRegistry textureHandleRegistry_
Registry for type-safe texture handles.
uint32_t fallbackTextureDescriptorIndex_
Ecs::AudioAssetPipeline & getAudioAssetPipeline()
Gets the audio loading pipeline.
std::unordered_map< Assets::Textures::TextureIdentityKey, Assets::RuntimeTexture *, Assets::Textures::TextureIdentityKeyHash > textures
Assets::RuntimeTexture * registerTextureFromPrepared(const std::filesystem::path &path, Assets::TextureType type, Assets::RuntimeTexture texture)
Registers a typed texture whose Vulkan resources are already created.
Assets::RuntimeTextureDescriptorLease reserveRuntimeTextureDescriptor()
Reserves a stable descriptor index for a runtime-generated sampled image.
void cleanup()
Waits for asset jobs and releases loaded runtime texture resources.
void loadEcsTexture(const std::filesystem::path &path)
Submits a texture file for asynchronous loading.
Assets::Loaders::GltfLoader gltfLoader
~AssetManager()
Destroys owned asset managers and worker pools.
Assets::MeshAssetManager * meshAssetManager
std::vector< VkDescriptorImageInfo > getTextureDescriptorInfos() const
Builds descriptor image info records for resident textures.
NamedThreadPool * threadPool_
Assets::AudioAssetManager * getAudioAssetManager() const
Gets the audio asset manager for direct access.
Assets::AudioAssetManager * audioAssetManager_
uint32_t getTextureDescriptorIndex(const std::filesystem::path &path, Assets::TextureType type)
Gets the descriptor index of a resident texture by path and semantic type.
Assets::Audio * getAudioAsset(const Asset::Path &path)
Gets a loaded audio asset by path.
Assets::AnimationAssetRef AnimationAssetRef
Legacy asset reference type for animation assets.
friend RenderingDataManager
AssetManager(ApplicationContext *context)
Creates an asset manager bound to an application context.
Assets::MaterialAssetRef MaterialAssetRef
Legacy asset reference type for material assets.
Assets::AnimationAssetManager * animationAssetManager_
void unregisterTexture(Assets::RuntimeTexture *texture)
Unregisters a runtime texture and clears its descriptor slot.
Assets::RuntimeTexture * registerTexture(const std::filesystem::path &path, Assets::RuntimeTexture texture)
Creates Vulkan resources for a texture and registers it as file-backed texture data.
std::unordered_set< uint32_t > fileTextureDescriptorIndices_
Assets::ModelAssetManager * getModelAssetManager() const
Gets the model asset manager for model and glTF loading state lookups.
Assets::RuntimeTexture * registerTextureFromPrepared(const std::filesystem::path &path, Assets::RuntimeTexture texture)
Registers a texture whose Vulkan resources are already created.
void loadEcsModel(const std::filesystem::path &path)
Submits a glTF model file for asynchronous loading.
Assets::TextureAssetManager * textureAssetManager
Assets::RuntimeTexture * registerTexture(const std::filesystem::path &path, Assets::TextureType type, Assets::RuntimeTexture texture)
Creates Vulkan resources for a typed texture and registers it as file-backed texture data.
std::vector< Assets::RuntimeTexture * > texturesToCopyImageData
Ecs::TextureAssetPipeline & getTextureAssetPipeline()
Gets the texture loading pipeline.
void ensureFallbackTextureLocked()
Creates the built-in fallback texture when it does not already exist.
NamedThreadPool * getAssetLoaderPool() const
Gets the worker pool used for asynchronous asset loading.
void unloadRuntimeTextures()
Releases all runtime texture data and descriptor reservations owned by this manager.
Ecs::AssetImportPipeline assetImportPipeline
NamedThreadPool * getCalculationPool() const
Gets the worker pool used for asset-side CPU calculations.
NamedThreadPool * threadedCalculation_
void attachToRenderer(Rendering::Renderer *renderer)
Attaches the renderer used for texture uploads and descriptor reservation notifications.
Assets::SkinAssetRef SkinAssetRef
Legacy asset reference type for skin assets.
friend ApplicationContext
std::unordered_map< std::string, std::vector< Assets::Textures::TextureIdentityKey > > textureIdentitiesByPath_
BidirectionalMap< uint32_t, Assets::RuntimeTexture * > textureIndexMap
Assets::CubemapTexture * loadEcsCubemap(const std::filesystem::path &path)
Loads a six-face cubemap asset from a directory.
void releaseRuntimeTextureDescriptorIndex(uint32_t descriptorIndex)
uint32_t getTextureDescriptorIndex(const std::filesystem::path &path)
Gets the descriptor index of a resident texture by path.
Assets::AnimationAssetManager * getAnimationAssetManager() const
Gets the animation asset manager for direct access.
Assets::MeshAssetManager * getMeshAssetManager() const
Gets the mesh asset manager for mesh asset lookups.
ApplicationContext * context
std::unordered_set< uint32_t > runtimeTextureDescriptorIndices_
Assets::RuntimeTexture * replaceTextureFromPrepared(const std::filesystem::path &path, Assets::TextureType type, Assets::RuntimeTexture texture)
Replaces an already registered typed texture while preserving its descriptor index.
std::array< std::optional< Assets::RuntimeTexture >, MAX_TEXTURE_COUNT > textureData
Assets::SkinAssetManager * getSkinAssetManager() const
Gets the skin asset manager for direct access.
AudioAssetRef loadAudioAsset(const Asset::Path &path)
Submits an audio file for async loading through the audio pipeline.
Assets::TypedTextureHandle< Type > getOrCreateTextureHandleWithSlot(const std::filesystem::path &path)
Gets or creates a typed texture handle and reserves a stable descriptor slot for it.
Ecs::ModelAssetPipeline & getMeshAssetPipeline()
Gets the glTF model loading pipeline.
Use this class to manage a finite amount of memory. The idea is to have an array which stores objects...
Master asset import pipeline that dispatches asset submissions to the texture, model and audio sub-pi...
Async pipeline for loading audio assets (WAV, FLAC, MP3)
The model asset pipeline loads a gltf scene and loads and loads the mesh and material data....
Infrastructure to load images into the ecs.
Utility class for spawning GLTF meshes into a scene.
@ LOADED
All components of the asset have been loaded, and it is ready to be used.
@ REQUESTED_LOAD
An asset has been requested to load and is waiting for an asset pipeline to start working on it.
@ LOADING
While the asset is currently being processed in the asset pipeline.
@ UNLOADED
When the asset is not loaded yet but the frame is already existing for the heavy data to be loaded in...
CpuLoadingState LoadState
Alias used by the asset manager and refs.
Asset::Ref< Asset::MeshPath, Animation > AnimationAssetRef
Asset reference to an animation loaded from a mesh asset path.
Asset::Ref< Asset::Path, Audio > AudioAssetRef
Asset reference to decoded audio data loaded from a filesystem path.
Asset::Ref< Asset::Path, Texture > TextureAssetRef
Asset reference to a texture loaded from a filesystem path.
Asset::Ref< Asset::MeshPath, Skin > SkinAssetRef
Asset reference to skin binding data loaded from a mesh asset path.
Asset::Ref< Asset::MeshPath, Mesh > MeshAssetRef
Asset reference to mesh geometry loaded from a mesh asset path.
Asset::Ref< Asset::MeshPath, Material > MaterialAssetRef
Asset reference to material data loaded from a mesh asset path.
TextureType
Represents the semantic type of a texture, determining its Vulkan format.
uint32_t packTexCoordR16G16_SFLOAT(const glm::vec2 &tc)
Packs a 2D texture coordinate into R16G16_SFLOAT layout.
uint32_t packColorR8G8B8A8_UNORM(const glm::vec3 &c)
Packs an RGB color into R8G8B8A8_UNORM layout with opaque alpha.
uint32_t packNormalA2B10G10R10_SNORM(const glm::vec3 &n)
Packs a signed normalized 3D normal into A2B10G10R10_SNORM layout.
Identifies a named mesh-like asset inside an asset file.
Identifies a single asset file on disk.
const std::filesystem::path & getFilePath() const
Gets the stored filesystem path.
Hash functor for TextureIdentityKey.
Path and semantic type pair that uniquely identifies a texture handle.
Compact vertex format used by mesh packing code.
glm::vec3 position
Full-precision local-space position.
uint32_t packedNormal
Normal packed as A2B10G10R10_SNORM.
uint32_t packedTexCoord
Texture coordinate packed as R16G16_SFLOAT.
uint32_t packedColor
Vertex color packed as R8G8B8A8_UNORM.
Hash functor for filesystem paths used in unordered containers.
std::size_t operator()(const std::filesystem::path &p) const noexcept
Hashes a filesystem path by its string representation.
Texture asset entry paired with its descriptor index.
std::shared_ptr< Assets::Texture > texture
Managed texture asset.
bool operator<(const T &other)
Compares texture storage entries by descriptor index.
bool operator>(const T &other)
Compares texture storage entries by descriptor index.
uint32_t index
Descriptor or storage index assigned to the texture.