Commit f23eb89
authored
Vulkan/D3D11/D3D12: Add scRGB HDR support and fix HDR pipeline (#18759)
* D3D11/D3D12/Vulkan: Disable internal HDR10 conversion for RGBA16 output
When a shader preset's last pass explicitly outputs RGBA16, disable
the internal hdr10 conversion flag the same way RGB10A2 already does.
This lets the user's shader fully control HDR10/PQ output rather than
having the internal conversion applied on top.
* Refactor HDR setting: replace EnableHDR bool + Linearize with HDRMode uint enum
Replace the bool video_hdr_enable toggle and separate Linearize shader
uniform with a single HDRMode setting (0=Off, 1=HDR10, 2=scRGB).
Menu now shows HDR: Off/HDR10/scRGB instead of Enable HDR: ON/OFF.
Slang semantic renamed from EnableHDR (float) to HDRMode (uint).
Internal HDR pipeline shader updated to use HDRMode == 2u for scRGB path.
* Vulkan: Fix scRGB HDR pipeline mode using emits_hdr10/hdr16 flags
The runtime game_hdr_mode selection used back_buffer_format from
get_pass_rt_format() to decide between mode 2 (sRGB→scRGB) and
mode 3 (PQ→scRGB). However, the last pass's rt_format is overwritten
with the swapchain format in shader_vulkan.cpp, so it always returned
RGBA16F in scRGB mode regardless of the shader's #pragma format.
Use vulkan_filter_chain_emits_hdr10/hdr16() instead, which are set
before the rt_format overwrite and reliably reflect the shader's
declared output format.
* Vulkan/D3D: Add scRGB HDR pipeline with PQ→scRGB and sRGB→scRGB conversion
Add HDRMode enum to shaders (0=passthrough, 1=HDR10, 2=sRGB→scRGB,
3=PQ→scRGB). Swapchain format selection driven by menu HDR mode:
Off→B8G8R8A8, HDR10→A2B10G10R10+ST2084, scRGB→R16G16B16A16F+ExtLinearSRGB.
ConvertHDR10_To_scRGB() decodes PQ, converts Rec.2020→Rec.709, and
scales by 125 (10000/80 nits). GLSL and HLSL shaders updated in parallel.
* D3D12: Port scRGB HDR support and fix shader pass HDRMode semantic
- Port scRGB swapchain/format/colorspace selection from Vulkan driver
- Fix 16-bit format: UNORM→FLOAT for R16G16B16A16 swapchain
- Add HDR10↔scRGB mode change detection (triggers swapchain resize)
- Set hdr_mode UBO at all 3 HDR draw points (stock, back_buffer copy, menu)
- Fix back_buffer format to match shader's declared output (prevents
10-bit PQ data being quantised to 8-bit through R8G8B8A8 intermediate)
- Fix shader pass semantics: enable_hdr(float)→hdr_mode(unsigned) to match
SLANG_SEMANTIC_HDR (uint), and expand_gamut(float)→unsigned to match
SLANG_SEMANTIC_EXPAND_GAMUT (uint)
- Fix configuration.c: move video_hdr_mode from bool to uint settings section
* GLSL/HLSL: Rename ConvertHDR10_To_scRGB, add kscRGBWhiteNits constant
- Rename ConvertHDR10_To_scRGB() to HDR10ToscRGB()
- Add kscRGBWhiteNits = 80.0 constant (scRGB reference white)
- Replace all hardcoded 80.0 with kscRGBWhiteNits
- Replace hardcoded 125.0 with kMaxNitsFor2084 / kscRGBWhiteNits
* D3D11: Port scRGB HDR support and fix shader pass HDRMode semantic
Port all scRGB HDR changes from D3D12 driver to D3D11:
- Replace per-pass EnableHDR float with HDRMode uint semantic
- Fix 16-bit swapchain format (R16G16B16A16_FLOAT, not UNORM)
- Add swapchain bit depth selection: scRGB→16bit, HDR10→10bit
- Add scRGB colorspace (DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709)
- Dynamic swapchain resize on HDR mode changes (Off/HDR10/scRGB)
- Full hdr_mode logic in shader preset loading and HDR pipeline
- Mode-aware UBO values at all 3 upload sites (Point 1, Point 2,
menu/overlay composite) with proper save/restore of hdr_mode
- Per-pass HDRMode semantic uses video_info->hdr_mode (menu setting)
not pipeline conversion mode, so shaders see 1 for HDR10
* Vulkan/D3D: Add colour boost (ExpandGamut) to scRGB HDR path
The scRGB (HDRMode 2) non-scanlines path was ignoring the ExpandGamut
setting entirely. Now applies gamut conversion matching the "Colour
Boost" menu option:
0 (Accurate): k2020to709 — convert to clean Rec.709
1 (Expanded): kExpanded709to2020 * k2020to709 — slight saturation boost
2 (Wide): kP3to2020 * k2020to709 — wider boost
3 (Super): passthrough — no gamut conversion
Updated in hdr.frag (Vulkan) and hdr_sm5.hlsl.h (D3D11).
* GLSL/HLSL: Fix ExpandGamut matrices and scRGB scanline path
Replace incorrect gamut conversion matrices that treated Rec.709 input
AS the target colourspace (kP3to2020, kExpanded709to2020) with proper
709-to-target matrices (k709toP3, k709toExpanded709) computed as
k709to2020 * k2020toTarget.
Fix scRGB scanline path: skip InverseTonemap (HDR()) for HDRMode==2
since scRGB input is already in linear HDR, but keep LinearToSignal
gamma 2.4 encode needed for CRT scanline simulation.
Always apply k2020to709 back-conversion in scRGB paths regardless of
ExpandGamut level, so Super mode gives maximum colour boost (matching
HDR10 behaviour).
* D3D12/D3D11: Fix HDR pipeline format mismatch for scRGB
Fix D3D12 validation error where HDR pipeline state objects (PSOs) were
hardcoded to R10G10B10A2_UNORM but the scRGB swapchain uses
R16G16B16A16_FLOAT.
Extract HDR PSO creation into d3d12_gfx_init_hdr_pipes() which creates
both stock HDR shader pipes and sprite HDR pipes for a given render
target format. Called at init and dynamically recreated whenever the
swapchain format changes (e.g. switching between HDR10 and scRGB).
Fix D3D11/D3D12 hidden HDR pass detection: only insert a conversion
pass when the shader output has LOWER precision than the swapchain.
RGBA16F writing to a 10-bit HDR10 swapchain is just a precision
downsize the hardware handles naturally.1 parent 68c878b commit f23eb89
25 files changed
Lines changed: 2732 additions & 1707 deletions
File tree
- gfx
- common
- drivers_shader
- drivers
- d3d_shaders
- vulkan_shaders
- intl
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
500 | 500 | | |
501 | 501 | | |
502 | 502 | | |
503 | | - | |
504 | | - | |
| 503 | + | |
| 504 | + | |
505 | 505 | | |
506 | 506 | | |
507 | 507 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1920 | 1920 | | |
1921 | 1921 | | |
1922 | 1922 | | |
1923 | | - | |
1924 | 1923 | | |
1925 | 1924 | | |
1926 | 1925 | | |
| |||
2556 | 2555 | | |
2557 | 2556 | | |
2558 | 2557 | | |
| 2558 | + | |
2559 | 2559 | | |
2560 | 2560 | | |
2561 | 2561 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
385 | 386 | | |
386 | 387 | | |
387 | 388 | | |
| |||
690 | 691 | | |
691 | 692 | | |
692 | 693 | | |
693 | | - | |
694 | 694 | | |
695 | 695 | | |
696 | 696 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
569 | 569 | | |
570 | 570 | | |
571 | 571 | | |
572 | | - | |
| 572 | + | |
573 | 573 | | |
574 | 574 | | |
575 | 575 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2225 | 2225 | | |
2226 | 2226 | | |
2227 | 2227 | | |
2228 | | - | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
2229 | 2231 | | |
2230 | 2232 | | |
2231 | 2233 | | |
2232 | 2234 | | |
2233 | 2235 | | |
2234 | 2236 | | |
2235 | | - | |
| 2237 | + | |
2236 | 2238 | | |
2237 | | - | |
2238 | | - | |
| 2239 | + | |
| 2240 | + | |
2239 | 2241 | | |
2240 | | - | |
2241 | | - | |
2242 | | - | |
| 2242 | + | |
| 2243 | + | |
| 2244 | + | |
| 2245 | + | |
| 2246 | + | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
| 2263 | + | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
| 2274 | + | |
| 2275 | + | |
| 2276 | + | |
| 2277 | + | |
2243 | 2278 | | |
2244 | 2279 | | |
2245 | 2280 | | |
2246 | | - | |
| 2281 | + | |
| 2282 | + | |
2247 | 2283 | | |
2248 | 2284 | | |
2249 | 2285 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| 290 | + | |
| 291 | + | |
290 | 292 | | |
291 | 293 | | |
292 | 294 | | |
| |||
0 commit comments