diff --git a/.idea/src.iml b/.idea/src.iml index 8c2d7a9..bb57c00 100644 --- a/.idea/src.iml +++ b/.idea/src.iml @@ -14,6 +14,7 @@ + diff --git a/Cargo.lock b/Cargo.lock index 5d1c87e..59a8ee7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -456,7 +456,6 @@ name = "librashader-reflect" version = "0.1.0" dependencies = [ "bitflags", - "bytemuck", "librashader-common", "librashader-preprocess", "naga", @@ -468,6 +467,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "librashader-runtime" +version = "0.1.0" +dependencies = [ + "bytemuck", + "librashader-preprocess", + "librashader-presets", + "librashader-reflect", + "rustc-hash", +] + [[package]] name = "librashader-runtime-d3d11" version = "0.1.0" @@ -478,6 +488,7 @@ dependencies = [ "librashader-preprocess", "librashader-presets", "librashader-reflect", + "librashader-runtime", "rustc-hash", "windows", ] @@ -493,6 +504,7 @@ dependencies = [ "librashader-preprocess", "librashader-presets", "librashader-reflect", + "librashader-runtime", "rustc-hash", "spirv_cross", "thiserror", @@ -509,6 +521,7 @@ dependencies = [ "librashader-preprocess", "librashader-presets", "librashader-reflect", + "librashader-runtime", "rustc-hash", "spirv_cross", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 2f5760d..df8cf6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "librashader-presets", "librashader-preprocess", "librashader-reflect", + "librashader-runtime", "librashader-runtime-d3d11", "librashader-runtime-gl", "librashader-runtime-gl46", diff --git a/librashader-reflect/Cargo.toml b/librashader-reflect/Cargo.toml index 687f8be..c493da7 100644 --- a/librashader-reflect/Cargo.toml +++ b/librashader-reflect/Cargo.toml @@ -21,9 +21,6 @@ naga = { version = "0.10.0", features = ["glsl-in", "spv-in", "spv-out", "glsl-o rspirv = { version = "0.11.0+1.5.4", optional = true } rspirv-reflect = { git = "https://github.com/Traverse-Research/rspirv-reflect", optional = true } - -bytemuck = "1.12.3" - [features] default = [] unstable-rust-pipeline = [ "naga", "rspirv", "rspirv-reflect" ] diff --git a/librashader-reflect/src/reflect/mod.rs b/librashader-reflect/src/reflect/mod.rs index a554a4d..8489a31 100644 --- a/librashader-reflect/src/reflect/mod.rs +++ b/librashader-reflect/src/reflect/mod.rs @@ -13,7 +13,6 @@ pub mod semantics; mod naga; #[cfg(feature = "unstable-rust-pipeline")] mod rspirv; -pub mod uniforms; pub trait ReflectShader { fn reflect( diff --git a/librashader-runtime-d3d11/Cargo.toml b/librashader-runtime-d3d11/Cargo.toml index 4f0a483..2b49630 100644 --- a/librashader-runtime-d3d11/Cargo.toml +++ b/librashader-runtime-d3d11/Cargo.toml @@ -6,10 +6,12 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -"librashader-common" = { path = "../librashader-common", features = ["d3d11"] } -"librashader-presets" = { path = "../librashader-presets" } -"librashader-preprocess" = { path = "../librashader-preprocess" } -"librashader-reflect" = { path = "../librashader-reflect" } +librashader-common = { path = "../librashader-common", features = ["d3d11"] } +librashader-presets = { path = "../librashader-presets" } +librashader-preprocess = { path = "../librashader-preprocess" } +librashader-reflect = { path = "../librashader-reflect" } +librashader-runtime = { path = "../librashader-runtime" } + rustc-hash = "1.1.0" gfx-maths = "0.2.8" bytemuck = "1.12.3" diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 5675bd1..5c34d92 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -53,55 +53,6 @@ pub struct FilterCommon { } impl FilterChain { - fn load_pass_semantics( - uniform_semantics: &mut FxHashMap, - texture_semantics: &mut FxHashMap>, - config: &ShaderPassConfig, - ) { - let Some(alias) = &config.alias else { - return; - }; - - // Ignore empty aliases - if alias.trim().is_empty() { - return; - } - - let index = config.id as usize; - - // PassOutput - texture_semantics.insert( - alias.clone(), - SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}Size"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }), - ); - - // PassFeedback - texture_semantics.insert( - format!("{alias}Feedback"), - SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}FeedbackSize"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }), - ); - } - fn create_constant_buffer(device: &ID3D11Device, size: u32) -> util::Result { eprintln!("{size}"); unsafe { @@ -343,35 +294,19 @@ impl FilterChain { .collect::)>>>()?; for details in &passes { - FilterChain::load_pass_semantics( + librashader_runtime::semantics::insert_pass_semantics( &mut uniform_semantics, &mut texture_semantics, details.0, ) } - - // add lut params - for (index, texture) in preset.textures.iter().enumerate() { - texture_semantics.insert( - texture.name.clone(), - SemanticMap { - semantics: TextureSemantics::User, - index, - }, - ); - - uniform_semantics.insert( - format!("{}Size", texture.name), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::User, - index, - }), - ); - } + librashader_runtime::semantics::insert_lut_semantics(&preset.textures, + &mut uniform_semantics, + &mut texture_semantics); let semantics = ReflectSemantics { uniform_semantics, - texture_semantics: texture_semantics, + texture_semantics, }; Ok((passes, semantics)) diff --git a/librashader-runtime-d3d11/src/filter_pass.rs b/librashader-runtime-d3d11/src/filter_pass.rs index 007c2a9..e74ed0a 100644 --- a/librashader-runtime-d3d11/src/filter_pass.rs +++ b/librashader-runtime-d3d11/src/filter_pass.rs @@ -91,7 +91,7 @@ impl FilterPass { &mut self, pass_index: usize, parent: &FilterCommon, - mvp: &[f32], + mvp: &[f32; 16], frame_count: u32, frame_direction: i32, fb_size: Size, diff --git a/librashader-runtime-d3d11/src/render_target.rs b/librashader-runtime-d3d11/src/render_target.rs index 86d4940..1ddb4cf 100644 --- a/librashader-runtime-d3d11/src/render_target.rs +++ b/librashader-runtime-d3d11/src/render_target.rs @@ -3,7 +3,7 @@ use librashader_common::Size; use crate::framebuffer::{OutputFramebuffer}; #[rustfmt::skip] -static DEFAULT_MVP: &[f32] = &[ +static DEFAULT_MVP: &[f32; 16] = &[ 2f32, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, @@ -12,12 +12,12 @@ static DEFAULT_MVP: &[f32] = &[ #[derive(Debug, Clone)] pub struct RenderTarget<'a> { - pub mvp: &'a [f32], + pub mvp: &'a [f32; 16], pub output: OutputFramebuffer } impl<'a> RenderTarget<'a> { - pub fn new(backbuffer: OutputFramebuffer, mvp: Option<&'a [f32]>) -> Self { + pub fn new(backbuffer: OutputFramebuffer, mvp: Option<&'a [f32; 16]>) -> Self { if let Some(mvp) = mvp { RenderTarget { output: backbuffer, diff --git a/librashader-runtime-gl/Cargo.toml b/librashader-runtime-gl/Cargo.toml index 4b35ce1..e557ed1 100644 --- a/librashader-runtime-gl/Cargo.toml +++ b/librashader-runtime-gl/Cargo.toml @@ -10,6 +10,7 @@ librashader-common = { path = "../librashader-common", features = ["opengl"] } librashader-presets = { path = "../librashader-presets" } librashader-preprocess = { path = "../librashader-preprocess" } librashader-reflect = { path = "../librashader-reflect" } +librashader-runtime = { path = "../librashader-runtime" } spirv_cross = "0.23.1" rustc-hash = "1.1.0" gl = "0.14.0" diff --git a/librashader-runtime-gl/src/binding.rs b/librashader-runtime-gl/src/binding.rs index fa55290..02b818d 100644 --- a/librashader-runtime-gl/src/binding.rs +++ b/librashader-runtime-gl/src/binding.rs @@ -1,6 +1,6 @@ use gl::types::GLint; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; +use librashader_runtime::uniforms::{BindUniform, UniformStorage, UniformScalar}; #[derive(Debug)] pub enum VariableLocation { diff --git a/librashader-runtime-gl/src/filter_chain.rs b/librashader-runtime-gl/src/filter_chain.rs index 1203aa0..18b97ea 100644 --- a/librashader-runtime-gl/src/filter_chain.rs +++ b/librashader-runtime-gl/src/filter_chain.rs @@ -52,55 +52,6 @@ pub struct FilterMutable { } impl FilterChain { - fn load_pass_semantics( - uniform_semantics: &mut FxHashMap, - texture_semantics: &mut FxHashMap>, - config: &ShaderPassConfig, - ) { - let Some(alias) = &config.alias else { - return; - }; - - // Ignore empty aliases - if alias.trim().is_empty() { - return; - } - - let index = config.id as usize; - - // PassOutput - texture_semantics.insert( - alias.clone(), - SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}Size"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }), - ); - - // PassFeedback - texture_semantics.insert( - format!("{alias}Feedback"), - SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}FeedbackSize"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }), - ); - } - fn reflect_uniform_location(pipeline: GLuint, meta: &impl UniformMeta) -> VariableLocation { // todo: support both ubo and pushco // todo: fix this. @@ -237,31 +188,16 @@ impl FilterChain { .collect::)>>>()?; for details in &passes { - FilterChain::load_pass_semantics( + librashader_runtime::semantics::insert_pass_semantics( &mut uniform_semantics, &mut texture_semantics, &details.0, ) } - // add lut params - for (index, texture) in textures.iter().enumerate() { - texture_semantics.insert( - texture.name.clone(), - SemanticMap { - semantics: TextureSemantics::User, - index, - }, - ); - - uniform_semantics.insert( - format!("{}Size", texture.name), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::User, - index, - }), - ); - } + librashader_runtime::semantics::insert_lut_semantics(textures, + &mut uniform_semantics, + &mut texture_semantics); let semantics = ReflectSemantics { uniform_semantics, diff --git a/librashader-runtime-gl/src/filter_pass.rs b/librashader-runtime-gl/src/filter_pass.rs index 96ca8c6..e632923 100644 --- a/librashader-runtime-gl/src/filter_pass.rs +++ b/librashader-runtime-gl/src/filter_pass.rs @@ -1,3 +1,4 @@ +use std::marker::PhantomData; use gl::types::{GLint, GLsizei, GLsizeiptr, GLuint}; use librashader_reflect::back::cross::GlslangGlslContext; use librashader_reflect::back::ShaderCompilerOutput; @@ -8,7 +9,7 @@ use librashader_preprocess::ShaderSource; use librashader_presets::ShaderPassConfig; use librashader_reflect::reflect::semantics::{BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, VariableSemantics}; use rustc_hash::FxHashMap; -use librashader_reflect::reflect::uniforms::UniformStorage; +use librashader_runtime::uniforms::UniformStorage; use crate::binding::{BufferStorage, GlUniformBinder, UniformLocation, VariableLocation}; use crate::filter_chain::FilterCommon; @@ -42,7 +43,7 @@ impl FilterPass { viewport: &Viewport, original: &Texture, source: &Texture, - output: RenderTarget, + output: RenderTarget ) { let framebuffer = output.framebuffer; @@ -203,7 +204,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::Original.semantics(0)) { - FilterPass::bind_texture(&parent.samplers, binding, original); + Self::bind_texture(&parent.samplers, binding, original); } // bind OriginalSize @@ -223,7 +224,7 @@ impl FilterPass { .get(&TextureSemantics::Source.semantics(0)) { // eprintln!("setting source binding to {}", binding.binding); - FilterPass::bind_texture(&parent.samplers, binding, source); + Self::bind_texture(&parent.samplers, binding, source); } // bind SourceSize @@ -241,7 +242,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::OriginalHistory.semantics(0)) { - FilterPass::bind_texture(&parent.samplers, binding, original); + Self::bind_texture(&parent.samplers, binding, original); } if let Some((location, offset)) = self .uniform_bindings @@ -258,7 +259,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::OriginalHistory.semantics(index + 1)) { - FilterPass::bind_texture(&parent.samplers, binding, output); + Self::bind_texture(&parent.samplers, binding, output); } if let Some((location, offset)) = self.uniform_bindings.get( @@ -279,7 +280,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::PassOutput.semantics(index)) { - FilterPass::bind_texture(&parent.samplers, binding, output); + Self::bind_texture(&parent.samplers, binding, output); } if let Some((location, offset)) = self @@ -302,7 +303,7 @@ impl FilterPass { if feedback.image.handle == 0 { eprintln!("[WARNING] trying to bind PassFeedback: {index} which has texture 0 to slot {} in pass {pass_index}", binding.binding) } - FilterPass::bind_texture(&parent.samplers, binding, feedback); + Self::bind_texture(&parent.samplers, binding, feedback); } if let Some((location, offset)) = self @@ -351,7 +352,7 @@ impl FilterPass { .texture_meta .get(&TextureSemantics::User.semantics(*index)) { - FilterPass::bind_texture(&parent.samplers, binding, lut); + Self::bind_texture(&parent.samplers, binding, lut); } if let Some((location, offset)) = self diff --git a/librashader-runtime-gl/src/util.rs b/librashader-runtime-gl/src/util.rs index dfaf139..75cb29d 100644 --- a/librashader-runtime-gl/src/util.rs +++ b/librashader-runtime-gl/src/util.rs @@ -2,7 +2,7 @@ use gl::types::{GLenum, GLint, GLuint}; use librashader_common::Size; use librashader_reflect::back::cross::GlVersion; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; +use librashader_runtime::uniforms::{BindUniform, UniformStorage, UniformScalar}; use crate::binding::UniformLocation; pub fn calc_miplevel(size: Size) -> u32 { diff --git a/librashader-runtime-gl46/Cargo.toml b/librashader-runtime-gl46/Cargo.toml index d36b7a0..7790b8c 100644 --- a/librashader-runtime-gl46/Cargo.toml +++ b/librashader-runtime-gl46/Cargo.toml @@ -10,6 +10,8 @@ librashader-common = { path = "../librashader-common", features = ["opengl"] } librashader-presets = { path = "../librashader-presets" } librashader-preprocess = { path = "../librashader-preprocess" } librashader-reflect = { path = "../librashader-reflect" } +librashader-runtime = { path = "../librashader-runtime" } + spirv_cross = "0.23.1" rustc-hash = "1.1.0" gl = "0.14.0" diff --git a/librashader-runtime-gl46/src/binding.rs b/librashader-runtime-gl46/src/binding.rs index fa55290..02b818d 100644 --- a/librashader-runtime-gl46/src/binding.rs +++ b/librashader-runtime-gl46/src/binding.rs @@ -1,6 +1,6 @@ use gl::types::GLint; use librashader_reflect::reflect::semantics::BindingStage; -use librashader_reflect::reflect::uniforms::{BindUniform, UniformStorage, UniformScalar}; +use librashader_runtime::uniforms::{BindUniform, UniformStorage, UniformScalar}; #[derive(Debug)] pub enum VariableLocation { diff --git a/librashader-runtime-gl46/src/filter_chain.rs b/librashader-runtime-gl46/src/filter_chain.rs index a56cec7..512c3e9 100644 --- a/librashader-runtime-gl46/src/filter_chain.rs +++ b/librashader-runtime-gl46/src/filter_chain.rs @@ -51,55 +51,6 @@ pub struct FilterMutable { } impl FilterChain { - fn load_pass_semantics( - uniform_semantics: &mut FxHashMap, - texture_semantics: &mut FxHashMap>, - config: &ShaderPassConfig, - ) { - let Some(alias) = &config.alias else { - return; - }; - - // Ignore empty aliases - if alias.trim().is_empty() { - return; - } - - let index = config.id as usize; - - // PassOutput - texture_semantics.insert( - alias.clone(), - SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}Size"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassOutput, - index, - }), - ); - - // PassFeedback - texture_semantics.insert( - format!("{alias}Feedback"), - SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }, - ); - uniform_semantics.insert( - format!("{alias}FeedbackSize"), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::PassFeedback, - index, - }), - ); - } - fn reflect_uniform_location(pipeline: GLuint, meta: &impl UniformMeta) -> VariableLocation { // todo: support both ubo and pushco // todo: fix this. @@ -236,7 +187,7 @@ impl FilterChain { .collect::)>>>()?; for details in &passes { - FilterChain::load_pass_semantics( + librashader_runtime::semantics::insert_pass_semantics( &mut uniform_semantics, &mut texture_semantics, &details.0, @@ -244,24 +195,9 @@ impl FilterChain { } // add lut params - for (index, texture) in textures.iter().enumerate() { - texture_semantics.insert( - texture.name.clone(), - SemanticMap { - semantics: TextureSemantics::User, - index, - }, - ); - - uniform_semantics.insert( - format!("{}Size", texture.name), - UniformSemantic::Texture(SemanticMap { - semantics: TextureSemantics::User, - index, - }), - ); - } - + librashader_runtime::semantics::insert_lut_semantics(textures, + &mut uniform_semantics, + &mut texture_semantics); let semantics = ReflectSemantics { uniform_semantics, texture_semantics, diff --git a/librashader-runtime/Cargo.toml b/librashader-runtime/Cargo.toml new file mode 100644 index 0000000..560d6e3 --- /dev/null +++ b/librashader-runtime/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "librashader-runtime" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +librashader-presets = { path = "../librashader-presets" } +librashader-preprocess = { path = "../librashader-preprocess" } +librashader-reflect = { path = "../librashader-reflect" } +bytemuck = "1.12.3" +rustc-hash = "1.1.0" \ No newline at end of file diff --git a/librashader-runtime/src/lib.rs b/librashader-runtime/src/lib.rs new file mode 100644 index 0000000..e94188a --- /dev/null +++ b/librashader-runtime/src/lib.rs @@ -0,0 +1,2 @@ +pub mod semantics; +pub mod uniforms; diff --git a/librashader-runtime/src/semantics.rs b/librashader-runtime/src/semantics.rs new file mode 100644 index 0000000..0cd0f28 --- /dev/null +++ b/librashader-runtime/src/semantics.rs @@ -0,0 +1,78 @@ +use librashader_presets::{ShaderPassConfig, TextureConfig}; +use rustc_hash::FxHashMap; +use librashader_reflect::reflect::semantics::{SemanticMap, TextureSemantics, UniformSemantic}; + +pub type UniformSemanticsMap = FxHashMap; +pub type TextureSemanticsMap = FxHashMap>; + + +pub fn insert_pass_semantics( + uniform_semantics: &mut UniformSemanticsMap, + texture_semantics: &mut TextureSemanticsMap, + config: &ShaderPassConfig, +) { + let Some(alias) = &config.alias else { + return; + }; + + // Ignore empty aliases + if alias.trim().is_empty() { + return; + } + + let index = config.id as usize; + + // PassOutput + texture_semantics.insert( + alias.clone(), + SemanticMap { + semantics: TextureSemantics::PassOutput, + index, + }, + ); + uniform_semantics.insert( + format!("{alias}Size"), + UniformSemantic::Texture(SemanticMap { + semantics: TextureSemantics::PassOutput, + index, + }), + ); + + // PassFeedback + texture_semantics.insert( + format!("{alias}Feedback"), + SemanticMap { + semantics: TextureSemantics::PassFeedback, + index, + }, + ); + uniform_semantics.insert( + format!("{alias}FeedbackSize"), + UniformSemantic::Texture(SemanticMap { + semantics: TextureSemantics::PassFeedback, + index, + }), + ); +} + +pub fn insert_lut_semantics(textures: &[TextureConfig], + uniform_semantics: &mut UniformSemanticsMap, + texture_semantics: &mut TextureSemanticsMap) { + for (index, texture) in textures.iter().enumerate() { + texture_semantics.insert( + texture.name.clone(), + SemanticMap { + semantics: TextureSemantics::User, + index, + }, + ); + + uniform_semantics.insert( + format!("{}Size", texture.name), + UniformSemantic::Texture(SemanticMap { + semantics: TextureSemantics::User, + index, + }), + ); + } +} diff --git a/librashader-reflect/src/reflect/uniforms.rs b/librashader-runtime/src/uniforms.rs similarity index 98% rename from librashader-reflect/src/reflect/uniforms.rs rename to librashader-runtime/src/uniforms.rs index fdc945d..c62e5d9 100644 --- a/librashader-reflect/src/reflect/uniforms.rs +++ b/librashader-runtime/src/uniforms.rs @@ -1,5 +1,5 @@ use std::marker::PhantomData; -use crate::reflect::semantics::MemberOffset; +use librashader_reflect::reflect::semantics::MemberOffset; pub trait UniformScalar: Copy + bytemuck::Pod {} impl UniformScalar for f32 {}