This commit is contained in:
parent
bc94b68c0c
commit
e9ce480f96
10 changed files with 175 additions and 136 deletions
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
use crate::vulkan::{VkInstance, VkPhysicalDevice, LOG_TARGET};
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk;
|
||||
use std::sync::Arc;
|
||||
use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
||||
|
||||
pub struct VkSurface {
|
||||
|
@ -10,11 +10,9 @@ pub struct VkSurface {
|
|||
}
|
||||
|
||||
impl VkSurface {
|
||||
pub fn new(
|
||||
window: &crate::display::Window,
|
||||
instance: Arc<VkInstance>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let window_handle = window.handle()
|
||||
pub fn new(window: &crate::display::Window, instance: Arc<VkInstance>) -> anyhow::Result<Self> {
|
||||
let window_handle = window
|
||||
.handle()
|
||||
.ok_or_else(|| anyhow::anyhow!("Window handle is not available."))?;
|
||||
|
||||
let surface = unsafe {
|
||||
|
@ -29,42 +27,48 @@ impl VkSurface {
|
|||
|
||||
log::debug!(target: LOG_TARGET, "Surface created ({:?})", surface);
|
||||
|
||||
Ok(Self {
|
||||
instance,
|
||||
surface,
|
||||
})
|
||||
Ok(Self { instance, surface })
|
||||
}
|
||||
|
||||
pub fn physical_device_queue_supported(&self, physical_device: &VkPhysicalDevice, queue_index: u32) -> VkResult<bool> {
|
||||
pub fn physical_device_queue_supported(
|
||||
&self,
|
||||
physical_device: &VkPhysicalDevice,
|
||||
queue_index: u32,
|
||||
) -> VkResult<bool> {
|
||||
unsafe {
|
||||
self.instance.surface_loader.get_physical_device_surface_support(
|
||||
physical_device.handle,
|
||||
queue_index,
|
||||
self.surface,
|
||||
)
|
||||
self.instance
|
||||
.surface_loader
|
||||
.get_physical_device_surface_support(
|
||||
physical_device.handle,
|
||||
queue_index,
|
||||
self.surface,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_physical_device_surface_infos(&self, physical_device: &VkPhysicalDevice) -> VkResult<(
|
||||
pub fn get_physical_device_surface_infos(
|
||||
&self,
|
||||
physical_device: &VkPhysicalDevice,
|
||||
) -> VkResult<(
|
||||
Vec<vk::SurfaceFormatKHR>,
|
||||
vk::SurfaceCapabilitiesKHR,
|
||||
Vec<vk::PresentModeKHR>
|
||||
Vec<vk::PresentModeKHR>,
|
||||
)> {
|
||||
unsafe {
|
||||
let formats = self.instance.surface_loader.get_physical_device_surface_formats(
|
||||
physical_device.handle,
|
||||
self.surface,
|
||||
)?;
|
||||
let formats = self
|
||||
.instance
|
||||
.surface_loader
|
||||
.get_physical_device_surface_formats(physical_device.handle, self.surface)?;
|
||||
|
||||
let capabilities = self.instance.surface_loader.get_physical_device_surface_capabilities(
|
||||
physical_device.handle,
|
||||
self.surface,
|
||||
)?;
|
||||
let capabilities = self
|
||||
.instance
|
||||
.surface_loader
|
||||
.get_physical_device_surface_capabilities(physical_device.handle, self.surface)?;
|
||||
|
||||
let present_modes = self.instance.surface_loader.get_physical_device_surface_present_modes(
|
||||
physical_device.handle,
|
||||
self.surface,
|
||||
)?;
|
||||
let present_modes = self
|
||||
.instance
|
||||
.surface_loader
|
||||
.get_physical_device_surface_present_modes(physical_device.handle, self.surface)?;
|
||||
|
||||
Ok((formats, capabilities, present_modes))
|
||||
}
|
||||
|
@ -74,8 +78,10 @@ impl VkSurface {
|
|||
impl Drop for VkSurface {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
self.instance.surface_loader.destroy_surface(self.surface, None);
|
||||
self.instance
|
||||
.surface_loader
|
||||
.destroy_surface(self.surface, None);
|
||||
}
|
||||
log::debug!(target: LOG_TARGET, "Surface destroyed ({:?})", self.surface);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue