video: fencing to avoid passing frame back to decoder too early
With atomic kms backend, userspace can get further ahead of the gpu. In
the decoder, we unref the previous frame when retrieving the current
frame. If userspace gets too far ahead, this can happen while the gpu
is still sampling from the previous frame.
Simple solution is add a fence.
Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Rob Clark
7 years ago
48 | 48 | struct decoder *decoder; |
49 | 49 | int filenames_count, idx; |
50 | 50 | const char *filenames[32]; |
51 | ||
52 | EGLSyncKHR last_fence; | |
51 | 53 | } gl; |
52 | 54 | |
53 | 55 | static const struct egl *egl = &gl.egl; |
222 | 224 | ESMatrix modelview; |
223 | 225 | EGLImage frame; |
224 | 226 | |
227 | if (gl.last_fence) { | |
228 | egl->eglClientWaitSyncKHR(egl->display, gl.last_fence, 0, EGL_FOREVER_KHR); | |
229 | egl->eglDestroySyncKHR(egl->display, gl.last_fence); | |
230 | gl.last_fence = NULL; | |
231 | } | |
232 | ||
225 | 233 | frame = video_frame(gl.decoder); |
226 | 234 | if (!frame) { |
227 | 235 | /* end of stream */ |
288 | 296 | glDrawArrays(GL_TRIANGLE_STRIP, 12, 4); |
289 | 297 | glDrawArrays(GL_TRIANGLE_STRIP, 16, 4); |
290 | 298 | glDrawArrays(GL_TRIANGLE_STRIP, 20, 4); |
299 | ||
300 | gl.last_fence = egl->eglCreateSyncKHR(egl->display, EGL_SYNC_FENCE_KHR, NULL); | |
291 | 301 | } |
292 | 302 | |
293 | 303 | const struct egl * init_cube_video(const struct gbm *gbm, const char *filenames) |
299 | 309 | if (ret) |
300 | 310 | return NULL; |
301 | 311 | |
302 | if (egl_check(&gl.egl, glEGLImageTargetTexture2DOES)) | |
312 | if (egl_check(&gl.egl, glEGLImageTargetTexture2DOES) || | |
313 | egl_check(egl, eglCreateSyncKHR) || | |
314 | egl_check(egl, eglDestroySyncKHR) || | |
315 | egl_check(egl, eglClientWaitSyncKHR)) | |
303 | 316 | return NULL; |
304 | 317 | |
305 | 318 | fnames = strdup(filenames); |