wgpu_hal/vulkan/
pnext_chain.rs

1use core::ffi::c_void;
2
3use ash::vk;
4
5/// A caller-provided `pNext` chain, stashed by one of the `set_next_*_chain`
6/// setters until the Vulkan call that consumes it.
7pub(crate) struct PnextChain(*mut vk::BaseOutStructure<'static>);
8
9// SAFETY: The pointer is only dereferenced at the Vulkan call that consumes the
10// chain. Each setter's contract keeps the chain valid and unaliased until then.
11unsafe impl Send for PnextChain {}
12unsafe impl Sync for PnextChain {}
13
14impl PnextChain {
15    /// Wraps the raw chain pointer that a `set_next_*_chain` setter received.
16    pub(crate) fn new(chain: *mut c_void) -> Self {
17        Self(chain.cast())
18    }
19
20    /// Splices this chain in front of `existing`, the current `p_next` of a
21    /// Vulkan info struct, and returns the new chain head.
22    ///
23    /// # Safety
24    ///
25    /// The chain must still be valid, and the info struct must be passed to the
26    /// Vulkan call that consumes the chain.
27    pub(crate) unsafe fn splice_into(self, existing: *const c_void) -> *const c_void {
28        unsafe {
29            let mut tail = self.0;
30            while !(*tail).p_next.is_null() {
31                tail = (*tail).p_next;
32            }
33            (*tail).p_next = existing.cast_mut().cast();
34        }
35        self.0.cast()
36    }
37}