From 9402e473a0dfdb7856283ebc609e91d6df9f2305 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 13 Oct 2024 02:26:26 -0600 Subject: [PATCH 1/5] add support for vulkan use `ash` for the vulkan types --- Cargo.toml | 2 ++ build.rs | 15 +++++++++++++++ src/lib.rs | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index fa691ce..0bb674e 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.17" @@ -121,3 +122,4 @@ avresample = [] postproc = [] swresample = [] swscale = [] +vulkan = ["ash"] diff --git a/build.rs b/build.rs index 69e563a..65d472e 100644 --- a/build.rs +++ b/build.rs @@ -1541,6 +1541,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(), @@ -1670,6 +1675,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 2dd5d6e..c4a054d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,29 @@ extern crate libc; +#[cfg(feature = "vulkan")] +extern crate ash; + +#[cfg(feature = "vulkan")] +use ash::vk::{ + Device as VkDevice, Format as VkFormat, Image as VkImage, + ImageCreateFlags as VkImageCreateFlags, ImageTiling as VkImageTiling, + ImageUsageFlags as VkImageUsageFlagBits, Instance as VkInstance, PFN_vkGetInstanceProcAddr, + PhysicalDevice as VkPhysicalDevice, + DeviceMemory as VkDeviceMemory, + MemoryPropertyFlags as VkMemoryPropertyFlagBits, + AccessFlags as VkAccessFlagBits, + ImageLayout as VkImageLayout, + Semaphore as VkSemaphore, + QueueFlags as VkQueueFlagBits, + VideoCodecOperationFlagsKHR as VkVideoCodecOperationFlagBitsKHR +}; + +#[cfg(feature = "vulkan")] +type VkAllocationCallbacks = ash::vk::AllocationCallbacks<'static>; // hack! +#[cfg(feature = "vulkan")] +type VkPhysicalDeviceFeatures2 = ash::vk::PhysicalDeviceFeatures2<'static>; // hack! + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); #[macro_use] From 3bfbfc95a10e52508cc8ed81bc24c4addaad9955 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 4 Nov 2024 21:23:17 -0700 Subject: [PATCH 2/5] fmt & better comments --- src/lib.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c4a054d..658ae47 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,23 +17,27 @@ extern crate ash; #[cfg(feature = "vulkan")] use ash::vk::{ - Device as VkDevice, Format as VkFormat, Image as VkImage, - ImageCreateFlags as VkImageCreateFlags, ImageTiling as VkImageTiling, - ImageUsageFlags as VkImageUsageFlagBits, Instance as VkInstance, PFN_vkGetInstanceProcAddr, - PhysicalDevice as VkPhysicalDevice, - DeviceMemory as VkDeviceMemory, - MemoryPropertyFlags as VkMemoryPropertyFlagBits, - AccessFlags as VkAccessFlagBits, - ImageLayout as VkImageLayout, - Semaphore as VkSemaphore, - QueueFlags as VkQueueFlagBits, - VideoCodecOperationFlagsKHR as VkVideoCodecOperationFlagBitsKHR + 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>; // hack! +type VkAllocationCallbacks = ash::vk::AllocationCallbacks<'static>; #[cfg(feature = "vulkan")] -type VkPhysicalDeviceFeatures2 = ash::vk::PhysicalDeviceFeatures2<'static>; // hack! +type VkPhysicalDeviceFeatures2 = ash::vk::PhysicalDeviceFeatures2<'static>; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); From ff4b564de3c3cca2c5e3dac955482ae81c9e12f5 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 4 Nov 2024 21:53:55 -0700 Subject: [PATCH 3/5] attempt at vulkan CI --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 587073d..f7c837d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 From 1222a88a196b0e8db0a8004796ee16950e83d2f0 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sat, 13 Sep 2025 13:20:17 -0600 Subject: [PATCH 4/5] blocklist more vulkan stuff that we don't want --- build.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 65d472e..4ca67b7 100644 --- a/build.rs +++ b/build.rs @@ -1541,11 +1541,14 @@ 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_type("^PFN_vk[A-Z].*") // vulkan.h + .blocklist_type("^StdVideo.*") // vulkan.h .blocklist_var("^VK_.*") + .blocklist_var("^STD_VIDEO_.*") + .blocklist_var("^vulkan_video_codec_.*") + .blocklist_var("^VULKAN_VIDEO_CODEC_.*") .opaque_type("__mingw_ldbl_type_t") .default_enum_style(bindgen::EnumVariation::Rust { non_exhaustive: env::var("CARGO_FEATURE_NON_EXHAUSTIVE_ENUMS").is_ok(), From f72e6c54587a6f4f8733ac2e0d1b7ae928448b3e Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sat, 13 Sep 2025 13:25:43 -0600 Subject: [PATCH 5/5] improve comments --- build.rs | 16 ++++++++-------- src/lib.rs | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 4ca67b7..0e5e50e 100644 --- a/build.rs +++ b/build.rs @@ -1541,14 +1541,14 @@ fn main() { .blocklist_function("y0l") .blocklist_function("y1l") .blocklist_function("ynl") - .blocklist_type("^Vk[A-Z].*") - .blocklist_function("^vk[A-Z].*") - .blocklist_type("^PFN_vk[A-Z].*") // vulkan.h - .blocklist_type("^StdVideo.*") // vulkan.h - .blocklist_var("^VK_.*") - .blocklist_var("^STD_VIDEO_.*") - .blocklist_var("^vulkan_video_codec_.*") - .blocklist_var("^VULKAN_VIDEO_CODEC_.*") + .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(), diff --git a/src/lib.rs b/src/lib.rs index 658ae47..5c90bf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,6 +15,9 @@ 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,