d3d12: H264 encode - Allow CONSTRAINED_BASELINE profile to be written in headers
Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26456>
This commit is contained in:
@@ -1075,7 +1075,6 @@ d3d12_video_encoder_build_codec_headers_h264(struct d3d12_video_encoder *pD3D12E
|
||||
D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA currentPicParams =
|
||||
d3d12_video_encoder_get_current_picture_param_settings(pD3D12Enc);
|
||||
|
||||
auto profDesc = d3d12_video_encoder_get_current_profile_desc(pD3D12Enc);
|
||||
auto levelDesc = d3d12_video_encoder_get_current_level_desc(pD3D12Enc);
|
||||
auto codecConfigDesc = d3d12_video_encoder_get_current_codec_config_desc(pD3D12Enc);
|
||||
auto MaxDPBCapacity = d3d12_video_encoder_get_current_max_dpb_capacity(pD3D12Enc);
|
||||
@@ -1106,7 +1105,7 @@ d3d12_video_encoder_build_codec_headers_h264(struct d3d12_video_encoder *pD3D12E
|
||||
size_t writtenSPSBytesCount = 0;
|
||||
if (writeNewSPS) {
|
||||
pH264BitstreamBuilder->build_sps(pD3D12Enc->m_currentEncodeConfig.m_encoderCodecSpecificSequenceStateDescH264,
|
||||
*profDesc.pH264Profile,
|
||||
pD3D12Enc->base.profile,
|
||||
*levelDesc.pH264LevelSetting,
|
||||
pD3D12Enc->m_currentEncodeConfig.m_encodeFormatInfo.Format,
|
||||
*codecConfigDesc.pH264Config,
|
||||
@@ -1122,7 +1121,7 @@ d3d12_video_encoder_build_codec_headers_h264(struct d3d12_video_encoder *pD3D12E
|
||||
}
|
||||
|
||||
size_t writtenPPSBytesCount = 0;
|
||||
pH264BitstreamBuilder->build_pps(*profDesc.pH264Profile,
|
||||
pH264BitstreamBuilder->build_pps(pD3D12Enc->base.profile,
|
||||
*codecConfigDesc.pH264Config,
|
||||
*currentPicParams.pH264PicData,
|
||||
currentPicParams.pH264PicData->pic_parameter_set_id,
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "d3d12_video_encoder_bitstream_builder_h264.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "util/u_video.h"
|
||||
|
||||
d3d12_video_bitstream_builder_h264::d3d12_video_bitstream_builder_h264(bool insert_aud_nalu)
|
||||
: m_insert_aud_nalu(insert_aud_nalu)
|
||||
@@ -54,7 +55,7 @@ Convert12ToSpecH264Profiles(D3D12_VIDEO_ENCODER_PROFILE_H264 profile12)
|
||||
|
||||
void
|
||||
d3d12_video_bitstream_builder_h264::build_sps(const struct pipe_h264_enc_seq_param & seqData,
|
||||
const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile,
|
||||
const enum pipe_video_profile & profile,
|
||||
const D3D12_VIDEO_ENCODER_LEVELS_H264 & level,
|
||||
const DXGI_FORMAT & inputFmt,
|
||||
const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig,
|
||||
@@ -67,8 +68,8 @@ d3d12_video_bitstream_builder_h264::build_sps(const struct pipe_h264_enc_seq_par
|
||||
std::vector<uint8_t>::iterator placingPositionStart,
|
||||
size_t & writtenBytes)
|
||||
{
|
||||
H264_SPEC_PROFILES profile_idc = Convert12ToSpecH264Profiles(profile);
|
||||
uint32_t constraint_set1_flag = (profile_idc == H264_PROFILE_MAIN) ? 1 : 0;
|
||||
H264_SPEC_PROFILES profile_idc = (H264_SPEC_PROFILES) u_get_h264_profile_idc(profile);
|
||||
uint32_t constraint_set1_flag = ((profile_idc == H264_PROFILE_MAIN) || (profile_idc == H264_PROFILE_CONSTRAINED_BASELINE)) ? 1 : 0;
|
||||
uint32_t constraint_set3_flag = 0;
|
||||
uint32_t level_idc = 0;
|
||||
d3d12_video_encoder_convert_from_d3d12_level_h264(
|
||||
@@ -78,7 +79,7 @@ d3d12_video_bitstream_builder_h264::build_sps(const struct pipe_h264_enc_seq_par
|
||||
|
||||
// constraint_set3_flag is for Main profile only and levels 11 or 1b: levels 11 if off, level 1b if on. Always 0 for
|
||||
// HIGH/HIGH10 profiles
|
||||
if ((profile == D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH) || (profile == D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH_10)) {
|
||||
if ((profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH) || (profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10)) {
|
||||
// Force 0 for high profiles
|
||||
constraint_set3_flag = 0;
|
||||
}
|
||||
@@ -205,7 +206,7 @@ d3d12_video_bitstream_builder_h264::write_aud(std::vector<uint8_t> & hea
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_video_bitstream_builder_h264::build_pps(const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile,
|
||||
d3d12_video_bitstream_builder_h264::build_pps(const enum pipe_video_profile & profile,
|
||||
const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig,
|
||||
const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264 &pictureControl,
|
||||
uint32_t pic_parameter_set_id,
|
||||
@@ -215,7 +216,7 @@ d3d12_video_bitstream_builder_h264::build_pps(const D3D12_VIDEO_ENCODER_PROFILE_
|
||||
size_t & writtenBytes)
|
||||
{
|
||||
BOOL bIsHighProfile =
|
||||
((profile == D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH) || (profile == D3D12_VIDEO_ENCODER_PROFILE_H264_HIGH_10));
|
||||
((profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH) || (profile == PIPE_VIDEO_PROFILE_MPEG4_AVC_HIGH10));
|
||||
|
||||
H264_PPS ppsStructure = {
|
||||
pic_parameter_set_id,
|
||||
@@ -244,7 +245,7 @@ d3d12_video_bitstream_builder_h264::build_pps(const D3D12_VIDEO_ENCODER_PROFILE_
|
||||
"[D3D12 d3d12_video_bitstream_builder_h264] H264_PPS Structure generated before writing to bitstream:\n");
|
||||
print_pps(ppsStructure);
|
||||
|
||||
// Convert the H264 SPS structure into bytes
|
||||
// Convert the H264 PPS structure into bytes
|
||||
m_h264Encoder.pps_to_nalu_bytes(&ppsStructure, headerBitstream, bIsHighProfile, placingPositionStart, writtenBytes);
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ class d3d12_video_bitstream_builder_h264 : public d3d12_video_bitstream_builder_
|
||||
~d3d12_video_bitstream_builder_h264() {};
|
||||
|
||||
void build_sps(const struct pipe_h264_enc_seq_param & seqData,
|
||||
const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile,
|
||||
const enum pipe_video_profile & profile,
|
||||
const D3D12_VIDEO_ENCODER_LEVELS_H264 & level,
|
||||
const DXGI_FORMAT & inputFmt,
|
||||
const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig,
|
||||
@@ -48,7 +48,7 @@ class d3d12_video_bitstream_builder_h264 : public d3d12_video_bitstream_builder_
|
||||
std::vector<uint8_t>::iterator placingPositionStart,
|
||||
size_t & writtenBytes);
|
||||
|
||||
void build_pps(const D3D12_VIDEO_ENCODER_PROFILE_H264 & profile,
|
||||
void build_pps(const enum pipe_video_profile & profile,
|
||||
const D3D12_VIDEO_ENCODER_CODEC_CONFIGURATION_H264 & codecConfig,
|
||||
const D3D12_VIDEO_ENCODER_PICTURE_CONTROL_CODEC_DATA_H264 &pictureControl,
|
||||
uint32_t pic_parameter_set_id,
|
||||
|
||||
@@ -58,11 +58,13 @@ d3d12_video_nalu_writer_h264::write_sps_bytes(d3d12_video_encoder_bitstream *pBi
|
||||
pBitstream->put_bits(8, pSPS->level_idc);
|
||||
pBitstream->exp_Golomb_ue(pSPS->seq_parameter_set_id);
|
||||
|
||||
// Only support profiles defined in D3D12 Video Encode
|
||||
// If adding new profile support, check that the chroma_format_idc and bit depth are set correctly below
|
||||
// for the new additions
|
||||
assert((pSPS->profile_idc == H264_PROFILE_MAIN) || (pSPS->profile_idc == H264_PROFILE_HIGH) ||
|
||||
(pSPS->profile_idc == H264_PROFILE_HIGH10));
|
||||
assert((pSPS->profile_idc == H264_PROFILE_MAIN) ||
|
||||
(pSPS->profile_idc == H264_PROFILE_HIGH) ||
|
||||
(pSPS->profile_idc == H264_PROFILE_HIGH10) ||
|
||||
(pSPS->profile_idc == H264_PROFILE_BASELINE) ||
|
||||
(pSPS->profile_idc == H264_PROFILE_CONSTRAINED_BASELINE));
|
||||
|
||||
if ((pSPS->profile_idc == H264_PROFILE_HIGH) || (pSPS->profile_idc == H264_PROFILE_HIGH10)) {
|
||||
// chroma_format_idc always 4.2.0
|
||||
|
||||
@@ -147,6 +147,9 @@ struct H264_PPS
|
||||
|
||||
enum H264_SPEC_PROFILES
|
||||
{
|
||||
// Same as BASELINE (66) with constraint_set1_flag set
|
||||
H264_PROFILE_CONSTRAINED_BASELINE = 66,
|
||||
H264_PROFILE_BASELINE = 66,
|
||||
H264_PROFILE_MAIN = 77,
|
||||
H264_PROFILE_HIGH = 100,
|
||||
H264_PROFILE_HIGH10 = 110,
|
||||
|
||||
Reference in New Issue
Block a user