This project provides a way to use safe Rust to write a Vulkan layer.
See CONTRIBUTING.md
for details.
Apache 2.0; see LICENSE
for details.
This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.
-
Install the Rust Android toolchain
rustup target add x86_64-linux-android
-
Set up the linker to use. Add the following lines to the
config.toml
file. I will just use%CARGO_HOME%/config.toml
.[target.x86_64-linux-android] linker = "%NDK_HOME%\\toolchains\\llvm\\prebuilt\\windows-x86_64\\bin\\x86_64-linux-android33-clang"
Note that
%NDK_HOME%
must be expanded to an explicit absolute path, which is usually%LOCALAPPDATA%/Android/Sdk/ndk/<version-number>
. -
If the NDK version is greater than 22, follow this workaround.
-
cargo build --target x86_64-linux-android
.
cargo build
TODO
- Set up
Android.bp
to build in an Android tree.- Upgrade ash in aosp, and remove vulkano, so that we can build from aosp/master.
- Auto-generate the binding from
vk_layer.h
. - Auto-generate the
Layer
trait and the interception code fromvk.xml
. - Use an attribute macro to track which function is implemented in the
Layer
trait, and don't inject all other functions for performance. - Make global instance trivially destructible after all instances are destroyed, so the layer is robust against the situation where the dynamic library is loaded and unloaded for several times.
- Use procedure macro to generate the export functions in
lib.rs
file for the layer user. - Use the cargo-make workflow to generate the layer json files for examples.
- Support the latest layer interface version. Currently 2 is the latest version. e.g.
correctly handle the
vk_layerGetPhysicalDeviceProcAddr
case. - Allow intercepting pre-instance functions.
- Add docstring to generated
layer_trait.rs
file. - Testing
- e2e test: the test boundary is the Vulkan layer ABI. The Vulkan loader and the mock ICD
will be used for testing. Write a
cdylib
crate namedtests
, with a layer that is allowed to customize the behavior through a function exported as a dynamic library symbol. We run different tests in different processes. For different tests, we customize the layer differently, and asserts either inside the customization point or after it returns, e.g. to test initialization and destruction on DLL loading and unloading time, we can customize the ctor and the drop implementation for the layer, then load and unload the Vulkan library then verify if the ctor is called the same time as the drop. We also need to create ae2e
task to build the DLL, generate the json, set the environment variables, and spawn tests in different processes(cargo-nextest can be used here since it runs tests in their own process). -
vulkan-layer
level integration test
- e2e test: the test boundary is the Vulkan layer ABI. The Vulkan loader and the mock ICD
will be used for testing. Write a
- catch unwind at the FFI boundary to allow the library to be compiled with
panic="unwind"
. - Improve Miri test
- Check why fp comparison in miri fails in test_should_move_layer_device_link_forward, test_should_move_layer_device_link_forward, and test_should_return_fp_for_get_instance_proc_addr.