preprocess: move ShaderSource to preprocess and rename common def libs
This commit is contained in:
parent
e0b66c2c60
commit
80fa30e54e
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -611,7 +611,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "68783febc7782c6c5cb401fbda4de5a9898be1762314da0bb2c10ced61f18b0c"
|
||||
|
||||
[[package]]
|
||||
name = "librashader"
|
||||
name = "librashader-common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gl",
|
||||
|
@ -622,7 +622,7 @@ dependencies = [
|
|||
name = "librashader-preprocess"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"nom",
|
||||
"thiserror",
|
||||
]
|
||||
|
@ -631,9 +631,10 @@ dependencies = [
|
|||
name = "librashader-presets"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"nom",
|
||||
"nom_locate",
|
||||
"num-traits",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
|
@ -642,7 +643,8 @@ name = "librashader-reflect"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"librashader-preprocess",
|
||||
"naga",
|
||||
"rspirv",
|
||||
"rspirv-reflect",
|
||||
|
@ -656,7 +658,7 @@ dependencies = [
|
|||
name = "librashader-runtime-dx11"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"librashader-preprocess",
|
||||
"librashader-presets",
|
||||
"librashader-reflect",
|
||||
|
@ -671,7 +673,7 @@ dependencies = [
|
|||
"bytemuck",
|
||||
"gl",
|
||||
"glfw",
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"librashader-preprocess",
|
||||
"librashader-presets",
|
||||
"librashader-reflect",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[workspace]
|
||||
members = [
|
||||
"librashader",
|
||||
"librashader-common",
|
||||
"librashader-presets",
|
||||
"librashader-preprocess",
|
||||
"librashader-reflect",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "librashader"
|
||||
name = "librashader-common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
|
@ -5,25 +5,6 @@ pub mod image;
|
|||
use std::convert::Infallible;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ShaderSource {
|
||||
pub vertex: String,
|
||||
pub fragment: String,
|
||||
pub name: Option<String>,
|
||||
pub parameters: Vec<ShaderParameter>,
|
||||
pub format: ShaderFormat,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ShaderParameter {
|
||||
pub id: String,
|
||||
pub description: String,
|
||||
pub initial: f32,
|
||||
pub minimum: f32,
|
||||
pub maximum: f32,
|
||||
pub step: f32,
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum ShaderFormat {
|
|
@ -8,7 +8,7 @@ edition = "2021"
|
|||
[dependencies]
|
||||
thiserror = "1.0.37"
|
||||
nom = "7.1.1"
|
||||
librashader = { path = "../librashader" }
|
||||
"librashader-common" = { path = "../librashader-common" }
|
||||
|
||||
[features]
|
||||
default = [ "line_directives" ]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use librashader::ShaderParameter;
|
||||
use crate::ShaderParameter;
|
||||
use std::convert::Infallible;
|
||||
use std::path::PathBuf;
|
||||
use thiserror::Error;
|
||||
|
|
|
@ -5,9 +5,34 @@ mod stage;
|
|||
|
||||
use crate::include::read_source;
|
||||
pub use error::*;
|
||||
use librashader::ShaderSource;
|
||||
use librashader_common::ShaderFormat;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ShaderSource {
|
||||
pub vertex: String,
|
||||
pub fragment: String,
|
||||
pub name: Option<String>,
|
||||
pub parameters: Vec<ShaderParameter>,
|
||||
pub format: ShaderFormat,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ShaderParameter {
|
||||
pub id: String,
|
||||
pub description: String,
|
||||
pub initial: f32,
|
||||
pub minimum: f32,
|
||||
pub maximum: f32,
|
||||
pub step: f32,
|
||||
}
|
||||
|
||||
impl ShaderSource {
|
||||
pub fn load(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
|
||||
load_shader_source(path)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) trait SourceOutput {
|
||||
fn push_line(&mut self, str: &str);
|
||||
fn mark_line(&mut self, line_no: usize, comment: &str) {
|
||||
|
@ -23,7 +48,7 @@ impl SourceOutput for String {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
|
||||
pub(crate) fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
|
||||
let source = read_source(path)?;
|
||||
let meta = pragma::parse_pragma_meta(&source)?;
|
||||
let text = stage::process_stages(&source)?;
|
||||
|
@ -70,3 +95,4 @@ mod test {
|
|||
eprintln!("{params:?}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::PreprocessError;
|
||||
use librashader::{ShaderFormat, ShaderParameter};
|
||||
use crate::{PreprocessError, ShaderParameter};
|
||||
use librashader_common::ShaderFormat;
|
||||
use nom::bytes::complete::{is_not, tag, take_until, take_while};
|
||||
use nom::combinator::map_res;
|
||||
use nom::number::complete::float;
|
||||
|
@ -120,7 +120,7 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
|
|||
#[cfg(test)]
|
||||
mod test {
|
||||
use crate::pragma::parse_parameter_string;
|
||||
use librashader::ShaderParameter;
|
||||
use crate::ShaderParameter;
|
||||
|
||||
#[test]
|
||||
fn parses_parameter_pragma() {
|
||||
|
|
|
@ -9,5 +9,5 @@ edition = "2021"
|
|||
thiserror = "1.0.37"
|
||||
nom = "7.1.1"
|
||||
nom_locate = "4.0.0"
|
||||
librashader = { path = "../librashader" }
|
||||
"librashader-common" = { path = "../librashader-common" }
|
||||
num-traits = "0.2"
|
|
@ -14,7 +14,7 @@ use std::fs::File;
|
|||
use std::io::Read;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use librashader::{FilterMode, WrapMode};
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Value {
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::error::ParsePresetError;
|
|||
use std::ops::Mul;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use librashader::{FilterMode, WrapMode};
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ShaderPassConfig {
|
||||
|
|
|
@ -9,7 +9,8 @@ edition = "2021"
|
|||
naga = { version = "0.10.0", path = "../naga", features = ["glsl-in", "spv-in", "spv-out", "glsl-out", "wgsl-out"] }
|
||||
shaderc = { version = "0.8.0" }
|
||||
spirv_cross = { version = "0.23.1", features = [ "glsl", "hlsl" ] }
|
||||
librashader = { path = "../librashader" }
|
||||
|
||||
|
||||
thiserror = "1.0.37"
|
||||
bitflags = "1.3.2"
|
||||
rustc-hash = "1.1.0"
|
||||
|
@ -17,4 +18,7 @@ rspirv = "0.11.0+1.5.4"
|
|||
|
||||
rspirv-reflect = { git = "https://github.com/Traverse-Research/rspirv-reflect" }
|
||||
|
||||
librashader-common = { path = "../librashader-common" }
|
||||
librashader-preprocess = { path = "../librashader-preprocess" }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::error::ShaderCompileError;
|
||||
use librashader::ShaderSource;
|
||||
use librashader_preprocess::ShaderSource;
|
||||
use naga::front::glsl::{Options, Parser};
|
||||
use naga::{Module, ShaderStage};
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::error::ShaderCompileError;
|
||||
use librashader::ShaderSource;
|
||||
use librashader_preprocess::ShaderSource;
|
||||
use shaderc::{CompilationArtifact, CompileOptions, Limit, ShaderKind};
|
||||
|
||||
pub struct GlslangCompilation {
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
"librashader" = { path = "../librashader" }
|
||||
"librashader-common" = { path = "../librashader-common" }
|
||||
"librashader-presets" = { path = "../librashader-presets" }
|
||||
"librashader-preprocess" = { path = "../librashader-preprocess" }
|
||||
"librashader-reflect" = { path = "../librashader-reflect" }
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::collections::HashMap;
|
|||
use std::error::Error;
|
||||
use std::path::Path;
|
||||
use rustc_hash::FxHashMap;
|
||||
use librashader::ShaderSource;
|
||||
use librashader_preprocess::ShaderSource;
|
||||
use librashader_presets::ShaderPassConfig;
|
||||
use librashader_reflect::back::{CompileShader};
|
||||
use librashader_reflect::back::targets::{FromCompilation, HLSL};
|
||||
|
@ -91,7 +91,7 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
|
|||
let mut reflections = Vec::new();
|
||||
let mut compiled = Vec::new();
|
||||
|
||||
for (index, (_, _, reflect)) in passes.iter_mut().enumerate() {
|
||||
for (index, (_, _, mut reflect)) in passes.into_iter().enumerate() {
|
||||
let reflection = reflect.reflect(index, &semantics)
|
||||
.unwrap();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
"librashader" = { path = "../librashader", features = ["opengl"] }
|
||||
"librashader-common" = { path = "../librashader-common", features = ["opengl"] }
|
||||
"librashader-presets" = { path = "../librashader-presets" }
|
||||
"librashader-preprocess" = { path = "../librashader-preprocess" }
|
||||
"librashader-reflect" = { path = "../librashader-reflect" }
|
||||
|
|
|
@ -6,8 +6,8 @@ use crate::render_target::RenderTarget;
|
|||
use crate::util;
|
||||
use crate::util::{InlineRingBuffer, Texture};
|
||||
use gl::types::{GLenum, GLint, GLsizei, GLsizeiptr, GLuint};
|
||||
use librashader::image::Image;
|
||||
use librashader::{FilterMode, ShaderSource, Size, WrapMode};
|
||||
use librashader_common::image::Image;
|
||||
use librashader_common::{FilterMode, Size, WrapMode};
|
||||
use librashader_presets::{ScaleType, ShaderPassConfig, ShaderPreset, TextureConfig};
|
||||
use librashader_reflect::back::cross::{GlslangGlslContext, GlVersion};
|
||||
use librashader_reflect::back::targets::{CompilerBackend, FromCompilation, GLSL};
|
||||
|
@ -20,6 +20,7 @@ use rustc_hash::FxHashMap;
|
|||
use spirv_cross::spirv::Decoration;
|
||||
use std::error::Error;
|
||||
use std::path::Path;
|
||||
use librashader_preprocess::ShaderSource;
|
||||
use crate::quad_render::DrawQuad;
|
||||
|
||||
pub struct FilterChain {
|
||||
|
@ -126,14 +127,13 @@ type ShaderPassMeta<'a> = (
|
|||
CompilerBackend<
|
||||
impl CompileShader<GLSL, Options = GlVersion, Context = GlslangGlslContext>
|
||||
+ ReflectShader
|
||||
+ Sized,
|
||||
>,
|
||||
);
|
||||
|
||||
impl FilterChain {
|
||||
/// Load a filter chain from a pre-parsed `ShaderPreset`.
|
||||
pub fn load_from_preset(preset: ShaderPreset) -> Result<FilterChain, Box<dyn Error>> {
|
||||
let (passes, semantics) = FilterChain::load_preset(&preset);
|
||||
let (passes, semantics) = FilterChain::load_preset(&preset)?;
|
||||
|
||||
// initialize passes
|
||||
let filters = FilterChain::init_passes(passes, &semantics)?;
|
||||
|
@ -193,21 +193,21 @@ impl FilterChain {
|
|||
Self::load_from_preset(preset)
|
||||
}
|
||||
|
||||
fn load_preset(preset: &ShaderPreset) -> (Vec<ShaderPassMeta>, ReflectSemantics) {
|
||||
fn load_preset(preset: &ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ReflectSemantics), Box<dyn Error>> {
|
||||
let mut uniform_semantics: FxHashMap<String, UniformSemantic> = Default::default();
|
||||
let mut texture_semantics: FxHashMap<String, SemanticMap<TextureSemantics>> =
|
||||
Default::default();
|
||||
|
||||
let passes: Vec<(&ShaderPassConfig, ShaderSource, _)> = preset
|
||||
let passes = preset
|
||||
.shaders
|
||||
.iter()
|
||||
.map(|shader| {
|
||||
eprintln!("[gl] loading {}", &shader.name.display());
|
||||
let source: ShaderSource =
|
||||
librashader_preprocess::load_shader_source(&shader.name).unwrap();
|
||||
ShaderSource::load(&shader.name)?;
|
||||
|
||||
let spirv = librashader_reflect::front::shaderc::compile_spirv(&source).unwrap();
|
||||
let reflect = GLSL::from_compilation(spirv).unwrap();
|
||||
let spirv = librashader_reflect::front::shaderc::compile_spirv(&source)?;
|
||||
let reflect = GLSL::from_compilation(spirv)?;
|
||||
|
||||
for parameter in source.parameters.iter() {
|
||||
uniform_semantics.insert(
|
||||
|
@ -218,12 +218,12 @@ impl FilterChain {
|
|||
}),
|
||||
);
|
||||
}
|
||||
|
||||
(shader, source, reflect)
|
||||
Ok::<_, Box<dyn Error>>((shader, source, reflect))
|
||||
})
|
||||
.collect();
|
||||
|
||||
// todo: this can probably be extracted out.
|
||||
.into_iter()
|
||||
.collect::<Result<Vec<(&ShaderPassConfig,
|
||||
ShaderSource,
|
||||
CompilerBackend<_>)>, _>>()?;
|
||||
|
||||
for details in &passes {
|
||||
FilterChain::load_pass_semantics(
|
||||
|
@ -257,7 +257,7 @@ impl FilterChain {
|
|||
non_uniform_semantics: texture_semantics,
|
||||
};
|
||||
|
||||
(passes, semantics)
|
||||
Ok((passes, semantics))
|
||||
}
|
||||
|
||||
fn load_luts(textures: &[TextureConfig]) -> Result<FxHashMap<usize, Texture>, Box<dyn Error>> {
|
||||
|
|
|
@ -3,12 +3,13 @@ use librashader_reflect::back::cross::GlslangGlslContext;
|
|||
use librashader_reflect::back::ShaderCompilerOutput;
|
||||
use librashader_reflect::reflect::ShaderReflection;
|
||||
|
||||
use librashader::{ShaderFormat, ShaderSource, Size};
|
||||
use librashader_common::{ShaderFormat, Size};
|
||||
use librashader_presets::ShaderPassConfig;
|
||||
use librashader_reflect::reflect::semantics::{
|
||||
MemberOffset, TextureImage, TextureSemantics, VariableSemantics,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
use librashader_preprocess::ShaderSource;
|
||||
|
||||
use crate::binding::{UniformBinding, UniformLocation, VariableLocation};
|
||||
use crate::filter_chain::FilterCommon;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::util;
|
||||
use crate::util::Texture;
|
||||
use gl::types::{GLenum, GLint, GLsizei, GLuint};
|
||||
use librashader::{FilterMode, ShaderFormat, Size, WrapMode};
|
||||
use librashader_common::{FilterMode, ShaderFormat, Size, WrapMode};
|
||||
use librashader_presets::{Scale2D, ScaleType, Scaling};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::sync::mpsc::Receiver;
|
|||
use glfw::{Context, Glfw, Window, WindowEvent};
|
||||
|
||||
use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
|
||||
use librashader::Size;
|
||||
use librashader_common::Size;
|
||||
|
||||
use crate::filter_chain::FilterChain;
|
||||
use crate::framebuffer::{Framebuffer, GlImage, Viewport};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::framebuffer::{Framebuffer, GlImage};
|
||||
use gl::types::{GLenum, GLuint};
|
||||
use librashader::{FilterMode, WrapMode};
|
||||
use librashader_common::{FilterMode, WrapMode};
|
||||
|
||||
pub fn calc_miplevel(width: u32, height: u32) -> u32 {
|
||||
let mut size = std::cmp::max(width, height);
|
||||
|
|
Loading…
Reference in a new issue