1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:07:46 +00:00

LibVideo/VP9: Count syntax elements in TileContext, and sum at the end

Syntax element counters were previously accessed across tiles, which
would cause a race condition updating the counts in a tile-threaded
mode.
This commit is contained in:
Zaggy1024 2023-02-13 17:13:16 -06:00 committed by Jelle Raaijmakers
parent a8604d9356
commit 1fcac52e77
7 changed files with 120 additions and 48 deletions

View file

@ -5,10 +5,11 @@
*/
#include "SyntaxElementCounter.h"
#include <AK/Format.h>
namespace Video::VP9 {
void SyntaxElementCounter::clear_counts()
SyntaxElementCounter::SyntaxElementCounter()
{
__builtin_memset(m_counts_intra_mode, 0, sizeof(m_counts_intra_mode));
__builtin_memset(m_counts_uv_mode, 0, sizeof(m_counts_uv_mode));
@ -34,4 +35,54 @@ void SyntaxElementCounter::clear_counts()
__builtin_memset(m_counts_more_coefs, 0, sizeof(m_counts_more_coefs));
}
template<typename T, size_t size>
static void sum_arrays(T (&destination)[size], const T (&left)[size], const T (&right)[size])
{
for (size_t i = 0; i < size; i++) {
destination[i] = left[i] + right[i];
}
}
template<typename T, size_t size, size_t size_2>
static void sum_arrays(T (&destination)[size][size_2], const T (&left)[size][size_2], const T (&right)[size][size_2])
{
for (size_t i = 0; i < size; i++) {
sum_arrays(destination[i], left[i], right[i]);
}
}
SyntaxElementCounter SyntaxElementCounter::operator+(SyntaxElementCounter const& other) const
{
SyntaxElementCounter result;
sum_arrays(result.m_counts_intra_mode, this->m_counts_intra_mode, other.m_counts_intra_mode);
sum_arrays(result.m_counts_uv_mode, this->m_counts_uv_mode, other.m_counts_uv_mode);
sum_arrays(result.m_counts_partition, this->m_counts_partition, other.m_counts_partition);
sum_arrays(result.m_counts_interp_filter, this->m_counts_interp_filter, other.m_counts_interp_filter);
sum_arrays(result.m_counts_inter_mode, this->m_counts_inter_mode, other.m_counts_inter_mode);
sum_arrays(result.m_counts_tx_size, this->m_counts_tx_size, other.m_counts_tx_size);
sum_arrays(result.m_counts_is_inter, this->m_counts_is_inter, other.m_counts_is_inter);
sum_arrays(result.m_counts_comp_mode, this->m_counts_comp_mode, other.m_counts_comp_mode);
sum_arrays(result.m_counts_single_ref, this->m_counts_single_ref, other.m_counts_single_ref);
sum_arrays(result.m_counts_comp_ref, this->m_counts_comp_ref, other.m_counts_comp_ref);
sum_arrays(result.m_counts_skip, this->m_counts_skip, other.m_counts_skip);
sum_arrays(result.m_counts_mv_joint, this->m_counts_mv_joint, other.m_counts_mv_joint);
sum_arrays(result.m_counts_mv_sign, this->m_counts_mv_sign, other.m_counts_mv_sign);
sum_arrays(result.m_counts_mv_class, this->m_counts_mv_class, other.m_counts_mv_class);
sum_arrays(result.m_counts_mv_class0_bit, this->m_counts_mv_class0_bit, other.m_counts_mv_class0_bit);
sum_arrays(result.m_counts_mv_class0_fr, this->m_counts_mv_class0_fr, other.m_counts_mv_class0_fr);
sum_arrays(result.m_counts_mv_class0_hp, this->m_counts_mv_class0_hp, other.m_counts_mv_class0_hp);
sum_arrays(result.m_counts_mv_bits, this->m_counts_mv_bits, other.m_counts_mv_bits);
sum_arrays(result.m_counts_mv_fr, this->m_counts_mv_fr, other.m_counts_mv_fr);
sum_arrays(result.m_counts_mv_hp, this->m_counts_mv_hp, other.m_counts_mv_hp);
sum_arrays(result.m_counts_token, this->m_counts_token, other.m_counts_token);
sum_arrays(result.m_counts_more_coefs, this->m_counts_more_coefs, other.m_counts_more_coefs);
return result;
}
SyntaxElementCounter& SyntaxElementCounter::operator+=(SyntaxElementCounter const& other)
{
*this = *this + other;
return *this;
}
}