def _setup_meshes_resources(self, staging_alloc, staging_buffer, mesh_buffer_size): engine, api, device = self.ctx mem = engine.memory_manager cmd = engine.setup_command_buffer # Final buffer allocation mesh_buffer = hvk.create_buffer( api, device, hvk.buffer_create_info(size=mesh_buffer_size, usage=vk.BUFFER_USAGE_INDEX_BUFFER_BIT | vk.BUFFER_USAGE_VERTEX_BUFFER_BIT | vk.BUFFER_USAGE_TRANSFER_DST_BIT)) mesh_alloc = mem.alloc(mesh_buffer, vk.STRUCTURE_TYPE_BUFFER_CREATE_INFO, (vk.MEMORY_PROPERTY_DEVICE_LOCAL_BIT, )) # Uploading commands region = vk.BufferCopy(src_offset=0, dst_offset=0, size=mesh_buffer_size) regions = (region, ) hvk.begin_command_buffer(api, cmd, hvk.command_buffer_begin_info()) hvk.copy_buffer(api, cmd, staging_buffer, mesh_buffer, regions) hvk.end_command_buffer(api, cmd) # Submitting engine.submit_setup_command(wait=True) return mesh_alloc, mesh_buffer
def mesh_to_device(): global mesh_buffer, mesh_memory, staging_mesh_buffer, staging_mesh_memory, mesh_data # Create mesh resources mesh_buffer = hvk.create_buffer( api, device, hvk.buffer_create_info(size=total_mesh_size, usage=vk.BUFFER_USAGE_TRANSFER_DST_BIT | vk.BUFFER_USAGE_INDEX_BUFFER_BIT | vk.BUFFER_USAGE_VERTEX_BUFFER_BIT)) mesh_req = hvk.buffer_memory_requirements(api, device, mesh_buffer) mt_index = find_memory_type(vk.MEMORY_HEAP_DEVICE_LOCAL_BIT, vk.MEMORY_PROPERTY_DEVICE_LOCAL_BIT) mesh_memory = hvk.allocate_memory( api, device, hvk.memory_allocate_info(allocation_size=mesh_req.size, memory_type_index=mt_index)) hvk.bind_buffer_memory(api, device, mesh_buffer, mesh_memory, 0) # Upload mesh to device memory (recording) hvk.begin_command_buffer(api, staging_cmd, hvk.command_buffer_begin_info()) region = vk.BufferCopy(src_offset=0, dst_offset=0, size=mesh_req.size) hvk.copy_buffer(api, staging_cmd, staging_mesh_buffer, mesh_buffer, (region, )) hvk.end_command_buffer(api, staging_cmd) # Upload mesh to device memory (submiting) submit_info = hvk.submit_info(command_buffers=(staging_cmd, )) hvk.queue_submit(api, render_queue.handle, (submit_info, ), fence=staging_fence) hvk.wait_for_fences(api, device, (staging_fence, )) # Free staging resources hvk.destroy_buffer(api, device, staging_mesh_buffer) hvk.free_memory(api, device, staging_mesh_memory) del mesh_data, staging_mesh_buffer, staging_mesh_memory