Skip to content

Commit

Permalink
patches
Browse files Browse the repository at this point in the history
everything in one commit, woop!
  • Loading branch information
SolDev69 committed Dec 8, 2023
1 parent 0fafd86 commit d4f3b7b
Show file tree
Hide file tree
Showing 36 changed files with 1,049 additions and 195 deletions.
26 changes: 26 additions & 0 deletions android-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[binaries]
ar = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
c = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC']
cpp = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android26-clang++', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-static-libstdc++']
c_ld = 'lld'
cpp_ld = 'lld'
strip = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
# Android doesn't come with a pkg-config, but we need one for meson to be happy not
# finding all the optional deps it looks for. Use system pkg-config pointing at a
# directory we get to populate with any .pc files we want to add for Android

# Also, include the plain DRM lib we found earlier. Panfrost relies on it rather heavily, especially when
# interacting with the panfrost DRM module and not kbase

pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=.:/tmp/drm-static/lib/pkgconfig', '/usr/bin/pkg-config']

[host_machine]
system = 'linux'
# cpu_family = 'x86_64'
# cpu = 'amd64'

# ik this is wrong but workaround sanity check
cpu_family = 'arm'
cpu = 'armv8'

endian = 'little'
26 changes: 26 additions & 0 deletions android-arm32
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[binaries]
ar = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
c = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC']
cpp = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi26-clang++', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-static-libstdc++']
c_ld = 'lld'
cpp_ld = 'lld'
strip = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
# Android doesn't come with a pkg-config, but we need one for meson to be happy not
# finding all the optional deps it looks for. Use system pkg-config pointing at a
# directory we get to populate with any .pc files we want to add for Android

# Also, include the plain DRM lib we found earlier. Panfrost relies on it rather heavily, especially when
# interacting with the panfrost DRM module and not kbase

pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=.:/tmp/drm-static/lib/pkgconfig', '/usr/bin/pkg-config']

[host_machine]
system = 'linux'
# cpu_family = 'x86_64'
# cpu = 'amd64'

# ik this is wrong but workaround sanity check
cpu_family = 'arm'
cpu = 'armv7'

endian = 'little'
22 changes: 22 additions & 0 deletions android-drm-aarch64
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[binaries]
ar = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
c = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC']
cpp = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-static-libstdc++']
c_ld = 'lld'
cpp_ld = 'lld'
strip = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
# Android doesn't come with a pkg-config, but we need one for meson to be happy not
# finding all the optional deps it looks for. Use system pkg-config pointing at a
# directory we get to populate with any .pc files we want to add for Android
pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=.', '/usr/bin/pkg-config']

[host_machine]
system = 'linux'
# cpu_family = 'x86_64'
# cpu = 'amd64'

# ik this is wrong but workaround sanity check
cpu_family = 'arm'
cpu = 'armv8'

