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

◆ initialise()

bool MayaFlux::Yantra::GpuResourceManager::initialise ( const std::string &  key,
const GpuComputeConfig config,
const std::vector< GpuBufferBinding > &  bindings 
)

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.

Definition at line 166 of file GpuResourceManager.cpp.

169{
170 if (const auto* existing = find_unit(key); existing && existing->ready)
171 return true;
172
173 auto& foundry = Portal::Graphics::get_shader_foundry();
174 auto& compute_press = Portal::Graphics::get_compute_press();
175
176 auto unit = std::make_unique<PipelineUnit>();
177
178 if (config.shader_id != Portal::Graphics::INVALID_SHADER) {
179 unit->shader_id = config.shader_id;
180 } else {
181 unit->shader_id = foundry.load_shader(config.shader_path);
182 }
183
184 if (unit->shader_id == Portal::Graphics::INVALID_SHADER) {
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;
196 if (is_image) {
197 by_set[b.set].push_back({
198 .set = b.set,
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;
209 if (!is_image) {
210 by_set[b.set].push_back({
211 .set = b.set,
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
226 if (unit->pipeline_id == Portal::Graphics::INVALID_COMPUTE_PIPELINE) {
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,...)
size_t b
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.
Definition Analysis.cpp:436
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)
Definition Depot.cpp:108

References b, MayaFlux::Journal::BufferProcessing, find_unit(), MayaFlux::Portal::Graphics::get_compute_press(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_SAMPLED, MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_STORAGE, MayaFlux::Portal::Graphics::INVALID_COMPUTE_PIPELINE, MayaFlux::Portal::Graphics::INVALID_SHADER, MayaFlux::is_image(), m_units, MF_ERROR, MayaFlux::Portal::Graphics::GpuComputeConfig::push_constant_size, MayaFlux::Portal::Graphics::GpuComputeConfig::shader_id, MayaFlux::Portal::Graphics::GpuComputeConfig::shader_path, and MayaFlux::Journal::Yantra.

Referenced by MayaFlux::Yantra::GpuDispatchCore::ensure_gpu_ready().

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