// Copyright 2018-2023 The Khronos Group Inc.
//
// SPDX-License-Identifier: CC-BY-4.0

[[encode-h264]]
== Encode H.264

The `apiext:VK_EXT_video_encode_h264` extension adds H.264 codec specific
structures/types needed to support H.264 encoding.
Unless otherwise noted, all references to the H.264 specification are to the
2010 edition published by the ITU-T, dated March 2010.
This specification is available at https://www.itu.int/rec/T-REC-H.264.

[NOTE]
.Note
====
Refer to the <<preamble, Preamble>> for information on how the Khronos
Intellectual Property Rights Policy relates to normative references to
external materials not created by Khronos.
====


=== H.264 Encode Profile

[open,refpage='VkVideoEncodeH264ProfileInfoEXT',desc='Structure specifying H.264 encode profile',type='structs']
--
The sname:VkVideoEncodeH264ProfileInfoEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264ProfileInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:stdProfileIdc is a code:StdVideoH264ProfileIdc value specifying
    the H.264 codec profile IDC.

An H.264 encode profile is specified by including a
sname:VkVideoEncodeH264ProfileInfoEXT structure in the pname:pNext chain of
the slink:VkVideoProfileInfoKHR structure when
slink:VkVideoProfileInfoKHR::pname:videoCodecOperation is
ename:VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT.

include::{generated}/validity/structs/VkVideoEncodeH264ProfileInfoEXT.adoc[]
--


=== Capabilities

[open,refpage='VkVideoEncodeH264CapabilitiesEXT',desc='Structure specifying H.264 encode capabilities',type='structs']
--
When calling flink:vkGetPhysicalDeviceVideoCapabilitiesKHR with
pname:pVideoProfile->videoCodecOperation specified as
ename:VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT, the
slink:VkVideoEncodeH264CapabilitiesEXT structure must: be included in the
pname:pNext chain of the slink:VkVideoCapabilitiesKHR structure to retrieve
more capabilities specific to H.264 video encoding.

The slink:VkVideoEncodeH264CapabilitiesEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264CapabilitiesEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is a bitmask of elink:VkVideoEncodeH264CapabilityFlagBitsEXT
    indicating supported H.264 encoding capabilities.
  * pname:maxLevelIdc is a code:StdVideoH264LevelIdc value indicating the
    maximum H.264 level supported.
  * pname:maxSliceCount indicates the maximum number of slices that can: be
    encoded for a single picture.
    Further restrictions may: apply to the number of slices that can: be
    encoded for a single picture depending on other capabilities and
    codec-specific rules.
  * pname:maxPPictureL0ReferenceCount indicates the maximum number of
    reference pictures the implementation supports in the reference list L0
    for P pictures.
  * pname:maxBPictureL0ReferenceCount indicates the maximum number of
    reference pictures the implementation supports in the reference list L0
    for B pictures.
    The reported value is `0` if encoding of B pictures is not supported.
  * pname:maxL1ReferenceCount reports the maximum number of reference
    pictures the implementation supports in the reference list L1 if
    encoding of B pictures is supported.
    The reported value is `0` if encoding of B pictures is not supported.
  * pname:maxTemporalLayerCount indicates the maximum number of H.264
    temporal layers supported by the implementation.
  * pname:expectDyadicTemporalLayerPattern indicates that the
    implementation's rate control algorithms expect the application to use a
    dyadic temporal layer pattern when encoding multiple temporal layers.
  * pname:minQp indicates the minimum QP value supported.
  * pname:maxQp indicates the maximum QP value supported.
  * pname:prefersGopRemainingFrames indicates that the implementation's rate
    control algorithm prefers the application to specify the number of
    frames of each type remaining in the current group of pictures.
  * pname:requiresGopRemainingFrames indicates that the implementation's
    rate control algorithm requires the application to specify the number of
    frames of each type remaining in the current group of pictures.
  * pname:stdSyntaxFlags is a bitmask of
    elink:VkVideoEncodeH264StdFlagBitsEXT indicating capabilities related to
    H.264 syntax elements.

When flink:vkGetPhysicalDeviceVideoCapabilitiesKHR is called to query the
capabilities with parameter pname:videoCodecOperation specified as
ename:VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT, a
sname:VkVideoEncodeH264CapabilitiesEXT structure can: be chained to
slink:VkVideoCapabilitiesKHR to retrieve H.264 extension specific
capabilities.

