From 22fbdf34f4b4fd6a7f7758792b63bb0db7f7c49e Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Thu, 20 Dec 2007 19:24:17 +0000 Subject: [PATCH] fix a nondeterminism involving 8x8dct, rdo, and threads. git-svn-id: svn://svn.videolan.org/x264/trunk@713 df754926-b1dd-0310-bc7b-ec298dee348c --- common/common.h | 1 - common/macroblock.c | 42 ++++++++++++++++++++++++++++++------------ common/macroblock.h | 2 +- encoder/analyse.c | 11 ++--------- encoder/cabac.c | 2 +- encoder/cavlc.c | 2 +- 6 files changed, 35 insertions(+), 25 deletions(-) diff --git a/common/common.h b/common/common.h index 10164e06..88606519 100644 --- a/common/common.h +++ b/common/common.h @@ -471,7 +471,6 @@ struct x264_t /* number of neighbors (top and left) that used 8x8 dct */ int i_neighbour_transform_size; - int b_transform_8x8_allowed; int i_neighbour_interlaced; } cache; diff --git a/common/macroblock.c b/common/macroblock.c index a8056de5..e0307e13 100644 --- a/common/macroblock.c +++ b/common/macroblock.c @@ -52,22 +52,40 @@ int x264_mb_predict_non_zero_code( x264_t *h, int idx ) int x264_mb_transform_8x8_allowed( x264_t *h ) { - if( IS_SKIP( h->mb.i_type ) ) + // intra and skip are disallowed + // large partitions are allowed + // direct and 8x8 are conditional + static const uint8_t partition_tab[X264_MBTYPE_MAX] = { + 0,0,0,0,1,2,0,2,1,1,1,1,1,1,1,1,1,2,0, + }; + int p, i; + + if( !h->pps->b_transform_8x8_mode ) return 0; - if( h->mb.i_type == P_8x8 || h->mb.i_type == B_8x8 ) + p = partition_tab[h->mb.i_type]; + if( p < 2 ) + return p; + else if( h->mb.i_type == B_DIRECT ) + return h->sps->b_direct8x8_inference; + else if( h->mb.i_type == P_8x8 ) + { + if( !(h->param.analyse.inter & X264_ANALYSE_PSUB8x8) ) + return 1; + for( i=0; i<4; i++ ) + if( h->mb.i_sub_partition[i] != D_L0_8x8 ) + return 0; + return 1; + } + else // B_8x8 { - int i; - for( i = 0; i < 4; i++ ) - if( !IS_SUB8x8(h->mb.i_sub_partition[i]) - || ( h->mb.i_sub_partition[i] == D_DIRECT_8x8 && !h->sps->b_direct8x8_inference ) ) - { + // x264 currently doesn't use sub-8x8 B partitions, so don't check for them + if( h->sps->b_direct8x8_inference ) + return 1; + for( i=0; i<4; i++ ) + if( h->mb.i_sub_partition[i] == D_DIRECT_8x8 ) return 0; - } + return 1; } - if( h->mb.i_type == B_DIRECT && !h->sps->b_direct8x8_inference ) - return 0; - - return 1; } void x264_mb_predict_mv( x264_t *h, int i_list, int idx, int i_width, int mvp[2] ) diff --git a/common/macroblock.h b/common/macroblock.h index 1b4a4869..570bb80d 100644 --- a/common/macroblock.h +++ b/common/macroblock.h @@ -287,7 +287,7 @@ int x264_mb_predict_non_zero_code( x264_t *h, int idx ); /* x264_mb_transform_8x8_allowed: * check whether any partition is smaller than 8x8 (or at least * might be, according to just partition type.) - * doesn't check for intra or cbp */ + * doesn't check for cbp */ int x264_mb_transform_8x8_allowed( x264_t *h ); void x264_mb_mc( x264_t *h ); diff --git a/encoder/analyse.c b/encoder/analyse.c index 3d7ba90f..4532bf22 100644 --- a/encoder/analyse.c +++ b/encoder/analyse.c @@ -1984,11 +1984,7 @@ static void refine_bidir( x264_t *h, x264_mb_analysis_t *a ) static inline void x264_mb_analyse_transform( x264_t *h ) { - h->mb.cache.b_transform_8x8_allowed = - h->pps->b_transform_8x8_mode - && !IS_INTRA( h->mb.i_type ) && x264_mb_transform_8x8_allowed( h ); - - if( h->mb.cache.b_transform_8x8_allowed && h->param.analyse.b_transform_8x8 ) + if( x264_mb_transform_8x8_allowed( h ) && h->param.analyse.b_transform_8x8 ) { int i_cost4, i_cost8; /* FIXME only luma mc is needed */ @@ -2005,10 +2001,7 @@ static inline void x264_mb_analyse_transform( x264_t *h ) static inline void x264_mb_analyse_transform_rd( x264_t *h, x264_mb_analysis_t *a, int *i_satd, int *i_rd ) { - h->mb.cache.b_transform_8x8_allowed = - h->pps->b_transform_8x8_mode && x264_mb_transform_8x8_allowed( h ); - - if( h->mb.cache.b_transform_8x8_allowed && h->param.analyse.b_transform_8x8 ) + if( x264_mb_transform_8x8_allowed( h ) && h->param.analyse.b_transform_8x8 ) { int i_rd8; x264_analyse_update_cache( h, a ); diff --git a/encoder/cabac.c b/encoder/cabac.c index f5ece2bc..6b3a0180 100644 --- a/encoder/cabac.c +++ b/encoder/cabac.c @@ -1009,7 +1009,7 @@ void x264_macroblock_write_cabac( x264_t *h, x264_cabac_t *cb ) x264_cabac_mb_cbp_chroma( h, cb ); } - if( h->mb.cache.b_transform_8x8_allowed && h->mb.i_cbp_luma && !IS_INTRA(i_mb_type) ) + if( x264_mb_transform_8x8_allowed( h ) && h->mb.i_cbp_luma ) { x264_cabac_mb_transform_size( h, cb ); } diff --git a/encoder/cavlc.c b/encoder/cavlc.c index 6ac15b19..a20c0b0f 100644 --- a/encoder/cavlc.c +++ b/encoder/cavlc.c @@ -650,7 +650,7 @@ void x264_macroblock_write_cavlc( x264_t *h, bs_t *s ) } /* transform size 8x8 flag */ - if( h->mb.cache.b_transform_8x8_allowed && h->mb.i_cbp_luma && !IS_INTRA(i_mb_type) ) + if( x264_mb_transform_8x8_allowed( h ) && h->mb.i_cbp_luma ) { bs_write1( s, h->mb.b_transform_8x8 ); } -- 2.47.3