private unsafe void CreateBuffers() { PositionColorVertex[] positionData = VertexData.IndexedCubeData; ushort[] indexData = VertexData.CubeIndexData; InstanceData[] instanceData = new InstanceData[] { new InstanceData(new Vector3(0, 0, 0)), new InstanceData(new Vector3(2, 0, 0)), new InstanceData(new Vector3(-2, 0, 0)) }; CreateHostBufferWithContent <PositionColorVertex>(positionData, out var hostBuffer1, out var hostAlloc1); CreateHostBufferWithContent <ushort>(indexData, out var hostBuffer2, out var hostAlloc2); CreateHostBufferWithContent <InstanceData>(instanceData, out var hostBuffer3, out var hostAlloc3); CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageVertexBufferBit, GetByteLength(positionData), out this.VertexBuffer, out this.VertexAllocation); CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageIndexBufferBit, GetByteLength(indexData), out this.IndexBuffer, out this.IndexAllocation); CreateDeviceLocalBuffer(BufferUsageFlags.BufferUsageVertexBufferBit, GetByteLength(instanceData), out this.InstanceBuffer, out this.InstanceAllocation); var cbuffer = AllocateCommandBuffer(CommandBufferLevel.Primary); BufferCopy *copies = stackalloc BufferCopy[1]; BeginCommandBuffer(cbuffer, CommandBufferUsageFlags.CommandBufferUsageOneTimeSubmitBit); copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(positionData)); VkApi.CmdCopyBuffer(cbuffer, hostBuffer1, this.VertexBuffer, 1, copies); copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(indexData)); VkApi.CmdCopyBuffer(cbuffer, hostBuffer2, this.IndexBuffer, 1, copies); copies[0] = new BufferCopy(0, 0, (ulong)GetByteLength(instanceData)); VkApi.CmdCopyBuffer(cbuffer, hostBuffer3, this.InstanceBuffer, 1, copies); EndCommandBuffer(cbuffer); var subInfo = new SubmitInfo(commandBufferCount: 1, pCommandBuffers: &cbuffer); var fence = CreateFence(); var res = VkApi.QueueSubmit(GraphicsQueue, 1, &subInfo, fence); if (res != Result.Success) { throw new Exception("Unable to submit to queue. " + res); } var bufferTmp = cbuffer; //Allows the capture of this command buffer in a lambda BufferCopyPromise = this.scheduler.WaitForFenceAsync(fence); BufferCopyPromise.GetAwaiter().OnCompleted(() => { VkApi.DestroyFence(Device, fence, null); FreeCommandBuffer(bufferTmp); VkApi.DestroyBuffer(Device, hostBuffer1, null); VkApi.DestroyBuffer(Device, hostBuffer2, null); VkApi.DestroyBuffer(Device, hostBuffer3, null); hostAlloc1.Dispose(); hostAlloc2.Dispose(); hostAlloc3.Dispose(); }); this.VertexCount = (uint)positionData.Length; this.IndexCount = (uint)indexData.Length; this.InstanceCount = (uint)instanceData.Length; }