Added KRPipeline::updateDescriptorSets

WIP creating and updating descriptor sets for KRPipeline binding.
This commit is contained in:
2022-09-20 18:54:01 -07:00
parent 5ab035b076
commit 3df8433205
2 changed files with 26 additions and 1 deletions

View File

@@ -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<KRDevice>& device = surface.getDevice();
// TODO - Handle device removal
m_deviceHandle = surface.m_deviceHandle;
std::unique_ptr<KRDevice>& 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<KRPointLight*>* point_lights, const std::vector<KRDirectionalLight*>* directional_lights, const std::vector<KRSpotLight*>* 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<KRDevice>& device = getContext().getDeviceManager()->getDevice(m_deviceHandle);
// TODO - Handle device context loss
m_descriptorSets.resize(KRENGINE_MAX_FRAMES_IN_FLIGHT, VK_NULL_HANDLE);
std::vector<VkDescriptorSetLayout> layouts(KRENGINE_MAX_FRAMES_IN_FLIGHT, m_descriptorSetLayout);
device->createDescriptorSets(layouts, m_descriptorSets);
}
const char* KRPipeline::getKey() const
{
return m_szKey;

View File

@@ -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<VkDescriptorSet> m_descriptorSets;
KrDeviceHandle m_deviceHandle;
void initPushConstantStage(ShaderStage stage, const SpvReflectShaderModule* reflection);
void initDescriptorSetStage(ShaderStage stage, const SpvReflectShaderModule* reflection);