include::{generated}/validity/structs/VkVideoEncodeH264CapabilitiesEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264CapabilityFlagBitsEXT',desc='Video encode H.264 capability flags',type='enums']
--
Bits which may: be set in
slink:VkVideoEncodeH264CapabilitiesEXT::pname:flags, indicating the
supported H.264 encoding capabilities, are:

include::{generated}/api/enums/VkVideoEncodeH264CapabilityFlagBitsEXT.adoc[]

  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_HRD_COMPLIANCE_BIT_EXT indicates
    if the implementation guarantees generating a HRD compliant bitstream if
    code:nal_hrd_parameters_present_flag or
    code:vcl_hrd_parameters_present_flag are enabled in
    code:StdVideoH264SpsVuiFlags.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_PREDICTION_WEIGHT_TABLE_GENERATED_BIT_EXT
    indicates that when code:weighted_pred_flag is enabled or
    code:STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_EXPLICIT from
    code:StdVideoH264WeightedBipredIdc is used, the implementation is able
    to internally decide syntax for code:pred_weight_table.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_ROW_UNALIGNED_SLICE_BIT_EXT
    indicates that each slice in a frame with multiple slices may begin or
    finish at any offset in a macroblock row.
    If not supported, all slices in the frame must: begin at the start of a
    macroblock row (and hence each slice must: finish at the end of a
    macroblock row).
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_DIFFERENT_SLICE_TYPE_BIT_EXT
    indicates that when a frame is encoded with multiple slices, the
    implementation allows encoding each slice with a different
    code:StdVideoEncodeH264SliceHeader::code:slice_type.
    If not supported, all slices of the frame must: be encoded with the same
    code:slice_type which corresponds to the picture type of the frame.
    For example, all slices of a P-frame would be encoded as P-slices.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L0_LIST_BIT_EXT
    indicates support for using a B frame as L0 reference.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_B_FRAME_IN_L1_LIST_BIT_EXT
    indicates support for using a B frame as L1 reference.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_PER_PICTURE_TYPE_MIN_MAX_QP_BIT_EXT
    indicates support for specifying different QP values in the members of
    slink:VkVideoEncodeH264QpEXT.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_PER_SLICE_CONSTANT_QP_BIT_EXT
    indicates support for specifying different constant QP values for each
    slice.
  * ename:VK_VIDEO_ENCODE_H264_CAPABILITY_GENERATE_PREFIX_NALU_BIT_EXT
    indicates support for generating prefix NALUs by setting
    slink:VkVideoEncodeH264PictureInfoEXT::pname:generatePrefixNalu to
    ename:VK_TRUE.
--

[open,refpage='VkVideoEncodeH264CapabilityFlagsEXT',desc='Bitmask of VkVideoEncodeH264CapabilityFlagBitsEXT',type='flags']
--
include::{generated}/api/flags/VkVideoEncodeH264CapabilityFlagsEXT.adoc[]

tname:VkVideoEncodeH264CapabilityFlagsEXT is a bitmask type for setting a
mask of zero or more elink:VkVideoEncodeH264CapabilityFlagBitsEXT.
--

[open,refpage='VkVideoEncodeH264StdFlagBitsEXT',desc='Video encode H.264 syntax capability flags',type='enums']
--
Bits which may: be set in
slink:VkVideoEncodeH264CapabilitiesEXT::pname:stdSyntaxFlags, indicating the
capabilities related to the H.264 syntax elements, are:

