cache: make cache opt-in by default so docs.rs can build sqlite properly

This commit is contained in:
chyyran 2023-02-16 00:54:22 -05:00
parent f42328280a
commit 284d644f99
11 changed files with 33 additions and 20 deletions

View file

@ -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"]

View file

@ -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;

View file

@ -9,7 +9,7 @@ pub struct CachedCompilation<T> {
compilation: T,
}
#[cfg(not(feature = "docsrs"))]
#[cfg(feature = "cache")]
impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderCompilation for CachedCompilation<T>
{
@ -57,12 +57,14 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
}
}
#[cfg(feature = "docsrs")]
#[cfg(not(feature = "cache"))]
impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderCompilation for CachedCompilation<T>
{
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
T::compile(source)
Ok(CachedCompilation {
compilation: T::compile(source)?
})
}
}

View file

@ -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<E, T, R, const KEY_SIZE: usize>(
index: &str,
keys: &[&dyn CacheKey; KEY_SIZE],
@ -15,6 +17,7 @@ pub fn cache_pipeline<E, T, R, const KEY_SIZE: usize>(
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<E, T, R, const KEY_SIZE: usize>(
///
/// - `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<E, T, R, H, const KEY_SIZE: usize>(
index: &str,
keys: &[H; KEY_SIZE],
@ -33,5 +37,6 @@ pub fn cache_shader_object<E, T, R, H, const KEY_SIZE: usize>(
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)?)?);
}

View file

@ -24,5 +24,5 @@ pub use cache::cache_shader_object;
mod d3d;
#[cfg(feature = "docsrs")]
#[cfg(not(feature = "cache"))]
mod docsrs;

View file

@ -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"]

View file

@ -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"

View file

@ -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"

View file

@ -31,4 +31,4 @@ glfw = "0.47.0"
[[test]]
name = "triangle"
required-features = ["librashader-cache/sqlite-bundled"]
required-features = ["librashader-cache/cache"]

View file

@ -40,4 +40,4 @@ ash-window = "0.12.0"
[[test]]
name = "triangle"
required-features = ["librashader-cache/sqlite-bundled"]
required-features = ["librashader-cache/cache"]

View file

@ -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" ]