runtime: move some runtime commonalities into runtime crate
This commit is contained in:
parent
515fe12568
commit
ae257d8574
|
@ -14,6 +14,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/librashader-common/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/librashader-runtime-d3d11/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/librashader-runtime-gl46/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/librashader-runtime/src" isTestSource="false" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
|
|
15
Cargo.lock
generated
15
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -5,6 +5,7 @@ members = [
|
|||
"librashader-presets",
|
||||
"librashader-preprocess",
|
||||
"librashader-reflect",
|
||||
"librashader-runtime",
|
||||
"librashader-runtime-d3d11",
|
||||
"librashader-runtime-gl",
|
||||
"librashader-runtime-gl46",
|
||||
|
|
|
@ -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" ]
|
||||
|
|
|
@ -13,7 +13,6 @@ pub mod semantics;
|
|||
mod naga;
|
||||
#[cfg(feature = "unstable-rust-pipeline")]
|
||||
mod rspirv;
|
||||
pub mod uniforms;
|
||||
|
||||
pub trait ReflectShader {
|
||||
fn reflect(
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -53,55 +53,6 @@ pub struct FilterCommon {
|
|||
}
|
||||
|
||||
impl FilterChain {
|
||||
fn load_pass_semantics(
|
||||
uniform_semantics: &mut FxHashMap<String, UniformSemantic>,
|
||||
texture_semantics: &mut FxHashMap<String, SemanticMap<TextureSemantics>>,
|
||||
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<ID3D11Buffer> {
|
||||
eprintln!("{size}");
|
||||
unsafe {
|
||||
|
@ -343,35 +294,19 @@ impl FilterChain {
|
|||
.collect::<util::Result<Vec<(&ShaderPassConfig, ShaderSource, CompilerBackend<_>)>>>()?;
|
||||
|
||||
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))
|
||||
|
|
|
@ -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<u32>,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -52,55 +52,6 @@ pub struct FilterMutable {
|
|||
}
|
||||
|
||||
impl FilterChain {
|
||||
fn load_pass_semantics(
|
||||
uniform_semantics: &mut FxHashMap<String, UniformSemantic>,
|
||||
texture_semantics: &mut FxHashMap<String, SemanticMap<TextureSemantics>>,
|
||||
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::<Result<Vec<(ShaderPassConfig, ShaderSource, CompilerBackend<_>)>>>()?;
|
||||
|
||||
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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>) -> u32 {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -51,55 +51,6 @@ pub struct FilterMutable {
|
|||
}
|
||||
|
||||
impl FilterChain {
|
||||
fn load_pass_semantics(
|
||||
uniform_semantics: &mut FxHashMap<String, UniformSemantic>,
|
||||
texture_semantics: &mut FxHashMap<String, SemanticMap<TextureSemantics>>,
|
||||
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::<Result<Vec<(ShaderPassConfig, ShaderSource, CompilerBackend<_>)>>>()?;
|
||||
|
||||
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,
|
||||
|
|
13
librashader-runtime/Cargo.toml
Normal file
13
librashader-runtime/Cargo.toml
Normal file
|
@ -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"
|
2
librashader-runtime/src/lib.rs
Normal file
2
librashader-runtime/src/lib.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod semantics;
|
||||
pub mod uniforms;
|
78
librashader-runtime/src/semantics.rs
Normal file
78
librashader-runtime/src/semantics.rs
Normal file
|
@ -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<String, UniformSemantic>;
|
||||
pub type TextureSemanticsMap = FxHashMap<String, SemanticMap<TextureSemantics>>;
|
||||
|
||||
|
||||
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,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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 {}
|
Loading…
Reference in a new issue