/src/x265/source/common/wavefront.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * Copyright (C) 2013-2020 MulticoreWare, Inc |
3 | | * |
4 | | * Authors: Steve Borho <steve@borho.org> |
5 | | * Min Chen <chenm003@163.com> |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify |
8 | | * it under the terms of the GNU General Public License as published by |
9 | | * the Free Software Foundation; either version 2 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * This program is distributed in the hope that it will be useful, |
13 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | | * GNU General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU General Public License |
18 | | * along with this program; if not, write to the Free Software |
19 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA. |
20 | | * |
21 | | * This program is also available under a commercial proprietary license. |
22 | | * For more information, contact us at license @ x265.com |
23 | | *****************************************************************************/ |
24 | | |
25 | | #ifndef X265_WAVEFRONT_H |
26 | | #define X265_WAVEFRONT_H |
27 | | |
28 | | #include "common.h" |
29 | | #include "threadpool.h" |
30 | | |
31 | | namespace X265_NS { |
32 | | // x265 private namespace |
33 | | |
34 | | // Generic wave-front scheduler, manages busy-state of CU rows as a priority |
35 | | // queue (higher CU rows have priority over lower rows) |
36 | | // |
37 | | // Derived classes must implement ProcessRow(). |
38 | | class WaveFront : public JobProvider |
39 | | { |
40 | | private: |
41 | | |
42 | | // bitmaps of rows queued for processing, uses atomic intrinsics |
43 | | |
44 | | // Dependencies are categorized as internal and external. Internal dependencies |
45 | | // are caused by neighbor block availability. External dependencies are generally |
46 | | // reference frame reconstructed pixels being available. |
47 | | uint32_t volatile *m_internalDependencyBitmap; |
48 | | uint32_t volatile *m_externalDependencyBitmap; |
49 | | |
50 | | // number of words in the bitmap |
51 | | int m_numWords; |
52 | | |
53 | | int m_numRows; |
54 | | |
55 | | protected: |
56 | | uint32_t *m_row_to_idx; |
57 | | uint32_t *m_idx_to_row; |
58 | | |
59 | | public: |
60 | | |
61 | | WaveFront() |
62 | | : m_internalDependencyBitmap(NULL) |
63 | | , m_externalDependencyBitmap(NULL) |
64 | 0 | {} |
65 | | |
66 | | virtual ~WaveFront(); |
67 | | |
68 | | // If returns false, the frame must be encoded in series. |
69 | | bool init(int numRows); |
70 | | |
71 | | // Enqueue a row to be processed (mark its internal dependencies as resolved). |
72 | | // A worker thread will later call processRow(row). |
73 | | // This provider must be enqueued in the pool before enqueuing a row |
74 | | void enqueueRow(int row); |
75 | | |
76 | | // Mark a row as no longer having internal dependencies resolved. Returns |
77 | | // true if bit clear was successful, false otherwise. |
78 | | bool dequeueRow(int row); |
79 | | |
80 | | // Mark the row's external dependencies as being resolved |
81 | | void enableRow(int row); |
82 | | |
83 | | // Mark all row external dependencies as being resolved. Some wavefront |
84 | | // implementations (lookahead, for instance) have no recon pixel dependencies. |
85 | | void enableAllRows(); |
86 | | |
87 | | // Mark all rows as having external dependencies which must be |
88 | | // resolved before each row may proceed. |
89 | | void clearEnabledRowMask(); |
90 | | |
91 | | // WaveFront's implementation of JobProvider::findJob. Consults |
92 | | // m_queuedBitmap and calls ProcessRow(row) for lowest numbered queued row |
93 | | // processes available rows and returns when no work remains |
94 | | void findJob(int threadId); |
95 | | |
96 | | // Start or resume encode processing of this row, must be implemented by |
97 | | // derived classes. |
98 | | virtual void processRow(int row, int threadId) = 0; |
99 | | }; |
100 | | } // end namespace X265_NS |
101 | | |
102 | | #endif // ifndef X265_WAVEFRONT_H |