Continue vulkan c++ tutorial
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 0s

This commit is contained in:
Florian RICHER 2024-11-17 20:19:34 +01:00
parent 81e4212d8e
commit b2d28ef408
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
9 changed files with 156 additions and 3 deletions

View file

@ -0,0 +1,42 @@
use crate::vulkan::VkDevice;
use ash::vk;
use std::path::Path;
use std::sync::Arc;
pub struct VkShaderModule {
device: Arc<VkDevice>,
pub(super) handle: vk::ShaderModule,
}
impl VkShaderModule {
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)?;
let shader_create_info = vk::ShaderModuleCreateInfo::default().code(&frag_shader_str);
let shader_module = unsafe {
device
.handle
.create_shader_module(&shader_create_info, None)?
};
log::debug!(
"Shader module created ({shader_module:?}) from {:?}",
path.as_ref()
);
Ok(Self {
device,
handle: shader_module,
})
}
}
impl Drop for VkShaderModule {
fn drop(&mut self) {
unsafe {
self.device.handle.destroy_shader_module(self.handle, None);
log::debug!("Shader module destroyed ({:?})", self.handle);
}
}
}