Skip to content

Commit

Permalink
Update ash
Browse files Browse the repository at this point in the history
- Use CStr shorthand for extension_name
- Function pointer structs were separated between instance and device in ash-rs/ash#734
  • Loading branch information
krakow10 committed Jan 6, 2025
1 parent 997f253 commit a9d7c45
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 41 deletions.
77 changes: 60 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ license = "BSD-2-Clause"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ash = { git = "https://github.com/ash-rs/ash", rev="3f5b96b3638a9ff341584e82188c3ba3aa5cb996", version = "0.37.3+1.3.251" }
ash = "0.38.0"
h264-reader = "0.7.0"
thiserror = "1.0.44"
thiserror = "1.0.44"
4 changes: 2 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub enum Error {
#[error("A NUL byte was encountered")]
Nul(#[from] std::ffi::NulError),

#[error("A NUL byte was encountered")]
FromBytesWithNul(#[from] std::ffi::FromBytesWithNulError),
#[error("CStr too large for static array")]
CStrTooLargeForStaticArray(#[from] ash::vk::CStrTooLargeForStaticArray),

#[error("Could not load Vulkan")]
Loading(#[from] ash::LoadingError),
Expand Down
31 changes: 11 additions & 20 deletions src/video/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,21 @@ use crate::allocation::Allocation;
use crate::device::{Device, DeviceShared};
use crate::error::Error;
use crate::video::h264::H264StreamInspector;
use ash::khr::{video_decode_queue::DeviceFn as KhrVideoDecodeQueueDeviceFn, video_queue::DeviceFn as KhrVideoQueueDeviceFn};
use ash::vk;
use ash::vk::{
BindVideoSessionMemoryInfoKHR, ExtensionProperties, Extent2D, Format, KhrVideoDecodeQueueFn, KhrVideoQueueFn,
VideoSessionCreateFlagsKHR, VideoSessionCreateInfoKHR, VideoSessionKHR, VideoSessionMemoryRequirementsKHR,
BindVideoSessionMemoryInfoKHR, ExtensionProperties, Extent2D, Format, VideoSessionCreateFlagsKHR, VideoSessionCreateInfoKHR,
VideoSessionKHR, VideoSessionMemoryRequirementsKHR,
};
use std::ffi::c_char;
use std::iter::zip;
use std::ptr::null;
use std::sync::Arc;

fn extension_name(name: &[u8]) -> [c_char; 256] {
let mut extension_name = [0; 256];

for (y, x) in zip(&mut extension_name, name) {
*y = *x as c_char;
}

extension_name
}

pub(crate) struct VideoSessionShared {
shared_device: Arc<DeviceShared>,
native_queue_fns: KhrVideoQueueFn,
native_decode_queue_fns: KhrVideoDecodeQueueFn,
native_queue_fns: KhrVideoQueueDeviceFn,
native_decode_queue_fns: KhrVideoDecodeQueueDeviceFn,
native_session: VideoSessionKHR,
allocations: Vec<Allocation>,
}
Expand All @@ -39,12 +30,12 @@ impl VideoSessionShared {
let native_instance = shared_instance.native();
let native_entry = shared_instance.native_entry();

let extension_name = extension_name(b"VK_STD_vulkan_video_codec_h264_decode");
let extension_name = c"VK_STD_vulkan_video_codec_h264_decode";
let extension_version = vk::make_api_version(0, 1, 0, 0);

let extensions_names = ExtensionProperties::default()
.spec_version(extension_version)
.extension_name(extension_name);
.extension_name(extension_name)?;

let profiles = stream_inspector.profiles();

Expand All @@ -60,15 +51,15 @@ impl VideoSessionShared {
.std_header_version(&extensions_names);

unsafe {
let queue_fns = KhrVideoQueueFn::load(
let queue_fns = KhrVideoQueueDeviceFn::load(
|x| {
native_entry
.get_instance_proc_addr(native_instance.handle(), x.as_ptr() as *const _)
.expect("Must have function pointer") as *const _
}, // TODO: Is this guaranteed to exist?
);

let decode_queue_fns = KhrVideoDecodeQueueFn::load(
let decode_queue_fns = KhrVideoDecodeQueueDeviceFn::load(
|x| {
native_entry
.get_instance_proc_addr(native_instance.handle(), x.as_ptr() as *const _)
Expand Down Expand Up @@ -131,11 +122,11 @@ impl VideoSessionShared {
self.native_session
}

pub(crate) fn queue_fns(&self) -> KhrVideoQueueFn {
pub(crate) fn queue_fns(&self) -> KhrVideoQueueDeviceFn {
self.native_queue_fns.clone()
}

pub(crate) fn decode_fns(&self) -> KhrVideoDecodeQueueFn {
pub(crate) fn decode_fns(&self) -> KhrVideoDecodeQueueDeviceFn {
self.native_decode_queue_fns.clone()
}

Expand Down

0 comments on commit a9d7c45

Please # to comment.