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.
205{
207 return true;
208
211
212 auto unit = std::make_unique<PipelineUnit>();
213
215 unit->shader_id = config.shader_id;
216 } else {
217 unit->shader_id = foundry.load_shader(config.shader_path);
218 }
219
222 "GpuResourceManager: failed to load shader '{}' for key '{}'",
223 config.shader_path.empty() ? "<generated>" : config.shader_path, key);
224 return false;
225 }
226
227 std::map<uint32_t, std::vector<Portal::Graphics::DescriptorBindingInfo>> by_set;
228 for (
const auto&
b : bindings) {
229 const auto et =
b.element_type;
233 by_set[
b.set].push_back({
235 .binding =
b.binding,
236 .type = element_type_to_vk(et),
237 });
238 }
239 }
240
241 for (
const auto&
b : bindings) {
242 const auto et =
b.element_type;
246 by_set[
b.set].push_back({
248 .binding =
b.binding,
249 .type = vk::DescriptorType::eStorageBuffer,
250 });
251 }
252 }
253
254 std::vector<std::vector<Portal::Graphics::DescriptorBindingInfo>> descriptor_sets;
255 descriptor_sets.reserve(by_set.size());
256 for (auto& [set_idx, set_bindings] : by_set)
257 descriptor_sets.push_back(
std::
move(set_bindings));
258
259 unit->pipeline_id = compute_press.create_pipeline(
260 unit->shader_id, descriptor_sets, config.push_constant_size);
261
264 "GpuResourceManager: failed to create pipeline for key '{}'", key);
265 foundry.destroy_shader(unit->shader_id);
266 return false;
267 }
268
269 unit->descriptor_set_ids = compute_press.allocate_pipeline_descriptors(unit->pipeline_id);
270 if (unit->descriptor_set_ids.empty()) {
272 "GpuResourceManager: failed to allocate descriptor sets for key '{}'", key);
273 compute_press.destroy_pipeline(unit->pipeline_id);
274 foundry.destroy_shader(unit->shader_id);
275 return false;
276 }
277
278 unit->impl = std::make_unique<GpuResourceManagerImpl>();
279 size_t max_binding = 0;
280 for (
const auto&
b : bindings)
281 max_binding =
std::
max(max_binding, static_cast<size_t>(
b.binding));
282 const size_t capacity = bindings.empty() ? 0 : max_binding + 1;
283 unit->impl->buffers.resize(capacity);
284 unit->buffer_slots.resize(capacity);
285 unit->image_slots.resize(capacity);
286 unit->ready = true;
287
288 m_units[key] = std::move(unit);
289 return true;
290}
#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.
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()
void move(EditableText &s, int n)
Move the cursor by n codepoints.
bool is_image(const fs::path &filepath)