-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(Vulkan) Implement HDR viewport readback #16525
Conversation
Sounds great!
You can always use homebrew, like the 240p test suite, which we have available for many cores via the online updater's content downloader. |
Cool, I noticed that this happened sometime ago and that this was missing from the initial Vulkan HDR implementation indeed. |
One quick question about |
Right now the PR unmodified crashes on macOS at startup in vkQueueSubmit just after printing this error:
I'll look into why. (Just to rule things out, |
Great point! I've updated the PR description |
That would be the correct behavior, yes. The current logic does not check if the extension is supported, but I'll make it work |
Maybe try ending the command buffer and starting a new one just for the readback pipeline? Could be there's some state that isn't flushed until queue submit. |
Done. I added an extra context flag for HDR support, and gated all HDR-related functionality behind it. As a bonus, the driver will no longer attempt to reinitialize HDR pipelines every frame if HDR is enabled in the settings but disabled in the OS, something which I noticed could cause a lot of slowdown. |
Thanks. So I think the current issue is the issues on Mac with MoltenVK, not sure how to really proceed there. I assume the other platforms are fine so far. |
I think I might have caught the issue with MoltenVK. When creating pipelines, the |
It works! |
Description
This PR adds HDR support for screenshots (aka viewport reading, aka readback) to the Vulkan video driver.
This is implemented on the GPU by running a pipeline which converts the HDR10 pixels in the backbuffer to BGRA8 format through a fragment shader which also applies tonemapping if necessary. The resulting image buffer is saved to an image using already-existing scaler logic for SDR screenshots.
If the currently active filter chain does not emit HDR10, the driver already applies SDR->HDR inverse tonemapping to the image as a final pass before submitting it to the swapchain. I thought it would be wasteful to then immediately tonemap the image back to the original result when taking a screenshot, so in these instances the original linear-space SDR image is used as a source for format conversion, and tonemapping is skipped.
Some light refactoring of HDR-relevant code is included in this PR for convenience of implementation. Embedded HDR shaders have also been refactored so that (inverse) tonemapping and related HDR utilities are all defined in one shader file,
hdr_common.glsl
, which is then#include
d by both the tonemapping and inverse tonemapping fragment shaders. I also explicitly enabled theVK_EXT_swapchain_colorspace
extension, as the Vulkan validation layers were complaining about undefined constants on swapchain creation.No explicit reference is made in the code to specific swapchain formats such as
A2R10G10B10
orA2B10G10R10
, so the implementation should be format-agnostic, but so far I only tested it on my machine which supportsA2R10G10B10
only.Screenshots
The following screenshots are of the SMPTE Color Bars from the SNES 240p test ROM. Click to zoom on both as these are 4k screenshots and (especially the shader one) will show artifacts when scaled.
No shaders active, reading directly from SDR buffer:
Using the crt-sony-megatron-default-hdr shader, which emits HDR10 colors:
Related Pull Requests
#16435: Original PR in which this feature was requested.
Reviewers
@warmenhoven @MajorPainTheCactus