Does not wait on its own dispatch. It resolves the previous call's submission, submits this one and returns. output() can be recorded against immediately, but it is not valid to read from the host until a later mill() or release() has resolved the fence.
Runs on the graphics queue, so a draw submitted afterwards is ordered after the write. The destination grows to fit and never shrinks.
667{
669
671
672 if (!source || runs.empty()) {
673 return 0;
674 }
675
676 if (!layout)
677 layout =
source->get_vertex_layout();
678 if (!layout.has_value()) {
679 return 0;
680 }
681
682 MillOffsets off;
683 if (!offsets_from(*layout, off)) {
685 "PrimitiveMill: layout is not millable, stride {} needs word alignment "
686 "and an addressable position attribute",
687 layout->stride_bytes);
688 return 0;
689 }
690
691 const bool indexed =
source->has_index_buffer();
692 const auto index_count =
static_cast<uint32_t
>(
source->get_index_buffer_size() /
sizeof(uint32_t));
693 const uint32_t source_vertices = layout->vertex_count;
694 for (
const auto&
run : runs) {
695 if (
run.vertex_count == 0) {
696 continue;
697 }
698 const bool by_index = indexed && is_triangle_topology(
run.topology);
699 const uint32_t limit = by_index ? index_count : source_vertices;
700 if (
run.vertex_offset > limit
701 ||
run.vertex_count > limit -
run.vertex_offset) {
703 "PrimitiveMill: run [{}, {}) exceeds the source's {} {}",
704 run.vertex_offset,
run.vertex_offset +
run.vertex_count, limit,
705 by_index ? "indices" : "vertices");
706 return 0;
707 }
708 }
709
711 const uint32_t total =
m_prefix.back();
712 if (total == 0) {
713 return 0;
714 }
715
717 return 0;
718 }
719
721
724
725 for (size_t r = 0; r < runs.size(); ++r) {
728 const bool emulated = is_triangle_topology(runs[r].topology)
731 const uint32_t fill_code = !emulated ? 0
U : (runs[r].fill ==
PolygonMode::POINT ? 1U : 2U);
732 run_ptr[r * RUN_WORDS + 0] = static_cast<uint32_t>(runs[r].topology) | (fill_code << 8U);
733 run_ptr[r * RUN_WORDS + 1] = runs[r].vertex_offset;
734 run_ptr[r * RUN_WORDS + 2] = runs[r].vertex_count;
735 }
736
741
742 const bool billboard =
m_spec.billboard_instances
744 && off.tangent != ABSENT;
745 if (
m_spec.billboard_instances && off.tangent == ABSENT) {
747 "PrimitiveMill: billboard_instances needs a tangent attribute in the vertex layout");
748 }
749
750 const auto pc = make_pc(
m_spec, view, off, total, runs.size(), indexed, billboard);
751
754
756
758
759 foundry.buffer_barrier(
760 cmd_id,
761 destination,
762 vk::AccessFlagBits2::eVertexAttributeRead,
763 vk::AccessFlagBits2::eShaderWrite,
764 vk::PipelineStageFlagBits2::eVertexInput,
765 vk::PipelineStageFlagBits2::eComputeShader);
766
767 const auto storage_write = [](uint32_t binding, const std::shared_ptr<VKBuffer>& buf) {
768 PushDescriptorWrite write;
769 write.binding = binding;
770 write.type = vk::DescriptorType::eStorageBuffer;
771 write.buffer = vk::DescriptorBufferInfo { buf->get_buffer(), 0, buf->get_size_bytes() };
772 return write;
773 };
774
775 const auto slot_write = [](uint32_t binding, const vk::DescriptorBufferInfo& info) {
776 PushDescriptorWrite write;
777 write.binding = binding;
778 write.type = vk::DescriptorType::eStorageBuffer;
779 write.buffer = info;
780 return write;
781 };
782
784 PushDescriptorWrite index_write = slot_write(4, run_info);
785 if (indexed) {
786 index_write.buffer = vk::DescriptorBufferInfo {
787 source->get_index_buffer(), 0,
source->get_index_buffer_size()
788 };
789 }
790
791 const std::array<SlotLease, 2> leases {
793 };
794
797 storage_write(0, source),
798 slot_write(1, run_info),
801 index_write,
802 },
803 leases);
805 press.dispatch(cmd_id, (total + WORKGROUP - 1) / WORKGROUP, 1, 1);
806
807 foundry.buffer_barrier(
808 cmd_id,
809 destination,
810 vk::AccessFlagBits2::eShaderWrite,
811 vk::AccessFlagBits2::eVertexAttributeRead,
812 vk::PipelineStageFlagBits2::eComputeShader,
813 vk::PipelineStageFlagBits2::eVertexInput);
814
815 const FenceID fence = foundry.submit_async(cmd_id);
818 "PrimitiveMill: dispatch submission failed");
819 return 0;
820 }
821
823
825
827 "PrimitiveMill: milled {} runs into {} vertices", runs.size(), total);
828
829 return total;
830}
#define MF_RT_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
std::unique_ptr< SlotArena > m_prefix_arena
std::vector< uint32_t > m_prefix
bool ensure_buffers(const std::shared_ptr< Buffers::VKBuffer > &source, const Kakshya::VertexLayout &layout, uint32_t total, size_t run_count)
Grows the destination ring, run and prefix arenas to fit.
void collect_completed()
Reclaim every dispatch that has finished, without waiting.
std::unique_ptr< SlotArena > m_run_arena
bool ensure_kernel()
Compiles the kernel and creates its pipeline with a push descriptor set, once.
std::vector< std::shared_ptr< Buffers::VKBuffer > > m_outputs
Milled buffers rotated between dispatches, all at m_output_capacity.
ComputePipelineID m_pipeline
std::vector< FenceID > m_in_flight
Dispatches submitted and not yet observed complete, oldest first.
std::vector< uint32_t > m_run_words
@ Rendering
GPU rendering operations (graphics pipeline, frame rendering).
@ Portal
High-level user-facing API layer.
PolygonMode
Rasterization polygon mode.
constexpr FenceID INVALID_FENCE
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
MAYAFLUX_API ComputePress & get_compute_press()
std::shared_ptr< Buffers::TextBuffer > press(std::string_view text, const PressParams ¶ms)
Composite a UTF-8 string into a new TextBuffer.
@ WorldFacing
Turned to face the viewpoint, in world space.