Files
video/libs/mesa/patches/200-panfrost-Enable-cross-compilation-of-precompilers-on.patch
T
Daniel Golle 897356ac2f mesa: update to version 26.1.1
The first stable release of the Mesa 26.1 release branch comes with
countless new features and bugfixes since 26.0.6.

Link: https://docs.mesa3d.org/relnotes/26.1.0.html
Link: https://docs.mesa3d.org/relnotes/26.1.1.html
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
2026-05-31 14:19:37 +01:00

222 lines
6.6 KiB
Diff

From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 13 Oct 2025 01:32:22 +0100
Subject: panfrost: Enable cross-compilation of precompilers on non-Linux hosts
This patch enables building Mesa's Panfrost precompilers on non-Linux
hosts (macOS, Windows, etc.) by introducing a stub kernel mode driver
interface when building without full driver support.
The main issue was that pan_texture.c now requires pan_desc.h, which
includes kmod/pan_kmod.h that depends on Linux-specific DRM headers
(drm.h, xf86drm.h). These headers are not available on non-Linux hosts,
preventing cross-compilation of the Panfrost shader precompilers.
Changes:
1. Created kmod/pan_kmod_stub.h with minimal type definitions needed
by pan_desc.h inline functions (pan_kmod_dev_props)
2. Modified pan_desc.h and pan_image.h to conditionally include either
the full kmod header or the stub version based on PAN_KMOD_STUB
3. Updated build system to:
- Skip building kmod/ subdirectory when not needed
- Exclude pan_desc.c, pan_mod.c, pan_props.c from builds without
driver support
- Add -DPAN_KMOD_STUB define for precompiler-only builds
- Conditionally link kmod library only when building full driver
4. Extended panfrost build to support with_drivers_clc for CLC
precompiler requirements
Refreshed against Mesa 26.1.1: the per-arch source list now contains
pan_buffer.c, pan_fb.c and pan_fb_nir.c in addition to pan_blend.c
and pan_texture.c. All of those include pan_desc.h transitively but
do not call into kmod, so they can build against the stub header on
non-Linux hosts.
--- a/src/meson.build
+++ b/src/meson.build
@@ -92,7 +92,7 @@ endif
if with_any_intel
subdir('intel')
endif
-if with_gallium_panfrost or with_gallium_lima or with_panfrost_vk or with_tools.contains('panfrost')
+if with_drivers_clc or with_gallium_panfrost or with_gallium_lima or with_panfrost_vk or with_tools.contains('panfrost')
subdir('panfrost')
endif
if with_microsoft_clc or with_gallium_d3d12 or with_spirv_to_dxil or with_microsoft_vk
--- /dev/null
+++ b/src/panfrost/lib/kmod/pan_kmod_stub.h
@@ -0,0 +1,29 @@
+/*
+ * Copyright © 2025 Collabora, Ltd.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Stub definitions for pan_kmod types when building without full DRM support.
+ * This allows building the panfrost precompilers on non-Linux hosts.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* Minimal stub for pan_kmod_dev_props used by pan_desc.h and pan_image.h
+ * inline functions */
+struct pan_kmod_dev_props {
+ uint32_t gpu_id;
+ uint32_t max_threads_per_core;
+ uint32_t max_tasks_per_core;
+ uint32_t max_threads_per_wg;
+};
+
+#if defined(__cplusplus)
+} /* extern C */
+#endif
--- a/src/panfrost/lib/meson.build
+++ b/src/panfrost/lib/meson.build
@@ -2,7 +2,9 @@
# Copyright © 2019 Collabora
# SPDX-License-Identifier: MIT
-subdir('kmod')
+if with_gallium_panfrost or with_panfrost_vk
+ subdir('kmod')
+endif
pixel_format_versions = ['5', '6', '7', '9', '10', '12', '13']
libpanfrost_pixel_format = []
@@ -21,21 +23,28 @@ foreach ver : pixel_format_versions
endforeach
libpanfrost_per_arch = []
+libpanfrost_per_arch_files = [
+ 'pan_blend.c',
+ 'pan_buffer.c',
+ 'pan_fb.c',
+ 'pan_fb_nir.c',
+ 'pan_texture.c',
+]
+libpanfrost_per_arch_c_args = []
+
+if with_gallium_panfrost or with_panfrost_vk
+ libpanfrost_per_arch_files += ['pan_desc.c', 'pan_mod.c']
+else
+ # Building without full driver support (e.g., for precompilers only)
+ # Use stub kmod definitions to avoid requiring DRM headers
+ libpanfrost_per_arch_c_args += '-DPAN_KMOD_STUB'
+endif
foreach ver : ['4', '5', '6', '7', '9', '10', '12', '13']
libpanfrost_per_arch += static_library(
- 'pan-arch-v' + ver,
- [
- 'pan_blend.c',
- 'pan_buffer.c',
- 'pan_desc.c',
- 'pan_fb.c',
- 'pan_fb_nir.c',
- 'pan_mod.c',
- 'pan_texture.c',
- ],
+ 'pan-arch-v' + ver, libpanfrost_per_arch_files,
include_directories : [inc_include, inc_src, inc_panfrost],
- c_args : ['-DPAN_ARCH=' + ver],
+ c_args : ['-DPAN_ARCH=' + ver] + libpanfrost_per_arch_c_args,
gnu_symbol_visibility : 'hidden',
dependencies : [deps_for_libpanfrost, idep_nir],
)
@@ -52,26 +61,44 @@ libpanfrost_lib_files = files(
'pan_layout.c',
'pan_scratch.c',
'pan_trace.c',
- 'pan_props.c',
'pan_util.c',
'pan_afbc.c',
)
+if with_gallium_panfrost or with_panfrost_vk
+ libpanfrost_lib_files += files('pan_props.c')
+endif
+
+libpanfrost_link_with = [libpanfrost_pixel_format, libpanfrost_per_arch]
+if with_gallium_panfrost or with_panfrost_vk
+ libpanfrost_link_with += libpankmod_lib
+endif
+
+libpanfrost_lib_c_args = [no_override_init_args]
+if not (with_gallium_panfrost or with_panfrost_vk)
+ libpanfrost_lib_c_args += '-DPAN_KMOD_STUB'
+endif
+
libpanfrost_lib = static_library(
'panfrost_lib',
[libpanfrost_lib_files, pan_packers],
include_directories : [inc_include, inc_src, inc_panfrost],
- c_args : [no_override_init_args],
+ c_args : libpanfrost_lib_c_args,
gnu_symbol_visibility : 'hidden',
dependencies: [dep_libdrm, idep_nir, idep_mesautil, libpanfrost_model_dep],
build_by_default : false,
- link_with: [libpanfrost_pixel_format, libpanfrost_per_arch, libpankmod_lib],
+ link_with: libpanfrost_link_with,
)
+libpanfrost_dependencies = [deps_for_libpanfrost, idep_nir]
+if with_gallium_panfrost or with_panfrost_vk
+ libpanfrost_dependencies += libpankmod_dep
+endif
+
libpanfrost_dep = declare_dependency(
link_with: [libpanfrost_lib, libpanfrost_decode, libpanfrost_compiler, libpanfrost_pixel_format, libpanfrost_per_arch],
include_directories: [inc_include, inc_src, inc_panfrost],
- dependencies: [deps_for_libpanfrost, libpankmod_dep, idep_nir],
+ dependencies: libpanfrost_dependencies,
)
if with_tests
--- a/src/panfrost/lib/pan_desc.h
+++ b/src/panfrost/lib/pan_desc.h
@@ -8,7 +8,11 @@
#include "genxml/gen_macros.h"
+#if defined(PAN_KMOD_STUB)
+#include "kmod/pan_kmod_stub.h"
+#else
#include "kmod/pan_kmod.h"
+#endif
#include "pan_image.h"
#include "pan_pool.h"
--- a/src/panfrost/meson.build
+++ b/src/panfrost/meson.build
@@ -14,7 +14,7 @@ subdir('shared')
subdir('model')
subdir('compiler')
-if with_gallium_panfrost or with_panfrost_vk or with_tools.contains('panfrost')
+if with_drivers_clc or with_gallium_panfrost or with_panfrost_vk or with_tools.contains('panfrost')
subdir('genxml')
subdir('lib')
subdir('clc')
--- a/src/panfrost/lib/pan_image.h
+++ b/src/panfrost/lib/pan_image.h
@@ -18,7 +18,11 @@
#include "pan_mod.h"
#include "pan_props.h"
+#if defined(PAN_KMOD_STUB)
+#include "kmod/pan_kmod_stub.h"
+#else
#include "kmod/pan_kmod.h"
+#endif
#include "util/log.h"