Function Prototype

vkCmdSetViewport

Set the viewport dynamically for a command buffer
primary / secondary
both
graphics
state

To dynamically set the viewport transformation parameters, call:

void vkCmdSetViewport(
    VkCommandBuffer commandBuffer,
    uint32_t firstViewport,
    uint32_t viewportCount,
    const VkViewport* pViewports);
  • commandBuffer is the command buffer into which the command will be recorded.
  • firstViewport is the index of the first viewport whose parameters are updated by the command.
  • viewportCount is the number of viewports whose parameters are updated by the command.
  • pViewports is a pointer to an array of VkViewport structures specifying viewport parameters.

This command sets the viewport transformation parameters state for subsequent drawing commands when drawing using shader objects, or when the graphics pipeline is created with VK_DYNAMIC_STATE_VIEWPORT set in VkPipelineDynamicStateCreateInfo::pDynamicStates. Otherwise, this state is specified by the VkPipelineViewportStateCreateInfo::pViewports values used to create the currently active pipeline.

The viewport parameters taken from element i of pViewports replace the current state for the viewport index firstViewport + i, for i in [0, viewportCount).

Valid Usage

VUID-vkCmdSetViewport-firstViewport-01223

The sum of firstViewport and viewportCount must be between 1 and VkPhysicalDeviceLimits::maxViewports, inclusive

VUID-vkCmdSetViewport-firstViewport-01224

If the multiViewport feature is not enabled, firstViewport must be 0

VUID-vkCmdSetViewport-viewportCount-01225

If the multiViewport feature is not enabled, viewportCount must be 1

Valid Usage (Implicit)

VUID-vkCmdSetViewport-pViewports-parameter

pViewports must be a valid pointer to an array of viewportCount valid VkViewport structures

VUID-vkCmdSetViewport-commandBuffer-cmdpool

The VkCommandPool that commandBuffer was allocated from must support graphics operations

VUID-vkCmdSetViewport-videocoding

This command must only be called outside of a video coding scope

VUID-vkCmdSetViewport-viewportCount-arraylength

viewportCount must be greater than 0

Host Synchronization

  • Host access to commandBuffer must be externally synchronized
  • Host access to the VkCommandPool that commandBuffer was allocated from must be externally synchronized ::