72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <XCEngine/Core/Math/Matrix4.h>
|
|
#include <XCEngine/Rendering/BuiltinPassTypes.h>
|
|
#include <XCEngine/Rendering/ObjectIdEncoding.h>
|
|
#include <XCEngine/Rendering/RenderPass.h>
|
|
#include <XCEngine/Rendering/RenderResourceCache.h>
|
|
#include <XCEngine/Core/Asset/ResourceHandle.h>
|
|
#include <XCEngine/RHI/RHIPipelineState.h>
|
|
#include <XCEngine/Resources/Shader/Shader.h>
|
|
|
|
#include <unordered_map>
|
|
|
|
namespace XCEngine {
|
|
namespace Rendering {
|
|
struct VisibleRenderItem;
|
|
|
|
namespace Passes {
|
|
|
|
class BuiltinObjectIdPass final : public RenderPass {
|
|
public:
|
|
~BuiltinObjectIdPass() 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::Vector4 objectIdColor = Math::Vector4::Zero();
|
|
};
|
|
|
|
struct OwnedDescriptorSet {
|
|
RHI::RHIDescriptorPool* pool = nullptr;
|
|
RHI::RHIDescriptorSet* set = nullptr;
|
|
};
|
|
|
|
bool EnsureInitialized(const RenderContext& context);
|
|
bool CreateResources(const RenderContext& context);
|
|
void DestroyResources();
|
|
|
|
RHI::RHIDescriptorSet* GetOrCreatePerObjectSet(uint64_t objectId);
|
|
void DestroyOwnedDescriptorSet(OwnedDescriptorSet& descriptorSet);
|
|
bool DrawVisibleItem(
|
|
const RenderContext& context,
|
|
const RenderSceneData& sceneData,
|
|
const VisibleRenderItem& visibleItem);
|
|
|
|
RHI::RHIDevice* m_device = nullptr;
|
|
RHI::RHIType m_backendType = RHI::RHIType::D3D12;
|
|
RHI::RHIPipelineLayout* m_pipelineLayout = nullptr;
|
|
RHI::RHIPipelineState* m_pipelineState = nullptr;
|
|
PassResourceBindingLocation m_perObjectBinding = {};
|
|
BuiltinPassSetLayoutMetadata m_perObjectSetLayout = {};
|
|
Core::uint32 m_firstDescriptorSet = 0;
|
|
Resources::ResourceHandle<Resources::Shader> m_builtinObjectIdShader;
|
|
RenderResourceCache m_resourceCache;
|
|
std::unordered_map<uint64_t, OwnedDescriptorSet> m_perObjectSets;
|
|
};
|
|
|
|
} // namespace Passes
|
|
} // namespace Rendering
|
|
} // namespace XCEngine
|