diff --git a/kraken/KRPipeline.cpp b/kraken/KRPipeline.cpp index 7bc4f48..75f3d44 100644 --- a/kraken/KRPipeline.cpp +++ b/kraken/KRPipeline.cpp @@ -125,9 +125,11 @@ KRPipeline::KRPipeline(KRContext& context, KRSurface& surface, const PipelineInf m_descriptorSetLayout = nullptr; m_pipelineLayout = nullptr; m_graphicsPipeline = nullptr; + m_descriptorSets.reserve(KRENGINE_MAX_FRAMES_IN_FLIGHT); - std::unique_ptr& device = surface.getDevice(); // TODO - Handle device removal + m_deviceHandle = surface.m_deviceHandle; + std::unique_ptr& device = surface.getDevice(); strcpy(m_szKey, szKey); @@ -636,6 +638,7 @@ void KRPipeline::setPushConstant(PushConstant location, const Matrix4* value, co bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KRViewport& viewport, const Matrix4& matModel, const std::vector* point_lights, const std::vector* directional_lights, const std::vector* spot_lights, const KRNode::RenderPass& renderPass) { + updateDescriptorSets(); setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime()); int light_directional_count = 0; @@ -834,6 +837,25 @@ bool KRPipeline::bind(VkCommandBuffer& commandBuffer, KRCamera& camera, const KR return true; } +void KRPipeline::updateDescriptorSets() +{ + if (m_descriptorSetLayout == VK_NULL_HANDLE) { + // There are no descriptors + return; + } + if (m_descriptorSets.size()) { + // TODO - We should detect changes to descriptor sets and update them + return; + } + + std::unique_ptr& device = getContext().getDeviceManager()->getDevice(m_deviceHandle); + // TODO - Handle device context loss + + m_descriptorSets.resize(KRENGINE_MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE); + std::vector layouts(KRENGINE_MAX_FRAMES_IN_FLIGHT, m_descriptorSetLayout); + device->createDescriptorSets(layouts, m_descriptorSets); +} + const char* KRPipeline::getKey() const { return m_szKey; diff --git a/kraken/KRPipeline.h b/kraken/KRPipeline.h index a8c11e7..5f2fe5d 100644 --- a/kraken/KRPipeline.h +++ b/kraken/KRPipeline.h @@ -308,6 +308,7 @@ public: void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler); VkPipeline& getPipeline(); + void updateDescriptorSets(); private: static const char* KRENGINE_PUSH_CONSTANT_NAMES[]; @@ -357,6 +358,8 @@ private: VkDescriptorSetLayout m_descriptorSetLayout; VkPipelineLayout m_pipelineLayout; VkPipeline m_graphicsPipeline; + std::vector m_descriptorSets; + KrDeviceHandle m_deviceHandle; void initPushConstantStage(ShaderStage stage, const SpvReflectShaderModule* reflection); void initDescriptorSetStage(ShaderStage stage, const SpvReflectShaderModule* reflection);