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

◆ record_draw() [2/2]

void MayaFlux::Buffers::RenderProcessor::record_draw ( const std::shared_ptr< VKBuffer > &  buffer,
const BufferState &  state 
)
private

Record an already validated attachment without repeating its lookup.

Definition at line 828 of file RenderProcessor.cpp.

829{
830 buffer->set_pipeline_window(m_pipeline_id, m_target_window);
831
832 auto& foundry = Portal::Graphics::get_shader_foundry();
834
835 vk::Format color_format = static_cast<vk::Format>(
837
838 vk::Format depth_format = m_depth_enabled
839 ? vk::Format::eD32Sfloat
840 : vk::Format::eUndefined;
841
842 auto cmd_id = foundry.begin_secondary_commands(color_format, depth_format);
843 auto cmd = foundry.get_command_buffer(cmd_id);
844
845 uint32_t width = 0, height = 0;
847
848 if (width > 0 && height > 0) {
849 auto cmd = foundry.get_command_buffer(cmd_id);
850
851 vk::Viewport viewport {
852 0.0F,
853 static_cast<float>(height),
854 static_cast<float>(width),
855 -static_cast<float>(height),
856 0.0F,
857 1.0F
858 };
859 cmd.setViewport(0, 1, &viewport);
860
861 const vk::Rect2D scissor = resolve_scissor_rect(width, height);
862 cmd.setScissor(0, 1, &scissor);
863 }
864
865 flow.bind_pipeline(cmd_id, m_pipeline_id);
866
867 auto& engine_bindings = buffer->get_engine_context().ssbo_bindings;
868 for (const auto& binding : engine_bindings) {
869 if (binding.set == 0 && binding.binding == 0) {
871 "Engine SSBO at binding=0 is reserved for RenderTransform UBO");
872 continue;
873 }
876 "Engine SSBO binding {} skipped: engine descriptor set not allocated", binding.binding);
877 continue;
878 }
879 foundry.update_descriptor_buffer(
881 binding.binding,
882 binding.type,
883 binding.buffer_info.buffer,
884 binding.buffer_info.offset,
885 binding.buffer_info.range);
886 }
887
888 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
889 if (!descriptor_bindings.empty()) {
890 for (const auto& binding : descriptor_bindings) {
891 auto ds_index = resolve_ds_index(binding.set);
892 if (!ds_index) {
894 "Descriptor set index {} out of range or reserved", binding.set);
895 continue;
896 }
897
898 foundry.update_descriptor_buffer(
899 m_descriptor_set_ids[*ds_index],
900 binding.binding,
901 binding.type,
902 binding.buffer_info.buffer,
903 binding.buffer_info.offset,
904 binding.buffer_info.range);
905 }
906 }
907
908 if (!m_descriptor_set_ids.empty()) {
909 flow.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
910 }
911
913 flow.bind_descriptor_sets(
914 cmd_id, m_pipeline_id,
916 0);
917 }
918
919 if (!m_descriptor_set_ids.empty()) {
920 flow.bind_descriptor_sets(
921 cmd_id, m_pipeline_id,
923 1);
924 }
925
926 const auto push_data = resolve_push_constants(buffer);
927 if (!push_data.empty()) {
928 flow.push_constants(
929 cmd_id, m_pipeline_id, push_data.data(), push_data.size());
930 }
931
932 on_before_execute(cmd_id, buffer);
933
934 flow.bind_vertex_buffers(cmd_id, { state.draw_source });
935
936 if (state.vertex_count > 0) {
937 if (state.draw_source->has_index_buffer()) {
938 flow.bind_index_buffer(cmd_id, state.draw_source);
939 flow.draw_indexed(cmd_id, state.index_count, m_instance_count, 0, 0, 0);
940 } else if (!m_triangulate && m_runs.size() > 1
941 && std::ranges::all_of(m_runs, [this](const Portal::Graphics::DrawRun& run) {
942 return run.topology == m_primitive_topology;
943 })) {
944 for (const auto& run : m_runs) {
945 if (run.vertex_count > 0) {
946 flow.draw(cmd_id, run.vertex_count, m_instance_count, run.vertex_offset, 0);
947 }
948 }
949 } else {
950 flow.draw(cmd_id, state.vertex_count, m_instance_count, state.first_vertex, 0);
951 }
952 }
953
954 foundry.end_commands(cmd_id);
955
956 buffer->set_pipeline_command(m_pipeline_id, cmd_id);
957 m_target_window->track_frame_command(cmd_id);
958
960 "Recorded secondary command buffer {} for window '{}'",
961 cmd_id, m_target_window->get_create_info().title);
962}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
vk::CommandBuffer cmd
std::shared_ptr< NetworkGeometryBuffer > buffer
uint32_t width
uint32_t height
Registry::Service::DisplayService * m_display_service
std::vector< Portal::Graphics::DrawRun > m_runs
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Called before each process callback.
vk::Rect2D resolve_scissor_rect(uint32_t width, uint32_t height) const noexcept
Resolve the active scissor against a live framebuffer size.
Portal::Graphics::RenderPipelineID m_pipeline_id
Portal::Graphics::DescriptorSetID m_render_transform_descriptor_set_id
std::shared_ptr< Core::Window > m_target_window
std::optional< uint32_t > resolve_ds_index(uint32_t set) const
Resolve logical descriptor set index to actual index.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
std::vector< uint8_t > resolve_push_constants(const std::shared_ptr< VKBuffer > &buffer) const
This processor's push constant data with buffer-staged fragments overlaid at their declared offsets.
void run()
Definition main.cpp:21
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
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 DescriptorSetID INVALID_DESCRIPTOR_SET
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 buffer, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, cmd, MayaFlux::Buffers::RenderProcessor::BufferState::draw_source, MayaFlux::Buffers::RenderProcessor::BufferState::first_vertex, MayaFlux::Portal::Graphics::get_render_flow(), MayaFlux::Portal::Graphics::get_shader_foundry(), height, MayaFlux::Buffers::RenderProcessor::BufferState::index_count, MayaFlux::Portal::Graphics::INVALID_DESCRIPTOR_SET, MF_RT_ERROR, MF_RT_TRACE, run(), MayaFlux::Buffers::RenderProcessor::BufferState::vertex_count, and width.

+ Here is the call graph for this function: