Skip to content

Video: AV1 headers with reference frame state, AV1 film grain decode (stacked on #288) - #290

Merged
dzhdanNV merged 23 commits into
NVIDIA-RTX:mainfrom
Daedie-git:feat/video-av1-follow-ups
Oct 22, 2026
Merged

dzhdanNV merged 23 commits into
NVIDIA-RTX:mainfrom
Daedie-git:feat/video-av1-follow-ups

Conversation

@Daedie-git

@Daedie-git Daedie-git commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #288 (which is stacked on #265 and #264). Review only the last 2 commits. I'll rebase this PR once those merge.

These are the remaining follow-up gaps from the #264 review: AV1 headers that inherit state from reference frames, and AV1 film grain decode.

1. Shared: AV1 frame headers that inherit state from reference frames

The AV1 header parser rejected every frame header whose syntax depends on reference frames. libaom inter frames already failed on loop-filter deltas inherited from primary_ref_frame.

The caller now passes the state of the 8 reference slots: VideoAV1EncodeDecodeInfoDesc::savedFrameStates, indexed by refFrameIndex. The parser returns the parsed frame's state in VideoAV1EncodeDecodeInfo::savedFrameState, for the slots in refresh_frame_flags. A header that needs missing state is rejected. A header that inherits missing state it doesn't use returns an invalid saved state.

Newly parsed:

  • error-resilient INTER frames;
  • frame_refs_short_signaling (set_frame_refs);
  • frame_size_with_refs;
  • segmentation_params, coded or loaded, with segment ALT_Q included in CodedLossless;
  • loop-filter deltas of primary_ref_frame;
  • global motion relative to PrevGmParams, with invalid from setup_shear (DXVA wminvalid);
  • film_grain_params, including load_grain_params. The resolved parameters are returned in filmGrain, and apply_grain is restored from the reference.

The D3D12 metadata path fills savedFrameState too.

2. AV1 film grain decode

Sessions created with VideoSessionDesc::av1FilmGrain decode frames with APPLY_GRAIN. The output picture gets the film grain; the setup (reference) picture stays without it, so applying grain requires a distinct setup picture.

  • Vulkan: the session and its textures (TextureDesc::videoAV1FilmGrain) use an AV1 decode profile with filmGrainSupport. The distinct setup picture is allowed even if DPB_AND_OUTPUT_DISTINCT isn't advertised (VUIDs 07141 and 09249).
  • D3D12: film grain sessions require distinct decode output (D3D12: distinct decode output and reference-only DPB pictures (stacked on #265) #288). DXVA applies the grain to the conversion output.
  • Validation:
    • session and texture flags only for AV1 decode;
    • decode pictures and sessions must agree on the flag;
    • APPLY_GRAIN requires a film grain session, a distinct setup picture and in-range filmGrain parameters.

Not included

Explicit AV1 encode segmentation (D3D12 CUSTOM_SEGMENTATION) stays unsupported. The RTX 5080 doesn't support it, and requires AUTO_SEGMENTATION, so I can't verify a D3D12 path for it.

Verification

  • RTX 5080: libaom and SVT-AV1 streams decode bit-exact against dav1d on D3D12 and Vulkan, with the Khronos validation layer clean. The libaom streams use inherited loop-filter deltas; streams with film grain use update_grain = 1. Before this PR, the libaom inter frames failed at picture 1. Grain is really applied: the output differs from dav1d's no-grain decode (43 dB). The SVT streams on D3D12 also need the reference-frame-map fix (D3D12: AV1 decode gets the complete reference frame map (stacked on #288) #289).
  • NRISamples case matrix:
  • Tests: parser tests (a synthetic AV1 header writer) and validation tests are on my fork's test branch. Each rule was confirmed to make its test fail when removed.

🤖 Generated with Claude Code

BjornSAIM and others added 23 commits October 21, 2026 13:33
- TextureUsageBits::VIDEO_OUTPUT_ONLY for decode outputs / encode inputs
  that never act as DPB pictures (drivers requiring separate DPB images)
- H.264 SPS frame cropping (FRAME_CROPPING + crop offsets)
- VideoH265EncodePictureDesc to select VPS/SPS/PPS ids on encode
- VideoAV1DecodePictureDesc::skipModeFrames
- VideoAV1EncodeDecodeInfoDesc::pictureDesc/av1PictureDesc for the
  metadata-only (no payload header) reconstruction path
- documented H.265 generalLevelIdc units and H.264 frame reference flags
- documented AV1 encode txMode 0 (backend default), AV1 decode orderHints indexing
  and the decode setup slot contract

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- reject encode feedback readback buffers that are not CPU-visible
  (track MemoryLocation on BufferVal for bound, committed and placed buffers)
- VIDEO_OUTPUT_ONLY textures: require a video usage, forbid combining with
  VIDEO_REFERENCE_ONLY, forbid reference pictures and coincident DPB setup
- H.264 SPS frame cropping range checks (session parameters, Annex-B writer)
- H.265 encode VPS/SPS/PPS selection must exist in the session parameters
- AV1 decode SKIP_MODE_PRESENT requires valid, referenced skipModeFrames
- AV1 encode decode-info: require pictureDesc/av1PictureDesc and a CPU-visible
  readback buffer when no payload header is provided
- decode setup slot / encode reconstructed slot must not be a current reference
- AV1: bound distinct reference slots (names may share a slot); require all 7
  reference names for inter frame decode

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AV1 GetEncodeDecodeInfoFromHeader (single spec-ordered frame header parser
replacing the separate key/inter parsers):
- read delta_frame_id_minus_1 per reference; allow_high_precision_mv gated on
  force_integer_mv
- quantization: NumPlanes (mono_chrome), diff_uv_delta and V deltas; NumPlanes
  gating for loop filter, CDEF and loop restoration
- 128x128 superblocks in tile info and single-tile layouts
- loop restoration: Remap_Lr_Type, lr_unit_shift/lr_uv_shift, USES_LR flags
- byte_alignment before the tile group of an OBU_FRAME
- inter tail order: reference mode, skip mode (fills skipModeFrames),
  allow_warped_motion, reduced_tx_set, global motion
- superres MiCols from the downscaled width; intrabc only without superres
- honor key-frame frame size override; parse delta_lf params
- reject film grain with apply_grain, reduced still picture headers and
  nonzero byte-alignment padding
- keep enable_ref_frame_mvs/enable_jnt_comp consistent without order hints

Annex-B writer: H.264 SPS frame cropping; reject invalid frame id lengths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- decode: always pass the validated setup slot when the session has DPB
  slots (VUID-VkVideoDecodeInfoKHR-pSetupReferenceSlot-07168)
- decode H.265: slice segment offsets point at the 3-byte start code
  (+1 instead of +4); sort StCurrBefore/StCurrAfter by POC
- encode: track rate control state and apply changes with
  vkCmdControlVideoCodingKHR (VUID-...-08254); constantQp only for CQP
  (08269/08272)
- encode H.265: select VPS/SPS/PPS ids from h265PictureDesc (08231-08233);
  convert generalLevelIdc from bitstream units to StdVideoH265LevelIdc and
  pick spec-correct default levels
- encode H.264: num_ref_idx_active_override_flag; SPS frame cropping
- AV1 decode: pass interpolation filter and tx mode through, OrderHints and
  expectedFrameId by reference name, SkipModeFrame, setup SavedOrderHints
  from the current frame's OrderHints
- AV1 encode: signal loop filter ref/mode delta updates
- GetTextureMemoryDesc2: chain the video profile list like texture creation
  (RADV crashed without it)
- VIDEO_OUTPUT_ONLY usage (DST/SRC only); query DST and DPB usage separately
  and report coincide/distinct decode modes from the driver (fixes decode
  being reported unsupported on RADV)
- encode feedback: fail instead of dereferencing an unmapped buffer
- H.264 decode: a frame reference with both field flags has no std field flags
- AV1 encode: txMode 0 keeps the default; keep the app's seq_force_screen_content_tools
  and fail with UNSUPPORTED if driver overrides change the sequence header that
  WriteVideoAV1ObuHeaders writes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- legacy barriers: per-layer/mip barriers on planar formats (NV12/P010/P016)
  transition every plane (debug layer id 538)
- decode: advertise D3D12_VIDEO_DECODE_MIN_BITSTREAM_OFFSET_ALIGNMENT
  (debug layer id 1110)
- AV1 decode: pass interp_filter and tx_mode through, filter_intra from the
  sequence, order_hint_bits 0 without order hints, warped_motion from the
  frame flag, derive tile sizes for uniform layouts without size arrays
  (null dereference)
- AV1 encode: key frames always refresh 0xFF; set driver-required picture
  control flags (frame segmentation auto, force integer MV); pass explicit
  interpolation filter / CDEF damping values through
- AV1 metadata-only decode info: frame type, order hint, refresh flags,
  frame id and interpolation filter from the submitted picture desc;
  bitstreamOffset relative to encodedBitstreamOffset
- rate control: enable QP range, initial QP, max frame size and VBV flags
  when values are supplied and supported by the encoder
- H.264 decode: UsedForReferenceFlags = 3 for frame references
- H.265 decode: sort StCurrBefore/StCurrAfter by POC; spec default scaling
  lists when enabled without list data
- H.265 encode: PPS id from h265PictureDesc
- encode feedback: don't read unmapped buffers; null-check descs
- barriers: PlaneBits::COLOR on multi-planar formats covers all planes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e output pictures

CmdDecodeVideo accepts a DECODE_OUTPUT picture (not OUTPUT_ONLY) as a decode
reference or setup picture, GetVideoPictureState rejected the same roles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A session with DPB slots requires pSetupReferenceSlot for every encode
(VVL: pSetupReferenceSlot is NULL but the session was created with maxDpbSlots).
B frames and AV1 pictures with refreshFrameFlags = 0 passed none. The std
is_reference flag still follows the frame type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…buffer is re-recorded

NVIDIA (610.57.04) reads the chained codec picture structures after
vkCmdDecodeVideoKHR returned: H.264 decode with 3 or more references crashed
in vkQueueSubmit2 (null pointer in the driver, depends on the stack contents).
The structures and arrays chained into the decode command now live in
per-command-buffer storage, released by Begin and the destructor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NVIDIA (610.57) ignored the bitrate without it: 8 H.264 frames took 4045 bytes
for 300 and 80000 kbit/s alike, with the range they take 16 KB and 481 KB.
qpMin/qpMax were ignored by the Vulkan backend (D3D12 applies them), the
default is the full codec range. A QP range change is a rate control change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The offsets landed on the NAL header (+4 of the documented 4-byte start code),
H.265 was fixed to +1 already. NVIDIA 580.142 (RTX 3080) decoded every H.264
picture as garbage (4.8 dB), ffmpeg decodes the same stream at 43.6 dB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The header parser stored cdef_y/uv_sec_strength with the AV1 3 -> 4
adjustment applied. Vulkan expects the coded value 0..3 and adjusts it
itself: NVIDIA 580.142 decoded SVT-AV1 streams with luma errors of up to 3
in every picture that has a coded strength of 3 (bit-exact once the coded
value is passed).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The driver writes the slice headers with log2_max_frame_num, pic_order_cnt_type and log2_max_pic_order_cnt_lsb from the GOP structure, which was hardwired to 0, so a SPS with other values (as the Vulkan path accepts) produced undecodable streams.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ences differ from the PPS defaults

The driver writes slice headers without the override flag unless it is requested, so P pictures with more than one reference (and B pictures) decoded with the wrong list sizes. The H.265 active counts are passed as well.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
H.264/H.265 encode set no_output_of_prior_pics_flag on every IDR. With
reordered B pictures, a conformant decoder (ffmpeg) then dropped the last
pictures before the IDR (2 of 20 frames of a BBBP stream with idr period 7).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The NVIDIA workaround passed 0/51 (AV1 1/255) when qpMin/qpMax were omitted.
That leaves the advertised capability range (Intel ANV: minQp 10,
VUID useMinQp-08286). Keep the queried minQp/maxQp (H.264/H.265) and
minQIndex/maxQIndex (AV1) on the session, use them for omitted bounds and
clamp explicit bounds to them. The range is still always enabled.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… slots

reconstructedPicture is documented as required when maxReferenceNum > 0, also
for non-reference pictures (B, AV1 refreshFrameFlags = 0), but a null one was
forwarded and the Vulkan backend then passed no setup slot
(VUID-vkCmdEncodeVideoKHR-pEncodeInfo-08377). This replaces the AV1-only
check. Sessions without DPB slots are unchanged. Adds VID-REG-031 and the
missing pictures in three existing validation tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Zero is not a level and has no native Vulkan enum (it became STD_VIDEO_H265_LEVEL_IDC_INVALID), and the Annex B writer would code it as is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Like H.265 level 0, H.264 levelIdc 0 (and level 1b, coded as 9) has no native Vulkan level and became STD_VIDEO_H264_LEVEL_IDC_INVALID; the Annex B writer would code it as is. Both session parameters and the validated Annex B writer now reject it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On NVIDIA (driver 610.57.04, RTX 5080) vkCmdCopyQueryPoolResults on a
VK_QUERY_TYPE_VIDEO_ENCODE_FEEDBACK_KHR pool never completes on graphics or
compute queues (WAIT_BIT hangs the queue, otherwise VK_ERROR_DEVICE_LOST).
Reproduced with a minimal NRI-free Vulkan program that is clean under the
validation layers.

CmdResolveVideoEncodeFeedback now only records the query index; the results
are fetched on the host with vkGetQueryPoolResults (64-bit, WITH_STATUS) in
GetVideoEncodeFeedback, which returns FAILURE while the query is not ready.
The resolved metadata range shrinks accordingly (no device-side results).

The same driver writes the offset and the size as packed 32-bit values when
VK_QUERY_RESULT_64_BIT is requested (status lands in the third 64-bit slot), so
NVIDIA reads them as 32-bit and caps "bitstreamSizeMax" of encode sessions to
UINT32_MAX; Validation now also checks "dstBitstream.size" against it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
D3D12 decode only supported coincide mode: a distinct setup picture never
received the reconstructed frame, because ConversionArguments was not set, and
configurations requiring reference-only allocations were rejected.

Distinct mode is now advertised when D3D12_FEATURE_VIDEO_DECODE_CONVERSION_SUPPORT
reports a same-format conversion without colour conversion whose output size
range includes the decode size, and DecodeVideo routes the reconstructed
picture to the setup picture through ConversionArguments. Configurations with
REFERENCE_ONLY_ALLOCATIONS_REQUIRED are accepted when distinct mode is
supported; they advertise only distinct mode and the new
VideoCapabilities::decodeReferenceOnlyRequired, and Validation then requires
VIDEO_REFERENCE_ONLY textures for the setup and reference pictures. Tier 1
decoders advertise dpbTextureArrayRequired. Validation requires a distinct
setup picture to have the extent of the output picture (no scaling).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GetVideoAV1EncodeDecodeInfo (and the shared header parser) rejected every frame
header whose syntax depends on reference frames: libaom inter frames already
failed on loop filter deltas inherited from primary_ref_frame. The caller now
passes the state of the 8 reference slots ("savedFrameStates", indexed by
refFrameIndex), and the parser returns the state of the parsed frame
("savedFrameState") for the slots in refresh_frame_flags. A header that needs
missing state is rejected; one that inherits missing state without needing it
returns an invalid saved state.

Newly parsed: error resilient INTER frames (implied PRIMARY_REF_NONE,
ref_order_hint), frame_refs_short_signaling (set_frame_refs),
frame_size_with_refs, segmentation_params (coded or loaded), loop filter
deltas of primary_ref_frame, global motion parameters relative to
PrevGmParams, and film_grain_params (update_grain or load_grain_params; the
resolved parameters are returned in "filmGrain"). The D3D12 metadata path
fills "savedFrameState" too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AV1 decode rejected every sequence with film_grain_params_present. Sessions
created with "VideoSessionDesc::av1FilmGrain" now decode frames with
"APPLY_GRAIN": the output picture gets the film grain, the setup (reference)
picture stays without it, so applying grain requires a distinct setup picture.

- Vulkan: the session and the textures ("TextureDesc::videoAV1FilmGrain") use
  an AV1 decode profile with "filmGrainSupport"; "GetVideoCapabilities" with
  such a session desc reports whether the profile is supported.
- D3D12: DXVA applies the film grain to the output of the decode conversion
  ("ConversionArguments" route the reconstructed picture to the setup
  picture); film grain sessions require distinct decode output support.
- Validation: "av1FilmGrain" only for AV1 decode sessions and
  "videoAV1FilmGrain" only for AV1 decode textures, pictures and decode
  sessions must agree on it (encode profiles don't have it), "APPLY_GRAIN"
  requires such a session, a distinct setup picture (also if distinct mode
  isn't advertised otherwise) and valid "filmGrain" parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-21T14:51:55.738633Z
We couldn’t complete this review. Comment @codex review to try again.
ad2a6b4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dzhdanNV

Copy link
Copy Markdown
Collaborator

And the last one is merged too. Even if there are issues, it's not a problem: we can continue from the new much better baseline.

@dzhdanNV
dzhdanNV merged commit e516543 into NVIDIA-RTX:main Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants