Asset System
The Asset System in EntropyPortal ensures secure, efficient, and stutter-free loading of content.
AssetLoaderService
Section titled “AssetLoaderService”The AssetLoaderService is the entry point for all content retrieval.
graph TD
Req[Request AssetId] --> Cache{In Cache?}
Cache -->|Yes| Return[Return Data]
Cache -->|No| Fetch[Fetch URI]
Fetch --> Decrypt[Decrypt AES-256]
Decrypt --> Hash[Verify Hash]
Hash --> Store[Store in Cache]
Store --> Return
Security
Section titled “Security”- Encryption: Assets are encrypted at rest (AES-256-GCM). The service automatically fetches decryption keys from the
AssetClient. - Verification: Content integrity is verified using SHA-256 hashes before being returned to the application.
Caching
Section titled “Caching”- LRU Strategy: An in-memory Least Recently Used cache keeps frequently accessed assets ready.
- Deduplication: Simultaneous requests for the same asset are coalesced into a single network fetch.
Mesh & Texture Services
Section titled “Mesh & Texture Services”These services bridge the gap between CPU data and GPU memory.
Async GPU Upload
Section titled “Async GPU Upload”To prevent frame spikes when loading large levels, uploads are performed asynchronously.
graph TD
Start[Request Upload] --> Work[Async Worker]
subgraph "CPU Work"
Work --> Swizzle[Swizzle / Pack]
Swizzle --> Stage[Copy to Staging]
end
Stage --> Ready[Mark Ready]
subgraph "Render Thread"
Ready --> Check{Process Pending?}
Check -->|Limit/Frame| Upload[Copy Staging -> GPU]
end
- Preparation: CPU-intensive work (texture swizzling, vertex packing) is offloaded to worker threads via
WorkContract. - Staging: Data is copied to a staging buffer.
- Transfer: The copy from Staging -> Default heap is sliced across multiple frames if necessary (throttled).
Asset Identification
Section titled “Asset Identification”Resources are tracked via AssetId (a 128-bit UUID).
- Lookup: The renderer (and
MaterialService) looks up resources byAssetIdto verify they are loaded and ready.
Shader Loading & Compilation
Section titled “Shader Loading & Compilation”Shaders follow a specialized pipeline to handle High-Level Shading Language (Slang), variants, and diverse backends.
graph TD
Load[Load Source] --> Pool[Acquire Compiler]
subgraph "Worker Thread Pool"
Pool --> Compile["Compile (Slang)"]
Compile --> Reflect[Reflect & Layout]
Reflect --> Bytecode["Bytes (SPIR-V/DXIL/MSL)"]
end
Bytecode --> Callback[OnCompileComplete]
subgraph "Render Thread"
Callback --> PSO[Create Pipeline State]
PSO --> Cache[Store in VariantSet]
end
Concurrent Compilation
Section titled “Concurrent Compilation”The ShaderCompilerService maintains a Thread Pool of Compiler Instances.
- Isolation: Each worker thread gets its own
slang::ISessionto avoid lock contention. - Async: Compilation happens in the background. The engine continues rendering with “fallback” shaders (e.g., magenta) until the real shader is ready.
Pipeline State Management
Section titled “Pipeline State Management”Once bytecode is ready, the ShaderVariantSet on the main thread:
- Creates the
GpuShaderobject. - Binds it to the required Render State (Blend, Depth, Rasterizer).
- Uploads it to the GPU.