コード例 #1
0
ファイル: Initializers.cs プロジェクト: gomson/vk
        public static VkCommandBufferBeginInfo CommandBufferBeginInfo()
        {
            VkCommandBufferBeginInfo cmdBufferBeginInfo = new VkCommandBufferBeginInfo();

            cmdBufferBeginInfo.sType = VkStructureType.CommandBufferBeginInfo;
            return(cmdBufferBeginInfo);
        }
コード例 #2
0
        public void BeginAndContinueRenderPass(RenderContext context)
        {
            if (vkCmd.Handle == NullHandle)
            {
                return;
            }
            CheckNotBegun();
            CheckSecondary();

            VkCommandBufferBeginInfo       cmdBufInfo      = Initializers.commandBufferBeginInfo();
            VkCommandBufferInheritanceInfo inheritanceInfo = VkCommandBufferInheritanceInfo.New();

            cmdBufInfo.flags = VkCommandBufferUsageFlags.RenderPassContinue;

            inheritanceInfo.renderPass  = context.currentRenderPass.vkRenderPass;
            inheritanceInfo.subpass     = context.currentSubPassIndex;
            inheritanceInfo.framebuffer = context.currentFrameBuffer.vkFrameBuffer;

            cmdBufInfo.pInheritanceInfo = &inheritanceInfo;

            Util.CheckResult(vkBeginCommandBuffer(vkCmd, &cmdBufInfo));
            begun        = true;
            inRenderPass = true;

            //Does not draw anything without viewport and scissor
            SetViewportScissor(context);
        }
コード例 #3
0
ファイル: VkCommandList.cs プロジェクト: dav1977/veldrid
        public override void Begin()
        {
            if (_commandBufferBegun)
            {
                throw new VeldridException(
                          "CommandList must be in its initial state, or End() must have been called, for Begin() to be valid to call.");
            }
            if (_commandBufferEnded)
            {
                _commandBufferEnded = false;
                _cb = GetNextCommandBuffer();
                if (_currentStagingInfo != null)
                {
                    RecycleStagingInfo(_currentStagingInfo);
                }
            }

            _currentStagingInfo = GetStagingResourceInfo();

            VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();

            beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;
            vkBeginCommandBuffer(_cb, ref beginInfo);
            _commandBufferBegun = true;

            ClearCachedState();
            _currentFramebuffer      = null;
            _currentGraphicsPipeline = null;
            Util.ClearArray(_currentGraphicsResourceSets);
            Util.ClearArray(_scissorRects);

            _currentComputePipeline = null;
            Util.ClearArray(_currentComputeResourceSets);
        }
コード例 #4
0
        public unsafe void Begin(
            VkCommandBufferUsageFlags commandBufferUsageFlag,
            RenderPass renderPass,
            Framebuffer framebuffer,
            uint subpass = 0
            )
        {
            if (_level != VkCommandBufferLevel.Secondary)
            {
                throw new Exception("you can only use this method for secondary command buffers");
            }

            var inheritanceInfo = new VkCommandBufferInheritanceInfo
            {
                sType       = VkStructureType.CommandBufferInheritanceInfo,
                renderPass  = renderPass.Handle,
                framebuffer = framebuffer.Handle
            };

            var beginInfo = new VkCommandBufferBeginInfo
            {
                sType            = VkStructureType.CommandBufferBeginInfo,
                flags            = commandBufferUsageFlag,
                pInheritanceInfo = &inheritanceInfo
            };

            if (VulkanNative.vkBeginCommandBuffer(
                    _handle,
                    &beginInfo
                    ) != VkResult.Success)
            {
                throw new Exception("failed to begin command buffer");
            }
        }
