diff --git a/source/blender/gpu/vulkan/vk_index_buffer.cc b/source/blender/gpu/vulkan/vk_index_buffer.cc index a96adb2af66..4242b9a7a57 100644 --- a/source/blender/gpu/vulkan/vk_index_buffer.cc +++ b/source/blender/gpu/vulkan/vk_index_buffer.cc @@ -45,9 +45,11 @@ void VKIndexBuffer::bind_as_ssbo(uint binding) VKContext &context = *VKContext::get(); VKShader *shader = static_cast(context.shader); const VKShaderInterface &shader_interface = shader->interface_get(); - const VKDescriptorSet::Location location = shader_interface.descriptor_set_location( - shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, binding); - shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, location); + const std::optional location = + shader_interface.descriptor_set_location( + shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, binding); + BLI_assert_msg(location, "Locations to SSBOs should always exist."); + shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, *location); } void VKIndexBuffer::read(uint32_t *data) const diff --git a/source/blender/gpu/vulkan/vk_shader_interface.cc b/source/blender/gpu/vulkan/vk_shader_interface.cc index ac0ba074bac..a8fd996442b 100644 --- a/source/blender/gpu/vulkan/vk_shader_interface.cc +++ b/source/blender/gpu/vulkan/vk_shader_interface.cc @@ -84,7 +84,7 @@ void VKShaderInterface::init(const shader::ShaderCreateInfo &info) /* Uniform blocks */ for (const ShaderCreateInfo::Resource &res : all_resources) { if (res.bind_type == ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER) { - copy_input_name(input, res.image.name, name_buffer_, name_buffer_offset); + copy_input_name(input, res.uniformbuf.name, name_buffer_, name_buffer_offset); input->location = input->binding = res.slot; input++; } @@ -196,11 +196,13 @@ const VKDescriptorSet::Location VKShaderInterface::descriptor_set_location( return descriptor_set_location(shader_input); } -const VKDescriptorSet::Location VKShaderInterface::descriptor_set_location( +const std::optional VKShaderInterface::descriptor_set_location( const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const { const ShaderInput *shader_input = shader_input_get(bind_type, binding); - BLI_assert(shader_input); + if (shader_input == nullptr) { + return std::nullopt; + } return descriptor_set_location(shader_input); } diff --git a/source/blender/gpu/vulkan/vk_shader_interface.hh b/source/blender/gpu/vulkan/vk_shader_interface.hh index 5f361f61092..d91437b635c 100644 --- a/source/blender/gpu/vulkan/vk_shader_interface.hh +++ b/source/blender/gpu/vulkan/vk_shader_interface.hh @@ -38,7 +38,7 @@ class VKShaderInterface : public ShaderInterface { const VKDescriptorSet::Location descriptor_set_location( const shader::ShaderCreateInfo::Resource &resource) const; - const VKDescriptorSet::Location descriptor_set_location( + const std::optional descriptor_set_location( const shader::ShaderCreateInfo::Resource::BindType &bind_type, int binding) const; /** Get the Layout of the shader. */ diff --git a/source/blender/gpu/vulkan/vk_storage_buffer.cc b/source/blender/gpu/vulkan/vk_storage_buffer.cc index 3e050e46479..5b141507e84 100644 --- a/source/blender/gpu/vulkan/vk_storage_buffer.cc +++ b/source/blender/gpu/vulkan/vk_storage_buffer.cc @@ -37,9 +37,11 @@ void VKStorageBuffer::bind(int slot) } VKShader *shader = static_cast(context.shader); const VKShaderInterface &shader_interface = shader->interface_get(); - const VKDescriptorSet::Location location = shader_interface.descriptor_set_location( - shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, slot); - shader->pipeline_get().descriptor_set_get().bind(*this, location); + const std::optional location = + shader_interface.descriptor_set_location( + shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, slot); + BLI_assert_msg(location, "Locations to SSBOs should always exist."); + shader->pipeline_get().descriptor_set_get().bind(*this, *location); } void VKStorageBuffer::unbind() {} diff --git a/source/blender/gpu/vulkan/vk_texture.cc b/source/blender/gpu/vulkan/vk_texture.cc index 7ed8a07f29b..75f3884bb00 100644 --- a/source/blender/gpu/vulkan/vk_texture.cc +++ b/source/blender/gpu/vulkan/vk_texture.cc @@ -312,9 +312,13 @@ void VKTexture::image_bind(int binding) VKContext &context = *VKContext::get(); VKShader *shader = static_cast(context.shader); const VKShaderInterface &shader_interface = shader->interface_get(); - const VKDescriptorSet::Location location = shader_interface.descriptor_set_location( - shader::ShaderCreateInfo::Resource::BindType::IMAGE, binding); - shader->pipeline_get().descriptor_set_get().image_bind(*this, location); + const std::optional location = + shader_interface.descriptor_set_location(shader::ShaderCreateInfo::Resource::BindType::IMAGE, + binding); + if (location) { + VKDescriptorSetTracker &descriptor_set = shader->pipeline_get().descriptor_set_get(); + descriptor_set.image_bind(*this, *location); + } } /* -------------------------------------------------------------------- */ diff --git a/source/blender/gpu/vulkan/vk_uniform_buffer.cc b/source/blender/gpu/vulkan/vk_uniform_buffer.cc index 4dd427d0649..8c39b3f16de 100644 --- a/source/blender/gpu/vulkan/vk_uniform_buffer.cc +++ b/source/blender/gpu/vulkan/vk_uniform_buffer.cc @@ -44,10 +44,12 @@ void VKUniformBuffer::bind(int slot, shader::ShaderCreateInfo::Resource::BindTyp VKContext &context = *VKContext::get(); VKShader *shader = static_cast(context.shader); const VKShaderInterface &shader_interface = shader->interface_get(); - const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(bind_type, - slot); - VKDescriptorSetTracker &descriptor_set = shader->pipeline_get().descriptor_set_get(); - descriptor_set.bind(*this, location); + const std::optional location = + shader_interface.descriptor_set_location(bind_type, slot); + if (location) { + VKDescriptorSetTracker &descriptor_set = shader->pipeline_get().descriptor_set_get(); + descriptor_set.bind(*this, *location); + } } void VKUniformBuffer::bind(int slot) diff --git a/source/blender/gpu/vulkan/vk_vertex_buffer.cc b/source/blender/gpu/vulkan/vk_vertex_buffer.cc index 1147df5f646..148e991b11a 100644 --- a/source/blender/gpu/vulkan/vk_vertex_buffer.cc +++ b/source/blender/gpu/vulkan/vk_vertex_buffer.cc @@ -27,9 +27,11 @@ void VKVertexBuffer::bind_as_ssbo(uint binding) VKContext &context = *VKContext::get(); VKShader *shader = static_cast(context.shader); const VKShaderInterface &shader_interface = shader->interface_get(); - const VKDescriptorSet::Location location = shader_interface.descriptor_set_location( - shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, binding); - shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, location); + const std::optional location = + shader_interface.descriptor_set_location( + shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER, binding); + BLI_assert_msg(location, "Locations to SSBOs should always exist."); + shader->pipeline_get().descriptor_set_get().bind_as_ssbo(*this, *location); } void VKVertexBuffer::bind_as_texture(uint /*binding*/) {}