private void CreateCommandBuffers()
        {
            this.commandBuffers = new VkCommandBuffer[this.swapChainFramebuffers.Length];

            VkCommandBufferAllocateInfo allocInfo = new VkCommandBufferAllocateInfo()
            {
                sType              = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
                commandPool        = commandPool,
                level              = VkCommandBufferLevel.VK_COMMAND_BUFFER_LEVEL_PRIMARY,
                commandBufferCount = (uint)commandBuffers.Length,
            };

            fixed(VkCommandBuffer *commandBuffersPtr = &this.commandBuffers[0])
            {
                Helpers.CheckErrors(VulkanNative.vkAllocateCommandBuffers(this.device, &allocInfo, commandBuffersPtr));
            }

            // Begin
            for (uint i = 0; i < this.commandBuffers.Length; i++)
            {
                VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo()
                {
                    sType            = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
                    flags            = 0,    // Optional
                    pInheritanceInfo = null, // Optional
                };

                Helpers.CheckErrors(VulkanNative.vkBeginCommandBuffer(this.commandBuffers[i], &beginInfo));

                // Pass
                VkClearValue clearColor = new VkClearValue()
                {
                    color = new VkClearColorValue(0.0f, 0.0f, 0.0f, 1.0f),
                };

                VkRenderPassBeginInfo renderPassInfo = new VkRenderPassBeginInfo()
                {
                    sType           = VkStructureType.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
                    renderPass      = this.renderPass,
                    framebuffer     = this.swapChainFramebuffers[i],
                    renderArea      = new VkRect2D(0, 0, this.swapChainExtent.width, this.swapChainExtent.height),
                    clearValueCount = 1,
                    pClearValues    = &clearColor,
                };

                VulkanNative.vkCmdBeginRenderPass(this.commandBuffers[i], &renderPassInfo, VkSubpassContents.VK_SUBPASS_CONTENTS_INLINE);

                // Draw
                VulkanNative.vkCmdBindPipeline(this.commandBuffers[i], VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS, this.graphicsPipeline);

                VulkanNative.vkCmdDraw(this.commandBuffers[i], 3, 1, 0, 0);

                VulkanNative.vkCmdEndRenderPass(this.commandBuffers[i]);

                Helpers.CheckErrors(VulkanNative.vkEndCommandBuffer(this.commandBuffers[i]));
            }
        }
Beispiel #2
0
        private void CreateCommandBuffers()
        {
            var allocInfo = new VkCommandBufferAllocateInfo()
            {
                sType              = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
                commandPool        = vkCommandPool,
                level              = VkCommandBufferLevel.VK_COMMAND_BUFFER_LEVEL_PRIMARY,
                commandBufferCount = (uint)vkSwapChainFramebuffers.Length,
            };

            vkCommandBuffers = new VkCommandBuffer[vkSwapChainFramebuffers.Length];

            fixed(VkCommandBuffer *newCommandBuffer = vkCommandBuffers)
            VulkanNative.vkAllocateCommandBuffers(vkDevice, &allocInfo, newCommandBuffer);

            for (int i = 0; i < vkCommandBuffers.Length; i++)
            {
                var commandBuffer = vkCommandBuffers[i];

                var beginInfo = new VkCommandBufferBeginInfo()
                {
                    sType            = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
                    flags            = VkCommandBufferUsageFlagBits.VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,
                    pInheritanceInfo = null,
                };

                var result = VulkanNative.vkBeginCommandBuffer(commandBuffer, &beginInfo);
                Helpers.CheckErrors(result);

                VkClearValue clearColor = new VkClearValue()
                {
                    color = new VkClearColorValue(0, 0, 0, 1f),
                };

                var renderPassInfo = new VkRenderPassBeginInfo()
                {
                    sType       = VkStructureType.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
                    renderPass  = vkRenderPass,
                    framebuffer = vkSwapChainFramebuffers[i],
                    renderArea  = new VkRect2D()
                    {
                        extent = vkSwapChainExtent
                    },
                    pClearValues    = &clearColor,
                    clearValueCount = 1,
                };

                VulkanNative.vkCmdBeginRenderPass(commandBuffer, &renderPassInfo, VkSubpassContents.VK_SUBPASS_CONTENTS_INLINE);
                VulkanNative.vkCmdBindPipeline(commandBuffer, VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS, vkGraphicsPipeline);
                VulkanNative.vkCmdDraw(commandBuffer, 3, 1, 0, 0);
                VulkanNative.vkCmdEndRenderPass(commandBuffer);
                result = VulkanNative.vkEndCommandBuffer(commandBuffer);
                Helpers.CheckErrors(result);
            }
        }
Beispiel #3
0
 public unsafe void EndRenderPass()
 {
     VulkanNative.vkCmdEndRenderPass(_handle);
 }