log: Remove vulkan target
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-17 15:40:30 +01:00
parent fc4a856048
commit 891835c4af
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
8 changed files with 52 additions and 50 deletions

View file

@ -1,4 +1,4 @@
use winit::event_loop::EventLoop;
use winit::event_loop::{ControlFlow, EventLoop};
mod display;
mod vulkan;
@ -7,7 +7,8 @@ fn main() {
env_logger::init();
let event_loop = EventLoop::new().unwrap();
event_loop.set_control_flow(ControlFlow::Poll);
let window_attributes = winit::window::Window::default_attributes()
.with_title("Rust ASH Test")
.with_inner_size(winit::dpi::PhysicalSize::new(
@ -18,5 +19,5 @@ fn main() {
let window = display::Window::new(window_attributes);
let mut app = display::App::new(window);
let _ = event_loop.run_app(&mut app);
event_loop.run_app(&mut app).unwrap();
}

View file

@ -1,5 +1,3 @@
pub(self) const LOG_TARGET: &str = "app::vulkan";
pub(self) mod vk_render_context;
pub use vk_render_context::VkRenderContext;

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkInstance, VkPhysicalDevice, LOG_TARGET};
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;
@ -46,7 +46,7 @@ impl VkDevice {
.handle
.create_device(physical_device.handle, &device_create_info, None)?
};
log::debug!(target: LOG_TARGET, "Device created ({:?})", device.handle());
log::debug!("Device created ({:?})", device.handle());
let queues = queues_priorities
.iter()
@ -127,7 +127,7 @@ impl Drop for VkDevice {
fn drop(&mut self) {
unsafe {
self.handle.destroy_device(None);
log::debug!(target: LOG_TARGET, "Device destroyed ({:?})", self.handle.handle());
log::debug!("Device destroyed ({:?})", self.handle.handle());
}
}
}

View file

@ -1,5 +1,5 @@
use crate::vulkan::utils::layers::{use_layers, LayersSelector};
use crate::vulkan::{VkPhysicalDevice, LOG_TARGET};
use crate::vulkan::VkPhysicalDevice;
use ash::khr::surface;
use ash::{vk, Entry, Instance};
use std::ffi::{c_char, CStr, CString};
@ -14,9 +14,9 @@ impl VkInstance {
pub fn new(required_extensions: &Vec<*const c_char>) -> Self {
let entry = Entry::linked();
log::debug!(target: LOG_TARGET, "Initializing Vulkan instance");
log::debug!("Initializing Vulkan instance");
if log::log_enabled!(target: LOG_TARGET, log::Level::Debug) {
if log::log_enabled!(log::Level::Debug) {
let layer_properties =
unsafe { entry.enumerate_instance_layer_properties() }.unwrap_or_default();
@ -27,7 +27,7 @@ impl VkInstance {
)
}
.unwrap_or_default();
log::debug!(target: LOG_TARGET, "{layer_property:#?} {layer_extensions:#?}");
log::debug!("{layer_property:#?} {layer_extensions:#?}");
}
}
@ -37,7 +37,10 @@ impl VkInstance {
.map(|str| unsafe { CStr::from_ptr(*str) })
.map(|cstr| cstr.to_string_lossy())
.collect::<Vec<_>>();
log::debug!(target: LOG_TARGET, "Required instance extensions: {}", required_extensions.join(", "));
log::debug!(
"Required instance extensions: {}",
required_extensions.join(", ")
);
}
// Layers
@ -58,7 +61,7 @@ impl VkInstance {
.iter()
.map(|layer| layer.to_string_lossy())
.collect::<Vec<_>>();
log::debug!(target: LOG_TARGET, "Selected debug layers : {}", layers.join(", "))
log::debug!("Selected debug layers : {}", layers.join(", "))
}
let layers_raw = layers.iter().map(|s| s.as_ptr()).collect::<Vec<_>>();
@ -93,7 +96,7 @@ impl VkInstance {
let surface_loader = surface::Instance::new(&entry, &instance);
log::debug!(target: LOG_TARGET, "Vulkan instance created ({:?})", instance.handle());
log::debug!("Vulkan instance created ({:?})", instance.handle());
Self {
entry,
@ -117,6 +120,6 @@ impl Drop for VkInstance {
unsafe {
self.handle.destroy_instance(None);
}
log::debug!(target: LOG_TARGET, "Vulkan instance destroyed ({:?})", self.handle.handle());
log::debug!("Vulkan instance destroyed ({:?})", self.handle.handle());
}
}

View file

@ -1,5 +1,4 @@
use crate::vulkan::vk_surface::VkSurface;
use crate::vulkan::LOG_TARGET;
use ash::vk;
pub struct VkPhysicalDevice {
@ -12,14 +11,14 @@ pub struct VkPhysicalDevice {
impl VkPhysicalDevice {
pub fn new(instance: &ash::Instance, physical_device: vk::PhysicalDevice) -> Self {
log::debug!(target: LOG_TARGET, "New physical device");
log::debug!("New physical device");
let device_properties = unsafe { instance.get_physical_device_properties(physical_device) };
log::debug!(target: LOG_TARGET, "{device_properties:#?}");
log::debug!("{device_properties:#?}");
let device_features = unsafe { instance.get_physical_device_features(physical_device) };
log::debug!(target: LOG_TARGET, "{device_features:#?}");
log::debug!("{device_features:#?}");
let device_queue_families =
unsafe { instance.get_physical_device_queue_family_properties(physical_device) };
log::debug!(target: LOG_TARGET, "{device_queue_families:#?}");
log::debug!("{device_queue_families:#?}");
Self {
handle: physical_device,

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain, LOG_TARGET};
use crate::vulkan::{VkDevice, VkInstance, VkPhysicalDevice, VkSurface, VkSwapchain};
use ash::vk;
use std::sync::Arc;
@ -39,7 +39,10 @@ impl VkRenderContext {
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());
log::debug!(
"Selected queue {properties:#?} for physical device {:?}",
physical_device.properties.device_name_as_c_str()
);
let device = Arc::new(VkDevice::new_graphics_device(
instance.clone(),

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkInstance, VkPhysicalDevice, LOG_TARGET};
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;
@ -31,7 +31,7 @@ impl VkSurface {
)?
};
log::debug!(target: LOG_TARGET, "Surface created ({:?})", surface);
log::debug!("Surface created ({:?})", surface);
Ok(Self { instance, surface })
}
@ -88,6 +88,6 @@ impl Drop for VkSurface {
.surface_loader
.destroy_surface(self.surface, None);
}
log::debug!(target: LOG_TARGET, "Surface destroyed ({:?})", self.surface);
log::debug!("Surface destroyed ({:?})", self.surface);
}
}

View file

@ -1,6 +1,6 @@
use crate::display::Window;
use crate::vulkan::vk_surface::SwapchainSupportDetails;
use crate::vulkan::{VkDevice, VkPhysicalDevice, VkSurface, LOG_TARGET};
use crate::vulkan::{VkDevice, VkPhysicalDevice, VkSurface};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;
@ -28,7 +28,7 @@ impl VkSwapchain {
device: Arc<VkDevice>,
physical_device: &VkPhysicalDevice,
) -> anyhow::Result<Self> {
log::debug!(target: LOG_TARGET, "Creating swapchain");
log::debug!("Creating swapchain");
let window_size = window
.physical_size::<u32>()
@ -39,15 +39,15 @@ impl VkSwapchain {
})
})
.ok_or_else(|| anyhow::anyhow!("Failed to get swapchain extent"))?;
log::debug!(target: LOG_TARGET, "Window size ({}x{})", window_size.width, window_size.height);
log::debug!("Window size ({}x{})", window_size.width, window_size.height);
let swapchain_support_details =
surface.get_physical_device_swapchain_support_details(physical_device)?;
let SwapchainSupportDetails(surface_formats, surface_capabilities, present_modes) =
&swapchain_support_details;
log::debug!(target: LOG_TARGET, "Supported surface formats by physical device: {surface_formats:#?}");
log::debug!(target: LOG_TARGET, "Surface capabilities: {surface_capabilities:#?}");
log::debug!(target: LOG_TARGET, "Present modes: {present_modes:#?}");
log::debug!("Supported surface formats by physical device: {surface_formats:#?}");
log::debug!("Surface capabilities: {surface_capabilities:#?}");
log::debug!("Present modes: {present_modes:#?}");
let surface_format = Self::choose_surface_format(surface_formats)
.ok_or_else(|| anyhow::anyhow!("No available surface formats"))?;
@ -102,12 +102,12 @@ impl VkSwapchain {
})
.collect::<Vec<_>>();
if log::log_enabled!(target: LOG_TARGET, log::Level::Debug) {
if log::log_enabled!(log::Level::Debug) {
let label = match self.swapchain {
None => "Swapchain created",
Some(_) => "Swapchain updated",
};
log::debug!(target: LOG_TARGET, "{label} ({swapchain:?}) : {swapchain_create_info:#?}");
log::debug!("{label} ({swapchain:?}) : {swapchain_create_info:#?}");
}
self.swapchain = Some(swapchain);
@ -118,7 +118,7 @@ impl VkSwapchain {
}
pub(super) fn update_resolution(&mut self, width: u32, height: u32) -> VkResult<()> {
log::debug!(target: LOG_TARGET, "New resolution requested ({width}x{height})");
log::debug!("New resolution requested ({width}x{height})");
let chosen_extent = Self::choose_swapchain_extent(
vk::Extent2D { width, height },
@ -128,11 +128,15 @@ impl VkSwapchain {
|| chosen_extent.height != self.surface_resolution.height
{
self.surface_resolution = chosen_extent;
log::debug!(target: LOG_TARGET, "New resolution applied ({}x{})", chosen_extent.width, chosen_extent.height);
log::debug!(
"New resolution applied ({}x{})",
chosen_extent.width,
chosen_extent.height
);
self.create_swapchain()?;
} else {
log::debug!(target: LOG_TARGET, "New resolution skipped ({width}x{height}) : Same resolution");
log::debug!("New resolution skipped ({width}x{height}) : Same resolution");
}
Ok(())
@ -171,16 +175,12 @@ impl VkSwapchain {
}
fn choose_surface_format(
surface_formats: &Vec<vk::SurfaceFormatKHR>
surface_formats: &Vec<vk::SurfaceFormatKHR>,
) -> Option<vk::SurfaceFormatKHR> {
surface_formats
.first()
.and_then(|f| Some(*f))
surface_formats.first().and_then(|f| Some(*f))
}
fn choose_desired_image_count(
surface_capabilities: &vk::SurfaceCapabilitiesKHR
) -> u32 {
fn choose_desired_image_count(surface_capabilities: &vk::SurfaceCapabilitiesKHR) -> u32 {
let mut desired_image_count = surface_capabilities.min_image_count + 1;
if surface_capabilities.max_image_count > 0
&& desired_image_count > surface_capabilities.max_image_count
@ -191,7 +191,7 @@ impl VkSwapchain {
}
fn choose_pre_transform(
surface_capabilities: &vk::SurfaceCapabilitiesKHR
surface_capabilities: &vk::SurfaceCapabilitiesKHR,
) -> vk::SurfaceTransformFlagsKHR {
if surface_capabilities
.supported_transforms
@ -202,10 +202,8 @@ impl VkSwapchain {
surface_capabilities.current_transform
}
}
fn choose_present_mode(
present_modes: &Vec<vk::PresentModeKHR>
) -> vk::PresentModeKHR {
fn choose_present_mode(present_modes: &Vec<vk::PresentModeKHR>) -> vk::PresentModeKHR {
present_modes
.iter()
.cloned()
@ -223,7 +221,7 @@ impl Drop for VkSwapchain {
.destroy_swapchain(swapchain, None);
}
self.swapchain = None;
log::debug!(target: LOG_TARGET, "Swapchain destroyed ({swapchain:?})");
log::debug!("Swapchain destroyed ({swapchain:?})");
}
}
}