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

◆ fallback_renderer()

void MayaFlux::Buffers::PresentProcessor::fallback_renderer ( const std::shared_ptr< RootGraphicsBuffer > &  root)
private

Definition at line 201 of file RootGraphicsBuffer.cpp.

202{
203 const auto& renderable_buffers = root->get_renderable_buffers();
204 if (renderable_buffers.empty()) {
205 return;
206 }
207
208 std::unordered_map<Core::Window*, std::vector<const RootGraphicsBuffer::RenderableBufferInfo*>> buffers_by_window;
209 for (const auto& renderable : renderable_buffers) {
210 if (renderable.target_window && renderable.target_window->is_graphics_registered()
211 && renderable.command_buffer_id != Portal::Graphics::INVALID_COMMAND_BUFFER) {
212 buffers_by_window[renderable.target_window.get()].push_back(&renderable);
213 }
214 }
215
216 if (buffers_by_window.empty()) {
217 root->clear_renderable_buffers();
218 return;
219 }
220
222 "PresentProcessor submitting to {} windows", buffers_by_window.size());
223
224 auto& foundry = Portal::Graphics::get_shader_foundry();
226 auto display_service = Registry::BackendRegistry::instance()
227 .get_service<Registry::Service::DisplayService>();
228
229 if (!display_service) {
231 "DisplayService not available for dynamic rendering");
232 return;
233 }
234
235 for (const auto& [window_ptr, buffer_infos] : buffers_by_window) {
236 auto window = buffer_infos[0]->target_window;
237
238 uint64_t image_bits = display_service->acquire_next_swapchain_image(window);
239 if (image_bits == 0) {
241 "Failed to acquire swapchain image for window '{}'",
242 window->get_create_info().title);
243 continue;
244 }
245 vk::Image swapchain_image { reinterpret_cast<VkImage>(image_bits) };
246
247 auto primary_cmd_id = foundry.begin_commands(Portal::Graphics::ShaderFoundry::CommandBufferType::GRAPHICS);
248 auto primary_cmd = foundry.get_command_buffer(primary_cmd_id);
249
250 if (!primary_cmd) {
252 "Failed to create primary command buffer for window '{}'",
253 window->get_create_info().title);
254 for (const auto* info : buffer_infos) {
255 info->buffer->clear_pipeline_commands();
256 }
257 continue;
258 }
259
260 try {
261 bool window_needs_depth = false;
262 for (const auto* info : buffer_infos) {
263 if (info->needs_depth) {
264 window_needs_depth = true;
265 break;
266 }
267 }
268
269 vk::ImageView depth_view = nullptr;
270 if (window_needs_depth) {
271 display_service->ensure_depth_attachment(window);
272 auto* view_ptr = display_service->get_depth_image_view(window);
273 if (view_ptr) {
274 depth_view = *static_cast<vk::ImageView*>(view_ptr);
275 }
276 }
277
278 flow.begin_rendering(primary_cmd_id, window, swapchain_image,
280
281 std::vector<vk::CommandBuffer> secondary_buffers;
282 for (const auto* info : buffer_infos) {
283 auto secondary = foundry.get_command_buffer(info->command_buffer_id);
284 if (secondary) {
285 secondary_buffers.push_back(secondary);
286 }
287 }
288
289 if (!secondary_buffers.empty()) {
290 primary_cmd.executeCommands(secondary_buffers);
291 }
292
293 flow.end_rendering(primary_cmd_id, window);
294
295 foundry.end_commands(primary_cmd_id);
296 uint64_t primary_bits = *reinterpret_cast<uint64_t*>(&primary_cmd);
297 display_service->submit_and_present(window, primary_bits);
298
300 "Presented {} buffers to window '{}'",
301 secondary_buffers.size(), window->get_create_info().title);
302
303 } catch (const std::exception& e) {
305 "Failed to submit/present for window '{}': {}",
306 window->get_create_info().title,
307 e.what());
308 }
309
310 for (const auto* info : buffer_infos) {
311 info->buffer->clear_pipeline_commands();
312 }
313 }
314
315 root->clear_renderable_buffers();
316}
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
const std::array< float, 4 > default_color
MAYAFLUX_API RenderFlow & get_render_flow()
Get the global render flow instance.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr CommandBufferID INVALID_COMMAND_BUFFER

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Portal::Graphics::default_color, MayaFlux::Portal::Graphics::get_render_flow(), MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::ShaderFoundry::GRAPHICS, MayaFlux::Registry::BackendRegistry::instance(), MayaFlux::Portal::Graphics::INVALID_COMMAND_BUFFER, MF_RT_DEBUG, MF_RT_ERROR, and MF_RT_WARN.

Referenced by processing_function().

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