From 48be4f2e72d752efb3fc40c9171125dfc292c9fb Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 13 Oct 2024 02:26:26 -0600 Subject: [PATCH 1/3] 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 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..122e3fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,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 49ef1f265c12149df97c8fcd23bf7a2215012148 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 4 Nov 2024 21:23:17 -0700 Subject: [PATCH 2/3] 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 122e3fe..21fd3b4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,23 +14,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 79d272837d3d3e199087c2d576e7bd1f16aef360 Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Mon, 4 Nov 2024 21:53:55 -0700 Subject: [PATCH 3/3] attempt at vulkan CI --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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