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 121 of file RenderProcessor.cpp.

125{
126 if (!texture || !texture->is_initialized() || !texture->get_image_view()) {
128 "Cannot bind null texture to binding {}", binding);
129 return;
130 }
131
132 if (!sampler) {
134 sampler = loom.get_default_sampler();
135 }
136
137 m_texture_bindings[binding] = { .texture = texture, .sampler = sampler };
139
141
142 auto& foundry = Portal::Graphics::get_shader_foundry();
143 auto cfg_it = std::ranges::find_if(m_config.bindings,
144 [binding](const auto& pair) {
145 return binding >= pair.second.binding
146 && binding < pair.second.binding + pair.second.count;
147 });
148
149 if (cfg_it != m_config.bindings.end() && !m_descriptor_set_ids.empty()) {
150 const uint32_t cfg_set = cfg_it->second.set;
151 if (cfg_set == 0) {
153 uint32_t array_idx = 0;
154 if (cfg_it->second.count > 1 && binding >= cfg_it->second.binding) {
155 array_idx = binding - cfg_it->second.binding;
156 }
157 foundry.update_descriptor_image(
159 cfg_it->second.binding,
160 texture->get_image_view(),
161 sampler,
162 vk::ImageLayout::eShaderReadOnlyOptimal,
163 array_idx);
164 }
165 } else {
166 auto ds_index = resolve_ds_index(cfg_set);
167 if (ds_index && *ds_index < m_descriptor_set_ids.size()) {
168 foundry.update_descriptor_image(
169 m_descriptor_set_ids[*ds_index],
170 cfg_it->second.binding,
171 texture->get_image_view(),
172 sampler,
173 vk::ImageLayout::eShaderReadOnlyOptimal);
174 }
175 }
176 }
177 }
178
180 "Bound texture to binding {}", binding);
181}
#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: