Add log + Cleanup
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s
This commit is contained in:
parent
21195b57e6
commit
bc94b68c0c
8 changed files with 46 additions and 131 deletions
|
@ -28,7 +28,7 @@ impl ApplicationHandler for App {
|
||||||
self.render_context = VkRenderContext::init(&self.window).ok();
|
self.render_context = VkRenderContext::init(&self.window).ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) {
|
fn window_event(&mut self, event_loop: &ActiveEventLoop, _id: WindowId, event: WindowEvent) {
|
||||||
match event {
|
match event {
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
log::debug!("The close button was pressed; stopping");
|
log::debug!("The close button was pressed; stopping");
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use std::ffi::c_char;
|
use std::ffi::c_char;
|
||||||
use winit::event::WindowEvent;
|
|
||||||
use winit::event_loop::ActiveEventLoop;
|
use winit::event_loop::ActiveEventLoop;
|
||||||
use winit::raw_window_handle::HasDisplayHandle;
|
use winit::raw_window_handle::HasDisplayHandle;
|
||||||
use winit::window::WindowId;
|
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
handle: Option<winit::window::Window>,
|
handle: Option<winit::window::Window>,
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
use ash::vk::LayerProperties;
|
|
||||||
|
|
||||||
pub fn format_vulkan_version(version: u32) -> String {
|
|
||||||
format!(
|
|
||||||
"{}.{}.{}",
|
|
||||||
ash::vk::api_version_major(version),
|
|
||||||
ash::vk::api_version_minor(version),
|
|
||||||
ash::vk::api_version_patch(version)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn format_driver_version(vendor_id: u32, driver_version_raw: u32) -> String {
|
|
||||||
if vendor_id == 0x10de { // NVIDIA
|
|
||||||
format!(
|
|
||||||
"{}.{}.{}.{}",
|
|
||||||
(driver_version_raw >> 22) & 0x3ff,
|
|
||||||
(driver_version_raw >> 14) & 0x0ff,
|
|
||||||
(driver_version_raw >> 6) & 0x0ff,
|
|
||||||
(driver_version_raw) & 0x003f
|
|
||||||
)
|
|
||||||
} else if vendor_id == 0x8086 { // Intel
|
|
||||||
format!(
|
|
||||||
"{}.{}",
|
|
||||||
driver_version_raw >> 14,
|
|
||||||
driver_version_raw & 0x3fff
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
format_vulkan_version(driver_version_raw)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn format_instance_layer(instance_layer: &LayerProperties) -> String {
|
|
||||||
let layer_name = instance_layer
|
|
||||||
.layer_name_as_c_str()
|
|
||||||
.and_then(|s| Ok(s.to_string_lossy()))
|
|
||||||
.and_then(|s| Ok(s.to_string()))
|
|
||||||
.unwrap_or(String::from("No layer name"));
|
|
||||||
|
|
||||||
let description = instance_layer
|
|
||||||
.description_as_c_str()
|
|
||||||
.and_then(|s| Ok(s.to_string_lossy()))
|
|
||||||
.and_then(|s| Ok(s.to_string()))
|
|
||||||
.unwrap_or(String::from("No layer name"));
|
|
||||||
|
|
||||||
format!(
|
|
||||||
"Name: {layer_name} Vulkan Version: {} Revision: {} Description: {description}",
|
|
||||||
format_vulkan_version(instance_layer.spec_version),
|
|
||||||
instance_layer.implementation_version,
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,2 +1 @@
|
||||||
pub mod layers;
|
pub mod layers;
|
||||||
pub mod formatter;
|
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
use crate::vulkan::utils::formatter::format_instance_layer;
|
|
||||||
use crate::vulkan::utils::layers::{use_layers, LayersSelector};
|
use crate::vulkan::utils::layers::{use_layers, LayersSelector};
|
||||||
use crate::vulkan::vk_surface::VkSurface;
|
|
||||||
use crate::vulkan::{VkPhysicalDevice, LOG_TARGET};
|
use crate::vulkan::{VkPhysicalDevice, LOG_TARGET};
|
||||||
use ash::khr::surface;
|
use ash::khr::surface;
|
||||||
use ash::prelude::VkResult;
|
|
||||||
use ash::vk::QueueFlags;
|
|
||||||
use ash::{vk, Entry, Instance};
|
use ash::{vk, Entry, Instance};
|
||||||
use std::ffi::{c_char, CStr, CString};
|
use std::ffi::{c_char, CStr, CString};
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
use winit::raw_window_handle::{HasDisplayHandle, HasWindowHandle};
|
|
||||||
|
|
||||||
pub struct VkInstance {
|
pub struct VkInstance {
|
||||||
pub(super) entry: Entry,
|
pub(super) entry: Entry,
|
||||||
|
@ -24,6 +18,17 @@ impl VkInstance {
|
||||||
|
|
||||||
log::debug!(target: LOG_TARGET, "Initializing Vulkan instance");
|
log::debug!(target: LOG_TARGET, "Initializing Vulkan instance");
|
||||||
|
|
||||||
|
if log::log_enabled!(target: LOG_TARGET, log::Level::Debug) {
|
||||||
|
let layer_properties = unsafe { entry.enumerate_instance_layer_properties() }
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
for layer_property in layer_properties {
|
||||||
|
let layer_extensions = unsafe { entry.enumerate_instance_extension_properties(layer_property.layer_name_as_c_str().ok()) }
|
||||||
|
.unwrap_or_default();
|
||||||
|
log::debug!(target: LOG_TARGET, "{layer_property:#?} {layer_extensions:#?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let required_extensions = required_extensions
|
let required_extensions = required_extensions
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -106,25 +111,3 @@ impl Drop for VkInstance {
|
||||||
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed ({:?})", self.handle.handle());
|
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed ({:?})", self.handle.handle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for VkInstance {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
writeln!(f, "")?;
|
|
||||||
|
|
||||||
let instance_layers = unsafe { self.entry.enumerate_instance_layer_properties().unwrap_or_default() };
|
|
||||||
writeln!(f, "Instance layers ({}) :", instance_layers.len())?;
|
|
||||||
for instance_layer in &instance_layers {
|
|
||||||
writeln!(f, "{}", format_instance_layer(instance_layer))?;
|
|
||||||
}
|
|
||||||
writeln!(f, "")?;
|
|
||||||
|
|
||||||
let physical_devices = self.get_physical_devices();
|
|
||||||
writeln!(f, "Physical Devices ({}) :", physical_devices.len())?;
|
|
||||||
for physical_device in physical_devices {
|
|
||||||
writeln!(f, "{physical_device}")?;
|
|
||||||
}
|
|
||||||
writeln!(f, "")?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,7 +1,6 @@
|
||||||
use crate::vulkan::utils::formatter::{format_driver_version, format_vulkan_version};
|
|
||||||
use crate::vulkan::vk_surface::VkSurface;
|
use crate::vulkan::vk_surface::VkSurface;
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
use std::fmt::{Display, Formatter};
|
use crate::vulkan::LOG_TARGET;
|
||||||
|
|
||||||
pub struct VkPhysicalDevice {
|
pub struct VkPhysicalDevice {
|
||||||
// Vulkan properties
|
// Vulkan properties
|
||||||
|
@ -13,10 +12,14 @@ pub struct VkPhysicalDevice {
|
||||||
|
|
||||||
impl VkPhysicalDevice {
|
impl VkPhysicalDevice {
|
||||||
pub fn new(instance: &ash::Instance, physical_device: vk::PhysicalDevice) -> Self {
|
pub fn new(instance: &ash::Instance, physical_device: vk::PhysicalDevice) -> Self {
|
||||||
|
log::debug!(target: LOG_TARGET, "New physical device");
|
||||||
let device_properties = unsafe { instance.get_physical_device_properties(physical_device) };
|
let device_properties = unsafe { instance.get_physical_device_properties(physical_device) };
|
||||||
|
log::debug!(target: LOG_TARGET, "{device_properties:#?}");
|
||||||
let device_features = unsafe { instance.get_physical_device_features(physical_device) };
|
let device_features = unsafe { instance.get_physical_device_features(physical_device) };
|
||||||
|
log::debug!(target: LOG_TARGET, "{device_features:#?}");
|
||||||
let device_queue_families =
|
let device_queue_families =
|
||||||
unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
|
unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
|
||||||
|
log::debug!(target: LOG_TARGET, "{device_queue_families:#?}");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
handle: physical_device,
|
handle: physical_device,
|
||||||
|
@ -82,22 +85,3 @@ impl VkPhysicalDevice {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for VkPhysicalDevice {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let device_name = self.properties
|
|
||||||
.device_name_as_c_str()
|
|
||||||
.and_then(|s| Ok(s.to_string_lossy()))
|
|
||||||
.and_then(|s| Ok(s.to_string()))
|
|
||||||
.unwrap_or(String::from("No device name"));
|
|
||||||
|
|
||||||
writeln!(f, "Nom: {device_name}")?;
|
|
||||||
writeln!(f, "Vendor ID: {:#x}", self.properties.vendor_id)?;
|
|
||||||
writeln!(f, "Device ID: {:#x}", self.properties.device_id)?;
|
|
||||||
writeln!(f, "Driver version: {}", format_driver_version(self.properties.vendor_id, self.properties.driver_version))?;
|
|
||||||
writeln!(f, "Vulkan version: {}", format_vulkan_version(self.properties.api_version))?;
|
|
||||||
writeln!(f, "Device type: {:?}", self.properties.device_type)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain};
|
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain, LOG_TARGET};
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
|
|
||||||
pub struct VkRenderContext {
|
pub struct VkRenderContext {
|
||||||
|
@ -37,11 +37,12 @@ impl VkRenderContext {
|
||||||
let mut physical_devices = instance.get_physical_devices();
|
let mut physical_devices = instance.get_physical_devices();
|
||||||
physical_devices.sort_by(|a, b| b.priority().cmp(&a.priority()));
|
physical_devices.sort_by(|a, b| b.priority().cmp(&a.priority()));
|
||||||
|
|
||||||
let (physical_device, queue_family_index, _) = VkPhysicalDevice::pick_physical_device_and_queue_by(
|
let (physical_device, queue_family_index, properties) = VkPhysicalDevice::pick_physical_device_and_queue_by(
|
||||||
&physical_devices,
|
&physical_devices,
|
||||||
Some(vk::QueueFlags::GRAPHICS),
|
Some(vk::QueueFlags::GRAPHICS),
|
||||||
Some(&surface),
|
Some(&surface),
|
||||||
).ok_or_else(|| anyhow::anyhow!("Unable to find physical device"))?;
|
).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)?);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, LOG_TARGET};
|
use crate::vulkan::{VkDevice, VkPhysicalDevice, VkSurface, LOG_TARGET};
|
||||||
use ash::prelude::VkResult;
|
use ash::prelude::VkResult;
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
use crate::display::Window;
|
use crate::display::Window;
|
||||||
|
|
Loading…
Reference in a new issue