1 /*
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <assert.h>
12 #include <limits.h>
13 #include "./vpx_config.h"
14 #include "vpx_dsp/vpx_dsp_common.h"
15 #include "vpx_mem/vpx_mem.h"
16 #include "vp9/common/vp9_entropymode.h"
17 #include "vp9/common/vp9_thread_common.h"
18 #include "vp9/common/vp9_reconinter.h"
19 #include "vp9/common/vp9_loopfilter.h"
20
21 #if CONFIG_MULTITHREAD
mutex_lock(pthread_mutex_t * const mutex)22 static INLINE void mutex_lock(pthread_mutex_t *const mutex) {
23 const int kMaxTryLocks = 4000;
24 int locked = 0;
25 int i;
26
27 for (i = 0; i < kMaxTryLocks; ++i) {
28 if (!pthread_mutex_trylock(mutex)) {
29 locked = 1;
30 break;
31 }
32 }
33
34 if (!locked) pthread_mutex_lock(mutex);
35 }
36 #endif // CONFIG_MULTITHREAD
37
sync_read(VP9LfSync * const lf_sync,int r,int c)38 static INLINE void sync_read(VP9LfSync *const lf_sync, int r, int c) {
39 #if CONFIG_MULTITHREAD
40 const int nsync = lf_sync->sync_range;
41
42 if (r && !(c & (nsync - 1))) {
43 pthread_mutex_t *const mutex = &lf_sync->mutex[r - 1];
44 mutex_lock(mutex);
45
46 while (c > lf_sync->cur_sb_col[r - 1] - nsync) {
47 pthread_cond_wait(&lf_sync->cond[r - 1], mutex);
48 }
49 pthread_mutex_unlock(mutex);
50 }
51 #else
52 (void)lf_sync;
53 (void)r;
54 (void)c;
55 #endif // CONFIG_MULTITHREAD
56 }
57
sync_write(VP9LfSync * const lf_sync,int r,int c,const int sb_cols)58 static INLINE void sync_write(VP9LfSync *const lf_sync, int r, int c,
59 const int sb_cols) {
60 #if CONFIG_MULTITHREAD
61 const int nsync = lf_sync->sync_range;
62 int cur;
63 // Only signal when there are enough filtered SB for next row to run.
64 int sig = 1;
65
66 if (c < sb_cols - 1) {
67 cur = c;
68 if (c % nsync) sig = 0;
69 } else {
70 cur = sb_cols + nsync;
71 }
72
73 if (sig) {
74 mutex_lock(&lf_sync->mutex[r]);
75
76 lf_sync->cur_sb_col[r] = cur;
77
78 pthread_cond_signal(&lf_sync->cond[r]);
79 pthread_mutex_unlock(&lf_sync->mutex[r]);
80 }
81 #else
82 (void)lf_sync;
83 (void)r;
84 (void)c;
85 (void)sb_cols;
86 #endif // CONFIG_MULTITHREAD
87 }
88
89 // Implement row loopfiltering for each thread.
thread_loop_filter_rows(const YV12_BUFFER_CONFIG * const frame_buffer,VP9_COMMON * const cm,struct macroblockd_plane planes[MAX_MB_PLANE],int start,int stop,int y_only,VP9LfSync * const lf_sync)90 static INLINE void thread_loop_filter_rows(
91 const YV12_BUFFER_CONFIG *const frame_buffer, VP9_COMMON *const cm,
92 struct macroblockd_plane planes[MAX_MB_PLANE], int start, int stop,
93 int y_only, VP9LfSync *const lf_sync) {
94 const int num_planes = y_only ? 1 : MAX_MB_PLANE;
95 const int sb_cols = mi_cols_aligned_to_sb(cm->mi_cols) >> MI_BLOCK_SIZE_LOG2;
96 const int num_active_workers = lf_sync->num_active_workers;
97 int mi_row, mi_col;
98 enum lf_path path;
99 if (y_only)
100 path = LF_PATH_444;
101 else if (planes[1].subsampling_y == 1 && planes[1].subsampling_x == 1)
102 path = LF_PATH_420;
103 else if (planes[1].subsampling_y == 0 && planes[1].subsampling_x == 0)
104 path = LF_PATH_444;
105 else
106 path = LF_PATH_SLOW;
107
108 assert(num_active_workers > 0);
109
110 for (mi_row = start; mi_row < stop;
111 mi_row += num_active_workers * MI_BLOCK_SIZE) {
112 MODE_INFO **const mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
113 LOOP_FILTER_MASK *lfm = get_lfm(&cm->lf, mi_row, 0);
114
115 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE, ++lfm) {
116 const int r = mi_row >> MI_BLOCK_SIZE_LOG2;
117 const int c = mi_col >> MI_BLOCK_SIZE_LOG2;
118 int plane;
119
120 sync_read(lf_sync, r, c);
121
122 vp9_setup_dst_planes(planes, frame_buffer, mi_row, mi_col);
123
124 vp9_adjust_mask(cm, mi_row, mi_col, lfm);
125
126 vp9_filter_block_plane_ss00(cm, &planes[0], mi_row, lfm);
127 for (plane = 1; plane < num_planes; ++plane) {
128 switch (path) {
129 case LF_PATH_420:
130 vp9_filter_block_plane_ss11(cm, &planes[plane], mi_row, lfm);
131 break;
132 case LF_PATH_444:
133 vp9_filter_block_plane_ss00(cm, &planes[plane], mi_row, lfm);
134 break;
135 case LF_PATH_SLOW:
136 vp9_filter_block_plane_non420(cm, &planes[plane], mi + mi_col,
137 mi_row, mi_col);
138 break;
139 }
140 }
141
142 sync_write(lf_sync, r, c, sb_cols);
143 }
144 }
145 }
146
147 // Row-based multi-threaded loopfilter hook
loop_filter_row_worker(void * arg1,void * arg2)148 static int loop_filter_row_worker(void *arg1, void *arg2) {
149 VP9LfSync *const lf_sync = (VP9LfSync *)arg1;
150 LFWorkerData *const lf_data = (LFWorkerData *)arg2;
151 thread_loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
152 lf_data->start, lf_data->stop, lf_data->y_only,
153 lf_sync);
154 return 1;
155 }
156
loop_filter_rows_mt(YV12_BUFFER_CONFIG * frame,VP9_COMMON * cm,struct macroblockd_plane planes[MAX_MB_PLANE],int start,int stop,int y_only,VPxWorker * workers,int nworkers,VP9LfSync * lf_sync)157 static void loop_filter_rows_mt(YV12_BUFFER_CONFIG *frame, VP9_COMMON *cm,
158 struct macroblockd_plane planes[MAX_MB_PLANE],
159 int start, int stop, int y_only,
160 VPxWorker *workers, int nworkers,
161 VP9LfSync *lf_sync) {
162 const VPxWorkerInterface *const winterface = vpx_get_worker_interface();
163 // Number of superblock rows and cols
164 const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2;
165 const int num_tile_cols = 1 << cm->log2_tile_cols;
166 // Limit the number of workers to prevent changes in frame dimensions from
167 // causing incorrect sync calculations when sb_rows < threads/tile_cols.
168 // Further restrict them by the number of tile columns should the user
169 // request more as this implementation doesn't scale well beyond that.
170 const int num_workers = VPXMIN(nworkers, VPXMIN(num_tile_cols, sb_rows));
171 int i;
172
173 if (!lf_sync->sync_range || sb_rows != lf_sync->rows ||
174 num_workers > lf_sync->num_workers) {
175 vp9_loop_filter_dealloc(lf_sync);
176 vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width, num_workers);
177 }
178 lf_sync->num_active_workers = num_workers;
179
180 // Initialize cur_sb_col to -1 for all SB rows.
181 memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows);
182
183 // Set up loopfilter thread data.
184 // The decoder is capping num_workers because it has been observed that using
185 // more threads on the loopfilter than there are cores will hurt performance
186 // on Android. This is because the system will only schedule the tile decode
187 // workers on cores equal to the number of tile columns. Then if the decoder
188 // tries to use more threads for the loopfilter, it will hurt performance
189 // because of contention. If the multithreading code changes in the future
190 // then the number of workers used by the loopfilter should be revisited.
191 for (i = 0; i < num_workers; ++i) {
192 VPxWorker *const worker = &workers[i];
193 LFWorkerData *const lf_data = &lf_sync->lfdata[i];
194
195 worker->hook = loop_filter_row_worker;
196 worker->data1 = lf_sync;
197 worker->data2 = lf_data;
198
199 // Loopfilter data
200 vp9_loop_filter_data_reset(lf_data, frame, cm, planes);
201 lf_data->start = start + i * MI_BLOCK_SIZE;
202 lf_data->stop = stop;
203 lf_data->y_only = y_only;
204
205 // Start loopfiltering
206 if (i == num_workers - 1) {
207 winterface->execute(worker);
208 } else {
209 winterface->launch(worker);
210 }
211 }
212
213 // Wait till all rows are finished
214 for (i = 0; i < num_workers; ++i) {
215 winterface->sync(&workers[i]);
216 }
217 }
218
vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG * frame,VP9_COMMON * cm,struct macroblockd_plane planes[MAX_MB_PLANE],int frame_filter_level,int y_only,int partial_frame,VPxWorker * workers,int num_workers,VP9LfSync * lf_sync)219 void vp9_loop_filter_frame_mt(YV12_BUFFER_CONFIG *frame, VP9_COMMON *cm,
220 struct macroblockd_plane planes[MAX_MB_PLANE],
221 int frame_filter_level, int y_only,
222 int partial_frame, VPxWorker *workers,
223 int num_workers, VP9LfSync *lf_sync) {
224 int start_mi_row, end_mi_row, mi_rows_to_filter;
225
226 if (!frame_filter_level) return;
227
228 start_mi_row = 0;
229 mi_rows_to_filter = cm->mi_rows;
230 if (partial_frame && cm->mi_rows > 8) {
231 start_mi_row = cm->mi_rows >> 1;
232 start_mi_row &= 0xfffffff8;
233 mi_rows_to_filter = VPXMAX(cm->mi_rows / 8, 8);
234 }
235 end_mi_row = start_mi_row + mi_rows_to_filter;
236 vp9_loop_filter_frame_init(cm, frame_filter_level);
237
238 loop_filter_rows_mt(frame, cm, planes, start_mi_row, end_mi_row, y_only,
239 workers, num_workers, lf_sync);
240 }
241
vp9_lpf_mt_init(VP9LfSync * lf_sync,VP9_COMMON * cm,int frame_filter_level,int num_workers)242 void vp9_lpf_mt_init(VP9LfSync *lf_sync, VP9_COMMON *cm, int frame_filter_level,
243 int num_workers) {
244 const int sb_rows = mi_cols_aligned_to_sb(cm->mi_rows) >> MI_BLOCK_SIZE_LOG2;
245
246 if (!frame_filter_level) return;
247
248 if (!lf_sync->sync_range || sb_rows != lf_sync->rows ||
249 num_workers > lf_sync->num_workers) {
250 vp9_loop_filter_dealloc(lf_sync);
251 vp9_loop_filter_alloc(lf_sync, cm, sb_rows, cm->width, num_workers);
252 }
253
254 // Initialize cur_sb_col to -1 for all SB rows.
255 memset(lf_sync->cur_sb_col, -1, sizeof(*lf_sync->cur_sb_col) * sb_rows);
256
257 lf_sync->corrupted = 0;
258
259 memset(lf_sync->num_tiles_done, 0,
260 sizeof(*lf_sync->num_tiles_done) * sb_rows);
261 cm->lf_row = 0;
262 }
263
264 // Set up nsync by width.
get_sync_range(int width)265 static INLINE int get_sync_range(int width) {
266 // nsync numbers are picked by testing. For example, for 4k
267 // video, using 4 gives best performance.
268 if (width < 640)
269 return 1;
270 else if (width <= 1280)
271 return 2;
272 else if (width <= 4096)
273 return 4;
274 else
275 return 8;
276 }
277
278 // Allocate memory for lf row synchronization
vp9_loop_filter_alloc(VP9LfSync * lf_sync,VP9_COMMON * cm,int rows,int width,int num_workers)279 void vp9_loop_filter_alloc(VP9LfSync *lf_sync, VP9_COMMON *cm, int rows,
280 int width, int num_workers) {
281 lf_sync->rows = rows;
282 #if CONFIG_MULTITHREAD
283 {
284 int i;
285
286 CHECK_MEM_ERROR(&cm->error, lf_sync->mutex,
287 vpx_malloc(sizeof(*lf_sync->mutex) * rows));
288 if (lf_sync->mutex) {
289 for (i = 0; i < rows; ++i) {
290 pthread_mutex_init(&lf_sync->mutex[i], NULL);
291 }
292 }
293
294 CHECK_MEM_ERROR(&cm->error, lf_sync->cond,
295 vpx_malloc(sizeof(*lf_sync->cond) * rows));
296 if (lf_sync->cond) {
297 for (i = 0; i < rows; ++i) {
298 pthread_cond_init(&lf_sync->cond[i], NULL);
299 }
300 }
301
302 CHECK_MEM_ERROR(&cm->error, lf_sync->lf_mutex,
303 vpx_malloc(sizeof(*lf_sync->lf_mutex)));
304 pthread_mutex_init(lf_sync->lf_mutex, NULL);
305
306 CHECK_MEM_ERROR(&cm->error, lf_sync->recon_done_mutex,
307 vpx_malloc(sizeof(*lf_sync->recon_done_mutex) * rows));
308 if (lf_sync->recon_done_mutex) {
309 for (i = 0; i < rows; ++i) {
310 pthread_mutex_init(&lf_sync->recon_done_mutex[i], NULL);
311 }
312 }
313
314 CHECK_MEM_ERROR(&cm->error, lf_sync->recon_done_cond,
315 vpx_malloc(sizeof(*lf_sync->recon_done_cond) * rows));
316 if (lf_sync->recon_done_cond) {
317 for (i = 0; i < rows; ++i) {
318 pthread_cond_init(&lf_sync->recon_done_cond[i], NULL);
319 }
320 }
321 }
322 #endif // CONFIG_MULTITHREAD
323
324 CHECK_MEM_ERROR(&cm->error, lf_sync->lfdata,
325 vpx_malloc(num_workers * sizeof(*lf_sync->lfdata)));
326 lf_sync->num_workers = num_workers;
327 lf_sync->num_active_workers = lf_sync->num_workers;
328
329 CHECK_MEM_ERROR(&cm->error, lf_sync->cur_sb_col,
330 vpx_malloc(sizeof(*lf_sync->cur_sb_col) * rows));
331
332 CHECK_MEM_ERROR(&cm->error, lf_sync->num_tiles_done,
333 vpx_malloc(sizeof(*lf_sync->num_tiles_done) *
334 mi_cols_aligned_to_sb(cm->mi_rows) >>
335 MI_BLOCK_SIZE_LOG2));
336
337 // Set up nsync.
338 lf_sync->sync_range = get_sync_range(width);
339 }
340
341 // Deallocate lf synchronization related mutex and data
vp9_loop_filter_dealloc(VP9LfSync * lf_sync)342 void vp9_loop_filter_dealloc(VP9LfSync *lf_sync) {
343 assert(lf_sync != NULL);
344
345 #if CONFIG_MULTITHREAD
346 if (lf_sync->mutex != NULL) {
347 int i;
348 for (i = 0; i < lf_sync->rows; ++i) {
349 pthread_mutex_destroy(&lf_sync->mutex[i]);
350 }
351 vpx_free(lf_sync->mutex);
352 }
353 if (lf_sync->cond != NULL) {
354 int i;
355 for (i = 0; i < lf_sync->rows; ++i) {
356 pthread_cond_destroy(&lf_sync->cond[i]);
357 }
358 vpx_free(lf_sync->cond);
359 }
360 if (lf_sync->recon_done_mutex != NULL) {
361 int i;
362 for (i = 0; i < lf_sync->rows; ++i) {
363 pthread_mutex_destroy(&lf_sync->recon_done_mutex[i]);
364 }
365 vpx_free(lf_sync->recon_done_mutex);
366 }
367
368 if (lf_sync->lf_mutex != NULL) {
369 pthread_mutex_destroy(lf_sync->lf_mutex);
370 vpx_free(lf_sync->lf_mutex);
371 }
372 if (lf_sync->recon_done_cond != NULL) {
373 int i;
374 for (i = 0; i < lf_sync->rows; ++i) {
375 pthread_cond_destroy(&lf_sync->recon_done_cond[i]);
376 }
377 vpx_free(lf_sync->recon_done_cond);
378 }
379 #endif // CONFIG_MULTITHREAD
380
381 vpx_free(lf_sync->lfdata);
382 vpx_free(lf_sync->cur_sb_col);
383 vpx_free(lf_sync->num_tiles_done);
384 // clear the structure as the source of this call may be a resize in which
385 // case this call will be followed by an _alloc() which may fail.
386 vp9_zero(*lf_sync);
387 }
388
get_next_row(VP9_COMMON * cm,VP9LfSync * lf_sync)389 static int get_next_row(VP9_COMMON *cm, VP9LfSync *lf_sync) {
390 int return_val = -1;
391 const int max_rows = cm->mi_rows;
392
393 #if CONFIG_MULTITHREAD
394 int cur_row;
395 const int tile_cols = 1 << cm->log2_tile_cols;
396
397 pthread_mutex_lock(lf_sync->lf_mutex);
398 if (cm->lf_row < max_rows) {
399 cur_row = cm->lf_row >> MI_BLOCK_SIZE_LOG2;
400 return_val = cm->lf_row;
401 cm->lf_row += MI_BLOCK_SIZE;
402 if (cm->lf_row < max_rows) {
403 /* If this is not the last row, make sure the next row is also decoded.
404 * This is because the intra predict has to happen before loop filter */
405 cur_row += 1;
406 }
407 }
408 pthread_mutex_unlock(lf_sync->lf_mutex);
409
410 if (return_val == -1) return return_val;
411
412 pthread_mutex_lock(&lf_sync->recon_done_mutex[cur_row]);
413 if (lf_sync->num_tiles_done[cur_row] < tile_cols) {
414 pthread_cond_wait(&lf_sync->recon_done_cond[cur_row],
415 &lf_sync->recon_done_mutex[cur_row]);
416 }
417 pthread_mutex_unlock(&lf_sync->recon_done_mutex[cur_row]);
418 pthread_mutex_lock(lf_sync->lf_mutex);
419 if (lf_sync->corrupted) {
420 int row = return_val >> MI_BLOCK_SIZE_LOG2;
421 pthread_mutex_lock(&lf_sync->mutex[row]);
422 lf_sync->cur_sb_col[row] = INT_MAX;
423 pthread_cond_signal(&lf_sync->cond[row]);
424 pthread_mutex_unlock(&lf_sync->mutex[row]);
425 return_val = -1;
426 }
427 pthread_mutex_unlock(lf_sync->lf_mutex);
428 #else
429 (void)lf_sync;
430 if (cm->lf_row < max_rows) {
431 return_val = cm->lf_row;
432 cm->lf_row += MI_BLOCK_SIZE;
433 }
434 #endif // CONFIG_MULTITHREAD
435
436 return return_val;
437 }
438
vp9_loopfilter_rows(LFWorkerData * lf_data,VP9LfSync * lf_sync)439 void vp9_loopfilter_rows(LFWorkerData *lf_data, VP9LfSync *lf_sync) {
440 int mi_row;
441 VP9_COMMON *cm = lf_data->cm;
442
443 while ((mi_row = get_next_row(cm, lf_sync)) != -1 && mi_row < cm->mi_rows) {
444 lf_data->start = mi_row;
445 lf_data->stop = mi_row + MI_BLOCK_SIZE;
446
447 thread_loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
448 lf_data->start, lf_data->stop, lf_data->y_only,
449 lf_sync);
450 }
451 }
452
vp9_set_row(VP9LfSync * lf_sync,int num_tiles,int row,int is_last_row,int corrupted)453 void vp9_set_row(VP9LfSync *lf_sync, int num_tiles, int row, int is_last_row,
454 int corrupted) {
455 #if CONFIG_MULTITHREAD
456 pthread_mutex_lock(lf_sync->lf_mutex);
457 lf_sync->corrupted |= corrupted;
458 pthread_mutex_unlock(lf_sync->lf_mutex);
459 pthread_mutex_lock(&lf_sync->recon_done_mutex[row]);
460 lf_sync->num_tiles_done[row] += 1;
461 if (num_tiles == lf_sync->num_tiles_done[row]) {
462 if (is_last_row) {
463 /* The last 2 rows wait on the last row to be done.
464 * So, we have to broadcast the signal in this case.
465 */
466 pthread_cond_broadcast(&lf_sync->recon_done_cond[row]);
467 } else {
468 pthread_cond_signal(&lf_sync->recon_done_cond[row]);
469 }
470 }
471 pthread_mutex_unlock(&lf_sync->recon_done_mutex[row]);
472 #else
473 (void)lf_sync;
474 (void)num_tiles;
475 (void)row;
476 (void)is_last_row;
477 (void)corrupted;
478 #endif // CONFIG_MULTITHREAD
479 }
480
vp9_loopfilter_job(LFWorkerData * lf_data,VP9LfSync * lf_sync)481 void vp9_loopfilter_job(LFWorkerData *lf_data, VP9LfSync *lf_sync) {
482 thread_loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
483 lf_data->start, lf_data->stop, lf_data->y_only,
484 lf_sync);
485 }
486
487 // Accumulate frame counts.
vp9_accumulate_frame_counts(FRAME_COUNTS * accum,const FRAME_COUNTS * counts,int is_dec)488 void vp9_accumulate_frame_counts(FRAME_COUNTS *accum,
489 const FRAME_COUNTS *counts, int is_dec) {
490 int i, j, k, l, m;
491
492 for (i = 0; i < BLOCK_SIZE_GROUPS; i++)
493 for (j = 0; j < INTRA_MODES; j++)
494 accum->y_mode[i][j] += counts->y_mode[i][j];
495
496 for (i = 0; i < INTRA_MODES; i++)
497 for (j = 0; j < INTRA_MODES; j++)
498 accum->uv_mode[i][j] += counts->uv_mode[i][j];
499
500 for (i = 0; i < PARTITION_CONTEXTS; i++)
501 for (j = 0; j < PARTITION_TYPES; j++)
502 accum->partition[i][j] += counts->partition[i][j];
503
504 if (is_dec) {
505 int n;
506 for (i = 0; i < TX_SIZES; i++)
507 for (j = 0; j < PLANE_TYPES; j++)
508 for (k = 0; k < REF_TYPES; k++)
509 for (l = 0; l < COEF_BANDS; l++)
510 for (m = 0; m < COEFF_CONTEXTS; m++) {
511 accum->eob_branch[i][j][k][l][m] +=
512 counts->eob_branch[i][j][k][l][m];
513 for (n = 0; n < UNCONSTRAINED_NODES + 1; n++)
514 accum->coef[i][j][k][l][m][n] += counts->coef[i][j][k][l][m][n];
515 }
516 } else {
517 for (i = 0; i < TX_SIZES; i++)
518 for (j = 0; j < PLANE_TYPES; j++)
519 for (k = 0; k < REF_TYPES; k++)
520 for (l = 0; l < COEF_BANDS; l++)
521 for (m = 0; m < COEFF_CONTEXTS; m++)
522 accum->eob_branch[i][j][k][l][m] +=
523 counts->eob_branch[i][j][k][l][m];
524 // In the encoder, coef is only updated at frame
525 // level, so not need to accumulate it here.
526 // for (n = 0; n < UNCONSTRAINED_NODES + 1; n++)
527 // accum->coef[i][j][k][l][m][n] +=
528 // counts->coef[i][j][k][l][m][n];
529 }
530
531 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++)
532 for (j = 0; j < SWITCHABLE_FILTERS; j++)
533 accum->switchable_interp[i][j] += counts->switchable_interp[i][j];
534
535 for (i = 0; i < INTER_MODE_CONTEXTS; i++)
536 for (j = 0; j < INTER_MODES; j++)
537 accum->inter_mode[i][j] += counts->inter_mode[i][j];
538
539 for (i = 0; i < INTRA_INTER_CONTEXTS; i++)
540 for (j = 0; j < 2; j++)
541 accum->intra_inter[i][j] += counts->intra_inter[i][j];
542
543 for (i = 0; i < COMP_INTER_CONTEXTS; i++)
544 for (j = 0; j < 2; j++) accum->comp_inter[i][j] += counts->comp_inter[i][j];
545
546 for (i = 0; i < REF_CONTEXTS; i++)
547 for (j = 0; j < 2; j++)
548 for (k = 0; k < 2; k++)
549 accum->single_ref[i][j][k] += counts->single_ref[i][j][k];
550
551 for (i = 0; i < REF_CONTEXTS; i++)
552 for (j = 0; j < 2; j++) accum->comp_ref[i][j] += counts->comp_ref[i][j];
553
554 for (i = 0; i < TX_SIZE_CONTEXTS; i++) {
555 for (j = 0; j < TX_SIZES; j++)
556 accum->tx.p32x32[i][j] += counts->tx.p32x32[i][j];
557
558 for (j = 0; j < TX_SIZES - 1; j++)
559 accum->tx.p16x16[i][j] += counts->tx.p16x16[i][j];
560
561 for (j = 0; j < TX_SIZES - 2; j++)
562 accum->tx.p8x8[i][j] += counts->tx.p8x8[i][j];
563 }
564
565 for (i = 0; i < TX_SIZES; i++)
566 accum->tx.tx_totals[i] += counts->tx.tx_totals[i];
567
568 for (i = 0; i < SKIP_CONTEXTS; i++)
569 for (j = 0; j < 2; j++) accum->skip[i][j] += counts->skip[i][j];
570
571 for (i = 0; i < MV_JOINTS; i++) accum->mv.joints[i] += counts->mv.joints[i];
572
573 for (k = 0; k < 2; k++) {
574 nmv_component_counts *const comps = &accum->mv.comps[k];
575 const nmv_component_counts *const comps_t = &counts->mv.comps[k];
576
577 for (i = 0; i < 2; i++) {
578 comps->sign[i] += comps_t->sign[i];
579 comps->class0_hp[i] += comps_t->class0_hp[i];
580 comps->hp[i] += comps_t->hp[i];
581 }
582
583 for (i = 0; i < MV_CLASSES; i++) comps->classes[i] += comps_t->classes[i];
584
585 for (i = 0; i < CLASS0_SIZE; i++) {
586 comps->class0[i] += comps_t->class0[i];
587 for (j = 0; j < MV_FP_SIZE; j++)
588 comps->class0_fp[i][j] += comps_t->class0_fp[i][j];
589 }
590
591 for (i = 0; i < MV_OFFSET_BITS; i++)
592 for (j = 0; j < 2; j++) comps->bits[i][j] += comps_t->bits[i][j];
593
594 for (i = 0; i < MV_FP_SIZE; i++) comps->fp[i] += comps_t->fp[i];
595 }
596 }
597