Multi-Views and Multi-Scissors in command buffer recording

Hello,
I set viewport and scissor dynamic when creating pipeline
Also, set 2 viewports and 2 scissors

In BuildCommandBuffers function, I did below

		VkViewport viewports[2] = {
			{ (float)width / 2.0f, 0, (float)width / 2.0f, (float)height, 0.0, 1.0f },
			{ 0, 0, (float)width / 2.0f, (float)height, 0.0, 1.0f },
		};
		vkCmdSetViewport(drawCmdBuffers[i], 0, 2, viewports);

		VkRect2D scissorRects[2] = {
			vks::initializers::rect2D(width/2, height, width / 2, 0),
			vks::initializers::rect2D(width/2, height, 0, 0),
		};
		vkCmdSetScissor(drawCmdBuffers[i], 0, 2, scissorRects);

		and Draw something ...

But this does not work. The screen only draw one among two viewports

However, in the tutorial ViewportArray.cpp
this tutorial can draw two viewports at the same time with shader programming

Moreover, though I can use two different viewports in one commandbuffer recording
I can only use one scissor working in one recording

If I try to use two different scissors in one recording, the second scissor is ignored

So my question is
without following ViewportArray tutorial
can I draw multi-viewports and multi-scissors ?

Thank you

Well, you need to somehow tell the GPU that you want to render to multiple viewports simultaneously and where to output, and that requires doing something at the shader level. Either the way it’s done in (I guess my) viewport array sample with a geometry shader, or by using a newer feature called multiview. See this sample for how that’s done using a view mask telling the GPU you want to broadcast to multiple viewports.

1 Like

Hello, Sascha
OK, I understand now.
I saw multiview sample which use one viewport, but I will study that
Have a nice weekend

I looked through your sample a couple of weeks ago, and didn’t understand the view masks and how I would go about implementing runtime dynamic viewports (at some point..). So I kept testing other ways. One of the options I found was this:

// One scissor for the whole client area
vkCmdSetScissor(cmdBuffer, 0, 1, &mv.scissor);

bindPipeline(cmdBuffer, ...);
bindDescriptorSets(cmdBuffer, ...);

// Viewport 1
vkCmdSetViewport(cmdBuffer, 0, 1, &mv.viewports[0]);
bindBuffers(...);
drawIndexed(...);

// Viewport 2
/* optionally bind different pipeline/descriptor sets */
vkCmdSetViewport(cmdBuffer, 0, 1, &mv.viewports[2]);
bindBuffers(...);
drawIndexed(...);

// more viewports...

Not ideal, but an option for a smaller scene, I guess.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.