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

◆ execute_shader()

void MayaFlux::Buffers::RenderProcessor::execute_shader ( const std::shared_ptr< VKBuffer > &  buffer)
overrideprotectedvirtual

Implements MayaFlux::Buffers::ShaderProcessor.

Definition at line 391 of file RenderProcessor.cpp.

392{
393 if (m_buffer_info.find(buffer) == m_buffer_info.end()) {
394 if (buffer->has_vertex_layout()) {
395 auto vertex_layout = buffer->get_vertex_layout();
396 if (vertex_layout.has_value()) {
397 m_buffer_info[buffer] = {
398 .semantic_layout = vertex_layout.value(),
399 .use_reflection = false
400 };
401 }
402 }
403 }
404
405 if (!m_target_window->is_graphics_registered()) {
406 return;
407 }
408
410 return;
411 }
412
413 const Kakshya::VertexLayout* local_layout = get_or_cache_vertex_layout(m_buffer_info, buffer);
414 if (!local_layout) {
416 "VKBuffer has no vertex layout set. Use buffer->set_vertex_layout()");
417 return;
418 }
419
420 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
421
422 auto& foundry = Portal::Graphics::get_shader_foundry();
424
425 vk::Format color_format = static_cast<vk::Format>(
427
428 auto cmd_id = foundry.begin_secondary_commands(color_format);
429 auto cmd = foundry.get_command_buffer(cmd_id);
430
431 uint32_t width = 0, height = 0;
433
434 if (width > 0 && height > 0) {
435 auto cmd = foundry.get_command_buffer(cmd_id);
436
437 vk::Viewport viewport {
438 0.0F,
439 static_cast<float>(height),
440 static_cast<float>(width),
441 -static_cast<float>(height),
442 0.0F,
443 1.0F
444 };
445 cmd.setViewport(0, 1, &viewport);
446
447 vk::Rect2D scissor { { 0, 0 }, { width, height } };
448 cmd.setScissor(0, 1, &scissor);
449 }
450
451 flow.bind_pipeline(cmd_id, m_pipeline_id);
452
453 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
454 if (!descriptor_bindings.empty()) {
455 for (const auto& binding : descriptor_bindings) {
456 if (binding.set >= m_descriptor_set_ids.size()) {
458 "Descriptor set index {} out of range", binding.set);
459 continue;
460 }
461
462 foundry.update_descriptor_buffer(
463 m_descriptor_set_ids[binding.set],
464 binding.binding,
465 binding.type,
466 binding.buffer_info.buffer,
467 binding.buffer_info.offset,
468 binding.buffer_info.range);
469 }
470 }
471
472 if (!m_descriptor_set_ids.empty()) {
473 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
474 }
475
476 if (m_view_transform_source || m_view_transform.has_value()) {
477 Kinesis::ViewTransform vt = m_view_transform_source
479 : m_view_transform.value();
480
481 auto& staging = buffer->get_pipeline_context().push_constant_staging;
482
483 if (!staging.empty()) {
484 if (staging.size() < sizeof(Kinesis::ViewTransform)) {
485 staging.resize(std::max(staging.size(), sizeof(Kinesis::ViewTransform)));
486 }
487 std::memcpy(staging.data(), &vt, sizeof(Kinesis::ViewTransform));
488 } else {
489 std::memcpy(m_push_constant_data.data(), &vt, sizeof(Kinesis::ViewTransform));
490 }
491 }
492
493 const auto& staging = buffer->get_pipeline_context();
494 if (!staging.push_constant_staging.empty()) {
495 flow.push_constants(
496 cmd_id,
498 staging.push_constant_staging.data(),
499 staging.push_constant_staging.size());
500 } else if (!m_push_constant_data.empty()) {
501 flow.push_constants(
502 cmd_id,
505 m_push_constant_data.size());
506 }
507
508 on_before_execute(cmd_id, buffer);
509
510 flow.bind_vertex_buffers(cmd_id, { buffer });
511
512 uint32_t draw_count = 0;
513 if (m_vertex_count > 0) {
514 draw_count = m_vertex_count;
515 } else {
516 auto current_layout = buffer->get_vertex_layout();
517 if (!current_layout.has_value() || current_layout->vertex_count == 0) {
519 "Vertex layout has zero vertices, skipping draw");
520 return;
521 }
522 draw_count = current_layout->vertex_count;
523 }
524
525 flow.draw(cmd_id, draw_count, 1, m_first_vertex, 0);
526
527 foundry.end_commands(cmd_id);
528
529 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
530 m_target_window->track_frame_command(cmd_id);
531
533 "Recorded secondary command buffer {} for window '{}'",
534 cmd_id, m_target_window->get_create_info().title);
535}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
#define MF_RT_DEBUG(comp, ctx,...)
std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > m_buffer_info
Registry::Service::DisplayService * m_display_service
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
std::function< Kinesis::ViewTransform()> m_view_transform_source
Portal::Graphics::RenderPipelineID m_pipeline_id
std::optional< Kinesis::ViewTransform > m_view_transform
const Kakshya::VertexLayout * get_or_cache_vertex_layout(std::unordered_map< std::shared_ptr< VKBuffer >, VertexInfo > &buffer_info, const std::shared_ptr< VKBuffer > &buffer)
std::shared_ptr< Core::Window > m_target_window
std::vector< uint8_t > m_push_constant_data
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
constexpr RenderPipelineID INVALID_RENDER_PIPELINE
MAYAFLUX_API RenderFlow & get_render_flow()
Get the global render flow instance.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
std::function< int(const std::shared_ptr< void > &)> get_swapchain_format
Get actual swapchain format for a window.
std::function< void(const std::shared_ptr< void > &, uint32_t &, uint32_t &)> get_swapchain_extent
Get swapchain extent for a window.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, get_or_cache_vertex_layout(), MayaFlux::Portal::Graphics::get_render_flow(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Registry::Service::DisplayService::get_swapchain_extent, MayaFlux::Registry::Service::DisplayService::get_swapchain_format, MayaFlux::Portal::Graphics::INVALID_RENDER_PIPELINE, m_buffer_info, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_display_service, m_first_vertex, m_pipeline_id, MayaFlux::Buffers::ShaderProcessor::m_push_constant_data, m_target_window, m_vertex_count, m_view_transform, m_view_transform_source, MF_RT_DEBUG, MF_RT_ERROR, MF_RT_TRACE, and on_before_execute().

+ Here is the call graph for this function: