Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
ffmpeg_version: ["6.1", "7.0", "7.1", "8.0"]
env:
CARGO_PROFILE_DEV_BUILD_OVERRIDE_DEBUG: true
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-${{ matrix.ffmpeg_version }}-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.17"
Expand Down Expand Up @@ -121,3 +122,4 @@ avresample = []
postproc = []
swresample = []
swscale = []
vulkan = ["ash"]
18 changes: 18 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,14 @@ fn main() {
.blocklist_function("y0l")
.blocklist_function("y1l")
.blocklist_function("ynl")
.blocklist_type("^Vk[A-Z].*") // vulkan, use ash instead
.blocklist_function("^vk[A-Z].*") // vulkan, use ash instead
.blocklist_type("^PFN_vk[A-Z].*") // vulkan, use ash instead
.blocklist_type("^StdVideo.*") // vulkan, use ash instead
.blocklist_var("^VK_.*") // vulkan, use ash instead
.blocklist_var("^STD_VIDEO_.*") // vulkan, use ash instead
.blocklist_var("^vulkan_video_codec_.*") // vulkan, use ash instead
.blocklist_var("^VULKAN_VIDEO_CODEC_.*") // vulkan, use ash instead
.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 @@ -1670,6 +1678,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
30 changes: 30 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@

extern crate libc;

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

// ffmpeg used vulkan types in it's headers. Instead of having bindgen generate vulkan.h structs,
// we blocklist them for bindgen then use the ash crate's vulkan bindings instead. This maps themn from the ash names
// to the vulkan.h names
#[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