コード例 #5
0
        protected override void buildCommandBuffers()
        {
            var cmdBufInfo = new VkCommandBufferBeginInfo();

            cmdBufInfo.sType = CommandBufferBeginInfo;

            var clearValues = new VkClearValue[2];

            clearValues[0].color        = defaultClearColor;
            clearValues[1].depthStencil = new VkClearDepthStencilValue(1.0f, 0);

            var info = new VkRenderPassBeginInfo();

            info.sType                    = RenderPassBeginInfo;
            info.renderPass               = renderPass;
            info.renderArea.offset.x      = 0;
            info.renderArea.offset.y      = 0;
            info.renderArea.extent.width  = width;
            info.renderArea.extent.height = height;
            info.clearValues              = clearValues;

            for (int i = 0; i < drawCmdBuffers.Length; ++i)
            {
                info.framebuffer = frameBuffers[i];

                vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo);

                vkCmdBeginRenderPass(drawCmdBuffers[i], &info, VkSubpassContents.Inline);

                var viewport = new VkViewport(0, 0, width, height, 0.0f, 1.0f);
                vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);

                var scissor = new VkRect2D(0, 0, width, height);
                vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);

                vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipeline);

                VkDeviceSize offsets = 0;
                VkBuffer     buffer  = vertexBuffer.buffer;
                vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &buffer, &offsets);
                vkCmdBindIndexBuffer(drawCmdBuffers[i], indexBuffer.buffer, 0, VkIndexType.Uint32);

                // Render multiple objects using different model matrices by dynamically offsetting into one uniform buffer
                for (uint j = 0; j < OBJECT_INSTANCES; j++)
                {
                    // One dynamic offset per dynamic descriptor to offset into the ubo containing all model matrices
                    uint dynamicOffset = j * (uint)(dynamicAlignment);
                    // Bind the descriptor set for rendering a mesh using the dynamic offset
                    VkDescriptorSet set = descriptorSet;
                    vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics,
                                            pipelineLayout, 0, 1, &set, 1, &dynamicOffset);

                    vkCmdDrawIndexed(drawCmdBuffers[i], indexCount, 1, 0, 0, 0);
                }

                vkCmdEndRenderPass(drawCmdBuffers[i]);

                vkEndCommandBuffer(drawCmdBuffers[i]);
            }
        }
コード例 #6
0
ファイル: RadialBlurExample.cs プロジェクト: AdrienTorris/vk
        protected override void buildCommandBuffers()
        {
            VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();

            FixedArray2 <VkClearValue> clearValues = new FixedArray2 <VkClearValue>();

            clearValues.First.color         = defaultClearColor;
            clearValues.Second.depthStencil = new VkClearDepthStencilValue {
                depth = 1.0f, stencil = 0
            };

            VkRenderPassBeginInfo renderPassBeginInfo = Initializers.renderPassBeginInfo();

            renderPassBeginInfo.renderPass               = renderPass;
            renderPassBeginInfo.renderArea.offset.x      = 0;
            renderPassBeginInfo.renderArea.offset.y      = 0;
            renderPassBeginInfo.renderArea.extent.width  = width;
            renderPassBeginInfo.renderArea.extent.height = height;
            renderPassBeginInfo.clearValueCount          = 2;
            renderPassBeginInfo.pClearValues             = &clearValues.First;

            for (int i = 0; i < drawCmdBuffers.Count; ++i)
            {
                // Set target frame buffer
                renderPassBeginInfo.framebuffer = frameBuffers[i];

                Util.CheckResult(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));

                vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);

                VkViewport viewport = Initializers.viewport((float)width, (float)height, 0.0f, 1.0f);
                vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);

                VkRect2D scissor = Initializers.rect2D(width, height, 0, 0);
                vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);

                ulong offsets = 0;

                // 3D scene
                vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts_scene, 0, 1, ref descriptorSets_scene, 0, null);
                vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines_phongPass);

                vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, ref models_example.vertices.buffer, &offsets);
                vkCmdBindIndexBuffer(drawCmdBuffers[i], models_example.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
                vkCmdDrawIndexed(drawCmdBuffers[i], models_example.indexCount, 1, 0, 0, 0);

                // Fullscreen triangle (clipped to a quad) with radial blur
                if (blur)
                {
                    vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts_radialBlur, 0, 1, ref descriptorSets_radialBlur, 0, null);
                    vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, (displayTexture) ? pipelines_offscreenDisplay : pipelines_radialBlur);
                    vkCmdDraw(drawCmdBuffers[i], 3, 1, 0, 0);
                }

                vkCmdEndRenderPass(drawCmdBuffers[i]);

                Util.CheckResult(vkEndCommandBuffer(drawCmdBuffers[i]));
            }
        }
コード例 #7
0
        private void createCommandBuffers()
        {
            int commandBuffersCount = swapChainFramebuffers.Length;

            commandBuffers = new VkCommandBuffer[commandBuffersCount];

            VkCommandBufferAllocateInfo allocInfo = new VkCommandBufferAllocateInfo();

            allocInfo.sType              = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
            allocInfo.commandPool        = commandPool;
            allocInfo.level              = VkCommandBufferLevel.VK_COMMAND_BUFFER_LEVEL_PRIMARY;
            allocInfo.commandBufferCount = commandBuffersCount;

            VkResult result = Vulkan.vkAllocateCommandBuffers(device, allocInfo, commandBuffers);

            if (result != VkResult.VK_SUCCESS)
            {
                throw Program.Throw("failed to allocate command buffers!", result);
            }

            for (int i = 0; i < commandBuffersCount; i++)
            {
                VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo();
                beginInfo.sType = VkStructureType.VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
                beginInfo.flags = VkCommandBufferUsageFlagBits.VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT;

                Vulkan.vkBeginCommandBuffer(commandBuffers[i], beginInfo);

                VkRenderPassBeginInfo renderPassInfo = new VkRenderPassBeginInfo();
                renderPassInfo.sType             = VkStructureType.VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
                renderPassInfo.renderPass        = renderPass;
                renderPassInfo.framebuffer       = swapChainFramebuffers[i];
                renderPassInfo.renderArea.offset = VkOffset2D.Create(0, 0);
                renderPassInfo.renderArea.extent = swapChainExtent;

                VkClearValue clearColor = VkClearValue.Create(0.01f, 0.03f, 0.01f, 1.0f);
                renderPassInfo.clearValueCount = 1;
                renderPassInfo.pClearValues    = new VkClearValue[] { clearColor };

                Vulkan.vkCmdBeginRenderPass(commandBuffers[i], renderPassInfo, VkSubpassContents.VK_SUBPASS_CONTENTS_INLINE);

                Vulkan.vkCmdBindPipeline(commandBuffers[i], VkPipelineBindPoint.VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);

                VkBuffer[] vertexBuffers = new VkBuffer[] { vertexBuffer };
                int[]      offsets       = new int[] { 0 };
                Vulkan.vkCmdBindVertexBuffers(commandBuffers[i], 0, 1, vertexBuffers, offsets);

                Vulkan.vkCmdDraw(commandBuffers[i], vertices.Length, 1, 0, 0);

                Vulkan.vkCmdEndRenderPass(commandBuffers[i]);

                result = Vulkan.vkEndCommandBuffer(commandBuffers[i]);
                if (result != VkResult.VK_SUCCESS)
                {
                    throw Program.Throw("failed to record command buffer!", result);
                }
            }
        }
コード例 #8
0
        protected override void buildCommandBuffers()
        {
            var cmdInfo = VkCommandBufferBeginInfo.Alloc();

            var clearValues = VkClearValue.Alloc(2);

            clearValues[0].color        = defaultClearColor;
            clearValues[1].depthStencil = new VkClearDepthStencilValue()
            {
                depth = 1.0f, stencil = 0
            };

            var info = VkRenderPassBeginInfo.Alloc();

            info[0].renderPass               = renderPass;
            info[0].renderArea.offset.x      = 0;
            info[0].renderArea.offset.y      = 0;
            info[0].renderArea.extent.width  = width;
            info[0].renderArea.extent.height = height;
            info[0].clearValues.count        = 2;
            info[0].clearValues.pointer      = clearValues;

            for (int i = 0; i < drawCmdBuffers.Length; ++i)
            {
                // Set target frame buffer
                info[0].framebuffer = frameBuffers[i];

                vkBeginCommandBuffer(drawCmdBuffers[i], cmdInfo);

                vkCmdBeginRenderPass(drawCmdBuffers[i], info, VkSubpassContents.Inline);

                VkViewport viewport = new VkViewport((float)width, (float)height, 0.0f, 1.0f);
                vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);

                VkRect2D scissor = new VkRect2D(0, 0, width, height);
                vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
                {
                    VkDescriptorSet set = descriptorSet;
                    vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout,
                                            0, 1, &set, 0, null);
                }
                vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipeline);

                {
                    VkDeviceSize offsets = 0;
                    VkBuffer     buffer  = vertexBuffer.buffer;
                    vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1,
                                           &buffer, &offsets);
                }
                vkCmdBindIndexBuffer(drawCmdBuffers[i], indexBuffer.buffer, 0, VkIndexType.Uint32);

                vkCmdDrawIndexed(drawCmdBuffers[i], indexCount, 1, 0, 0, 0);

                vkCmdEndRenderPass(drawCmdBuffers[i]);

                vkEndCommandBuffer(drawCmdBuffers[i]);
            }
        }
コード例 #9
0
        protected override void buildCommandBuffers()
        {
            VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();

            FixedArray2 <VkClearValue> clearValues = new FixedArray2 <VkClearValue>();

            clearValues.First.color         = defaultClearColor;
            clearValues.Second.depthStencil = new VkClearDepthStencilValue {
                depth = 1.0f, stencil = 0
            };

            VkRenderPassBeginInfo renderPassBeginInfo = Initializers.renderPassBeginInfo();

            renderPassBeginInfo.renderPass               = renderPass;
            renderPassBeginInfo.renderArea.offset.x      = 0;
            renderPassBeginInfo.renderArea.offset.y      = 0;
            renderPassBeginInfo.renderArea.extent.width  = width;
            renderPassBeginInfo.renderArea.extent.height = height;
            renderPassBeginInfo.clearValueCount          = 2;
            renderPassBeginInfo.pClearValues             = &clearValues.First;

            for (int i = 0; i < drawCmdBuffers.Count; ++i)
            {
                renderPassBeginInfo.framebuffer = frameBuffers[i];

                Util.CheckResult(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));

                vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);

                VkViewport viewport = Initializers.viewport((float)width, (float)height, 0.0f, 1.0f);
                vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);

                VkRect2D scissor = Initializers.rect2D(width, height, 0, 0);
                vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);

                vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline);

                ulong offsets = 0;
                vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, ref vertexBuffer.buffer, &offsets);
                vkCmdBindIndexBuffer(drawCmdBuffers[i], indexBuffer.buffer, 0, VK_INDEX_TYPE_UINT32);

                // Render multiple objects using different model matrices by dynamically offsetting into one uniform buffer
                for (uint j = 0; j < OBJECT_INSTANCES; j++)
                {
                    // One dynamic offset per dynamic descriptor to offset into the ubo containing all model matrices
                    uint dynamicOffset = j * (uint)(dynamicAlignment);
                    // Bind the descriptor set for rendering a mesh using the dynamic offset
                    vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, ref descriptorSet, 1, &dynamicOffset);

                    vkCmdDrawIndexed(drawCmdBuffers[i], indexCount, 1, 0, 0, 0);
                }

                vkCmdEndRenderPass(drawCmdBuffers[i]);

                Util.CheckResult(vkEndCommandBuffer(drawCmdBuffers[i]));
            }
        }
コード例 #10
0
        // Sets up the command buffer that renders the scene to the offscreen frame buffer
        void buildOffscreenCommandBuffer()
        {
            if (offscreenPass.commandBuffer == NullHandle)
            {
                offscreenPass.commandBuffer = createCommandBuffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, false);
            }
            if (offscreenPass.semaphore == NullHandle)
            {
                VkSemaphoreCreateInfo semaphoreCreateInfo = Initializers.semaphoreCreateInfo();
                Util.CheckResult(vkCreateSemaphore(device, &semaphoreCreateInfo, null, out offscreenPass.semaphore));
            }

            VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();

            FixedArray2 <VkClearValue> clearValues = new FixedArray2 <VkClearValue>();

            clearValues.First.color = new VkClearColorValue {
                float32_0 = 0.0f, float32_1 = 0.0f, float32_2 = 0.0f, float32_3 = 0.0f
            };
            clearValues.Second.depthStencil = new VkClearDepthStencilValue {
                depth = 1.0f, stencil = 0
            };

            VkRenderPassBeginInfo renderPassBeginInfo = Initializers.renderPassBeginInfo();

            renderPassBeginInfo.renderPass               = offscreenPass.renderPass;
            renderPassBeginInfo.framebuffer              = offscreenPass.frameBuffer;
            renderPassBeginInfo.renderArea.extent.width  = offscreenPass.width;
            renderPassBeginInfo.renderArea.extent.height = offscreenPass.height;
            renderPassBeginInfo.clearValueCount          = 2;
            renderPassBeginInfo.pClearValues             = &clearValues.First;

            Util.CheckResult(vkBeginCommandBuffer(offscreenPass.commandBuffer, &cmdBufInfo));

            VkViewport viewport = Initializers.viewport((float)offscreenPass.width, (float)offscreenPass.height, 0.0f, 1.0f);

            vkCmdSetViewport(offscreenPass.commandBuffer, 0, 1, &viewport);

            VkRect2D scissor = Initializers.rect2D(offscreenPass.width, offscreenPass.height, 0, 0);

            vkCmdSetScissor(offscreenPass.commandBuffer, 0, 1, &scissor);

            vkCmdBeginRenderPass(offscreenPass.commandBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);

            vkCmdBindDescriptorSets(offscreenPass.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts_scene, 0, 1, ref descriptorSets_scene, 0, null);
            vkCmdBindPipeline(offscreenPass.commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines_colorPass);

            ulong offsets = 0;

            vkCmdBindVertexBuffers(offscreenPass.commandBuffer, VERTEX_BUFFER_BIND_ID, 1, ref models_example.vertices.buffer, &offsets);
            vkCmdBindIndexBuffer(offscreenPass.commandBuffer, models_example.indices.buffer, 0, VK_INDEX_TYPE_UINT32);
            vkCmdDrawIndexed(offscreenPass.commandBuffer, models_example.indexCount, 1, 0, 0, 0);

            vkCmdEndRenderPass(offscreenPass.commandBuffer);

            Util.CheckResult(vkEndCommandBuffer(offscreenPass.commandBuffer));
        }
コード例 #11
0
        protected override void buildCommandBuffers()
        {
            VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();

            FixedArray2<VkClearValue> clearValues = new FixedArray2<VkClearValue>();
            clearValues.First.color = defaultClearColor;
            clearValues.Second.depthStencil = new VkClearDepthStencilValue { depth = 1.0f, stencil = 0 };

            VkRenderPassBeginInfo renderPassBeginInfo = Initializers.renderPassBeginInfo();
            renderPassBeginInfo.renderPass = renderPass;
            renderPassBeginInfo.renderArea.offset.x = 0;
            renderPassBeginInfo.renderArea.offset.y = 0;
            renderPassBeginInfo.renderArea.extent.width = width;
            renderPassBeginInfo.renderArea.extent.height = height;
            renderPassBeginInfo.clearValueCount = 2;
            renderPassBeginInfo.pClearValues = &clearValues.First;

            for (int i = 0; i < drawCmdBuffers.Count; ++i)
            {
                // Set target frame buffer
                renderPassBeginInfo.framebuffer = frameBuffers[i];

                Util.CheckResult(vkBeginCommandBuffer(drawCmdBuffers[i], &cmdBufInfo));

                vkCmdBeginRenderPass(drawCmdBuffers[i], &renderPassBeginInfo, VkSubpassContents.Inline);

                VkViewport viewport = Initializers.viewport((float)width, (float)height, 0.0f, 1.0f);
                vkCmdSetViewport(drawCmdBuffers[i], 0, 1, &viewport);

                VkRect2D scissor = Initializers.rect2D(width, height, 0, 0);
                vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);

                ulong offsets = 0;

                // Skybox
                if (displaySkybox)
                {
                    vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout, 0, 1, ref descriptorSets_skybox, 0, null);
                    vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, ref models_skybox.vertices.buffer, ref offsets);
                    vkCmdBindIndexBuffer(drawCmdBuffers[i], models_skybox.indices.buffer, 0, VkIndexType.Uint32);
                    vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelines_skybox);
                    vkCmdDrawIndexed(drawCmdBuffers[i], models_skybox.indexCount, 1, 0, 0, 0);
                }

                // 3D object
                vkCmdBindDescriptorSets(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout, 0, 1, ref descriptorSets_object, 0, null);
                var vbuffer = models_objects[(int)models_objectIndex].vertices.buffer;
                vkCmdBindVertexBuffers(drawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, &vbuffer, ref offsets);
                vkCmdBindIndexBuffer(drawCmdBuffers[i], models_objects[(int)models_objectIndex].indices.buffer, 0, VkIndexType.Uint32);
                vkCmdBindPipeline(drawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelines_reflect);
                vkCmdDrawIndexed(drawCmdBuffers[i], models_objects[(int)models_objectIndex].indexCount, 1, 0, 0, 0);

                vkCmdEndRenderPass(drawCmdBuffers[i]);

                Util.CheckResult(vkEndCommandBuffer(drawCmdBuffers[i]));
            }
        }
コード例 #12
0
        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]));
            }
        }
コード例 #13
0
ファイル: Vulkan.cs プロジェクト: ab4d/Vortice.Vulkan
        public static VkResult vkBeginCommandBuffer(VkCommandBuffer commandBuffer, VkCommandBufferUsageFlags flags)
        {
            VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo
            {
                sType = VkStructureType.CommandBufferBeginInfo,
                flags = VkCommandBufferUsageFlags.OneTimeSubmit
            };

            return(vkBeginCommandBuffer(commandBuffer, &beginInfo));
        }
コード例 #14
0
ファイル: CommandBuffer.cs プロジェクト: Gaiaxis/SharpGame
        public void Begin(VkCommandBufferUsageFlags flags = VkCommandBufferUsageFlags.None)
        {
            var cmdBufInfo = new VkCommandBufferBeginInfo();

            cmdBufInfo.sType = VkStructureType.CommandBufferBeginInfo;
            cmdBufInfo.flags = flags;
            VulkanUtil.CheckResult(vkBeginCommandBuffer(commandBuffer, &cmdBufInfo));
            opened = true;
            ClearDescriptorSets();
        }
コード例 #15
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);
            }
        }
コード例 #16
0
        public void BeginRenderPassContinue()
        {
            VkCommandBufferBeginInfo cmd_buffer_info = new VkCommandBufferBeginInfo()
            {
                sType = VkStructureType.CommandBufferBeginInfo,
                flags = VkCommandBufferUsageFlags.RenderPassContinue,
                pNext = null,
            };

            vkBeginCommandBuffer(handle, &cmd_buffer_info);
        }
コード例 #17
0
        public void BeginOneTimeSubmit()
        {
            VkCommandBufferBeginInfo cmd_buffer_info = new VkCommandBufferBeginInfo()
            {
                sType = VkStructureType.CommandBufferBeginInfo,
                flags = VkCommandBufferUsageFlags.OneTimeSubmit,
                pNext = null,
            };

            vkBeginCommandBuffer(handle, &cmd_buffer_info);
        }
コード例 #18
0
ファイル: Program.cs プロジェクト: liuzhaolovezt/CSGL_Samples
        VkCommandBuffer BeginSingleTimeCommands()
        {
            var commandBuffer = commandPool.Allocate(VkCommandBufferLevel.Primary);

            var beginInfo = new VkCommandBufferBeginInfo();

            beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmitBit;

            commandBuffer.Begin(beginInfo);

            return(commandBuffer);
        }
コード例 #19
0
        public VkResult Begin(VkCommandBufferBeginInfo pBeginInfo)
        {
            if (m_State == CommandBufferState.Recording)
            {
                return(VkResult.VK_ERROR_VALIDATION_FAILED_EXT);
            }

            m_State = CommandBufferState.Recording;
            m_Commands.Clear();
            m_CmdBeginInfo = pBeginInfo;
            return(VkResult.VK_SUCCESS);
        }
コード例 #20
0
        protected override void buildCommandBuffers()
        {
            VkCommandBufferBeginInfo cmdBufInfo = Initializers.CommandBufferBeginInfo();

            FixedArray2 <VkClearValue> clearValues = new FixedArray2 <VkClearValue>();

            clearValues.First.color         = defaultClearColor;
            clearValues.Second.depthStencil = new VkClearDepthStencilValue()
            {
                depth = 1.0f, stencil = 0
            };

            VkRenderPassBeginInfo renderPassBeginInfo = Initializers.renderPassBeginInfo();

            renderPassBeginInfo.renderPass               = RenderPass;
            renderPassBeginInfo.renderArea.offset.x      = 0;
            renderPassBeginInfo.renderArea.offset.y      = 0;
            renderPassBeginInfo.renderArea.extent.width  = Width;
            renderPassBeginInfo.renderArea.extent.height = Height;
            renderPassBeginInfo.clearValueCount          = 2;
            renderPassBeginInfo.pClearValues             = &clearValues.First;

            for (int i = 0; i < DrawCmdBuffers.Count; ++i)
            {
                // Set target frame buffer
                renderPassBeginInfo.framebuffer = Framebuffers[i];

                Util.CheckResult(vkBeginCommandBuffer(DrawCmdBuffers[i], &cmdBufInfo));

                vkCmdBeginRenderPass(DrawCmdBuffers[i], &renderPassBeginInfo, VkSubpassContents.Inline);

                VkViewport viewport = Initializers.viewport((float)Width, (float)Height, 0.0f, 1.0f);
                vkCmdSetViewport(DrawCmdBuffers[i], 0, 1, &viewport);

                VkRect2D scissor = Initializers.rect2D(Width, Height, 0, 0);
                vkCmdSetScissor(DrawCmdBuffers[i], 0, 1, &scissor);

                vkCmdBindDescriptorSets(DrawCmdBuffers[i], VkPipelineBindPoint.Graphics, pipelineLayout, 0, 1, ref descriptorSet, 0, null);
                vkCmdBindPipeline(DrawCmdBuffers[i], VkPipelineBindPoint.Graphics, wireframe ? pipelines_wireframe : pipelines_solid);

                ulong offsets = 0;
                // Bind mesh vertex buffer
                vkCmdBindVertexBuffers(DrawCmdBuffers[i], VERTEX_BUFFER_BIND_ID, 1, ref model_vertices_buffer, ref offsets);
                // Bind mesh index buffer
                vkCmdBindIndexBuffer(DrawCmdBuffers[i], model_indices_buffer, 0, VkIndexType.Uint32);
                // Render mesh vertex buffer using it's indices
                vkCmdDrawIndexed(DrawCmdBuffers[i], (uint)model_indices_count, 1, 0, 0, 0);

                vkCmdEndRenderPass(DrawCmdBuffers[i]);

                Util.CheckResult(vkEndCommandBuffer(DrawCmdBuffers[i]));
            }
        }
コード例 #21
0
        /// <inheritdoc />
        public override void BeginFrame()
        {
            var graphicsFence = VulkanGraphicsFence;

            graphicsFence.Wait();
            graphicsFence.Reset();

            var commandBufferBeginInfo = new VkCommandBufferBeginInfo {
                sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
            };

            ThrowExternalExceptionIfNotSuccess(nameof(vkBeginCommandBuffer), vkBeginCommandBuffer(VulkanCommandBuffer, &commandBufferBeginInfo));
        }
コード例 #22
0
        public void Begin()
        {
            CheckNotBegun();
            if (vkCmd.Handle == NullHandle)
            {
                return;
            }
            VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();

            cmdBufInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;
            Util.CheckResult(vkBeginCommandBuffer(vkCmd, &cmdBufInfo));

            begun = true;
        }
コード例 #23
0
ファイル: CommandBuffer.cs プロジェクト: Gaiaxis/SharpGame
 public void Begin(VkCommandBufferUsageFlags flags, ref CommandBufferInheritanceInfo commandBufferInheritanceInfo)
 {
     unsafe
     {
         var cmdBufBeginInfo = new VkCommandBufferBeginInfo
         {
             sType            = VkStructureType.CommandBufferBeginInfo,
             flags            = flags,
             pInheritanceInfo = (VkCommandBufferInheritanceInfo *)Unsafe.AsPointer(ref commandBufferInheritanceInfo.native)
         };
         VulkanUtil.CheckResult(vkBeginCommandBuffer(commandBuffer, &cmdBufBeginInfo));
     }
     opened = true;
     ClearDescriptorSets();
 }
コード例 #24
0
        internal VkCommandBufferBeginInfo GetNative(DisposableList <IDisposable> marshalled)
        {
            VkCommandBufferBeginInfo info = new VkCommandBufferBeginInfo();

            info.sType = VkStructureType.CommandBufferBeginInfo;
            info.flags = flags;

            if (inheritanceInfo != null)
            {
                var inheritanceInfoMarshalled = new Marshalled <VkCommandBufferInheritanceInfo>(inheritanceInfo.GetNative());
                info.pInheritanceInfo = inheritanceInfoMarshalled.Address;
                marshalled.Add(inheritanceInfoMarshalled);
            }

            return(info);
        }
コード例 #25
0
ファイル: FCommandBuffer.cs プロジェクト: SamHSmith/VulkanRen
        public void RecordCommandBuffer(Action <VkCommandBuffer>[] executions)
        {
            Assert(vkResetCommandBuffer(buffer, VkCommandBufferResetFlags.None));
            VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();

            beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;

            Assert(vkBeginCommandBuffer(buffer, &beginInfo));

            for (int i = 0; i < executions.Length; i++)
            {
                executions[i](buffer);
            }

            Assert(vkEndCommandBuffer(buffer));
        }
コード例 #26
0
ファイル: CommandBuffer.cs プロジェクト: jpbruyere/vke.net
        public void Start(VkCommandBufferUsageFlags usage = 0, RenderPass rp = null, uint subpass = 0, FrameBuffer fb = null,
                          bool occlusionQueryEnable       = false, VkQueryControlFlags queryFlags = 0, VkQueryPipelineStatisticFlags statFlags = 0)
        {
            VkCommandBufferInheritanceInfo inheri = VkCommandBufferInheritanceInfo.New();

            inheri.renderPass           = rp == null ? 0 : rp.handle;
            inheri.subpass              = subpass;
            inheri.framebuffer          = fb == null ? 0 : fb.handle;
            inheri.occlusionQueryEnable = occlusionQueryEnable;
            inheri.queryFlags           = queryFlags;
            inheri.pipelineStatistics   = statFlags;
            VkCommandBufferBeginInfo cmdBufInfo = new VkCommandBufferBeginInfo(usage);

            cmdBufInfo.pInheritanceInfo = inheri.Pin();
            Utils.CheckResult(vkBeginCommandBuffer(handle, ref cmdBufInfo));
            inheri.Unpin();
        }
コード例 #27
0
        protected VkCommandBuffer createCommandBuffer(VkCommandBufferLevel level, bool begin)
        {
            VkCommandBuffer cmdBuffer;

            VkCommandBufferAllocateInfo cmdBufAllocateInfo = Initializers.CommandBufferAllocateInfo(cmdPool, level, 1);

            Util.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, out cmdBuffer));

            // If requested, also start the new command buffer
            if (begin)
            {
                VkCommandBufferBeginInfo cmdBufInfo = Initializers.commandBufferBeginInfo();
                Util.CheckResult(vkBeginCommandBuffer(cmdBuffer, &cmdBufInfo));
            }

            return(cmdBuffer);
        }
コード例 #28
0
ファイル: Program.cs プロジェクト: liuzhaolovezt/CSGL_Samples
        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.BindVertexBuffers(0, new VkBuffer[] { vertexBuffer }, new long[] { 0 });
                buffer.BindIndexBuffer(indexBuffer, 0, VkIndexType.UINT32);
                buffer.BindDescriptorSets(VkPipelineBindPoint.Graphics, pipelineLayout, 0, new VkDescriptorSet[] { descriptorSet }, null);
                buffer.DrawIndexed(indices.Length, 1, 0, 0, 0);
                buffer.EndRenderPass();
                buffer.End();
            }
        }
コード例 #29
0
ファイル: VkCommandList.cs プロジェクト: suprafun/veldrid
        public override void Begin()
        {
            if (_commandBufferBegun)
            {
                throw new VeldridException(
                          "CommandList must be in it's initial state, or End() must have been called, for Begin() to be valid to call.");
            }
            if (_commandBufferEnded)
            {
                _commandBufferEnded = false;
                vkResetCommandPool(_gd.Device, _pool, VkCommandPoolResetFlags.None);
            }

            VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();

            vkBeginCommandBuffer(_cb, ref beginInfo);
            _commandBufferBegun = true;
        }
コード例 #30
0
        protected VkCommandBuffer BeginOneTimeCommands()
        {
            VkCommandBufferAllocateInfo allocInfo = VkCommandBufferAllocateInfo.New();

            allocInfo.commandBufferCount = 1;
            allocInfo.commandPool        = _rc.GraphicsCommandPool;
            allocInfo.level = VkCommandBufferLevel.Primary;

            vkAllocateCommandBuffers(_device, ref allocInfo, out VkCommandBuffer cb);

            VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New();

            beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit;

            vkBeginCommandBuffer(cb, ref beginInfo);

            return(cb);
        }