[avx2] Move dep quant stuff to strategies

This commit is contained in:
Joose Sainio 2023-04-17 15:14:35 +03:00
parent 0591342b3a
commit dfff9a8030
12 changed files with 1997 additions and 1464 deletions

View file

@ -144,7 +144,6 @@ target_include_directories(uvg266 PUBLIC src/extras)
target_include_directories(uvg266 PUBLIC src/strategies) target_include_directories(uvg266 PUBLIC src/strategies)
file(GLOB LIB_SOURCES_STRATEGIES_AVX2 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/avx2/*.c") file(GLOB LIB_SOURCES_STRATEGIES_AVX2 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/avx2/*.c")
file(GLOB LIB_SOURCES_STRATEGIES_AVX2 RELATIVE ${PROJECT_SOURCE_DIR} "src/dep_quant.c")
file(GLOB LIB_SOURCES_STRATEGIES_SSE41 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse41/*.c") file(GLOB LIB_SOURCES_STRATEGIES_SSE41 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse41/*.c")
file(GLOB LIB_SOURCES_STRATEGIES_SSE42 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse42/*.c") file(GLOB LIB_SOURCES_STRATEGIES_SSE42 RELATIVE ${PROJECT_SOURCE_DIR} "src/strategies/sse42/*.c")

File diff suppressed because it is too large Load diff

View file

@ -46,6 +46,8 @@
typedef struct encoder_control_t encoder_control_t; typedef struct encoder_control_t encoder_control_t;
enum ScanPosType { SCAN_ISCSBB = 0, SCAN_SOCSBB = 1, SCAN_EOCSBB = 2 };
struct dep_quant_scan_info struct dep_quant_scan_info
{ {
uint8_t sig_ctx_offset[2]; uint8_t sig_ctx_offset[2];
@ -97,6 +99,91 @@ typedef struct
uint16_t outPos[5]; uint16_t outPos[5];
} NbInfoOut; } NbInfoOut;
typedef struct {
int32_t absLevel[4];
int64_t deltaDist[4];
} PQData;
typedef struct {
int64_t ALIGNED(32) rdCost[8];
int32_t ALIGNED(32) absLevel[8];
int32_t ALIGNED(32) prevId[8];
} Decision;
typedef struct {
uint8_t* sbbFlags;
uint8_t* levels;
} SbbCtx;
typedef struct {
const NbInfoOut* m_nbInfo;
uint32_t m_sbbFlagBits[2][2];
SbbCtx m_allSbbCtx[8];
int m_curr_sbb_ctx_offset;
int m_prev_sbb_ctx_offset;
uint8_t sbb_memory[8 * 1024];
uint8_t level_memory[8 * TR_MAX_WIDTH * TR_MAX_WIDTH];
int num_coeff;
} common_context;
typedef struct {
int64_t m_rdCost;
uint16_t m_absLevelsAndCtxInit
[24]; // 16x8bit for abs levels + 16x16bit for ctx init id
int8_t m_numSigSbb;
int m_remRegBins;
int8_t m_refSbbCtxId;
uint32_t m_sbbFracBits[2];
uint32_t m_sigFracBits[2];
int32_t m_coeffFracBits[6];
int8_t m_goRicePar;
int8_t m_goRiceZero;
int8_t m_stateId;
uint32_t* m_sigFracBitsArray[12];
int32_t* m_gtxFracBitsArray[21];
common_context* m_commonCtx;
unsigned effWidth;
unsigned effHeight;
} depquant_state;
typedef struct {
int64_t ALIGNED(32) m_rdCost[12];
uint16_t ALIGNED(32) m_absLevelsAndCtxInit
[12][24]; // 16x8bit for abs levels + 16x16bit for ctx init id
int8_t ALIGNED(16) m_numSigSbb[12];
int ALIGNED(32) m_remRegBins[12];
int8_t ALIGNED(16) m_refSbbCtxId[12];
uint32_t ALIGNED(32) m_sbbFracBits[12][2];
uint32_t ALIGNED(32) m_sigFracBits[12][2];
int32_t ALIGNED(32) m_coeffFracBits[12][6];
int8_t ALIGNED(16) m_goRicePar[12];
int8_t ALIGNED(16) m_goRiceZero[12];
int8_t ALIGNED(16) m_stateId[12];
uint32_t ALIGNED(32) m_sigFracBitsArray[12][12][2];
int32_t ALIGNED(32) m_gtxFracBitsArray[21][6];
common_context* m_commonCtx;
unsigned effWidth;
unsigned effHeight;
bool all_gte_four;
bool all_lt_four;
} all_depquant_states;
typedef struct {
common_context m_common_context;
all_depquant_states m_allStates;
int m_curr_state_offset;
int m_prev_state_offset;
int m_skip_state_offset;
depquant_state m_startState;
quant_block* m_quant;
Decision m_trellis[TR_MAX_WIDTH * TR_MAX_WIDTH];
} context_store;
int uvg_init_nb_info(encoder_control_t* encoder); int uvg_init_nb_info(encoder_control_t* encoder);
void uvg_dealloc_nb_info(encoder_control_t* encoder); void uvg_dealloc_nb_info(encoder_control_t* encoder);
@ -122,4 +209,40 @@ int uvg_dep_quant(
enum uvg_tree_type tree_type, enum uvg_tree_type tree_type,
int* absSum, int* absSum,
const bool enableScalingLists); const bool enableScalingLists);
void uvg_dep_quant_update_state(
context_store* ctxs,
int numIPos,
const uint32_t scan_pos,
const Decision* decisions,
const uint32_t sigCtxOffsetNext,
const uint32_t gtxCtxOffsetNext,
const NbInfoSbb next_nb_info_ssb,
const int baseLevel,
const bool extRiceFlag,
int decision_id);
void uvg_dep_quant_update_state_eos(
context_store* ctxs,
const uint32_t scan_pos,
const uint32_t cg_pos,
const uint32_t sigCtxOffsetNext,
const uint32_t gtxCtxOffsetNext,
const uint32_t width_in_sbb,
const uint32_t height_in_sbb,
const uint32_t next_sbb_right,
const uint32_t next_sbb_below,
const Decision* decisions,
int decision_id);
void uvg_dep_quant_check_rd_costs(
const all_depquant_states* const state,
const enum ScanPosType spt,
const PQData* pqDataA,
Decision* decisions,
const int decisionA,
const int decisionB,
const int state_offset);
#endif #endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,46 @@
#ifndef STRATEGIES_DEPQUANT_AVX2_H_
#define STRATEGIES_DEPQUANT_AVX2_H_
/*****************************************************************************
* This file is part of uvg266 VVC encoder.
*
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
****************************************************************************/
/**
* \ingroup Optimization
* \file
* Optimizations for AVX2.
*/
#include "global.h" // IWYU pragma: keep
int uvg_strategy_register_depquant_avx2(void* opaque, uint8_t bitdepth);
#endif //STRATEGIES_DEPQUANT_AVX2_H_

View file

@ -0,0 +1,238 @@
/*****************************************************************************
* This file is part of uvg266 VVC encoder.
*
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
****************************************************************************/
#include "strategies/generic/depquant-generic.h"
#include "dep_quant.h"
#include "cu.h"
#include "encoderstate.h"
#include "intra.h"
#include "rdo.h"
#include "strategyselector.h"
#include "transform.h"
#include "uvg_math.h"
#include "generic/quant-generic.h"
static const int32_t g_goRiceBits[4][RICEMAX] = {
{32768, 65536, 98304, 131072, 163840, 196608, 262144, 262144,
327680, 327680, 327680, 327680, 393216, 393216, 393216, 393216,
393216, 393216, 393216, 393216, 458752, 458752, 458752, 458752,
458752, 458752, 458752, 458752, 458752, 458752, 458752, 458752},
{65536, 65536, 98304, 98304, 131072, 131072, 163840, 163840,
196608, 196608, 229376, 229376, 294912, 294912, 294912, 294912,
360448, 360448, 360448, 360448, 360448, 360448, 360448, 360448,
425984, 425984, 425984, 425984, 425984, 425984, 425984, 425984},
{98304, 98304, 98304, 98304, 131072, 131072, 131072, 131072,
163840, 163840, 163840, 163840, 196608, 196608, 196608, 196608,
229376, 229376, 229376, 229376, 262144, 262144, 262144, 262144,
327680, 327680, 327680, 327680, 327680, 327680, 327680, 327680},
{131072, 131072, 131072, 131072, 131072, 131072, 131072, 131072,
163840, 163840, 163840, 163840, 163840, 163840, 163840, 163840,
196608, 196608, 196608, 196608, 196608, 196608, 196608, 196608,
229376, 229376, 229376, 229376, 229376, 229376, 229376, 229376},
};
static INLINE void checkRdCostSkipSbbZeroOut(
Decision* decision,
const all_depquant_states* const state,
int decision_id,
int skip_offset) {
int64_t rdCost = state->m_rdCost[decision_id + skip_offset] + state->m_sbbFracBits[decision_id + skip_offset][0];
decision->rdCost[decision_id] = rdCost;
decision->absLevel[decision_id] = 0;
decision->prevId[decision_id] = 4 + state->m_stateId[decision_id + skip_offset];
}
static INLINE void checkRdCostSkipSbb(const all_depquant_states* const state, Decision * decisions, int decision_id, int skip_offset)
{
int64_t rdCost = state->m_rdCost[skip_offset + decision_id] + state->m_sbbFracBits[skip_offset + decision_id][0];
if (rdCost < decisions->rdCost[decision_id])
{
decisions->rdCost[decision_id] = rdCost;
decisions->absLevel[decision_id] = 0;
decisions->prevId[decision_id] = 4 + state->m_stateId[skip_offset + decision_id];
}
}
static INLINE void checkRdCostStart(const depquant_state* const state, int32_t lastOffset, const PQData *pqData, Decision *decisions, int
decision_id)
{
int64_t rdCost = pqData->deltaDist[decision_id] + lastOffset;
if (pqData->absLevel[decision_id] < 4) {
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id]];
}
else {
const coeff_t value = (pqData->absLevel[decision_id] - 4) >> 1;
rdCost += state->m_coeffFracBits[pqData->absLevel[decision_id] - (value << 1)]
+ g_goRiceBits[state->m_goRicePar][value < RICEMAX ? value : RICEMAX - 1];
}
if (rdCost < decisions->rdCost[decision_id]) {
decisions->rdCost[decision_id] = rdCost;
decisions->absLevel[decision_id] = pqData->absLevel[decision_id];
decisions->prevId[decision_id] = -1;
}
}
static const Decision startDec = { .rdCost = {INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2, INT64_MAX >> 2},
.absLevel = {-1, -1, -1, -1, 0, 0, 0, 0}, .prevId = {-2, -2, -2, -2, 4, 5, 6, 7} };
static INLINE void preQuantCoeff(const quant_block * const qp, const coeff_t absCoeff, PQData* pqData, coeff_t quanCoeff)
{
int64_t scaledOrg = (int64_t)(absCoeff) * quanCoeff;
coeff_t qIdx = MAX(1, (coeff_t)MIN(qp->m_maxQIdx, ((scaledOrg + qp->m_QAdd) >> qp->m_QShift)));
int64_t scaledAdd = qIdx * qp->m_DistStepAdd - scaledOrg * qp->m_DistOrgFact;
int index = qIdx & 3;
pqData->deltaDist[index] = (scaledAdd * qIdx + qp->m_DistAdd) >> qp->m_DistShift;
pqData->absLevel[index] = (++qIdx) >> 1;
scaledAdd += qp->m_DistStepAdd;
index = qIdx & 3;
pqData->deltaDist[index] = (scaledAdd * qIdx + qp->m_DistAdd) >> qp->m_DistShift;
pqData->absLevel[index] = (++qIdx) >> 1;
scaledAdd += qp->m_DistStepAdd;
index = qIdx & 3;
pqData->deltaDist[index] = (scaledAdd * qIdx + qp->m_DistAdd) >> qp->m_DistShift;
pqData->absLevel[index] = (++qIdx) >> 1;
scaledAdd += qp->m_DistStepAdd;
index = qIdx & 3;
pqData->deltaDist[index] = (scaledAdd * qIdx + qp->m_DistAdd) >> qp->m_DistShift;
pqData->absLevel[index] = (++qIdx) >> 1;
}
static void xDecide(
all_depquant_states* const all_states,
depquant_state* const m_startState,
quant_block* qp,
const enum ScanPosType spt,
const coeff_t absCoeff,
const int lastOffset,
Decision* decisions,
bool zeroOut,
coeff_t quanCoeff,
const int skip_offset,
const int prev_offset)
{
memcpy(decisions, &startDec, sizeof(Decision));
if (zeroOut) {
if (spt == SCAN_EOCSBB) {
checkRdCostSkipSbbZeroOut(decisions, all_states, 0, skip_offset);
checkRdCostSkipSbbZeroOut(decisions, all_states, 1, skip_offset);
checkRdCostSkipSbbZeroOut(decisions, all_states, 2, skip_offset);
checkRdCostSkipSbbZeroOut(decisions, all_states, 3, skip_offset);
}
return;
}
PQData pqData;
preQuantCoeff(qp, absCoeff, &pqData, quanCoeff);
uvg_dep_quant_check_rd_costs(all_states, spt, &pqData, decisions, 0, 2, prev_offset + 0);
uvg_dep_quant_check_rd_costs(all_states, spt, &pqData, decisions, 2, 0, prev_offset + 1);
uvg_dep_quant_check_rd_costs(all_states, spt, &pqData, decisions, 1, 3, prev_offset + 2);
uvg_dep_quant_check_rd_costs(all_states, spt, &pqData, decisions, 3, 1, prev_offset + 3);
if (spt == SCAN_EOCSBB) {
checkRdCostSkipSbb(all_states, decisions, 0, skip_offset);
checkRdCostSkipSbb(all_states, decisions, 1, skip_offset);
checkRdCostSkipSbb(all_states, decisions, 2, skip_offset);
checkRdCostSkipSbb(all_states, decisions, 3, skip_offset);
}
checkRdCostStart(m_startState, lastOffset, &pqData, decisions, 0);
checkRdCostStart(m_startState, lastOffset, &pqData, decisions, 2);
}
static void uvg_dep_quant_decide_and_update_generic(
rate_estimator_t* re,
context_store* ctxs,
struct dep_quant_scan_info const* const scan_info,
const coeff_t absCoeff,
const uint32_t scan_pos,
const uint32_t width_in_sbb,
const uint32_t height_in_sbb,
const NbInfoSbb next_nb_info_ssb,
bool zeroOut,
coeff_t quantCoeff,
const uint32_t effWidth,
const uint32_t effHeight,
bool is_chroma)
{
Decision* decisions = &ctxs->m_trellis[scan_pos];
SWAP(ctxs->m_curr_state_offset, ctxs->m_prev_state_offset, int);
enum ScanPosType spt = 0;
if ((scan_pos & 15) == 15 && scan_pos > 16 && scan_pos < effHeight * effWidth - 1)
{
spt = SCAN_SOCSBB;
}
else if ((scan_pos & 15) == 0 && scan_pos > 0 && scan_pos < effHeight * effWidth - 16)
{
spt = SCAN_EOCSBB;
}
xDecide(&ctxs->m_allStates, &ctxs->m_startState, ctxs->m_quant, spt, absCoeff, re->m_lastBitsX[scan_info->pos_x] + re->m_lastBitsY[scan_info->pos_y], decisions, zeroOut, quantCoeff,ctxs->m_skip_state_offset, ctxs->m_prev_state_offset);
if (scan_pos) {
if (!(scan_pos & 15)) {
SWAP(ctxs->m_common_context.m_curr_sbb_ctx_offset, ctxs->m_common_context.m_prev_sbb_ctx_offset, int);
uvg_dep_quant_update_state_eos(ctxs, scan_pos, scan_info->cg_pos, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], width_in_sbb, height_in_sbb, scan_info->next_sbb_right, scan_info->next_sbb_below, decisions, 0);
uvg_dep_quant_update_state_eos(ctxs, scan_pos, scan_info->cg_pos, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], width_in_sbb, height_in_sbb, scan_info->next_sbb_right, scan_info->next_sbb_below, decisions, 1);
uvg_dep_quant_update_state_eos(ctxs, scan_pos, scan_info->cg_pos, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], width_in_sbb, height_in_sbb, scan_info->next_sbb_right, scan_info->next_sbb_below, decisions, 2);
uvg_dep_quant_update_state_eos(ctxs, scan_pos, scan_info->cg_pos, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], width_in_sbb, height_in_sbb, scan_info->next_sbb_right, scan_info->next_sbb_below, decisions, 3);
memcpy(decisions->prevId + 4, decisions->prevId, 4 * sizeof(int32_t));
memcpy(decisions->absLevel + 4, decisions->absLevel, 4 * sizeof(int32_t));
memcpy(decisions->rdCost + 4, decisions->rdCost, 4 * sizeof(int64_t));
} else if (!zeroOut) {
uvg_dep_quant_update_state(ctxs, next_nb_info_ssb.num, scan_pos, decisions, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], next_nb_info_ssb, 4, false, 0);
uvg_dep_quant_update_state(ctxs, next_nb_info_ssb.num, scan_pos, decisions, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], next_nb_info_ssb, 4, false, 1);
uvg_dep_quant_update_state(ctxs, next_nb_info_ssb.num, scan_pos, decisions, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], next_nb_info_ssb, 4, false, 2);
uvg_dep_quant_update_state(ctxs, next_nb_info_ssb.num, scan_pos, decisions, scan_info->sig_ctx_offset[is_chroma], scan_info->gtx_ctx_offset[is_chroma], next_nb_info_ssb, 4, false, 3);
}
if (spt == SCAN_SOCSBB) {
SWAP(ctxs->m_skip_state_offset, ctxs->m_prev_state_offset, int);
}
}
}
int uvg_strategy_register_depquant_generic(void* opaque, uint8_t bitdepth)
{
bool success = true;
success &= uvg_strategyselector_register(opaque, "dep_quant_decide_and_update", "generic", 40, &uvg_dep_quant_decide_and_update_generic);
return success;
}

View file

@ -0,0 +1,50 @@
#ifndef STRATEGIES_DEPQUANT_GENERIC_H_
#define STRATEGIES_DEPQUANT_GENERIC_H_
/*****************************************************************************
* This file is part of uvg266 VVC encoder.
*
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
****************************************************************************/
/**
* \ingroup Optimization
* \file
* Generic C implementations of optimized functions.
*/
#include "cu.h"
#include "encoderstate.h"
#include "global.h" // IWYU pragma: keep
#include "uvg266.h"
#include "tables.h"
int uvg_strategy_register_depquant_generic(void* opaque, uint8_t bitdepth);
#endif //STRATEGIES_DEPQUANT_GENERIC_H_

View file

@ -0,0 +1,54 @@
/*****************************************************************************
* This file is part of uvg266 VVC encoder.
*
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
****************************************************************************/
#include "strategies/strategies-depquant.h"
#include "strategies/avx2/depquant-avx2.h"
#include "strategies/generic/depquant-generic.h"
#include "strategyselector.h"
// Define function pointers.
dep_quant_decide_and_update_func* uvg_dep_quant_decide_and_update;
int uvg_strategy_register_depquant(void *opaque, uint8_t bitdepth)
{
bool success = true;
success &= uvg_strategy_register_depquant_generic(opaque, bitdepth);
if (uvg_g_hardware_flags.intel_flags.avx2) {
success &= uvg_strategy_register_depquant_avx2(opaque, bitdepth);
}
return success;
}