include::{generated}/api/enums/VkVideoEncodeH264StdFlagBitsEXT.adoc[]

  * ename:VK_VIDEO_ENCODE_H264_STD_SEPARATE_COLOR_PLANE_FLAG_SET_BIT_EXT
    indicates if enabling code:separate_colour_plane_flag in
    code:StdVideoH264SpsFlags is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_QPPRIME_Y_ZERO_TRANSFORM_BYPASS_FLAG_SET_BIT_EXT
    indicates if enabling code:qpprime_y_zero_transform_bypass_flag in
    code:StdVideoH264SpsFlags is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_SCALING_MATRIX_PRESENT_FLAG_SET_BIT_EXT
    indicates if enabling code:seq_scaling_matrix_present_flag in
    code:StdVideoH264SpsFlags or code:pic_scaling_matrix_present_flag in
    code:StdVideoH264PpsFlags are supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_CHROMA_QP_INDEX_OFFSET_BIT_EXT indicates
    if setting non-zero code:chroma_qp_index_offset in
    code:StdVideoH264PictureParameterSet is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_SECOND_CHROMA_QP_INDEX_OFFSET_BIT_EXT
    indicates if setting non-zero code:second_chroma_qp_index_offset in
    code:StdVideoH264PictureParameterSet is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_PIC_INIT_QP_MINUS26_BIT_EXT indicates if
    setting non-zero code:pic_init_qp_minus26 in
    code:StdVideoH264PictureParameterSet is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_WEIGHTED_PRED_FLAG_SET_BIT_EXT indicates
    if enabling code:weighted_pred_flag in code:StdVideoH264PpsFlags is
    supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_WEIGHTED_BIPRED_IDC_EXPLICIT_BIT_EXT
    indicates if using code:STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_EXPLICIT from
    code:StdVideoH264WeightedBipredIdc is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_WEIGHTED_BIPRED_IDC_IMPLICIT_BIT_EXT
    indicates if using code:STD_VIDEO_H264_WEIGHTED_BIPRED_IDC_IMPLICIT from
    code:StdVideoH264WeightedBipredIdc is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_TRANSFORM_8X8_MODE_FLAG_SET_BIT_EXT
    indicates if enabling code:transform_8x8_mode_flag in
    code:StdVideoH264PpsFlags is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_DIRECT_SPATIAL_MV_PRED_FLAG_UNSET_BIT_EXT
    indicates if disabling
    code:StdVideoEncodeH264SliceHeaderFlags::code:direct_spatial_mv_pred_flag
    is supported when it is present in the slice header.
  * ename:VK_VIDEO_ENCODE_H264_STD_ENTROPY_CODING_MODE_FLAG_UNSET_BIT_EXT
    indicates if CAVLC entropy coding is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_ENTROPY_CODING_MODE_FLAG_SET_BIT_EXT
    indicates if CABAC entropy coding is supported.
    An implementation must: support at least one entropy coding mode.
  * ename:VK_VIDEO_ENCODE_H264_STD_DIRECT_8X8_INFERENCE_FLAG_UNSET_BIT_EXT
    indicates if disabling code:direct_8x8_inference_flag in
    code:StdVideoH264SpsFlags is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_CONSTRAINED_INTRA_PRED_FLAG_SET_BIT_EXT
    indicates if enabling code:constrained_intra_pred_flag in
    code:StdVideoH264PpsFlags is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_DEBLOCKING_FILTER_DISABLED_BIT_EXT
    indicates if using
    code:STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_DISABLED from
    StdVideoH264DisableDeblockingFilterIdc is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_DEBLOCKING_FILTER_ENABLED_BIT_EXT
    indicates if using
    code:STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_ENABLED from
    StdVideoH264DisableDeblockingFilterIdc is supported.
  * ename:VK_VIDEO_ENCODE_H264_STD_DEBLOCKING_FILTER_PARTIAL_BIT_EXT
    indicates if using
    code:STD_VIDEO_H264_DISABLE_DEBLOCKING_FILTER_IDC_PARTIAL from
    StdVideoH264DisableDeblockingFilterIdc is supported.
    An implementation must: support at least one deblocking filter mode.
  * ename:VK_VIDEO_ENCODE_H264_STD_SLICE_QP_DELTA_BIT_EXT indicates whether
    the implementation supports using the application-provided value for
    code:StdVideoEncodeH264SliceHeader::code:slice_qp_delta when that value
    is identical across the slices of the encoded frame.
  * ename:VK_VIDEO_ENCODE_H264_STD_DIFFERENT_SLICE_QP_DELTA_BIT_EXT
    indicates whether the implementation supports using the
    application-provided value for
    code:StdVideoEncodeH264SliceHeader::code:slice_qp_delta when that value
    is different across the slices of the encoded frame.
--

[open,refpage='VkVideoEncodeH264StdFlagsEXT',desc='Bitmask of VkVideoEncodeH264StdFlagBitsEXT',type='flags']
--
include::{generated}/api/flags/VkVideoEncodeH264StdFlagsEXT.adoc[]

tname:VkVideoEncodeH264StdFlagsEXT is a bitmask type for setting a mask of
zero or more elink:VkVideoEncodeH264StdFlagBitsEXT.
--


=== H.264 Encode Quality Level Properties

[open,refpage='VkVideoEncodeH264QualityLevelPropertiesEXT',desc='Structure describing the H.264 encode quality level properties',type='structs']
--
When calling flink:vkGetPhysicalDeviceVideoEncodeQualityLevelPropertiesKHR
with pname:pVideoProfile->videoCodecOperation specified as
ename:VK_VIDEO_CODEC_OPERATION_ENCODE_H264_BIT_EXT, the
slink:VkVideoEncodeH264QualityLevelPropertiesEXT structure can: be included
in the pname:pNext chain of the slink:VkVideoEncodeQualityLevelPropertiesKHR
structure to retrieve additional video encode quality level properties
specific to H.264 encoding.

The slink:VkVideoEncodeH264QualityLevelPropertiesEXT structure is defined
as:

include::{generated}/api/structs/VkVideoEncodeH264QualityLevelPropertiesEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:preferredRateControlFlags is a bitmask of
    elink:VkVideoEncodeH264RateControlFlagBitsEXT values indicating the
    preferred flags to use for
    slink:VkVideoEncodeH264RateControlInfoEXT::pname:flags.
  * pname:preferredGopFrameCount indicates the preferred value to use for
    slink:VkVideoEncodeH264RateControlInfoEXT::pname:gopFrameCount.
  * pname:preferredIdrPeriod indicates the preferred value to use for
    slink:VkVideoEncodeH264RateControlInfoEXT::pname:idrPeriod.
  * pname:preferredConsecutiveBFrameCount indicates the preferred value to
    use for
    slink:VkVideoEncodeH264RateControlInfoEXT::pname:consecutiveBFrameCount.
  * pname:preferredTemporalLayerCount indicates the preferred value to use
    for slink:VkVideoEncodeH264RateControlInfoEXT::pname:temporalLayerCount.
  * pname:preferredConstantQp indicates the preferred values to use for
    slink:VkVideoEncodeH264NaluSliceInfoEXT::pname:constantQp for each
    picture type when using rate control mode
    ename:VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR.
  * pname:preferredMaxL0ReferenceCount indicates the preferred maximum
    number of reference pictures to use in the reference list L0.
  * pname:preferredMaxL1ReferenceCount indicates the preferred maximum
    number of reference pictures to use in the reference list L1.
  * pname:preferredStdEntropyCodingModeFlag indicates the preferred value to
    use for code:entropy_coding_mode_flag in code:StdVideoH264PpsFlags.

include::{generated}/validity/structs/VkVideoEncodeH264QualityLevelPropertiesEXT.adoc[]
--


=== H.264 Encode Session

Additional parameters can be specified when creating a video session with an
H.264 encode profile by including an instance of the
slink:VkVideoEncodeH264SessionCreateInfoEXT structure in the pname:pNext
chain of slink:VkVideoSessionCreateInfoKHR.

[open,refpage='VkVideoEncodeH264SessionCreateInfoEXT',desc='Structure specifies H.264 encode session parameters',type='structs']
--
The sname:VkVideoEncodeH264SessionCreateInfoEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264SessionCreateInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:useMaxLevelIdc indicates whether the value of pname:maxLevelIdc
    should be used by the implementation.
    When it is set to ename:VK_FALSE, the implementation ignores the value
    of pname:maxLevelIdc and uses the value of
    slink:VkVideoEncodeH264CapabilitiesEXT::pname:maxLevelIdc, as reported
    by flink:vkGetPhysicalDeviceVideoCapabilitiesKHR for the video profile.
  * pname:maxLevelIdc provides the upper bound on the H.264 level for the
    video bitstreams produced by the created video session.

include::{generated}/validity/structs/VkVideoEncodeH264SessionCreateInfoEXT.adoc[]
--


=== Encoder Parameter Sets

To reduce parameter traffic during encoding, the encoder parameter set
object supports storing H.264 SPS/PPS parameter sets that may: be later
referenced during encoding.

[open,refpage='VkVideoEncodeH264SessionParametersCreateInfoEXT',desc='Structure specifies H.264 encoder parameter set information',type='structs']
--
The slink:VkVideoEncodeH264SessionParametersCreateInfoEXT structure is
defined as:

include::{generated}/api/structs/VkVideoEncodeH264SessionParametersCreateInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:maxStdSPSCount is the maximum number of SPS parameters that the
    sname:VkVideoSessionParametersKHR can contain.
  * pname:maxStdPPSCount is the maximum number of PPS parameters that the
    sname:VkVideoSessionParametersKHR can contain.
  * pname:pParametersAddInfo is `NULL` or a pointer to a
    sname:VkVideoEncodeH264SessionParametersAddInfoEXT structure specifying
    H.264 parameters to add upon object creation.

