Compare commits

..

7 commits

Author SHA1 Message Date
Alex Janka e45e5f242d shaders can be either a path or a string 2024-07-07 10:14:08 +10:00
chyyran fff80df5a0 ci: temporarily remove deny-deprecated on ctypes to unblock ares 2024-06-14 18:17:36 -04:00
chyyran 875968d097 dep: update spirv_cross 2024-06-14 18:17:36 -04:00
chyyran fa48b936be rt: cap texture scaling to [1, 16384]
Fixes #79, #78
2024-06-14 18:17:36 -04:00
chyyran 0a9fa16855 rt: update for new TAIT scope rules 2024-06-14 18:17:36 -04:00
chyyran d558c6e50d dep: update image dependency 2024-06-14 18:17:36 -04:00
chyyran 48d91dfe58 dep: update image dependency 2024-06-14 18:17:36 -04:00
14 changed files with 898 additions and 471 deletions

1021
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -181,7 +181,6 @@ pub(crate) use config_struct;
pub(crate) use config_version_set; pub(crate) use config_version_set;
#[doc(hidden)] #[doc(hidden)]
#[deny(deprecated)]
#[deprecated = "Forward declarations for cbindgen, do not use."] #[deprecated = "Forward declarations for cbindgen, do not use."]
mod __cbindgen_opaque_forward_declarations { mod __cbindgen_opaque_forward_declarations {
macro_rules! typedef_struct { macro_rules! typedef_struct {
@ -189,7 +188,6 @@ mod __cbindgen_opaque_forward_declarations {
$($(#[$($attrss)*])* $($(#[$($attrss)*])*
#[allow(unused)] #[allow(unused)]
#[doc(hidden)] #[doc(hidden)]
#[deny(deprecated)]
#[deprecated] #[deprecated]
pub struct $name; pub struct $name;
)* )*

View file

@ -66,7 +66,6 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![deny(deprecated)]
extern crate alloc; extern crate alloc;

View file

@ -75,13 +75,16 @@ pub(crate) struct FilterCommon {
pub(crate) draw_quad: DrawQuad, pub(crate) draw_quad: DrawQuad,
} }
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes(
pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::< HLSL::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -95,8 +98,11 @@ fn compile_passes(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
impl FilterChainD3D11 { impl FilterChainD3D11 {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path( pub unsafe fn load_from_path(

View file

@ -146,13 +146,16 @@ impl Drop for FrameResiduals {
} }
} }
type DxilShaderPassMeta = mod compile {
use super::*;
pub type DxilShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes_dxil(
pub fn compile_passes_dxil(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
DXIL::compile_preset_passes::< DXIL::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -166,14 +169,16 @@ fn compile_passes_dxil(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
} }
type HlslShaderPassMeta =
pub type HlslShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes_hlsl(
pub fn compile_passes_hlsl(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::< HLSL::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -187,8 +192,11 @@ fn compile_passes_hlsl(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes_dxil, compile_passes_hlsl, DxilShaderPassMeta, HlslShaderPassMeta};
impl FilterChainD3D12 { impl FilterChainD3D12 {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path( pub unsafe fn load_from_path(

View file

@ -63,14 +63,16 @@ pub struct FilterChainD3D9 {
default_options: FrameOptionsD3D9, default_options: FrameOptionsD3D9,
} }
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes( pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::< HLSL::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -84,8 +86,11 @@ fn compile_passes(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
impl FilterChainD3D9 { impl FilterChainD3D9 {
fn init_passes( fn init_passes(
device: &IDirect3DDevice9, device: &IDirect3DDevice9,

View file

@ -92,13 +92,16 @@ impl<T: GLInterface> FilterChainImpl<T> {
} }
} }
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation, SpirvCross>>; ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation, SpirvCross>>;
fn compile_passes(
pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
GLSL::compile_preset_passes::< GLSL::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -112,8 +115,11 @@ fn compile_passes(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
impl<T: GLInterface> FilterChainImpl<T> { impl<T: GLInterface> FilterChainImpl<T> {
/// Load a filter chain from a pre-parsed `ShaderPreset`. /// Load a filter chain from a pre-parsed `ShaderPreset`.
pub(crate) unsafe fn load_from_preset( pub(crate) unsafe fn load_from_preset(

View file

@ -40,19 +40,25 @@ use std::collections::VecDeque;
use std::fmt::{Debug, Formatter}; use std::fmt::{Debug, Formatter};
use std::path::Path; use std::path::Path;
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<MSL, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<MSL, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes(
pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = let (passes, semantics) =
MSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>( MSL::compile_preset_passes::<SpirvCompilation, SpirvCross, FilterChainError>(
shaders, &textures, shaders, &textures,
)?; )?;
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
/// A Metal filter chain. /// A Metal filter chain.
pub struct FilterChainMetal { pub struct FilterChainMetal {
pub(crate) common: FilterCommon, pub(crate) common: FilterCommon,

View file

@ -209,13 +209,16 @@ impl Drop for FrameResiduals {
} }
} }
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross> + Send>; ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross> + Send>;
fn compile_passes(
pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
disable_cache: bool, disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache { let (passes, semantics) = if !disable_cache {
SPIRV::compile_preset_passes::< SPIRV::compile_preset_passes::<
CachedCompilation<SpirvCompilation>, CachedCompilation<SpirvCompilation>,
@ -229,8 +232,11 @@ fn compile_passes(
}; };
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
impl FilterChainVulkan { impl FilterChainVulkan {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub unsafe fn load_from_path<V, E>( pub unsafe fn load_from_path<V, E>(

View file

@ -21,7 +21,7 @@ librashader-reflect = { path = "../librashader-reflect", version = "0.2.7", feat
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.7" } librashader-runtime = { path = "../librashader-runtime" , version = "0.2.7" }
wgpu = { version = "0.20.0", default-features = false, features = ["wgsl"] } wgpu = { version = "0.20.0", default-features = false, features = ["wgsl"] }
image = "0.24.7" image = "0.25.1"
thiserror = "1.0.50" thiserror = "1.0.50"
bytemuck = { version = "1.14.0", features = ["derive"] } bytemuck = { version = "1.14.0", features = ["derive"] }
array-concat = "0.5.2" array-concat = "0.5.2"

View file

@ -38,19 +38,25 @@ use crate::options::{FilterChainOptionsWgpu, FrameOptionsWgpu};
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::{InputImage, OwnedImage}; use crate::texture::{InputImage, OwnedImage};
type ShaderPassMeta = mod compile {
use super::*;
pub type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation, Naga> + Send>; ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation, Naga> + Send>;
fn compile_passes(
pub fn compile_passes(
shaders: Vec<ShaderPassConfig>, shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig], textures: &[TextureConfig],
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> { ) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = let (passes, semantics) =
WGSL::compile_preset_passes::<SpirvCompilation, Naga, FilterChainError>( WGSL::compile_preset_passes::<SpirvCompilation, Naga, FilterChainError>(
shaders, &textures, shaders, &textures,
)?; )?;
Ok((passes, semantics)) Ok((passes, semantics))
}
} }
use compile::{compile_passes, ShaderPassMeta};
/// A wgpu filter chain. /// A wgpu filter chain.
pub struct FilterChainWgpu { pub struct FilterChainWgpu {
pub(crate) common: FilterCommon, pub(crate) common: FilterCommon,

View file

@ -23,7 +23,7 @@ array-concat = "0.5.2"
tinymap = "0.4.0" tinymap = "0.4.0"
[dependencies.image] [dependencies.image]
version = "0.24.5" version = "0.25.1"
features = [ features = [
"gif", "jpeg", "png", "gif", "jpeg", "png",
"tga", "pnm", "tiff", "tga", "pnm", "tiff",

View file

@ -5,24 +5,27 @@ use librashader_presets::{Scale2D, ScaleFactor, ScaleType, Scaling};
use num_traits::AsPrimitive; use num_traits::AsPrimitive;
use std::ops::Mul; use std::ops::Mul;
pub const MAX_TEXEL_SIZE: f32 = 16384f32;
/// Trait for size scaling relative to the viewport. /// Trait for size scaling relative to the viewport.
pub trait ViewportSize<T> pub trait ViewportSize<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
/// Produce a `Size<T>` scaled with the input scaling options. /// Produce a `Size<T>` scaled with the input scaling options.
/// The size will at minimum be 1x1, and at a maximum 16384x16384.
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>; fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>;
} }
impl<T> ViewportSize<T> for Size<T> impl<T> ViewportSize<T> for Size<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T> fn scale_viewport(self, scaling: Scale2D, viewport: Size<T>, original: Size<T>) -> Size<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
scaling::scale(scaling, self, viewport, original) scaling::scale(scaling, self, viewport, original)
@ -35,6 +38,7 @@ pub trait MipmapSize<T> {
fn calculate_miplevels(self) -> T; fn calculate_miplevels(self) -> T;
/// Scale the size according to the given mipmap level. /// Scale the size according to the given mipmap level.
/// The size will at minimum be 1x1, and at a maximum 16384x16384.
fn scale_mipmap(self, miplevel: T) -> Size<T>; fn scale_mipmap(self, miplevel: T) -> Size<T>;
} }
@ -59,7 +63,7 @@ impl MipmapSize<u32> for Size<u32> {
fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>, original: Size<T>) -> Size<T> fn scale<T>(scaling: Scale2D, source: Size<T>, viewport: Size<T>, original: Size<T>) -> Size<T>
where where
T: Mul<ScaleFactor, Output = f32> + Copy + 'static, T: Mul<ScaleFactor, Output = f32> + Copy + Ord + 'static,
f32: AsPrimitive<T>, f32: AsPrimitive<T>,
{ {
let width = match scaling.x { let width = match scaling.x {
@ -101,8 +105,14 @@ where
}; };
Size { Size {
width: width.round().as_(), width: std::cmp::min(
height: height.round().as_(), std::cmp::max(width.round().as_(), 1f32.as_()),
MAX_TEXEL_SIZE.as_(),
),
height: std::cmp::min(
std::cmp::max(height.round().as_(), 1f32.as_()),
MAX_TEXEL_SIZE.as_(),
),
} }
} }