refer to:
https://github.com/XpressReal/linux/tree/v6.6.54-xpressreal-t3
https://android.googlesource.com/kernel/amlogic-tv-modules/mali-driver/+/refs/tags/android-tv-10.0.0_r0.1/bifrost
------linux 5.10------
1.
https://github.com/XpressReal/linux/blob/v6.6.54-xpressreal-t3/arch/arm64/boot/dts/realtek/rtd16xxb.dtsi
# rtd16xxb.dtsi, add
gpu-wrap@1d0000 {
reg = <0x1d0000 0x4000>,
<0x1d6000 0x1000>;
reg-names = "ip", "bist";
compatible = "realtek,rtd1619b-gpu-wrap";
clocks = <&cc RTD1619B_CRT_CLK_GPU>;
resets = <&cc RTD1619B_CRT_RSTN_GPU>, <&cc RTD1619B_CRT_RSTN_GPU_BIST>;
reset-names = "core", "bist";
power-domains = <&pwr_gpu>;
nvmem-cells = <&otp_bist_rst_ctrl>;
nvmem-cell-names = "bist_rst_ctrl";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x0 0x1d0000 0x20000>;
assigned-clocks = <&cc RTD1619B_CRT_PLL_GPU>;
assigned-clock-rates = <702000000>;
gpu: gpu@0 {
compatible = "arm,mali-valhall-jm";
reg = <0x0 0x4000>;
interrupts = <GIC_SPI 76 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 77 IRQ_TYPE_LEVEL_HIGH>,
<GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>;
interrupt-names = "job", "mmu", "gpu";
clocks = <&cc RTD1619B_CRT_CLK_GPU>;
clock-names = "clk_mali";
mali-supply = <&gpu_supp>;
status = "okay";
operating-points-v2 = <&gpu_opps>;
gpu_opps: opp-table-gpu {
compatible = "operating-points-v2",
"operating-points-v2-mali";
opp-450000000 {
opp-hz = /bits/ 64 <450000000>;
opp-hz-real = /bits/ 64 <450000000>;
opp-microvolt = <800000>;
opp-suspend;
};
opp-550000000 {
opp-hz = /bits/ 64 <550000000>;
opp-hz-real = /bits/ 64 <550000000>;
opp-microvolt = <800000>;
};
opp-650000000 {
opp-hz = /bits/ 64 <650000000>;
opp-hz-real = /bits/ 64 <650000000>;
opp-microvolt = <800000>;
};
opp-702000000 {
opp-hz = /bits/ 64 <702000000>;
opp-hz-real = /bits/ 64 <702000000>;
opp-microvolt = <800000>;
};
};
power_model {
compatible = "arm,mali-simple-power-model";
static-coefficient = <0>;
dynamic-coefficient = <0>;
ts = <0 0 0 0>;
thermal-zone = "";
};
};
};
gpu_supp: gpu-supply {
compatible = "regulator-fixed";
regulator-name = "gpu-supply";
regulator-min-microvolt = <800000>;
regulator-max-microvolt = <800000>;
};
#note: pwr_gpu: power-gpu use your default
2.
~/linux-5.10.x/drivers/soc/realtek/Makefile
#add
obj-y += gpu/
3.
~/source/linux-5.10.x/drivers/soc/realtek/Kconfig
#add
source "drivers/soc/realtek/gpu/Kconfig"
4.
https://github.com/XpressReal/linux/tree/v6.6.54-xpressreal-t3/drivers/soc/realtek/gpu
#or mirror
https://www.mediafire.com/file/pixjbe1zzo9u9mf/gpu.zip/file
#all source to copy
~/linux-5.10.x/drivers/soc/realtek/gpu
5.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_device.h
static inline int panfrost_model_cmp(struct panfrost_device *pfdev, s32 id)
{
s32 match_id = pfdev->features.id;
//by stone
if (match_id == 0x9091 && id == 0x9091)
return 0;
if (match_id & 0xf000)
match_id &= 0xf00f;
return match_id - id;
}
6.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_drv.c
static const struct of_device_id dt_match[] = {
/* Set first to probe before the generic compatibles */
{ .compatible = "amlogic,meson-gxm-mali",
.data = &amlogic_data, },
{ .compatible = "amlogic,meson-g12a-mali",
.data = &amlogic_data, },
{ .compatible = "arm,mali-t604", .data = &default_data, },
{ .compatible = "arm,mali-t624", .data = &default_data, },
{ .compatible = "arm,mali-t628", .data = &default_data, },
{ .compatible = "arm,mali-t720", .data = &default_data, },
{ .compatible = "arm,mali-t760", .data = &default_data, },
{ .compatible = "arm,mali-t820", .data = &default_data, },
{ .compatible = "arm,mali-t830", .data = &default_data, },
{ .compatible = "arm,mali-t860", .data = &default_data, },
{ .compatible = "arm,mali-t880", .data = &default_data, },
{ .compatible = "arm,mali-bifrost", .data = &default_data, },
{ .compatible = "arm,mali-valhall-jm", .data = &default_data, }, //by stone
{}
};
7.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_features.h
...
HW_FEATURE_THREAD_GROUP_SPLIT,
//by stone
HW_FEATURE_IDVS_GROUP_SIZE,
HW_FEATURE_3BIT_EXT_RW_L2_MMU_CONFIG,
...
//by stone
#define hw_features_g57 (\
BIT_ULL(HW_FEATURE_JOBCHAIN_DISAMBIGUATION) | \
BIT_ULL(HW_FEATURE_PWRON_DURING_PWROFF_TRANS) | \
BIT_ULL(HW_FEATURE_XAFFINITY) | \
BIT_ULL(HW_FEATURE_WARPING) | \
BIT_ULL(HW_FEATURE_INTERPIPE_REG_ALIASING) | \
BIT_ULL(HW_FEATURE_32_BIT_UNIFORM_ADDRESS) | \
BIT_ULL(HW_FEATURE_ATTR_AUTO_TYPE_INFERRAL) | \
BIT_ULL(HW_FEATURE_BRNDOUT_CC) | \
BIT_ULL(HW_FEATURE_BRNDOUT_KILL) | \
BIT_ULL(HW_FEATURE_LD_ST_LEA_TEX) | \
BIT_ULL(HW_FEATURE_LD_ST_TILEBUFFER) | \
BIT_ULL(HW_FEATURE_LINEAR_FILTER_FLOAT) | \
BIT_ULL(HW_FEATURE_MRT) | \
BIT_ULL(HW_FEATURE_MSAA_16X) | \
BIT_ULL(HW_FEATURE_NEXT_INSTRUCTION_TYPE) | \
BIT_ULL(HW_FEATURE_OUT_OF_ORDER_EXEC) | \
BIT_ULL(HW_FEATURE_T7XX_PAIRING_RULES) | \
BIT_ULL(HW_FEATURE_TEST4_DATUM_MODE) | \
BIT_ULL(HW_FEATURE_FLUSH_REDUCTION) | \
BIT_ULL(HW_FEATURE_PROTECTED_MODE) | \
BIT_ULL(HW_FEATURE_PROTECTED_DEBUG_MODE) | \
BIT_ULL(HW_FEATURE_COHERENCY_REG) | \
BIT_ULL(HW_FEATURE_AARCH64_MMU) | \
BIT_ULL(HW_FEATURE_IDVS_GROUP_SIZE))
8.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_issues.h
...
HW_ISSUE_TGOX_R1_1234,
/* Must set SC_VAR_ALGORITHM, by stone */
HW_ISSUE_TTRX_2968_TTRX_3162,
HW_ISSUE_END
...
//by stone
#define hw_issues_g57 (\
BIT_ULL(HW_ISSUE_TTRX_2968_TTRX_3162))
#define hw_issues_g57_r0p1 0
9.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_regs.h
/* SHADER_CONFIG register */
#define SC_ALT_COUNTERS BIT(3)
#define SC_OVERRIDE_FWD_PIXEL_KILL BIT(4)
#define SC_SDC_DISABLE_OQ_DISCARD BIT(6)
#define SC_LS_ALLOW_ATTR_TYPES BIT(16)
#define SC_LS_PAUSEBUFFER_DISABLE BIT(16)
#define SC_TLS_HASH_ENABLE BIT(17)
#define SC_LS_ATTR_CHECK_DISABLE BIT(18)
#define SC_ENABLE_TEXGRD_FLAGS BIT(25)
//by stone
#define SC_VAR_ALGORITHM BIT(29)
/* End SHADER_CONFIG register */
...
#define JM_IDVS_GROUP_SIZE_SHIFT 16
//by stone
#define JM_DEFAULT_IDVS_GROUP_SIZE 0xF
#define JM_MAX_IDVS_GROUP_SIZE 0x3F
...
10.
~/linux-5.10.x/drivers/gpu/drm/panfrost/panfrost_gpu.c
static void panfrost_gpu_init_quirks(struct panfrost_device *pfdev)
{
u32 quirks = 0;
if (panfrost_has_hw_issue(pfdev, HW_ISSUE_8443) ||
panfrost_has_hw_issue(pfdev, HW_ISSUE_11035))
quirks |= SC_LS_PAUSEBUFFER_DISABLE;
if (panfrost_has_hw_issue(pfdev, HW_ISSUE_10327))
quirks |= SC_SDC_DISABLE_OQ_DISCARD;
if (panfrost_has_hw_issue(pfdev, HW_ISSUE_10797))
quirks |= SC_ENABLE_TEXGRD_FLAGS;
if (!panfrost_has_hw_issue(pfdev, GPUCORE_1619)) {
if (panfrost_model_cmp(pfdev, 0x750) < 0) /* T60x, T62x, T72x */
quirks |= SC_LS_ATTR_CHECK_DISABLE;
else if (panfrost_model_cmp(pfdev, 0x880) <= 0) /* T76x, T8xx */
quirks |= SC_LS_ALLOW_ATTR_TYPES;
}
//by stone
if (panfrost_has_hw_issue(pfdev, HW_ISSUE_TTRX_2968_TTRX_3162))
quirks |= SC_VAR_ALGORITHM;
if (panfrost_has_hw_feature(pfdev, HW_FEATURE_TLS_HASHING))
quirks |= SC_TLS_HASH_ENABLE;
if (quirks)
gpu_write(pfdev, GPU_SHADER_CONFIG, quirks);
quirks = gpu_read(pfdev, GPU_TILER_CONFIG);
/* Set tiler clock gate override if required */
if (panfrost_has_hw_issue(pfdev, HW_ISSUE_T76X_3953))
quirks |= TC_CLOCK_GATE_OVERRIDE;
gpu_write(pfdev, GPU_TILER_CONFIG, quirks);
quirks = gpu_read(pfdev, GPU_L2_MMU_CONFIG);
/* Limit read & write ID width for AXI */
if (panfrost_has_hw_feature(pfdev, HW_FEATURE_3BIT_EXT_RW_L2_MMU_CONFIG))
quirks &= ~(L2_MMU_CONFIG_3BIT_LIMIT_EXTERNAL_READS |
L2_MMU_CONFIG_3BIT_LIMIT_EXTERNAL_WRITES);
else
quirks &= ~(L2_MMU_CONFIG_LIMIT_EXTERNAL_READS |
L2_MMU_CONFIG_LIMIT_EXTERNAL_WRITES);
gpu_write(pfdev, GPU_L2_MMU_CONFIG, quirks);
quirks = 0;
if ((panfrost_model_eq(pfdev, 0x860) || panfrost_model_eq(pfdev, 0x880)) &&
pfdev->features.revision >= 0x2000)
quirks |= JM_MAX_JOB_THROTTLE_LIMIT << JM_JOB_THROTTLE_LIMIT_SHIFT;
else if (panfrost_model_eq(pfdev, 0x6000) &&
pfdev->features.coherency_features == COHERENCY_ACE)
quirks |= (COHERENCY_ACE_LITE | COHERENCY_ACE) <<
JM_FORCE_COHERENCY_FEATURES_SHIFT;
//by stone
if (panfrost_has_hw_feature(pfdev, HW_FEATURE_IDVS_GROUP_SIZE))
quirks |= JM_DEFAULT_IDVS_GROUP_SIZE << JM_IDVS_GROUP_SIZE_SHIFT;
if (quirks)
gpu_write(pfdev, GPU_JM_CONFIG, quirks);
/* Here goes platform specific quirks */
if (pfdev->comp->vendor_quirk)
pfdev->comp->vendor_quirk(pfdev);
}
static const struct panfrost_model gpu_models[] = {
/* T60x has an oddball version */
GPU_MODEL(t600, 0x600,
GPU_REV_EXT(t600, 0, 0, 1, _15dev0)),
GPU_MODEL(t620, 0x620,
GPU_REV(t620, 0, 1), GPU_REV(t620, 1, 0)),
GPU_MODEL(t720, 0x720),
GPU_MODEL(t760, 0x750,
GPU_REV(t760, 0, 0), GPU_REV(t760, 0, 1),
GPU_REV_EXT(t760, 0, 1, 0, _50rel0),
GPU_REV(t760, 0, 2), GPU_REV(t760, 0, 3)),
GPU_MODEL(t820, 0x820),
GPU_MODEL(t830, 0x830),
GPU_MODEL(t860, 0x860),
GPU_MODEL(t880, 0x880),
GPU_MODEL(g71, 0x6000,
GPU_REV_EXT(g71, 0, 0, 1, _05dev0)),
GPU_MODEL(g72, 0x6001),
GPU_MODEL(g51, 0x7000),
GPU_MODEL(g76, 0x7001),
GPU_MODEL(g52, 0x7002),
/* Realtek RTD1619B Mali-G57 (Stone fix for 5.10),by stone */
GPU_MODEL(g57, 0x9091,
GPU_REV(g57, 0, 1)),
GPU_MODEL(g31, 0x7003,
GPU_REV(g31, 1, 0)),
};
11. linux 5.10.x default config
#add
CONFIG_DEVFREQ_THERMAL=y
CONFIG_REGULATOR_FIXED_VOLTAGE=y
#
# Graphics support
#
# CONFIG_VGA_ARB is not set
CONFIG_DRM=y
# CONFIG_DRM_DP_AUX_CHARDEV is not set
# CONFIG_DRM_DEBUG_MM is not set
# CONFIG_DRM_DEBUG_SELFTEST is not set
# CONFIG_DRM_FBDEV_EMULATION is not set
# CONFIG_DRM_LOAD_EDID_FIRMWARE is not set
# CONFIG_DRM_DP_CEC is not set
CONFIG_DRM_GEM_SHMEM_HELPER=y
CONFIG_DRM_SCHED=y
#
# ARM devices
#
# CONFIG_DRM_HDLCD is not set
# CONFIG_DRM_MALI_DISPLAY is not set
# CONFIG_DRM_KOMEDA is not set
# end of ARM devices
# CONFIG_DRM_RADEON is not set
# CONFIG_DRM_AMDGPU is not set
# CONFIG_DRM_NOUVEAU is not set
# CONFIG_DRM_VGEM is not set
# CONFIG_DRM_VKMS is not set
# CONFIG_DRM_UDL is not set
# CONFIG_DRM_AST is not set
# CONFIG_DRM_MGAG200 is not set
# CONFIG_DRM_RCAR_DW_HDMI is not set
# CONFIG_DRM_RCAR_LVDS is not set
# CONFIG_DRM_QXL is not set
# CONFIG_DRM_BOCHS is not set
CONFIG_DRM_BRIDGE=y
#
# Display Interface Bridges
#
# CONFIG_DRM_CDNS_DSI is not set
# CONFIG_DRM_CHRONTEL_CH7033 is not set
# CONFIG_DRM_DISPLAY_CONNECTOR is not set
# CONFIG_DRM_LONTIUM_LT9611 is not set
# CONFIG_DRM_LVDS_CODEC is not set
# CONFIG_DRM_MEGACHIPS_STDPXXXX_GE_B850V3_FW is not set
# CONFIG_DRM_NWL_MIPI_DSI is not set
# CONFIG_DRM_NXP_PTN3460 is not set
# CONFIG_DRM_PARADE_PS8622 is not set
# CONFIG_DRM_PARADE_PS8640 is not set
# CONFIG_DRM_SIL_SII8620 is not set
# CONFIG_DRM_SII902X is not set
# CONFIG_DRM_SII9234 is not set
# CONFIG_DRM_SIMPLE_BRIDGE is not set
# CONFIG_DRM_THINE_THC63LVD1024 is not set
# CONFIG_DRM_TOSHIBA_TC358762 is not set
# CONFIG_DRM_TOSHIBA_TC358764 is not set
# CONFIG_DRM_TOSHIBA_TC358767 is not set
# CONFIG_DRM_TOSHIBA_TC358768 is not set
# CONFIG_DRM_TOSHIBA_TC358775 is not set
# CONFIG_DRM_TI_TFP410 is not set
# CONFIG_DRM_TI_SN65DSI86 is not set
# CONFIG_DRM_TI_TPD12S015 is not set
# CONFIG_DRM_ANALOGIX_ANX6345 is not set
# CONFIG_DRM_ANALOGIX_ANX78XX is not set
# CONFIG_DRM_I2C_ADV7511 is not set
# CONFIG_DRM_CDNS_MHDP8546 is not set
# end of Display Interface Bridges
# CONFIG_DRM_ETNAVIV is not set
# CONFIG_DRM_ARCPGU is not set
# CONFIG_DRM_HISI_HIBMC is not set
# CONFIG_DRM_HISI_KIRIN is not set
# CONFIG_DRM_MXSFB is not set
# CONFIG_DRM_CIRRUS_QEMU is not set
# CONFIG_DRM_GM12U320 is not set
# CONFIG_DRM_PL111 is not set
# CONFIG_DRM_LIMA is not set
# CONFIG_DRM_TIDSS is not set
# CONFIG_DRM_LEGACY is not set
CONFIG_DRM_PANFROST=y
CONFIG_DRM_PANEL_ORIENTATION_QUIRKS=y
#
# DMABUF options
#
CONFIG_SYNC_FILE=y
# CONFIG_SW_SYNC is not set
# CONFIG_MAILBOX is not set
CONFIG_IOMMU_API=y
CONFIG_IOMMU_SUPPORT=y
# CONFIG_IOMMU_IO_PGTABLE_LPAE_SELFTEST is not set
# CONFIG_IOMMU_IO_PGTABLE_ARMV7S is not set
# CONFIG_IOMMU_DEBUGFS is not set
# CONFIG_IOMMU_DEFAULT_PASSTHROUGH is not set
# CONFIG_ARM_SMMU is not set
# CONFIG_ARM_SMMU_V3 is not set
CONFIG_OF_IOMMU=y
CONFIG_IOMMU_DMA=y
CONFIG_RTK_INFO_PLL=y
CONFIG_RTK_CPU_VOLT_SEL=y
CONFIG_RTK_BUFLOCK=y
CONFIG_RTK_GPU_WRAP=y
CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND=y
CONFIG_CRYPTO_LZO=m
12. after kernel boot
root@AS3304Tv2-B77E:/volume1 # dmesg | grep panfrost
[ 12.765142] panfrost 981d0000.gpu: clock rate = 702000000
[ 12.771025] panfrost 981d0000.gpu: mali-g57 id 0x9091 major 0x0 minor 0x1 status 0x0
[ 12.778765] panfrost 981d0000.gpu: features: 00000000,27de77ff, issues: 00000000,80000400
[ 12.786932] panfrost 981d0000.gpu: Features: L2:0x07100206 Shader:0x00000000 Tiler:0x00000809 Mem:0x1 MMU:0x00002830 AS:0xff JS:0x7
[ 12.798742] panfrost 981d0000.gpu: shader_present=0x1 l2_present=0x1
[ 12.805940] [drm] Initialized panfrost 1.1.0 20180908 for 981d0000.gpu on minor 0
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~mesa-24.3.4 GLES2 Vulkan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. ubuntu 24.04 preinstall
sudo apt install libzstd-dev libxml2-dev libexpat-dev rustup
sudo pip3 install --force-reinstall --upgrade --break-system-packages --target=/usr/lib/python3/dist-packages lxml rnc2rng
rustup target add aarch64-unknown-linux-gnu
rustup component add rustfmt
cargo install bindgen-cli --version 0.71.1
ln -sf /root/.cargo/bin/bindgen /usr/bin/bindgen
2.
cross compile need arm64 base libs, libdrm(2.4.120) libexpat libzstd libz, pre-install them in your lib directory
3.
#if gles2 only, use mesa-24.3.4 is faster
git clone --depth 1 -b mesa-24.3.4 https://gitlab.freedesktop.org/mesa/mesa.git
#or
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
git checkout -B mesa-24.3.4-work mesa-24.3.4
4.
gedit /root/mesa/meson.build
# by stone
#dep_elf = dependency('libelf', required : false)
dep_elf = dependency('', required : false)
5.
gedit /root/mesa/mesa_crossfile.ini
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
[properties]
sys_root = '/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot'
[constants]
cross_compile = '/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-'
[binaries]
c = cross_compile + 'gcc'
cpp = cross_compile + 'g++'
ar = cross_compile + 'ar'
ld = cross_compile + 'ld'
strip = cross_compile + 'strip'
nm = cross_compile + 'nm'
objdump = cross_compile + 'objdump'
readelf = cross_compile + 'readelf'
pkgconfig = '/usr/bin/pkg-config'
rust = ['rustc', '--target', 'aarch64-unknown-linux-gnu']
[built-in options]
c_args
= ['-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/include',
'-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/include',
'-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/include',
'-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/include/libdrm',
'-mcpu=cortex-a55+crypto']
cpp_args = c_args
c_link_args =
['-L/root/project_arm64rt2_debug/arm64rt2/staging/lib',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/lib64',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib64',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib64',
'-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/lib',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/lib64',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib64',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib64',
'-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib']
cpp_link_args = c_link_args
# https://www.mediafire.com/file/2b5qvaedngv7cq9/mesa_crossfile.ini/file
6.
ln -sf /opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot/lib/ld-linux-aarch64.so.1 /lib/
export LD_LIBRARY_PATH=/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot/lib
cd mesa
meson setup build . \
--cross-file /root/mesa/mesa_crossfile.ini \
--prefix=/opt/mesa \
--buildtype=release \
-Dgallium-drivers=panfrost \
-Dgallium-va=disabled \
-Dgallium-rusticl=false \
-Dvulkan-drivers= \
-Dplatforms= \
-Degl-native-platform=surfaceless \
-Dgles1=disabled \
-Dgles2=enabled \
-Degl=enabled \
-Dgbm=enabled \
-Dglx=disabled \
-Dglvnd=disabled \
-Dllvm=disabled \
-Dlibunwind=disabled
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/mesa/build -j$CPU_NUM
ninja -C /root/mesa/build install
7.
#if vulkan only, use mesa-24.3.4
git clone --depth 1 -b mesa-24.3.4 https://gitlab.freedesktop.org/mesa/mesa.git
#or
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
git checkout -B mesa-24.3.4-work mesa-24.3.4
#vulkan still not support mali-g57 mali version 9 like 0x9001 0x9003
meson setup build . \
--cross-file /root/mesa/mesa_crossfile.ini \
--prefix=/opt/mesa \
--buildtype=release \
-Dgallium-drivers= \
-Dvulkan-drivers=panfrost \
-Dplatforms= \
-Dglx=disabled \
-Dgles1=disabled \
-Dgles2=disabled \
-Degl=disabled \
-Dgbm=disabled \
-Dgallium-va=disabled \
-Dllvm=disabled \
-Dlibunwind=disabled
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/mesa/build -j$CPU_NUM
ninja -C /root/mesa/build install
8.
git clone https://github.com/KhronosGroup/Vulkan-Loader.git
cd Vulkan-Loader
git checkout v1.3.296
mkdir -p build && cd build
cmake .. -G"Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE=../toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/Vulkan-Loader \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_FLAGS_RELEASE="-I/root/mesa/include -mcpu=cortex-a55+crypto -O3" \
-DCMAKE_CXX_FLAGS_RELEASE="-I/root/mesa/include -mcpu=cortex-a55+crypto -O3" \
-DBUILD_WSI_XCB_SUPPORT=OFF \
-DBUILD_WSI_XLIB_SUPPORT=OFF \
-DBUILD_WSI_WAYLAND_SUPPORT=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
cmake --build . --config Release --target install -- -j$CPU_NUM
-----------modify api_version
/root/mesa/build/src/panfrost/vulkan/panfrost_icd.aarch64.json
{
"ICD": {
"api_version": "1.3.296",
"library_path": "/usr/local/lib/libvulkan_panfrost.so"
},
"file_format_version": "1.0.0"
}
9. upload and run in target board
export VK_ICD_FILENAMES=/volume1/panfrost_icd.aarch64.json
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~mesa-26.2.2 GLES2 Rusticl
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. ubuntu 24.04 preinstall
sudo apt install libzstd-dev libxml2-dev libexpat-dev rustup
sudo pip3 install --force-reinstall --upgrade --break-system-packages --target=/usr/lib/python3/dist-packages lxml rnc2rng
rustup target add aarch64-unknown-linux-gnu
rustup component add rustfmt
#if llvm <= v19
cargo install bindgen-cli --version 0.71.1
#if llvm >= v22
cargo install bindgen-cli --version 0.73.2
ln -sf /root/.cargo/bin/bindgen /usr/bin/bindgen
#cross compile need arm64 base libs, libdrm(2.4.120) libexpat libzstd libz, pre-install them in your lib directory
2. my all source put in "/root/GpuProjects"
git clone --depth 1 -b release/19.x https://github.com/llvm/llvm-project.git
git clone https://github.com/KhronosGroup/SPIRV-Tools -b v2025.1
git clone https://github.com/KhronosGroup/SPIRV-LLVM-Translator -b v19.1.7
cat /root/git_source/SPIRV-Tools/DEPS | grep spirv_headers_revision
git clone https://github.com/KhronosGroup/SPIRV-Headers
cd SPIRV-Headers && git checkout 09913f088a1197aba4aefd300a876b2ebbaa3391
git clone https://github.com/KhronosGroup/OpenCL-Headers.git -b v2024.10.24
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader.git -b v2024.10.24
git clone --depth 1 -b mesa-26.2.2 https://gitlab.freedesktop.org/mesa/mesa.git
#or
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
git checkout -B mesa-26.2.2-work mesa-26.2.2
--------------- another match version ---------------
git clone --depth 1 -b release/22.x https://github.com/llvm/llvm-project.git
git clone --depth 1 -b llvm_22 https://gitlab.freedesktop.org/karolherbst/mesa-libclc.git
mesa-libclc's [*.cl] [*.h] [SOURCES] copy cover to /root/GpuProjects/llvm-project/libclc
git clone --depth 1 -b v2026.2 https://github.com/KhronosGroup/SPIRV-Tools
git clone --depth 1 -b v22.1.2 https://github.com/KhronosGroup/SPIRV-LLVM-Translator
cat /root/git_source/SPIRV-Tools/DEPS | grep spirv_headers_revision
git clone https://github.com/KhronosGroup/SPIRV-Headers
cd SPIRV-Headers && git checkout ad9184e76a66b1001c29db9b0a3e87f646c64de0
git clone -b v2026.05.29 https://github.com/KhronosGroup/OpenCL-Headers.git
git clone -b v2026.05.29 https://github.com/KhronosGroup/OpenCL-ICD-Loader.git
git clone --depth 1 -b mesa-26.2.3 https://gitlab.freedesktop.org/mesa/mesa.git
#or
git clone https://gitlab.freedesktop.org/mesa/mesa.git
cd mesa
git checkout -B mesa-26.2.3-work mesa-26.2.3
git branch
~~~~~~~~~~~~~~~~~~~~~~
Mesa x64 host toolchain
Mesa Rusticl need x64 toolchain, so we need build x64 then arm64
~~~~~~~~~~~~~~~~~~~~~~
1.
#if llvm-project <= v19
cd llvm-project
cmake -S ./llvm \
-B /root/GpuProjects/llvm-project/build-x64 \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/x64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/opt/llvm/x64/lib \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-x64 -j$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-x64 install
#if llvm-project >= v22
cd llvm-project
cmake -S ./llvm \
-B /root/GpuProjects/llvm-project/build-x64 \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/x64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/opt/llvm/x64/lib \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_ENABLE_RUNTIMES="libclc" \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-x64 -j$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-x64 install
2.
cd SPIRV-Tools
cmake -S . \
-B /root/GpuProjects/SPIRV-Tools/build-x64 \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/x64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/opt/llvm/x64/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/llvm/x64/bin/clang++ \
-DCMAKE_INSTALL_RPATH=/opt/llvm/x64/lib \
-DSPIRV-Headers_SOURCE_DIR=/root/GpuProjects/SPIRV-Headers
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-Tools/build-x64 -j$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-Tools/build-x64 install
3.
cd SPIRV-LLVM-Translator
cmake -S . \
-B /root/GpuProjects/SPIRV-LLVM-Translator/build-x64 \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/x64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=/opt/llvm/x64/bin/clang \
-DCMAKE_CXX_COMPILER=/opt/llvm/x64/bin/clang++ \
-DCMAKE_INSTALL_RPATH=/opt/llvm/x64/lib \
-DLLVM_DIR=/opt/llvm/x64/lib/cmake/llvm \
-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=/root/GpuProjects/SPIRV-Headers
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-LLVM-Translator/build-x64 -j$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-LLVM-Translator/build-x64 install
4. mesa_crossfile_x64.ini
[binaries]
c = '/usr/bin/gcc'
cpp = '/usr/bin/g++'
ar = '/usr/bin/ar'
ld = '/usr/bin/ld'
strip = '/usr/bin/strip'
nm = '/usr/bin/nm'
objdump = '/usr/bin/objdump'
readelf = '/usr/bin/readelf'
pkgconfig = '/usr/bin/pkg-config'
llvm-config = '/opt/llvm/x64/bin/llvm-config'
[built-in options]
c_args = ['-I/opt/llvm/x64/include']
cpp_args = c_args
c_link_args = ['-L/opt/llvm/x64/lib', '-Wl,-rpath,/opt/llvm/x64/lib']
cpp_link_args = c_link_args
# https://www.mediafire.com/file/9zuj6ag8ssr3b01/mesa_crossfile_x64.ini/file
5.
A way: upload *.spv to target /usr/share/clc/
gedit /root/GpuProjects/mesa/src/compiler/clc/meson.build
# by stone
#_libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)]
_libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format('/usr/share/clc')]
B way: If you want use -Dstatic-libclc=all, I do not use this because affect x64 versionon
# by stone
#_libclc_file = _basedir
_libclc_file = '/opt/llvm/x64/share/clc'
I choice A way, after meson setup check result:
cat /root/GpuProjects/mesa/build-x64/compile_commands.json | grep DYNAMIC_LIBCLC_PATH
#env
#if llvm-project <= v19
export PKG_CONFIG_PATH=/opt/llvm/x64/lib/pkgconfig
#if llvm-project >= v22
export PKG_CONFIG_PATH=/opt/llvm/x64/lib/pkgconfig:/opt/llvm/x64/share/pkgconfig
cd mesa
meson setup build-x64 . \
--cross-file /root/GpuProjects/mesa/mesa_crossfile_x64.ini \
--prefix=/opt/mesa/x64 \
--buildtype=release \
-Dmesa-clc-bundle-headers=enabled \
-Dinstall-mesa-clc=true \
-Dinstall-precomp-compiler=true \
-Dgallium-drivers=panfrost \
-Dgallium-va=disabled \
-Dgallium-rusticl=true \
-Drust_std=2021 \
-Dvulkan-drivers= \
-Dplatforms= \
-Degl-native-platform=surfaceless \
-Dgles1=disabled \
-Dgles2=enabled \
-Degl=enabled \
-Dgbm=enabled \
-Dglx=disabled \
-Dglvnd=disabled \
-Dllvm=enabled \
-Dshared-llvm=enabled \
-Dlibunwind=disabled
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/mesa/build-x64 -j$CPU_NUM
ninja -C /root/GpuProjects/mesa/build-x64 install
~~~~~~~~~~~~~~~~~~~~~~
Mesa arm64 target bin
~~~~~~~~~~~~~~~~~~~~~~
1. toolchain_arm64.cmake
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CROSS_COMPILE "aarch64-oem_arm64-linux-gnu-")
set(CMAKE_C_COMPILER "/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-g++")
# https://www.mediafire.com/file/6l5b1uuqd2ehp2o/toolchain_arm64.cmake/file
2.
#if llvm-project <= v19
cd llvm-project
cmake -S ./llvm \
-B /root/GpuProjects/llvm-project/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/llvm-project/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_TARGETS_TO_BUILD="AArch64" \
-DLLVM_ENABLE_PROJECTS="clang;libclc" \
-DLLVM_NATIVE_TOOL_DIR=/opt/llvm/x64/bin \
-DLLVM_SPIRV=/opt/llvm/x64/bin/llvm-spirv \
-DLIBCLC_TARGETS_TO_BUILD="spirv-mesa3d-;spirv64-mesa3d-" \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-arm64 install
#if llvm-project >= v22
export LD_LIBRARY_PATH=/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot/lib
cd llvm-project
cmake -S ./llvm \
-B /root/GpuProjects/llvm-project/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/llvm-project/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DBUILD_SHARED_LIBS=ON \
-DLLVM_TARGETS_TO_BUILD="AArch64" \
-DLLVM_ENABLE_PROJECTS="clang" \
-DLLVM_ENABLE_RUNTIMES="libclc" \
-DLLVM_NATIVE_TOOL_DIR=/opt/llvm/x64/bin \
-DRUNTIMES_CMAKE_ARGS="-DLLVM_SPIRV=/opt/llvm/x64/bin/llvm-spirv" \
-DLIBCLC_TARGETS_TO_BUILD="spirv-mesa3d-;spirv64-mesa3d-" \
-DLLVM_ENABLE_DUMP=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_INCLUDE_EXAMPLES=OFF \
-DLLVM_INCLUDE_BENCHMARKS=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/llvm-project/build-arm64 install
#note: /opt/llvm/x64/bin/llvm-spirv make sure can run, maybe need chmod 755
3.
cd SPIRV-Tools
cmake -S . \
-B /root/GpuProjects/SPIRV-Tools/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/SPIRV-Tools/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DSPIRV-Headers_SOURCE_DIR=/root/GpuProjects/SPIRV-Headers
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-Tools/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-Tools/build-arm64 install
4.
cd SPIRV-LLVM-Translator
cmake -S . \
-B /root/GpuProjects/SPIRV-LLVM-Translator/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/SPIRV-LLVM-Translator/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/llvm/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DLLVM_DIR=/opt/llvm/arm64/lib/cmake/llvm \
-DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=/root/GpuProjects/SPIRV-Headers
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-LLVM-Translator/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/SPIRV-LLVM-Translator/build-arm64 install
5. mesa_crossfile_arm64.ini
[host_machine]
system = 'linux'
cpu_family = 'aarch64'
cpu = 'aarch64'
endian = 'little'
[properties]
sys_root = '/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot'
[constants]
cross_compile = '/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-'
[binaries]
c = cross_compile + 'gcc'
cpp = cross_compile + 'g++'
ar = cross_compile + 'ar'
ld = cross_compile + 'ld'
strip = cross_compile + 'strip'
nm = cross_compile + 'nm'
objdump = cross_compile + 'objdump'
readelf = cross_compile + 'readelf'
pkgconfig = '/usr/bin/pkg-config'
llvm-config = '/opt/llvm/arm64/bin/llvm-config'
rust = ['rustc', '--target', 'aarch64-unknown-linux-gnu']
[built-in options]
c_args = ['-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/include', '-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/include', '-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/include', '-I/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/include/libdrm', '-I/opt/llvm/arm64/include', '-mcpu=cortex-a55+crypto']
cpp_args = c_args
c_link_args = ['-L/root/project_arm64rt2_debug/arm64rt2/staging/lib', '-L/root/project_arm64rt2_debug/arm64rt2/staging/lib64', '-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib', '-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib64', '-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib', '-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib64', '-L/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib', '-L/opt/llvm/arm64/lib', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/lib', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/lib64', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/lib64', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/builtin/lib64', '-Wl,-rpath-link,/root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib', '-Wl,-rpath-link,/opt/llvm/arm64/lib']
cpp_link_args = c_link_args
# https://www.mediafire.com/file/469se254fe8xp4i/mesa_crossfile_arm64.ini/file
6.
A way: upload *.spv to target /usr/share/clc/
gedit /root/GpuProjects/mesa/src/compiler/clc/meson.build
# by stone
#_libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format(_basedir)]
_libmesaclc_c_args += ['-DDYNAMIC_LIBCLC_PATH="@0@/"'.format('/usr/share/clc')]
B way: If you want use -Dstatic-libclc=all, I do not use this because affect x64 versionon
# by stone
#_libclc_file = _basedir
_libclc_file = '/opt/llvm/arm64/share/clc'
I choice A way, after meson setup check result:
cat /root/GpuProjects/mesa/build-arm64/compile_commands.json | grep DYNAMIC_LIBCLC_PATH
#add mesa_crossfile.ini in mesa
[binaries]
rust = ['rustc', '--target', 'aarch64-unknown-linux-gnu']
#make sure /opt/llvm/arm64/bin/llvm-config can run well
ln -sf /opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot/lib/ld-linux-aarch64.so.1 /lib/
#env, /usr/bin/bindgen need x64 libclang.so to parser .h
export LD_LIBRARY_PATH=/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot/lib:/opt/llvm/arm64/lib
export PKG_CONFIG_PATH=/opt/llvm/arm64/lib/pkgconfig:/opt/llvm/arm64/share/pkgconfig
export LIBCLANG_PATH=/opt/llvm/x64/lib
export BINDGEN_EXTRA_CLANG_ARGS=\
"--target=aarch64-linux-gnu \
--sysroot=/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/sysroot \
-I/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/include/c++/13.2.0 \
-I/opt/toolchain/aarch64-oem_arm64-linux-gnu/aarch64-oem_arm64-linux-gnu/include/c++/13.2.0/aarch64-oem_arm64-linux-gnu"
export PATH=$PATH:/opt/mesa/x64/bin
cd mesa
meson setup build-arm64 . \
--cross-file /root/GpuProjects/mesa/mesa_crossfile_arm64.ini \
--prefix=/opt/mesa/arm64 \
--buildtype=release \
-Dprecomp-compiler=system \
-Dmesa-clc=system \
-Dmesa-clc-bundle-headers=enabled \
-Dgallium-drivers=panfrost \
-Dgallium-va=disabled \
-Dgallium-rusticl=true \
-Drust_std=2021 \
-Dvulkan-drivers= \
-Dplatforms= \
-Degl-native-platform=surfaceless \
-Dgles1=disabled \
-Dgles2=enabled \
-Degl=enabled \
-Dgbm=enabled \
-Dglx=disabled \
-Dglvnd=disabled \
-Dllvm=enabled \
-Dshared-llvm=enabled \
-Dlibunwind=disabled
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/mesa/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/mesa/build-arm64 install
7.
cd /root/GpuProjects/OpenCL-Headers
cmake -S . \
-B /root/GpuProjects/OpenCL-Headers/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/OpenCL-Headers/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/opencl/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/OpenCL-Headers/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/OpenCL-Headers/build-arm64 install
8.
cd /root/GpuProjects/OpenCL-ICD-Loader
cmake -S . \
-B /root/GpuProjects/OpenCL-ICD-Loader/build-arm64 \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=/root/GpuProjects/OpenCL-ICD-Loader/toolchain_arm64.cmake \
-DCMAKE_INSTALL_PREFIX=/opt/opencl/arm64 \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_RPATH=/usr/local/lib \
-DOPENCL_ICD_LOADER_HEADERS_DIR=/opt/opencl/arm64/include
CPU_NUM=$(echo $(grep -c processor /proc/cpuinfo)/2 | bc)
echo "CPU number = "$CPU_NUM
ninja -C /root/GpuProjects/OpenCL-ICD-Loader/build-arm64 -j$CPU_NUM
ninja -C /root/GpuProjects/OpenCL-ICD-Loader/build-arm64 install
9. upload
--------------------------libdrm
sshpass -p "20260901" scp /root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib/libdrm.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib/libdrm.so.2 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /root/project_arm64rt2_debug/arm64rt2/staging/usr/local/lib/libdrm.so.2.4.0 root@172.16.1.93:/usr/local/lib/
--------------------------libllvm
sshpass -p "20260901" scp /opt/llvm/arm64/lib/libLLVM* root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/llvm/arm64/lib/libclang-cpp.so root@172.16.1.93:/usr/local/lib/
#if llvm <= v19
sshpass -p "202302001" scp /opt/llvm/arm64/lib/libclang-cpp.so.19.1 root@172.16.1.93:/usr/local/lib/
#if llvm >= v22
sshpass -p "202302001" scp /opt/llvm/arm64/lib/libclang-cpp.so.22.1 root@172.16.1.93:/usr/local/lib/
--------------------------libgles2, librusticl
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libEGL.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libEGL.so.1 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libEGL.so.1.0.0 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libgallium-26.2.3.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libgbm.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libgbm.so.1 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libgbm.so.1.0.0 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libGLESv2.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libGLESv2.so.2 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libGLESv2.so.2.0.0 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libRusticlOpenCL.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libRusticlOpenCL.so.1 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/libRusticlOpenCL.so.1.0.0 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/mesa/arm64/lib/gbm/dri_gbm.so root@172.16.1.93:/usr/local/lib/
--------------------------libopencl
sshpass -p "20260901" scp /opt/opencl/arm64/lib/libOpenCL.so root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/opencl/arm64/lib/libOpenCL.so.1 root@172.16.1.93:/usr/local/lib/
sshpass -p "20260901" scp /opt/opencl/arm64/lib/libOpenCL.so.1.0.0 root@172.16.1.93:/usr/local/lib/
--------------------------opencl icd
sshpass -p "20260901" ssh root@172.16.1.93 "mkdir -p /etc/OpenCL/vendors"
sshpass -p "20260901" ssh root@172.16.1.93 "echo '/usr/local/lib/libRusticlOpenCL.so.1' > /etc/OpenCL/vendors/rusticl.icd"
--------------------------clc
sshpass -p "20260901" ssh root@172.16.1.93 "mkdir -p /usr/share/clc"
#if llvm <= v19
sshpass -p "202302001" scp /opt/llvm/arm64/share/clc/*.spv root@172.16.1.93:/usr/share/clc/
#if llvm >= v22
sshpass -p "202302001" scp /opt/llvm/arm64/lib/clang/22/lib/libclc/*.spv root@172.16.1.93:/usr/share/clc/
10. in target board
cat /etc/OpenCL/vendors/rusticl.icd
show: /usr/local/lib/libRusticlOpenCL.so.1
11. in target board
export VK_ICD_FILENAMES=/volume1/panfrost_icd.aarch64.json
export PAN_I_WANT_A_BROKEN_VULKAN_DRIVER=1
export GBM_BACKENDS_PATH=/usr/local/lib
12.
source for testing mesa gles2 rusticl
https://www.mediafire.com/file/yshyldmsladbcnd/api_client_arm64.zip/file
testing demo:
https://www.mediafire.com/view/gdhlg0scrchipcq/gles2.jpg/file
https://www.mediafire.com/file/cr5lfzqvmb2vxn3/rusticl.jpg/file
https://www.mediafire.com/view/z64926lthwza6lc/llvmv22_01.jpg/file
https://www.mediafire.com/view/s8bg4iyz1p13zhe/llvmv22_02.jpg/file
13. Learning how to compile .rs
# 13.1
cat << 'EOF' > helper.rs
#[no_mangle]
pub extern "C" fn compute_square(x: i32) -> i32 {
x * x
}
EOF
cat << 'EOF' > test.rs
extern "C" {
fn compute_square(x: i32) -> i32;
}
#[no_mangle]
pub extern "C" fn run_process(x: i32) -> i32 {
unsafe { compute_square(x) * 2 }
}
EOF
# 13.2 Compile both source files directly into ARM64 .o object files
rustc --target aarch64-unknown-linux-gnu --crate-type=lib --emit=obj helper.rs -o helper.o
rustc --target aarch64-unknown-linux-gnu --crate-type=lib --emit=obj test.rs -o test.o
# 13.3 Perform final linking using the GCC cross-linker to create a shared library
/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-gcc \
helper.o test.o -shared -o libtest.so
# 13.4 Verify the ELF header of the object file
/opt/toolchain/aarch64-oem_arm64-linux-gnu/bin/aarch64-oem_arm64-linux-gnu-readelf -h ./test.o
14. Learning how to compile .cl
# 14.1
cat << 'EOF' > helper.cl
float compute_square(float x) {
return x * x;
}
EOF
cat << 'EOF' > test.cl
extern float compute_square(float x);
__kernel void process(__global float *val) {
*val = compute_square(*val);
}
EOF
# 14.2 Compile .cl source files into spir64 LLVM Bitcode
/opt/llvm/x64/bin/clang -target spir64-unknown-unknown -emit-llvm -c helper.cl -o helper.bc
/opt/llvm/x64/bin/clang -target spir64-unknown-unknown -emit-llvm -c test.cl -o test.bc
# 14.3 Merge the LLVM bitcode files
/opt/llvm/x64/bin/llvm-link helper.bc test.bc -o test_linked.bc
# 14.4 Translate the linked bitcode into the final SPIR-V (.spv) binary
/opt/llvm/x64/bin/llvm-spirv test_linked.bc -o test.spv
15.
if run binary show:
=== Rusticl warning: Patched Mesa libclc not detected. Upstream libclc may contain known bugs or breaking changes and isn't guaranteed to work reliably. Please visit https://gitlab.freedesktop.org/karolherbst/mesa-libclc for more information. ===
in ~/mesa/docs/rusticl.rst
LLVM: 15.0.0 (recommended 19.0.0)
The mesa v26.x rusticl use llvm v19.x, but mesa-libclc v22.1.8.3 needs at least LLVM 22.1.0
The future, mesa v27.x maybe use llvm-v22.1.0, then auto fix this issue.
沒有留言:
張貼留言