|
13 | 13 |
|
14 | 14 | namespace impeller { |
15 | 15 |
|
16 | | -static std::optional<GLuint> CreateGLHandle(const ProcTableGLES& gl, |
17 | | - HandleType type) { |
18 | | - GLuint handle = GL_NONE; |
| 16 | +// static |
| 17 | +std::optional<ReactorGLES::GLStorage> ReactorGLES::CreateGLHandle( |
| 18 | + const ProcTableGLES& gl, |
| 19 | + HandleType type) { |
| 20 | + GLStorage handle = GLStorage{.handle = GL_NONE}; |
19 | 21 | switch (type) { |
20 | 22 | case HandleType::kUnknown: |
21 | 23 | return std::nullopt; |
22 | 24 | case HandleType::kTexture: |
23 | | - gl.GenTextures(1u, &handle); |
| 25 | + gl.GenTextures(1u, &handle.handle); |
24 | 26 | return handle; |
25 | 27 | case HandleType::kBuffer: |
26 | | - gl.GenBuffers(1u, &handle); |
| 28 | + gl.GenBuffers(1u, &handle.handle); |
27 | 29 | return handle; |
28 | 30 | case HandleType::kProgram: |
29 | | - return gl.CreateProgram(); |
| 31 | + return GLStorage{.handle = gl.CreateProgram()}; |
30 | 32 | case HandleType::kRenderBuffer: |
31 | | - gl.GenRenderbuffers(1u, &handle); |
| 33 | + gl.GenRenderbuffers(1u, &handle.handle); |
32 | 34 | return handle; |
33 | 35 | case HandleType::kFrameBuffer: |
34 | | - gl.GenFramebuffers(1u, &handle); |
| 36 | + gl.GenFramebuffers(1u, &handle.handle); |
35 | 37 | return handle; |
| 38 | + case HandleType::kFence: |
| 39 | + return GLStorage{.sync = gl.FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0)}; |
36 | 40 | } |
37 | 41 | return std::nullopt; |
38 | 42 | } |
39 | 43 |
|
40 | | -static bool CollectGLHandle(const ProcTableGLES& gl, |
41 | | - HandleType type, |
42 | | - GLuint handle) { |
| 44 | +// static |
| 45 | +bool ReactorGLES::CollectGLHandle(const ProcTableGLES& gl, |
| 46 | + HandleType type, |
| 47 | + ReactorGLES::GLStorage handle) { |
43 | 48 | switch (type) { |
44 | 49 | case HandleType::kUnknown: |
45 | 50 | return false; |
46 | 51 | case HandleType::kTexture: |
47 | | - gl.DeleteTextures(1u, &handle); |
| 52 | + gl.DeleteTextures(1u, &handle.handle); |
48 | 53 | return true; |
49 | 54 | case HandleType::kBuffer: |
50 | | - gl.DeleteBuffers(1u, &handle); |
| 55 | + gl.DeleteBuffers(1u, &handle.handle); |
51 | 56 | return true; |
52 | 57 | case HandleType::kProgram: |
53 | | - gl.DeleteProgram(handle); |
| 58 | + gl.DeleteProgram(handle.handle); |
54 | 59 | return true; |
55 | 60 | case HandleType::kRenderBuffer: |
56 | | - gl.DeleteRenderbuffers(1u, &handle); |
| 61 | + gl.DeleteRenderbuffers(1u, &handle.handle); |
57 | 62 | return true; |
58 | 63 | case HandleType::kFrameBuffer: |
59 | | - gl.DeleteFramebuffers(1u, &handle); |
| 64 | + gl.DeleteFramebuffers(1u, &handle.handle); |
60 | 65 | return true; |
| 66 | + case HandleType::kFence: |
| 67 | + gl.DeleteSync(handle.sync); |
| 68 | + break; |
61 | 69 | } |
62 | 70 | return false; |
63 | 71 | } |
@@ -116,24 +124,48 @@ const ProcTableGLES& ReactorGLES::GetProcTable() const { |
116 | 124 | return *proc_table_; |
117 | 125 | } |
118 | 126 |
|
119 | | -std::optional<GLuint> ReactorGLES::GetGLHandle(const HandleGLES& handle) const { |
| 127 | +std::optional<ReactorGLES::GLStorage> ReactorGLES::GetHandle( |
| 128 | + const HandleGLES& handle) const { |
120 | 129 | ReaderLock handles_lock(handles_mutex_); |
121 | 130 | if (auto found = handles_.find(handle); found != handles_.end()) { |
122 | 131 | if (found->second.pending_collection) { |
123 | 132 | VALIDATION_LOG |
124 | 133 | << "Attempted to acquire a handle that was pending collection."; |
125 | 134 | return std::nullopt; |
126 | 135 | } |
127 | | - if (!found->second.name.has_value()) { |
| 136 | + std::optional<ReactorGLES::GLStorage> name = found->second.name; |
| 137 | + if (!name.has_value()) { |
128 | 138 | VALIDATION_LOG << "Attempt to acquire a handle outside of an operation."; |
129 | 139 | return std::nullopt; |
130 | 140 | } |
131 | | - return found->second.name; |
| 141 | + return name; |
132 | 142 | } |
133 | 143 | VALIDATION_LOG << "Attempted to acquire an invalid GL handle."; |
134 | 144 | return std::nullopt; |
135 | 145 | } |
136 | 146 |
|
| 147 | +std::optional<GLuint> ReactorGLES::GetGLHandle(const HandleGLES& handle) const { |
| 148 | + if (handle.type == HandleType::kFence) { |
| 149 | + return std::nullopt; |
| 150 | + } |
| 151 | + std::optional<ReactorGLES::GLStorage> gl_handle = GetHandle(handle); |
| 152 | + if (gl_handle.has_value()) { |
| 153 | + return gl_handle->handle; |
| 154 | + } |
| 155 | + return std::nullopt; |
| 156 | +} |
| 157 | + |
| 158 | +std::optional<GLsync> ReactorGLES::GetGLFence(const HandleGLES& handle) const { |
| 159 | + if (handle.type != HandleType::kFence) { |
| 160 | + return std::nullopt; |
| 161 | + } |
| 162 | + std::optional<ReactorGLES::GLStorage> gl_handle = GetHandle(handle); |
| 163 | + if (gl_handle.has_value()) { |
| 164 | + return gl_handle->sync; |
| 165 | + } |
| 166 | + return std::nullopt; |
| 167 | +} |
| 168 | + |
137 | 169 | bool ReactorGLES::AddOperation(Operation operation) { |
138 | 170 | if (!operation) { |
139 | 171 | return false; |
@@ -171,9 +203,9 @@ HandleGLES ReactorGLES::CreateHandle(HandleType type, GLuint external_handle) { |
171 | 203 | } |
172 | 204 | WriterLock handles_lock(handles_mutex_); |
173 | 205 |
|
174 | | - std::optional<GLuint> gl_handle; |
| 206 | + std::optional<ReactorGLES::GLStorage> gl_handle; |
175 | 207 | if (external_handle != GL_NONE) { |
176 | | - gl_handle = external_handle; |
| 208 | + gl_handle = ReactorGLES::GLStorage{.handle = external_handle}; |
177 | 209 | } else if (CanReactOnCurrentThread()) { |
178 | 210 | gl_handle = CreateGLHandle(GetProcTable(), type); |
179 | 211 | } |
@@ -215,6 +247,8 @@ static DebugResourceType ToDebugResourceType(HandleType type) { |
215 | 247 | return DebugResourceType::kRenderBuffer; |
216 | 248 | case HandleType::kFrameBuffer: |
217 | 249 | return DebugResourceType::kFrameBuffer; |
| 250 | + case HandleType::kFence: |
| 251 | + return DebugResourceType::kFence; |
218 | 252 | } |
219 | 253 | FML_UNREACHABLE(); |
220 | 254 | } |
@@ -253,9 +287,10 @@ bool ReactorGLES::ConsolidateHandles() { |
253 | 287 | handle.second.name = gl_handle; |
254 | 288 | } |
255 | 289 | // Set pending debug labels. |
256 | | - if (handle.second.pending_debug_label.has_value()) { |
| 290 | + if (handle.second.pending_debug_label.has_value() && |
| 291 | + handle.first.type != HandleType::kFence) { |
257 | 292 | if (gl.SetDebugLabel(ToDebugResourceType(handle.first.type), |
258 | | - handle.second.name.value(), |
| 293 | + handle.second.name.value().handle, |
259 | 294 | handle.second.pending_debug_label.value())) { |
260 | 295 | handle.second.pending_debug_label = std::nullopt; |
261 | 296 | } |
|
0 commit comments