rt: expose cache disable option in filter options
This commit is contained in:
parent
604edfb78f
commit
e7645a5592
|
@ -1,5 +1,5 @@
|
|||
use crate::key::CacheKey;
|
||||
use crate::cacheable::Cacheable;
|
||||
use crate::key::CacheKey;
|
||||
use platform_dirs::AppDirs;
|
||||
use rusqlite::{params, Connection, DatabaseName};
|
||||
use std::error::Error;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Cache implementations for D3D blob types that need to live
|
||||
//! here because of the orphan rule.
|
||||
|
||||
use crate::{Cacheable, CacheKey};
|
||||
use crate::{CacheKey, Cacheable};
|
||||
|
||||
impl CacheKey for windows::Win32::Graphics::Direct3D::ID3DBlob {
|
||||
fn hash_bytes(&self) -> &[u8] {
|
||||
|
@ -15,7 +15,6 @@ impl CacheKey for windows::Win32::Graphics::Direct3D::Dxc::IDxcBlob {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Cacheable for windows::Win32::Graphics::Direct3D::ID3DBlob {
|
||||
fn from_bytes(bytes: &[u8]) -> Option<Self> {
|
||||
let Some(blob) = (unsafe { windows::Win32::Graphics::Direct3D::Fxc::D3DCreateBlob(bytes.len()).ok() }) else {
|
||||
|
|
|
@ -118,15 +118,24 @@ impl FilterChainD3D11 {
|
|||
ctx: &ID3D11DeviceContext,
|
||||
options: Option<&FilterChainOptionsD3D11>,
|
||||
) -> error::Result<FilterChainD3D11> {
|
||||
let (passes, semantics) = HLSL::compile_preset_passes::<
|
||||
CachedCompilation<GlslangCompilation>,
|
||||
FilterChainError,
|
||||
>(preset.shaders, &preset.textures)?;
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = if !disable_cache {
|
||||
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
} else {
|
||||
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
};
|
||||
|
||||
let samplers = SamplerSet::new(device)?;
|
||||
|
||||
// initialize passes
|
||||
let filters = FilterChainD3D11::init_passes(device, passes, &semantics)?;
|
||||
let filters = FilterChainD3D11::init_passes(device, passes, &semantics, disable_cache)?;
|
||||
println!("passes loded");
|
||||
|
||||
let immediate_context = unsafe { device.GetImmediateContext()? };
|
||||
|
@ -212,6 +221,7 @@ impl FilterChainD3D11 {
|
|||
device: &ID3D11Device,
|
||||
passes: Vec<ShaderPassMeta>,
|
||||
semantics: &ShaderSemantics,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<Vec<FilterPass>> {
|
||||
let device_is_singlethreaded =
|
||||
unsafe { (device.GetCreationFlags() & D3D11_CREATE_DEVICE_SINGLETHREADED.0) == 1 };
|
||||
|
@ -235,7 +245,7 @@ impl FilterChainD3D11 {
|
|||
blob,
|
||||
))
|
||||
},
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
let ia_desc = DrawQuad::get_spirv_cross_vbo_desc();
|
||||
|
@ -248,7 +258,7 @@ impl FilterChainD3D11 {
|
|||
|blob| {
|
||||
d3d11_compile_bound_shader(device, &blob, None, ID3D11Device::CreatePixelShader)
|
||||
},
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 {
|
||||
|
|
|
@ -61,6 +61,7 @@ mod tests {
|
|||
filter.as_deref().unwrap_or(FILTER_PATH),
|
||||
Some(&FilterChainOptionsD3D11 {
|
||||
force_no_mipmaps: false,
|
||||
disable_cache: false,
|
||||
}),
|
||||
// replace below with 'None' for the triangle
|
||||
Some(image),
|
||||
|
@ -85,6 +86,7 @@ mod tests {
|
|||
FILTER_PATH,
|
||||
Some(&FilterChainOptionsD3D11 {
|
||||
force_no_mipmaps: false,
|
||||
disable_cache: false,
|
||||
}),
|
||||
// replace below with 'None' for the triangle
|
||||
// None,
|
||||
|
|
|
@ -18,4 +18,7 @@ pub struct FilterChainOptionsD3D11 {
|
|||
/// Whether or not to explicitly disable mipmap
|
||||
/// generation regardless of shader preset settings.
|
||||
pub force_no_mipmaps: bool,
|
||||
/// Disable the shader object cache. Shaders will be
|
||||
/// recompiled rather than loaded from the cache.
|
||||
pub disable_cache: bool,
|
||||
}
|
||||
|
|
|
@ -207,16 +207,31 @@ impl FilterChainD3D12 {
|
|||
let lut_count = preset.textures.len();
|
||||
|
||||
let shader_copy = preset.shaders.clone();
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = DXIL::compile_preset_passes::<
|
||||
CachedCompilation<GlslangCompilation>,
|
||||
FilterChainError,
|
||||
>(preset.shaders, &preset.textures)?;
|
||||
let (passes, semantics) = if !disable_cache {
|
||||
DXIL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
} else {
|
||||
DXIL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
};
|
||||
|
||||
let (hlsl_passes, _) = HLSL::compile_preset_passes::<
|
||||
CachedCompilation<GlslangCompilation>,
|
||||
FilterChainError,
|
||||
>(shader_copy, &preset.textures)?;
|
||||
let (hlsl_passes, _) = if !disable_cache {
|
||||
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
shader_copy,
|
||||
&preset.textures,
|
||||
)?
|
||||
} else {
|
||||
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
shader_copy,
|
||||
&preset.textures,
|
||||
)?
|
||||
};
|
||||
|
||||
let samplers = SamplerSet::new(device)?;
|
||||
let mipmap_gen = D3D12MipmapGen::new(device, false)?;
|
||||
|
@ -244,6 +259,7 @@ impl FilterChainD3D12 {
|
|||
hlsl_passes,
|
||||
&semantics,
|
||||
options.map_or(false, |o| o.force_hlsl_pipeline),
|
||||
disable_cache,
|
||||
)?;
|
||||
|
||||
let mut residuals = FrameResiduals::new();
|
||||
|
@ -367,6 +383,7 @@ impl FilterChainD3D12 {
|
|||
hlsl_passes: Vec<HlslShaderPassMeta>,
|
||||
semantics: &ShaderSemantics,
|
||||
force_hlsl: bool,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<(
|
||||
ID3D12DescriptorHeap,
|
||||
ID3D12DescriptorHeap,
|
||||
|
@ -432,7 +449,8 @@ impl FilterChainD3D12 {
|
|||
validator,
|
||||
&dxil,
|
||||
root_signature,
|
||||
render_format
|
||||
render_format,
|
||||
disable_cache
|
||||
) {
|
||||
(dxil_reflection, graphics_pipeline)
|
||||
} else {
|
||||
|
@ -446,6 +464,7 @@ impl FilterChainD3D12 {
|
|||
&hlsl,
|
||||
root_signature,
|
||||
render_format,
|
||||
disable_cache
|
||||
)?;
|
||||
(hlsl_reflection, graphics_pipeline)
|
||||
};
|
||||
|
@ -458,8 +477,8 @@ impl FilterChainD3D12 {
|
|||
.map_or(1, |push| push.size as usize);
|
||||
|
||||
let uniform_storage = UniformStorage::new_with_storage(
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, ubo_size)?)?,
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)?
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, ubo_size)?)?,
|
||||
RawD3D12Buffer::new(D3D12Buffer::new(device, push_size)?)?
|
||||
);
|
||||
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ pub struct D3D12GraphicsPipeline {
|
|||
pub(crate) format: DXGI_FORMAT,
|
||||
vertex: Vec<u8>,
|
||||
fragment: Vec<u8>,
|
||||
cache_disabled: bool,
|
||||
}
|
||||
|
||||
const D3D12_SLANG_ROOT_PARAMETERS: &[D3D12_ROOT_PARAMETER1; 4] = &[
|
||||
|
@ -152,6 +153,7 @@ impl D3D12GraphicsPipeline {
|
|||
fragment_dxil: IDxcBlob,
|
||||
root_signature: &D3D12RootSignature,
|
||||
render_format: DXGI_FORMAT,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<D3D12GraphicsPipeline> {
|
||||
let input_element = DrawQuad::get_spirv_cross_vbo_desc();
|
||||
|
||||
|
@ -246,7 +248,7 @@ impl D3D12GraphicsPipeline {
|
|||
let cached_pso = pso.GetCachedBlob()?;
|
||||
Ok(cached_pso)
|
||||
},
|
||||
true,
|
||||
!disable_cache,
|
||||
)?
|
||||
};
|
||||
|
||||
|
@ -264,6 +266,7 @@ impl D3D12GraphicsPipeline {
|
|||
format: render_format,
|
||||
vertex,
|
||||
fragment,
|
||||
cache_disabled: disable_cache,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -288,8 +291,14 @@ impl D3D12GraphicsPipeline {
|
|||
)?;
|
||||
(vertex, fragment)
|
||||
};
|
||||
let mut new_pipeline =
|
||||
Self::new_from_blobs(device, vertex.into(), fragment.into(), root_sig, format)?;
|
||||
let mut new_pipeline = Self::new_from_blobs(
|
||||
device,
|
||||
vertex.into(),
|
||||
fragment.into(),
|
||||
root_sig,
|
||||
format,
|
||||
self.cache_disabled,
|
||||
)?;
|
||||
|
||||
std::mem::swap(self, &mut new_pipeline);
|
||||
Ok(())
|
||||
|
@ -302,6 +311,7 @@ impl D3D12GraphicsPipeline {
|
|||
shader_assembly: &ShaderCompilerOutput<DxilObject, ()>,
|
||||
root_signature: &D3D12RootSignature,
|
||||
render_format: DXGI_FORMAT,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<D3D12GraphicsPipeline> {
|
||||
if shader_assembly.vertex.requires_runtime_data() {
|
||||
return Err(Direct3DOperationError(
|
||||
|
@ -319,7 +329,7 @@ impl D3D12GraphicsPipeline {
|
|||
&[shader_assembly.vertex.deref()],
|
||||
|&[source]| util::dxc_validate_shader(library, validator, source),
|
||||
|f| Ok(f),
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
let fragment_dxil = cache_object(
|
||||
|
@ -327,7 +337,7 @@ impl D3D12GraphicsPipeline {
|
|||
&[shader_assembly.fragment.deref()],
|
||||
|&[source]| util::dxc_validate_shader(library, validator, source),
|
||||
|f| Ok(f),
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
Self::new_from_blobs(
|
||||
|
@ -336,6 +346,7 @@ impl D3D12GraphicsPipeline {
|
|||
fragment_dxil,
|
||||
root_signature,
|
||||
render_format,
|
||||
disable_cache,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -346,13 +357,14 @@ impl D3D12GraphicsPipeline {
|
|||
shader_assembly: &ShaderCompilerOutput<String, CrossHlslContext>,
|
||||
root_signature: &D3D12RootSignature,
|
||||
render_format: DXGI_FORMAT,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<D3D12GraphicsPipeline> {
|
||||
let vertex_dxil = cache_object(
|
||||
"dxil",
|
||||
&[shader_assembly.vertex.as_bytes()],
|
||||
|&[source]| util::dxc_compile_shader(library, dxc, source, u16cstr!("vs_6_0")),
|
||||
|f| Ok(f),
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
let fragment_dxil = cache_object(
|
||||
|
@ -360,7 +372,7 @@ impl D3D12GraphicsPipeline {
|
|||
&[shader_assembly.fragment.as_bytes()],
|
||||
|&[source]| util::dxc_compile_shader(library, dxc, source, u16cstr!("ps_6_0")),
|
||||
|f| Ok(f),
|
||||
true,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
Self::new_from_blobs(
|
||||
|
@ -369,6 +381,7 @@ impl D3D12GraphicsPipeline {
|
|||
fragment_dxil,
|
||||
root_signature,
|
||||
render_format,
|
||||
disable_cache,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,4 +22,8 @@ pub struct FilterChainOptionsD3D12 {
|
|||
/// generation for intermediate passes regardless
|
||||
/// of shader preset settings.
|
||||
pub force_no_mipmaps: bool,
|
||||
|
||||
/// Disable the shader object cache. Shaders will be
|
||||
/// recompiled rather than loaded from the cache.
|
||||
pub disable_cache: bool,
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ use librashader_reflect::back::{CompileReflectShader, CompileShader};
|
|||
use librashader_reflect::front::GlslangCompilation;
|
||||
use librashader_reflect::reflect::semantics::{ShaderSemantics, UniformMeta};
|
||||
|
||||
use librashader_cache::compilation::CachedCompilation;
|
||||
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
||||
use librashader_reflect::reflect::ReflectShader;
|
||||
use librashader_runtime::binding::BindingUtil;
|
||||
|
@ -104,15 +105,24 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
preset: ShaderPreset,
|
||||
options: Option<&FilterChainOptionsGL>,
|
||||
) -> error::Result<Self> {
|
||||
let (passes, semantics) = GLSL::compile_preset_passes::<
|
||||
GlslangCompilation,
|
||||
FilterChainError,
|
||||
>(preset.shaders, &preset.textures)?;
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = if !disable_cache {
|
||||
GLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
} else {
|
||||
GLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
};
|
||||
|
||||
let version = options.map_or_else(gl_get_version, |o| gl_u16_to_version(o.glsl_version));
|
||||
|
||||
// initialize passes
|
||||
let filters = Self::init_passes(version, passes, &semantics)?;
|
||||
let filters = Self::init_passes(version, passes, &semantics, disable_cache)?;
|
||||
|
||||
let default_filter = filters.first().map(|f| f.config.filter).unwrap_or_default();
|
||||
let default_wrap = filters
|
||||
|
@ -181,6 +191,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
version: GlslVersion,
|
||||
passes: Vec<ShaderPassMeta>,
|
||||
semantics: &ShaderSemantics,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<Box<[FilterPass<T>]>> {
|
||||
let mut filters = Vec::new();
|
||||
|
||||
|
@ -189,7 +200,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
let reflection = reflect.reflect(index, semantics)?;
|
||||
let glsl = reflect.compile(version)?;
|
||||
|
||||
let (program, ubo_location) = T::CompileShader::compile_program(glsl, true)?;
|
||||
let (program, ubo_location) = T::CompileShader::compile_program(glsl, !disable_cache)?;
|
||||
|
||||
let ubo_ring = if let Some(ubo) = &reflection.ubo {
|
||||
let ring = UboRing::new(ubo.size);
|
||||
|
|
|
@ -40,6 +40,7 @@ mod tests {
|
|||
glsl_version: 0,
|
||||
use_dsa: false,
|
||||
force_no_mipmaps: false,
|
||||
disable_cache: false,
|
||||
}),
|
||||
)
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
|
@ -59,6 +60,7 @@ mod tests {
|
|||
glsl_version: 0,
|
||||
use_dsa: true,
|
||||
force_no_mipmaps: false,
|
||||
disable_cache: false,
|
||||
}),
|
||||
)
|
||||
// FilterChain::load_from_path("../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", None)
|
||||
|
|
|
@ -18,7 +18,11 @@ pub struct FilterChainOptionsGL {
|
|||
/// The GLSL version. Should be at least `330`.
|
||||
pub glsl_version: u16,
|
||||
/// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+.
|
||||
/// This is required to use shader caching.
|
||||
pub use_dsa: bool,
|
||||
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
|
||||
pub force_no_mipmaps: bool,
|
||||
/// Disable the shader object cache. Shaders will be
|
||||
/// recompiled rather than loaded from the cache.
|
||||
pub disable_cache: bool,
|
||||
}
|
||||
|
|
|
@ -307,10 +307,20 @@ impl FilterChainVulkan {
|
|||
V: TryInto<VulkanObjects, Error = E>,
|
||||
FilterChainError: From<E>,
|
||||
{
|
||||
let (passes, semantics) = SPIRV::compile_preset_passes::<
|
||||
CachedCompilation<GlslangCompilation>,
|
||||
FilterChainError,
|
||||
>(preset.shaders, &preset.textures)?;
|
||||
let disable_cache = options.map_or(false, |o| o.disable_cache);
|
||||
|
||||
let (passes, semantics) = if !disable_cache {
|
||||
SPIRV::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
} else {
|
||||
SPIRV::compile_preset_passes::<GlslangCompilation, FilterChainError>(
|
||||
preset.shaders,
|
||||
&preset.textures,
|
||||
)?
|
||||
};
|
||||
|
||||
let device = vulkan.try_into().map_err(From::from)?;
|
||||
|
||||
let mut frames_in_flight = options.map_or(0, |o| o.frames_in_flight);
|
||||
|
@ -325,6 +335,7 @@ impl FilterChainVulkan {
|
|||
&semantics,
|
||||
frames_in_flight,
|
||||
options.map_or(false, |o| o.use_render_pass),
|
||||
disable_cache,
|
||||
)?;
|
||||
|
||||
let luts = FilterChainVulkan::load_luts(&device, cmd, &preset.textures)?;
|
||||
|
@ -388,6 +399,7 @@ impl FilterChainVulkan {
|
|||
semantics: &ShaderSemantics,
|
||||
frames_in_flight: u32,
|
||||
use_render_pass: bool,
|
||||
disable_cache: bool,
|
||||
) -> error::Result<Box<[FilterPass]>> {
|
||||
let frames_in_flight = std::cmp::max(1, frames_in_flight);
|
||||
|
||||
|
@ -430,6 +442,7 @@ impl FilterChainVulkan {
|
|||
&reflection,
|
||||
frames_in_flight,
|
||||
render_pass_format,
|
||||
!disable_cache,
|
||||
)?;
|
||||
|
||||
Ok(FilterPass {
|
||||
|
|
|
@ -314,6 +314,7 @@ impl VulkanGraphicsPipeline {
|
|||
reflection: &ShaderReflection,
|
||||
replicas: u32,
|
||||
render_pass_format: vk::Format,
|
||||
cache_objects: bool,
|
||||
) -> error::Result<VulkanGraphicsPipeline> {
|
||||
let pipeline_layout = PipelineLayoutObjects::new(reflection, replicas, device)?;
|
||||
|
||||
|
@ -358,7 +359,7 @@ impl VulkanGraphicsPipeline {
|
|||
Ok::<_, FilterChainError>((pipeline, pipeline_cache))
|
||||
},
|
||||
|(_pipeline, cache)| unsafe { Ok(device.get_pipeline_cache_data(*cache)?) },
|
||||
true,
|
||||
cache_objects,
|
||||
)?;
|
||||
|
||||
Ok(VulkanGraphicsPipeline {
|
||||
|
|
|
@ -51,6 +51,7 @@ mod tests {
|
|||
frames_in_flight: 3,
|
||||
force_no_mipmaps: false,
|
||||
use_render_pass: true,
|
||||
disable_cache: false,
|
||||
}),
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -22,4 +22,7 @@ pub struct FilterChainOptionsVulkan {
|
|||
/// Use explicit render pass objects It is recommended if possible to use dynamic rendering,
|
||||
/// because render-pass mode will create new framebuffers per pass.
|
||||
pub use_render_pass: bool,
|
||||
/// Disable the shader object cache. Shaders will be
|
||||
/// recompiled rather than loaded from the cache.
|
||||
pub disable_cache: bool,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue