Merge branch 'rdoq_sign_hiding_fix'

This commit is contained in:
Marko Viitanen 2021-02-12 16:42:32 +02:00
commit 2d4a9a036a
7 changed files with 29 additions and 20 deletions

View file

@ -1298,6 +1298,12 @@ void kvz_encoder_state_write_bitstream_slice_header(
}
}
// ToDo: depquant
if (state->encoder_control->cfg.signhide_enable) {
WRITE_U(stream, 1, 1, "sh_sign_data_hiding_used_flag");
}
if (state->frame->slicetype != KVZ_SLICE_I) {
// BT Size set only with non-I-frames, in I-frames the size is 32x32

View file

@ -638,7 +638,7 @@ void kvz_rdoq_sign_hiding(
* coding engines using probability models like CABAC
* From HM 12.0
*/
/*
// ToDo: implement new RDOQ
void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff, int32_t width,
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth)
@ -699,7 +699,7 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff,
default: assert(0 && "There should be 1, 4, 16 or 64 coefficient groups");
}
cabac_ctx_t *base_coeff_group_ctx = &(cabac->ctx.cu_sig_coeff_group_model[type]);
cabac_ctx_t *base_coeff_group_ctx = &(cabac->ctx.sig_coeff_group_model[type]);
cabac_ctx_t *baseCtx = (type == 0) ? &(cabac->ctx.cu_sig_model_luma[0][0]) : &(cabac->ctx.cu_sig_model_chroma[0][0]);
struct {
@ -974,7 +974,7 @@ void kvz_rdoq(encoder_state_t * const state, coeff_t *coef, coeff_t *dest_coeff,
kvz_rdoq_sign_hiding(state, qp_scaled, scan, &sh_rates, best_last_idx_p1, coef, dest_coeff);
}
}
*/
/**
* Calculate cost of actual motion vectors using CABAC coding

View file

@ -36,8 +36,8 @@
extern const uint32_t kvz_g_go_rice_range[5];
extern const uint32_t kvz_g_go_rice_prefix_len[5];
/*void kvz_rdoq(encoder_state_t *state, coeff_t *coef, coeff_t *dest_coeff, int32_t width,
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth);*/
void kvz_rdoq(encoder_state_t *state, coeff_t *coef, coeff_t *dest_coeff, int32_t width,
int32_t height, int8_t type, int8_t scan_mode, int8_t block_type, int8_t tr_depth);
uint32_t kvz_get_coeff_cost(const encoder_state_t * const state,
const coeff_t *coeff,

View file

@ -349,8 +349,8 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr
int32_t height, int8_t type, int8_t scan_idx, int8_t block_type)
{
const encoder_control_t * const encoder = state->encoder_control;
//const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2;
//const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1];
const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2;
const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1];
int32_t qp_scaled = kvz_get_scaled_qp(type, state->qp, (encoder->bitdepth - 8) * 6);
const uint32_t log2_tr_size = kvz_g_convert_to_bit[width] + 2;
@ -359,7 +359,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr
const int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform
const int32_t q_bits = QUANT_SHIFT + qp_scaled / 6 + transform_shift;
const int32_t add = ((state->frame->slicetype == KVZ_SLICE_I) ? 171 : 85) << (q_bits - 9);
//const int32_t q_bits8 = q_bits - 8;
const int32_t q_bits8 = q_bits - 8;
uint32_t ac_sum = 0;
int32_t last_cg = -1;
@ -433,7 +433,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr
temp = _mm_add_epi32(temp, _mm_shuffle_epi32(temp, _MM_SHUFFLE(1, 0, 3, 2)));
temp = _mm_add_epi32(temp, _mm_shuffle_epi32(temp, _MM_SHUFFLE(0, 1, 0, 1)));
ac_sum += _mm_cvtsi128_si32(temp);
/*
// Signhiding disabled in VVC
if (!encoder->cfg.signhide_enable || ac_sum < 2)
return;
@ -505,7 +505,7 @@ void kvz_quant_avx2(const encoder_state_t * const state, const coeff_t * __restr
#undef VEC_WIDTH
#undef SCAN_SET_SIZE
#undef LOG2_SCAN_SET_SIZE
*/
}
#if KVZ_BIT_DEPTH == 8
@ -658,7 +658,7 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state,
}
// Quantize coeffs. (coeff -> coeff_out)
/*
if (state->encoder_control->cfg.rdoq_enable &&
(width > 4 || !state->encoder_control->cfg.rdoq_skip))
{
@ -666,7 +666,7 @@ int kvz_quantize_residual_avx2(encoder_state_t *const state,
tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0);
kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
scan_order, cur_cu->type, tr_depth);
} else*/ {
} else {
kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
scan_order, cur_cu->type);
}

