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

◆ upload_combined()

void MayaFlux::Buffers::MeshNetworkProcessor::upload_combined ( const std::shared_ptr< VKBuffer > &  vertex_buf)
private

Definition at line 121 of file MeshNetworkProcessor.cpp.

123{
124 const auto& slots = m_network->slots();
125 const auto& order = m_network->sorted_indices();
126
127 m_vertex_aggregate.clear();
128 m_index_aggregate.clear();
129 m_model_aggregate.clear();
131
132 uint32_t running_vertex_count = 0;
133
134 for (uint32_t idx : order) {
135 const auto& slot = slots[idx];
136 if (!slot.node)
137 continue;
138
139 const auto& verts = slot.node->get_mesh_vertices();
140 const auto& indices = slot.node->get_mesh_indices();
141
142 const size_t v_bytes = verts.size() * sizeof(Nodes::MeshVertex);
143 const auto* v_src = reinterpret_cast<const uint8_t*>(verts.data());
144 m_vertex_aggregate.insert(m_vertex_aggregate.end(), v_src, v_src + v_bytes);
145
146 for (uint32_t i : indices)
147 m_index_aggregate.push_back(i + running_vertex_count);
148
149 m_model_aggregate.push_back(slot.world_transform);
150
151 const auto sorted_slot_pos = static_cast<uint32_t>(m_model_aggregate.size() - 1);
153 m_slot_index_aggregate.end(), verts.size(), sorted_slot_pos);
154
155 running_vertex_count += static_cast<uint32_t>(verts.size());
156 }
157
158 if (m_vertex_aggregate.empty())
159 return;
160
161 const size_t v_required = m_vertex_aggregate.size();
162 if (v_required > vertex_buf->get_size_bytes()) {
163 const auto new_size = static_cast<size_t>(
164 static_cast<float>(v_required) * 1.5F);
165 vertex_buf->resize(new_size, false);
167 m_vertex_staging->resize(new_size, false);
168 }
169
171 m_vertex_aggregate.data(),
172 v_required,
173 vertex_buf,
174 vertex_buf->is_host_visible() ? nullptr : m_vertex_staging);
175
176 const size_t i_required = m_index_aggregate.size() * sizeof(uint32_t);
177 if (m_gpu_index_buffer && i_required > m_gpu_index_buffer->get_size_bytes()) {
178 const auto new_size = static_cast<size_t>(
179 static_cast<float>(i_required) * 1.5F);
180 m_gpu_index_buffer->resize(new_size, false);
181 if (m_index_staging)
182 m_index_staging->resize(new_size, false);
183 }
184
185 if (m_gpu_index_buffer && !m_index_aggregate.empty()) {
187 m_index_aggregate.data(),
188 i_required,
191 }
192
193 for (uint32_t idx : order) {
194 const auto& slot = slots[idx];
195 if (slot.node && slot.node->get_mesh_vertex_count() > 0) {
196 if (auto layout = slot.node->get_vertex_layout()) {
197 layout->vertex_count = running_vertex_count;
198 vertex_buf->set_vertex_layout(*layout);
199 }
200 break;
201 }
202 }
203}
std::vector< uint32_t > m_slot_index_aggregate
CPU-side scratch for per-vertex slot indices, reused each cycle.
std::vector< uint8_t > m_vertex_aggregate
Aggregate scratch buffers reused each cycle to avoid allocation.
std::shared_ptr< Nodes::Network::MeshNetwork > m_network
std::vector< glm::mat4 > m_model_aggregate
CPU-side scratch for model matrices, reused each cycle.
void upload_to_gpu(const void *data, size_t size, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging)
Upload raw data to GPU buffer (auto-detects host-visible vs device-local)

References m_gpu_index_buffer, m_index_aggregate, m_index_staging, m_model_aggregate, m_network, m_slot_index_aggregate, m_vertex_aggregate, m_vertex_staging, and MayaFlux::Buffers::upload_to_gpu().

Referenced by on_attach(), and processing_function().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: