This commit is contained in:
parent
bc94b68c0c
commit
e9ce480f96
10 changed files with 175 additions and 136 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain, LOG_TARGET};
|
||||
use ash::vk;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct VkRenderContext {
|
||||
instance: Arc<VkInstance>,
|
||||
|
@ -8,7 +8,6 @@ pub struct VkRenderContext {
|
|||
device: Arc<VkDevice>,
|
||||
|
||||
swapchain: Arc<VkSwapchain>,
|
||||
|
||||
// present_queue: vk::Queue,
|
||||
//
|
||||
// pool: vk::CommandPool,
|
||||
|
@ -25,32 +24,34 @@ pub struct VkRenderContext {
|
|||
|
||||
impl VkRenderContext {
|
||||
pub fn init(window: &crate::display::Window) -> anyhow::Result<Self> {
|
||||
let required_extensions = window
|
||||
.required_extensions()?;
|
||||
let required_extensions = window.required_extensions()?;
|
||||
|
||||
let instance = Arc::new(VkInstance::new(&required_extensions));
|
||||
let surface = Arc::new(VkSurface::new(
|
||||
&window,
|
||||
instance.clone()
|
||||
)?);
|
||||
let surface = Arc::new(VkSurface::new(&window, instance.clone())?);
|
||||
|
||||
let mut physical_devices = instance.get_physical_devices();
|
||||
physical_devices.sort_by(|a, b| b.priority().cmp(&a.priority()));
|
||||
|
||||
let (physical_device, queue_family_index, properties) = VkPhysicalDevice::pick_physical_device_and_queue_by(
|
||||
&physical_devices,
|
||||
Some(vk::QueueFlags::GRAPHICS),
|
||||
Some(&surface),
|
||||
).ok_or_else(|| anyhow::anyhow!("Unable to find physical device"))?;
|
||||
let (physical_device, queue_family_index, properties) =
|
||||
VkPhysicalDevice::pick_physical_device_and_queue_by(
|
||||
&physical_devices,
|
||||
Some(vk::QueueFlags::GRAPHICS),
|
||||
Some(&surface),
|
||||
)
|
||||
.ok_or_else(|| anyhow::anyhow!("Unable to find physical device"))?;
|
||||
log::debug!(target: LOG_TARGET, "Selected queue {properties:#?} for physical device {:?}", physical_device.properties.device_name_as_c_str());
|
||||
|
||||
let device = Arc::new(VkDevice::new_graphics_device(instance.clone(), &physical_device, queue_family_index)?);
|
||||
let device = Arc::new(VkDevice::new_graphics_device(
|
||||
instance.clone(),
|
||||
&physical_device,
|
||||
queue_family_index,
|
||||
)?);
|
||||
|
||||
let swapchain = Arc::new(VkSwapchain::new(
|
||||
&window,
|
||||
surface.clone(),
|
||||
device.clone(),
|
||||
&physical_device
|
||||
&physical_device,
|
||||
)?);
|
||||
|
||||
// let present_queue = device.get_device_queue(0);
|
||||
|
@ -97,7 +98,6 @@ impl VkRenderContext {
|
|||
device,
|
||||
|
||||
swapchain,
|
||||
|
||||
// present_queue,
|
||||
//
|
||||
// pool,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue