Taking large screenshots in Vulkan

Started by
2 comments, last by taby 1 year ago

Does anyone have code to take large screenshots in Vulkan?

I found Sascha Willems' screenshot code, and I tried altering it so that it makes a large screenshot (say, 6400x6400 pixels), but it either crashes or gives a blank result.

Does anyone have any experience with this?

Advertisement

At a very basic level you could just increase all framebuffer resolutions for a frame (or however long you need for the screenshot), but this may cause a handful of issues for resolutions higher than “standard” ones like 4k:

  1. Your device may not support framebuffers / textures at that high of a resolution
  2. You may run out of memory allocating such high-resolution framebuffers (a single 6400x6400 rgba8 texture is 156 MiB, now imagine a g-buffer with a bunch of channels…)

I can't speak to how other engines work, but the engine I work with takes high-res screenshots over multiple frames by pausing the game clock, switching to a supported, standard screen resolution (e.g. 1080p), and taking 1 screenshot per frame over multiple frames. Each frame the camera is shifted by a single pixel and then the resulting images are composited by interleaving the pixels to form the higher-res image. For example, to create a 4k screenshot we take 4 1080p screenshots and combine them like so:

Frame 1    Frame 2    Frame 3    Frame 4    Result
1 1        2 2        3 3        4 4        1 2 1 2
1 1        2 2        3 3        4 4        3 4 3 4
                                            1 2 1 2
                                            3 4 3 4

I'll admit that this is fairly complex and our renderer needs to account for this type of screenshot in a handful of places (temporal effects, etc. that could get confused) but it means we can take very high-res screenshots without needing to use higher-resolution framebuffers.

I tried doing the onscreen framebuffer, but no luck… it just generates a black image. I’m certain that the key is to render to an offscreen framebuffer. It doesn’t help that I am a total beginner at Vulkan.

Thanks for your time and experaise.

This topic is closed to new replies.

Advertisement