endian = 'little'
22 changes: 22 additions & 0 deletions android-drm-arm32
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[binaries]
ar = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar'
c = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC']
cpp = ['ccache', '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++', '-O3', '-DVK_USE_PLATFORM_ANDROID_KHR', '-fPIC', '-fno-exceptions', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-static-libstdc++']
c_ld = 'lld'
cpp_ld = 'lld'
strip = '$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip'
# Android doesn't come with a pkg-config, but we need one for meson to be happy not
# finding all the optional deps it looks for. Use system pkg-config pointing at a
# directory we get to populate with any .pc files we want to add for Android
pkgconfig = ['env', 'PKG_CONFIG_LIBDIR=.', '/usr/bin/pkg-config']

[host_machine]
system = 'linux'
# cpu_family = 'x86_64'
# cpu = 'amd64'

# ik this is wrong but workaround sanity check
cpu_family = 'arm'
cpu = 'armv7'

endian = 'little'
8 changes: 4 additions & 4 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ foreach gallium_driver : gallium_drivers
pre_args += '-DHAVE_@0@'.format(gallium_driver.to_upper())
endforeach

if get_option('freedreno-kmds').contains('kgsl')
pre_args += '-DHAVE_FREEDRENO_KGSL'
endif

with_gallium = gallium_drivers.length() != 0
with_gallium_kmsro = system_has_kms_drm and [
with_gallium_asahi,
Expand Down Expand Up @@ -252,10 +256,6 @@ if freedreno_kmds.length() != 0 and freedreno_kmds != [ 'msm' ] and with_freedre
warning('As a side-effect, Turnip is forced to link with libdrm when built alongside Gallium DRM drivers which platforms such as Android may not have available at runtime.')
elif _vulkan_drivers != [ 'freedreno' ]
warning('Turnip is forced to link with libdrm when built alongside other Vulkan drivers which platforms such as Android may not have available at runtime.')
else
# If DRM support isn't needed, we can get rid of it since linking
# to libdrm can be a potential compatibility hazard.
system_has_kms_drm = false
endif
endif

Expand Down
2 changes: 1 addition & 1 deletion src/android_stub/meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if with_android_stub
stub_libs = []
lib_names = ['cutils', 'hardware', 'log', 'nativewindow', 'sync']
lib_names = ['hardware', 'log', 'nativewindow', 'sync']

if with_libbacktrace
lib_names += ['backtrace']
Expand Down
107 changes: 107 additions & 0 deletions src/egl/drivers/dri2/platform_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,64 @@ cros_get_buffer_info(struct dri2_egl_display *dri2_dpy,
return -EINVAL;
}

static int
kgsl_window_buffer_get_buffer_info(struct dri2_egl_display *dri2_dpy,
struct ANativeWindowBuffer *buf,
struct buffer_info *out_buf_info)
{
/* The below code is tested against the version of gralloc shipped
* with the below properties. Different versions of gralloc could modifiy
* the internal format of the handle requiring the handle_data access to be different
* id: "gralloc"
* name: "Graphics Memory Module"
* author: "Code Aurora Forum"
* module_api_version: 0x100
* hal_api_version: 0x100
*/

/* The below code does not handle the YUV texture case */
const uint32_t *handle_fds = (uint32_t *)buf->handle->data;
const uint32_t *handle_data = &handle_fds[buf->handle->numFds];
uint32_t gmsm = ('g' << 24) | ('m' << 16) | ('s' << 8) | 'm';
int drm_fourcc = 0;
int pitch = 0;
int fds[3];
int num_fds = get_native_buffer_fds(buf, fds);

if (num_fds == 2 && buf->handle->numInts >= 2 && handle_data[0] == gmsm) {
drm_fourcc = get_fourcc(buf->format);
if (drm_fourcc == -1) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return -EINVAL;
}

pitch = buf->stride * get_format_bpp(buf->format);
if (pitch == 0) {
_eglError(EGL_BAD_PARAMETER, "eglCreateEGLImageKHR");
return -EINVAL;
}

*out_buf_info = (struct buffer_info){
.width = buf->width,
.height = buf->height,
.drm_fourcc = drm_fourcc,
.num_planes = 1,
.fds = { fds[0], -1, -1, -1 },
.modifier = handle_data[1] & 0x08000000 ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR,
.offsets = { 0, 0, 0, 0 },
.pitches = { pitch, 0, 0, 0 },
.yuv_color_space = EGL_ITU_REC601_EXT,
.sample_range = EGL_YUV_NARROW_RANGE_EXT,
.horizontal_siting = EGL_YUV_CHROMA_SITING_0_EXT,
.vertical_siting = EGL_YUV_CHROMA_SITING_0_EXT,
};

return 0;
}

return -EINVAL;
}

static __DRIimage *
droid_create_image_from_buffer_info(struct dri2_egl_display *dri2_dpy,
struct buffer_info *buf_info, void *priv)
Expand Down Expand Up @@ -455,6 +513,9 @@ droid_create_image_from_native_buffer(_EGLDisplay *disp,
if (!img && !cros_get_buffer_info(dri2_dpy, buf, &buf_info))
img = droid_create_image_from_buffer_info(dri2_dpy, &buf_info, priv);

if (!img && !kgsl_window_buffer_get_buffer_info(dri2_dpy, buf, &buf_info))
img = droid_create_image_from_buffer_info(dri2_dpy, &buf_info, priv);

if (!img && !native_window_buffer_get_buffer_info(dri2_dpy, buf, &buf_info))
img = droid_create_image_from_buffer_info(dri2_dpy, &buf_info, priv);

Expand Down Expand Up @@ -1396,9 +1457,46 @@ droid_probe_device(_EGLDisplay *disp, bool swrast)
return EGL_TRUE;
}

static EGLBoolean droid_open_device_kgsl(_EGLDisplay *disp, bool swrast)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
static const char path[] = "/dev/kgsl-3d0";
static const char driver_name[] = "kgsl";

dri2_dpy->fd_render_gpu = loader_open_device(path);
if (dri2_dpy->fd_render_gpu < 0) {
_eglLog(_EGL_WARNING, "Failed to open kgsl");
return EGL_FALSE;
}

dri2_dpy->driver_name = strdup(driver_name);
dri2_dpy->loader_extensions = droid_image_loader_extensions;
if (!dri2_load_driver_dri3(disp)) {
free(dri2_dpy->driver_name);
dri2_dpy->driver_name = NULL;
goto error;
}

if (!dri2_create_screen(disp)) {
_eglLog(_EGL_WARNING, "DRI2: Failed to create screen");
droid_unload_driver(disp);
goto error;
}

return EGL_TRUE;
error:
close(dri2_dpy->fd_render_gpu);
dri2_dpy->fd_render_gpu = -1;
return EGL_FALSE;
}

