Compare commits

...

5 commits

11 changed files with 94 additions and 37 deletions

View file

@ -12,7 +12,7 @@ description = "RetroArch shaders for all."
[dependencies]
serde = { version = "1.0" }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = ["serialize", "dxil"] }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = ["serialize"] }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4" }
platform-dirs = "0.3.0"
blake3 = { version = "1.3.3" }
@ -32,7 +32,7 @@ features = [
optional = true
[features]
d3d = ["windows"]
d3d = ["windows", "librashader-reflect/dxil"]
# hack to get building on docsrs
docsrs = ["blake3/pure", "rusqlite/in_gecko"]

View file

@ -1,6 +1,8 @@
//! Cache helpers for `ShaderCompilation` objects to cache compiled SPIRV.
use librashader_preprocess::ShaderSource;
use librashader_reflect::back::targets::{DXIL, GLSL, HLSL, SPIRV};
#[cfg(feature = "windows")]
use librashader_reflect::back::targets::DXIL;
use librashader_reflect::back::targets::{GLSL, HLSL, SPIRV};
use librashader_reflect::back::{CompilerBackend, FromCompilation};
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};
use librashader_reflect::front::{GlslangCompilation, ShaderCompilation};
@ -56,6 +58,7 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
}
}
#[cfg(feature = "windows")]
impl FromCompilation<CachedCompilation<GlslangCompilation>> for DXIL {
type Target = <DXIL as FromCompilation<GlslangCompilation>>::Target;
type Options = <DXIL as FromCompilation<GlslangCompilation>>::Options;

View file

@ -12,23 +12,38 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all."
[lib]
crate-type = [ "cdylib", "staticlib" ]
crate-type = ["cdylib", "staticlib"]
[features]
default = ["runtime-all" ]
runtime-all = ["runtime-opengl", "runtime-d3d11", "runtime-d3d12", "runtime-vulkan"]
default = ["runtime-all"]
runtime-all = [
"runtime-opengl",
"runtime-d3d11",
"runtime-d3d12",
"runtime-vulkan",
]
runtime-opengl = ["gl", "librashader/runtime-gl"]
runtime-d3d11 = ["windows", "librashader/runtime-d3d11", "windows/Win32_Graphics_Direct3D11"]
runtime-d3d12 = ["windows", "librashader/runtime-d3d12", "windows/Win32_Graphics_Direct3D12"]
runtime-d3d11 = [
"windows",
"librashader/runtime-d3d11",
"windows/Win32_Graphics_Direct3D11",
]
runtime-d3d12 = [
"windows",
"librashader/runtime-d3d12",
"windows/Win32_Graphics_Direct3D12",
]
runtime-vulkan = ["ash", "librashader/runtime-vk"]
[dependencies]
librashader = { path = "../librashader", version = "0.1.4", features = ["internal"] }
librashader = { path = "../librashader", version = "0.1.4", features = [
"internal",
] }
thiserror = "1.0.37"
paste = "1.0.9"
gl = { version = "0.14.0", optional = true }
rustc-hash = "1.1.0"
ash = { version = "0.37.2+1.3.238", optional = true }
ash = { version = "0.37", optional = true }
spirv_cross = { package = "librashader-spirv-cross", version = "0.23" }
[target.'cfg(windows)'.dependencies.windows]

View file

@ -21,7 +21,7 @@ vulkan = ["ash"]
[dependencies]
gl = { version = "0.14.0", optional = true }
ash = { version = "0.37.1+1.3.235", optional = true }
ash = { version = "0.37", optional = true }
num-traits = "0.2.15"

View file

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

View file

@ -17,7 +17,6 @@ use crate::include::read_source;
pub use error::*;
use librashader_common::ImageFormat;
use rustc_hash::FxHashMap;
use std::path::Path;
/// The source file for a single shader pass.
#[derive(Debug, Clone, PartialEq)]
@ -58,8 +57,8 @@ pub struct ShaderParameter {
impl ShaderSource {
/// Load the source file at the given path, resolving includes relative to the location of the
/// source file.
pub fn load(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
load_shader_source(path)
pub fn load(file: &librashader_common::ShaderStorage) -> Result<ShaderSource, PreprocessError> {
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> {
let source = read_source(path)?;
pub(crate) fn load_shader_source(
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 text = stage::process_stages(&source)?;
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 {
id,
name,
name: librashader_common::ShaderStorage::Path(name),
alias: shader_values.iter().find_map(|f| match f {
Value::Alias(_, value) => Some(value.to_string()),
_ => None,

View file

@ -10,7 +10,7 @@ pub struct ShaderPassConfig {
/// The index of the shader pass relative to its parent preset.
pub id: i32,
/// 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.
pub alias: Option<String>,
/// The filtering mode that this shader pass should expect.

View file

@ -14,19 +14,24 @@ description = "RetroArch shaders for all."
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
librashader-common = { path = "../librashader-common", features = ["vulkan"], version = "0.1.4" }
librashader-common = { path = "../librashader-common", features = [
"vulkan",
], version = "0.1.4" }
librashader-presets = { path = "../librashader-presets", version = "0.1.4" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4" }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = [] }
librashader-runtime = { path = "../librashader-runtime" , version = "0.1.4" }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = [
] }
librashader-runtime = { path = "../librashader-runtime", version = "0.1.4" }
librashader-cache = { path = "../librashader-cache", version = "0.1.4" }
spirv_cross = { package = "librashader-spirv-cross", version = "0.23" }
rustc-hash = "1.1.0"
bytemuck = "1.12.3"
thiserror = "1.0.37"
ash = { version = "0.37.1+1.3.235", features = ["linked", "debug"] }
gpu-allocator = { version = "0.22.0", default-features = false, features = ["vulkan"] }
ash = { version = "0.37", features = ["linked", "debug"] }
gpu-allocator = { version = "0.22.0", default-features = false, features = [
"vulkan",
] }
parking_lot = "0.12.1"
rayon = "1.6.1"

View file

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

View file

@ -16,16 +16,18 @@ description = "RetroArch shaders for all."
librashader-common = { path = "../librashader-common", version = "0.1.4" }
librashader-presets = { path = "../librashader-presets", version = "0.1.4" }
librashader-preprocess = { path = "../librashader-preprocess", version = "0.1.4" }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = ["standalone"] }
librashader-runtime = { path = "../librashader-runtime", version = "0.1.4" }
librashader-runtime-d3d11 = { path = "../librashader-runtime-d3d11", version = "0.1.4", optional = true }
librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version = "0.1.4", optional = true }
librashader-reflect = { path = "../librashader-reflect", version = "0.1.4", features = [
"standalone",
] }
librashader-runtime = { path = "../librashader-runtime", version = "0.1.4" }
librashader-runtime-d3d11 = { path = "../librashader-runtime-d3d11", version = "0.1.4", optional = true }
librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version = "0.1.4", optional = true }
librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.1.4", optional = true }
librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.1.4", optional = true }
librashader-cache = { path = "../librashader-cache", version = "0.1.4" }
ash = { version = "0.37.1+1.3.235", optional = true }
ash = { version = "0.37", optional = true }
[target.'cfg(windows)'.dependencies.windows]
version = "0.48.0"
@ -39,10 +41,34 @@ preprocess = []
presets = []
# runtimes
runtime-gl = [ "runtime", "reflect-cross", "librashader-common/opengl", "librashader-runtime-gl" ]
runtime-d3d11 = [ "runtime", "reflect-cross","librashader-common/d3d11", "librashader-runtime-d3d11", "windows/Win32_Graphics_Direct3D11" ]
runtime-d3d12 = [ "runtime", "reflect-cross", "reflect-dxil", "librashader-common/d3d12", "librashader-runtime-d3d12", "windows/Win32_Graphics_Direct3D12" ]
runtime-vk = ["runtime", "reflect-cross", "librashader-common/vulkan", "librashader-runtime-vk", "ash" ]
runtime-gl = [
"runtime",
"reflect-cross",
"librashader-common/opengl",
"librashader-runtime-gl",
]
runtime-d3d11 = [
"runtime",
"reflect-cross",
"librashader-common/d3d11",
"librashader-runtime-d3d11",
"windows/Win32_Graphics_Direct3D11",
]
runtime-d3d12 = [
"runtime",
"reflect-cross",
"reflect-dxil",
"librashader-common/d3d12",
"librashader-runtime-d3d12",
"windows/Win32_Graphics_Direct3D12",
]
runtime-vk = [
"runtime",
"reflect-cross",
"librashader-common/vulkan",
"librashader-runtime-vk",
"ash",
]
# reflection
reflect-cross = ["reflect", "librashader-reflect/cross"]
@ -52,7 +78,7 @@ runtime-all = ["runtime-gl", "runtime-d3d11", "runtime-d3d12", "runtime-vk"]
reflect-all = ["reflect-cross", "reflect-dxil"]
# enable all features by default
default = [ "full" ]
default = ["full"]
internal = []
full = ["runtime-all", "reflect-all", "preprocess", "presets"]
@ -62,4 +88,4 @@ docsrs = ["librashader-cache/docsrs"]
[package.metadata.docs.rs]
targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"]
features = [ "librashader-cache/docsrs" ]
features = ["librashader-cache/docsrs"]