Compare commits

..

No commits in common. "a6692474062361480e889d977a48943a4c2df2f6" and "dd8a5a97ea5403e773da10d56e34c344b21494ae" have entirely different histories.

21 changed files with 85 additions and 83 deletions

View file

@ -1,5 +1,5 @@
use crate::display::window::Window;
use crate::renderer::vulkan::VkRenderContext;
use crate::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 renderer;
mod vulkan;
fn main() {
env_logger::init();

View file

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

View file

@ -1,41 +0,0 @@
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;

41
src/vulkan/mod.rs Normal file
View file

@ -0,0 +1,41 @@
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;

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,4 @@
use super::{
use crate::vulkan::{
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.handle.unwrap()];
let swapchains = [self.swapchain.swapchain.unwrap()];
let indices = [index];
let present_info = vk::PresentInfoKHR::default()
.wait_semaphores(&signal_semaphores)

View file

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

View file

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

View file

@ -1,4 +1,4 @@
use super::VkDevice;
use crate::vulkan::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.clone(),
device,
handle: shader_module,
})
}

View file

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

View file

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