[Mesa-dev] [PATCH 2/6] meson: build glx

Dylan Baker dylan at pnwbakers.com
Wed Oct 4 00:26:45 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.

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 include/meson.build            |   2 +-
 meson.build                    | 179 +++++++++++++++++++++++++++++----------
 meson_options.txt              |   6 ++
 src/compiler/nir/meson.build   |   1 +
 src/glx/meson.build            | 184 +++++++++++++++++++++++++++++++++++++++++
 src/{ => loader}/meson.build   |  56 +++++--------
 src/mapi/glapi/gen/meson.build |   5 +-
 src/mapi/glapi/meson.build     |   2 +
 src/meson.build                |   5 +-
 9 files changed, 353 insertions(+), 87 deletions(-)
 create mode 100644 src/glx/meson.build
 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 1824a7ea184..52ac24f59ca 100644
--- a/meson.build
+++ b/meson.build
@@ -21,7 +21,18 @@
 project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
         default_options : ['c_std=c99', 'cpp_std=c++11'])
 
-with_dri3 = true  # XXX: need a switch for this
+# Arguments for the preprocessor, put these in a separate array from the C and
+# C++ (cpp in meson terminology) arguments since they need to be added to the
+# default arguments for both C and C++.
+pre_args = [
+  '-D__STDC_CONSTANT_MACROS',
+  '-D__STDC_FORMAT_MACROS',
+  '-D__STDC_LIMIT_MACROS',
+  '-DVERSION="@0@"'.format(meson.project_version()),
+  '-DPACKAGE_VERSION=VERSION',
+  '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
+]
+
 with_vulkan_icd_dir = get_option('vulkan-icd-dir')
 with_tests = get_option('build-tests')
 with_valgrind = get_option('valgrind')
@@ -35,11 +46,24 @@ 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
+
+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: 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
@@ -72,6 +96,12 @@ if not with_dri
   with_shared_glapi = false
 endif
 
+# TODO: other OSes
+with_dri_platform = 'drm'
+
+with_gallium = false
+# TODO: gallium drivers
+
 # TODO: there are more platforms required for non-vulkan drivers
 with_platform_wayland = false
 with_platform_x11 = false
@@ -82,20 +112,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 not with_platform_x11 and 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')
@@ -109,18 +184,6 @@ if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
   error('When using GCC, version 4.4.6 or later is required.')
 endif
 
-# Arguments for the preprocessor, put these in a separate array from the C and
-# C++ (cpp in meson terminology) arguments since they need to be added to the
-# default arguments for both C and C++.
-pre_args = [
-  '-D__STDC_CONSTANT_MACROS',
-  '-D__STDC_FORMAT_MACROS',
-  '-D__STDC_LIMIT_MACROS',
-  '-DVERSION="@0@"'.format(meson.project_version()),
-  '-DPACKAGE_VERSION=VERSION',
-  '-DPACKAGE_BUGREPORT="https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa"',
-]
-
 # Define DEBUG for debug and debugoptimized builds
 if get_option('buildtype').startswith('debug')
   pre_args += '-DDEBUG'
@@ -411,6 +474,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
@@ -443,18 +512,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
@@ -471,32 +530,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 568903f1a0a..62d6b593f88 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 : 'comma separated list of window systems to support. wayland, x11, surfaceless, drm, etc.')
 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', vaule : false,
+       description : 'Enable GLVND support.')
 option('asm',            type : 'boolean', value : true,
        description : 'Build assembly code if possible')
 option('valgrind',       type : 'boolean', vaule : true,
diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build
index 8a85d119530..faa69e3aa30 100644
--- a/src/compiler/nir/meson.build
+++ b/src/compiler/nir/meson.build
@@ -90,6 +90,7 @@ files_libnir = files(
   'nir_instr_set.h',
   'nir_intrinsics.c',
   'nir_intrinsics.h',
+  'nir_linking_helpers.c',
   'nir_liveness.c',
   'nir_loop_analyze.c',
   'nir_loop_analyze.h',
diff --git a/src/glx/meson.build b/src/glx/meson.build
new file mode 100644
index 00000000000..821623dc263
--- /dev/null
+++ b/src/glx/meson.build
@@ -0,0 +1,184 @@
+# 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
+
+# TODO: libglvnd
+
+dri_driver_dir = join_paths(get_option('prefix'), get_option('libdir'), 'dri')
+if not with_glvnd
+  gl_lib_name = 'GL'
+  gl_lib_version = '1.2'
+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_RENTRANT', '-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_indirect_c, glx_indirect_h, glx_indirect_init_c,
+   glx_indirect_size_c, glx_indirect_size_h],
+  include_directories : [
+    inc_common, inc_glapi,
+    include_directories('../loader', '../../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, 
+      include_directories('../loader', '../../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
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..2c2af7a3d59 100644
--- a/src/meson.build
+++ b/src/loader/meson.build
@@ -18,43 +18,25 @@
 # 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('.')
+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
 
-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],
+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,
 )
-
-sha1_h = vcs_tag(
-  input : 'git_sha1.h.in',
-  output : 'git_sha1.h',
-)
-
-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/gen/meson.build b/src/mapi/glapi/gen/meson.build
index f4c1343202c..cf1f014b4f0 100644
--- a/src/mapi/glapi/gen/meson.build
+++ b/src/mapi/glapi/gen/meson.build
@@ -247,7 +247,7 @@ glx_indirect_size_h = custom_target(
   input : ['glX_proto_size.py', 'gl_API.xml'],
   output : 'indirect_size.h',
   command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'size_h',
-             '--header-tag', '_INDIRECT_SIZE_H_'],
+             '--header-tag', '_INDIRECT_SIZE_H_', '--only-set'],
   depend_files : glx_gen_depends,
   capture : true,
 )
@@ -256,7 +256,8 @@ glx_indirect_size_c = custom_target(
   'indirect_size.c',
   input : ['glX_proto_size.py', 'gl_API.xml'],
   output : 'indirect_size.c',
-  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'size_c'],
+  command : [prog_python2, '@INPUT0@', '-f', '@INPUT1@', '-m', 'size_c',
+             '--only-set'],
   depend_files : glx_gen_depends,
   capture : true,
 )
diff --git a/src/mapi/glapi/meson.build b/src/mapi/glapi/meson.build
index 3312cc18ac5..abc4dba14ed 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