refactor: route builtin forward pipeline through shader assets

This commit is contained in:
2026-04-02 19:00:48 +08:00
parent 86144416af
commit 9f7d8fd68d
8 changed files with 585 additions and 220 deletions

View File

@@ -14,6 +14,7 @@
#include <XCEngine/RHI/RHISampler.h>
#include <XCEngine/RHI/RHITexture.h>
#include <functional>
#include <unordered_map>
namespace XCEngine {
@@ -23,6 +24,7 @@ class GameObject;
namespace Resources {
class Material;
class Shader;
class Texture;
} // namespace Resources
@@ -76,9 +78,41 @@ private:
RHI::RHIResourceView* textureView = 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;
bool operator==(const PipelineStateKey& other) const {
return renderState == other.renderState &&
shader == other.shader &&
passName == other.passName;
}
};
struct PipelineStateKeyHash {
size_t operator()(const PipelineStateKey& key) const noexcept {
size_t hash = MaterialRenderStateHash()(key.renderState);
auto combine = [&hash](size_t value) {
hash ^= value + 0x9e3779b9u + (hash << 6) + (hash >> 2);
};
combine(reinterpret_cast<size_t>(key.shader));
combine(std::hash<Containers::String>{}(key.passName));
return hash;
}
};
bool EnsureInitialized(const RenderContext& context);
bool CreatePipelineResources(const RenderContext& context);
void DestroyPipelineResources();
ResolvedShaderPass ResolveForwardShaderPass(const Resources::Material* material) const;
RHI::RHIPipelineState* GetOrCreatePipelineState(
const RenderContext& context,
const Resources::Material* material);
@@ -99,13 +133,14 @@ private:
RHI::RHIDevice* m_device = nullptr;
RHI::RHIType m_backendType = RHI::RHIType::D3D12;
bool m_initialized = false;
Resources::ResourceHandle<Resources::Shader> m_builtinForwardShader;
RenderResourceCache m_resourceCache;
RHI::RHIDescriptorPool* m_samplerPool = nullptr;
RHI::RHIDescriptorSet* m_samplerSet = nullptr;
RHI::RHIPipelineLayout* m_pipelineLayout = nullptr;
std::unordered_map<Resources::MaterialRenderState, RHI::RHIPipelineState*, MaterialRenderStateHash> m_pipelineStates;
std::unordered_map<PipelineStateKey, RHI::RHIPipelineState*, PipelineStateKeyHash> m_pipelineStates;
std::unordered_map<Core::uint64, OwnedDescriptorSet> m_perObjectSets;
std::unordered_map<const Resources::Material*, CachedMaterialBindings> m_materialBindings;
RHI::RHISampler* m_sampler = nullptr;