rusticl/gl: make GLX support optional

Signed-off-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26394>
This commit is contained in:
Karol Herbst
2023-11-29 22:31:49 +01:00
committed by Marge Bot
parent 494fd5d068
commit b470bd7359
4 changed files with 35 additions and 9 deletions

View File

@@ -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

View File

@@ -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)?;

View File

@@ -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 : [

View File

@@ -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; }