Skip to content

Commit 5cb4e4d

Browse files
committed
add support for vulkan
use `ash` for the vulkan types
1 parent a13516c commit 5cb4e4d

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ doctest = false
1717

1818
[dependencies]
1919
libc = "0.2"
20+
ash = { version = "0.38.0", optional = true}
2021

2122
[build-dependencies]
2223
num_cpus = "1.16"
@@ -109,3 +110,4 @@ avresample = []
109110
postproc = []
110111
swresample = []
111112
swscale = []
113+
vulkan = ["ash"]

build.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,11 @@ fn main() {
12441244
.blocklist_function("y0l")
12451245
.blocklist_function("y1l")
12461246
.blocklist_function("ynl")
1247+
.blocklist_file("vulkan.h")
1248+
.blocklist_type("^Vk[A-Z].*")
1249+
.blocklist_function("^vk[A-Z].*")
1250+
.blocklist_type("^PFN_vk[A-Z].*")
1251+
.blocklist_var("^VK_.*")
12471252
.opaque_type("__mingw_ldbl_type_t")
12481253
.default_enum_style(bindgen::EnumVariation::Rust {
12491254
non_exhaustive: env::var("CARGO_FEATURE_NON_EXHAUSTIVE_ENUMS").is_ok(),
@@ -1363,6 +1368,16 @@ fn main() {
13631368
builder = builder.header(hwcontext_drm_header);
13641369
}
13651370

1371+
if env::var("CARGO_FEATURE_VULKAN").is_ok() {
1372+
if let Some(hwcontext_vulkan_header) =
1373+
maybe_search_include(&include_paths, "libavutil/hwcontext_vulkan.h")
1374+
{
1375+
builder = builder.header(hwcontext_vulkan_header);
1376+
} else {
1377+
panic!("vulkan feature asked for but no vulkan header?");
1378+
}
1379+
}
1380+
13661381
// Finish the builder and generate the bindings.
13671382
let bindings = builder
13681383
.generate()

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,29 @@
99

1010
extern crate libc;
1111

12+
#[cfg(feature = "vulkan")]
13+
extern crate ash;
14+
15+
#[cfg(feature = "vulkan")]
16+
use ash::vk::{
17+
Device as VkDevice, Format as VkFormat, Image as VkImage,
18+
ImageCreateFlags as VkImageCreateFlags, ImageTiling as VkImageTiling,
19+
ImageUsageFlags as VkImageUsageFlagBits, Instance as VkInstance, PFN_vkGetInstanceProcAddr,
20+
PhysicalDevice as VkPhysicalDevice,
21+
DeviceMemory as VkDeviceMemory,
22+
MemoryPropertyFlags as VkMemoryPropertyFlagBits,
23+
AccessFlags as VkAccessFlagBits,
24+
ImageLayout as VkImageLayout,
25+
Semaphore as VkSemaphore,
26+
QueueFlags as VkQueueFlagBits,
27+
VideoCodecOperationFlagsKHR as VkVideoCodecOperationFlagBitsKHR
28+
};
29+
30+
#[cfg(feature = "vulkan")]
31+
type VkAllocationCallbacks = ash::vk::AllocationCallbacks<'static>; // hack!
32+
#[cfg(feature = "vulkan")]
33+
type VkPhysicalDeviceFeatures2 = ash::vk::PhysicalDeviceFeatures2<'static>; // hack!
34+
1235
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
1336

1437
#[macro_use]

0 commit comments

Comments
 (0)