-
-
Notifications
You must be signed in to change notification settings - Fork 36.4k
Expand file tree
/
Copy pathTimestampQueryPool.js
More file actions
163 lines (132 loc) · 3.06 KB
/
TimestampQueryPool.js
File metadata and controls
163 lines (132 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { warn } from '../../utils.js';
/**
* Abstract base class of a timestamp query pool.
*
* @abstract
*/
class TimestampQueryPool {
/**
* Creates a new timestamp query pool.
*
* @param {number} [maxQueries=256] - Maximum number of queries this pool can hold.
*/
constructor( maxQueries = 256 ) {
/**
* Whether to track timestamps or not.
*
* @type {boolean}
* @default true
*/
this.trackTimestamp = true;
/**
* Maximum number of queries this pool can hold.
*
* @type {number}
* @default 256
*/
this.maxQueries = maxQueries;
/**
* How many queries allocated so far.
*
* @type {number}
* @default 0
*/
this.currentQueryIndex = 0;
/**
* Tracks offsets for different contexts.
*
* @type {Map<string, number>}
*/
this.queryOffsets = new Map();
/**
* Whether the pool has been disposed or not.
*
* @type {boolean}
* @default false
*/
this.isDisposed = false;
/**
* The total frame duration until the next update.
*
* @type {number}
* @default 0
*/
this.lastValue = 0;
/**
* Stores all timestamp frames.
*
* @type {Array<number>}
*/
this.frames = [];
/**
* This property is used to avoid multiple concurrent resolve operations.
* The WebGL backend uses it as a boolean flag. In context of WebGPU, it holds
* the promise of the current resolve operation.
*
* @type {boolean|Promise<number>}
* @default false
*/
this.pendingResolve = false;
/**
* Stores the latest timestamp for each render context.
*
* @type {Map<string, number>}
*/
this.timestamps = new Map();
}
/**
* Returns all timestamp frames.
*
* @return {Array<number>} The timestamp frames.
*/
getTimestampFrames() {
return this.frames;
}
/**
* Returns the timestamp for a given render context.
*
* @param {string} uid - A unique identifier for the render context.
* @return {?number} The timestamp, or undefined if not available.
*/
getTimestamp( uid ) {
let timestamp = this.timestamps.get( uid );
if ( timestamp === undefined ) {
warn( `TimestampQueryPool: No timestamp available for uid ${ uid }.` );
timestamp = 0;
}
return timestamp;
}
/**
* Returns whether a timestamp is available for a given render context.
*
* @param {string} uid - A unique identifier for the render context.
* @return {boolean} True if a timestamp is available, false otherwise.
*/
hasTimestamp( uid ) {
return this.timestamps.has( uid );
}
/**
* Allocate queries for a specific uid.
*
* @abstract
* @param {string} uid - A unique identifier for the render context.
* @param {number} frameId - The current frame identifier.
* @returns {?number}
*/
allocateQueriesForContext( /* uid, frameId */ ) {}
/**
* Resolve all timestamps and return data (or process them).
*
* @abstract
* @async
* @returns {Promise<number>|number} The resolved timestamp value.
*/
async resolveQueriesAsync() {}
/**
* Dispose of the query pool.
*
* @abstract
*/
dispose() {}
}
export default TimestampQueryPool;