public CommandBuffer[] Allocate(VkCommandBufferLevel level, int count) { var info = new VkCommandBufferAllocateInfo(); info.sType = VkStructureType.CommandBufferAllocateInfo; info.level = level; info.commandPool = commandPool; info.commandBufferCount = (uint)count; using (var commandBuffersMarshalled = new NativeArray <VkCommandBuffer>(count)) { CommandBuffer[] commandBuffers = new CommandBuffer[count]; var result = Device.Commands.allocateCommandBuffers(Device.Native, ref info, commandBuffersMarshalled.Address); if (result != VkResult.Success) { throw new CommandPoolException(string.Format("Error allocating command buffers: {0}", result)); } for (int i = 0; i < count; i++) { commandBuffers[i] = new CommandBuffer(Device, this, commandBuffersMarshalled[i], level); } return(commandBuffers); } }
public unsafe CommandBuffer( CommandPool commandPool, VkCommandBufferLevel level = VkCommandBufferLevel.Primary, bool isFenceSignaled = false ) { _commandPool = commandPool; _level = level; var allocateInfo = new VkCommandBufferAllocateInfo { sType = VkStructureType.CommandBufferAllocateInfo, commandPool = commandPool.Handle, level = level, commandBufferCount = 1 }; VkCommandBuffer commandBuffer; if (VulkanNative.vkAllocateCommandBuffers( commandPool.Device.Handle, &allocateInfo, &commandBuffer ) != VkResult.Success) { throw new Exception("failed to allocate command buffers"); } _handle = commandBuffer; _fence = new Fence(commandPool.Device, isFenceSignaled); }
private void GrowBuffers(VkCommandBufferLevel level, uint numBuffers) { NativeList <VkCommandBuffer> buffers = level == VkCommandBufferLevel.Primary ? primaryCmdBuffers : secondaryCmdBuffers; uint oldBuffers = buffers.Count; if (numBuffers <= oldBuffers) { return; } // Create one command buffer for each swap chain image and reuse for rendering buffers.Resize(numBuffers); buffers.Count = numBuffers; if (buffers.Count > MAX_BUFFERS) { throw new InvalidOperationException("Hit max buffer amount. Please check if buffers are not being reused correctly."); } VkCommandBufferAllocateInfo cmdBufAllocateInfo = Initializers.CommandBufferAllocateInfo(vkCmdPool, level, buffers.Count - oldBuffers); Util.CheckResult(vkAllocateCommandBuffers(device.device, ref cmdBufAllocateInfo, (VkCommandBuffer *)buffers.GetAddress(oldBuffers))); var queue = level == VkCommandBufferLevel.Primary ? freePrimaryBuffers : freeSecondaryBuffers; for (uint i = oldBuffers; i < buffers.Count; i++) { queue.Enqueue(buffers[i]); } }
private SoftwareCommandBuffer(SoftwareDevice device, VkCommandBufferAllocateInfo allocInfo) { this.m_device = device; this.m_allocInfo = allocInfo; this.m_Commands = new List <SoftwareBufferCommand>(); this.m_State = CommandBufferState.Initial; }
public void Build(CommandPool pool) { if (!locked) { unsafe { var allocInfo = new VkCommandBufferAllocateInfo() { sType = VkStructureType.StructureTypeCommandBufferAllocateInfo, commandBufferCount = 1, commandPool = pool.hndl, level = VkCommandBufferLevel.CommandBufferLevelPrimary, }; devID = pool.devID; if (pool.queueFamily == GraphicsDevice.DeviceInformation[devID].ComputeFamily) { IsRadRayStream = true; } IntPtr cmdBufferPtr_l = IntPtr.Zero; if (vkAllocateCommandBuffers(GraphicsDevice.GetDeviceInfo(devID).Device, allocInfo.Pointer(), &cmdBufferPtr_l) != VkResult.Success) { throw new Exception("Failed to allocate command buffer."); } cmdPool = pool; hndl = cmdBufferPtr_l; IsEmpty = true; if (IsRadRayStream) { IntPtr radRayStrmPtr_l = IntPtr.Zero; if (rrGetCommandStreamFromVkCommandBuffer(GraphicsDevice.DeviceInformation[devID].RaysContext, cmdBufferPtr_l, &radRayStrmPtr_l) != RRError.RrSuccess) { throw new Exception("Failed to create RadeonRays stream."); } radRayStream = radRayStrmPtr_l; } if (GraphicsDevice.EnableValidation) { var objName = new VkDebugUtilsObjectNameInfoEXT() { sType = VkStructureType.StructureTypeDebugUtilsObjectNameInfoExt, pObjectName = Name, objectType = VkObjectType.ObjectTypeCommandBuffer, objectHandle = (ulong)hndl }; GraphicsDevice.SetDebugUtilsObjectNameEXT(GraphicsDevice.GetDeviceInfo(devID).Device, objName.Pointer()); } } locked = true; } else { throw new Exception("Command buffer locked."); } }
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); } } }
void CreateCommandBuffers() { VkCommandBufferAllocateInfo info = new VkCommandBufferAllocateInfo { commandBufferCount = swapchainImages.Count, level = VkCommandBufferLevel.Primary }; commandBuffers = commandPool.Allocate(info); }
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])); } }
private void Vkctrl_VulkanInitialized(object sender, SharpVulkanWpf.VulkanEventArgs args) { var device = args.Device; var commandPoolCreateInfo = new VkCommandPoolCreateInfo() { queueFamilyIndex = args.GraphicsQueueIndex, flags = VkCommandPoolCreateFlags.VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, }; VulkanAPI.vkCreateCommandPool(device, ref commandPoolCreateInfo, out m_commandPool); var allocateInfo = new VkCommandBufferAllocateInfo() { commandBufferCount = 1, commandPool = m_commandPool, }; VulkanAPI.vkAllocateCommandBuffers(device, ref allocateInfo, out m_commandBuffers); // 頂点入力情報の構築. m_vertexInputState = CreateVertexInputState(); // プリミティブの情報 トライアングルリストでデータが生成されている. m_inputAssemblyState = new VkPipelineInputAssemblyStateCreateInfo() { topology = VkPrimitiveTopology.VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST }; // シェーダーステージ情報の構築. m_shaderStages = new VkPipelineShaderStageCreateInfo[2] { SampleHelpers.CreateShader(device, "resource/simpleVS.spv", VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT), SampleHelpers.CreateShader(device, "resource/simpleFS.spv", VkShaderStageFlagBits.VK_SHADER_STAGE_FRAGMENT_BIT), }; // ラスタライザーステートの構築. m_rasterizationState = new VkPipelineRasterizationStateCreateInfo(); // デプスステンシルステートの構築. m_depthStencilState = new VkPipelineDepthStencilStateCreateInfo(); // カラーブレンドステートの構築. m_colorBlendState = new VkPipelineColorBlendStateCreateInfo(); var colorBlendAttachment = new VkPipelineColorBlendAttachmentState(); m_colorBlendState.attachments = new[] { colorBlendAttachment }; // マルチサンプルステートの構築. m_multisampleState = new VkPipelineMultisampleStateCreateInfo(); // パイプラインレイアウトの構築. m_pipelineLayout = CreatePipelineLayout(device); // ビューポートステートの構築. m_viewportState = CreateViewportState(); // グラフィックスパイプラインを構築. m_graphicsPipeline = CreateGraphicsPipeline(device, vkctrl.GetControlRenderPass()); // 頂点バッファの作成. CreateVertexBuffer(device, args.PhysicalDevice); }
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); } }
protected void createCommandBuffers() { // Create one command buffer for each swap chain image and reuse for rendering drawCmdBuffers.Resize(Swapchain.ImageCount); drawCmdBuffers.Count = Swapchain.ImageCount; VkCommandBufferAllocateInfo cmdBufAllocateInfo = Initializers.CommandBufferAllocateInfo(cmdPool, VkCommandBufferLevel.Primary, drawCmdBuffers.Count); Util.CheckResult(vkAllocateCommandBuffers(device, ref cmdBufAllocateInfo, (VkCommandBuffer *)drawCmdBuffers.Data)); }
public static void AllocateCommandBuffers(VkCommandPool cmdPool, VkCommandBufferLevel level, uint count, VkCommandBuffer *cmdBuffers) { VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo { sType = VkStructureType.CommandBufferAllocateInfo }; cmdBufAllocateInfo.commandPool = cmdPool; cmdBufAllocateInfo.level = level; cmdBufAllocateInfo.commandBufferCount = count; VulkanUtil.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers)); }
/// <summary> /// Allocates single primary command buffer. /// When command buffers are first allocated, they are in the initial state. /// </summary> /// <returns>The command buffer in the Init state.</returns> public SecondaryCommandBuffer AllocateSecondaryCommandBuffer() { VkCommandBuffer buff; VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New(); infos.commandPool = handle; infos.level = VkCommandBufferLevel.Secondary; infos.commandBufferCount = 1; Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, out buff)); return(new SecondaryCommandBuffer(Dev.VkDev, this, buff)); }
private VkCommandBuffer GetPrimaryCommandBuffer() { VkCommandBufferAllocateInfo commandBufferAI = VkCommandBufferAllocateInfo.New(); commandBufferAI.commandBufferCount = 1; commandBufferAI.commandPool = _perFrameCommandPool; commandBufferAI.level = VkCommandBufferLevel.Primary; VkResult result = vkAllocateCommandBuffers(_device, ref commandBufferAI, out VkCommandBuffer ret); CheckResult(result); return(ret); }
public static VkCommandBufferAllocateInfo CommandBufferAllocateInfo( VkCommandPool commandPool, VkCommandBufferLevel level, uint bufferCount) { VkCommandBufferAllocateInfo commandBufferAllocateInfo = new VkCommandBufferAllocateInfo(); commandBufferAllocateInfo.sType = VkStructureType.CommandBufferAllocateInfo; commandBufferAllocateInfo.commandPool = commandPool; commandBufferAllocateInfo.level = level; commandBufferAllocateInfo.commandBufferCount = bufferCount; return(commandBufferAllocateInfo); }
public CommandBuffer AllocateCommandBuffer(VkCommandBufferLevel level = VkCommandBufferLevel.Primary) { VkCommandBuffer buff; VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New(); infos.commandPool = handle; infos.level = level; infos.commandBufferCount = 1; Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, out buff)); return(new CommandBuffer(Dev.VkDev, this, buff)); }
public FCommandBuffer(VkDevice device, int pool) { VkCommandBufferAllocateInfo pAllocateInfo = VkCommandBufferAllocateInfo.New(); pAllocateInfo.commandPool = CommandPoolManager.GetPool(pool); pAllocateInfo.level = VkCommandBufferLevel.Primary; pAllocateInfo.commandBufferCount = 1; VkCommandBuffer cmdBuffer = VkCommandBuffer.Null; Assert(vkAllocateCommandBuffers(device, &pAllocateInfo, &cmdBuffer)); buffer = cmdBuffer; }
private VkCommandBuffer CreateVulkanCommandBuffer() { VkCommandBuffer vulkanCommandBuffer; var commandBufferAllocateInfo = new VkCommandBufferAllocateInfo { sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, commandPool = VulkanCommandPool, commandBufferCount = 1, }; ThrowExternalExceptionIfNotSuccess(nameof(vkAllocateCommandBuffers), vkAllocateCommandBuffers(VulkanGraphicsDevice.VulkanDevice, &commandBufferAllocateInfo, (IntPtr *)&vulkanCommandBuffer)); return(vulkanCommandBuffer); }
internal VkCommandBuffer CreateCommandBufferSecondary() { VkCommandBufferAllocateInfo allocInfo = new VkCommandBufferAllocateInfo() { sType = VkStructureType.CommandBufferAllocateInfo, commandPool = NativeCommandPool, level = VkCommandBufferLevel.Secondary, commandBufferCount = 1, }; vkAllocateCommandBuffers(Device, ref allocInfo, out var commandBuffers); return(commandBuffers); }
public override VkResult AllocateCommandBuffers(VkCommandBufferAllocateInfo allocInfo, VkCommandBuffer[] commandBuffers) { VkResult result; for (int i = 0; i < allocInfo.commandBufferCount; i++) { VkCommandBuffer commandBuffer = null; result = AllocateCommandBuffer(allocInfo, out commandBuffer); if (result != VkResult.VK_SUCCESS) { return(result); } commandBuffers[i] = commandBuffer; } return(VkResult.VK_SUCCESS); }
protected override unsafe VkCommandBuffer CreateObject() { // No allocator ready to be used, let's create a new one var commandBufferAllocationInfo = new VkCommandBufferAllocateInfo { sType = VkStructureType.CommandBufferAllocateInfo, level = VkCommandBufferLevel.Primary, commandPool = commandPool, commandBufferCount = 1, }; VkCommandBuffer commandBuffer; vkAllocateCommandBuffers(GraphicsDevice.NativeDevice, &commandBufferAllocationInfo, &commandBuffer); return(commandBuffer); }
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); }
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(); } }
public CommandBuffer[] AllocateCommandBuffer(uint count, VkCommandBufferLevel level = VkCommandBufferLevel.Primary) { VkCommandBufferAllocateInfo infos = VkCommandBufferAllocateInfo.New(); infos.commandPool = handle; infos.level = level; infos.commandBufferCount = count; VkCommandBuffer[] buffs = new VkCommandBuffer[count]; Utils.CheckResult(vkAllocateCommandBuffers(Dev.VkDev, ref infos, buffs.Pin())); buffs.Unpin(); CommandBuffer[] cmds = new CommandBuffer[count]; for (int i = 0; i < count; i++) { cmds[i] = new CommandBuffer(Dev.VkDev, this, buffs[i]); } return(cmds); }
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); }
protected void createCommandBuffers() { // Create one command buffer for each swap chain image and reuse for rendering drawCmdBuffers = new VkCommandBuffer[Swapchain.ImageCount]; VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo(); cmdBufAllocateInfo.sType = CommandBufferAllocateInfo; cmdBufAllocateInfo.level = VkCommandBufferLevel.Primary; cmdBufAllocateInfo.commandBufferCount = (UInt32)drawCmdBuffers.Length; cmdBufAllocateInfo.commandPool = cmdPool; //vkAllocateCommandBuffers(device, & cmdBufAllocateInfo, (VkCommandBuffer*)drawCmdBuffers.Data); fixed(VkCommandBuffer *pointer = drawCmdBuffers) { vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, pointer); } }
public VkCommandBuffer BeginNewCommandBuffer() { VkCommandBufferAllocateInfo allocateInfo = VkCommandBufferAllocateInfo.New(); allocateInfo.commandBufferCount = 1; allocateInfo.level = VkCommandBufferLevel.Primary; allocateInfo.commandPool = _pool; VkResult result = vkAllocateCommandBuffers(_gd.Device, ref allocateInfo, out VkCommandBuffer cb); CheckResult(result); VkCommandBufferBeginInfo beginInfo = VkCommandBufferBeginInfo.New(); beginInfo.flags = VkCommandBufferUsageFlags.OneTimeSubmit; result = vkBeginCommandBuffer(cb, ref beginInfo); CheckResult(result); return(cb); }
private void Vkctrl_VulkanInitialized(object sender, SharpVulkanWpf.VulkanEventArgs args) { var device = args.Device; var commandPoolCreateInfo = new VkCommandPoolCreateInfo() { queueFamilyIndex = args.GraphicsQueueIndex, flags = VkCommandPoolCreateFlags.VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, }; VulkanAPI.vkCreateCommandPool(device, ref commandPoolCreateInfo, out m_commandPool); var allocateInfo = new VkCommandBufferAllocateInfo() { commandBufferCount = 1, commandPool = m_commandPool, }; VulkanAPI.vkAllocateCommandBuffers(device, ref allocateInfo, out m_commandBuffers); }
public VkCommandList(VkGraphicsDevice gd, ref CommandListDescription description) : base(ref description) { _gd = gd; VkCommandPoolCreateInfo poolCI = VkCommandPoolCreateInfo.New(); poolCI.queueFamilyIndex = gd.GraphicsQueueIndex; VkResult result = vkCreateCommandPool(_gd.Device, ref poolCI, null, out _pool); CheckResult(result); VkCommandBufferAllocateInfo cbAI = VkCommandBufferAllocateInfo.New(); cbAI.commandPool = _pool; cbAI.commandBufferCount = 1; cbAI.level = VkCommandBufferLevel.Primary; result = vkAllocateCommandBuffers(gd.Device, ref cbAI, out _cb); CheckResult(result); }
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(); } }