Refactoring, eliminated DescriptorSetInfo.query, merging into DescriptorSetInfo.bindings
Implemented KRPipeline::setImageBinding Added stub function KRPipeline::updateDescriptorBinding
This commit is contained in:
@@ -529,22 +529,31 @@ void KRPipeline::initDescriptorSetStage(ShaderStage stage, const SpvReflectShade
|
|||||||
for (int i = 0; i < reflection->descriptor_set_count; i++) {
|
for (int i = 0; i < reflection->descriptor_set_count; i++) {
|
||||||
SpvReflectDescriptorSet descriptorSet = reflection->descriptor_sets[i];
|
SpvReflectDescriptorSet descriptorSet = reflection->descriptor_sets[i];
|
||||||
DescriptorSetInfo& descriptorSetInfo = descriptorSets.emplace_back();
|
DescriptorSetInfo& descriptorSetInfo = descriptorSets.emplace_back();
|
||||||
descriptorSetInfo.query.reserve(descriptorSet.binding_count);
|
descriptorSetInfo.bindings.reserve(descriptorSet.binding_count);
|
||||||
for (int j = 0; j < descriptorSet.binding_count; j++) {
|
for (int j = 0; j < descriptorSet.binding_count; j++) {
|
||||||
SpvReflectDescriptorBinding& binding = *descriptorSet.bindings[j];
|
SpvReflectDescriptorBinding& binding = *descriptorSet.bindings[j];
|
||||||
std::pair<VkDescriptorType, std::string>& descriptorQuery = descriptorSetInfo.query.emplace_back();
|
DescriptorBinding& descriptorQuery = descriptorSetInfo.bindings.emplace_back();
|
||||||
descriptorQuery.second = binding.name;
|
|
||||||
switch (binding.descriptor_type) {
|
switch (binding.descriptor_type) {
|
||||||
case SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
case SPV_REFLECT_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
|
||||||
descriptorQuery.first = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
{
|
||||||
break;
|
ImageDescriptorInfo& imageInfo = descriptorQuery.emplace<ImageDescriptorInfo>();
|
||||||
case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
imageInfo.name = binding.name;
|
||||||
descriptorQuery.first = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
|
imageInfo.texture = nullptr;
|
||||||
break;
|
imageInfo.sampler = nullptr;
|
||||||
default:
|
}
|
||||||
// Not supported
|
break;
|
||||||
// TODO - Error handling
|
case SPV_REFLECT_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
|
||||||
break;
|
{
|
||||||
|
UniformBufferDescriptorInfo& bufferInfo = descriptorQuery.emplace<UniformBufferDescriptorInfo>();
|
||||||
|
bufferInfo.name = binding.name;
|
||||||
|
bufferInfo.buffer = nullptr;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Not supported
|
||||||
|
// TODO - Error handling
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -636,8 +645,15 @@ void KRPipeline::setPushConstant(PushConstant location, const Matrix4* value, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KRPipeline::updateDescriptorBinding()
|
||||||
|
{
|
||||||
|
// TODO - Implement
|
||||||
|
// Vulkan Refactoring
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
|
updateDescriptorBinding();
|
||||||
updateDescriptorSets();
|
updateDescriptorSets();
|
||||||
bindDescriptorSets(commandBuffer);
|
bindDescriptorSets(commandBuffer);
|
||||||
setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime());
|
setPushConstant(PushConstant::absolute_time, getContext().getAbsoluteTime());
|
||||||
@@ -948,5 +964,19 @@ VkPipeline& KRPipeline::getPipeline()
|
|||||||
|
|
||||||
void KRPipeline::setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler)
|
void KRPipeline::setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler)
|
||||||
{
|
{
|
||||||
// TODO - Implement
|
for (int stage = 0; stage < static_cast<size_t>(ShaderStage::ShaderStageCount); stage++) {
|
||||||
|
StageInfo& stageInfo = m_stages[stage];
|
||||||
|
for (DescriptorSetInfo& descriptorSetInfo : stageInfo.descriptorSets) {
|
||||||
|
int bindingIndex = 0;
|
||||||
|
for (DescriptorBinding& binding : descriptorSetInfo.bindings) {
|
||||||
|
ImageDescriptorInfo* image = std::get_if<ImageDescriptorInfo>(&binding);
|
||||||
|
if (image) {
|
||||||
|
if (image->name == name) {
|
||||||
|
image->texture = texture;
|
||||||
|
image->sampler = sampler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ public:
|
|||||||
void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler);
|
void setImageBinding(const std::string& name, KRTexture* texture, KRSampler* sampler);
|
||||||
|
|
||||||
VkPipeline& getPipeline();
|
VkPipeline& getPipeline();
|
||||||
|
void updateDescriptorBinding();
|
||||||
void updateDescriptorSets();
|
void updateDescriptorSets();
|
||||||
void bindDescriptorSets(VkCommandBuffer& commandBuffer);
|
void bindDescriptorSets(VkCommandBuffer& commandBuffer);
|
||||||
|
|
||||||
@@ -327,20 +328,20 @@ private:
|
|||||||
{
|
{
|
||||||
KRTexture* texture;
|
KRTexture* texture;
|
||||||
KRSampler* sampler;
|
KRSampler* sampler;
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct UniformBufferDescriptorInfo
|
struct UniformBufferDescriptorInfo
|
||||||
{
|
{
|
||||||
KRUniformBuffer* buffer;
|
KRUniformBuffer* buffer;
|
||||||
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<std::pair<VkDescriptorType, std::string>> DescriptorSetQuery;
|
|
||||||
typedef std::variant<ImageDescriptorInfo, UniformBufferDescriptorInfo> DescriptorBinding;
|
typedef std::variant<ImageDescriptorInfo, UniformBufferDescriptorInfo> DescriptorBinding;
|
||||||
typedef std::vector<DescriptorBinding> DescriptorSetBinding;
|
typedef std::vector<DescriptorBinding> DescriptorSetBinding;
|
||||||
|
|
||||||
struct DescriptorSetInfo
|
struct DescriptorSetInfo
|
||||||
{
|
{
|
||||||
DescriptorSetQuery query;
|
|
||||||
DescriptorSetBinding bindings;
|
DescriptorSetBinding bindings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user