Formalize GaussianSplat render cache

This commit is contained in:
2026-04-10 20:44:24 +08:00
parent 84faa585d5
commit 8f5c342799
4 changed files with 863 additions and 9 deletions

View File

@@ -4,6 +4,7 @@
#include <XCEngine/RHI/RHIDevice.h>
#include <XCEngine/RHI/RHIResourceView.h>
#include <XCEngine/RHI/RHITexture.h>
#include <XCEngine/Resources/GaussianSplat/GaussianSplat.h>
#include <XCEngine/Resources/Mesh/Mesh.h>
#include <XCEngine/Resources/Texture/Texture.h>
#include <XCEngine/Resources/Volume/VolumeField.h>
@@ -15,6 +16,14 @@ namespace Rendering {
class RenderResourceCache {
public:
enum class GaussianSplatResidencyState {
Uninitialized = 0,
CpuReady,
GpuUploading,
GpuReady,
Failed
};
struct CachedMesh {
RHI::RHIBuffer* vertexBuffer = nullptr;
RHI::RHIResourceView* vertexBufferView = nullptr;
@@ -46,6 +55,30 @@ public:
Resources::VolumeStorageKind storageKind = Resources::VolumeStorageKind::Unknown;
};
struct CachedGaussianSplatSection {
RHI::RHIBuffer* buffer = nullptr;
RHI::RHIResourceView* shaderResourceView = nullptr;
Resources::GaussianSplatSectionType type = Resources::GaussianSplatSectionType::Unknown;
Resources::GaussianSplatSectionFormat format = Resources::GaussianSplatSectionFormat::Unknown;
uint32_t elementStride = 0;
uint32_t elementCount = 0;
uint64_t payloadSize = 0;
};
struct CachedGaussianSplat {
GaussianSplatResidencyState residencyState = GaussianSplatResidencyState::Uninitialized;
uint32_t contentVersion = 0;
uint32_t splatCount = 0;
uint32_t chunkCount = 0;
uint32_t cameraCount = 0;
Math::Bounds bounds;
CachedGaussianSplatSection positions;
CachedGaussianSplatSection other;
CachedGaussianSplatSection color;
CachedGaussianSplatSection sh;
CachedGaussianSplatSection chunks;
};
~RenderResourceCache();
void Shutdown();
@@ -55,6 +88,9 @@ public:
const CachedVolumeField* GetOrCreateVolumeField(
RHI::RHIDevice* device,
const Resources::VolumeField* volumeField);
const CachedGaussianSplat* GetOrCreateGaussianSplat(
RHI::RHIDevice* device,
const Resources::GaussianSplat* gaussianSplat);
const CachedBufferView* GetOrCreateBufferView(
RHI::RHIDevice* device,
RHI::RHIBuffer* buffer,
@@ -94,6 +130,18 @@ private:
RHI::RHIDevice* device,
const Resources::VolumeField* volumeField,
CachedVolumeField& cachedVolumeField);
bool UploadGaussianSplat(
RHI::RHIDevice* device,
const Resources::GaussianSplat* gaussianSplat,
CachedGaussianSplat& cachedGaussianSplat);
bool UploadGaussianSplatSection(
RHI::RHIDevice* device,
const Resources::GaussianSplat* gaussianSplat,
Resources::GaussianSplatSectionType sectionType,
Resources::GaussianSplatSectionFormat requiredFormat,
uint32_t requiredStride,
bool requiredSection,
CachedGaussianSplatSection& cachedSection);
bool CreateBufferView(
RHI::RHIDevice* device,
RHI::RHIBuffer* buffer,
@@ -104,6 +152,7 @@ private:
std::unordered_map<const Resources::Mesh*, CachedMesh> m_meshCache;
std::unordered_map<const Resources::Texture*, CachedTexture> m_textureCache;
std::unordered_map<const Resources::VolumeField*, CachedVolumeField> m_volumeFieldCache;
std::unordered_map<const Resources::GaussianSplat*, CachedGaussianSplat> m_gaussianSplatCache;
std::unordered_map<BufferViewCacheKey, CachedBufferView, BufferViewCacheKeyHash> m_bufferViewCache;
};