MayaFlux 0.4.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 139 of file RenderProcessor.cpp.

143{
144 if (!texture || !texture->is_initialized() || !texture->get_image_view()) {
146 "Cannot bind null texture to binding {}", binding);
147 return;
148 }
149
150 if (!sampler) {
152 sampler = loom.get_default_sampler();
153 }
154
155 m_texture_bindings[binding] = { .texture = texture, .sampler = sampler };
157
159
160 auto& foundry = Portal::Graphics::get_shader_foundry();
161 auto cfg_it = std::ranges::find_if(m_config.bindings,
162 [binding](const auto& pair) {
163 return binding >= pair.second.binding
164 && binding < pair.second.binding + pair.second.count;
165 });
166
167 if (cfg_it != m_config.bindings.end() && !m_descriptor_set_ids.empty()) {
168 const uint32_t cfg_set = cfg_it->second.set;
169 if (cfg_set == 0) {
171 uint32_t array_idx = 0;
172 if (cfg_it->second.count > 1 && binding >= cfg_it->second.binding) {
173 array_idx = binding - cfg_it->second.binding;
174 }
175 foundry.update_descriptor_image(
177 cfg_it->second.binding,
178 texture->get_image_view(),
179 sampler,
180 vk::ImageLayout::eShaderReadOnlyOptimal,
181 array_idx);
182 }
183 } else {
184 auto ds_index = resolve_ds_index(cfg_set);
185 if (ds_index && *ds_index < m_descriptor_set_ids.size()) {
186 foundry.update_descriptor_image(
187 m_descriptor_set_ids[*ds_index],
188 cfg_it->second.binding,
189 texture->get_image_view(),
190 sampler,
191 vk::ImageLayout::eShaderReadOnlyOptimal);
192 }
193 }
194 }
195 }
196
198 "Bound texture to binding {}", binding);
199}
#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: