Compare commits

...

2 commits

Author SHA1 Message Date
Alex Janka 2d0dd5909d fix double free 2024-01-25 09:38:23 +11:00
Alex Janka 03546153ff shaders can be either a path or a string 2024-01-25 09:38:23 +11:00
5 changed files with 18 additions and 10 deletions

View file

@ -27,6 +27,12 @@ use num_traits::AsPrimitive;
use std::convert::Infallible; use std::convert::Infallible;
use std::str::FromStr; use std::str::FromStr;
#[derive(Debug, Clone)]
pub enum ShaderStorage {
Path(std::path::PathBuf),
String(String),
}
#[repr(u32)] #[repr(u32)]
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)] #[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
/// Supported image formats for textures. /// Supported image formats for textures.

View file

@ -17,7 +17,6 @@ use crate::include::read_source;
pub use error::*; pub use error::*;
use librashader_common::ImageFormat; use librashader_common::ImageFormat;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::path::Path;
/// The source file for a single shader pass. /// The source file for a single shader pass.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
@ -58,8 +57,8 @@ pub struct ShaderParameter {
impl ShaderSource { impl ShaderSource {
/// Load the source file at the given path, resolving includes relative to the location of the /// Load the source file at the given path, resolving includes relative to the location of the
/// source file. /// source file.
pub fn load(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> { pub fn load(file: &librashader_common::ShaderStorage) -> Result<ShaderSource, PreprocessError> {
load_shader_source(path) load_shader_source(file)
} }
} }
@ -78,8 +77,14 @@ impl SourceOutput for String {
} }
} }
pub(crate) fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> { pub(crate) fn load_shader_source(
let source = read_source(path)?; file: &librashader_common::ShaderStorage,
) -> Result<ShaderSource, PreprocessError> {
let source = match file {
librashader_common::ShaderStorage::Path(path) => read_source(path)?,
librashader_common::ShaderStorage::String(s) => s.to_string(),
};
let meta = pragma::parse_pragma_meta(&source)?; let meta = pragma::parse_pragma_meta(&source)?;
let text = stage::process_stages(&source)?; let text = stage::process_stages(&source)?;
let parameters = FxHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p))); let parameters = FxHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p)));

View file

@ -114,7 +114,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
let shader = ShaderPassConfig { let shader = ShaderPassConfig {
id, id,
name, name: librashader_common::ShaderStorage::Path(name),
alias: shader_values.iter().find_map(|f| match f { alias: shader_values.iter().find_map(|f| match f {
Value::Alias(_, value) => Some(value.to_string()), Value::Alias(_, value) => Some(value.to_string()),
_ => None, _ => None,

View file

@ -10,7 +10,7 @@ pub struct ShaderPassConfig {
/// The index of the shader pass relative to its parent preset. /// The index of the shader pass relative to its parent preset.
pub id: i32, pub id: i32,
/// The fully qualified path to the shader pass source file. /// The fully qualified path to the shader pass source file.
pub name: PathBuf, pub name: librashader_common::ShaderStorage,
/// The alias of the shader pass if available. /// The alias of the shader pass if available.
pub alias: Option<String>, pub alias: Option<String>,
/// The filtering mode that this shader pass should expect. /// The filtering mode that this shader pass should expect.

View file

@ -186,9 +186,6 @@ impl Drop for RawVulkanBuffer {
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
ManuallyDrop::drop(&mut self.buffer); ManuallyDrop::drop(&mut self.buffer);
if self.buffer.handle != vk::Buffer::null() {
self.buffer.device.destroy_buffer(self.buffer.handle, None);
}
} }
} }
} }