Swapchain images being rescaled rather than clipped with MoltenVK

105 views Asked by At

I'm trying to implement window scaling with a dynamic viewport in MoltenVK, by creating oversized swapchain images and calling vkCmdSetViewport. But the entire swapchain image is being scaled down to fit the window, rather than kept at 100% scale and clipped. Where is this scaling happening, and how can I disable it?

If it helps, I'm using the Rust crates winit to create a window and raw-window-metal to create a Metal layer.

1

There are 1 answers

1
Nicol Bolas On

Vulkan has the VK_KHR_display_swapchain extension, which allows specifying both a source and destination rectangle for presenting a swapchain image. If that extension is not available to you, then you can't control scaling.

It's a new extension and is not widely available at present. So for most practical purposes, you only have the default Vulkan behavior: the entire swapchain image will be copied to the entire surface area, with scaling if the two are not matched.

The best you can do is a manual solution. You can effectively undo the scaling by adjusting your projection matrices such that they negate the scaling done by the display engine. That is, if your surface is half the width and height of the swapchain image, magnify your projection matrices' X and Y scaling by a factor of 2.