|
Foundation
|
Owns all GPU-resident scene data (geometry, textures, instance/material/light tables, acceleration structures) behind an asynchronous upload work queue. More...
#include <GPUScene.hpp>
Classes | |
| struct | GPUSceneTables |
| GPUScene-owned, caller-filled spans for the instance/material/light tables, plus their ring-buffer base offsets. More... | |
| struct | MemoryStat |
| struct | UpdateResult |
| Ring-buffer offsets and element counts for instances/materials/lights. More... | |
Public Types | |
| enum class | Result { Ready , InProgress , InvalidInput , InvalidHandle , OutOfMemory , DecodeFailed , SubmitFailed , Cancelled } |
| Outcome of an Upload / Query / Poll call. More... | |
| enum class | LightSamplerType { Uniform , Power } |
| enum class | TLASBuildResult { Built , Empty } |
Public Member Functions | |
| GPUScene (RHIDevice *device, Allocator *allocator, GPUSceneDesc const &desc, AllocatorStack *frameScratch=nullptr) | |
| ~GPUScene () | |
| Result | Upload (FBlobDeserializer *blobs, FSerializedMesh const &source, GeometryHandle &outHandle) |
| Reserves final resident memory for a resource and queues the rest of its upload, returning Result::InProgress when accepted. | |
| Result | Upload (FBlobDeserializer *blobs, FSerializedCurve const &source, GeometryHandle &outHandle) |
| Result | UploadDynamic (FBlobDeserializer *blobs, FSerializedMesh const &source, GeometryHandle &outHandle) |
| Uploads a mesh as CPU-updateable dynamic geometry (deformation workloads). | |
| Result | Upload (FBlobDeserializer *blobs, FSerializedTexture const &source, TextureHandle &outTexture, const char *debugName=nullptr, bool pinned=false) |
| Queues a serialized texture upload, binding its bindless slot up front. | |
| Result | Upload (FTexture const &source, TextureHandle &outTexture, const char *debugName=nullptr, bool pinned=false) |
| Uploads a CPU-resident FTexture through the same queue (runs to completion). | |
| Result | Upload (RHIBuffer *dst, Span< const unsigned char > data, uint32_t dstOffset=0) |
Queues a copy of data into a device-local buffer region (drained by Join/Poll). | |
| Result | Query (GeometryHandle handle) const |
| Residency state of an uploaded geometry handle. | |
| Result | Query (TextureHandle texture) const |
| Residency state of an uploaded texture slot. | |
| void | Join () |
| Drains all queued uploads on the calling thread, blocking until GPU-resident. | |
| Result | Poll () |
| Non-blocking drain: kicks a background worker on the first call with queued work, then reports progress while streaming residency in. | |
| Result | UploadViewLUTs (FTexture const &sdr, FTexture const &hdr) |
| Uploads the SDR/HDR display-transform view LUTs (owns its staging). | |
| Result | UploadEnvMap (FTexture const &source) |
| Uploads an environment map and computes its importance-sampling CDFs. | |
| void | BuildUBO (UBO &globals, bool hdr) const |
Writes every GPUScene-owned global bindless index into the renderer UBO: the GGX/sheen LUTs, the display-transform view LUT (SDR or HDR per hdr), and the environment map + its importance-sampling CDFs (default-substituted when no env map is loaded). | |
| GPUSceneTables | BeginScene (uint32_t instanceCount, uint32_t materialCount, uint32_t lightCount) |
| Begins a scene-table update, returning caller-fill spans. | |
| UpdateResult | EndScene (GPUSceneTables &tables) |
| Commits the filled spans: patches instance geometry fields, snapshots the tables for TLAS/picking/Collect, and computes the light alias table. | |
| void | DbgGetMemoryStatistics (Vector< MemoryStat > &outStats) const |
| String | DbgGetBufferStatistics () const |
| uint32_t | GetLightCapacity () const |
| TLASBuildResult | BuildTLAS (RHICommandList *cmd, bool update=false) |
| Builds (update=false) or refits (update=true) the TLAS from the committed instance table; instances whose geometry isn't yet Result::Ready are skipped. | |
| bool | HasDynamicGeometry () const |
| True when at least one dynamic geometry is resident. | |
| void | BeginDynamicGeometryUpdate () |
| Opens the per-frame dynamic-geometry update window and advances the ring to the next frame slot. Call exactly once per rendered frame before any UpdateDynamicGeometry. | |
| Span< std::byte > | UpdateDynamicGeometry (GeometryHandle handle) |
Returns the mapped vertex sub-span (quantized FQVertex bytes) for handle in the current frame slot and marks it dirty for this frame's BLAS refit. Lock-free: each dynamic handle owns a disjoint region. Only valid inside the BeginDynamicGeometryUpdate / EndDynamicGeometryUpdate window. | |
| void | EndDynamicGeometryUpdate () |
| Closes the per-frame dynamic-geometry update window opened by BeginDynamicGeometryUpdate. | |
| void | BuildBLAS (RHICommandList *cmd) |
| Refits (or periodically rebuilds) every dirty dynamic geometry's BLAS in place against the current frame slot. Record in a render-graph pass that runs before the "TLAS Update" pass, declaring an acceleration-structure write on the BLAS region. | |
| void | SetDynamicGeometryRebuildRate (uint32_t framesOrZero) |
| Frames between forced full BLAS rebuilds for dynamic geo (0 = refit only). Default 64. | |
| uint32_t | GetDynamicRefitCount () const |
| Dynamic geos refitted in the last RefitDynamicGeometry call. | |
| uint32_t | GetDynamicRebuildCount () const |
| Of the last refit, how many were full rebuilds (the rest were in-place updates). | |
| void | Collect () |
| Garbage-collects geometry and textures no longer referenced by the committed scene tables. | |
| GSInstance | GetInstance (uint32_t index) const |
| uint32_t | GetInstanceCount () const |
| uint32_t | ResolvePickedInstance (uint32_t pickID) const |
| Maps a TLAS pick id (instanceID) to its committed instance index, or UINT32_MAX. | |
| GSLight | GetLight (uint32_t index) const |
| uint32_t | GetLightCount () const |
| GSMaterial | GetMaterial (uint32_t index) const |
| uint32_t | GetMaterialCount () const |
| RHIBuffer * | GetPrimitiveBuffer () const |
| RHIBuffer * | GetDynamicPrimitiveBuffer () const |
| The host-coherent dynamic (CPU-updateable) primitive ring, bound as a second primitive storage buffer; instances with kGSInstanceFlagDynamic read from it. | |
| RHIBuffer * | GetInstanceBuffer () const |
| RHIBuffer * | GetMaterialBuffer () const |
| RHIBuffer * | GetLightBuffer () const |
| RHIBuffer * | GetLightAliasTableBuffer () const |
| BindlessPool * | GetTexture2DPool () |
| BindlessPool * | GetTexture3DPool () |
| uint32_t | GetGGXLutEIndex () const |
| uint32_t | GetGGXLutEavgIndex () const |
| uint32_t | GetGGXLutEIORIndex () const |
| uint32_t | GetGGXLutEIORavgIndex () const |
| uint32_t | GetGGXLutEIORInvIndex () const |
| uint32_t | GetGGXLutEIORInvavgIndex () const |
| uint32_t | GetSheenLtcIndex () const |
| uint32_t | GetViewLutSdrIndex () const |
| uint32_t | GetViewLutHdrIndex () const |
| RHITexture * | GetFoundationDefaultTexture2D () const |
| RHITexture * | GetFoundationDefaultTexture2DFloat () const |
| RHIBuffer * | GetFoundationDefaultBufferFloat () const |
| bool | HasEnvMap () const |
| uint32_t | GetEnvMapIndexOrDefault () const |
| uint32_t | GetEnvMapMarginalCDFIndexOrDefault () const |
| uint32_t | GetEnvMapConditionalCDFIndexOrDefault () const |
| RHIAccelerationStructure * | GetTLAS () const |
| RHIBuffer * | GetSobolMatricesBuffer () const |
| void | Reset () |
Static Public Member Functions | |
| static size_t | CalculateMeshPrimitiveSize (FSerializedMesh const &src) |
| static size_t | CalculateCurvePrimitiveSize (FSerializedCurve const &src) |
| static size_t | CalculateCurveAABBSize (FSerializedCurve const &src) |
Public Attributes | |
| LightSamplerType | mLightSamplerType = LightSamplerType::Power |
Friends | |
| struct | GPUSceneImpl |
Owns all GPU-resident scene data (geometry, textures, instance/material/light tables, acceleration structures) behind an asynchronous upload work queue.
Typical render-build flow (after proper Renderer setup seen in Rasterizer.cpp/Pathtracer.cpp):
Upload(blobs, mesh/curve/texture, outHandle) per resource — reserves memory immediately, returns Result::InProgress. UploadEnvMap / UploadViewLUTs for environment + display LUTs.Poll() each frame (background drain) or Join() (blocking) until ready.BeginScene → fill the mapped instance/material/light spans → EndScene, then write the returned UpdateResult offsets into the renderer UBO.BuildUBO(ubo*) to update the UBO with the latest scene data.BuildTLAS(cmd) Geometry is reclaimed explicitly via Collect after destructive edits.
|
strong |
|
strong |
Outcome of an Upload / Query / Poll call.
Ready is the GPU-usable boundary, not merely "bytes copied": for geometry it means primitive/curve bytes are visible, the BLAS is built and residency is patched; for textures it means all subresources are uploaded, layouts are transitioned, and the bindless slot is shader-readable. | Enumerator | |
|---|---|
| Ready | |
| InProgress | |
| InvalidInput | |
| InvalidHandle | |
| OutOfMemory | |
| DecodeFailed | |
| SubmitFailed | |
| Cancelled | |
|
strong |
| GPUScene::GPUScene | ( | RHIDevice * | device, |
| Allocator * | allocator, | ||
| GPUSceneDesc const & | desc, | ||
| AllocatorStack * | frameScratch = nullptr |
||
| ) |
|
default |
| void GPUScene::BeginDynamicGeometryUpdate | ( | ) |
Opens the per-frame dynamic-geometry update window and advances the ring to the next frame slot. Call exactly once per rendered frame before any UpdateDynamicGeometry.
The slot the CPU writes (current) is distinct from the slot the GPU traced last frame, mirroring the table rings' frames-in-flight invariant. Must be paired with EndDynamicGeometryUpdate.
| GPUScene::GPUSceneTables GPUScene::BeginScene | ( | uint32_t | instanceCount, |
| uint32_t | materialCount, | ||
| uint32_t | lightCount | ||
| ) |
Begins a scene-table update, returning caller-fill spans.
Fill instances with InstanceDesc (geometry handle + transform + material); EndScene resolves the GPU-owned geometry offset/type. The materials/lights spans are mapped GPU memory filled in place. Must be paired with EndScene.
| void GPUScene::BuildBLAS | ( | RHICommandList * | cmd | ) |
Refits (or periodically rebuilds) every dirty dynamic geometry's BLAS in place against the current frame slot. Record in a render-graph pass that runs before the "TLAS Update" pass, declaring an acceleration-structure write on the BLAS region.
| GPUScene::TLASBuildResult GPUScene::BuildTLAS | ( | RHICommandList * | cmd, |
| bool | update = false |
||
| ) |
Builds (update=false) or refits (update=true) the TLAS from the committed instance table; instances whose geometry isn't yet Result::Ready are skipped.
Writes every GPUScene-owned global bindless index into the renderer UBO: the GGX/sheen LUTs, the display-transform view LUT (SDR or HDR per hdr), and the environment map + its importance-sampling CDFs (default-substituted when no env map is loaded).
| hdr | Selects the HDR view LUT when true, the SDR one otherwise. |
|
static |
|
static |
|
static |
| void GPUScene::Collect | ( | ) |
Garbage-collects geometry and textures no longer referenced by the committed scene tables.
| String GPUScene::DbgGetBufferStatistics | ( | ) | const |
| void GPUScene::DbgGetMemoryStatistics | ( | Vector< MemoryStat > & | outStats | ) | const |
| void GPUScene::EndDynamicGeometryUpdate | ( | ) |
Closes the per-frame dynamic-geometry update window opened by BeginDynamicGeometryUpdate.
| GPUScene::UpdateResult GPUScene::EndScene | ( | GPUSceneTables & | tables | ) |
| RHIBuffer * GPUScene::GetDynamicPrimitiveBuffer | ( | ) | const |
The host-coherent dynamic (CPU-updateable) primitive ring, bound as a second primitive storage buffer; instances with kGSInstanceFlagDynamic read from it.
| uint32_t GPUScene::GetDynamicRebuildCount | ( | ) | const |
Of the last refit, how many were full rebuilds (the rest were in-place updates).
| uint32_t GPUScene::GetDynamicRefitCount | ( | ) | const |
Dynamic geos refitted in the last RefitDynamicGeometry call.
|
inline |
|
inline |
|
inline |
|
inline |
| RHITexture * GPUScene::GetFoundationDefaultTexture2D | ( | ) | const |
| RHITexture * GPUScene::GetFoundationDefaultTexture2DFloat | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
| RHIBuffer * GPUScene::GetInstanceBuffer | ( | ) | const |
|
inline |
| RHIBuffer * GPUScene::GetLightAliasTableBuffer | ( | ) | const |
| RHIBuffer * GPUScene::GetLightBuffer | ( | ) | const |
| uint32_t GPUScene::GetLightCapacity | ( | ) | const |
|
inline |
|
inline |
| RHIBuffer * GPUScene::GetMaterialBuffer | ( | ) | const |
|
inline |
|
inline |
|
inline |
|
inline |
| BindlessPool * GPUScene::GetTexture2DPool | ( | ) |
| BindlessPool * GPUScene::GetTexture3DPool | ( | ) |
|
inline |
|
inline |
|
inline |
| bool GPUScene::HasDynamicGeometry | ( | ) | const |
True when at least one dynamic geometry is resident.
|
inline |
| void GPUScene::Join | ( | ) |
Drains all queued uploads on the calling thread, blocking until GPU-resident.
| GPUScene::Result GPUScene::Poll | ( | ) |
Non-blocking drain: kicks a background worker on the first call with queued work, then reports progress while streaming residency in.
The worker uploads geometry/textures and publishes residency incrementally; the owning GPUScene MAY be rendered concurrently while this returns InProgress. Instances stream into the TLAS as their geometry becomes Result::Ready, and Query reports per-texture residency so materials can fall back to defaults.
| GPUScene::Result GPUScene::Query | ( | GeometryHandle | handle | ) | const |
Residency state of an uploaded geometry handle.
| GPUScene::Result GPUScene::Query | ( | TextureHandle | texture | ) | const |
Residency state of an uploaded texture slot.
| void GPUScene::Reset | ( | ) |
Maps a TLAS pick id (instanceID) to its committed instance index, or UINT32_MAX.
Frames between forced full BLAS rebuilds for dynamic geo (0 = refit only). Default 64.
| Span< std::byte > GPUScene::UpdateDynamicGeometry | ( | GeometryHandle | handle | ) |
Returns the mapped vertex sub-span (quantized FQVertex bytes) for handle in the current frame slot and marks it dirty for this frame's BLAS refit. Lock-free: each dynamic handle owns a disjoint region. Only valid inside the BeginDynamicGeometryUpdate / EndDynamicGeometryUpdate window.
| GPUScene::Result GPUScene::Upload | ( | FBlobDeserializer * | blobs, |
| FSerializedCurve const & | source, | ||
| GeometryHandle & | outHandle | ||
| ) |
| GPUScene::Result GPUScene::Upload | ( | FBlobDeserializer * | blobs, |
| FSerializedMesh const & | source, | ||
| GeometryHandle & | outHandle | ||
| ) |
Reserves final resident memory for a resource and queues the rest of its upload, returning Result::InProgress when accepted.
The returned handle / texture slot is valid immediately and usable as a Query key while the work is pending. Hard failures that cannot succeed later (invalid input, final-residency OOM) are returned up front. Drain the queue with Join (blocking) or Poll (background); the resource is GPU-usable only once Query reports Result::Ready.
| blobs | Deserializer for the source's payloads; must outlive the drain. |
| source | Serialized mesh/curve/texture to upload. |
| outHandle | [out] Geometry handle, allocated before completion. |
| GPUScene::Result GPUScene::Upload | ( | FBlobDeserializer * | blobs, |
| FSerializedTexture const & | source, | ||
| TextureHandle & | outTexture, | ||
| const char * | debugName = nullptr, |
||
| bool | pinned = false |
||
| ) |
Queues a serialized texture upload, binding its bindless slot up front.
| outTexture | [in,out] Pass a default (invalid) handle to allocate a new slot, or an existing handle to update it in place (env map / view LUT reload). |
| pinned | When true the slot is a GPUScene-owned singleton that Collect must never reclaim (LUTs / defaults / env map); scene textures pass false. |
| GPUScene::Result GPUScene::Upload | ( | FTexture const & | source, |
| TextureHandle & | outTexture, | ||
| const char * | debugName = nullptr, |
||
| bool | pinned = false |
||
| ) |
Uploads a CPU-resident FTexture through the same queue (runs to completion).
| GPUScene::Result GPUScene::Upload | ( | RHIBuffer * | dst, |
| Span< const unsigned char > | data, | ||
| uint32_t | dstOffset = 0 |
||
| ) |
Queues a copy of data into a device-local buffer region (drained by Join/Poll).
| GPUScene::Result GPUScene::UploadDynamic | ( | FBlobDeserializer * | blobs, |
| FSerializedMesh const & | source, | ||
| GeometryHandle & | outHandle | ||
| ) |
Uploads a mesh as CPU-updateable dynamic geometry (deformation workloads).
Topology (indices) is fixed; only vertex positions change per frame. The source's quantized verts + LOD0 indices are reserved in the host-coherent dynamic ring (replicated across every frame slot) and a single RHIAccelerationStructureBuildFlagsBits::AllowUpdate BLAS is built once. Per frame the caller rewrites the current slot's verts via BeginGeometryUpdate / EndGeometryUpdate and the graph's "Dynamic BLAS Refit" pass (RefitDynamicGeometry) refits the BLAS in place. DAG/meshlet payloads are ignored (dynamic geo is drawn with a plain vertex/index path, not the meshlet pipeline). Requires GPUSceneDesc::dynamicGeometryBudget > 0.
| GPUScene::Result GPUScene::UploadEnvMap | ( | FTexture const & | source | ) |
Uploads an environment map and computes its importance-sampling CDFs.
| GPUScene::Result GPUScene::UploadViewLUTs | ( | FTexture const & | sdr, |
| FTexture const & | hdr | ||
| ) |
Uploads the SDR/HDR display-transform view LUTs (owns its staging).
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
| LightSamplerType GPUScene::mLightSamplerType = LightSamplerType::Power |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |