Add a lot of thing
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-15 13:59:19 +01:00
parent 09e109d6ef
commit fb4ac29c07
6 changed files with 255 additions and 43 deletions

View file

@ -1,13 +1,14 @@
use ash::vk;
use crate::vulkan::{VkInstance, VkPhysicalDevice};
use ash::prelude::VkResult;
use ash::vk;
pub struct VkDevice {
pub(crate) handle: ash::Device,
queue_family_index: u32
pub(super) handle: ash::Device,
queue_family_index: u32,
}
impl VkDevice {
pub fn new_graphics_device(
pub(super) fn new_graphics_device(
instance: &VkInstance,
physical_device: &VkPhysicalDevice,
queue_family_index: u32,
@ -37,15 +38,55 @@ impl VkDevice {
Ok(Self {
handle: device,
queue_family_index
queue_family_index,
})
}
pub fn get_device_queue(&self, queue_index: u32) -> vk::Queue {
pub(super) fn get_device_queue(&self, queue_index: u32) -> vk::Queue {
unsafe {
self.handle.get_device_queue(self.queue_family_index, queue_index)
}
}
pub(super) fn create_image_view(&self, image: vk::Image, surface_format: vk::SurfaceFormatKHR) -> VkResult<vk::ImageView> {
let create_view_info = vk::ImageViewCreateInfo::default()
.view_type(vk::ImageViewType::TYPE_2D)
.format(surface_format.format)
.components(vk::ComponentMapping {
r: vk::ComponentSwizzle::R,
g: vk::ComponentSwizzle::G,
b: vk::ComponentSwizzle::B,
a: vk::ComponentSwizzle::A,
})
.subresource_range(vk::ImageSubresourceRange {
aspect_mask: vk::ImageAspectFlags::COLOR,
base_mip_level: 0,
level_count: 1,
base_array_layer: 0,
layer_count: 1,
})
.image(image);
unsafe { self.handle.create_image_view(&create_view_info, None) }
}
pub(super) fn create_command_pool(&self, info: &vk::CommandPoolCreateInfo) -> VkResult<vk::CommandPool> {
let info = info.queue_family_index(self.queue_family_index);
unsafe { self.handle.create_command_pool(&info, None) }
}
pub(super) fn allocate_command_buffers(&self, info: &vk::CommandBufferAllocateInfo) -> VkResult<Vec<vk::CommandBuffer>> {
unsafe { self.handle.allocate_command_buffers(&info) }
}
pub(super) fn create_fence(&self, info: &vk::FenceCreateInfo) -> VkResult<vk::Fence> {
unsafe { self.handle.create_fence(&info, None) }
}
pub(super) fn create_semaphore(&self, info: &vk::SemaphoreCreateInfo) -> VkResult<vk::Semaphore> {
unsafe { self.handle.create_semaphore(&info, None) }
}
}
impl Drop for VkDevice {