From adbe8b6c17a76bb5ee0b924d927473f81c593eba Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Wed, 15 Feb 2023 19:23:21 +0000 Subject: [PATCH] mesa: optimize out _mesa_is_desktop_gl*() and _mesa_is_gles*() calls when not built This will in turn optimize out anything that's gated on those. Suggested-by: Adam Jackson Signed-off-by: Eric Engestrom Reviewed-by: Adam Jackson Part-of: --- meson.build | 4 ++++ src/mesa/main/context.h | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/meson.build b/meson.build index 326d8c645b352..91a7fb8669e89 100644 --- a/meson.build +++ b/meson.build @@ -121,6 +121,10 @@ with_gles2 = get_option('gles2') \ .require(with_shared_glapi, error_message : 'OpengGL ES 2.x requires shared-glapi') \ .allowed() +pre_args += '-DHAVE_OPENGL=@0@'.format(with_opengl ? '1' : '0') +pre_args += '-DHAVE_OPENGL_ES_1=@0@'.format(with_gles1 ? '1' : '0') +pre_args += '-DHAVE_OPENGL_ES_2=@0@'.format(with_gles2 ? '1' : '0') + with_any_opengl = with_opengl or with_gles1 or with_gles2 # Only build shared_glapi if at least one OpenGL API is enabled with_shared_glapi = with_shared_glapi and with_any_opengl diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index 362be1a167eb5..34bc76293306b 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -252,7 +252,11 @@ do { \ static inline bool _mesa_is_desktop_gl_compat(const struct gl_context *ctx) { +#if HAVE_OPENGL return ctx->API == API_OPENGL_COMPAT; +#else + return false; +#endif } /** @@ -261,7 +265,11 @@ _mesa_is_desktop_gl_compat(const struct gl_context *ctx) static inline bool _mesa_is_desktop_gl_core(const struct gl_context *ctx) { +#if HAVE_OPENGL return ctx->API == API_OPENGL_CORE; +#else + return false; +#endif } /** @@ -279,7 +287,11 @@ _mesa_is_desktop_gl(const struct gl_context *ctx) static inline bool _mesa_is_gles1(const struct gl_context *ctx) { +#if HAVE_OPENGL_ES_1 return ctx->API == API_OPENGLES; +#else + return false; +#endif } /** @@ -288,7 +300,11 @@ _mesa_is_gles1(const struct gl_context *ctx) static inline bool _mesa_is_gles2(const struct gl_context *ctx) { +#if HAVE_OPENGL_ES_2 return ctx->API == API_OPENGLES2; +#else + return false; +#endif } /**