feat(client): HDR pass-through on the D3D11VA path

A PQ stream on the D3D11VA backend was always tone-mapped to sRGB by the
VideoProcessor — with D3D11VA now auto's first choice on Intel (40030e90),
Intel Windows users would have lost HDR entirely. When the presenter can
import an RGB10A2 D3D11 texture AND offers an HDR10 swapchain (the new
VulkanDecodeDevice::d3d11_hdr10 probe), the hand-off ring switches to
RGB10A2 and the VideoProcessor does a pure colorspace conversion (YCbCr
G2084 -> RGB G2084, no tone mapping); the emitted frame carries PQ/BT.2020
color, so the presenter flips its HDR10 swapchain and video image exactly
as it does for Vulkan Video PQ frames, and the blit passes the PQ values
through untouched. SDR-only paths keep the tonemap-to-sRGB BGRA8 ring;
in-band PQ flips rebuild the ring like a resize (generation-bumped).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-19 14:19:35 +02:00
parent 40030e90c8
commit fb8deb31a5
5 changed files with 143 additions and 46 deletions
+29 -12
View File
@@ -1,6 +1,7 @@
//! D3D11 shared-texture → Vulkan import (Windows): the presenter half of the D3D11VA
//! decode path (`pf_client_core::video_d3d11`). Each decoded frame arrives as the NT
//! handle of a shareable **BGRA8** texture (the decoder's VideoProcessor already did
//! handle of a shareable single-plane RGB texture — **BGRA8** sRGB normally, **RGB10A2**
//! PQ for the HDR pass-through flavor (the decoder's VideoProcessor already did
//! YUV→RGB); we import it as a single-plane VkImage (`VK_KHR_external_memory_win32`,
//! dedicated allocation) and the presenter blits it straight into its video image — no
//! CSC pass. Single-plane RGBA is deliberate: importing the earlier multiplanar NV12
@@ -28,31 +29,41 @@ pub const DEVICE_EXTENSIONS: [&std::ffi::CStr; 2] = [
ash::khr::win32_keyed_mutex::NAME,
];
/// Can this device import a D3D11 BGRA8 texture as a blit source? The spec-required
/// Can this device import a D3D11 texture of `format` as a blit source? The spec-required
/// capability probe for the exact image the import path creates — creating an external
/// image the driver doesn't support is undefined behavior (observed as
/// `VK_ERROR_DEVICE_LOST` at the first submits with the old NV12 hand-off).
pub fn import_supported(instance: &ash::Instance, pdev: vk::PhysicalDevice) -> bool {
fn format_importable(
instance: &ash::Instance,
pdev: vk::PhysicalDevice,
format: vk::Format,
) -> bool {
let mut ext_info = vk::PhysicalDeviceExternalImageFormatInfo::default()
.handle_type(vk::ExternalMemoryHandleTypeFlags::D3D11_TEXTURE);
let fmt_info = vk::PhysicalDeviceImageFormatInfo2::default()
.format(vk::Format::B8G8R8A8_UNORM)
.format(format)
.ty(vk::ImageType::TYPE_2D)
.tiling(vk::ImageTiling::OPTIMAL)
.usage(vk::ImageUsageFlags::TRANSFER_SRC)
.push_next(&mut ext_info);
let mut ext_props = vk::ExternalImageFormatProperties::default();
let mut props = vk::ImageFormatProperties2::default().push_next(&mut ext_props);
let ok = unsafe {
instance.get_physical_device_image_format_properties2(pdev, &fmt_info, &mut props)
}
.is_ok()
unsafe { instance.get_physical_device_image_format_properties2(pdev, &fmt_info, &mut props) }
.is_ok()
&& ext_props
.external_memory_properties
.external_memory_features
.contains(vk::ExternalMemoryFeatureFlags::IMPORTABLE);
tracing::info!(bgra8 = ok, "D3D11 texture → Vulkan import support");
ok
.contains(vk::ExternalMemoryFeatureFlags::IMPORTABLE)
}
/// The two hand-off flavors' import support: `.0` = BGRA8 (the SDR ring — gates the whole
/// D3D11VA path), `.1` = RGB10A2 (the HDR PQ ring — gates only the pass-through flavor;
/// without it a PQ stream keeps the decoder-side tonemap to BGRA8).
pub fn import_supported(instance: &ash::Instance, pdev: vk::PhysicalDevice) -> (bool, bool) {
let bgra8 = format_importable(instance, pdev, vk::Format::B8G8R8A8_UNORM);
let rgb10 = format_importable(instance, pdev, vk::Format::A2B10G10R10_UNORM_PACK32);
tracing::info!(bgra8, rgb10, "D3D11 texture → Vulkan import support");
(bgra8, rgb10)
}
/// One imported frame: the BGRA8 image over the shared texture and its imported
@@ -98,7 +109,13 @@ pub fn import(
if std::env::var_os("PUNKTFUNK_HW_FAULT").is_some_and(|v| v == "import") {
bail!("injected import failure (PUNKTFUNK_HW_FAULT=import)");
}
let mp_format = vk::Format::B8G8R8A8_UNORM;
// DXGI R10G10B10A2 and Vulkan A2B10G10R10_PACK32 are the same bit layout (R in the
// low bits) — the standard interop pairing, same as BGRA8 ↔ B8G8R8A8.
let mp_format = if frame.rgb10 {
vk::Format::A2B10G10R10_UNORM_PACK32
} else {
vk::Format::B8G8R8A8_UNORM
};
let handle_type = vk::ExternalMemoryHandleTypeFlags::D3D11_TEXTURE;
// One single-plane image over the whole texture, transfer-source only — the blit is
+5 -4
View File
@@ -239,11 +239,12 @@ impl Presenter {
);
}
// D3D11 frame: acquire the imported BGRA texture from the external "queue
// D3D11 frame: acquire the imported RGB texture from the external "queue
// family" (the keyed mutex on the submit is the actual cross-API sync) and
// blit it into the video image — the frame arrives as ready sRGB from the
// decoder's VideoProcessor, so there is no CSC pass; the blit converts the
// BGRA→RGBA component order. Same layout dance as the CPU staging path.
// blit it into the video image — the frame arrives as ready RGB from the
// decoder's VideoProcessor (sRGB BGRA8, or PQ RGB10A2 on the HDR ring —
// matching the HDR-mode video image), so there is no CSC pass; the blit
// converts component order. Same layout dance as the CPU staging path.
#[cfg(windows)]
if let (Some(f), Some(v)) = (&win_frame, &self.video) {
external_acquire_barrier(&self.device, self.cmd_buf, f.image(), self.qfi);
+14 -2
View File
@@ -94,8 +94,9 @@ impl Presenter {
// (vkGetPhysicalDeviceImageFormatProperties2 — creating an unsupported external
// image is UB, observed as VK_ERROR_DEVICE_LOST at the first submits on NVIDIA).
#[cfg(windows)]
let win_capable = crate::d3d11::DEVICE_EXTENSIONS.iter().all(|n| has(n))
&& crate::d3d11::import_supported(&instance, pdev);
let (import_bgra8, import_rgb10) = crate::d3d11::import_supported(&instance, pdev);
#[cfg(windows)]
let win_capable = crate::d3d11::DEVICE_EXTENSIONS.iter().all(|n| has(n)) && import_bgra8;
#[cfg(windows)]
if win_capable {
dev_exts.extend(crate::d3d11::DEVICE_EXTENSIONS.iter().map(|n| n.as_ptr()));
@@ -392,14 +393,25 @@ impl Presenter {
d3d11_import: win_capable,
#[cfg(not(windows))]
d3d11_import: false,
// Filled in below — the HDR10 surface facts arrive with pick_formats.
d3d11_hdr10: false,
adapter_luid,
queue_lock: queue_lock.clone(),
})
} else {
None
};
#[cfg(windows)]
let mut video_export = video_export;
let (format, hdr10_format) = pick_formats(&surface_i, pdev, surface, has_colorspace_ext)?;
// The D3D11VA backend may emit its HDR (RGB10 PQ) ring only when this device can
// import the 10-bit texture AND the surface offers an HDR10 swapchain to pass it
// through to; otherwise a PQ stream keeps the decoder-side tonemap to sRGB.
#[cfg(windows)]
if let Some(v) = video_export.as_mut() {
v.d3d11_hdr10 = win_capable && import_rgb10 && hdr10_format.is_some();
}
let present_mode = pick_present_mode(&surface_i, pdev, surface)?;
tracing::info!(
?format,