Draw calls and command streams

Draw calls

In the VkCV framework there are different kinds of draw calls. But in this case you want to use an InstanceDrawcall. This specific kind will only need a VertexData object an the amount of instances (which defaults to 1 because you won't need instancing fow now).

vkcv::VertexData vertexData; // a new vertex data object

// setting the vertex count to 3 (remember the vertex shader?)
vertexData.setCount(3);

// a new instance drawcall to draw the specified data once
vkcv::InstanceDrawcall drawcall (vertexData);

That's it. You don't need anything more because the vertex shader will already take care of positions and vertex colors for your triangle.


Command streams

Command streams are another abstraction of the VkCV framework. In Vulkan you would use command buffers which are managed via pre-allocated command pools for your device's queues. Here all this resource management gets out of your way and you can simply create a command stream selecting the preferred queue type, record your commands and other layout transitions to finally submit the command stream. After submission the recorded command stream will write to an available queue of specified type and your commands will be processed.

The following code takes the created pipeline, draw call and window to define the exact behavior as wanted. Additionally it creates an image handle to specify the swapchain image of the given window as render target for the draw call. The recording of draw calls is also the step where you would pass data for your push constants to be used in the shaders (in this case the vertex shader). For now it's fine to pass the identity matrix as value for the model-view-projection matrix.

#include <glm/glm.hpp>
// create an image handle for our swapchain image
const auto swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();

// create a new command stream to be used with a graphics queue
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);

core.recordDrawcallsToCmdStream(
  cmdStream,                   // command stream
  gfxPipeline,                 // graphics pipeline
  
  // push constants as template of type 'glm::mat4'
  vkcv::pushConstants<glm::mat4>(
  	glm::identity<glm::mat4>() // model-view-projection matrix for now
  ),
  
  { drawcall },                // vector of instance drawcalls to record
  { swapchainInput },          // render targets to attach as image handles
  windowHandle                 // window handle to select the surface
);

// after drawing the swapchain image will be prepared for presentation
core.prepareSwapchainImageForPresent(cmdStream);

core.submitCommandStream(cmdStream); // submit the command stream

You have probably noticed that the swapchain image needs to be prepared for presentation after drawing. But what is this presentation? You can think of it as final step in your rendering process when drawing to a surface:

  • 1. Step: Attaching the swapchain image
  • 2. Step: Clearing and writing to the swapchain image
  • 3. Step: Transitioning the layout of the swapchain image for presentation on the surface

The last step makes sure that no data will be written to the image anymore. So there won't be any problem with parallel access during the process of bringing its content to the surface of window. Notice that there are multiple ways for swapchains in Vulkan to present images onto a surface. However in the VkCV framework you can simply expect VSync to be always enabled with priority on lower latency.

Previous

Next

Popular posts from this blog

Introduction

Application development

First setup