View file

@ -273,6 +273,7 @@ void kvz_encode_coeff_nxn_generic(encoder_state_t * const state,
quant_state = (quant_state_transition_table >> ((quant_state << 2) + ((coeff_abs & 1) << 1))) & 3;
if (coeff_abs) {
num_non_zero++;
first_nz_pos_in_cg = scan_pos;
last_nz_pos_in_cg = MAX(last_nz_pos_in_cg, scan_pos);
coeff_signs <<= 1;
if (coeff[blk_pos] < 0) coeff_signs++;

View file

@ -38,8 +38,8 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff
int32_t height, int8_t type, int8_t scan_idx, int8_t block_type)
{
const encoder_control_t * const encoder = state->encoder_control;
//const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2;
//const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1];
const uint32_t log2_block_size = kvz_g_convert_to_bit[width] + 2;
const uint32_t * const scan = kvz_g_sig_last_scan[scan_idx][log2_block_size - 1];
int32_t qp_scaled = kvz_get_scaled_qp(type, state->qp, (encoder->bitdepth - 8) * 6);
const uint32_t log2_tr_size = kvz_g_convert_to_bit[width] + 2;
@ -48,7 +48,7 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff
const int32_t transform_shift = MAX_TR_DYNAMIC_RANGE - encoder->bitdepth - log2_tr_size; //!< Represents scaling through forward transform
const int32_t q_bits = QUANT_SHIFT + qp_scaled / 6 + transform_shift;
const int32_t add = ((state->frame->slicetype == KVZ_SLICE_I) ? 171 : 85) << (q_bits - 9);
//const int32_t q_bits8 = q_bits - 8;
const int32_t q_bits8 = q_bits - 8;
uint32_t ac_sum = 0;
@ -67,8 +67,8 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff
q_coef[n] = (coeff_t)(CLIP(-32768, 32767, level));
}
/*
// Signhiding disabled in VVC
// Signhiding
if (!encoder->cfg.signhide_enable || ac_sum < 2) return;
int32_t delta_u[LCU_WIDTH*LCU_WIDTH >> 2];
@ -165,7 +165,6 @@ void kvz_quant_generic(const encoder_state_t * const state, coeff_t *coef, coeff
#undef SCAN_SET_SIZE
#undef LOG2_SCAN_SET_SIZE
}
*/
}
/**
@ -220,7 +219,7 @@ int kvz_quantize_residual_generic(encoder_state_t *const state,
}
// Quantize coeffs. (coeff -> coeff_out)
/*
if (state->encoder_control->cfg.rdoq_enable &&
(width > 4 || !state->encoder_control->cfg.rdoq_skip))
{
@ -228,7 +227,7 @@ int kvz_quantize_residual_generic(encoder_state_t *const state,
tr_depth += (cur_cu->part_size == SIZE_NxN ? 1 : 0);
kvz_rdoq(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
scan_order, cur_cu->type, tr_depth);
} else*/ {
} else {
kvz_quant(state, coeff, coeff_out, width, width, (color == COLOR_Y ? 0 : 2),
scan_order, cur_cu->type);

View file

@ -9,3 +9,6 @@ set -eu
common_args='256x128 10 -p1 --preset=ultrafast --threads=0 --no-wpp --no-tmvp --no-deblock --sao=0 --alf=full --cpuid=0'
valgrind_test $common_args --rd=1
valgrind_test $common_args --rd=2 --no-transform-skip --qp 37
valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --rdoq
valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --signhide
valgrind_test $common_args --rd=2 --no-transform-skip --qp 37 --signhide --rdoq