MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ bind_texture() [2/2]

void MayaFlux::Buffers::RenderProcessor::bind_texture ( uint32_t  binding,
const std::shared_ptr< Core::VKImage > &  texture,
vk::Sampler  sampler = nullptr 
)

Bind a texture to a descriptor binding point.

Parameters
bindingBinding index (matches shader layout(binding = N))
textureVKImage texture to bind
samplerOptional sampler (uses default linear if null)

Definition at line 145 of file RenderProcessor.cpp.

149{
150 if (!texture || !texture->is_initialized() || !texture->get_image_view()) {
152 "Cannot bind null texture to binding {}", binding);
153 return;
154 }
155
156 if (!sampler) {
158 sampler = loom.get_default_sampler();
159 }
160
161 m_texture_bindings[binding] = { .texture = texture, .sampler = sampler };
163
165
166 auto& foundry = Portal::Graphics::get_shader_foundry();
167 auto cfg_it = std::ranges::find_if(m_config.bindings,
168 [binding](const auto& pair) {
169 return binding >= pair.second.binding
170 && binding < pair.second.binding + pair.second.count;
171 });
172
173 if (cfg_it != m_config.bindings.end() && !m_descriptor_set_ids.empty()) {
174 const uint32_t cfg_set = cfg_it->second.set;
175 if (cfg_set == 0) {
177 uint32_t array_idx = 0;
178 if (cfg_it->second.count > 1 && binding >= cfg_it->second.binding) {
179 array_idx = binding - cfg_it->second.binding;
180 }
181 foundry.update_descriptor_image(
183 cfg_it->second.binding,
184 texture->get_image_view(),
185 sampler,
186 vk::ImageLayout::eShaderReadOnlyOptimal,
187 array_idx);
188 }
189 } else {
190 auto ds_index = resolve_ds_index(cfg_set);
191 if (ds_index && *ds_index < m_descriptor_set_ids.size()) {
192 foundry.update_descriptor_image(
193 m_descriptor_set_ids[*ds_index],
194 cfg_it->second.binding,
195 texture->get_image_view(),
196 sampler,
197 vk::ImageLayout::eShaderReadOnlyOptimal);
198 }
199 }
200 }
201 }
202
204 "Bound texture to binding {}", binding);
205}
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Portal::Graphics::DescriptorSetID m_view_transform_descriptor_set_id
Portal::Graphics::RenderPipelineID m_pipeline_id
std::unordered_map< uint32_t, TextureBinding > m_texture_bindings
std::optional< uint32_t > resolve_ds_index(uint32_t set) const
Resolve logical descriptor set index to actual index.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
MAYAFLUX_API TextureLoom & get_texture_manager()
Get the global texture manager instance.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr DescriptorSetID INVALID_DESCRIPTOR_SET
std::unordered_map< std::string, ShaderBinding > bindings

References MayaFlux::Buffers::ShaderConfig::bindings, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::get_texture_manager(), MayaFlux::Portal::Graphics::INVALID_DESCRIPTOR_SET, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, MayaFlux::Buffers::ShaderProcessor::m_config, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, MayaFlux::Buffers::ShaderProcessor::m_needs_descriptor_rebuild, m_pipeline_id, m_texture_bindings, m_view_transform_descriptor_set_id, MF_DEBUG, MF_ERROR, and MayaFlux::Buffers::ShaderProcessor::resolve_ds_index().

Referenced by bind_texture().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: