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); }
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"); } }
public unsafe CommandBufferInheritanceInfo(Framebuffer framebuffer, RenderPass renderPass, uint subpass, bool occlusionQueryEnable = false, VkQueryControlFlags queryFlags = VkQueryControlFlags.None, VkQueryPipelineStatisticFlags pipelineStatistics = VkQueryPipelineStatisticFlags.None) { native = new VkCommandBufferInheritanceInfo { sType = VkStructureType.CommandBufferInheritanceInfo, renderPass = renderPass, subpass = subpass, framebuffer = framebuffer, occlusionQueryEnable = occlusionQueryEnable, queryFlags = queryFlags, pipelineStatistics = pipelineStatistics }; }
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(); }
internal VkCommandBufferInheritanceInfo GetNative() { VkCommandBufferInheritanceInfo info = new VkCommandBufferInheritanceInfo(); info.sType = VkStructureType.CommandBufferInheritanceInfo; info.renderPass = renderPass.Native; info.subpass = subpass; var framebufferNative = VkFramebuffer.Null; if (framebuffer != null) { framebufferNative = framebuffer.Native; } info.framebuffer = framebufferNative; info.occlusionQueryEnable = occlusionQueryEnable ? 1u : 0u; info.queryFlags = queryFlags; info.pipelineStatistics = pipelineStatistics; return(info); }
private void DrawPrimitives(int indexCount, int instanceCount, int startingIndex, int startingVertex) { RenderPassInfo renderPassState = GetCurrentRenderPass(); VkPipelineLayout layout = ShaderResourceBindingSlots.PipelineLayout; VkPipelineCacheKey pipelineCacheKey = new VkPipelineCacheKey(); pipelineCacheKey.RenderPass = renderPassState.Framebuffer.RenderPassClearBuffer; pipelineCacheKey.PipelineLayout = layout; pipelineCacheKey.BlendState = (VkBlendState)BlendState; pipelineCacheKey.Framebuffer = renderPassState.Framebuffer; pipelineCacheKey.DepthStencilState = (VkDepthStencilState)DepthStencilState; pipelineCacheKey.RasterizerState = (VkRasterizerState)RasterizerState; pipelineCacheKey.PrimitiveTopology = _primitiveTopology; pipelineCacheKey.ShaderSet = ShaderSet; pipelineCacheKey.VertexBindings = VertexBuffers; VkPipeline graphicsPipeline = _resourceCache.GetGraphicsPipeline(ref pipelineCacheKey); VkDescriptorSetCacheKey descriptorSetCacheKey = new VkDescriptorSetCacheKey(); descriptorSetCacheKey.ShaderResourceBindingSlots = ShaderResourceBindingSlots; descriptorSetCacheKey.ConstantBuffers = _constantBuffers; descriptorSetCacheKey.TextureBindings = _textureBindings; descriptorSetCacheKey.SamplerStates = _samplerStates; VkDescriptorSet descriptorSet = _resourceCache.GetDescriptorSet(ref descriptorSetCacheKey); VkCommandBuffer cb = GetCommandBuffer(); VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New(); beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit | VkCommandBufferUsageFlags.RenderPassContinue; VkCommandBufferInheritanceInfo inheritanceInfo = VkCommandBufferInheritanceInfo.New(); inheritanceInfo.renderPass = renderPassState.Framebuffer.RenderPassClearBuffer; beginInfo.pInheritanceInfo = &inheritanceInfo; vkBeginCommandBuffer(cb, ref beginInfo); vkCmdBindPipeline(cb, VkPipelineBindPoint.Graphics, graphicsPipeline); vkCmdBindDescriptorSets( cb, VkPipelineBindPoint.Graphics, layout, 0, 1, ref descriptorSet, 0, IntPtr.Zero); int vbCount = ShaderSet.InputLayout.InputDescriptions.Length; StackList <VkBuffer, Size512Bytes> vbs = new StackList <VkBuffer, Size512Bytes>(); for (int vbIndex = 0; vbIndex < vbCount; vbIndex++) { vbs.Add(((VkVertexBuffer)VertexBuffers[vbIndex]).DeviceBuffer); } StackList <VkBuffer, Size512Bytes> offsets = new StackList <VkBuffer, Size512Bytes>(); vkCmdBindVertexBuffers(cb, 0, vbs.Count, (IntPtr)vbs.Data, (IntPtr)offsets.Data); vkCmdBindIndexBuffer(cb, IndexBuffer.DeviceBuffer, 0, IndexBuffer.IndexType); VkViewport viewport = new VkViewport() { x = Viewport.X, y = Viewport.Y, width = Viewport.Width, height = Viewport.Height, minDepth = 0, maxDepth = 1 }; vkCmdSetViewport(cb, 0, 1, ref viewport); vkCmdSetScissor(cb, 0, 1, ref _scissorRect); vkCmdDrawIndexed(cb, (uint)indexCount, (uint)instanceCount, (uint)startingIndex, startingVertex, 0); vkEndCommandBuffer(cb); renderPassState.SecondaryCommandBuffers.Add(cb); }