| Message ID | 20261204031914.117401-5-me@coolgi.dev |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Quoting Remy Alipoursafari (2026-12-04 03:18:56) > From: Remy Alipoursafari <remy.alipoursafari@collabora.com> > > Separates searching for proc addresses using eglGetProcAddress into its > own function so that future searches can be more easily added. > > Initialisation is also no longer fails if the function addresses' does > not exist, so extension support must be checked before proc addresses are > used. > > Signed-off-by: Remy Alipoursafari <remy.alipoursafari@collabora.com> > Reviewed-by: Robert Mader <robert.mader@collabora.com> > --- > include/libcamera/internal/egl.h | 2 ++ > src/libcamera/egl.cpp | 41 +++++++++++++++++++------------- > 2 files changed, 26 insertions(+), 17 deletions(-) > > diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h > index 0f45c29b..1d1c530c 100644 > --- a/include/libcamera/internal/egl.h > +++ b/include/libcamera/internal/egl.h > @@ -164,5 +164,7 @@ private: > PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; > PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; > } vtable_ = {}; > + > + void locateProcAddresses(VTable *vtable); > }; > } //namespace libcamera > diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp > index 1a0b6c37..df5b542d 100644 > --- a/src/libcamera/egl.cpp > +++ b/src/libcamera/egl.cpp > @@ -417,23 +417,7 @@ int eGL::initEGLContext() > for (auto &&extName : utils::split(eglExtensions, " ")) > eglExtensions_.insert(std::move(extName)); > > - vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); > - if (!vtable.eglCreateImageKHR) { > - LOG(eGL, Error) << "eglCreateImageKHR not found"; > - return -ENODEV; > - } > - > - vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); > - if (!vtable.eglDestroyImageKHR) { > - LOG(eGL, Error) << "eglDestroyImageKHR not found"; > - return -ENODEV; > - } > - > - vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); > - if (!vtable.glEGLImageTargetTexture2DOES) { > - LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found"; > - return -ENODEV; > - } > + locateProcAddresses(&vtable); > > if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { > LOG(eGL, Error) << "eglChooseConfig fail"; > @@ -562,6 +546,29 @@ void eGL::makeCurrent() > } > } > > +/** > + * \brief Gets the addresses for EGL extension functions > + * \param[in,out] vtable VTable to store the function addresses > + * > + * Locates the relevant runtime function addresses needed to fill the VTable. > + * This does not fail when a function pointer is not found, nor does it validate > + * the functions are available for the GL context, so it is also expected to > + * also check the extension availability. > + */ > +void eGL::locateProcAddresses(VTable *vtable) > +{ > +#define GET_PROC_ADDRESS(location, name) ({ \ > + location = reinterpret_cast<decltype(location)>(eglGetProcAddress(name)); \ > + if (!location) { \ > + LOG(eGL, Debug) << name << " not found"; \ If these are not found, are we going to crash later? If so - change this to a very loud Error or even Fatal if it's simply not supposed to happen. We shouldn't be hiding this if there's no error checking in this initialisation. > + } \ > +}) > + > + GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR"); > + GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR"); And presumably, we would want a contract that vtable->(name) == "(name)" so you could go one step further and make the macro take: GET_PROC_ADDRESS(vtable, glEGLImageTargetTexture2DOES); #define GET_PROC_ADDRESS(vtable, name) \ vtable->name = reinterpret_cast<decltype(vtable->name)>(eglGetProcAddress(#name)); \ if (!vtable->name) \ LOG(eGL, Error) << #name << " not found"; \ (not compile tested) > + GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES"); > +} > + > /** > * \brief Add a preprocessor definition to shader environment > * \param[in,out] shaderEnv Vector of shader environment strings > -- > 2.56.1 >
2026. 12. 04. 8:34 keltezéssel, Kieran Bingham írta: > Quoting Remy Alipoursafari (2026-12-04 03:18:56) >> From: Remy Alipoursafari <remy.alipoursafari@collabora.com> >> >> Separates searching for proc addresses using eglGetProcAddress into its >> own function so that future searches can be more easily added. >> >> Initialisation is also no longer fails if the function addresses' does >> not exist, so extension support must be checked before proc addresses are >> used. >> >> Signed-off-by: Remy Alipoursafari <remy.alipoursafari@collabora.com> >> Reviewed-by: Robert Mader <robert.mader@collabora.com> >> --- >> include/libcamera/internal/egl.h | 2 ++ >> src/libcamera/egl.cpp | 41 +++++++++++++++++++------------- >> 2 files changed, 26 insertions(+), 17 deletions(-) >> >> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h >> index 0f45c29b..1d1c530c 100644 >> --- a/include/libcamera/internal/egl.h >> +++ b/include/libcamera/internal/egl.h >> @@ -164,5 +164,7 @@ private: >> PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; >> PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; >> } vtable_ = {}; >> + >> + void locateProcAddresses(VTable *vtable); >> }; >> } //namespace libcamera >> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp >> index 1a0b6c37..df5b542d 100644 >> --- a/src/libcamera/egl.cpp >> +++ b/src/libcamera/egl.cpp >> @@ -417,23 +417,7 @@ int eGL::initEGLContext() >> for (auto &&extName : utils::split(eglExtensions, " ")) >> eglExtensions_.insert(std::move(extName)); >> >> - vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); >> - if (!vtable.eglCreateImageKHR) { >> - LOG(eGL, Error) << "eglCreateImageKHR not found"; >> - return -ENODEV; >> - } >> - >> - vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); >> - if (!vtable.eglDestroyImageKHR) { >> - LOG(eGL, Error) << "eglDestroyImageKHR not found"; >> - return -ENODEV; >> - } >> - >> - vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); >> - if (!vtable.glEGLImageTargetTexture2DOES) { >> - LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found"; >> - return -ENODEV; >> - } >> + locateProcAddresses(&vtable); >> >> if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { >> LOG(eGL, Error) << "eglChooseConfig fail"; >> @@ -562,6 +546,29 @@ void eGL::makeCurrent() >> } >> } >> >> +/** >> + * \brief Gets the addresses for EGL extension functions >> + * \param[in,out] vtable VTable to store the function addresses >> + * >> + * Locates the relevant runtime function addresses needed to fill the VTable. >> + * This does not fail when a function pointer is not found, nor does it validate >> + * the functions are available for the GL context, so it is also expected to >> + * also check the extension availability. >> + */ >> +void eGL::locateProcAddresses(VTable *vtable) >> +{ >> +#define GET_PROC_ADDRESS(location, name) ({ \ >> + location = reinterpret_cast<decltype(location)>(eglGetProcAddress(name)); \ >> + if (!location) { \ >> + LOG(eGL, Debug) << name << " not found"; \ > > If these are not found, are we going to crash later? > > If so - change this to a very loud Error or even Fatal if it's simply > not supposed to happen. We shouldn't be hiding this if there's no error > checking in this initialisation. I think patch 2 solves this by explicitly checking the extension availability. And then it is assumed that the functions will exist if the extension is available: Initialisation is also no longer fails if the function addresses' does not exist, so extension support must be checked before proc addresses are used. > >> + } \ >> +}) >> + >> + GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR"); >> + GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR"); > > And presumably, we would want a contract that vtable->(name) == > "(name)" so you could go one step further and make the macro take: > > GET_PROC_ADDRESS(vtable, glEGLImageTargetTexture2DOES); > > #define GET_PROC_ADDRESS(vtable, name) \ > vtable->name = reinterpret_cast<decltype(vtable->name)>(eglGetProcAddress(#name)); \ > if (!vtable->name) \ > LOG(eGL, Error) << #name << " not found"; \ > > (not compile tested) I like this > > >> + GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES"); The macro is only needed in this function, right? Could you #undef it at the end? >> +} >> + >> /** >> * \brief Add a preprocessor definition to shader environment >> * \param[in,out] shaderEnv Vector of shader environment strings >> -- >> 2.56.1 >>
diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h index 0f45c29b..1d1c530c 100644 --- a/include/libcamera/internal/egl.h +++ b/include/libcamera/internal/egl.h @@ -164,5 +164,7 @@ private: PFNEGLCREATEIMAGEKHRPROC eglCreateImageKHR; PFNEGLDESTROYIMAGEKHRPROC eglDestroyImageKHR; } vtable_ = {}; + + void locateProcAddresses(VTable *vtable); }; } //namespace libcamera diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp index 1a0b6c37..df5b542d 100644 --- a/src/libcamera/egl.cpp +++ b/src/libcamera/egl.cpp @@ -417,23 +417,7 @@ int eGL::initEGLContext() for (auto &&extName : utils::split(eglExtensions, " ")) eglExtensions_.insert(std::move(extName)); - vtable.eglCreateImageKHR = (PFNEGLCREATEIMAGEKHRPROC)eglGetProcAddress("eglCreateImageKHR"); - if (!vtable.eglCreateImageKHR) { - LOG(eGL, Error) << "eglCreateImageKHR not found"; - return -ENODEV; - } - - vtable.eglDestroyImageKHR = (PFNEGLDESTROYIMAGEKHRPROC)eglGetProcAddress("eglDestroyImageKHR"); - if (!vtable.eglDestroyImageKHR) { - LOG(eGL, Error) << "eglDestroyImageKHR not found"; - return -ENODEV; - } - - vtable.glEGLImageTargetTexture2DOES = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress("glEGLImageTargetTexture2DOES"); - if (!vtable.glEGLImageTargetTexture2DOES) { - LOG(eGL, Error) << "glEGLImageTargetTexture2DOES not found"; - return -ENODEV; - } + locateProcAddresses(&vtable); if (eglChooseConfig(display_, configAttribs, &config, 1, &numConfigs) != EGL_TRUE) { LOG(eGL, Error) << "eglChooseConfig fail"; @@ -562,6 +546,29 @@ void eGL::makeCurrent() } } +/** + * \brief Gets the addresses for EGL extension functions + * \param[in,out] vtable VTable to store the function addresses + * + * Locates the relevant runtime function addresses needed to fill the VTable. + * This does not fail when a function pointer is not found, nor does it validate + * the functions are available for the GL context, so it is also expected to + * also check the extension availability. + */ +void eGL::locateProcAddresses(VTable *vtable) +{ +#define GET_PROC_ADDRESS(location, name) ({ \ + location = reinterpret_cast<decltype(location)>(eglGetProcAddress(name)); \ + if (!location) { \ + LOG(eGL, Debug) << name << " not found"; \ + } \ +}) + + GET_PROC_ADDRESS(vtable->eglCreateImageKHR, "eglCreateImageKHR"); + GET_PROC_ADDRESS(vtable->eglDestroyImageKHR, "eglDestroyImageKHR"); + GET_PROC_ADDRESS(vtable->glEGLImageTargetTexture2DOES, "glEGLImageTargetTexture2DOES"); +} + /** * \brief Add a preprocessor definition to shader environment * \param[in,out] shaderEnv Vector of shader environment strings