Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for vulkan #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
ffmpeg_version: ['3.3', '3.4', '4.0', '4.1', '4.2', '4.3', '4.4', '5.0', '5.1', '6.0', '6.1', '7.0']
fail-fast: false
env:
FEATURES: avcodec,avdevice,avfilter,avformat,postproc,swresample,swscale
FEATURES: avcodec,avdevice,avfilter,avformat,postproc,swresample,swscale,vulkan
steps:
- uses: actions/checkout@v2
- name: Install dependencies
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
env:
FEATURES: avcodec,avdevice,avfilter,avformat,swresample,swscale #,postproc
FEATURES: avcodec,avdevice,avfilter,avformat,swresample,swscale,vulkan #,postproc
FFMPEG_DIR: /home/runner/work/rust-ffmpeg-sys/rust-ffmpeg-sys/ffmpeg-7.1-linux-clang-default
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ doctest = false

[dependencies]
libc = "0.2"
ash = { version = "0.38.0", optional = true}

[build-dependencies]
num_cpus = "1.16"
Expand Down Expand Up @@ -109,3 +110,4 @@ avresample = []
postproc = []
swresample = []
swscale = []
vulkan = ["ash"]
15 changes: 15 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,11 @@ fn main() {
.blocklist_function("y0l")
.blocklist_function("y1l")
.blocklist_function("ynl")
.blocklist_file("vulkan.h")
.blocklist_type("^Vk[A-Z].*")
.blocklist_function("^vk[A-Z].*")
.blocklist_type("^PFN_vk[A-Z].*")
.blocklist_var("^VK_.*")
.opaque_type("__mingw_ldbl_type_t")
.default_enum_style(bindgen::EnumVariation::Rust {
non_exhaustive: env::var("CARGO_FEATURE_NON_EXHAUSTIVE_ENUMS").is_ok(),
Expand Down Expand Up @@ -1363,6 +1368,16 @@ fn main() {
builder = builder.header(hwcontext_drm_header);
}

if env::var("CARGO_FEATURE_VULKAN").is_ok() {
if let Some(hwcontext_vulkan_header) =
maybe_search_include(&include_paths, "libavutil/hwcontext_vulkan.h")
{
builder = builder.header(hwcontext_vulkan_header);
} else {
panic!("vulkan feature asked for but no vulkan header?");
}
}

// Finish the builder and generate the bindings.
let bindings = builder
.generate()
Expand Down
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@

extern crate libc;

#[cfg(feature = "vulkan")]
extern crate ash;

#[cfg(feature = "vulkan")]
use ash::vk::{
AccessFlags as VkAccessFlagBits, Device as VkDevice, DeviceMemory as VkDeviceMemory,
Format as VkFormat, Image as VkImage, ImageCreateFlags as VkImageCreateFlags,
ImageLayout as VkImageLayout, ImageTiling as VkImageTiling,
ImageUsageFlags as VkImageUsageFlagBits, Instance as VkInstance,
MemoryPropertyFlags as VkMemoryPropertyFlagBits, PFN_vkGetInstanceProcAddr,
PhysicalDevice as VkPhysicalDevice, QueueFlags as VkQueueFlagBits, Semaphore as VkSemaphore,
VideoCodecOperationFlagsKHR as VkVideoCodecOperationFlagBitsKHR,
};

// the generated bindgen structs need these types that have lifetimes in them,
// but there is no way within bindgen to propagate those lifetimes out into the structs
// that contain these structs
//
// so, just put 'static to let it compile. Making sure the lifetimes are actually
// check out nicely is now part of the checks an author must do when using the unsafe
// functions that take in these structs or any other structs that contain them.

#[cfg(feature = "vulkan")]
type VkAllocationCallbacks = ash::vk::AllocationCallbacks<'static>;
#[cfg(feature = "vulkan")]
type VkPhysicalDeviceFeatures2 = ash::vk::PhysicalDeviceFeatures2<'static>;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

#[macro_use]
Expand Down