Skip to content

Commit 68a0e4f

Browse files
committed
a few fix
1 parent ff34cb2 commit 68a0e4f

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Current implementation first copies VkImage inside the swapchain to a VkBuffer,
99
#### Programs
1010
✅: Works fine.
1111
🛠️: Tested, but not functioning well.
12+
❌: Tested, but not workding or barely working.
1213
⏹️: Untested.
1314

1415
- ✅ xcb hello triangle
@@ -17,14 +18,17 @@ Current implementation first copies VkImage inside the swapchain to a VkBuffer,
1718
- ✅ vkmark (~900 FPS on SD8Gen3)
1819
- 🛠️ gears (Only shows the red gear's first face)
1920
- 🛠️ glmark2 (Can't finish the benchmark, crash in the middle of it, error: `ralloc_header *get_header(const void *): assertion "info->canary == CANARY" failed`. ~350-400 FPS on SD8Gen3)
20-
- 🛠️ firefox (Only 4 FPS in WebGL Samples Aquarium)
21-
- 🛠️ chromium (When enabling vulkan flag: in chome://gpu, vulkan info shows it is using xvk_droid, but dawn is using the original vulkan loader)
21+
- ❌ firefox (Only 4 FPS in WebGL Samples Aquarium)
22+
- ❌ chromium (When enabling vulkan flag: in chome://gpu, vulkan info shows it is using xvk_droid, but dawn is using the original vulkan loader)
23+
- ❌ programs inside proot-distro (When compiling using glibc, the program can't load android dynamic library, we need to compile bionic libdl to work)
24+
- ❌ glibc packages (Same reason as proot-distro programs)
25+
- ⏹️ box64 wine dxvk (need to fix glibc packages first)
2226
- ⏹️ Minecraft (Require compiling OpenJFX for termux)
23-
- ⏹️ box64 wine dxvk
24-
- ⏹️ wgpu programs (winit is assuming termux an android environment)
27+
- ⏹️ wgpu programs (winit is assuming termux an android environment and not using x11 surface)
2528

2629
### TODO
2730
- Support test programs listed above.
31+
- Support loading android `libvulkan.so` when compiled using glibc, so that it can be used for glibc-repo programs and proot\chroot gnu linux programs.
2832
- Provide prebuilt binaries and make it a deb package.
2933
- Publish to Termux repo.
3034
- Make it an ICD driver to support coexisting with other vulkan drivers.

c_test/xv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#define VK_USE_PLATFORM_XCB_KHR
44
#include <vulkan/vk_icd.h>
55
#include <stdio.h>
6+
#include <string.h>
7+
68
// Data need to be freed afterwards.
79
void* readBinFile(char* path, long* size) {
810
FILE* file = fopen(path, "r");

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CC = clang
1+
CC = gcc
22

33
CFLAGS = -Wall -Werror
44
TARGET_DIR = target

xvk_droid/src/dlfcn.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ unsafe extern "C" {
1919
__symbol: *const ::std::os::raw::c_char,
2020
) -> *mut ::std::os::raw::c_void;
2121
}
22-
// unsafe extern "C" {
23-
// #[doc = " [dlclose(3)](http://man7.org/linux/man-pages/man3/dlclose.3.html)\n decrements the reference count for the given shared library (and\n any libraries brought in by that library's DT_NEEDED entries).\n\n If a library's reference count hits zero, it may be unloaded.\n Code that relies on this is not portable, and may not work on\n future versions of Android.\n\n dlclose() is dangerous because function pointers may or may not\n be rendered invalid, global data may or may not be rendered invalid,\n and memory may or may not leak. Code with global constructors is\n especially problematic. Instead of dlclose, prefer to leave the\n library open or, if cleanup is necessary, dlopen() the library in\n a child process which can later be killed by the parent or call\n exit() itself.\n\n Note also that dlclose() interacts badly with thread local variables\n with non-trivial destructors, with the\n (exact behavior varying by API level)[https://android.googlesource.com/platform/bionic/+/main/android-changes-for-ndk-developers.md#dlclose-interacts-badly-with-thread-local-variables-with-non_trivial-destructors].\n\n Returns 0 on success, and returns -1 on failure, in which case\n dlerror() can be used to retrieve the specific error."]
24-
// pub fn dlclose(__handle: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int;
25-
// }
22+
unsafe extern "C" {
23+
#[doc = " [dlclose(3)](http://man7.org/linux/man-pages/man3/dlclose.3.html)\n decrements the reference count for the given shared library (and\n any libraries brought in by that library's DT_NEEDED entries).\n\n If a library's reference count hits zero, it may be unloaded.\n Code that relies on this is not portable, and may not work on\n future versions of Android.\n\n dlclose() is dangerous because function pointers may or may not\n be rendered invalid, global data may or may not be rendered invalid,\n and memory may or may not leak. Code with global constructors is\n especially problematic. Instead of dlclose, prefer to leave the\n library open or, if cleanup is necessary, dlopen() the library in\n a child process which can later be killed by the parent or call\n exit() itself.\n\n Note also that dlclose() interacts badly with thread local variables\n with non-trivial destructors, with the\n (exact behavior varying by API level)[https://android.googlesource.com/platform/bionic/+/main/android-changes-for-ndk-developers.md#dlclose-interacts-badly-with-thread-local-variables-with-non_trivial-destructors].\n\n Returns 0 on success, and returns -1 on failure, in which case\n dlerror() can be used to retrieve the specific error."]
24+
pub fn dlclose(__handle: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int;
25+
}
2626
// unsafe extern "C" {
2727
// #[doc = " [dlerror(3)](http://man7.org/linux/man-pages/man3/dlerror.3.html)\n returns a human-readable error message describing the most recent\n failure from one of the <dlfcn.h> functions on the calling thread.\n\n This function also clears the error, so a second call (or a call\n before any failure) will return NULL.\n\n Returns a pointer to an error on success, and returns NULL if no\n error is pending."]
2828
// pub fn dlerror() -> *mut ::std::os::raw::c_char;

xvk_droid/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::ffi::CStr;
1+
use std::{ffi::{c_void, CStr}, ptr::null_mut};
22

3-
use dlfcn::{dlopen, RTLD_NOW};
3+
use dlfcn::{dlclose, dlopen, RTLD_NOW};
44
mod dlfcn;
55

66
// All original function pointers.
@@ -19,12 +19,19 @@ const SO_PATH: &CStr = c"/system/lib64/libvulkan.so";
1919
// const SO_PATH: &CStr = c"/data/data/com.termux/files/usr/lib/libvulkan.so";
2020
// const SO_PATH: &CStr = c"/data/data/com.termux/files/usr/lib/libvk_swiftshader.so";
2121

22+
static mut HANDLE: *mut c_void = null_mut();
23+
2224
// Initiations
2325
#[ctor::ctor]
2426
unsafe fn init_xvk() {
2527
println!("XVK_DROID loaded");
26-
let handle = dlopen(SO_PATH.as_ptr(), RTLD_NOW as i32);
28+
HANDLE = dlopen(SO_PATH.as_ptr(), RTLD_NOW as i32);
2729
// let get_pfn = dlsym(handle, c"vkGetInstanceProcAddr".as_ptr());
28-
init::init(handle);
30+
init::init(HANDLE);
2931
export::init();
3032
}
33+
34+
#[ctor::dtor]
35+
unsafe fn fini_xvk() {
36+
dlclose(HANDLE);
37+
}

0 commit comments

Comments
 (0)