Module: Mesa
Branch: main
Commit: b470bd735979e8e391a8ab87a04571296ec471c2
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b470bd735979e8e391a8ab87a04571296ec471c2

Author: Karol Herbst <[email protected]>
Date:   Wed Nov 29 22:31:49 2023 +0100

rusticl/gl: make GLX support optional

Signed-off-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26394>

---

 meson.build                                        |  6 ++---
 src/gallium/frontends/rusticl/core/gl.rs           | 27 ++++++++++++++++++----
 src/gallium/frontends/rusticl/meson.build          |  7 ++++++
 .../frontends/rusticl/rusticl_opencl_bindings.h    |  4 +++-
 4 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/meson.build b/meson.build
index 6181c1439ed..a69e4a7d161 100644
--- a/meson.build
+++ b/meson.build
@@ -2015,6 +2015,9 @@ if with_platform_x11
     dep_xfixes = dependency('xfixes', version : '>= 2.0')
     dep_xcb_glx = dependency('xcb-glx', version : '>= 1.8.1')
     dep_xcb_shm = dependency('xcb-shm')
+  elif with_gallium_rusticl
+    # needed for GL sharing extension
+    dep_x11 = dependency('x11')
   endif
   if (with_any_vk or with_glx == 'dri' or with_egl or
        (with_gallium_vdpau or with_gallium_va or
@@ -2069,9 +2072,6 @@ if with_platform_x11
   if with_xlib_lease
     dep_xlib_xrandr = dependency('xrandr', version : '>= 1.3')
   endif
-elif with_gallium_rusticl
-  # needed for GL sharing extension
-  dep_x11 = dependency('x11')
 endif
 
 if with_dri
diff --git a/src/gallium/frontends/rusticl/core/gl.rs 
b/src/gallium/frontends/rusticl/core/gl.rs
index d65b8c78017..09c40ba7f9e 100644
--- a/src/gallium/frontends/rusticl/core/gl.rs
+++ b/src/gallium/frontends/rusticl/core/gl.rs
@@ -16,6 +16,7 @@ use mesa_rust::pipe::resource::*;
 use mesa_rust::pipe::screen::*;
 
 use std::collections::HashMap;
+use std::ffi::CStr;
 use std::ffi::CString;
 use std::mem;
 use std::os::raw::c_void;
@@ -25,6 +26,7 @@ use std::sync::Arc;
 type CLGLMappings = Option<HashMap<Arc<PipeResource>, Arc<PipeResource>>>;
 
 pub struct XPlatManager {
+    #[cfg(glx)]
     glx_get_proc_addr: PFNGLXGETPROCADDRESSPROC,
     egl_get_proc_addr: PFNEGLGETPROCADDRESSPROC,
 }
@@ -38,6 +40,7 @@ impl Default for XPlatManager {
 impl XPlatManager {
     pub fn new() -> Self {
         Self {
+            #[cfg(glx)]
             glx_get_proc_addr: 
Self::get_proc_address_func("glXGetProcAddress"),
             egl_get_proc_addr: 
Self::get_proc_address_func("eglGetProcAddress"),
         }
@@ -51,14 +54,28 @@ impl XPlatManager {
         }
     }
 
+    #[cfg(glx)]
+    unsafe fn get_func_glx(&self, cname: &CStr) -> CLResult<__GLXextFuncPtr> {
+        unsafe {
+            Ok(self
+                .glx_get_proc_addr
+                .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?(
+                cname.as_ptr().cast(),
+            ))
+        }
+    }
+
+    // in theory it should return CLResult<__GLXextFuncPtr> but luckily it's 
identical
+    #[cfg(not(glx))]
+    unsafe fn get_func_glx(&self, _: &CStr) -> 
CLResult<__eglMustCastToProperFunctionPointerType> {
+        Err(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)
+    }
+
     fn get_func<T>(&self, name: &str) -> CLResult<T> {
         let cname = CString::new(name).unwrap();
         unsafe {
             let raw_func = if name.starts_with("glX") {
-                self.glx_get_proc_addr
-                    .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?(
-                    cname.as_ptr().cast()
-                )
+                self.get_func_glx(&cname)?
             } else if name.starts_with("egl") {
                 self.egl_get_proc_addr
                     .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?(
@@ -160,7 +177,7 @@ impl GLCtxManager {
                 interop_dev_info: info,
                 xplat_manager: xplat_manager,
             }))
-        } else if !glx_display.is_null() {
+        } else if !glx_display.is_null() && cfg!(glx) {
             let glx_query_device_info_func = xplat_manager
                 .MesaGLInteropGLXQueryDeviceInfo()?
                 .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?;
diff --git a/src/gallium/frontends/rusticl/meson.build 
b/src/gallium/frontends/rusticl/meson.build
index ee9d8c3fcd6..4bb13dcbca2 100644
--- a/src/gallium/frontends/rusticl/meson.build
+++ b/src/gallium/frontends/rusticl/meson.build
@@ -92,6 +92,12 @@ rusticl_args = [
   '-Aclippy::type_complexity',
 ]
 
+if with_platform_x11
+  rusticl_args += [
+    '--cfg', 'glx',
+  ]
+endif
+
 rusticl_gen_args = [
   # can't do anything about it anyway
   '-Aclippy::all',
@@ -159,6 +165,7 @@ rusticl_opencl_bindings_rs = rust.bindgen(
   ],
   c_args : [
     rusticl_bindgen_c_args,
+    pre_args,
     cl_c_args,
   ],
   args : [
diff --git a/src/gallium/frontends/rusticl/rusticl_opencl_bindings.h 
b/src/gallium/frontends/rusticl/rusticl_opencl_bindings.h
index 279534e4f01..dd3d2e339bc 100644
--- a/src/gallium/frontends/rusticl/rusticl_opencl_bindings.h
+++ b/src/gallium/frontends/rusticl/rusticl_opencl_bindings.h
@@ -1,7 +1,9 @@
 #include <CL/cl_icd.h>
-#include <EGL/egl.h>
 #include <GL/gl.h>
+#include <EGL/egl.h>
+#ifdef HAVE_X11_PLATFORM
 #include <GL/glx.h>
+#endif
 #include "GL/mesa_glinterop.h"
 
 #define DECL_CL_STRUCT(name) struct name { const cl_icd_dispatch *dispatch; }

Reply via email to