[Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
Signed-off-by: Tapani Pälli --- src/egl/drivers/dri2/egl_dri2.c | 43 + src/egl/drivers/dri2/egl_dri2.h | 4 src/egl/main/eglapi.c | 29 +++ src/egl/main/eglapi.h | 4 src/egl/main/egldisplay.h | 3 +++ src/egl/main/eglentrypoint.h| 1 + 6 files changed, 84 insertions(+) diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index d5a4f72e86..f9d0223fe2 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -458,6 +458,7 @@ static const struct dri2_extension_match optional_core_extensions[] = { { __DRI2_INTEROP, 1, offsetof(struct dri2_egl_display, interop) }, { __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) }, { __DRI2_FLUSH_CONTROL, 1, offsetof(struct dri2_egl_display, flush_control) }, + { __DRI2_BLOB, 1, offsetof(struct dri2_egl_display, blob) }, { NULL, 0, 0 } }; @@ -727,6 +728,9 @@ dri2_setup_screen(_EGLDisplay *disp) } } + if (dri2_dpy->blob) + disp->Extensions.ANDROID_blob_cache = EGL_TRUE; + disp->Extensions.KHR_reusable_sync = EGL_TRUE; if (dri2_dpy->image) { @@ -1470,6 +1474,26 @@ dri2_surf_update_fence_fd(_EGLContext *ctx, dri2_surface_set_out_fence_fd(surf, fence_fd); } +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + /** * Called via eglMakeCurrent(), drv->API.MakeCurrent(). */ @@ -1499,6 +1523,9 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf, if (old_ctx) dri2_gl_flush(); + /* Make sure cache functions are set for new context. */ + update_blob_cache_functions(dri2_dpy, dri2_ctx); + ddraw = (dsurf) ? dri2_dpy->vtbl->get_dri_drawable(dsurf) : NULL; rdraw = (rsurf) ? dri2_dpy->vtbl->get_dri_drawable(rsurf) : NULL; cctx = (dri2_ctx) ? dri2_ctx->dri_context : NULL; @@ -3016,6 +3043,21 @@ dri2_dup_native_fence_fd(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync) return dup(sync->SyncFd); } +static void +dri2_set_blob_cache_funcs(_EGLDriver *drv, _EGLDisplay *dpy, + EGLSetBlobFuncANDROID set, + EGLGetBlobFuncANDROID get) +{ + _EGLContext *ctx = _eglGetCurrentContext(); + struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy); + struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx); + + dri2_dpy->blob_cache_set = set; + dri2_dpy->blob_cache_get = get; + + update_blob_cache_functions(dri2_dpy, dri2_ctx); +} + static EGLint dri2_client_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync, EGLint flags, EGLTime timeout) @@ -3234,6 +3276,7 @@ _eglBuiltInDriver(void) dri2_drv->API.GLInteropQueryDeviceInfo = dri2_interop_query_device_info; dri2_drv->API.GLInteropExportObject = dri2_interop_export_object; dri2_drv->API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd; + dri2_drv->API.SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs; dri2_drv->Name = "DRI2"; diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h index cc76c73eab..a6777ad3f1 100644 --- a/src/egl/drivers/dri2/egl_dri2.h +++ b/src/egl/drivers/dri2/egl_dri2.h @@ -171,6 +171,7 @@ struct dri2_egl_display const __DRInoErrorExtension*no_error; const __DRI2configQueryExtension *config; const __DRI2fenceExtension *fence; + const __DRI2blobExtension *blob; const __DRI2rendererQueryExtension *rendererQuery; const __DRI2interopExtension *interop; int fd; @@ -230,6 +231,9 @@ struct dri2_egl_display bool is_render_node; bool is_different_gpu; + + EGLSetBlobFuncANDROID blob_cache_set; + EGLGetBlobFuncANDROID blob_cache_get; }; struct dri2_egl_context diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 5110688f2d..b8d64a913c 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -476,6 +476,7 @@ _eglCreateExtensionsString(_EGLDisplay *dpy) char *exts = dpy->ExtensionsString; /* Please keep these sorted alphabetically. */ + _EGL_CHECK_EXTENSION(ANDROID_blob_cache); _EGL_CHECK_EXTENSION(ANDROID_framebuffer_target); _EGL_CHECK_EXTENSION(ANDROID_image_native_buffer); _EGL_CHECK_EXTENSION(ANDROID_native_fence_sync); @@ -2522,6 +2523,34 @@ eglQueryDmaBufModifiersEXT(EGLDisplay dpy, EGLint format, EGLint max_modifiers, RETURN_EGL_EVAL(disp, ret); } +static void E
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: > +static void > +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, > +struct dri2_egl_context *dri2_ctx) > +{ > + if (!dri2_dpy || !dri2_ctx) > + return; AFAICT dri2_dpy can never be NULL. > + > + /* No blob support. */ > + if (!dri2_dpy->blob) > + return; > + > + /* No functions to set. */ > + if (!dri2_dpy->blob_cache_set) > + return; > + > + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, > + dri2_dpy->blob_cache_set, > + dri2_dpy->blob_cache_get); > +} > + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. > @@ -230,6 +231,9 @@ struct dri2_egl_display > > bool is_render_node; > bool is_different_gpu; > + > + EGLSetBlobFuncANDROID blob_cache_set; > + EGLGetBlobFuncANDROID blob_cache_get; These two are part of the EGL API, so they are better suited in struct _egl_display. -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 16.01.2018 19:45, Emil Velikov wrote: Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; AFAICT dri2_dpy can never be NULL. Yeah, that check can be removed. It was because of my 'debug framework' (see eariler RFC). It was hit when running PIGLIT_PLATFORM=gbm and during Piglit teardown we end up here from eglMakeCurrent that called drv->API.SetBlobCacheFuncsANDROID (and which is called during __run_exit_handlers) and display is then 0x0. But it won't ever happen without my 'debug framework' addition. + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. It's an extension so we would still need dri2_dpy->blob check but maybe not so much checks overall .. I'll see how that would look. Thanks! @@ -230,6 +231,9 @@ struct dri2_egl_display bool is_render_node; bool is_different_gpu; + + EGLSetBlobFuncANDROID blob_cache_set; + EGLGetBlobFuncANDROID blob_cache_get; These two are part of the EGL API, so they are better suited in struct _egl_display. OK, will move them there. // Tapani ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 16.01.2018 18:45, Emil Velikov wrote: Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; AFAICT dri2_dpy can never be NULL. + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. Yes, please make it a screen thing. It just makes more sense, and there's precedent in Gallium, where the disk-cache is a per-pipe_screen object as well. Thanks, Nicolai @@ -230,6 +231,9 @@ struct dri2_egl_display bool is_render_node; bool is_different_gpu; + + EGLSetBlobFuncANDROID blob_cache_set; + EGLGetBlobFuncANDROID blob_cache_get; These two are part of the EGL API, so they are better suited in struct _egl_display. -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev -- Lerne, wie die Welt wirklich ist, Aber vergiss niemals, wie sie sein sollte. ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 17.01.2018 13:28, Nicolai Hähnle wrote: On 16.01.2018 18:45, Emil Velikov wrote: Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, + struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; AFAICT dri2_dpy can never be NULL. + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. Yes, please make it a screen thing. It just makes more sense, and there's precedent in Gallium, where the disk-cache is a per-pipe_screen object as well. I chose context because eventually I need to access disk_cache which is part of gl_context. I'm not sure how would I propagate the set/get there from dri_screen? Thanks, Nicolai @@ -230,6 +231,9 @@ struct dri2_egl_display bool is_render_node; bool is_different_gpu; + + EGLSetBlobFuncANDROID blob_cache_set; + EGLGetBlobFuncANDROID blob_cache_get; These two are part of the EGL API, so they are better suited in struct _egl_display. -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 17 January 2018 at 16:11, Tapani Pälli wrote: > > > On 17.01.2018 13:28, Nicolai Hähnle wrote: >> >> On 16.01.2018 18:45, Emil Velikov wrote: >>> >>> Hi Tapani, >>> >>> On 15 January 2018 at 12:31, Tapani Pälli wrote: >>> +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; >>> >>> AFAICT dri2_dpy can never be NULL. >>> + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + >>> >>> I'm wondering why you opted to make set_cache_funcs dri_context >>> specific as opposed to dri_screen. >>> The latter seems to align better to EGLDisplay. >>> >>> Plus doing so will simplify the existing code - no hunk in >>> dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. >> >> >> Yes, please make it a screen thing. It just makes more sense, and there's >> precedent in Gallium, where the disk-cache is a per-pipe_screen object as >> well. > > > I chose context because eventually I need to access disk_cache which is part > of gl_context. I'm not sure how would I propagate the set/get there from > dri_screen? > Gallium does the following during create_context. I'm not sure if there's any particular reason why i965 cannot do the same. Tim, you've worked a fair bit in the area do you see any drawbacks? ctx->Cache = pipe->screen->det_dist_shader_cache(pipe->screen); -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 01/18/2018 04:55 PM, Emil Velikov wrote: On 17 January 2018 at 16:11, Tapani Pälli wrote: On 17.01.2018 13:28, Nicolai Hähnle wrote: On 16.01.2018 18:45, Emil Velikov wrote: Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; AFAICT dri2_dpy can never be NULL. + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. Yes, please make it a screen thing. It just makes more sense, and there's precedent in Gallium, where the disk-cache is a per-pipe_screen object as well. I chose context because eventually I need to access disk_cache which is part of gl_context. I'm not sure how would I propagate the set/get there from dri_screen? Gallium does the following during create_context. I'm not sure if there's any particular reason why i965 cannot do the same. Tim, you've worked a fair bit in the area do you see any drawbacks? ctx->Cache = pipe->screen->det_dist_shader_cache(pipe->screen); One problem is that client might set the callbacks only after context creation so we need to be able to do this during set_cache_funcs(). Now it works fine because we pass context there. // Tapani ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 19 January 2018 at 06:53, Tapani Pälli wrote: > > > On 01/18/2018 04:55 PM, Emil Velikov wrote: >> >> On 17 January 2018 at 16:11, Tapani Pälli wrote: >>> >>> >>> >>> On 17.01.2018 13:28, Nicolai Hähnle wrote: On 16.01.2018 18:45, Emil Velikov wrote: > > > Hi Tapani, > > On 15 January 2018 at 12:31, Tapani Pälli > wrote: > >> +static void >> +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, >> +struct dri2_egl_context *dri2_ctx) >> +{ >> + if (!dri2_dpy || !dri2_ctx) >> + return; > > > AFAICT dri2_dpy can never be NULL. > >> + >> + /* No blob support. */ >> + if (!dri2_dpy->blob) >> + return; >> + >> + /* No functions to set. */ >> + if (!dri2_dpy->blob_cache_set) >> + return; >> + >> + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, >> + dri2_dpy->blob_cache_set, >> + dri2_dpy->blob_cache_get); >> +} >> + > > > I'm wondering why you opted to make set_cache_funcs dri_context > specific as opposed to dri_screen. > The latter seems to align better to EGLDisplay. > > Plus doing so will simplify the existing code - no hunk in > dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. Yes, please make it a screen thing. It just makes more sense, and there's precedent in Gallium, where the disk-cache is a per-pipe_screen object as well. >>> >>> >>> >>> I chose context because eventually I need to access disk_cache which is >>> part >>> of gl_context. I'm not sure how would I propagate the set/get there from >>> dri_screen? >>> >> Gallium does the following during create_context. I'm not sure if >> there's any particular reason why i965 cannot do the same. >> Tim, you've worked a fair bit in the area do you see any drawbacks? >> >> ctx->Cache = pipe->screen->det_dist_shader_cache(pipe->screen); >> > > One problem is that client might set the callbacks only after context > creation so we need to be able to do this during set_cache_funcs(). Now it > works fine because we pass context there. > I don't see why that would be an issue. Both ctx::cache and screen::cache are pointer to a single instance. Hence, as we deref. screen::cache and update the callbacks, everything will be fine from ctx POV - no need to update for each make_current call/etc. Am I having a dull moment here? Thanks Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 2/7] egl: add support for EGL_ANDROID_blob_cache
On 01/22/2018 04:05 PM, Emil Velikov wrote: On 19 January 2018 at 06:53, Tapani Pälli wrote: On 01/18/2018 04:55 PM, Emil Velikov wrote: On 17 January 2018 at 16:11, Tapani Pälli wrote: On 17.01.2018 13:28, Nicolai Hähnle wrote: On 16.01.2018 18:45, Emil Velikov wrote: Hi Tapani, On 15 January 2018 at 12:31, Tapani Pälli wrote: +static void +update_blob_cache_functions(struct dri2_egl_display *dri2_dpy, +struct dri2_egl_context *dri2_ctx) +{ + if (!dri2_dpy || !dri2_ctx) + return; AFAICT dri2_dpy can never be NULL. + + /* No blob support. */ + if (!dri2_dpy->blob) + return; + + /* No functions to set. */ + if (!dri2_dpy->blob_cache_set) + return; + + dri2_dpy->blob->set_cache_funcs(dri2_ctx->dri_context, + dri2_dpy->blob_cache_set, + dri2_dpy->blob_cache_get); +} + I'm wondering why you opted to make set_cache_funcs dri_context specific as opposed to dri_screen. The latter seems to align better to EGLDisplay. Plus doing so will simplify the existing code - no hunk in dri2_make_current, no dri2_dpy->blob/blob_cache_set checks, etc. Yes, please make it a screen thing. It just makes more sense, and there's precedent in Gallium, where the disk-cache is a per-pipe_screen object as well. I chose context because eventually I need to access disk_cache which is part of gl_context. I'm not sure how would I propagate the set/get there from dri_screen? Gallium does the following during create_context. I'm not sure if there's any particular reason why i965 cannot do the same. Tim, you've worked a fair bit in the area do you see any drawbacks? ctx->Cache = pipe->screen->det_dist_shader_cache(pipe->screen); One problem is that client might set the callbacks only after context creation so we need to be able to do this during set_cache_funcs(). Now it works fine because we pass context there. I don't see why that would be an issue. Both ctx::cache and screen::cache are pointer to a single instance. Hence, as we deref. screen::cache and update the callbacks, everything will be fine from ctx POV - no need to update for each make_current call/etc. Am I having a dull moment here? I was confused since that is not how it works with i965. We create cache during context creation and store it in context (gl_context::Cache). This happens for each context and they get a unique disk_cache pointer. I understand your proposal would be to move Cache to screen structure and utilize this same disk_cache instance from each context. I guess it should be possible and could be done separately before blob cache implementation. // Tapani ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev