Compare commits

...

2 commits

Author SHA1 Message Date
a669247406
vulkan: Move to renderer module
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
2024-11-27 20:59:39 +01:00
001547dbc2
vulkan: Rename name mistake to handle 2024-11-27 20:48:34 +01:00
21 changed files with 83 additions and 85 deletions

View file

@ -1,5 +1,5 @@
use crate::display::window::Window;
use crate::vulkan::VkRenderContext;
use crate::renderer::vulkan::VkRenderContext;
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::ActiveEventLoop;

View file

@ -1,7 +1,7 @@
use winit::event_loop::{ControlFlow, EventLoop};
mod display;
mod vulkan;
mod renderer;
fn main() {
env_logger::init();

1
src/renderer/mod.rs Normal file
View file

@ -0,0 +1 @@
pub mod vulkan;

View file

@ -0,0 +1,41 @@
mod vk_render_context;
pub use vk_render_context::VkRenderContext;
mod vk_instance;
pub use vk_instance::VkInstance;
mod vk_surface;
pub use vk_surface::{SwapchainSupportDetails, VkSurface};
mod vk_physical_device;
pub use vk_physical_device::VkPhysicalDevice;
mod vk_device;
pub use vk_device::VkDevice;
mod vk_swapchain;
pub use vk_swapchain::VkSwapchain;
mod vk_shader_module;
pub use vk_shader_module::VkShaderModule;
mod vk_graphics_pipeline;
pub use vk_graphics_pipeline::VkGraphicsPipeline;
mod vk_render_pass;
pub use vk_render_pass::VkRenderPass;
mod vk_semaphore;
pub use vk_semaphore::VkSemaphore;
mod vk_command_pool;
pub use vk_command_pool::VkCommandPool;
mod vk_framebuffer;
pub use vk_framebuffer::VkFramebuffer;
mod vk_fence;
pub use vk_fence::VkFence;
mod utils;
mod vertex;

View file

@ -1,4 +1,4 @@
use crate::vulkan::VkDevice;
use super::VkDevice;
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use super::{VkInstance, VkPhysicalDevice};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;

View file

@ -1,4 +1,4 @@
use crate::vulkan::VkDevice;
use super::VkDevice;
use ash::vk;
use std::sync::Arc;

View file

@ -1,5 +1,4 @@
use crate::vulkan::vk_render_pass::VkRenderPass;
use crate::vulkan::{VkDevice, VkSwapchain};
use super::{VkDevice, VkRenderPass, VkSwapchain};
use ash::vk;
use std::sync::Arc;

View file

@ -1,5 +1,4 @@
use crate::vulkan::vk_render_pass::VkRenderPass;
use crate::vulkan::{VkDevice, VkShaderModule, VkSwapchain};
use super::{VkDevice, VkRenderPass, VkShaderModule, VkSwapchain};
use ash::vk;
use std::ffi::CStr;
use std::sync::Arc;
@ -22,7 +21,7 @@ impl VkGraphicsPipeline {
let shader_entry_name = CStr::from_bytes_with_nul(b"main\0")?;
let vert_shader_module =
VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.vert.spv")?;
VkShaderModule::from_spv_file(device, "res/shaders/main.vert.spv")?;
let vert_shader_info = vk::PipelineShaderStageCreateInfo::default()
.module(vert_shader_module.handle)
@ -30,7 +29,7 @@ impl VkGraphicsPipeline {
.stage(vk::ShaderStageFlags::VERTEX);
let frag_shader_module =
VkShaderModule::from_spv_file(device.clone(), "res/shaders/main.frag.spv")?;
VkShaderModule::from_spv_file(device, "res/shaders/main.frag.spv")?;
let frag_shader_info = vk::PipelineShaderStageCreateInfo::default()
.module(frag_shader_module.handle)

View file

@ -1,5 +1,7 @@
use crate::vulkan::utils::layers::{use_layers, LayersSelector};
use crate::vulkan::VkPhysicalDevice;
use crate::renderer::vulkan::{
utils::layers::{use_layers, LayersSelector},
VkPhysicalDevice,
};
use ash::khr::surface;
use ash::{vk, Entry, Instance};
use std::ffi::{c_char, CStr, CString};

View file

@ -1,4 +1,4 @@
use crate::vulkan::vk_surface::VkSurface;
use super::VkSurface;
use ash::vk;
pub struct VkPhysicalDevice {

View file

@ -1,4 +1,4 @@
use crate::vulkan::{
use super::{
VkCommandPool, VkDevice, VkFence, VkFramebuffer, VkGraphicsPipeline, VkInstance, VkPhysicalDevice,
VkRenderPass, VkSemaphore, VkSurface, VkSwapchain,
};
@ -187,7 +187,7 @@ impl VkRenderContext {
.queue_submit(*queue, &[submit_info], self.in_flight_fence.handle)?
};
let swapchains = [self.swapchain.swapchain.unwrap()];
let swapchains = [self.swapchain.handle.unwrap()];
let indices = [index];
let present_info = vk::PresentInfoKHR::default()
.wait_semaphores(&signal_semaphores)

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkDevice, VkSwapchain};
use super::{VkDevice, VkSwapchain};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;

View file

@ -1,4 +1,4 @@
use crate::vulkan::VkDevice;
use super::VkDevice;
use ash::vk;
use std::sync::Arc;

View file

@ -1,4 +1,4 @@
use crate::vulkan::VkDevice;
use super::VkDevice;
use ash::vk;
use std::path::Path;
use std::sync::Arc;
@ -10,7 +10,7 @@ pub struct VkShaderModule {
}
impl VkShaderModule {
pub fn from_spv_file<P: AsRef<Path>>(device: Arc<VkDevice>, path: P) -> anyhow::Result<Self> {
pub fn from_spv_file<P: AsRef<Path>>(device: &Arc<VkDevice>, path: P) -> anyhow::Result<Self> {
let mut file = std::fs::File::open(&path)?;
let frag_shader_str = ash::util::read_spv(&mut file)?;
@ -26,7 +26,7 @@ impl VkShaderModule {
);
Ok(Self {
device,
device: device.clone(),
handle: shader_module,
})
}

View file

@ -1,4 +1,4 @@
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use super::{VkInstance, VkPhysicalDevice};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;
@ -13,7 +13,7 @@ pub struct SwapchainSupportDetails(
pub struct VkSurface {
instance: Arc<VkInstance>,
pub(super) surface: vk::SurfaceKHR,
pub(super) handle: vk::SurfaceKHR,
}
impl VkSurface {
@ -34,7 +34,7 @@ impl VkSurface {
log::debug!("Surface created ({:?})", surface);
Ok(Self { instance, surface })
Ok(Self { instance, handle: surface })
}
pub fn physical_device_queue_supported(
@ -48,7 +48,7 @@ impl VkSurface {
.get_physical_device_surface_support(
physical_device.handle,
queue_index,
self.surface,
self.handle,
)
}
}
@ -61,17 +61,17 @@ impl VkSurface {
let formats = self
.instance
.surface_loader
.get_physical_device_surface_formats(physical_device.handle, self.surface)?;
.get_physical_device_surface_formats(physical_device.handle, self.handle)?;
let capabilities = self
.instance
.surface_loader
.get_physical_device_surface_capabilities(physical_device.handle, self.surface)?;
.get_physical_device_surface_capabilities(physical_device.handle, self.handle)?;
let present_modes = self
.instance
.surface_loader
.get_physical_device_surface_present_modes(physical_device.handle, self.surface)?;
.get_physical_device_surface_present_modes(physical_device.handle, self.handle)?;
Ok(SwapchainSupportDetails(
formats,
@ -87,8 +87,8 @@ impl Drop for VkSurface {
unsafe {
self.instance
.surface_loader
.destroy_surface(self.surface, None);
.destroy_surface(self.handle, None);
}
log::debug!("Surface destroyed ({:?})", self.surface);
log::debug!("Surface destroyed ({:?})", self.handle);
}
}

View file

@ -1,8 +1,5 @@
use super::{SwapchainSupportDetails, VkDevice, VkFramebuffer, VkPhysicalDevice, VkRenderPass, VkSemaphore, VkSurface};
use crate::display::Window;
use crate::vulkan::vk_render_pass::VkRenderPass;
use crate::vulkan::vk_semaphore::VkSemaphore;
use crate::vulkan::vk_surface::SwapchainSupportDetails;
use crate::vulkan::{VkDevice, VkFramebuffer, VkPhysicalDevice, VkSurface};
use ash::prelude::VkResult;
use ash::vk;
use std::sync::Arc;
@ -11,7 +8,7 @@ pub struct VkSwapchain {
surface: Arc<VkSurface>,
device: Arc<VkDevice>,
pub(super) swapchain: Option<vk::SwapchainKHR>,
pub(super) handle: Option<vk::SwapchainKHR>,
swapchain_support_details: SwapchainSupportDetails,
pub(super) desired_image_count: u32,
@ -64,7 +61,7 @@ impl VkSwapchain {
surface: surface.clone(),
device: device.clone(),
swapchain: None,
handle: None,
new_requested_surface_resolution: None,
swapchain_support_details,
desired_image_count,
@ -89,7 +86,7 @@ impl VkSwapchain {
let mut swapchain_create_info = self.create_swapchain_info(&self.surface);
if let Some(old_swapchain) = self.swapchain {
if let Some(old_swapchain) = self.handle {
swapchain_create_info.old_swapchain = old_swapchain;
}
@ -114,14 +111,14 @@ impl VkSwapchain {
.collect::<Vec<_>>();
if log::log_enabled!(log::Level::Debug) {
let label = match self.swapchain {
let label = match self.handle {
None => "Swapchain created",
Some(_) => "Swapchain updated",
};
log::debug!("{label} ({swapchain:?}) : {swapchain_create_info:#?}");
}
self.swapchain = Some(swapchain);
self.handle = Some(swapchain);
self.present_image_views = Some(present_images_view);
self.present_images = Some(present_images);
@ -177,7 +174,7 @@ impl VkSwapchain {
pub(super) fn acquire_next_image(&self, semaphore: &VkSemaphore) -> VkResult<(u32, bool)> {
unsafe {
self.device.swapchain_loader.acquire_next_image(
self.swapchain.unwrap(),
self.handle.unwrap(),
u64::MAX,
semaphore.handle,
vk::Fence::null(),
@ -191,7 +188,7 @@ impl VkSwapchain {
fn create_swapchain_info(&self, surface: &VkSurface) -> vk::SwapchainCreateInfoKHR {
vk::SwapchainCreateInfoKHR::default()
.surface(surface.surface)
.surface(surface.handle)
.min_image_count(self.desired_image_count)
.image_color_space(self.surface_format.color_space)
.image_format(self.surface_format.format)
@ -287,13 +284,13 @@ impl VkSwapchain {
impl Drop for VkSwapchain {
fn drop(&mut self) {
if let Some(swapchain) = self.swapchain {
if let Some(swapchain) = self.handle {
unsafe {
self.device
.swapchain_loader
.destroy_swapchain(swapchain, None);
}
self.swapchain = None;
self.handle = None;
log::debug!("Swapchain destroyed ({swapchain:?})");
}
}

View file

@ -1,41 +0,0 @@
pub(self) mod vk_render_context;
pub use vk_render_context::VkRenderContext;
pub(self) mod vk_instance;
pub use vk_instance::VkInstance;
pub(self) mod vk_surface;
pub use vk_surface::VkSurface;
pub(self) mod vk_physical_device;
pub use vk_physical_device::VkPhysicalDevice;
pub(self) mod vk_device;
pub use vk_device::VkDevice;
pub(self) mod vk_swapchain;
pub use vk_swapchain::VkSwapchain;
pub(self) mod vk_shader_module;
pub use vk_shader_module::VkShaderModule;
pub(self) mod vk_graphics_pipeline;
pub use vk_graphics_pipeline::VkGraphicsPipeline;
mod vk_render_pass;
pub(self) use vk_render_pass::VkRenderPass;
mod vk_semaphore;
pub(self) use vk_semaphore::VkSemaphore;
mod vk_command_pool;
pub(self) use vk_command_pool::VkCommandPool;
mod vk_framebuffer;
pub(self) use vk_framebuffer::VkFramebuffer;
mod vk_fence;
pub(self) use vk_fence::VkFence;
mod utils;
mod vertex;