pmse_render/vulkan/
vulkan_host.rs

1//! 初始化后的 vulkan
2use std::sync::Arc;
3
4use vulkano::{
5    command_buffer::allocator::{
6        StandardCommandBufferAllocator, StandardCommandBufferAllocatorCreateInfo,
7    },
8    device::{physical::PhysicalDevice, Device, Queue},
9    memory::allocator::StandardMemoryAllocator,
10    swapchain::Surface,
11};
12
13/// vulkan 宿主
14#[derive(Debug, Clone)]
15pub struct PmseRenderHost {
16    /// 物理设备
17    p: Arc<PhysicalDevice>,
18    /// vulkan 设备
19    d: Arc<Device>,
20    /// vulkan 队列
21    q: Arc<Queue>,
22    /// 内存分配器
23    ma: Arc<StandardMemoryAllocator>,
24    /// 窗口表面
25    s: Arc<Surface>,
26}
27
28impl PmseRenderHost {
29    pub(crate) fn new(
30        p: Arc<PhysicalDevice>,
31        d: Arc<Device>,
32        q: Arc<Queue>,
33        ma: Arc<StandardMemoryAllocator>,
34        s: Arc<Surface>,
35    ) -> Self {
36        Self { p, d, q, ma, s }
37    }
38
39    /// vulkan PhysicalDevice
40    pub fn p(&self) -> &Arc<PhysicalDevice> {
41        &self.p
42    }
43
44    /// vulkan Device
45    pub fn d(&self) -> &Arc<Device> {
46        &self.d
47    }
48
49    /// vulkan Queue
50    pub fn q(&self) -> &Arc<Queue> {
51        &self.q
52    }
53
54    /// 内存分配器
55    pub fn ma(&self) -> &Arc<StandardMemoryAllocator> {
56        &self.ma
57    }
58
59    /// vulkan Surface
60    pub fn s(&self) -> &Arc<Surface> {
61        &self.s
62    }
63
64    /// 创建 命令缓冲区 分配器
65    pub fn ca(&self) -> StandardCommandBufferAllocator {
66        StandardCommandBufferAllocator::new(
67            self.d.clone(),
68            StandardCommandBufferAllocatorCreateInfo::default(),
69        )
70    }
71}