vulkan: Move to renderer module
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
This commit is contained in:
parent
001547dbc2
commit
a669247406
21 changed files with 61 additions and 63 deletions
42
src/renderer/vulkan/vk_shader_module.rs
Normal file
42
src/renderer/vulkan/vk_shader_module.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use super::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: device.clone(),
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue