D3D11VA: P010 R16_UNORM sampling needs storage-aware YUV offsets and scaling

Author: StardustLuoCreated Sep 30, 2026Updated Sep 30, 2026

Describe the bug

The 10-bit CSC improvements discussed in #1667 and implemented in 50223dbdb89a95139201d6fdf8b7efb88a35c3cd correct the use of 8-bit offsets. However, the current D3D11VA P010 path appears to retain a smaller normalization mismatch: CSC constants assume samples normalized as code / 1023, while P010 viewed as R16_UNORM/R16G16_UNORM produces code * 64 / 65535.

Y410 viewed as R10G10B10A2_UNORM does use code / 1023, so the adjustment should be specific to the texture format rather than applied to all 10-bit content.

Public source evidence

Source examined at commit 8369d1a0e11b999d4d1598f62ca5f6dea49602fb:

Microsoft P010 documentation describes 10-bit values in 16-bit words with the low six bits zero. A neutral chroma code of 512 is therefore stored as 32768 and sampled as 32768 / 65535, not 512 / 1023.

Minimal numerical reproduction

python
code = 512
sample = (code << 6) / 65535
current_offset = 512 / 1023
current_chroma = (sample - current_offset) * (1023 / 896)
expected_chroma = (code - 512) / 896
print(sample, current_offset, current_chroma, expected_chroma)

Output:

0.5000076295109483 0.5004887585532747 -0.0005493247882810707 0.0

A theoretically neutral P010 sample thus produces negative Cb and Cr. The BT.2020 inverse matrix lowers red/blue and raises green relative to neutral. This full-precision calculation isolates normalization; actual min16float operations can introduce additional rounding.

Expected behavior / possible fix

For 10-bit limited-range P010:

Y  = (Y_code - 64) / 876
Cb = (Cb_code - 512) / 896
Cr = (Cr_code - 512) / 896

For actual R16_UNORM samples, the equivalent constants are:

Y offset  = 4096 / 65535
UV offset = 32768 / 65535
Y scale   = 65535 / (876 * 64)
UV scale  = 65535 / (896 * 64)

One option is to adjust generic CSC constants on the CPU for P010 storage. Relative to existing code/1023 constants, let k = 65535 / (1023 * 64): divide offsets by k and multiply the CSC matrix by k. Alternatively multiply sampled P010 values by k before using existing constants. Preserve fractional samples from filtering; integer rounding is unnecessary. NV12 and Y410 should retain their format-appropriate normalization.

Validation scope

This report is based on public source inspection and the numerical reproduction; it does not claim a live test of a master build. A regression check could exercise limited-range P010 black/white and a neutral ramp (Cb = Cr = 512), alongside NV12 and Y410, checking that reconstructed RGB channels remain equal for neutral inputs.

Source: moonlight-stream/moonlight-qt