diff mbox series

[9/9] package/mesa3d: add experimental RustiCL support

Message ID 20230725135105.536310-10-sebastian.weyer@smile.fr
State Superseded
Headers show
Series Add support for Rusticl in mesa3d | expand

Commit Message

Sebastian Weyer July 25, 2023, 1:51 p.m. UTC
From: Romain Naour <romain.naour@smile.fr>

To build Rusticl you need to satisfy the following build dependencies:

    rustc
    rustfmt (highly recommended, but only required for CI builds or when authoring patches)
    bindgen
    LLVM built with libclc and -DLLVM_ENABLE_DUMP=ON.
    SPIRV-Tools
    SPIRV-LLVM-Translator for a libLLVMSPIRVLib.so matching your version of LLVM, i.e. if you’re using LLVM 15 (libLLVM.so.15), then you need a libLLVMSPIRVLib.so.15.

See:
https://docs.mesa3d.org/rusticl.html

Since rusticl is an implementation of OpenCL, make it a provider of
OpenCL.

We need to use opencl-icd-loader in order to be able to capture API
calls and forward them to the correct implementation of OpenCL (RustiCL
in this case)

opencl-icd-loader needs to be installed in the toolchain's sysroot
as well to be able to compile packages depending on libopencl since
otherwise there's only for example libRustiOpenCL.so and no
libOpenCL.so

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Sebastian Weyer <sebastian.weyer@smile.fr>
---
 package/mesa3d/Config.in | 19 ++++++++++++++++++-
 package/mesa3d/mesa3d.mk | 20 +++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/package/mesa3d/Config.in b/package/mesa3d/Config.in
index c7ee2a8db0..4c725709d1 100644
--- a/package/mesa3d/Config.in
+++ b/package/mesa3d/Config.in
@@ -56,6 +56,23 @@  config BR2_PACKAGE_MESA3D_OPENCL
 	select BR2_PACKAGE_LIBCLC
 	select BR2_PACKAGE_HAS_LIBOPENCL
 
+# libclc dependencies are satisfied by
+# BR2_PACKAGE_MESA3D_LLVM
+config BR2_PACKAGE_MESA3D_RUSTICL
+	bool "RustiCL (OpenCL) support"
+	depends on BR2_PACKAGE_MESA3D_LLVM
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+	depends on BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_PANFROST
+	select BR2_PACKAGE_HOST_RUSTC
+	select BR2_PACKAGE_LLVM_RTTI
+	select BR2_PACKAGE_CLANG
+	select BR2_PACKAGE_LLVM_DUMP
+	select BR2_PACKAGE_LIBCLC
+	select BR2_PACKAGE_SPIRV_TOOLS
+	select BR2_PACKAGE_SPIRV_LLVM_TRANSLATOR
+	select BR2_PACKAGE_HAS_LIBOPENCL
+	select BR2_PACKAGE_OPENCL_ICD_LOADER
+
 # inform the .mk file of gallium, dri, dri3 or vulkan driver selection
 config BR2_PACKAGE_MESA3D_DRI3
 	bool
@@ -387,7 +404,7 @@  config BR2_PACKAGE_PROVIDES_LIBGLES
 	default "mesa3d" if BR2_PACKAGE_MESA3D_OPENGL_ES && !BR2_PACKAGE_LIBGLVND
 
 config BR2_PACKAGE_PROVIDES_LIBOPENCL
-	default "mesa3d" if BR2_PACKAGE_MESA3D_OPENCL
+	default "mesa3d" if BR2_PACKAGE_MESA3D_OPENCL || BR2_PACKAGE_MESA3D_RUSTICL
 
 endif # BR2_PACKAGE_MESA3D
 
diff --git a/package/mesa3d/mesa3d.mk b/package/mesa3d/mesa3d.mk
index 6fa5c1c686..3c7d919bb7 100644
--- a/package/mesa3d/mesa3d.mk
+++ b/package/mesa3d/mesa3d.mk
@@ -58,16 +58,34 @@  else
 MESA3D_CONF_OPTS += -Dllvm=disabled
 endif
 
-# Disable opencl-icd: OpenCL lib will be named libOpenCL instead of
 # libMesaOpenCL and CL headers are installed
 ifeq ($(BR2_PACKAGE_MESA3D_OPENCL),y)
 MESA3D_PROVIDES += libopencl
 MESA3D_DEPENDENCIES += clang libclc
+ifeq ($(BR2_PACKAGE_OPENCL_ICD_LOADER),y)
+MESA3D_CONF_OPTS += -Dgallium-opencl=icd
+MESA3D_DEPENDENCIES +=  opencl-icd-loader
+# Disable opencl-icd: OpenCL lib will be named libOpenCL instead of
+else
 MESA3D_CONF_OPTS += -Dgallium-opencl=standalone
+endif
 else
 MESA3D_CONF_OPTS += -Dgallium-opencl=disabled
 endif
 
+# -Drust_std=2021: known meson bug (https://github.com/mesonbuild/meson/issues/10664)
+#  By default devices are disabled in rusticl. If you want to enable a device,
+#  you need to set the environment variable RUSTICL_ENABLE to the driver you
+#  are using
+#  ref: https://docs.mesa3d.org/envvars.html#envvar-RUSTICL_ENABLE
+ifeq ($(BR2_PACKAGE_MESA3D_RUSTICL),y)
+MESA3D_PROVIDES += libopencl
+MESA3D_DEPENDENCIES += host-rustc host-rust-bindgen clang libclc opencl-icd-loader spirv-tools spirv-llvm-translator
+MESA3D_CONF_OPTS += -Dgallium-rusticl=true -Drust_std=2021
+else
+MESA3D_CONF_OPTS += -Dgallium-rusticl=false
+endif
+
 ifeq ($(BR2_PACKAGE_MESA3D_NEEDS_ELFUTILS),y)
 MESA3D_DEPENDENCIES += elfutils
 endif