MayaFlux 1.0.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 202 of file GpuResourceManager.cpp.

205{
206 if (const auto* existing = find_unit(key); existing && existing->ready)
207 return true;
208
209 auto& foundry = Portal::Graphics::get_shader_foundry();
210 auto& compute_press = Portal::Graphics::get_compute_press();
211
212 auto unit = std::make_unique<PipelineUnit>();
213
214 if (config.shader_id != Portal::Graphics::INVALID_SHADER) {
215 unit->shader_id = config.shader_id;
216 } else {
217 unit->shader_id = foundry.load_shader(config.shader_path);
218 }
219
220 if (unit->shader_id == Portal::Graphics::INVALID_SHADER) {
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;
232 if (is_image) {
233 by_set[b.set].push_back({
234 .set = b.set,
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;
245 if (!is_image) {
246 by_set[b.set].push_back({
247 .set = b.set,
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
262 if (unit->pipeline_id == Portal::Graphics::INVALID_COMPUTE_PIPELINE) {
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,...)
size_t b
glm::ivec3 max
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.
Definition TextEdit.cpp:20
bool is_image(const fs::path &filepath)
Definition Depot.cpp:136

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: