[Mesa-dev] [PATCH v2 07/12] meson: build glx

Dylan Baker dylan at pnwbakers.com
Thu Oct 5 17:12:25 UTC 2017


This gets GLX and the loader building. The resulting GLX and i965 have
been tested on piglit and seem to work fine. This patch leaves a lot of
todo's in it's wake, GLX is quite complicated, and the build options
involved are many, and the goal at the moment is to get dri and gallium
drivers building.

v2: - fix typo "vaule" -> "value"
    - put the not on the correct element of the conditional
    - Put correct description of dri3 option in this patch not the next
      one (Eric A)
    - fix non glvnd version (Eric A)
    - build glx tests
    - move loader include variables to this patch (Eric A)

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 include/meson.build                    |   2 +-
 meson.build                            | 163 ++++++++++++++++++++++-------
 meson_options.txt                      |   6 ++
 src/glx/meson.build                    | 185 +++++++++++++++++++++++++++++++++
 {include => src/glx/tests}/meson.build |  61 +++++------
 src/{ => loader}/meson.build           |  58 ++++-------
 src/mapi/glapi/meson.build             |   2 +
 src/meson.build                        |   5 +-
 8 files changed, 370 insertions(+), 112 deletions(-)
 create mode 100644 src/glx/meson.build
 copy {include => src/glx/tests}/meson.build (55%)
 copy src/{ => loader}/meson.build (55%)

diff --git a/include/meson.build b/include/meson.build
index beb57e3e044..e33a8569d76 100644
--- a/include/meson.build
+++ b/include/meson.build
@@ -51,7 +51,7 @@ if with_opengl
   )
 endif
 
-if with_glx
+if with_glx != 'disabled'
   install_headers('GL/glx.h', 'GL/glext.h', 'GL/glx_mangle.h', subdir : 'GL')
 endif
 
diff --git a/meson.build b/meson.build
index be6094e1d53..94b26414c1f 100644
--- a/meson.build
+++ b/meson.build
@@ -33,7 +33,6 @@ pre_args = [
   '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
 ]
 
-with_dri3 = true  # XXX: need a switch for this
 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
 with_tests = get_option('build-tests')
 with_valgrind = get_option('valgrind')
@@ -47,11 +46,11 @@ with_gles1 = get_option('gles1')
 with_gles2 = get_option('gles2')
 with_opengl = get_option('opengl')
 with_any_opengl = with_opengl or with_gles1 or with_gles2
-with_shared_glapi = get_option('shared-glapi')
+# Only build shared_glapi if at least one OpenGL API is enabled
+with_shared_glapi = get_option('shared-glapi') and with_any_opengl
 
 # TODO: these will need options, but at the moment they just control header
 # installs
-with_glx = false
 with_osmesa = false
 
 # shared-glapi is required if at least two OpenGL APIs are being built
@@ -84,6 +83,30 @@ if not with_dri
   with_shared_glapi = false
 endif
 
+# TODO: other OSes
+with_dri_platform = 'drm'
+
+with_gallium = false
+# TODO: gallium drivers
+
+# TODO: conditionalize libdrm requirement
+dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
+pre_args += '-DHAVE_LIBDRM'
+
+with_dri2 = with_dri_platform == 'drm' and dep_libdrm.found()
+with_dri3 = get_option('dri3')
+if with_dri3 == 'auto'
+  if host_machine.system() == 'linux'
+    with_dri3 = true
+  else
+    with_dri3 = false
+ endif
+elif with_dri3 == 'yes'
+  with_dri3 = true
+else
+  with_dri3 = false
+endif
+
 # TODO: there are more platforms required for non-vulkan drivers
 with_platform_wayland = false
 with_platform_x11 = false
@@ -94,20 +117,65 @@ if _platforms != ''
   with_platform_wayland = _split.contains('wayland')
 endif
 
+with_glx = get_option('glx')
+if with_glx != 'disabled'
+  pre_args += '-DGLX_USE_TLS'
+  if not (with_platform_x11 and with_any_opengl) and with_glx != 'auto'
+    error('Cannot build GLX support without X11 platform support and at least one OpenGL API')
+  elif with_glx == 'gallium-xlib' 
+    if not with_gallium
+      error('Gallium-xlib based GLX requires at least one gallium driver')
+    elif with_dri
+      error('gallium-xlib conflicts with any dri driver')
+    endif
+  elif with_glx == 'dri' and not with_dri
+    error('dri based GLX requires at least one DRI driver')
+  elif with_glx == 'auto'
+    if with_dri
+      with_glx = 'dri'
+    elif with_gallium
+      with_glx = 'gallium-xlib'
+    elif with_platform_x11 and with_any_opengl
+      with_glx = 'xlib'
+    else
+      with_glx = 'disabled'
+    endif
+  endif
+endif
+
+with_glvnd = get_option('glvnd')
+if with_glvnd and with_glx != 'dri'
+  message('glvnd requires dri based glx')
+endif
+
+# TODO: toggle for this
+with_glx_direct = true
+
 if with_vulkan_icd_dir == ''
   with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
 endif
 
 with_intel_vk = false
 with_amd_vk = false
+with_any_vk = false
 _vulkan_drivers = get_option('vulkan-drivers')
 if _vulkan_drivers != ''
   _split = _vulkan_drivers.split(',')
   with_intel_vk = _split.contains('intel')
   with_amd_vk = _split.contains('amd')
+  with_any_vk = with_amd_vk or with_intel_vk
   if not (with_platform_x11 or with_platform_wayland)
     error('Vulkan requires at least one platform (x11, wayland)')
   endif
+  if with_platform_x11 and not with_dri3
+    error('Vulkan drivers require dri3 for X11 support')
+  endif
+endif
+
+if with_dri # TODO: or gallium
+  if with_glx == 'disabled' # TODO: or egl
+    error('building dri or gallium drivers require at least one window system')
+  endif
 endif
 
 prog_python2 = find_program('python2')
@@ -378,9 +446,6 @@ dep_expat = dependency('expat')
 # its not linux and and wont
 dep_m = cc.find_library('m', required : false)
 
-# TODO: conditionalize libdrm requirement
-dep_libdrm = dependency('libdrm', version : '>= 2.4.75')
-pre_args += '-DHAVE_LIBDRM'
 dep_libdrm_amdgpu = []
 if with_amd_vk
   dep_libdrm_amdgpu = dependency('libdrm_amdgpu', version : '>= 2.4.82')
@@ -411,6 +476,12 @@ else
   ]
 endif
 
+dep_glvnd = []
+if with_glvnd
+  dep_glvnd = dependency('libglvnd', version : '>= 0.2.0')
+  pre_args += '-DUSE_LIBGLVND=1'
+endif
+
 # TODO: make this conditional
 dep_valgrind = dependency('valgrind', required : false)
 if dep_valgrind.found() and with_valgrind
@@ -442,18 +513,8 @@ dep_selinux = []
 
 # TODO: gallium drivers
 
-# TODO: libglvnd
-
 # TODO: symbol mangling
 
-# TODO: dri handling
-
-# TODO: shared-glapi
-
-# TODO: libgl requirements
-
-# TODO: GLX configuration
-
 # TODO: egl configuration
 
 if with_platform_wayland
@@ -470,32 +531,64 @@ endif
 
 dep_xcb_dri2 = []
 dep_xcb_dri3 = []
+dep_dri2proto = []
+dep_glproto = []
+dep_x11 = []
+dep_xf86vm = []
 if with_platform_x11
-  dep_xcb_dri2 = [
-    dependency('x11-xcb'),
-    dependency('xcb'),
-    dependency('xcb-dri2', version : '>= 1.8'),
-    dependency('xcb-xfixes'),
-  ]
-  if with_dri3
-    dep_xcb_dri3 = [
-      dep_xcb_dri2,
-      dependency('xcb-dri3'),
-      dependency('xcb-present'),
-      dependency('xcb-sync'),
-      dependency('xshmfence', version : '>= 1.1'),
-    ]
+  if with_glx == 'xlib'
+    # TODO
+    error('TODO')
+  elif with_glx == 'gallium-xlib'
+    # TODO
+    error('TODO')
   else
-    # TODO: dri3 is required for vulkan
+    pre_args += '-DGLX_INDIRECT_RENDERING'
+    if with_glx_direct
+      pre_args += '-DGLX_DIRECT_RENDERING'
+    endif
+    if with_dri_platform == 'drm'
+      pre_args += '-DGLX_USE_DRM'
+      dep_dri2proto = dependency('dri2proto', version : '>= 2.8')
+      dep_x11 = [
+        dependency('x11'),
+        dependency('xext'),
+        dependency('xdamage', version : '>= 1.1'),
+        dependency('xfixes'),
+        dependency('x11-xcb'),
+        dependency('xcb'),
+        dependency('xcb-glx', version : '>= 1.8.1'),
+      ]
+
+      dep_xf86vm = dependency('xf86vm', required : false)
+    endif
+    # TODO: XF86VIDMODE
+  endif
+  if with_glx != 'disabled'
+    dep_glproto = dependency('glproto', version : '>= 1.4.14')
+  endif
+  if with_any_vk or (with_glx == 'dri' and with_dri_platform == 'drm')
+    dep_xcb_dri2 = [
+      dependency('x11-xcb'),
+      dependency('xcb'),
+      dependency('xcb-dri2', version : '>= 1.8'),
+      dependency('xcb-xfixes'),
+    ]
+    if with_dri3
+      pre_args += '-DHAVE_DRI3'
+      dep_xcb_dri3 = [
+        dep_xcb_dri2,
+        dependency('xcb-dri3'),
+        dependency('xcb-present'),
+        dependency('xcb-sync'),
+        dependency('xshmfence', version : '>= 1.1'),
+      ]
+    endif
   endif
 endif
 
 # TODO: platforms for !vulkan
 
