Class NVDeviceGeneratedCommands

java.lang.Object
org.lwjgl.vulkan.NVDeviceGeneratedCommands

public class NVDeviceGeneratedCommands extends Object
This extension allows the device to generate a number of critical graphics commands for command buffers.

When rendering a large number of objects, the device can be leveraged to implement a number of critical functions, like updating matrices, or implementing occlusion culling, frustum culling, front to back sorting, etc. Implementing those on the device does not require any special extension, since an application is free to define its own data structures, and just process them using shaders.

However, if the application desires to quickly kick off the rendering of the final stream of objects, then unextended Vulkan forces the application to read back the processed stream and issue graphics command from the host. For very large scenes, the synchronization overhead and cost to generate the command buffer can become the bottleneck. This extension allows an application to generate a device side stream of state changes and commands, and convert it efficiently into a command buffer without having to read it back to the host.

Furthermore, it allows incremental changes to such command buffers by manipulating only partial sections of a command stream — for example pipeline bindings. Unextended Vulkan requires re-creation of entire command buffers in such a scenario, or updates synchronized on the host.

The intended usage for this extension is for the application to:

  • create VkBuffer objects and retrieve physical addresses from them via GetBufferDeviceAddressEXT
  • create a graphics pipeline using VkGraphicsPipelineShaderGroupsCreateInfoNV for the ability to change shaders on the device.
  • create a VkIndirectCommandsLayoutNV, which lists the VkIndirectCommandsTokenTypeNV it wants to dynamically execute as an atomic command sequence. This step likely involves some internal device code compilation, since the intent is for the GPU to generate the command buffer in the pipeline.
  • fill the input stream buffers with the data for each of the inputs it needs. Each input is an array that will be filled with token-dependent data.
  • set up a preprocess VkBuffer that uses memory according to the information retrieved via GetGeneratedCommandsMemoryRequirementsNV.
  • optionally preprocess the generated content using CmdPreprocessGeneratedCommandsNV, for example on an asynchronous compute queue, or for the purpose of re-using the data in multiple executions.
  • call CmdExecuteGeneratedCommandsNV to create and execute the actual device commands for all sequences based on the inputs provided.

For each draw in a sequence, the following can be specified:

  • a different shader group
  • a number of vertex buffer bindings
  • a different index buffer, with an optional dynamic offset and index type
  • a number of different push constants
  • a flag that encodes the primitive winding

While the GPU can be faster than a CPU to generate the commands, it will not happen asynchronously to the device, therefore the primary use case is generating “less” total work (occlusion culling, classification to use specialized shaders, etc.).

Example Code

Open-Source samples illustrating the usage of the extension can be found at the following location (may not yet exist at time of writing):

https://github.com/nvpro-samples/vk_device_generated_cmds

Name String
VK_NV_device_generated_commands
Extension Type
Device extension
Registered Extension Number
278
Revision
3
Extension and Version Dependencies
Version 1.1 and VK_KHR_buffer_device_address or Version 1.2
Contact
Other Extension Metadata
Last Modified Date
2020-02-20
Interactions and External Dependencies
  • This extension requires Vulkan 1.1
  • This extension requires VK_EXT_buffer_device_address or VK_KHR_buffer_device_address or Vulkan 1.2 for the ability to bind vertex and index buffers on the device.
  • This extension interacts with VK_NV_mesh_shader. If the latter extension is not supported, remove the command token to initiate mesh tasks drawing in this extension.
Contributors
  • Christoph Kubisch, NVIDIA
  • Pierre Boudier, NVIDIA
  • Jeff Bolz, NVIDIA
  • Eric Werness, NVIDIA
  • Yuriy O’Donnell, Epic Games
  • Baldur Karlsson, Valve
  • Mathias Schott, NVIDIA
  • Tyson Smith, NVIDIA
  • Ingo Esser, NVIDIA