Commit e47c7b77 authored by Miguel Casas's avatar Miguel Casas

media/gpu/vaapi: batch submitting VABufferIDs for JPEG encoding

This CL follows crrev.com/c/2393629 by batching up SubmitBuffer
calls in the JPEG encode accelerator (JEA).

This was not verified perf-wise but the savings are obvious given
all the other CLs on this bug: we avoid locking-unlocking the
|va_lock_| for every buffer submission, and there's 5 of them
per JEA Encode() call. Time saving of course will be minimal but
the target here is to reduce contention on the lock

Bug: b/166646505
Change-Id: I4ad8ba3498cdcb1d1259dc527a7b4799320fc599
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2405417
Auto-Submit: Miguel Casas <mcasas@chromium.org>
Reviewed-by: default avatarAndres Calderon Jaramillo <andrescj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807039}
parent 21c406ed
...@@ -343,45 +343,29 @@ bool VaapiJpegEncoder::Encode(const gfx::Size& input_size, ...@@ -343,45 +343,29 @@ bool VaapiJpegEncoder::Encode(const gfx::Size& input_size,
// Set picture parameters. // Set picture parameters.
VAEncPictureParameterBufferJPEG pic_param; VAEncPictureParameterBufferJPEG pic_param;
FillPictureParameters(input_size, quality, output_buffer_id, &pic_param); FillPictureParameters(input_size, quality, output_buffer_id, &pic_param);
if (!vaapi_wrapper_->SubmitBuffer(VAEncPictureParameterBufferType,
&pic_param)) {
return false;
}
if (!q_matrix_cached_) { if (!q_matrix_cached_) {
q_matrix_cached_.reset(new VAQMatrixBufferJPEG()); q_matrix_cached_.reset(new VAQMatrixBufferJPEG());
FillQMatrix(q_matrix_cached_.get()); FillQMatrix(q_matrix_cached_.get());
} }
if (!vaapi_wrapper_->SubmitBuffer(VAQMatrixBufferType,
q_matrix_cached_.get())) {
return false;
}
if (!huff_table_param_cached_) { if (!huff_table_param_cached_) {
huff_table_param_cached_.reset(new VAHuffmanTableBufferJPEGBaseline()); huff_table_param_cached_.reset(new VAHuffmanTableBufferJPEGBaseline());
FillHuffmanTableParameters(huff_table_param_cached_.get()); FillHuffmanTableParameters(huff_table_param_cached_.get());
} }
if (!vaapi_wrapper_->SubmitBuffer(VAHuffmanTableBufferType,
huff_table_param_cached_.get())) {
return false;
}
// Set slice parameters. // Set slice parameters.
if (!slice_param_cached_) { if (!slice_param_cached_) {
slice_param_cached_.reset(new VAEncSliceParameterBufferJPEG()); slice_param_cached_.reset(new VAEncSliceParameterBufferJPEG());
FillSliceParameters(slice_param_cached_.get()); FillSliceParameters(slice_param_cached_.get());
} }
if (!vaapi_wrapper_->SubmitBuffer(VAEncSliceParameterBufferType,
slice_param_cached_.get())) {
return false;
}
size_t jpeg_header_size = size_t jpeg_header_size =
exif_buffer_size > 0 exif_buffer_size > 0
? kJpegDefaultHeaderSize + kJFIFApp1HeaderSize + exif_buffer_size ? kJpegDefaultHeaderSize + kJFIFApp1HeaderSize + exif_buffer_size
: kJpegDefaultHeaderSize + kJFIFApp0Size; : kJpegDefaultHeaderSize + kJFIFApp0Size;
std::vector<uint8_t> jpeg_header(jpeg_header_size); std::vector<uint8_t> jpeg_header(jpeg_header_size);
size_t length_in_bits = const size_t length_in_bits =
FillJpegHeader(input_size, exif_buffer, exif_buffer_size, quality, FillJpegHeader(input_size, exif_buffer, exif_buffer_size, quality,
jpeg_header.data(), exif_offset); jpeg_header.data(), exif_offset);
...@@ -390,14 +374,19 @@ bool VaapiJpegEncoder::Encode(const gfx::Size& input_size, ...@@ -390,14 +374,19 @@ bool VaapiJpegEncoder::Encode(const gfx::Size& input_size,
header_param.type = VAEncPackedHeaderRawData; header_param.type = VAEncPackedHeaderRawData;
header_param.bit_length = length_in_bits; header_param.bit_length = length_in_bits;
header_param.has_emulation_bytes = 0; header_param.has_emulation_bytes = 0;
if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderParameterBufferType,
&header_param)) {
return false;
}
if (!vaapi_wrapper_->SubmitBuffer(VAEncPackedHeaderDataBufferType, if (!vaapi_wrapper_->SubmitBuffers(
(length_in_bits + 7) / 8, {{VAEncPictureParameterBufferType, sizeof(pic_param), &pic_param},
jpeg_header.data())) { {VAQMatrixBufferType, sizeof(*q_matrix_cached_),
q_matrix_cached_.get()},
{VAHuffmanTableBufferType, sizeof(*huff_table_param_cached_),
huff_table_param_cached_.get()},
{VAEncSliceParameterBufferType, sizeof(*slice_param_cached_),
slice_param_cached_.get()},
{VAEncPackedHeaderParameterBufferType, sizeof(header_param),
&header_param},
{VAEncPackedHeaderDataBufferType, (length_in_bits + 7) / 8,
jpeg_header.data()}})) {
return false; return false;
} }
......
...@@ -300,7 +300,7 @@ class MEDIA_GPU_EXPORT VaapiWrapper ...@@ -300,7 +300,7 @@ class MEDIA_GPU_EXPORT VaapiWrapper
bool SyncSurface(VASurfaceID va_surface_id); bool SyncSurface(VASurfaceID va_surface_id);
// Calls SubmitBuffer_Locked() to request libva to allocate a new VABufferID // Calls SubmitBuffer_Locked() to request libva to allocate a new VABufferID
// of |va_buffer_type| and |size|, and to copy the |data| into it. The // of |va_buffer_type| and |size|, and to map-and-copy the |data| into it. The
// allocated VABufferIDs stay alive until DestroyPendingBuffers_Locked(). Note // allocated VABufferIDs stay alive until DestroyPendingBuffers_Locked(). Note
// that this method does not submit the buffers for execution, they are simply // that this method does not submit the buffers for execution, they are simply
// stored until ExecuteAndDestroyPendingBuffers()/Execute_Locked(). The // stored until ExecuteAndDestroyPendingBuffers()/Execute_Locked(). The
......
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