static EGLBoolean
droid_open_device(_EGLDisplay *disp, bool swrast)
{
#ifdef HAVE_FREEDRENO_KGSL
if (droid_open_device_kgsl(disp, swrast))
goto done;
#endif
#define MAX_DRM_DEVICES 64
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
_EGLDevice *dev_list = _eglGlobal.DeviceList;
Expand Down Expand Up @@ -1505,6 +1603,15 @@ dri2_initialize_android(_EGLDisplay *disp)

dri2_dpy->fd_display_gpu = dri2_dpy->fd_render_gpu;

/* Only add a egl device if this is not the kgsl driver */
if (strcmp(dri2_dpy->driver_name, "kgsl") != 0) {
dev = _eglAddDevice(dri2_dpy->fd_render_gpu, false);
if (!dev) {
err = "DRI2: failed to find EGLDevice";
goto cleanup;
}
}

dev = _eglFindDevice(dri2_dpy->fd_render_gpu, false);
if (!dev) {
err = "DRI2: failed to find EGLDevice";
Expand Down
30 changes: 21 additions & 9 deletions src/freedreno/drm/freedreno_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fd_bo_from_handle(struct fd_device *dev, uint32_t handle, uint32_t size)
}

struct fd_bo *
fd_bo_from_dmabuf(struct fd_device *dev, int fd)
fd_bo_from_dmabuf_drm(struct fd_device *dev, int fd)
{
int ret, size;
uint32_t handle;
Expand Down Expand Up @@ -254,6 +254,12 @@ fd_bo_from_dmabuf(struct fd_device *dev, int fd)
return bo;
}

struct fd_bo *
fd_bo_from_dmabuf(struct fd_device *dev, int fd)
{
return dev->funcs->bo_from_dmabuf(dev, fd);
}

struct fd_bo *
fd_bo_from_name(struct fd_device *dev, uint32_t name)
{
Expand Down Expand Up @@ -430,6 +436,15 @@ fd_bo_fini_fences(struct fd_bo *bo)
free(bo->fences);
}

void
fd_bo_close_handle_drm(struct fd_device *dev, uint32_t handle)
{
struct drm_gem_close req = {
.handle = handle,
};
drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
}

/**
* Helper called by backends bo->funcs->destroy()
*
Expand All @@ -453,10 +468,7 @@ fd_bo_fini_common(struct fd_bo *bo)

if (handle) {
simple_mtx_lock(&table_lock);
struct drm_gem_close req = {
.handle = handle,
};
drmIoctl(dev->fd, DRM_IOCTL_GEM_CLOSE, &req);
dev->funcs->bo_close_handle(dev, handle);
_mesa_hash_table_remove_key(dev->handle_table, &handle);
if (bo->name)
_mesa_hash_table_remove_key(dev->name_table, &bo->name);
Expand Down Expand Up @@ -559,8 +571,8 @@ fd_bo_is_cached(struct fd_bo *bo)
return !!(bo->alloc_flags & FD_BO_CACHED_COHERENT);
}

static void *
bo_map(struct fd_bo *bo)
void *
fd_bo_map_os_mmap(struct fd_bo *bo)
{
if (!bo->map) {
uint64_t offset;
Expand Down Expand Up @@ -590,7 +602,7 @@ fd_bo_map(struct fd_bo *bo)
if (bo->alloc_flags & FD_BO_NOMAP)
return NULL;

return bo_map(bo);
return bo->funcs->map(bo);
}

void
Expand All @@ -601,7 +613,7 @@ fd_bo_upload(struct fd_bo *bo, void *src, unsigned off, unsigned len)
return;
}

memcpy((uint8_t *)bo_map(bo) + off, src, len);
memcpy((uint8_t *)bo->funcs->map(bo) + off, src, len);
}

bool
Expand Down
Loading

0 comments on commit d4f3b7b

Please sign in to comment.