VkCommandBuffer BeginSingleTimeCommands() { var commandBuffer = commandPool.Allocate(VkCommandBufferLevel.Primary); var beginInfo = new VkCommandBufferBeginInfo(); beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmitBit; commandBuffer.Begin(beginInfo); return(commandBuffer); }
void CopyBuffer(VkBuffer src, VkBuffer dst, long size) { var info = new VkCommandBufferAllocateInfo(); info.level = VkCommandBufferLevel.Primary; info.commandBufferCount = 1; var buffers = commandPool.Allocate(info); var buffer = buffers[0]; var beginInfo = new VkCommandBufferBeginInfo(); beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmitBit; buffer.Begin(beginInfo); VkBufferCopy region = new VkBufferCopy(); region.srcOffset = 0; region.dstOffset = 0; region.size = size; buffer.CopyBuffer(src, dst, new VkBufferCopy[] { region }); buffer.End(); var submitInfo = new VkSubmitInfo(); submitInfo.commandBuffers = new List <VkCommandBuffer> { buffer }; graphicsQueue.Submit(new List <VkSubmitInfo> { submitInfo }, null); graphicsQueue.WaitIdle(); commandPool.Free(buffers); }
void CreateCommandBuffers() { if (commandBuffers != null) { commandPool.Free(commandBuffers); } var info = new VkCommandBufferAllocateInfo(); info.level = VkCommandBufferLevel.Primary; info.commandBufferCount = swapchainFramebuffers.Count; commandBuffers = new List <VkCommandBuffer>(commandPool.Allocate(info)); for (int i = 0; i < commandBuffers.Count; i++) { var buffer = commandBuffers[i]; var beginInfo = new VkCommandBufferBeginInfo(); beginInfo.flags = VkCommandBufferUsageFlags.SimultaneousUseBit; buffer.Begin(beginInfo); var renderPassInfo = new VkRenderPassBeginInfo(); renderPassInfo.renderPass = renderPass; renderPassInfo.framebuffer = swapchainFramebuffers[i]; renderPassInfo.renderArea.extent = swapchainExtent; VkClearValue clearColor = new VkClearValue { color = new VkClearColorValue(0, 0, 0, 1f) }; renderPassInfo.clearValues = new List <VkClearValue> { clearColor }; buffer.BeginRenderPass(renderPassInfo, VkSubpassContents.Inline); buffer.BindPipeline(VkPipelineBindPoint.Graphics, pipeline); buffer.Draw(3, 1, 0, 0); buffer.EndRenderPass(); buffer.End(); } }