void CreateCommandBuffers() { if (commandBuffers != null) { var Native = new NativeArray <VkCommandBuffer>(commandBuffers); VK.FreeCommandBuffers(device, commandPool, (uint)commandBuffers.Count, Native.Address); Native.Dispose(); } commandBuffers = new List <VkCommandBuffer>(swapchainFramebuffers.Count); var info = new VkCommandBufferAllocateInfo(); info.sType = CSGL.Vulkan.VkStructureType.CommandBufferAllocateInfo; info.commandPool = commandPool; info.level = CSGL.Vulkan.VkCommandBufferLevel.Primary; info.commandBufferCount = (uint)commandBuffers.Capacity; var commandBuffersNative = new NativeArray <VkCommandBuffer>(commandBuffers.Capacity); var result = VK.AllocateCommandBuffers(device, ref info, commandBuffersNative.Address); for (int i = 0; i < commandBuffers.Capacity; i++) { commandBuffers.Add(commandBuffersNative[i]); } commandBuffersNative.Dispose(); for (int i = 0; i < commandBuffers.Count; i++) { var beginInfo = new VkCommandBufferBeginInfo(); beginInfo.sType = CSGL.Vulkan.VkStructureType.CommandBufferBeginInfo; beginInfo.flags = CSGL.Vulkan.VkCommandBufferUsageFlags.SimultaneousUseBit; VK.BeginCommandBuffer(commandBuffers[i], ref beginInfo); var renderPassInfo = new VkRenderPassBeginInfo(); renderPassInfo.sType = CSGL.Vulkan.VkStructureType.RenderPassBeginInfo; renderPassInfo.renderPass = renderPass; renderPassInfo.framebuffer = swapchainFramebuffers[i]; renderPassInfo.renderArea.extent = swapchainExtent; VkClearValue clearColor = new VkClearValue(); clearColor.color.float32_0 = 0; clearColor.color.float32_1 = 0; clearColor.color.float32_2 = 0; clearColor.color.float32_3 = 1f; var clearColorNative = new Native <VkClearValue>(clearColor); renderPassInfo.clearValueCount = 1; renderPassInfo.pClearValues = clearColorNative.Address; VK.CmdBeginRenderPass(commandBuffers[i], ref renderPassInfo, CSGL.Vulkan.VkSubpassContents.Inline); VK.CmdBindPipeline(commandBuffers[i], CSGL.Vulkan.VkPipelineBindPoint.Graphics, pipeline); VK.CmdDraw(commandBuffers[i], 3, 1, 0, 0); VK.CmdEndRenderPass(commandBuffers[i]); result = VK.EndCommandBuffer(commandBuffers[i]); clearColorNative.Dispose(); } }