Coverage Report

Created: 2025-07-23 08:18

/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
    int m_sLayerId;
56
57
protected:
58
    uint32_t *m_row_to_idx;
59
    uint32_t *m_idx_to_row;
60
61
public:
62
63
    WaveFront()
64
        : m_internalDependencyBitmap(NULL)
65
        , m_externalDependencyBitmap(NULL)
66
0
    {}
67
68
    virtual ~WaveFront();
69
70
    // If returns false, the frame must be encoded in series.
71
    bool init(int numRows);
72
73
    // Enqueue a row to be processed (mark its internal dependencies as resolved).
74
    // A worker thread will later call processRow(row).
75
    // This provider must be enqueued in the pool before enqueuing a row
76
    void enqueueRow(int row);
77
78
    // Mark a row as no longer having internal dependencies resolved. Returns
79
    // true if bit clear was successful, false otherwise.
80
    bool dequeueRow(int row);
81
82
    // Mark the row's external dependencies as being resolved
83
    void enableRow(int row);
84
85
    // Mark all row external dependencies as being resolved. Some wavefront
86
    // implementations (lookahead, for instance) have no recon pixel dependencies.
87
    void enableAllRows();
88
89
    // Mark all rows as having external dependencies which must be
90
    // resolved before each row may proceed.
91
    void clearEnabledRowMask();
92
93
    // WaveFront's implementation of JobProvider::findJob. Consults
94
    // m_queuedBitmap and calls ProcessRow(row) for lowest numbered queued row
95
    // processes available rows and returns when no work remains
96
    void findJob(int threadId);
97
98
    // Start or resume encode processing of this row, must be implemented by
99
    // derived classes.
100
    virtual void processRow(int row, int threadId, int layer) = 0;
101
102
    void setLayerId(int layer);
103
};
104
} // end namespace X265_NS
105
106
#endif // ifndef X265_WAVEFRONT_H