Exemple #1
0
        public void EndSingleTimeCommands(Vk.Queue queue,
                                          Vk.CommandPool commandPool, Vk.CommandBuffer buffer)
        {
            buffer.End();

            var submitInfo = new Vk.SubmitInfo();

            submitInfo.CommandBufferCount = 1;
            submitInfo.CommandBuffers     = new Vk.CommandBuffer[] { buffer };

            queue.Submit(new Vk.SubmitInfo[] { submitInfo });
            queue.WaitIdle();
            this.Device.FreeCommandBuffer(commandPool, buffer);
        }
Exemple #2
0
        private void createCommandBuffers(VkContext context)
        {
            var allocInfo = new Vk.CommandBufferAllocateInfo();

            allocInfo.CommandPool        = context.GraphicsCommandPool;
            allocInfo.Level              = Vk.CommandBufferLevel.Primary;
            allocInfo.CommandBufferCount = this.wrapper.ImageCapacity;

            try {
                this.wrapper.CommandBuffers = context.Device.AllocateCommandBuffers(allocInfo);
            } catch (Vk.ResultException result) {
                throw new VkException("An error occurred while creating the command buffers.", result);
            }

            for (int i = 0; i < this.wrapper.ImageCapacity; i++)
            {
                Vk.CommandBuffer buffer = this.wrapper.CommandBuffers[i];
                var beginInfo           = new Vk.CommandBufferBeginInfo();
                beginInfo.Flags = Vk.CommandBufferUsageFlags.SimultaneousUse;

                try {
                    buffer.Begin(beginInfo);
                } catch (Vk.ResultException result) {
                    throw new VkException($"An error occurred while beginning recording for command buffer {i}.", result);
                }

                var renderPassInfo = new Vk.RenderPassBeginInfo();
                renderPassInfo.RenderPass  = this.wrapper.RenderPass;
                renderPassInfo.Framebuffer = this.wrapper.Framebuffers[i];

                var clearColour = new Vk.ClearValue();
                var renderArea  = new Vk.Rect2D();

                clearColour.Color = new Vk.ClearColorValue(new float[] { 0.0F, 0.0F, 0.0F, 1.0F });

                renderArea.Extent.Width  = this.wrapper.Extent.Width;
                renderArea.Extent.Height = this.wrapper.Extent.Height;
                renderArea.Offset.X      = 0;
                renderArea.Offset.Y      = 0;

                var clearDepth = new Vk.ClearValue();

                var depth = new Vk.ClearDepthStencilValue();
                depth.Depth = 1;

                clearDepth.DepthStencil = depth;

                renderPassInfo.RenderArea      = renderArea;
                renderPassInfo.ClearValueCount = 2;
                renderPassInfo.ClearValues     = new Vk.ClearValue[] {
                    clearColour,
                    clearDepth
                };

                buffer.CmdBeginRenderPass(renderPassInfo, Vk.SubpassContents.Inline);
                buffer.CmdBindPipeline(Vk.PipelineBindPoint.Graphics, this.wrapper.Pipeline);
                buffer.CmdBindDescriptorSet(Vk.PipelineBindPoint.Graphics,
                                            this.wrapper.PipelineLayout, 0, this.wrapper.DescriptorSets[i], null);

                this.renderPassCallback.Invoke(buffer);

                buffer.CmdEndRenderPass();

                try {
                    buffer.End();
                } catch (Vk.ResultException result) {
                    throw new VkException($"An error occurred while recording for command buffer {i}.", result);
                }
            }
        }