Commit 3154c146 authored by Hirokazu Honda's avatar Hirokazu Honda Committed by Chromium LUCI CQ

media/gpu/vaapi/AV1VaapiVideoDecoderDelegate: Reuse VABuffers in AV1 decoding

VABuffers are created for each bitstream in AV1Decoding. This CL
applies the buffer reuse optimization (b/166646505) to av1
decoding though buffers for slice data are not reused due to
b/177028692.

Bug: b:166646505,b:175897723
Test: video.DecodeAccelVD.av1* video.DecodeCompliance.av1_test_vectors
Test: video.Play.av1_hw* video.Seek.av1* video.MemSeek.av1*
Change-Id: Id70b49bf3dd49d098b559286d0f01c2fe3a11ad7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2615727Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Commit-Queue: Andres Calderon Jaramillo <andrescj@chromium.org>
Auto-Submit: Hirokazu Honda <hiroh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843617}
parent bdbfecd8
......@@ -721,7 +721,11 @@ AV1VaapiVideoDecoderDelegate::AV1VaapiVideoDecoderDelegate(
base::DoNothing(),
nullptr) {}
AV1VaapiVideoDecoderDelegate::~AV1VaapiVideoDecoderDelegate() = default;
AV1VaapiVideoDecoderDelegate::~AV1VaapiVideoDecoderDelegate() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(!picture_params_);
DCHECK(slice_params_.empty());
}
scoped_refptr<AV1Picture> AV1VaapiVideoDecoderDelegate::CreateAV1Picture(
bool apply_grain) {
......@@ -777,28 +781,55 @@ bool AV1VaapiVideoDecoderDelegate::SubmitDecode(
return false;
}
// TODO(hiroh): Batch VABuffer submissions like Vp9VaapiVideoDecoderDelegate.
// Submit the picture parameters.
if (!vaapi_wrapper_->SubmitBuffer(VAPictureParameterBufferType, &pic_param))
return false;
// Submit the entire buffer and the per-tile information.
if (!picture_params_) {
picture_params_ = vaapi_wrapper_->CreateVABuffer(
VAPictureParameterBufferType, sizeof(pic_param));
if (!picture_params_)
return false;
}
if (slice_params_.size() != slice_params.size()) {
while (slice_params_.size() < slice_params.size()) {
slice_params_.push_back(vaapi_wrapper_->CreateVABuffer(
VASliceParameterBufferType, sizeof(VASliceParameterBufferAV1)));
if (!slice_params_.back()) {
slice_params_.clear();
return false;
}
}
slice_params_.resize(slice_params.size());
slice_params_.shrink_to_fit();
}
// TODO(hiroh): Don't submit the entire coded data to the buffer. Instead,
// only pass the data starting from the tile list OBU to reduce the size of
// the VA buffer.
if (!vaapi_wrapper_->SubmitBuffer(VASliceDataBufferType, data.size(),
data.data())) {
// Always re-create |encoded_data| because reusing the buffer causes horrific
// artifacts in decoded buffers. TODO(b/177028692): This seems to be a driver
// bug, fix it and reuse the buffer.
auto encoded_data =
vaapi_wrapper_->CreateVABuffer(VASliceDataBufferType, data.size_bytes());
if (!encoded_data)
return false;
}
for (const VASliceParameterBufferAV1& tile_param : slice_params) {
if (!vaapi_wrapper_->SubmitBuffer(VASliceParameterBufferType,
&tile_param)) {
return false;
}
std::vector<std::pair<VABufferID, VaapiWrapper::VABufferDescriptor>> buffers =
{{picture_params_->id(),
{picture_params_->type(), picture_params_->size(), &pic_param}},
{encoded_data->id(),
{encoded_data->type(), encoded_data->size(), data.data()}}};
for (size_t i = 0; i < slice_params.size(); ++i) {
buffers.push_back({slice_params_[i]->id(),
{slice_params_[i]->type(), slice_params_[i]->size(),
&slice_params[i]}});
}
const auto* vaapi_pic = static_cast<const VaapiAV1Picture*>(&pic);
return vaapi_wrapper_->ExecuteAndDestroyPendingBuffers(
vaapi_pic->reconstruct_va_surface()->id());
return vaapi_wrapper_->MapAndCopyAndExecute(
vaapi_pic->reconstruct_va_surface()->id(), buffers);
}
void AV1VaapiVideoDecoderDelegate::OnVAContextDestructionSoon() {
// Destroy the member ScopedVABuffers below since they refer to a VAContextID
// that will be destroyed soon.
picture_params_.reset();
slice_params_.clear();
}
} // namespace media
......@@ -5,10 +5,15 @@
#ifndef MEDIA_GPU_VAAPI_AV1_VAAPI_VIDEO_DECODER_DELEGATE_H_
#define MEDIA_GPU_VAAPI_AV1_VAAPI_VIDEO_DECODER_DELEGATE_H_
#include <memory>
#include <vector>
#include "media/gpu/av1_decoder.h"
#include "media/gpu/vaapi/vaapi_video_decoder_delegate.h"
namespace media {
class ScopedVABuffer;
class AV1VaapiVideoDecoderDelegate : public AV1Decoder::AV1Accelerator,
public VaapiVideoDecoderDelegate {
public:
......@@ -27,6 +32,13 @@ class AV1VaapiVideoDecoderDelegate : public AV1Decoder::AV1Accelerator,
const libgav1::Vector<libgav1::TileBuffer>& tile_buffers,
base::span<const uint8_t> data) override;
bool OutputPicture(const AV1Picture& pic) override;
// VaapiVideoDecoderDelegate implementation.
void OnVAContextDestructionSoon() override;
private:
std::unique_ptr<ScopedVABuffer> picture_params_;
std::vector<std::unique_ptr<ScopedVABuffer>> slice_params_;
};
} // namespace media
#endif // MEDIA_GPU_VAAPI_AV1_VAAPI_VIDEO_DECODER_DELEGATE_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment