<p>Both suggested methods are fine, but they should be preferred in certain situations.</p>

<p>Dynamic state should be preferred in situations where you have many, perhaps thousands of, pipeline objects or you need to change the resolution often (such as in some sort of windowed tool. The downside to this is that it may reduce runtime performance since the driver may not be able apply optimizations for this.</p>

<p>Having the viewport only defined when building the pipeline objects might be more appropriate for games or simulators where you don't change the resolution often. Of course, when the viewport does change, it hits performance hard during resizing. This also has the drawback of needing to generate new pipeline objects, which could be especially problematic if you cache pipelines in a hash table of something similar.</p>

CC BY-SA 3.0
2017-10-18T11:14:24.923Z
You could have a backup dynamic viewport pipeline object for use during resize until the finalized pipeline object with fixed viewport is ready.
ratchet freak
CC BY-SA 3.0
2017-10-18T03:43:39.957Z
2017-10-18T03:43:39.957Z
aces
<p>I have discovered that there are two ways to update the viewport (might be more, but not sure). Currently I am rebuilding the Pipeline when I resize my screen but there is a noticeable stutter as it rebuilds, but I have also found out that you can use <code>vkCmdSetViewport</code> when building/rebuilding your command buffers. But is this the right way to do it? And if I used <code>vkCmdSetViewport</code>, what should be put into the <code>VkGraphicsPipelineCreateInfo pViewportState</code>?</p>

<p>If there is an even better way of handling screen resizing please let me know.</p>

<c++><vulkan>
Vulkan best way of updating pipeline viewport
0xen
# Vulkan best way of updating pipeline viewport

(Asked by: username_0 on 2017-10-18)

I have discovered that there are two ways to update the viewport (might be more, but not sure). Currently I am rebuilding the Pipeline when I resize my screen but there is a noticeable stutter as it rebuilds, but I have also found out that you can use `vkCmdSetViewport` when building/rebuilding your command buffers. But is this the right way to do it? And if I used `vkCmdSetViewport`, what should be put into the `VkGraphicsPipelineCreateInfo pViewportState`?

If there is an even better way of handling screen resizing please let me know.

**Tags:** c++, vulkan


---

## 1 answers

### Answer by username_1 on 2017-10-18. Score: 5

Both suggested methods are fine, but they should be preferred in certain situations.

Dynamic state should be preferred in situations where you have many, perhaps thousands of, pipeline objects or you need to change the resolution often (such as in some sort of windowed tool. The downside to this is that it may reduce runtime performance since the driver may not be able apply optimizations for this.

Having the viewport only defined when building the pipeline objects might be more appropriate for games or simulators where you don't change the resolution often. Of course, when the viewport does change, it hits performance hard during resizing. This also has the drawback of needing to generate new pipeline objects, which could be especially problematic if you cache pipelines in a hash table of something similar.

> **Comments:**
> **username_2**: You could have a backup dynamic viewport pipeline object for use during resize until the finalized pipeline object with fixed viewport is ready.  

---

