mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-27 11:24:05 +00:00
Add strategy for avx2. Copy generic functions there.
This commit is contained in:
parent
4e30a215d8
commit
04fbb48a09
|
@ -163,6 +163,12 @@
|
|||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\strategies\avx2\sao-avx2.c">
|
||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
<EnableEnhancedInstructionSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AdvancedVectorExtensions2</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\strategies\generic\intra-generic.c" />
|
||||
<ClCompile Include="..\..\src\strategies\generic\quant-generic.c" />
|
||||
<ClCompile Include="..\..\src\strategies\generic\sao-generic.c" />
|
||||
|
@ -217,6 +223,7 @@
|
|||
<ClInclude Include="..\..\src\search_inter.h" />
|
||||
<ClInclude Include="..\..\src\search_intra.h" />
|
||||
<ClInclude Include="..\..\src\strategies\avx2\intra-avx2.h" />
|
||||
<ClInclude Include="..\..\src\strategies\avx2\sao-avx2.h" />
|
||||
<ClInclude Include="..\..\src\strategies\generic\intra-generic.h" />
|
||||
<ClInclude Include="..\..\src\strategies\generic\sao-generic.h" />
|
||||
<ClInclude Include="..\..\src\strategies\strategies-common.h" />
|
||||
|
|
|
@ -213,6 +213,9 @@
|
|||
<ClCompile Include="..\..\src\strategies\generic\sao-generic.c">
|
||||
<Filter>Optimization\strategies\generic</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\strategies\avx2\sao-avx2.c">
|
||||
<Filter>Optimization\strategies\avx2</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\bitstream.h">
|
||||
|
@ -395,6 +398,9 @@
|
|||
<ClInclude Include="..\..\src\strategies\generic\sao-generic.h">
|
||||
<Filter>Optimization\strategies\generic</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\strategies\avx2\sao-avx2.h">
|
||||
<Filter>Optimization\strategies\avx2</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<YASM Include="..\..\src\extras\x86inc.asm">
|
||||
|
|
|
@ -154,7 +154,10 @@ libavx2_la_SOURCES = \
|
|||
strategies/avx2/picture-avx2.c \
|
||||
strategies/avx2/picture-avx2.h \
|
||||
strategies/avx2/quant-avx2.c \
|
||||
strategies/avx2/quant-avx2.h
|
||||
strategies/avx2/quant-avx2.h \
|
||||
strategies/avx2/sao-avx2.c \
|
||||
strategies/avx2/sao-avx2.h
|
||||
|
||||
|
||||
libsse2_la_SOURCES = \
|
||||
strategies/sse2/picture-sse2.c \
|
||||
|
|
187
src/strategies/avx2/sao-avx2.c
Normal file
187
src/strategies/avx2/sao-avx2.c
Normal file
|
@ -0,0 +1,187 @@
|
|||
/*****************************************************************************
|
||||
* This file is part of Kvazaar HEVC encoder.
|
||||
*
|
||||
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
||||
* COPYING file).
|
||||
*
|
||||
* Kvazaar is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "sao-avx2.h"
|
||||
#include "sao.h"
|
||||
#include "strategyselector.h"
|
||||
#include "rdo.h"
|
||||
|
||||
#if COMPILE_INTEL_AVX2
|
||||
#include <immintrin.h>
|
||||
|
||||
// Mapping of edge_idx values to eo-classes.
|
||||
static int sao_calc_eo_cat(kvz_pixel a, kvz_pixel b, kvz_pixel c)
|
||||
{
|
||||
// Mapping relationships between a, b and c to eo_idx.
|
||||
static const int sao_eo_idx_to_eo_category[] = { 1, 2, 0, 3, 4 };
|
||||
|
||||
int eo_idx = 2 + SIGN3((int)c - (int)a) + SIGN3((int)c - (int)b);
|
||||
|
||||
return sao_eo_idx_to_eo_category[eo_idx];
|
||||
}
|
||||
|
||||
|
||||
int kvz_sao_edge_ddistortion_avx2(const kvz_pixel *orig_data, const kvz_pixel *rec_data,
|
||||
int block_width, int block_height,
|
||||
int eo_class, int offsets[NUM_SAO_EDGE_CATEGORIES])
|
||||
{
|
||||
int y, x;
|
||||
int sum = 0;
|
||||
vector2d_t a_ofs = g_sao_edge_offsets[eo_class][0];
|
||||
vector2d_t b_ofs = g_sao_edge_offsets[eo_class][1];
|
||||
|
||||
for (y = 1; y < block_height - 1; ++y) {
|
||||
for (x = 1; x < block_width - 1; ++x) {
|
||||
const kvz_pixel *c_data = &rec_data[y * block_width + x];
|
||||
kvz_pixel a = c_data[a_ofs.y * block_width + a_ofs.x];
|
||||
kvz_pixel c = c_data[0];
|
||||
kvz_pixel b = c_data[b_ofs.y * block_width + b_ofs.x];
|
||||
|
||||
int offset = offsets[sao_calc_eo_cat(a, b, c)];
|
||||
|
||||
if (offset != 0) {
|
||||
int diff = orig_data[y * block_width + x] - c;
|
||||
// Offset is applied to reconstruction, so it is subtracted from diff.
|
||||
sum += (diff - offset) * (diff - offset) - diff * diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \param orig_data Original pixel data. 64x64 for luma, 32x32 for chroma.
|
||||
* \param rec_data Reconstructed pixel data. 64x64 for luma, 32x32 for chroma.
|
||||
* \param dir_offsets
|
||||
* \param is_chroma 0 for luma, 1 for chroma. Indicates
|
||||
*/
|
||||
void kvz_calc_sao_edge_dir_avx2(const kvz_pixel *orig_data, const kvz_pixel *rec_data,
|
||||
int eo_class, int block_width, int block_height,
|
||||
int cat_sum_cnt[2][NUM_SAO_EDGE_CATEGORIES])
|
||||
{
|
||||
int y, x;
|
||||
vector2d_t a_ofs = g_sao_edge_offsets[eo_class][0];
|
||||
vector2d_t b_ofs = g_sao_edge_offsets[eo_class][1];
|
||||
// Arrays orig_data and rec_data are quarter size for chroma.
|
||||
|
||||
// Don't sample the edge pixels because this function doesn't have access to
|
||||
// their neighbours.
|
||||
for (y = 1; y < block_height - 1; ++y) {
|
||||
for (x = 1; x < block_width - 1; ++x) {
|
||||
const kvz_pixel *c_data = &rec_data[y * block_width + x];
|
||||
kvz_pixel a = c_data[a_ofs.y * block_width + a_ofs.x];
|
||||
kvz_pixel c = c_data[0];
|
||||
kvz_pixel b = c_data[b_ofs.y * block_width + b_ofs.x];
|
||||
|
||||
int eo_cat = sao_calc_eo_cat(a, b, c);
|
||||
|
||||
cat_sum_cnt[0][eo_cat] += orig_data[y * block_width + x] - c;
|
||||
cat_sum_cnt[1][eo_cat] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void kvz_sao_reconstruct_color_avx2(const encoder_control_t * const encoder,
|
||||
const kvz_pixel *rec_data, kvz_pixel *new_rec_data,
|
||||
const sao_info_t *sao,
|
||||
int stride, int new_stride,
|
||||
int block_width, int block_height,
|
||||
color_t color_i)
|
||||
{
|
||||
int y, x;
|
||||
// Arrays orig_data and rec_data are quarter size for chroma.
|
||||
int offset_v = color_i == COLOR_V ? 5 : 0;
|
||||
|
||||
if(sao->type == SAO_TYPE_BAND) {
|
||||
int offsets[1<<KVZ_BIT_DEPTH];
|
||||
kvz_calc_sao_offset_array(encoder, sao, offsets, color_i);
|
||||
for (y = 0; y < block_height; ++y) {
|
||||
for (x = 0; x < block_width; ++x) {
|
||||
new_rec_data[y * new_stride + x] = offsets[rec_data[y * stride + x]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Don't sample the edge pixels because this function doesn't have access to
|
||||
// their neighbours.
|
||||
for (y = 0; y < block_height; ++y) {
|
||||
for (x = 0; x < block_width; ++x) {
|
||||
vector2d_t a_ofs = g_sao_edge_offsets[sao->eo_class][0];
|
||||
vector2d_t b_ofs = g_sao_edge_offsets[sao->eo_class][1];
|
||||
const kvz_pixel *c_data = &rec_data[y * stride + x];
|
||||
kvz_pixel *new_data = &new_rec_data[y * new_stride + x];
|
||||
kvz_pixel a = c_data[a_ofs.y * stride + a_ofs.x];
|
||||
kvz_pixel c = c_data[0];
|
||||
kvz_pixel b = c_data[b_ofs.y * stride + b_ofs.x];
|
||||
|
||||
int eo_cat = sao_calc_eo_cat(a, b, c);
|
||||
|
||||
new_data[0] = (kvz_pixel)CLIP(0, (1 << KVZ_BIT_DEPTH) - 1, c_data[0] + sao->offsets[eo_cat + offset_v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int kvz_sao_band_ddistortion_avx2(const encoder_state_t * const state, const kvz_pixel *orig_data, const kvz_pixel *rec_data,
|
||||
int block_width, int block_height,
|
||||
int band_pos, int sao_bands[4])
|
||||
{
|
||||
int y, x;
|
||||
int shift = state->encoder_control->bitdepth-5;
|
||||
int sum = 0;
|
||||
|
||||
for (y = 0; y < block_height; ++y) {
|
||||
for (x = 0; x < block_width; ++x) {
|
||||
int band = (rec_data[y * block_width + x] >> shift) - band_pos;
|
||||
int offset = 0;
|
||||
if (band >= 0 && band < 4) {
|
||||
offset = sao_bands[band];
|
||||
}
|
||||
if (offset != 0) {
|
||||
int diff = orig_data[y * block_width + x] - rec_data[y * block_width + x];
|
||||
// Offset is applied to reconstruction, so it is subtracted from diff.
|
||||
sum += (diff - offset) * (diff - offset) - diff * diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
#endif //COMPILE_INTEL_AVX2
|
||||
|
||||
int kvz_strategy_register_sao_avx2(void* opaque, uint8_t bitdepth)
|
||||
{
|
||||
bool success = true;
|
||||
#if COMPILE_INTEL_AVX2
|
||||
if (bitdepth == 8) {
|
||||
success &= kvz_strategyselector_register(opaque, "sao_edge_ddistortion", "avx2", 40, &kvz_sao_edge_ddistortion_avx2);
|
||||
success &= kvz_strategyselector_register(opaque, "calc_sao_edge_dir", "avx2", 40, &kvz_calc_sao_edge_dir_avx2);
|
||||
success &= kvz_strategyselector_register(opaque, "sao_reconstruct_color", "avx2", 40, &kvz_sao_reconstruct_color_avx2);
|
||||
success &= kvz_strategyselector_register(opaque, "sao_band_ddistortion", "avx2", 40, &kvz_sao_band_ddistortion_avx2);
|
||||
}
|
||||
#endif //COMPILE_INTEL_AVX2
|
||||
return success;
|
||||
}
|
33
src/strategies/avx2/sao-avx2.h
Normal file
33
src/strategies/avx2/sao-avx2.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef STRATEGIES_SAO_AVX2_H_
|
||||
#define STRATEGIES_SAO_AVX2_H_
|
||||
/*****************************************************************************
|
||||
* This file is part of Kvazaar HEVC encoder.
|
||||
*
|
||||
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
||||
* COPYING file).
|
||||
*
|
||||
* Kvazaar is free software: you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* \ingroup Optimization
|
||||
* \file
|
||||
* AVX2 implementations of optimized functions.
|
||||
*/
|
||||
|
||||
#include "global.h"
|
||||
|
||||
int kvz_strategy_register_sao_avx2(void* opaque, uint8_t bitdepth);
|
||||
|
||||
#endif //STRATEGIES_SAO_AVX2_H_
|
|
@ -29,6 +29,7 @@ sao_band_ddistortion_func * kvz_sao_band_ddistortion;
|
|||
|
||||
// Headers for platform optimizations.
|
||||
#include "generic/sao-generic.h"
|
||||
#include "avx2/sao-avx2.h"
|
||||
|
||||
|
||||
int kvz_strategy_register_sao(void* opaque, uint8_t bitdepth) {
|
||||
|
@ -36,5 +37,9 @@ int kvz_strategy_register_sao(void* opaque, uint8_t bitdepth) {
|
|||
|
||||
success &= kvz_strategy_register_sao_generic(opaque, bitdepth);
|
||||
|
||||
if (kvz_g_hardware_flags.intel_flags.avx2) {
|
||||
success &= kvz_strategy_register_sao_avx2(opaque, bitdepth);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
Loading…
Reference in a new issue