Commit 3d641ef
committed
VIDEO/VULKAN: Fix black GPU screenshots when HDR is enabled
When 'Screenshot: Use GPU' was enabled with the Vulkan driver and HDR
active, the resulting PNG was entirely black on both scRGB (FP16) and
HDR10 (RGB10A2 PQ) swapchains.
Two compounding issues in the HDR readback path:
1. gfx/drivers/vulkan.c hardcoded hdr_mode = 0 on the hdr_to_sdr
pipeline call. In vulkan_run_hdr_pipeline() that falls into the
legacy HDR10 branch (InverseTonemap = 1, HDR10 = 1). With an scRGB
backbuffer the shader then ran HDR10ToLinear() — ST.2084 decode —
on values that were never PQ-encoded, collapsing output to ~0.
Pass the actual encoding instead: 2 for scRGB, 1 for HDR10. Also
add an explicit COLOR_ATTACHMENT_WRITE -> TRANSFER_READ memory
barrier between the tonemap render pass and vkCmdCopyImageToBuffer.
The readback render pass has dependencyCount = 0, so its implicit
finalLayout transition does not carry a memory-availability
guarantee on its own.
2. gfx/drivers/vulkan_shaders/hdr_tonemap.frag called Tonemap(linear)
with one argument while the helper in hdr_common.glsl takes three
(hdr_linear, max_nits, paper_white_nits). The checked-in
hdr_tonemap.frag.inc was therefore stale SPIR-V from an older
single-argument signature, so the HDR10 readback path was also
broken independently of the scRGB issue.
Rewrite the shader to branch on HDRMode:
- Mode 1 (HDR10 PQ): HDR10ToLinear -> Tonemap() back to SDR
using paper_white_nits for both arguments (matching the
forward pass).
- Mode 2 (scRGB): divide by (BrightnessNits / 80) to undo
the scRGB nit scaling so SDR paper-white maps back to 1.0.
Apply the sRGB OETF before writing in both cases — the readback
target is B8G8R8A8_UNORM, not _SRGB, so without encoding the saved
PNG would be too dark in any standard sRGB viewer.
Regenerate hdr_tonemap.frag.inc from the new source.
Fixes #141471 parent 9e20d7e commit 3d641ef
3 files changed
Lines changed: 520 additions & 363 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6901 | 6901 | | |
6902 | 6902 | | |
6903 | 6903 | | |
| 6904 | + | |
| 6905 | + | |
| 6906 | + | |
| 6907 | + | |
| 6908 | + | |
| 6909 | + | |
| 6910 | + | |
| 6911 | + | |
| 6912 | + | |
6904 | 6913 | | |
6905 | 6914 | | |
6906 | 6915 | | |
| |||
6910 | 6919 | | |
6911 | 6920 | | |
6912 | 6921 | | |
6913 | | - | |
| 6922 | + | |
| 6923 | + | |
| 6924 | + | |
| 6925 | + | |
| 6926 | + | |
| 6927 | + | |
| 6928 | + | |
| 6929 | + | |
| 6930 | + | |
| 6931 | + | |
| 6932 | + | |
| 6933 | + | |
| 6934 | + | |
| 6935 | + | |
| 6936 | + | |
| 6937 | + | |
| 6938 | + | |
| 6939 | + | |
| 6940 | + | |
| 6941 | + | |
6914 | 6942 | | |
6915 | 6943 | | |
6916 | 6944 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
10 | 29 | | |
11 | 30 | | |
12 | 31 | | |
13 | | - | |
14 | | - | |
15 | | - | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
16 | 44 | | |
17 | | - | |
18 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
19 | 50 | | |
20 | | - | |
21 | | - | |
| 51 | + | |
22 | 52 | | |
23 | | - | |
24 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
25 | 56 | | |
26 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
27 | 60 | | |
0 commit comments