diff --git a/librashader-cache/Cargo.toml b/librashader-cache/Cargo.toml index 70919fe..060d049 100644 --- a/librashader-cache/Cargo.toml +++ b/librashader-cache/Cargo.toml @@ -18,7 +18,7 @@ platform-dirs = "0.3.0" blake3 = { version = "1.3.3" } thiserror = "1.0.38" bincode = { version = "2.0.0-rc.2", features = ["serde"] } -rusqlite = { version = "0.28.0" } +rusqlite = { version = "0.28.0", default-features = false, optional = true } bytemuck = "1.13.0" @@ -31,10 +31,9 @@ features = [ ] optional = true - [features] # should be enabled at librashader crate level. -sqlite-bundled = ["rusqlite/bundled"] +cache = ["rusqlite/bundled"] d3d = ["windows"] docsrs = ["blake3/pure"] diff --git a/librashader-cache/src/cache.rs b/librashader-cache/src/cache.rs index 6970c8f..ebe7e19 100644 --- a/librashader-cache/src/cache.rs +++ b/librashader-cache/src/cache.rs @@ -1,7 +1,7 @@ use crate::cacheable::Cacheable; use crate::key::CacheKey; -#[cfg(not(feature = "docsrs"))] +#[cfg(feature = "cache")] pub(crate) mod internal { use platform_dirs::AppDirs; use rusqlite::{Connection, DatabaseName}; @@ -67,7 +67,7 @@ pub(crate) mod internal { } -#[cfg(not(feature = "docsrs"))] +#[cfg(feature = "cache")] /// Cache a shader object (usually bytecode) created by the keyed objects. /// /// - `factory` is the function that compiles the values passed as keys to a shader object. @@ -122,7 +122,7 @@ where Ok(load(blob)?) } -#[cfg(not(feature = "docsrs"))] +#[cfg(feature = "cache")] /// Cache a pipeline state object. /// /// Keys are not used to create the object and are only used to uniquely identify the pipeline state. @@ -183,8 +183,8 @@ where Ok(pipeline) } -#[cfg(feature = "docsrs")] +#[cfg(not(feature = "cache"))] pub use crate::docsrs::cache_pipeline; -#[cfg(feature = "docsrs")] +#[cfg(not(feature = "cache"))] pub use crate::docsrs::cache_shader_object; \ No newline at end of file diff --git a/librashader-cache/src/compilation.rs b/librashader-cache/src/compilation.rs index 10af190..c90572b 100644 --- a/librashader-cache/src/compilation.rs +++ b/librashader-cache/src/compilation.rs @@ -9,7 +9,7 @@ pub struct CachedCompilation { compilation: T, } -#[cfg(not(feature = "docsrs"))] +#[cfg(feature = "cache")] impl serde::Deserialize<'de> + serde::Serialize + Clone> ShaderCompilation for CachedCompilation { @@ -57,12 +57,14 @@ impl serde::Deserialize<'de> + serde::Serialize } } -#[cfg(feature = "docsrs")] +#[cfg(not(feature = "cache"))] impl serde::Deserialize<'de> + serde::Serialize + Clone> ShaderCompilation for CachedCompilation { fn compile(source: &ShaderSource) -> Result { - T::compile(source) + Ok(CachedCompilation { + compilation: T::compile(source)? + }) } } diff --git a/librashader-cache/src/docsrs.rs b/librashader-cache/src/docsrs.rs index 1618c05..bf60119 100644 --- a/librashader-cache/src/docsrs.rs +++ b/librashader-cache/src/docsrs.rs @@ -1,3 +1,4 @@ +use crate::{CacheKey, Cacheable}; /// Cache a pipeline state object. /// /// Keys are not used to create the object and are only used to uniquely identify the pipeline state. @@ -5,6 +6,7 @@ /// - `restore_pipeline` tries to restore the pipeline with either a cached binary pipeline state /// cache, or create a new pipeline if no cached value is available. /// - `fetch_pipeline_state` fetches the new pipeline state cache after the pipeline was created. +#[allow(unused_variables)] pub fn cache_pipeline( index: &str, keys: &[&dyn CacheKey; KEY_SIZE], @@ -15,6 +17,7 @@ pub fn cache_pipeline( where T: Cacheable, { + eprintln!("[librashader:warn] Cache support was not built, you must rebuild librashader with the cache feature."); return Ok(restore_pipeline(None)?); } @@ -22,6 +25,7 @@ pub fn cache_pipeline( /// /// - `factory` is the function that compiles the values passed as keys to a shader object. /// - `load` tries to load a compiled shader object to a driver-specialized result. +#[allow(unused_variables)] pub fn cache_shader_object( index: &str, keys: &[H; KEY_SIZE], @@ -33,5 +37,6 @@ pub fn cache_shader_object( H: CacheKey, T: Cacheable, { + eprintln!("[librashader:warn] Cache support was not built, you must rebuild librashader with the cache feature."); return Ok(load(factory(keys)?)?); } \ No newline at end of file diff --git a/librashader-cache/src/lib.rs b/librashader-cache/src/lib.rs index a6a6109..79c12b5 100644 --- a/librashader-cache/src/lib.rs +++ b/librashader-cache/src/lib.rs @@ -24,5 +24,5 @@ pub use cache::cache_shader_object; mod d3d; -#[cfg(feature = "docsrs")] +#[cfg(not(feature = "cache"))] mod docsrs; \ No newline at end of file diff --git a/librashader-capi/Cargo.toml b/librashader-capi/Cargo.toml index 16d4fc2..626b3b9 100644 --- a/librashader-capi/Cargo.toml +++ b/librashader-capi/Cargo.toml @@ -15,7 +15,8 @@ description = "RetroArch shaders for all." crate-type = [ "cdylib", "staticlib" ] [features] -default = ["runtime-opengl", "runtime-d3d11", "runtime-d3d12", "runtime-vulkan"] +default = ["runtime-all", "librashader/cache" ] +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"] @@ -38,3 +39,5 @@ optional = true [package.metadata.docs.rs] targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"] +default-features = false +features = ["runtime-all", "librashader/docsrs"] \ No newline at end of file diff --git a/librashader-runtime-d3d11/Cargo.toml b/librashader-runtime-d3d11/Cargo.toml index 09381e5..805b8b9 100644 --- a/librashader-runtime-d3d11/Cargo.toml +++ b/librashader-runtime-d3d11/Cargo.toml @@ -57,7 +57,7 @@ features = [ [[test]] name = "triangle" -required-features = ["librashader-cache/sqlite-bundled"] +required-features = ["librashader-cache/cache"] [dev-dependencies] gfx-maths = "0.2.8" diff --git a/librashader-runtime-d3d12/Cargo.toml b/librashader-runtime-d3d12/Cargo.toml index 93da207..24f4c90 100644 --- a/librashader-runtime-d3d12/Cargo.toml +++ b/librashader-runtime-d3d12/Cargo.toml @@ -65,7 +65,7 @@ features = [ [[test]] name = "triangle" -required-features = ["librashader-cache/sqlite-bundled"] +required-features = ["librashader-cache/cache"] [dev-dependencies] gfx-maths = "0.2.8" diff --git a/librashader-runtime-gl/Cargo.toml b/librashader-runtime-gl/Cargo.toml index 2093ca0..a1b3744 100644 --- a/librashader-runtime-gl/Cargo.toml +++ b/librashader-runtime-gl/Cargo.toml @@ -31,4 +31,4 @@ glfw = "0.47.0" [[test]] name = "triangle" -required-features = ["librashader-cache/sqlite-bundled"] +required-features = ["librashader-cache/cache"] diff --git a/librashader-runtime-vk/Cargo.toml b/librashader-runtime-vk/Cargo.toml index 69dc6cb..1df93aa 100644 --- a/librashader-runtime-vk/Cargo.toml +++ b/librashader-runtime-vk/Cargo.toml @@ -40,4 +40,4 @@ ash-window = "0.12.0" [[test]] name = "triangle" -required-features = ["librashader-cache/sqlite-bundled"] \ No newline at end of file +required-features = ["librashader-cache/cache"] diff --git a/librashader/Cargo.toml b/librashader/Cargo.toml index bb30082..253c828 100644 --- a/librashader/Cargo.toml +++ b/librashader/Cargo.toml @@ -22,7 +22,8 @@ librashader-runtime-d3d11 = { path = "../librashader-runtime-d3d11", version = librashader-runtime-d3d12 = { path = "../librashader-runtime-d3d12", version = "0.1.0-rc.5", optional = true } librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.1.0-rc.5", optional = true } librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.1.0-rc.5", optional = true } -librashader-cache = { path = "../librashader-cache", version = "0.1.0-rc.5" } + +librashader-cache = { path = "../librashader-cache", version = "0.1.0-rc.5", default-features = false } ash = { version = "0.37.1+1.3.235", optional = true } @@ -51,10 +52,13 @@ runtime-all = ["runtime-gl", "runtime-d3d11", "runtime-d3d12", "runtime-vk"] reflect-all = ["reflect-cross", "reflect-dxil"] # enable all features by default -default = [ "runtime-all", "reflect-all", "preprocess", "presets", "librashader-cache/sqlite-bundled" ] +default = [ "runtime-all", "reflect-all", "preprocess", "presets" ] internal = [] +cache = ["librashader-cache/cache"] + +docsrs = ["librashader-cache/docsrs"] [package.metadata.docs.rs] targets = ["x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu"] default-features = false -features = [ "runtime-all", "reflect-all", "preprocess", "presets", "librashader-cache/docsrs" ] +features = [ "librashader-cache/docsrs" ]