1
\$\begingroup\$

I'm creating my first Vulkan project and I'm at the point where I need to send commands to the GPU. Now I need help understanding how and when commands are being executed and what sort of commands can be sent. I have a working example of where I clear the screen using the following.

Creating the Buffer

VkCommandBufferAllocateInfo commandBufferAllocateInfo{};
commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
commandBufferAllocateInfo.commandPool = engine.pipeline.command_pool;
commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
commandBufferAllocateInfo.commandBufferCount = 1;


VkCommandBuffer commandBuffer = VK_NULL_HANDLE;

vkAllocateCommandBuffers(
    engine.device.instance,
    &commandBufferAllocateInfo,
    &commandBuffer
);

Clearing the screen

VkCommandBufferBeginInfo commandBufferBeginInfo{};
commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;

engine.ErrorCheck(vkBeginCommandBuffer(
    commandBuffer,
    &commandBufferBeginInfo
));

VkRect2D renderArea{};
renderArea.offset.x = 0;
renderArea.offset.y = 0;
renderArea.extent = window->GetVulkanSurfaceSize();

std::array<VkClearValue, 2> clearValues{};
// Depth stencil
clearValues[0].depthStencil.depth = 0.0f;
clearValues[0].depthStencil.stencil = 0;
// Color
clearValues[1].color.float32[0] = 0.0f;
clearValues[1].color.float32[1] = 0.0f;
clearValues[1].color.float32[2] = 1.0f;
clearValues[1].color.float32[3] = 0.0f;

VkRenderPassBeginInfo renderPassBeingInfo{};
renderPassBeingInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
renderPassBeingInfo.renderPass = engine.window.renderPass;
renderPassBeingInfo.framebuffer = engine.window.framebuffers[engine.window.activeSwapchainImageId]; // Get current frame buffer
renderPassBeingInfo.renderArea = renderArea;
renderPassBeingInfo.clearValueCount = clearValues.size();
renderPassBeingInfo.pClearValues = clearValues.data();

vkCmdBeginRenderPass(
    commandBuffer,
    &renderPassBeingInfo,
    VK_SUBPASS_CONTENTS_INLINE
);

I'm finding it difficult to understand. I see that when you define a CommandBuffer you point to the pool that it will be submitted to, then when you execute the command it gets added to the queue to be processed asynchronously with the logic that is happening CPU side? I'm not sure if that is right.

Also, can the command buffer be used for other commands? and if so, what commands and how would I find example usage of them.

And what is a command pool in the scheme of things that is happening?

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

CommandPool are objects used to manage the allocation of CommandBuffers, and CommandBuffer is used to store the commands.


You almost got the mechanic of a CommandBuffer right.

A command buffer doesn't point to the pool; in fact, a CommandPool allocates the memory for CommandBuffers. The pool isn't the place where a command will be submitted; the place we actually want to submit them is the Queue. We must provide the Queue pointers of all CommandBuffer objects, to be submitted in the struct VkSubmitInfo, and submit them using VkSubmitQueue. After that, the commands in the queue will be taken, and executed.

If you have time, check out some tutorials on Vulkan-Tutorial. It explains everything you need, including the type of commands CommandBuffer stores.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thank you for the suggestion of "Vulkan-Tutorial", I have the command buffers set up and have just finished creating the pipeline. They explain everything in an easy to understand, step by step format. Thanks! \$\endgroup\$
    – 0xen
    Jul 13, 2017 at 1:36
0
\$\begingroup\$

The command buffer only starts executing after you submit the buffer to a queue.

All vkCmd* functions will add a command to a command buffer. Every such command is annotated in the spec with where they are allowed to be used (primary command buffer, inside or outside a renderpass) and which queues capabilities it needs.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .