| 1799 | } |
| 1800 | |
| 1801 | void TaskGraph::add_task( |
| 1802 | void (*task_callback)(daxa::TaskInterface, void *), |
| 1803 | u64 * task_callback_memory, |
| 1804 | std::span<TaskAttachmentInfo> attachments, |
| 1805 | u32 attachment_shader_blob_size, |
| 1806 | u32 attachment_shader_blob_alignment, |
| 1807 | TaskType task_type, |
| 1808 | std::string_view name, |
| 1809 | Queue queue) |
| 1810 | { |
| 1811 | auto & impl = *reinterpret_cast<ImplTaskGraph *>(this->object); |
| 1812 | validate_not_compiled(impl); |
| 1813 | |
| 1814 | /// ============================ |
| 1815 | /// ==== CREATE UNIQUE NAME ==== |
| 1816 | /// ============================ |
| 1817 | |
| 1818 | static constexpr u64 DUP_TEXT_CHARS = 3; |
| 1819 | static constexpr u64 DUP_NUMBER_CHARS = 4; |
| 1820 | static constexpr u64 NAME_BUFFER_SIZE = 256; |
| 1821 | DAXA_DBG_ASSERT_TRUE_M(name.size() < (NAME_BUFFER_SIZE - (DUP_TEXT_CHARS + DUP_NUMBER_CHARS)), "IMPOSSIBLE CASE, Bump Buffer Size!"); |
| 1822 | std::array<char, NAME_BUFFER_SIZE> name_buffer = {}; |
| 1823 | u64 name_buffer_used_size = name.size(); |
| 1824 | std::memcpy(name_buffer.data(), name.data(), name.size()); |
| 1825 | if (impl.name_to_task_table.contains(name)) |
| 1826 | { |
| 1827 | u32 & occurances = std::get<2>(impl.name_to_task_table[name]); |
| 1828 | occurances += 1; // Increment collision counter |
| 1829 | |
| 1830 | DAXA_DBG_ASSERT_TRUE_M(occurances < ((1 << DUP_NUMBER_CHARS) - 1), "IMPOSSIBLE CASE, Bump Buffer Size!"); |
| 1831 | name_buffer_used_size = name_buffer_used_size + std::format_to_n(name_buffer.data() + name_buffer_used_size, (DUP_TEXT_CHARS + DUP_NUMBER_CHARS), " ({})", occurances).size; |
| 1832 | } |
| 1833 | name = impl.task_memory.allocate_copy_string(std::string_view{name_buffer.data(), name_buffer_used_size}); |
| 1834 | |
| 1835 | /// ========================================== |
| 1836 | /// ==== CONSTRUCT AND ALLOCATE TASK DATA ==== |
| 1837 | /// ========================================== |
| 1838 | |
| 1839 | queue = queue == QUEUE_NONE ? impl.info.default_queue : queue; |
| 1840 | |
| 1841 | std::span<std::span<ImageViewId>> attachment_image_views = impl.task_memory.allocate_trivial_span<std::span<ImageViewId>>(attachments.size()); |
| 1842 | for (u32 attach_i = 0u; attach_i < attachments.size(); ++attach_i) |
| 1843 | { |
| 1844 | if (attachments[attach_i].type == TaskAttachmentType::IMAGE) |
| 1845 | { |
| 1846 | TaskImageAttachmentInfo const & attachment_info = attachments[attach_i].value.image; |
| 1847 | attachment_image_views[attach_i] = impl.task_memory.allocate_trivial_span<ImageViewId>(std::max(1u, static_cast<u32>(attachment_info.shader_array_size))); |
| 1848 | } |
| 1849 | else |
| 1850 | { |
| 1851 | attachment_image_views[attach_i] = std::span<ImageViewId>{}; |
| 1852 | } |
| 1853 | } |
| 1854 | |
| 1855 | ImplTask impl_task = ImplTask{ |
| 1856 | .name = name, |
| 1857 | .task_callback = task_callback, |
| 1858 | .task_callback_memory = task_callback_memory, |