diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fcd35ee..c045f82 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 247bd8b..424eb2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ doctest = false [dependencies] libc = "0.2" +ash = { version = "0.38.0", optional = true} [build-dependencies] num_cpus = "1.16" @@ -109,3 +110,4 @@ avresample = [] postproc = [] swresample = [] swscale = [] +vulkan = ["ash"] diff --git a/build.rs b/build.rs index eb81e0c..9274704 100644 --- a/build.rs +++ b/build.rs @@ -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(), @@ -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() diff --git a/src/lib.rs b/src/lib.rs index 532f134..21fd3b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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]