Skip to content

Commit 17fab4a

Browse files
committed
fix for outdated libdrm on Ubuntu
1 parent 2dc5743 commit 17fab4a

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ AC_CHECK_DECL(GBM_BO_USE_FRONT_RENDERING,
134134

135135
CPPFLAGS="$SAVE_CPPFLAGS"
136136

137+
# Check for GFX12 tile version support in libdrm
138+
SAVE_CPPFLAGS="$CPPFLAGS"
139+
CPPFLAGS="$CPPFLAGS $LIBDRM_CFLAGS"
140+
AC_CHECK_DECLS([AMD_FMT_MOD_TILE_VER_GFX12, AMD_FMT_MOD_TILE_GFX12_256B_2D, AMD_FMT_MOD_TILE_GFX12_4K_2D, AMD_FMT_MOD_TILE_GFX12_64K_2D, AMD_FMT_MOD_TILE_GFX12_256K_2D],
141+
[AC_DEFINE(HAVE_AMD_FMT_MOD_TILE_GFX12, 1, [libdrm has GFX12 tile support])],
142+
[AC_MSG_WARN([Some GFX12 tile constants missing - disabling GFX12 support])],
143+
[#include <drm_fourcc.h>])
144+
CPPFLAGS="$SAVE_CPPFLAGS"
145+
137146
AC_CONFIG_FILES([Makefile src/Makefile man/Makefile conf/Makefile])
138147
AC_OUTPUT
139148

src/amdgpu_dri3.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ amdgpu_tiling_info_to_modifier(uint64_t tiling_info, int asic_family)
6060

6161
/* GFX12 and later use a different tiling format */
6262
if (asic_family >= AMDGPU_FAMILY_GC_12_0_0) {
63+
#ifdef HAVE_AMD_FMT_MOD_TILE_VER_GFX12
6364
uint32_t swizzle_mode = AMDGPU_TILING_GET(tiling_info, GFX12_SWIZZLE_MODE);
6465
uint64_t modifier = AMD_FMT_MOD |
6566
AMD_FMT_MOD_SET(TILE_VERSION, AMD_FMT_MOD_TILE_VER_GFX12);
@@ -85,6 +86,10 @@ amdgpu_tiling_info_to_modifier(uint64_t tiling_info, int asic_family)
8586
}
8687

8788
return modifier;
89+
#else
90+
/* GFX12 not supported by this libdrm version */
91+
return DRM_FORMAT_MOD_INVALID;
92+
#endif
8893
}
8994

9095
/* GFX9 - GFX11: Check for 64K tiled modes */
@@ -864,13 +869,15 @@ amdgpu_dri3_get_modifiers(ScreenPtr screen, uint32_t format,
864869
AMD_FMT_MOD | AMD_FMT_MOD_TILE_VER_GFX10 |
865870
AMD_FMT_MOD_TILE_GFX9_64K_D,
866871
};
872+
#ifdef HAVE_AMD_FMT_MOD_TILE_VER_GFX12
867873
static uint64_t amd_tiled_modifiers_gfx12[] = {
868874
/* LINEAR - no tiling */
869875
DRM_FORMAT_MOD_INVALID,
870876
/* AMD GFX12 64K_2D tiled */
871877
AMD_FMT_MOD | AMD_FMT_MOD_TILE_VER_GFX12 |
872878
AMD_FMT_MOD_TILE_GFX12_64K_2D,
873879
};
880+
#endif
874881
uint64_t *mods;
875882
uint32_t count;
876883
int asic_family;
@@ -880,8 +887,14 @@ amdgpu_dri3_get_modifiers(ScreenPtr screen, uint32_t format,
880887

881888
/* Determine which set of modifiers to return based on ASIC family */
882889
if (asic_family >= AMDGPU_FAMILY_GC_12_0_0) {
890+
#ifdef HAVE_AMD_FMT_MOD_TILE_VER_GFX12
883891
mods = amd_tiled_modifiers_gfx12;
884892
count = sizeof(amd_tiled_modifiers_gfx12) / sizeof(amd_tiled_modifiers_gfx12[0]);
893+
#else
894+
/* GFX12 not supported, fall back to GFX10 modifiers */
895+
mods = amd_tiled_modifiers_gfx10;
896+
count = sizeof(amd_tiled_modifiers_gfx10) / sizeof(amd_tiled_modifiers_gfx10[0]);
897+
#endif
885898
} else if (asic_family >= AMDGPU_FAMILY_NV) {
886899
/* Navi and newer (GFX10+) */
887900
mods = amd_tiled_modifiers_gfx10;
@@ -935,13 +948,20 @@ amdgpu_dri3_get_drawable_modifiers(DrawablePtr draw, uint32_t format,
935948
* For drawables, we return the same modifiers as screen-level modifiers.
936949
*/
937950
if (asic_family >= AMDGPU_FAMILY_GC_12_0_0) {
951+
#ifdef HAVE_AMD_FMT_MOD_TILE_VER_GFX12
938952
static uint64_t gfx12_mods[] = {
939953
DRM_FORMAT_MOD_INVALID,
940954
AMD_FMT_MOD | AMD_FMT_MOD_TILE_VER_GFX12 |
941955
AMD_FMT_MOD_TILE_GFX12_64K_2D,
942956
};
943957
mods = gfx12_mods;
944958
count = sizeof(gfx12_mods) / sizeof(gfx12_mods[0]);
959+
#else
960+
/* GFX12 not supported, fall back to invalid modifier */
961+
static uint64_t invalid_mods[] = { DRM_FORMAT_MOD_INVALID };
962+
mods = invalid_mods;
963+
count = 1;
964+
#endif
945965
} else if (asic_family >= AMDGPU_FAMILY_NV) {
946966
/* Navi and newer (GFX10+) */
947967
static uint64_t gfx10_mods[] = {

src/amdgpu_glamor.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,12 @@ amdgpu_glamor_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr secondary,
328328
tiling_info = amdgpu_pixmap_get_tiling_info(pixmap);
329329

330330
if (info->family >= AMDGPU_FAMILY_GC_12_0_0)
331+
#ifdef HAVE_AMD_FMT_MOD_TILE_VER_GFX12
331332
is_linear = AMDGPU_TILING_GET(tiling_info, GFX12_SWIZZLE_MODE) == 0;
333+
#else
334+
/* GFX12 not supported, fall back to assuming non-linear */
335+
is_linear = FALSE;
336+
#endif
332337
else if (info->family >= AMDGPU_FAMILY_AI)
333338
is_linear = AMDGPU_TILING_GET(tiling_info, SWIZZLE_MODE) == 0;
334339
else

src/meson.build

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ else
2929
error('libdrm headers not found - libdrm required')
3030
endif
3131

32+
# Check for GFX12 tile version support in libdrm
33+
gfx12_args = []
34+
gfx12_test = '''
35+
#include <drm_fourcc.h>
36+
int main() {
37+
int x = AMD_FMT_MOD_TILE_VER_GFX12;
38+
x = AMD_FMT_MOD_TILE_GFX12_256B_2D;
39+
x = AMD_FMT_MOD_TILE_GFX12_4K_2D;
40+
x = AMD_FMT_MOD_TILE_GFX12_64K_2D;
41+
x = AMD_FMT_MOD_TILE_GFX12_256K_2D;
42+
return 0;
43+
}
44+
'''
45+
if meson.get_compiler('c').compiles(gfx12_test, dependencies: [libdrm_dep])
46+
gfx12_args = ['-DHAVE_AMD_FMT_MOD_TILE_GFX12']
47+
else
48+
message('Some GFX12 tile constants missing - disabling GFX12 support')
49+
endif
50+
3251
amdgpu_drv_libs = [
3352
fontsproto_dep,
3453
gbm_dep,
@@ -51,7 +70,7 @@ shared_module(
5170
srcs,
5271
include_directories: include_directories('..'),
5372
dependencies: amdgpu_drv_libs,
54-
c_args: drm_args,
73+
c_args: drm_args + gfx12_args,
5574
install: true,
5675
install_dir: join_paths(moduledir, 'drivers'),
5776
name_prefix: '',

0 commit comments

Comments
 (0)