Skip to content

[vk-video] Make encoding coding control and rate control codec-generic.#1840

Open
jerzywilczek wants to merge 1 commit intovv-codec-genericsfrom
@jerzywilczek/vv-codec-generic-coding-control
Open

[vk-video] Make encoding coding control and rate control codec-generic.#1840
jerzywilczek wants to merge 1 commit intovv-codec-genericsfrom
@jerzywilczek/vv-codec-generic-coding-control

Conversation

@jerzywilczek
Copy link
Collaborator

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR makes Vulkan encoding rate-control and coding-control paths codec-generic by moving codec-specific Vulkan rate control structs behind the EncodeCodec trait, instead of hard-coding H.264 logic in VulkanEncoder.

Changes:

  • Add codec-generic rate control associated types + factory methods to EncodeCodec.
  • Move H.264 rate control layer/info construction into H264Codec’s EncodeCodec impl.
  • Update VulkanEncoder to build and push codec-specific rate control via C::codec_rate_control_* and remove H.264-specific helpers.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
vk-video/src/vulkan_encoder.rs Switch rate-control/coding-control setup to codec-generic calls; remove H.264-only helpers.
vk-video/src/codec/h264/encode.rs Implement the new codec-specific rate control hooks for H.264.
vk-video/src/codec.rs Extend EncodeCodec with codec-specific rate control associated types and constructors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1240 to +1253
layer_info = layer_info
.average_bitrate(average_bitrate)
.max_bitrate(max_bitrate)
.push_next(&mut h264_layer_info[0])
.push_next(&mut codec_layer_info[0])
}

RateControl::ConstantBitrate { bitrate, .. } => {
layer_info = layer_info
.average_bitrate(bitrate)
.max_bitrate(bitrate)
.push_next(&mut h264_layer_info[0])
.push_next(&mut codec_layer_info[0])
}

RateControl::Disabled => layer_info = layer_info.push_next(&mut h264_layer_info[0]),
RateControl::Disabled => layer_info = layer_info.push_next(&mut codec_layer_info[0]),
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rate_control_layers_for assumes the codec-specific layer-info slice is non-empty and unconditionally indexes [0]. Since EncodeCodec::codec_rate_control_layer_info returns Option<Vec<_>> with no guarantee that Some contains at least one element, this can panic at runtime (and also silently ignores additional layers if a codec provides more than one). Consider either enforcing/documenting a 1-layer contract at the trait level (e.g., return a single layer info), or iterating over all provided codec layers and generating matching VideoEncodeRateControlLayerInfoKHR entries; at minimum, use get_mut(0) and return None/error when empty.

Copilot uses AI. Check for mistakes.
Comment on lines +83 to +92
type CodecRateControlLayerInfo<'a>: vk::ExtendsVideoEncodeRateControlLayerInfoKHR;
type CodecRateControlInfo<'a>: vk::ExtendsVideoBeginCodingInfoKHR
+ vk::ExtendsVideoCodingControlInfoKHR;
fn codec_rate_control_layer_info<'a>(
rate_control: RateControl,
) -> Option<Vec<Self::CodecRateControlLayerInfo<'a>>>;
fn codec_rate_control_info<'a>(
layers: Option<&'a [vk::VideoEncodeRateControlLayerInfoKHR<'a>]>,
idr_period: u32,
) -> Option<Self::CodecRateControlInfo<'a>>;
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new EncodeCodec::codec_rate_control_layer_info API returns Option<Vec<_>>, but callers currently assume (1) Some implies at least one element and (2) only the first element is used to build VideoEncodeRateControlLayerInfoKHR. To avoid future panics and ambiguous multi-layer semantics for codec implementers, consider tightening the trait contract (e.g., return a single layer info, or specify that the vector must be non-empty and that its length must match the temporal layer count the codec will report).

Copilot uses AI. Check for mistakes.
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.

3 participants