Skip to main content

impeller_hal_vulkan/
hal.rs

1//! The backend's implementation of the rendering HAL.
2//!
3//! Thin by design: every method forwards to an inherent method on
4//! [`VulkanContext`]. Keeping the concrete API usable directly matters for
5//! bring-up and for tests that need backend specifics, while the trait is what
6//! the renderer and the conformance harness talk to.
7
8use crate::device::VulkanContext;
9use crate::fence::VulkanFence;
10use crate::resource::VulkanTexture;
11use impeller_hal::{
12    Batch, Capabilities, Extent2D, Hal, HalContext, HalTexture, Modifier, PassDescriptor,
13    PixelFormat, Result, TextureDescriptor,
14};
15
16/// Marker naming the Vulkan backend's family of types.
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct VulkanHal;
19
20impl Hal for VulkanHal {
21    type Context = VulkanContext;
22    type Texture = VulkanTexture;
23    type Fence = VulkanFence;
24
25    const NAME: &'static str = "vulkan";
26}
27
28impl HalTexture for VulkanTexture {
29    fn extent(&self) -> Extent2D {
30        VulkanTexture::extent(self)
31    }
32
33    fn format(&self) -> PixelFormat {
34        VulkanTexture::format(self)
35    }
36}
37
38impl HalContext for VulkanContext {
39    type Hal = VulkanHal;
40
41    fn capabilities(&self) -> &Capabilities {
42        VulkanContext::capabilities(self)
43    }
44
45    fn create_texture(&mut self, desc: &TextureDescriptor) -> Result<VulkanTexture> {
46        VulkanContext::create_texture(self, desc)
47    }
48
49    fn destroy_texture(&mut self, texture: VulkanTexture) {
50        VulkanContext::destroy_texture(self, texture)
51    }
52
53    fn register_program(&mut self, program: &impeller_hal::RuntimeProgram) -> Result<u32> {
54        VulkanContext::register_program(self, program)
55    }
56
57    fn submit_batch(
58        &mut self,
59        target: &mut VulkanTexture,
60        batch: &Batch,
61        pass: PassDescriptor,
62    ) -> Result<()> {
63        VulkanContext::submit_batch(self, target, batch, pass)
64    }
65
66    fn submit_batch_textured(
67        &mut self,
68        target: &mut VulkanTexture,
69        batch: &Batch,
70        pass: PassDescriptor,
71        textures: &[&VulkanTexture],
72    ) -> Result<()> {
73        VulkanContext::submit_batch_textured(self, target, batch, pass, textures)
74    }
75
76    fn read_texture(&mut self, texture: &mut VulkanTexture) -> Result<Vec<u8>> {
77        VulkanContext::read_texture(self, texture)
78    }
79
80    fn write_texture(&mut self, texture: &mut VulkanTexture, pixels: &[u8]) -> Result<()> {
81        VulkanContext::write_texture(self, texture, pixels)
82    }
83
84    fn create_exportable_texture(
85        &mut self,
86        extent: Extent2D,
87        format: PixelFormat,
88        modifiers: &[Modifier],
89    ) -> Result<VulkanTexture> {
90        VulkanContext::create_exportable_texture(self, extent, format, modifiers)
91    }
92
93    #[cfg(unix)]
94    fn export_texture(
95        &mut self,
96        texture: &VulkanTexture,
97    ) -> Result<impeller_hal::ExternalImageDesc> {
98        VulkanContext::export_texture(self, texture)
99    }
100
101    fn submit_batch_deferred_textured(
102        &mut self,
103        target: &mut VulkanTexture,
104        batch: &Batch,
105        pass: PassDescriptor,
106        textures: &[&VulkanTexture],
107    ) -> Result<VulkanFence> {
108        VulkanContext::submit_batch_deferred_synchronized(
109            self,
110            target,
111            batch,
112            pass,
113            textures,
114            Default::default(),
115        )
116    }
117
118    fn retire_fence(&mut self, fence: VulkanFence) {
119        VulkanContext::retire_fence(self, fence)
120    }
121}