-# TODO: dri paths
-
-# TODO: dri drivers
-
 # TODO: osmesa
 
 # TODO: egl
diff --git a/meson_options.txt b/meson_options.txt
index f352f384c14..09adce02860 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -20,6 +20,8 @@
 
 option('platforms', type : 'string', value : 'x11,wayland',
        description : 'comma separated list of window systems to support. wayland, x11, surfaceless, drm, etc.')
+option('dri3', type : 'combo', value : 'auto', choices : ['auto', 'yes', 'no'],
+       description : 'enable support for dri3')
 option('dri-drivers', type : 'string', value : 'i965',
        description : 'comma separated list of dri drivers to build.')
 option('vulkan-drivers', type : 'string', value : 'intel,amd',
@@ -36,6 +38,10 @@ option('gles2', type : 'boolean', value : true,
        description : 'Build support for OpenGL ES 2.x and 3.x')
 option('opengl', type : 'boolean', value : true,
        description : 'Build support for OpenGL (all versions)')
+option('glx', type : 'combo', value : 'auto', choices : ['auto', 'disabled', 'dri', 'xlib', 'gallium-xlib'],
+       description : 'Build support for GLX platform')
+option('glvnd', type : 'boolean', value : false,
+       description : 'Enable GLVND support.')
 option('asm', type : 'boolean', value : true,
        description : 'Build assembly code if possible')
 option('valgrind', type : 'boolean', value : true,
diff --git a/src/glx/meson.build b/src/glx/meson.build
new file mode 100644
index 00000000000..ad9a559b908
--- /dev/null
+++ b/src/glx/meson.build
@@ -0,0 +1,185 @@
+# Copyright © 2017 Intel Corporation
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# TODO: 
+#subdir('windows')
+
+files_libglx = files(
+  'clientattrib.c',
+  'clientinfo.c',
+  'compsize.c',
+  'create_context.c',
+  'eval.c',
+  'glxclient.h',
+  'glxcmds.c',
+  'glxconfig.c',
+  'glxconfig.h',
+  'glxcurrent.c',
+  'glx_error.c',
+  'glx_error.h',
+  'glxext.c',
+  'glxextensions.c',
+  'glxextensions.h',
+  'glxhash.c',
+  'glxhash.h',
+  'glx_pbuffer.c',
+  'glx_query.c',
+  'indirect_glx.c',
+  'indirect_init.h',
+  'indirect_texture_compression.c',
+  'indirect_transpose_matrix.c',
+  'indirect_vertex_array.c',
+  'indirect_vertex_array.h',
+  'indirect_vertex_array_priv.h',
+  'indirect_vertex_program.c',
+  'indirect_window_pos.c',
+  'packrender.h',
+  'packsingle.h',
+  'pixel.c',
+  'pixelstore.c',
+  'query_renderer.c',
+  'render2.c',
+  'renderpix.c',
+  'single2.c',
+  'singlepix.c',
+  'vertarr.c',
+)
+
+extra_libs_libglx = []
+
+if with_dri
+  files_libglx += files(
+    'dri_common.c',
+    'dri_common.h',
+    'dri_common_query_renderer.c',
+    'dri_common_interop.c',
+    'xfont.c',
+    'drisw_glx.c',
+    'drisw_priv.h',
+  )
+endif
+
+# dri2
+if with_dri and with_dri_platform == 'drm' and dep_libdrm.found()
+  files_libglx += files(
+    'dri2.c',
+    'dri2_glx.c',
+    'dri2.h',
+    'dri2_priv.h',
+    'dri_glx.c',
+    'dri_sarea.h',
+    'XF86dri.c',
+    'xf86dri.h',
+    'xf86dristr.h',
+  )
+endif
+
+if with_dri3
+  files_libglx += files('dri3_glx.c', 'dri3_priv.h')
+endif
+
+if with_appledri
+  files_libglx += files('applegl_glx.c')
+elif with_windowsdri
+  files_libglx += files('driwindows_glx.c')
+  # TODO
+  #extra_libs_libglx += [
+    #libwindowsdri,
+    #libwindowsglx,
+  #]
+endif
+
+dri_driver_dir = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
+if not with_glvnd
+  gl_lib_name = 'GL'
+  gl_lib_version = '1.0'
+else
+  gl_lib_name = 'GLX_mesa'
+  gl_lib_version = '0'
+  files_libglx += files(
+    'g_glxglvnddispatchfuncs.c',
+    'g_glxglvnddispatchindices.h',
+    'glxglvnd.c',
+    'glxglvnd.h',
+    'glxglvnddispatchfuncs.h',
+  )
+endif
+
+gl_lib_cargs = [
+  '-D_REENTRANT', '-DDEFAULT_DRIVER_DIR="@0@"'.format(dri_driver_dir),
+]
+
+if dep_xf86vm != [] and dep_xf86vm.found()
+  gl_lib_cargs += '-DHAVE_XF86VIDMODE'
+endif
+
+libglx = static_library(
+  'glx',
+  [files_libglx, glx_generated],
+  include_directories : [
+    inc_common, inc_glapi, inc_loader,
+    include_directories('../../include/GL/internal'),
+  ],
+  c_args : [c_vis_args, gl_lib_cargs,
+            '-DGL_LIB_NAME="lib at 0@.so. at 1@"'.format(gl_lib_name, gl_lib_version)],
+  link_with : [libloader, libloader_dri3_helper, libmesa_util, libxmlconfig],
+  dependencies : [dep_libdrm, dep_dri2proto, dep_glproto, dep_x11, dep_glvnd],
+  build_by_default : false,
+)
+
+# workaround for bug #2180
+dummy_c = custom_target(
+  'dummy_c',
+  output : 'dummy.c',
+  command : [prog_touch, '@OUTPUT@'],
+)
+
+if with_glx == 'dri'
+  libgl = shared_library(
+    gl_lib_name,
+    dummy_c,  # workaround for bug #2180
+    include_directories : [
+      inc_common, inc_glapi, inc_loader,
+      include_directories('../../include/GL/internal'),
+    ],
+    link_with : [libglapi_static, libglapi],
+    link_whole : libglx,
+    link_args : [ld_args_bsymbolic, ld_args_gc_sections],
+    dependencies : [dep_libdrm, dep_dl, dep_m, dep_thread, dep_x11,
+                    dep_xcb_dri2, dep_xcb_dri3],
+    version : gl_lib_version,
+    install : true,
+  )
+
+  pkg.generate(
+    name : 'gl',
+    filebase : 'gl',
+    description : 'Mesa OpenGL Library',
+    version : meson.project_version(),
+    libraries : libgl,
+    variables : ['glx_tls=yes']
+    # TODO: libs.private
+    # TODO: requires.private
+  )
+endif
+
+if with_tests
+  subdir('tests')
+endif
diff --git a/include/meson.build b/src/glx/tests/meson.build
similarity index 55%
copy from include/meson.build
copy to src/glx/tests/meson.build
index beb57e3e044..d81b76906da 100644
--- a/include/meson.build
+++ b/src/glx/tests/meson.build
@@ -18,43 +18,32 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-inc_drm_uapi = include_directories('drm-uapi')
-inc_vulkan = include_directories('vulkan')
-
-if with_gles1
-  install_headers(
-    'GLES/egl.h', 'GLES/gl.h', 'GLES/glext.h', 'GLES/glplatform.h',
-    subdir : 'GLES',
-  )
-endif
-
-if with_gles2
-  install_headers(
-    'GLES2/gl2.h', 'GLES2/gl2ext.h', 'GLES2/gl2platform.h',
-    subdir : 'GLES2',
-  )
-  install_headers(
-    'GLES3/gl3.h', 'GLES3/gl32.h', 'GLES3/gl32.h', 'GLES3/gl3ext.h',
-    'GLES3/gl3platform.h',
-    subdir : 'GLES3',
+if with_shared_glapi
+  files_glx_test = files(
+    'clientinfo_unittest.cpp',
+    'create_context_unittest.cpp',
+    'enum_sizes.cpp',
+    'fake_glx_screen.cpp',
+    'fake_glx_screen.h',
+    'indirect_api.cpp',
+    'mock_xdisplay.h',
+    'query_renderer_unittest.cpp',
   )
-endif
-
-if with_gles1 or with_gles2 # or with_egl
-  install_headers('KHR/khrplatform.h', subdir : 'KHR')
-endif
-
-if with_opengl
-  install_headers(
-    'GL/gl.h', 'GL/glext.h', 'GL/glcorearb.h', 'GL/gl_mangle.h',
-    subdir : 'GL',
+  if with_dri2
+    files_glx_test += files('query_renderer_implementation_unittest.cpp')
+  endif
+
+  glx_test = executable(
+    'glx-test',
+    [files_glx_test, glx_indirect_size_h],
+    link_with : [libglx, libglapi],
+    include_directories : [
+      include_directories('..', '../../../include/GL/internal'),
+      inc_src, inc_include, inc_mesa, inc_mapi,
+    ],
+    dependencies : [dep_libdrm, dep_thread, idep_gtest]
   )
-endif
-
-if with_glx
-  install_headers('GL/glx.h', 'GL/glext.h', 'GL/glx_mangle.h', subdir : 'GL')
-endif
 
-if with_osmesa
-  install_headers('GL/osmesa.h', subdir : 'GL')
+  test('glx-test', glx_test)
+  test('glx-dispatch-index-check', find_program('dispatch-index-check'))
 endif
diff --git a/src/meson.build b/src/loader/meson.build
similarity index 55%
copy from src/meson.build
copy to src/loader/meson.build
index 8e0860bb5a5..425620372aa 100644
--- a/src/meson.build
+++ b/src/loader/meson.build
@@ -18,43 +18,27 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
-inc_common = include_directories(
-  '../include', '.', 'mapi', 'mesa', 'gallium/include', 'gallium/auxiliary')
-inc_mesa = include_directories('mesa')
-inc_mapi = include_directories('mapi')
-inc_src = include_directories('.')
+inc_loader = include_directories('.')
 
-libglsl_util = static_library(
-  'glsl_util',
-  files('mesa/main/extensions_table.c', 'mesa/main/imports.c',
-        'mesa/program/prog_parameter.c', 'mesa/program/symbol_table.c',
-        'mesa/program/dummy_errors.c'),
-  include_directories : [inc_common],
-  c_args : [c_vis_args],
-  build_by_default : false,
-)
+if with_platform_x11 and with_dri3
+  libloader_dri3_helper = static_library(
+    'loader_dri3_helper',
+    ['loader_dri3_helper.c', 'loader_dri3_helper.h'],
+    c_args : c_vis_args,
+    include_directories : inc_include,
+    dependencies : [dep_xcb_dri3, dep_libdrm],
+    build_by_default : false,
+  )
+else
+  libloader_dri3_helper = []
+endif
 
-sha1_h = vcs_tag(
-  input : 'git_sha1.h.in',
-  output : 'git_sha1.h',
+libloader = static_library(
+  'loader',
+  ['loader.c', 'loader.h', 'pci_id_driver_map.c', 'pci_id_driver_map.h',
+   xmlpool_options_h],
+  c_args : [c_vis_args, '-DUSE_DRICONF'],
+  include_directories : [inc_include, inc_src, inc_util],
+  dependencies : dep_libdrm,
+  build_by_default : false,
 )
-
-subdir('gtest')
-subdir('util')
-subdir('mapi/glapi/gen')
-subdir('mapi')
-# TODO: opengl
-# TODO: glx
-# TODO: osmesa
-subdir('compiler')
-subdir('egl/wayland/wayland-drm')
-subdir('vulkan')
-subdir('amd')
-subdir('intel')
-# TODO: vc4
-subdir('mesa')
-# TODO: dri_glx
-# TODO: gbm
-# TODO: egl
-# TODO: radv
-# TODO: gallium
diff --git a/src/mapi/glapi/meson.build b/src/mapi/glapi/meson.build
index d09cf94e36f..d3e070d0d1a 100644
--- a/src/mapi/glapi/meson.build
+++ b/src/mapi/glapi/meson.build
@@ -18,6 +18,8 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+inc_glapi = include_directories('.')
+
 static_glapi_files = []
 static_glapi_args = []
 
diff --git a/src/meson.build b/src/meson.build
index 8e0860bb5a5..f49ad9e0e7e 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -44,7 +44,6 @@ subdir('util')
 subdir('mapi/glapi/gen')
 subdir('mapi')
 # TODO: opengl
-# TODO: glx
 # TODO: osmesa
 subdir('compiler')
 subdir('egl/wayland/wayland-drm')
@@ -53,8 +52,8 @@ subdir('amd')
 subdir('intel')
 # TODO: vc4
 subdir('mesa')
+subdir('loader')
+subdir('glx')
 # TODO: dri_glx
-# TODO: gbm
 # TODO: egl
-# TODO: radv
 # TODO: gallium
-- 
2.14.1



More information about the mesa-dev mailing list