// // Created by atdunbg on 2026/9/21. // #include #include #include #include #include #include #include #include namespace Engine { Material::Material(Device& device, MemoryAllocator& allocator, DescriptorManager& descriptorManager, vk::DescriptorSetLayout layout, const std::array& textures, const MaterialParams& params) : m_Textures(textures) { m_DescriptorSet = descriptorManager.AllocateDescriptorSet(layout); for (u32 slot = 0; slot < kSlotCount; ++slot) { descriptorManager.UpdateTexture( m_DescriptorSet, slot, m_Textures[slot]->GetSampler(), m_Textures[slot]->GetView()); } // 材质参数:per-slot ring,创建时写死(参数静态,无每帧更新) m_ParamsBuffer = CreateScope( device, allocator, sizeof(MaterialParams), kMaxFramesInFlight); for (u32 slot = 0; slot < kMaxFramesInFlight; ++slot) { m_ParamsBuffer->Update(slot, ¶ms, sizeof(params)); descriptorManager.UpdateUniformBuffer( m_DescriptorSet, kParamsBinding, m_ParamsBuffer->Get(slot), m_ParamsBuffer->GetSize()); } } Material::~Material() = default; std::string Material::MakeCacheKey(const std::string paths[kSlotCount], const MaterialParams& params) { std::string key; for (u32 slot = 0; slot < kSlotCount; ++slot) { key += paths[slot]; key += '\n'; } key += "f:" + std::to_string(params.factors.x) + "," + std::to_string(params.factors.y); return key; } } // namespace Engine