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

@@ -148,7 +148,8 @@ private:
ResourceManager() = default;
~ResourceManager() = default;
void EnsureInitialized();
IResource* FindInCache(ResourceGUID guid);
void AddToCache(ResourceGUID guid, IResource* resource);
IResourceLoader* FindLoader(ResourceType type);
@@ -168,6 +169,7 @@ private:
ResourceCache m_cache;
Core::UniqueRef<AsyncLoader> m_asyncLoader;
Threading::Mutex m_mutex;
std::mutex m_initializeMutex;
mutable std::recursive_mutex m_ioMutex;
std::mutex m_inFlightLoadsMutex;
std::unordered_map<InFlightLoadKey, std::shared_ptr<InFlightLoadState>, InFlightLoadKeyHasher> m_inFlightLoads;

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;

View File

@@ -17,17 +17,20 @@ enum class BuiltinPrimitiveType {
bool IsBuiltinResourcePath(const Containers::String& path);
bool IsBuiltinMeshPath(const Containers::String& path);
bool IsBuiltinMaterialPath(const Containers::String& path);
bool IsBuiltinShaderPath(const Containers::String& path);
bool IsBuiltinTexturePath(const Containers::String& path);
const char* GetBuiltinPrimitiveDisplayName(BuiltinPrimitiveType primitiveType);
Containers::String GetBuiltinPrimitiveMeshPath(BuiltinPrimitiveType primitiveType);
Containers::String GetBuiltinDefaultPrimitiveMaterialPath();
Containers::String GetBuiltinForwardLitShaderPath();
Containers::String GetBuiltinDefaultPrimitiveTexturePath();
bool TryParseBuiltinPrimitiveType(const Containers::String& path, BuiltinPrimitiveType& outPrimitiveType);
LoadResult CreateBuiltinMeshResource(const Containers::String& path);
LoadResult CreateBuiltinMaterialResource(const Containers::String& path);
LoadResult CreateBuiltinShaderResource(const Containers::String& path);
LoadResult CreateBuiltinTextureResource(const Containers::String& path);
} // namespace Resources