4 releases (2 breaking)
0.3.0 | Nov 5, 2023 |
---|---|
0.2.0 | Jun 24, 2023 |
0.1.2 | Apr 10, 2023 |
0.1.1 |
|
0.1.0 | Apr 8, 2023 |
#122 in Rendering
140KB
3K
SLoC
VKU
Work in progress utility crate for kickstarting vulkan development with shaderc, ash and the gpu-allocator.
Center module is Vkinit, created from RawHandles and VkInitCreateInfo.
Warning
This is mostly a personal utility crate and no guarentees are made in terms of stability until 1.0.0.
Initialization
use winit::window::WindowBuilder;
use winit::event_loop::{EventLoop, EventLoopBuilder};
use winit::dpi::LogicalSize;
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use vku::{VkInitCreateInfo, VkInit};
fn main() -> Result<(), vku::Error>{
let event_loop: EventLoop<()> = EventLoopBuilder::default().build();
let size = [800_u32, 600_u32];
let window = WindowBuilder::new()
.with_inner_size(LogicalSize{width: size[0], height: size[1]})
.build(&event_loop)
.unwrap();
let create_info = VkInitCreateInfo::default();
let vk_init = VkInit::new(Some(&window), Some(size), create_info)?;
Ok(())
}
Swapchain recreation:
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use vku::VkInit;
use winit::window::Window;
fn main() -> Result<(), vku::Error>{
let window: Window = todo!();
let mut vk_init: VkInit = todo!();
let new_size = [1200_u32, 900_u32];
vk_init.on_resize(&window, new_size)?;
Ok(())
}
Managed Image allocation and tracked layout transitions:
use vku::{VkInit, CmdType};
use ash::vk::{Extent3D, Format, ImageAspectFlags, ImageLayout};
fn main() -> Result<(), vku::Error>{
let vk_init: VkInit = todo!();
let setup_cmd_buffer_pool =
vk_init.create_cmd_pool(CmdType::Any)?;
let setup_cmd_buffer =
vk_init.create_command_buffers(&setup_cmd_buffer_pool, 1)?[0];
let setup_fence = vk_init.create_fence()?;
vk_init.begin_cmd_buffer(&setup_cmd_buffer)?;
let extent = Extent3D{width: 100, height: 100, depth: 1};
let format = Format::R8G8B8A8_UNORM;
let format_bytes = 4;
let aspect_flags = ImageAspectFlags::COLOR;
let mut image = vk_init.create_empty_image(extent, format, format_bytes, aspect_flags)?;
let image_barrier = image.get_image_layout_transition_barrier2(
ImageLayout::TRANSFER_DST_OPTIMAL,
None, None)?; // No queue family ownership transfer
vk_init.cmd_pipeline_barrier2(
&setup_cmd_buffer,
&[image_barrier], &[]); // Only this image barrier, no BufferMemoryBarriers
vk_init.end_and_submit_cmd_buffer(
&setup_cmd_buffer,
CmdType::Any,
&setup_fence, &[], &[], &[])?; // Wait on setup fence, wait/signal no semaphores
Ok(())
}
Shader compilation with #include directives:
fn main() -> Result<(), vku::Error>{
let src_dir_path = std::path::Path::new("./assets/shaders/src/");
let target_dir_path = std::path::Path::new("./assets/shaders/compiled_shaders/");
let debug_text_result = true;
vku::compile_all_shaders(&src_dir_path, &target_dir_path, debug_text_result)?;
Ok(())
}
Dependencies
~8–18MB
~311K SLoC