include::{generated}/validity/structs/VkVideoEncodeH264SessionParametersCreateInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264SessionParametersAddInfoEXT',desc='Structure specifies H.264 encoder parameter set information',type='structs']
--
The sname:VkVideoEncodeH264SessionParametersAddInfoEXT structure is defined
as:

include::{generated}/api/structs/VkVideoEncodeH264SessionParametersAddInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:stdSPSCount is the number of SPS elements in the pname:pStdSPSs.
    Its value must: be less than or equal to the value of
    pname:maxStdSPSCount.
  * pname:pStdSPSs is a pointer to an array of
    code:StdVideoH264SequenceParameterSet structures representing H.264
    sequence parameter sets.
    Each element of the array must: have a unique H.264 SPS ID.
  * pname:stdPPSCount is the number of PPS provided in pname:pStdPPSs.
    Its value must: be less than or equal to the value of
    pname:maxStdPPSCount.
  * pname:pStdPPSs is a pointer to an array of
    code:StdVideoH264PictureParameterSet structures representing H.264
    picture parameter sets.
    Each element of the array must: have a unique H.264 SPS-PPS ID pair.

.Valid Usage
****
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-stdSPSCount-04837]]
    The values of pname:stdSPSCount and pname:stdPPSCount must: be less than
    or equal to the values of pname:maxStdSPSCount and pname:maxStdPPSCount,
    respectively
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-maxStdSPSCount-04838]]
    When the pname:maxStdSPSCount number of parameters of type
    StdVideoH264SequenceParameterSet in the Video Session Parameters object
    is reached, no additional parameters of that type can be added to the
    object.
    ename:VK_ERROR_TOO_MANY_OBJECTS will be returned if an attempt is made
    to add additional data to this object at this point
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-maxStdPPSCount-04839]]
    When the pname:maxStdPPSCount number of parameters of type
    StdVideoH264PictureParameterSet in the Video Session Parameters object
    is reached, no additional parameters of that type can be added to the
    object.
    ename:VK_ERROR_TOO_MANY_OBJECTS will be returned if an attempt is made
    to add additional data to this object at this point
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-None-04840]]
    Each entry to be added must: have a unique, to the rest of the parameter
    array entries and the existing parameters in the Video Session
    Parameters Object that is being updated, SPS-PPS IDs
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-None-04841]]
    Parameter entries that already exist in Video Session Parameters object
    with a particular SPS-PPS IDs cannot: be replaced nor updated
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-None-04842]]
    When creating a new object using a Video Session Parameters as a
    template, the array's parameters with the same SPS-PPS IDs as the ones
    from the template take precedence
  * [[VUID-VkVideoEncodeH264SessionParametersAddInfoEXT-None-04843]]
    SPS/PPS parameters must: comply with the limits specified in
    slink:VkVideoSessionCreateInfoKHR during Video Session creation
****

include::{generated}/validity/structs/VkVideoEncodeH264SessionParametersAddInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264SessionParametersGetInfoEXT',desc='Structure specifying parameters for retrieving encoded H.264 parameter set data',type='structs']
--
The sname:VkVideoEncodeH264SessionParametersGetInfoEXT structure is defined
as:

include::{generated}/api/structs/VkVideoEncodeH264SessionParametersGetInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:writeStdSPS indicates whether the encoded H.264 sequence parameter
    set identified by pname:stdSPSId is requested to be retrieved.
  * pname:writeStdPPS indicates whether the encoded H.264 picture parameter
    set identified by the pair constructed from pname:stdSPSId and
    pname:stdPPSId is requested to be retrieved.
  * pname:stdSPSId specifies the H.264 sequence parameter set ID used to
    identify the retrieved H.264 sequence and/or picture parameter set(s).
  * pname:stdPPSId specifies the H.264 picture parameter set ID used to
    identify the retrieved H.264 picture parameter set when
    pname:writeStdPPS is set to ename:VK_TRUE.

When this structure is specified in the pname:pNext chain of the
slink:VkVideoEncodeSessionParametersGetInfoKHR structure passed to
flink:vkGetEncodedVideoSessionParametersKHR, the command will write encoded
parameter data to the output buffer in the following order:

  . The H.264 sequence parameter set identified by pname:stdSPSId, if
    pname:writeStdSPS is set to ename:VK_TRUE.
  . The H.264 picture parameter set identified by the pair constructed from
    pname:stdSPSId and pname:stdPPSId, if pname:writeStdPPS is set to
    ename:VK_TRUE.

include::{generated}/validity/structs/VkVideoEncodeH264SessionParametersGetInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264SessionParametersFeedbackInfoEXT',desc='Structure providing feedback about the requested H.264 video session parameters',type='structs']
--
The sname:VkVideoEncodeH264SessionParametersFeedbackInfoEXT structure is
defined as:

include::{generated}/api/structs/VkVideoEncodeH264SessionParametersFeedbackInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:hasStdSPSOverrides indicates whether any of the parameters of the
    requested H.264 sequence parameter set, if one was requested via
    slink:VkVideoEncodeH264SessionParametersGetInfoEXT::pname:writeStdSPS,
    were overridden by the implementation.
  * pname:hasStdPPSOverrides indicates whether any of the parameters of the
    requested H.264 picture parameter set, if one was requested via
    slink:VkVideoEncodeH264SessionParametersGetInfoEXT::pname:writeStdPPS,
    were overridden by the implementation.

include::{generated}/validity/structs/VkVideoEncodeH264SessionParametersFeedbackInfoEXT.adoc[]
--


=== Frame Encoding

In order to encode a frame, add a slink:VkVideoEncodeH264PictureInfoEXT
structure to the pname:pNext chain of the slink:VkVideoEncodeInfoKHR
structure passed to the flink:vkCmdEncodeVideoKHR command.

[open,refpage='VkVideoEncodeH264PictureInfoEXT',desc='Structure specifies H.264 encode frame parameters',type='structs']
--
The slink:VkVideoEncodeH264PictureInfoEXT structure representing a frame
encode operation is defined as:

include::{generated}/api/structs/VkVideoEncodeH264PictureInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:naluSliceEntryCount is the number of slice NALUs in the frame.
  * pname:pNaluSliceEntries is a pointer to an array of
    pname:naluSliceEntryCount slink:VkVideoEncodeH264NaluSliceInfoEXT
    structures specifying the division of the current picture into slices
    and the properties of these slices.
    This is an ordered sequence; the NALUs are generated consecutively in
    slink:VkVideoEncodeInfoKHR::pname:dstBuffer in the same order as in this
    array.
  * pname:pStdPictureInfo is a pointer to a
    code:StdVideoEncodeH264PictureInfo structure specifying the syntax and
    other codec-specific information from the H.264 specification associated
    with this picture.
    The information provided must: reflect the decoded picture marking
    operations that are applicable to this frame.
  * pname:generatePrefixNalu controls whether prefix NALUs are generated
    before slice NALUs into the target bitstream.

include::{generated}/validity/structs/VkVideoEncodeH264PictureInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264NaluSliceInfoEXT',desc='Structure specifies H.264 encode slice NALU parameters',type='structs']
--
The slink:VkVideoEncodeH264NaluSliceInfoEXT structure representing a slice
is defined as:

include::{generated}/api/structs/VkVideoEncodeH264NaluSliceInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:constantQp is the QP to use for the slice if the current rate
    control mode configured for the video session is
    ename:VK_VIDEO_ENCODE_RATE_CONTROL_MODE_DISABLED_BIT_KHR.
  * pname:pStdSliceHeader is a pointer to a
    code:StdVideoEncodeH264SliceHeader structure specifying the slice header
    for the current slice.

include::{generated}/validity/structs/VkVideoEncodeH264NaluSliceInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264DpbSlotInfoEXT',desc='Structure specifies H.264 encode DPB picture information',type='structs']
--
The slink:VkVideoEncodeH264DpbSlotInfoEXT structure, representing a
reconstructed picture that is being used as a reference picture, is defined
as:

include::{generated}/api/structs/VkVideoEncodeH264DpbSlotInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:pStdReferenceInfo is a pointer to a
    code:StdVideoEncodeH264ReferenceInfo structure specifying the syntax and
    other codec-specific information from the H.264 specification associated
    with this reference picture.

include::{generated}/validity/structs/VkVideoEncodeH264DpbSlotInfoEXT.adoc[]
--


=== Rate Control

[open,refpage='VkVideoEncodeH264RateControlInfoEXT',desc='Structure describing H.264 stream rate control parameters',type='structs']
--
The sname:VkVideoEncodeH264RateControlInfoEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264RateControlInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:flags is a bitmask of
    elink:VkVideoEncodeH264RateControlFlagBitsEXT specifying H.264 rate
    control flags.
  * pname:gopFrameCount is the number of frames contained within the group
    of pictures (GOP), starting from an intra frame and until the next intra
    frame.
    If it is set to 0, the implementation chooses a suitable value.
    If it is set to code:UINT32_MAX, the GOP length is treated as infinite.
  * pname:idrPeriod is the interval, in terms of number of frames, between
    two IDR frames.
    If it is set to 0, the implementation chooses a suitable value.
    If it is set to code:UINT32_MAX, the IDR period is treated as infinite.
  * pname:consecutiveBFrameCount is the number of consecutive B-frames
    between I- and/or P-frames within the GOP.
  * pname:temporalLayerCount specifies the number of temporal layers enabled
    in the stream.

In order to provide H.264-specific stream rate control parameters, add a
sname:VkVideoEncodeH264RateControlInfoEXT structure to the pname:pNext chain
of the slink:VkVideoEncodeRateControlInfoKHR structure in the pname:pNext
chain of the slink:VkVideoCodingControlInfoKHR structure passed to the
flink:vkCmdControlVideoCodingKHR command.

The parameters from this structure act as a guidance for implementations to
apply various rate control heuristics.

It is possible to infer the picture type to be used when encoding a frame,
on the basis of the values provided for pname:consecutiveBFrameCount,
pname:idrPeriod, and pname:gopFrameCount, but this inferred picture type
will not be used by implementations to override the picture type provided in
flink:vkCmdEncodeVideoKHR.
Additionally, it is not required for the video session to be reset if the
inferred picture type does not match the actual picture type.

include::{generated}/validity/structs/VkVideoEncodeH264RateControlInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264RateControlFlagBitsEXT',desc='H.264 encode rate control bits',type='enums']
--
Bits which can: be set in
slink:VkVideoEncodeH264RateControlInfoEXT::pname:flags, specifying H.264
rate control flags, are:

include::{generated}/api/enums/VkVideoEncodeH264RateControlFlagBitsEXT.adoc[]

  * ename:VK_VIDEO_ENCODE_H264_RATE_CONTROL_ATTEMPT_HRD_COMPLIANCE_BIT_EXT
    specifies that rate control should: attempt to produce an HRD compliant
    bitstream.
  * ename:VK_VIDEO_ENCODE_H264_RATE_CONTROL_REGULAR_GOP_BIT_EXT specifies
    that the application intends to use a regular GOP structure according to
    the parameters specified in the pname:gopFrameCount, pname:idrPeriod,
    and pname:consecutiveBFrameCount members of the
    slink:VkVideoEncodeH264RateControlInfoEXT structure.
  * ename:VK_VIDEO_ENCODE_H264_RATE_CONTROL_REFERENCE_PATTERN_FLAT_BIT_EXT
    specifies that the application intends to follow a flat reference
    pattern.
  * ename:VK_VIDEO_ENCODE_H264_RATE_CONTROL_REFERENCE_PATTERN_DYADIC_BIT_EXT
    specifies that the application intends to follow a dyadic reference
    pattern.
  * ename:VK_VIDEO_ENCODE_H264_RATE_CONTROL_TEMPORAL_LAYER_PATTERN_DYADIC_BIT_EXT
    specifies that the application intends to follow a dyadic temporal layer
    pattern.
--


[open,refpage='VkVideoEncodeH264RateControlFlagsEXT',desc='Bitmask specifying H.264 encode rate control flags',type='flags']
--
include::{generated}/api/flags/VkVideoEncodeH264RateControlFlagsEXT.adoc[]

tname:VkVideoEncodeH264RateControlFlagsEXT is a bitmask type for setting a
mask of zero or more elink:VkVideoEncodeH264RateControlFlagBitsEXT.
--


[open,refpage='VkVideoEncodeH264RateControlLayerInfoEXT',desc='Structure describing H.264 per-layer rate control parameters',type='structs']
--
The sname:VkVideoEncodeH264RateControlLayerInfoEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264RateControlLayerInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:useMinQp indicates whether the values within pname:minQp should be
    used by the implementation.
    When it is set to ename:VK_FALSE, the implementation ignores the values
    in pname:minQp and chooses suitable values.
  * pname:minQp provides the lower bound on the QP values for each picture
    type, to be used in rate control calculations.
  * pname:useMaxQp indicates whether the values within pname:maxQp should be
    used by the implementation.
    When it is set to ename:VK_FALSE, the implementation ignores the values
    in pname:maxQp and chooses suitable values.
  * pname:maxQp provides the upper bound on the QP values for each picture
    type, to be used in rate control calculations.
  * pname:useMaxFrameSize indicates whether the values within
    pname:maxFrameSize should be used by the implementation.
  * pname:maxFrameSize provides the upper bound on the encoded frame size
    for each picture type.
    The implementation does not guarantee the encoded frame sizes will be
    within the specified limits, however these limits may: be used as a
    guide in rate control calculations.
    If enabled and not set properly, the pname:maxQp limit may prevent the
    implementation from respecting the pname:maxFrameSize limit.

H.264-specific per-layer rate control parameters must: be specified by
adding a sname:VkVideoEncodeH264RateControlLayerInfoEXT structure to the
pname:pNext chain of each slink:VkVideoEncodeRateControlLayerInfoKHR
structure in a call to flink:vkCmdControlVideoCodingKHR command, when the
command buffer context has an active video encode H.264 session.

include::{generated}/validity/structs/VkVideoEncodeH264RateControlLayerInfoEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264QpEXT',desc='Structure describing H.264 QP values per picture type',type='structs']
--
The sname:VkVideoEncodeH264QpEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264QpEXT.adoc[]

  * pname:qpI is the QP to be used for I-frames.
  * pname:qpP is the QP to be used for P-frames.
  * pname:qpB is the QP to be used for B-frames.

include::{generated}/validity/structs/VkVideoEncodeH264QpEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264FrameSizeEXT',desc='Structure describing frame size values per H.264 picture type',type='structs']
--
The sname:VkVideoEncodeH264FrameSizeEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264FrameSizeEXT.adoc[]

  * pname:frameISize is the size in bytes to be used for I-frames.
  * pname:framePSize is the size in bytes to be used for P-frames.
  * pname:frameBSize is the size in bytes to be used for B-frames.

include::{generated}/validity/structs/VkVideoEncodeH264FrameSizeEXT.adoc[]
--

[open,refpage='VkVideoEncodeH264GopRemainingFrameInfoEXT',desc='Structure specifying H.264 encode rate control GOP remaining frame counts',type='structs']
--
The sname:VkVideoEncodeH264GopRemainingFrameInfoEXT structure is defined as:

include::{generated}/api/structs/VkVideoEncodeH264GopRemainingFrameInfoEXT.adoc[]

  * pname:sType is a elink:VkStructureType value identifying this structure.
  * pname:pNext is `NULL` or a pointer to a structure extending this
    structure.
  * pname:useGopRemainingFrames indicates whether the implementation's rate
    control algorithm should: use the values specified in
    pname:gopRemainingI, pname:gopRemainingP, and pname:gopRemainingB.
    If pname:useGopRemainingFrames is ename:VK_FALSE, then the values of
    pname:gopRemainingI, pname:gopRemainingP, and pname:gopRemainingB are
    ignored.
  * pname:gopRemainingI specifies the number of I-frames the
    implementation's rate control algorithm should: assume to be remaining
    in the GOP prior to executing the video encode operation.
  * pname:gopRemainingP specifies the number of P-frames the
    implementation's rate control algorithm should: assume to be remaining
    in the GOP prior to executing the video encode operation.
  * pname:gopRemainingB specifies the number of B-frames the
    implementation's rate control algorithm should: assume to be remaining
    in the GOP prior to executing the video encode operation.

Setting pname:useGopRemainingFrames to ename:VK_TRUE and including this
structure in the pname:pNext chain of slink:VkVideoEncodeInfoKHR is only
mandatory if the
slink:VkVideoEncodeH264CapabilitiesEXT::pname:requiresGopRemainingFrames
reported for the used <<video-profiles,video profile>> is ename:VK_TRUE.
However, implementations may: use these remaining frame counts, when
specified, even when it is not required.
In particular, when the application does not use a regular GOP structure,
these values may: provide additional guidance for the implementation's rate
control algorithm.

The slink:VkVideoEncodeH264CapabilitiesEXT::pname:prefersGopRemainingFrames
capability is also used to indicate that the implementation's rate control
algorithm may: operate more accurately if the application specifies the
remaining frame counts using this structure.

As with other rate control guidance values, if the effective order and
number of frames encoded by the application are not in line with the
remaining frame counts specified in this structure at any given point, then
the behavior of the implementation's rate control algorithm may: deviate
from the one expected by the application.

include::{generated}/validity/structs/VkVideoEncodeH264GopRemainingFrameInfoEXT.adoc[]
--