View file

@ -0,0 +1,77 @@
#ifndef STRATEGIES_DEPQUANT_H_
#define STRATEGIES_DEPQUANT_H_
/*****************************************************************************
* This file is part of uvg266 VVC encoder.
*
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
****************************************************************************/
/**
* \ingroup Optimization
* \file
* Interface for sao functions.
*/
#include "encoder.h"
#include "encoderstate.h"
#include "global.h" // IWYU pragma: keep
#include "uvg266.h"
#include "dep_quant.h"
// Declare function pointers.
typedef int(dep_quant_decide_and_update_func)(
rate_estimator_t* re,
context_store* ctxs,
struct dep_quant_scan_info const* const scan_info,
const coeff_t absCoeff,
const uint32_t scan_pos,
const uint32_t width_in_sbb,
const uint32_t height_in_sbb,
const NbInfoSbb next_nb_info_ssb,
bool zeroOut,
coeff_t quantCoeff,
const uint32_t effWidth,
const uint32_t effHeight,
bool is_chroma);
// Declare function pointers.
extern dep_quant_decide_and_update_func* uvg_dep_quant_decide_and_update;
int uvg_strategy_register_depquant(void* opaque, uint8_t bitdepth);
#define STRATEGIES_DEPQUANT_EXPORTS \
{"dep_quant_decide_and_update", (void**)&uvg_dep_quant_decide_and_update}, \
#endif //STRATEGIES_DEPQUANT_H_

View file

@ -38,15 +38,16 @@
// Define function pointers. // Define function pointers.
quant_func *uvg_quant; quant_func *uvg_quant;
quant_cbcr_func *uvg_quant_cbcr_residual; quant_cbcr_func *uvg_quant_cbcr_residual;
quant_residual_func *uvg_quantize_residual; quant_residual_func *uvg_quantize_residual;
dequant_func *uvg_dequant; dequant_func *uvg_dequant;
coeff_abs_sum_func *uvg_coeff_abs_sum; coeff_abs_sum_func *uvg_coeff_abs_sum;
fast_coeff_cost_func *uvg_fast_coeff_cost; fast_coeff_cost_func *uvg_fast_coeff_cost;
int uvg_strategy_register_quant(void* opaque, uint8_t bitdepth) { int uvg_strategy_register_quant(void *opaque, uint8_t bitdepth)
{
bool success = true; bool success = true;
success &= uvg_strategy_register_quant_generic(opaque, bitdepth); success &= uvg_strategy_register_quant_generic(opaque, bitdepth);

View file

@ -107,6 +107,10 @@ int uvg_strategyselector_init(int32_t cpuid, uint8_t bitdepth) {
fprintf(stderr, "uvg_strategy_register_encode failed!\n"); fprintf(stderr, "uvg_strategy_register_encode failed!\n");
return 0; return 0;
} }
if (!uvg_strategy_register_depquant(&strategies, bitdepth)) {
fprintf(stderr, "uvg_strategy_register_depquant failed!\n");
return 0;
}
while(cur_strategy_to_select->fptr) { while(cur_strategy_to_select->fptr) {
*(cur_strategy_to_select->fptr) = strategyselector_choose_for(&strategies, cur_strategy_to_select->strategy_type); *(cur_strategy_to_select->fptr) = strategyselector_choose_for(&strategies, cur_strategy_to_select->strategy_type);

View file

@ -108,6 +108,7 @@ int uvg_strategyselector_register(void *opaque, const char *type, const char *st
#include "strategies/strategies-intra.h" #include "strategies/strategies-intra.h"
#include "strategies/strategies-sao.h" #include "strategies/strategies-sao.h"
#include "strategies/strategies-encode.h" #include "strategies/strategies-encode.h"
#include "strategies/strategies-depquant.h"
#include "strategies/strategies-alf.h" #include "strategies/strategies-alf.h"
static const strategy_to_select_t strategies_to_select[] = { static const strategy_to_select_t strategies_to_select[] = {
@ -120,6 +121,7 @@ static const strategy_to_select_t strategies_to_select[] = {
STRATEGIES_SAO_EXPORTS STRATEGIES_SAO_EXPORTS
STRATEGIES_ENCODE_EXPORTS STRATEGIES_ENCODE_EXPORTS
STRATEGIES_ALF_EXPORTS STRATEGIES_ALF_EXPORTS
STRATEGIES_DEPQUANT_EXPORTS
{ NULL, NULL }, { NULL, NULL },
}; };