// Sensible default values for CDEF taken from
// https://github.com/intel/libva-utils/blob/master/encode/av1encode.c
I would prefer you use that from third_party/libaom/source/libaom/av1/encoder/pickcdef.c;l=750. At least we have different settings for screen content and camera content with that.
constexpr std::array<uint8_t, 8> cdef_y_pri_strength = {9, 12, 0, 6,
Even for constexpr std::array, we still expect consts to be defined with kXXX format. So it should be kCdefYPriStrenth. Same for ebelow.
// SAFETY: It is safe to access the buffer since the size is 7.
Instead of adding this comment, you could well get the element count of the array instead of hard-code to 7. Same for below.
cdef.CdefBits = 3;
Do we really always need 8 groups of cdef strengths? libaom uses 4 groups at most.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// Rfresh DPB slot 0 with current reconstructed picture.
refresh
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
sequence_header.enable_superres = false;
sequence_header.enable_cdef = true;
sequence_header.enable_restoration = false;
It is expected that when when ibc(intra-block-copy) is enbled, all these flags needs to be disabled. Please make sure cdef_bits is 0 when ibc is on.
CHECK_LT(static_cast<size_t>(tid),
VideoBitrateAllocation::kMaxTemporalLayers);
might want to consider to move this check out of the loop and maybe only check it once against the largest value?
CHECK_LT(static_cast<size_t>(num_temporal_layers), VideoBitrateAllocation::kMaxTemporalLayers);
.Codec = D3D12_VIDEO_ENCODER_CODEC_HEVC,
just double checking, is D3D12_VIDEO_ENCODER_CODEC_HEVC correct here? Should it be D3D12_VIDEO_ENCODER_CODEC_AV1 instead?
if (++picture_params_.PictureIndex == gop_sequence_.InterFramePeriod ||
Just wondering if picture_params_.PictureIndex needs be initialized to like '-1' in the constructor? So that ++ would make the 1st picture a key frame?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// Sensible default values for CDEF taken from
// https://github.com/intel/libva-utils/blob/master/encode/av1encode.c
I would prefer you use that from third_party/libaom/source/libaom/av1/encoder/pickcdef.c;l=750. At least we have different settings for screen content and camera content with that.
For cdef setting, the value from libaom doesn't show PSNR benefit on camera content, I prefer to keep align with VAAPI in the initial version.
constexpr std::array<uint8_t, 8> cdef_y_pri_strength = {9, 12, 0, 6,
Even for constexpr std::array, we still expect consts to be defined with kXXX format. So it should be kCdefYPriStrenth. Same for ebelow.
Done
sequence_header.enable_superres = false;
sequence_header.enable_cdef = true;
sequence_header.enable_restoration = false;
It is expected that when when ibc(intra-block-copy) is enbled, all these flags needs to be disabled. Please make sure cdef_bits is 0 when ibc is on.
The feature of intra-block-copy is not supported yet.
// SAFETY: It is safe to access the buffer since the size is 7.
Instead of adding this comment, you could well get the element count of the array instead of hard-code to 7. Same for below.
Done
CHECK_LT(static_cast<size_t>(tid),
VideoBitrateAllocation::kMaxTemporalLayers);
might want to consider to move this check out of the loop and maybe only check it once against the largest value?
CHECK_LT(static_cast<size_t>(num_temporal_layers), VideoBitrateAllocation::kMaxTemporalLayers);
Done
just double checking, is D3D12_VIDEO_ENCODER_CODEC_HEVC correct here? Should it be D3D12_VIDEO_ENCODER_CODEC_AV1 instead?
It should be D3D12_VIDEO_ENCODER_CODEC_AV1! Thanks!
if (++picture_params_.PictureIndex == gop_sequence_.InterFramePeriod ||
Just wondering if picture_params_.PictureIndex needs be initialized to like '-1' in the constructor? So that ++ would make the 1st picture a key frame?
Done
Do we really always need 8 groups of cdef strengths? libaom uses 4 groups at most.
Done
// Rfresh DPB slot 0 with current reconstructed picture.
Yingying Marefresh
Done
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
`std::size`
```
_EXPORT_STD template <class _Ty, size_t _Size>
_NODISCARD constexpr size_t size(const _Ty (&)[_Size]) noexcept {
return _Size;
}
```
The result will be compile-time constant.
// SAFETY: The access is safe because |LoopFilterLevel| has 2 elements.
`base::span(pic_params.LoopFilter.LoopFilterLevel);` is safe. Ditto elsewhere.
UNSAFE_BUFFERS(pic_params.ReferenceFramesReconPictureDescriptors[i])
Doing so we may get rid of UNSAFE_BUFFERS checks
```
base::span descriptors = pic_params.ReferenceFramesReconPictureDescriptors;
frame_header.ref_order_hint[i] = descriptors[i].OrderHint;
```
.InterFramePeriod = config.gop_length.value_or(kDefaultGOPLength)};
We have already set this value in the base delegate, if you don't need one other than 3000.
for (uint32_t i = 0; i < ARRAY_SIZE(picture_params_.ReferenceIndices); ++i) {
// SAFETY: The access is safe with the bound check above.
UNSAFE_BUFFERS(picture_params_.ReferenceIndices[i]) = 0;
}
Try `std::ranges::fill(picture_params_.ReferenceIndices, 0);`
if (codec == VideoCodec::kAV1) {
rate_control.params_.cqp = {
.ConstantQP_FullIntracodedFrame = 26,
.ConstantQP_InterPredictedFrame_PrevRefOnly = 30,
.ConstantQP_InterPredictedFrame_BiDirectionalRef = 30};
rate_control.rate_control_ = {
.Mode = D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP,
.ConfigParams = {.DataSize = sizeof(rate_control.params_.cqp),
.pConfiguration_CQP = &rate_control.params_.cqp},
.TargetFrameRate = {framerate, 1}};
} else {
To use software BRC, my plan is to override `UpdateRateControl()` and overwrite `rate_control_` in `InitializeVideoEncoder()`, instead of changing the base delegate.
Also if possible we may split the software BRC part to another CL.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
`std::size`
```
_EXPORT_STD template <class _Ty, size_t _Size>
_NODISCARD constexpr size_t size(const _Ty (&)[_Size]) noexcept {
return _Size;
}
```The result will be compile-time constant.
Done
// SAFETY: The access is safe because |LoopFilterLevel| has 2 elements.
`base::span(pic_params.LoopFilter.LoopFilterLevel);` is safe. Ditto elsewhere.
Done
UNSAFE_BUFFERS(pic_params.ReferenceFramesReconPictureDescriptors[i])
Doing so we may get rid of UNSAFE_BUFFERS checks
```
base::span descriptors = pic_params.ReferenceFramesReconPictureDescriptors;
frame_header.ref_order_hint[i] = descriptors[i].OrderHint;
```
Acknowledged
.InterFramePeriod = config.gop_length.value_or(kDefaultGOPLength)};
We have already set this value in the base delegate, if you don't need one other than 3000.
Done
for (uint32_t i = 0; i < ARRAY_SIZE(picture_params_.ReferenceIndices); ++i) {
// SAFETY: The access is safe with the bound check above.
UNSAFE_BUFFERS(picture_params_.ReferenceIndices[i]) = 0;
}
Try `std::ranges::fill(picture_params_.ReferenceIndices, 0);`
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
// Sensible default values for CDEF taken from
// https://github.com/intel/libva-utils/blob/master/encode/av1encode.c
Yingying MaI would prefer you use that from third_party/libaom/source/libaom/av1/encoder/pickcdef.c;l=750. At least we have different settings for screen content and camera content with that.
For cdef setting, the value from libaom doesn't show PSNR benefit on camera content, I prefer to keep align with VAAPI in the initial version.
Done
if (codec == VideoCodec::kAV1) {
rate_control.params_.cqp = {
.ConstantQP_FullIntracodedFrame = 26,
.ConstantQP_InterPredictedFrame_PrevRefOnly = 30,
.ConstantQP_InterPredictedFrame_BiDirectionalRef = 30};
rate_control.rate_control_ = {
.Mode = D3D12_VIDEO_ENCODER_RATE_CONTROL_MODE_CQP,
.ConfigParams = {.DataSize = sizeof(rate_control.params_.cqp),
.pConfiguration_CQP = &rate_control.params_.cqp},
.TargetFrameRate = {framerate, 1}};
} else {
To use software BRC, my plan is to override `UpdateRateControl()` and overwrite `rate_control_` in `InitializeVideoEncoder()`, instead of changing the base delegate.
Also if possible we may split the software BRC part to another CL.
Done
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
CHECK(!config.HasSpatialLayer() && !config.HasTemporalLayer())
Instead of
```
CHECK(A && B);
```
do
```
CHECK(A);
CHECK(B);
```
With the second code block, if the second CHECK gets hit, you know that A is true. Makes it easier to root cause crash dumps and logs.
D3D12_VIDEO_ENCODER_AV1_PROFILE av1_profile_;
I presume there will be new items added to this union over time?
Please add a comment that describes what variable in the class determines which one to use.
error << "D3D12VideoEncoder does not support input format "
<< DxgiFormatToString(support->InputFormat) << ". ";
For this and other string concatenation in this CL, please use `base::StrCat` for optimal performance.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
CHECK(!config.HasSpatialLayer() && !config.HasTemporalLayer())
Instead of
```
CHECK(A && B);
```do
```
CHECK(A);
CHECK(B);
```With the second code block, if the second CHECK gets hit, you know that A is true. Makes it easier to root cause crash dumps and logs.
Acknowledged
I presume there will be new items added to this union over time?
Please add a comment that describes what variable in the class determines which one to use.
Done
I presume there will be new items added to this union over time?
Please add a comment that describes what variable in the class determines which one to use.
Done
error << "D3D12VideoEncoder does not support input format "
<< DxgiFormatToString(support->InputFormat) << ". ";
For this and other string concatenation in this CL, please use `base::StrCat` for optimal performance.
Done
error << "D3D12VideoEncoder does not support input format "
<< DxgiFormatToString(support->InputFormat) << ". ";
For this and other string concatenation in this CL, please use `base::StrCat` for optimal performance.
Done
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
CHECK_LE(1u << cdef.CdefBits, std::size(kCdefYPriStrength));
no need to do it. there's a CHECK in each `std::array` access
std::copy_n(packed_frame_header.data(), packed_header_size,
bitstream_buffer.data());
I'm surprised that clang doen't catch this raw pointer copy. Could you please use `span::copy_from` here?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Commit-Queue | +1 |
CHECK_LE(1u << cdef.CdefBits, std::size(kCdefYPriStrength));
no need to do it. there's a CHECK in each `std::array` access
Done
std::copy_n(packed_frame_header.data(), packed_header_size,
bitstream_buffer.data());
I'm surprised that clang doen't catch this raw pointer copy. Could you please use `span::copy_from` here?
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_REDUCED_TX_SET)) {
I don't think reduced tx set is a mandatory feature. Please make this best-effort instead.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Per offline talk, the reduce-tx-mode feature checking will be updated with follow up CL.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Code-Review | +1 |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
D3D12_VIDEO_ENCODER_AV1_FEATURE_FLAG_REDUCED_TX_SET)) {
I don't think reduced tx set is a mandatory feature. Please make this best-effort instead.
Will add reduced tx set control in a follow up CL.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
[Win] Create AV1 D3D12 video encode accelerator
First pass implementation of the D3D12VideoEncodeAV1Delegate.
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |