Add NanoVDB volume test scaffolding
This commit is contained in:
209
engine/include/XCEngine/Rendering/Passes/BuiltinVolumetricPass.h
Normal file
209
engine/include/XCEngine/Rendering/Passes/BuiltinVolumetricPass.h
Normal file
@@ -0,0 +1,209 @@
|
||||
#pragma once
|
||||
|
||||
#include <XCEngine/Core/Asset/ResourceHandle.h>
|
||||
#include <XCEngine/Core/Math/Matrix4.h>
|
||||
#include <XCEngine/Rendering/Builtin/BuiltinPassTypes.h>
|
||||
#include <XCEngine/Rendering/Caches/RenderResourceCache.h>
|
||||
#include <XCEngine/Rendering/Materials/RenderMaterialResolve.h>
|
||||
#include <XCEngine/Rendering/Materials/RenderMaterialStateUtils.h>
|
||||
#include <XCEngine/Rendering/RenderPass.h>
|
||||
#include <XCEngine/RHI/RHIDescriptorPool.h>
|
||||
#include <XCEngine/RHI/RHIDescriptorSet.h>
|
||||
#include <XCEngine/RHI/RHIPipelineLayout.h>
|
||||
#include <XCEngine/RHI/RHIPipelineState.h>
|
||||
#include <XCEngine/Resources/Mesh/Mesh.h>
|
||||
#include <XCEngine/Resources/Shader/Shader.h>
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Components {
|
||||
class GameObject;
|
||||
} // namespace Components
|
||||
|
||||
namespace Resources {
|
||||
class Material;
|
||||
class VolumeField;
|
||||
} // namespace Resources
|
||||
|
||||
namespace Rendering {
|
||||
struct VisibleVolumeItem;
|
||||
|
||||
namespace Passes {
|
||||
|
||||
class BuiltinVolumetricPass final : public RenderPass {
|
||||
public:
|
||||
~BuiltinVolumetricPass() override;
|
||||
|
||||
static RHI::InputLayoutDesc BuildInputLayout();
|
||||
|
||||
const char* GetName() const override;
|
||||
bool Initialize(const RenderContext& context) override;
|
||||
bool Execute(const RenderPassContext& context) override;
|
||||
void Shutdown() override;
|
||||
|
||||
private:
|
||||
struct PerObjectConstants {
|
||||
Math::Matrix4x4 projection = Math::Matrix4x4::Identity();
|
||||
Math::Matrix4x4 view = Math::Matrix4x4::Identity();
|
||||
Math::Matrix4x4 model = Math::Matrix4x4::Identity();
|
||||
Math::Matrix4x4 inverseModel = Math::Matrix4x4::Identity();
|
||||
Math::Vector4 cameraWorldPosition = Math::Vector4::Zero();
|
||||
Math::Vector4 localBoundsMin = Math::Vector4::Zero();
|
||||
Math::Vector4 localBoundsMax = Math::Vector4::Zero();
|
||||
};
|
||||
|
||||
struct OwnedDescriptorSet {
|
||||
RHI::RHIDescriptorPool* pool = nullptr;
|
||||
RHI::RHIDescriptorSet* set = nullptr;
|
||||
};
|
||||
|
||||
struct PassLayoutKey {
|
||||
const Resources::Shader* shader = nullptr;
|
||||
Containers::String passName;
|
||||
|
||||
bool operator==(const PassLayoutKey& other) const {
|
||||
return shader == other.shader && passName == other.passName;
|
||||
}
|
||||
};
|
||||
|
||||
struct PassLayoutKeyHash {
|
||||
size_t operator()(const PassLayoutKey& key) const noexcept {
|
||||
size_t hash = reinterpret_cast<size_t>(key.shader);
|
||||
hash ^= std::hash<Containers::String>{}(key.passName) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct PassResourceLayout {
|
||||
RHI::RHIPipelineLayout* pipelineLayout = nullptr;
|
||||
Core::uint32 firstDescriptorSet = 0;
|
||||
Core::uint32 descriptorSetCount = 0;
|
||||
std::vector<BuiltinPassSetLayoutMetadata> setLayouts;
|
||||
PassResourceBindingLocation perObject = {};
|
||||
PassResourceBindingLocation material = {};
|
||||
PassResourceBindingLocation volumeField = {};
|
||||
};
|
||||
|
||||
struct DynamicDescriptorSetKey {
|
||||
PassLayoutKey passLayout = {};
|
||||
Core::uint32 setIndex = 0;
|
||||
Core::uint64 objectId = 0;
|
||||
const Resources::Material* material = nullptr;
|
||||
const Resources::VolumeField* volumeField = nullptr;
|
||||
|
||||
bool operator==(const DynamicDescriptorSetKey& other) const {
|
||||
return passLayout == other.passLayout &&
|
||||
setIndex == other.setIndex &&
|
||||
objectId == other.objectId &&
|
||||
material == other.material &&
|
||||
volumeField == other.volumeField;
|
||||
}
|
||||
};
|
||||
|
||||
struct DynamicDescriptorSetKeyHash {
|
||||
size_t operator()(const DynamicDescriptorSetKey& key) const noexcept {
|
||||
size_t hash = PassLayoutKeyHash()(key.passLayout);
|
||||
hash ^= std::hash<Core::uint32>{}(key.setIndex) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<Core::uint64>{}(key.objectId) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= reinterpret_cast<size_t>(key.material) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= reinterpret_cast<size_t>(key.volumeField) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
struct CachedDescriptorSet {
|
||||
OwnedDescriptorSet descriptorSet = {};
|
||||
Core::uint64 materialVersion = 0;
|
||||
RHI::RHIResourceView* volumeFieldView = nullptr;
|
||||
};
|
||||
|
||||
struct ResolvedShaderPass {
|
||||
const Resources::Shader* shader = nullptr;
|
||||
const Resources::ShaderPass* pass = nullptr;
|
||||
Containers::String passName;
|
||||
};
|
||||
|
||||
struct PipelineStateKey {
|
||||
Resources::MaterialRenderState renderState;
|
||||
const Resources::Shader* shader = nullptr;
|
||||
Containers::String passName;
|
||||
Containers::String keywordSignature;
|
||||
uint32_t renderTargetCount = 0;
|
||||
uint32_t renderTargetFormat = 0;
|
||||
uint32_t depthStencilFormat = 0;
|
||||
|
||||
bool operator==(const PipelineStateKey& other) const {
|
||||
return renderState == other.renderState &&
|
||||
shader == other.shader &&
|
||||
passName == other.passName &&
|
||||
keywordSignature == other.keywordSignature &&
|
||||
renderTargetCount == other.renderTargetCount &&
|
||||
renderTargetFormat == other.renderTargetFormat &&
|
||||
depthStencilFormat == other.depthStencilFormat;
|
||||
}
|
||||
};
|
||||
|
||||
struct PipelineStateKeyHash {
|
||||
size_t operator()(const PipelineStateKey& key) const noexcept {
|
||||
size_t hash = MaterialRenderStateHash()(key.renderState);
|
||||
hash ^= reinterpret_cast<size_t>(key.shader) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<Containers::String>{}(key.passName) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<Containers::String>{}(key.keywordSignature) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<uint32_t>{}(key.renderTargetCount) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<uint32_t>{}(key.renderTargetFormat) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
hash ^= std::hash<uint32_t>{}(key.depthStencilFormat) + 0x9e3779b9u + (hash << 6) + (hash >> 2);
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
bool EnsureInitialized(const RenderContext& context);
|
||||
bool CreateResources(const RenderContext& context);
|
||||
void DestroyResources();
|
||||
|
||||
ResolvedShaderPass ResolveVolumeShaderPass(
|
||||
const RenderSceneData& sceneData,
|
||||
const Resources::Material* material) const;
|
||||
PassResourceLayout* GetOrCreatePassResourceLayout(
|
||||
const RenderContext& context,
|
||||
const ResolvedShaderPass& resolvedShaderPass);
|
||||
RHI::RHIPipelineState* GetOrCreatePipelineState(
|
||||
const RenderContext& context,
|
||||
const RenderSurface& surface,
|
||||
const RenderSceneData& sceneData,
|
||||
const Resources::Material* material);
|
||||
bool CreateOwnedDescriptorSet(
|
||||
const BuiltinPassSetLayoutMetadata& setLayout,
|
||||
OwnedDescriptorSet& descriptorSet);
|
||||
CachedDescriptorSet* GetOrCreateDynamicDescriptorSet(
|
||||
const PassLayoutKey& passLayoutKey,
|
||||
const PassResourceLayout& passLayout,
|
||||
const BuiltinPassSetLayoutMetadata& setLayout,
|
||||
Core::uint32 setIndex,
|
||||
Core::uint64 objectId,
|
||||
const Resources::Material* material,
|
||||
const Resources::VolumeField* volumeField,
|
||||
const MaterialConstantPayloadView& materialConstants,
|
||||
RHI::RHIResourceView* volumeFieldView);
|
||||
void DestroyOwnedDescriptorSet(OwnedDescriptorSet& descriptorSet);
|
||||
void DestroyPassResourceLayout(PassResourceLayout& passLayout);
|
||||
bool DrawVisibleVolume(
|
||||
const RenderContext& context,
|
||||
const RenderSurface& surface,
|
||||
const RenderSceneData& sceneData,
|
||||
const VisibleVolumeItem& visibleVolume);
|
||||
|
||||
RHI::RHIDevice* m_device = nullptr;
|
||||
RHI::RHIType m_backendType = RHI::RHIType::D3D12;
|
||||
Resources::ResourceHandle<Resources::Mesh> m_builtinCubeMesh;
|
||||
RenderResourceCache m_resourceCache;
|
||||
|
||||
std::unordered_map<PassLayoutKey, PassResourceLayout, PassLayoutKeyHash> m_passResourceLayouts;
|
||||
std::unordered_map<PipelineStateKey, RHI::RHIPipelineState*, PipelineStateKeyHash> m_pipelineStates;
|
||||
std::unordered_map<DynamicDescriptorSetKey, CachedDescriptorSet, DynamicDescriptorSetKeyHash> m_dynamicDescriptorSets;
|
||||
};
|
||||
|
||||
} // namespace Passes
|
||||
} // namespace Rendering
|
||||
} // namespace XCEngine
|
||||
3454
engine/third_party/nanovdb/shaders/PNanoVDB.hlsl
vendored
Normal file
3454
engine/third_party/nanovdb/shaders/PNanoVDB.hlsl
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user