Create (or confirm existing) pipeline for the given key.
Create-if-absent: if a unit already exists and is ready for this key, returns true immediately without recreating anything. Call release(key) first to force recreation with a different config.
169{
171 return true;
172
175
176 auto unit = std::make_unique<PipelineUnit>();
177
179 unit->shader_id = config.shader_id;
180 } else {
181 unit->shader_id = foundry.load_shader(config.shader_path);
182 }
183
186 "GpuResourceManager: failed to load shader '{}' for key '{}'",
187 config.shader_path.empty() ? "<generated>" : config.shader_path, key);
188 return false;
189 }
190
191 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> by_set;
192 for (
const auto&
b : bindings) {
193 const auto et =
b.element_type;
197 by_set[
b.set].push_back({
199 .binding =
b.binding,
200 .type = element_type_to_vk(et),
201 });
202 }
203 }
204
205 for (
const auto&
b : bindings) {
206 const auto et =
b.element_type;
210 by_set[
b.set].push_back({
212 .binding =
b.binding,
213 .type = vk::DescriptorType::eStorageBuffer,
214 });
215 }
216 }
217
218 std::vector<std::vector<Portal::Graphics::DescriptorBindingInfo>> descriptor_sets;
219 descriptor_sets.reserve(by_set.size());
220 for (auto& [set_idx, set_bindings] : by_set)
221 descriptor_sets.push_back(
std::move(set_bindings));
222
223 unit->pipeline_id = compute_press.create_pipeline(
224 unit->shader_id, descriptor_sets, config.push_constant_size);
225
228 "GpuResourceManager: failed to create pipeline for key '{}'", key);
229 foundry.destroy_shader(unit->shader_id);
230 return false;
231 }
232
233 unit->descriptor_set_ids = compute_press.allocate_pipeline_descriptors(unit->pipeline_id);
234 if (unit->descriptor_set_ids.empty()) {
236 "GpuResourceManager: failed to allocate descriptor sets for key '{}'", key);
237 compute_press.destroy_pipeline(unit->pipeline_id);
238 foundry.destroy_shader(unit->shader_id);
239 return false;
240 }
241
242 unit->impl = std::make_unique<GpuResourceManagerImpl>();
243 size_t max_binding = 0;
244 for (
const auto&
b : bindings)
245 max_binding =
std::
max(max_binding, static_cast<size_t>(
b.binding));
246 const size_t capacity = bindings.empty() ? 0 : max_binding + 1;
247 unit->impl->buffers.resize(capacity);
248 unit->buffer_slots.resize(capacity);
249 unit->image_slots.resize(capacity);
250 unit->ready = true;
251
252 m_units[key] = std::move(unit);
253 return true;
254}
#define MF_ERROR(comp, ctx,...)
Cycle Behavior: The for_cycles(N) configuration controls how many times the capture operation execute...
std::unordered_map< std::string, std::unique_ptr< PipelineUnit > > m_units
const PipelineUnit * find_unit(const std::string &key) const
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
std::vector< double > max(std::span< const double > data, size_t n_windows, uint32_t hop_size, uint32_t window_size)
Maximum value per window.
constexpr ShaderID INVALID_SHADER
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr ComputePipelineID INVALID_COMPUTE_PIPELINE
MAYAFLUX_API ComputePress & get_compute_press()
bool is_image(const fs::path &filepath)