14struct MilledMeshNetworkVertex {
20static_assert(
sizeof(MilledMeshNetworkVertex) ==
sizeof(Kakshya::MeshVertex) + 2 *
sizeof(float));
22Kakshya::VertexLayout milled_mesh_network_layout()
25 layout.attributes.push_back({
27 .offset_in_vertex =
static_cast<uint32_t
>(
sizeof(Kakshya::MeshVertex)),
28 .name =
"slot_index_low"
30 layout.attributes.push_back({
32 .offset_in_vertex =
static_cast<uint32_t
>(
sizeof(Kakshya::MeshVertex) +
sizeof(
float)),
33 .
name =
"slot_index_high"
41 std::shared_ptr<Nodes::Network::MeshNetwork>
network)
66 "MeshNetworkProcessor attached to empty network");
70 auto vk_buf = std::dynamic_pointer_cast<VKBuffer>(
buffer);
73 "MeshNetworkProcessor: attached buffer is not a VKBuffer");
92 "MeshNetworkProcessor: initialised — {} slots, {} bytes vertex, {} indices",
124 auto vk_buf = std::dynamic_pointer_cast<VKBuffer>(
buffer);
143 "MeshNetworkProcessor: re-uploaded {} bytes vertex, {} indices",
152 const std::shared_ptr<VKBuffer>& vertex_buf)
157 if (v_bytes == 0 || i_bytes == 0) {
159 "MeshNetworkProcessor::allocate_gpu_buffers: network has no geometry");
163 if (!vertex_buf->is_host_visible())
172 "MeshNetworkProcessor: allocated vertex ({} bytes) + index ({} bytes)",
177 const std::shared_ptr<VKBuffer>& vertex_buf)
180 const auto& order =
m_network->sorted_indices();
187 uint32_t running_vertex_count = 0;
189 for (uint32_t idx : order) {
190 const auto& slot = slots[idx];
194 const auto& verts = slot.node->get_mesh_vertices();
195 const auto&
indices = slot.node->get_mesh_indices();
199 const float slot_low =
static_cast<float>(slot_id & 0xFFFFU);
200 const float slot_high =
static_cast<float>(slot_id >> 16U);
201 for (
const auto& vertex : verts) {
203 const auto* bytes =
reinterpret_cast<const uint8_t*
>(&packed);
209 const auto* v_src =
reinterpret_cast<const uint8_t*
>(verts.data());
218 const auto sorted_slot_pos =
static_cast<uint32_t
>(
m_model_aggregate.size() - 1);
222 running_vertex_count +=
static_cast<uint32_t
>(verts.size());
229 if (v_required > vertex_buf->get_size_bytes()) {
230 const auto new_size =
static_cast<size_t>(
231 static_cast<float>(v_required) * 1.5F);
232 vertex_buf->resize(new_size,
false);
247 const auto new_size =
static_cast<size_t>(
248 static_cast<float>(i_required) * 1.5F);
263 auto layout = milled_mesh_network_layout();
264 layout.vertex_count = running_vertex_count;
265 vertex_buf->set_vertex_layout(layout);
266 }
else for (uint32_t idx : order) {
267 const auto& slot = slots[idx];
268 if (slot.node && slot.node->get_mesh_vertex_count() > 0) {
269 if (
auto layout = slot.node->get_vertex_layout()) {
270 layout->vertex_count = running_vertex_count;
271 vertex_buf->set_vertex_layout(*layout);
279 const std::shared_ptr<VKBuffer>& vertex_buf)
284 vertex_buf->set_index_resources(
292 return std::ranges::any_of(
m_network->slots(), [](
const auto& slot) {
293 return slot.dirty || (slot.node && slot.node->needs_gpu_update());
302 slot.node->clear_gpu_update_flag();
309 for (
const auto& slot :
m_network->slots()) {
313 total += slot.node->get_mesh_vertex_count() * stride;
322 for (
const auto& slot :
m_network->slots()) {
324 total += slot.node->get_mesh_indices().size();
334 if (model_bytes == 0 || slot_index_bytes == 0) {
341 m_model_arena = std::make_shared<Portal::Graphics::SlotArena>();
377 auto& bindings =
buffer->get_engine_context().ssbo_bindings;
379 auto push = [&](uint32_t binding_idx,
const std::shared_ptr<Portal::Graphics::SlotArena>& arena,
size_t slot) {
383 info.
type = vk::DescriptorType::eStorageBuffer;
388 auto it = std::ranges::find_if(bindings, [&](
const auto&
b) {
391 if (it != bindings.end()) {
394 bindings.push_back(info);
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_RT_TRACE(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Core::GlobalNetworkConfig network
std::vector< uint32_t > indices
std::shared_ptr< NetworkGeometryBuffer > buffer
ProcessingToken m_processing_token
bool m_milling_slot_attribute
std::shared_ptr< Portal::Graphics::SlotArena > m_model_arena
Per-slot world matrices in sorted_indices order. One mat4 per slot.
size_t total_vertex_bytes() const
std::vector< uint32_t > m_slot_index_aggregate
CPU-side scratch for per-vertex slot indices, reused each cycle.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
std::vector< uint8_t > m_vertex_aggregate
Aggregate scratch buffers reused each cycle to avoid allocation.
std::shared_ptr< VKBuffer > m_index_staging
void link_index_resources(const std::shared_ptr< VKBuffer > &vertex_buf)
void upload_combined(const std::shared_ptr< VKBuffer > &vertex_buf)
void clear_slot_dirty_flags()
std::vector< uint32_t > m_index_aggregate
MeshNetworkProcessor(std::shared_ptr< Nodes::Network::MeshNetwork > network)
size_t total_index_count() const
bool any_slot_dirty() const
void allocate_gpu_buffers(const std::shared_ptr< VKBuffer > &vertex_buf)
std::shared_ptr< VKBuffer > m_vertex_staging
void set_milling_slot_attribute(bool enabled)
void allocate_ssbo_buffers()
std::shared_ptr< VKBuffer > m_gpu_index_buffer
void push_ssbo_bindings(const std::shared_ptr< VKBuffer > &buffer)
std::shared_ptr< Nodes::Network::MeshNetwork > m_network
std::shared_ptr< Portal::Graphics::SlotArena > m_slot_index_arena
Per-vertex slot index. One uint32_t per concatenated vertex.
void on_detach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is detached from a buffer.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
std::vector< glm::mat4 > m_model_aggregate
CPU-side scratch for model matrices, reused each cycle.
void initialize_buffer_service()
Registry::Service::BufferService * m_buffer_service
void ensure_initialized(const std::shared_ptr< VKBuffer > &buffer)
void upload_to_gpu(const void *data, size_t size, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging, size_t dst_offset, bool awaited)
Upload raw data to GPU buffer (auto-detects host-visible vs device-local)
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
std::shared_ptr< VKBuffer > create_staging_buffer(size_t size)
Create staging buffer for transfers.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ UNKNOWN
Unknown or undefined modality.
@ SCALAR_F32
Single-channel float data.
@ HOST_STORAGE
Host-visible storage buffer (eStorageBuffer + eHostVisible|eHostCoherent)
Vertex type for indexed triangle mesh primitives (TRIANGLE_LIST topology)
static VertexLayout for_meshes(uint32_t stride=68)
Factory: layout for MeshVertex (position, color, weight, uv, normal, tangent)
vk::DescriptorBufferInfo buffer_info
std::shared_ptr< SlotArena > arena
std::function< void(const std::shared_ptr< void > &)> initialize_buffer
Initialize a buffer object.