refactor: add minimal material gpu binding

This commit is contained in:
2026-04-02 17:13:53 +08:00
parent 33f16597fa
commit dd08d8969e
7 changed files with 455 additions and 81 deletions

View File

@@ -65,6 +65,17 @@ private:
Math::Vector4 mainLightColorAndFlags = Math::Vector4::Zero();
};
struct PerMaterialConstants {
Math::Vector4 baseColorFactor = Math::Vector4::One();
};
struct CachedMaterialBindings {
OwnedDescriptorSet constantSet = {};
OwnedDescriptorSet textureSet = {};
Core::uint64 materialVersion = 0;
RHI::RHIResourceView* textureView = nullptr;
};
bool EnsureInitialized(const RenderContext& context);
bool CreatePipelineResources(const RenderContext& context);
void DestroyPipelineResources();
@@ -72,7 +83,9 @@ private:
const RenderContext& context,
const Resources::Material* material);
RHI::RHIDescriptorSet* GetOrCreatePerObjectSet(Core::uint64 objectId);
RHI::RHIDescriptorSet* GetOrCreateTextureSet(RHI::RHIResourceView* textureView);
CachedMaterialBindings* GetOrCreateMaterialBindings(
const Resources::Material* material,
RHI::RHIResourceView* textureView);
void DestroyOwnedDescriptorSet(OwnedDescriptorSet& descriptorSet);
const Resources::Texture* ResolveTexture(const Resources::Material* material) const;
@@ -94,7 +107,7 @@ private:
RHI::RHIPipelineLayout* m_pipelineLayout = nullptr;
std::unordered_map<Resources::MaterialRenderState, RHI::RHIPipelineState*, MaterialRenderStateHash> m_pipelineStates;
std::unordered_map<Core::uint64, OwnedDescriptorSet> m_perObjectSets;
std::unordered_map<RHI::RHIResourceView*, OwnedDescriptorSet> m_textureSets;
std::unordered_map<const Resources::Material*, CachedMaterialBindings> m_materialBindings;
RHI::RHISampler* m_sampler = nullptr;
RHI::RHITexture* m_fallbackTexture = nullptr;
RHI::RHIResourceView* m_fallbackTextureView = nullptr;