reflect: make ShaderPassArtifact
simpler as PassResource
already includes the source data
This commit is contained in:
parent
3ee5e66c0d
commit
5978f95f76
|
@ -8,7 +8,7 @@ use crate::reflect::semantics::{
|
||||||
use librashader_common::map::{FastHashMap, ShortString};
|
use librashader_common::map::{FastHashMap, ShortString};
|
||||||
use librashader_pack::PassResource;
|
use librashader_pack::PassResource;
|
||||||
use librashader_preprocess::{PreprocessError, ShaderSource};
|
use librashader_preprocess::{PreprocessError, ShaderSource};
|
||||||
use librashader_presets::{PassMeta, ShaderPreset, TextureMeta};
|
use librashader_presets::{ShaderPreset, TextureMeta};
|
||||||
|
|
||||||
/// Artifacts of a reflected and compiled shader pass.
|
/// Artifacts of a reflected and compiled shader pass.
|
||||||
///
|
///
|
||||||
|
@ -28,7 +28,7 @@ use librashader_presets::{PassMeta, ShaderPreset, TextureMeta};
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This allows a runtime to not name the backing type of the compiled artifact if not necessary.
|
/// This allows a runtime to not name the backing type of the compiled artifact if not necessary.
|
||||||
pub type ShaderPassArtifact<T> = (PassMeta, ShaderSource, CompilerBackend<T>);
|
pub type ShaderPassArtifact<T> = (PassResource, CompilerBackend<T>);
|
||||||
|
|
||||||
impl<T: OutputTarget> CompilePresetTarget for T {}
|
impl<T: OutputTarget> CompilePresetTarget for T {}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ pub trait CompilePresetTarget: OutputTarget {
|
||||||
/// Compile passes of a shader preset given the applicable
|
/// Compile passes of a shader preset given the applicable
|
||||||
/// shader output target, compilation type, and resulting error.
|
/// shader output target, compilation type, and resulting error.
|
||||||
fn compile_preset_passes<'a, I, R, E>(
|
fn compile_preset_passes<'a, I, R, E>(
|
||||||
passes: Vec<PassResource>,
|
passes: impl IntoIterator<Item = PassResource>,
|
||||||
textures: impl Iterator<Item = &'a TextureMeta>,
|
textures: impl Iterator<Item = &'a TextureMeta>,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
|
@ -63,7 +63,7 @@ pub trait CompilePresetTarget: OutputTarget {
|
||||||
/// Compile passes of a shader preset given the applicable
|
/// Compile passes of a shader preset given the applicable
|
||||||
/// shader output target, compilation type, and resulting error.
|
/// shader output target, compilation type, and resulting error.
|
||||||
fn compile_preset_passes<'a, T, I, R, E>(
|
fn compile_preset_passes<'a, T, I, R, E>(
|
||||||
passes: Vec<PassResource>,
|
passes: impl IntoIterator<Item = PassResource>,
|
||||||
textures: impl Iterator<Item = &'a TextureMeta>,
|
textures: impl Iterator<Item = &'a TextureMeta>,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
|
@ -85,11 +85,11 @@ where
|
||||||
let mut texture_semantics: FastHashMap<ShortString, Semantic<TextureSemantics>> =
|
let mut texture_semantics: FastHashMap<ShortString, Semantic<TextureSemantics>> =
|
||||||
Default::default();
|
Default::default();
|
||||||
|
|
||||||
let passes = passes
|
let artifacts = passes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|shader| {
|
.map(|shader| {
|
||||||
let source = shader.data;
|
let source = &shader.data;
|
||||||
let compiled = I::Compiler::compile(&source)?;
|
let compiled = I::Compiler::compile(source)?;
|
||||||
let reflect = T::from_compilation(compiled)?;
|
let reflect = T::from_compilation(compiled)?;
|
||||||
|
|
||||||
for parameter in source.parameters.values() {
|
for parameter in source.parameters.values() {
|
||||||
|
@ -101,22 +101,22 @@ where
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Ok::<_, E>((shader.meta, source, reflect))
|
Ok::<_, E>((shader, reflect))
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<(PassMeta, ShaderSource, CompilerBackend<_>)>, E>>()?;
|
.collect::<Result<Vec<(PassResource, CompilerBackend<_>)>, E>>()?;
|
||||||
|
|
||||||
for (meta, source, _) in &passes {
|
for (pass, _) in artifacts.iter() {
|
||||||
insert_pass_semantics(
|
insert_pass_semantics(
|
||||||
&mut uniform_semantics,
|
&mut uniform_semantics,
|
||||||
&mut texture_semantics,
|
&mut texture_semantics,
|
||||||
meta.alias.as_ref(),
|
pass.meta.alias.as_ref(),
|
||||||
meta.id as usize,
|
pass.meta.id as usize,
|
||||||
);
|
);
|
||||||
insert_pass_semantics(
|
insert_pass_semantics(
|
||||||
&mut uniform_semantics,
|
&mut uniform_semantics,
|
||||||
&mut texture_semantics,
|
&mut texture_semantics,
|
||||||
source.name.as_ref(),
|
pass.data.name.as_ref(),
|
||||||
meta.id as usize,
|
pass.meta.id as usize,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ where
|
||||||
texture_semantics,
|
texture_semantics,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((passes, semantics))
|
Ok((artifacts, semantics))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert the available semantics for the input pass config into the provided semantic maps.
|
/// Insert the available semantics for the input pass config into the provided semantic maps.
|
||||||
|
|
|
@ -282,7 +282,7 @@ impl FilterChainD3D11 {
|
||||||
let device_is_singlethreaded =
|
let device_is_singlethreaded =
|
||||||
unsafe { (device.GetCreationFlags() & D3D11_CREATE_DEVICE_SINGLETHREADED.0) == 1 };
|
unsafe { (device.GetCreationFlags() & D3D11_CREATE_DEVICE_SINGLETHREADED.0) == 1 };
|
||||||
|
|
||||||
let builder_fn = |(index, (config, source, mut reflect)): (usize, ShaderPassMeta)| {
|
let builder_fn = |(index, (config, mut reflect)): (usize, ShaderPassMeta)| {
|
||||||
let reflection = reflect.reflect(index, semantics)?;
|
let reflection = reflect.reflect(index, semantics)?;
|
||||||
let hlsl = reflect.compile(None)?;
|
let hlsl = reflect.compile(None)?;
|
||||||
|
|
||||||
|
@ -365,8 +365,8 @@ impl FilterChainD3D11 {
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
uniform_buffer: ubo_cbuffer,
|
uniform_buffer: ubo_cbuffer,
|
||||||
push_buffer: push_cbuffer,
|
push_buffer: push_cbuffer,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -565,10 +565,7 @@ impl FilterChainD3D12 {
|
||||||
|dxc,
|
|dxc,
|
||||||
(
|
(
|
||||||
index,
|
index,
|
||||||
(
|
((((config, mut dxil), (_, mut hlsl)), mut texture_heap), mut sampler_heap),
|
||||||
(((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap),
|
|
||||||
mut sampler_heap,
|
|
||||||
),
|
|
||||||
)| {
|
)| {
|
||||||
let Ok((validator, library, compiler)) = dxc else {
|
let Ok((validator, library, compiler)) = dxc else {
|
||||||
return Err(FilterChainError::Direct3DOperationError(
|
return Err(FilterChainError::Direct3DOperationError(
|
||||||
|
@ -581,10 +578,10 @@ impl FilterChainD3D12 {
|
||||||
librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0,
|
librashader_reflect::back::dxil::ShaderModel::ShaderModel6_0,
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
let render_format = if let Some(format) = config.get_format_override() {
|
let render_format = if let Some(format) = config.meta.get_format_override() {
|
||||||
format
|
format
|
||||||
} else if source.format != ImageFormat::Unknown {
|
} else if config.data.format != ImageFormat::Unknown {
|
||||||
source.format
|
config.data.format
|
||||||
} else {
|
} else {
|
||||||
ImageFormat::R8G8B8A8Unorm
|
ImageFormat::R8G8B8A8Unorm
|
||||||
}
|
}
|
||||||
|
@ -650,10 +647,10 @@ impl FilterChainD3D12 {
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
pipeline: graphics_pipeline,
|
pipeline: graphics_pipeline,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
texture_heap,
|
texture_heap,
|
||||||
sampler_heap,
|
sampler_heap,
|
||||||
source,
|
source: config.data,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl FilterChainD3D9 {
|
||||||
semantics: &ShaderSemantics,
|
semantics: &ShaderSemantics,
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> error::Result<Vec<FilterPass>> {
|
) -> error::Result<Vec<FilterPass>> {
|
||||||
let builder_fn = |(index, (config, source, mut reflect)): (usize, ShaderPassMeta)| {
|
let builder_fn = |(index, (config, mut reflect)): (usize, ShaderPassMeta)| {
|
||||||
let mut reflection = reflect.reflect(index, semantics)?;
|
let mut reflection = reflect.reflect(index, semantics)?;
|
||||||
let hlsl = reflect.compile(Some(HlslShaderModel::ShaderModel3_0))?;
|
let hlsl = reflect.compile(Some(HlslShaderModel::ShaderModel3_0))?;
|
||||||
|
|
||||||
|
@ -174,8 +174,8 @@ impl FilterChainD3D9 {
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
gl_halfpixel,
|
gl_halfpixel,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -221,7 +221,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
let mut filters = Vec::new();
|
let mut filters = Vec::new();
|
||||||
|
|
||||||
// initialize passes
|
// initialize passes
|
||||||
for (index, (config, source, mut reflect)) in passes.into_iter().enumerate() {
|
for (index, (config, mut reflect)) in passes.into_iter().enumerate() {
|
||||||
let reflection = reflect.reflect(index, semantics)?;
|
let reflection = reflect.reflect(index, semantics)?;
|
||||||
let glsl = reflect.compile(version)?;
|
let glsl = reflect.compile(version)?;
|
||||||
|
|
||||||
|
@ -257,8 +257,8 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
ubo_ring,
|
ubo_ring,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ impl FilterChainMetal {
|
||||||
let filters: Vec<error::Result<FilterPass>> = passes
|
let filters: Vec<error::Result<FilterPass>> = passes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, (config, source, mut reflect))| {
|
.map(|(index, (config, mut reflect))| {
|
||||||
let reflection = reflect.reflect(index, semantics)?;
|
let reflection = reflect.reflect(index, semantics)?;
|
||||||
let msl = reflect.compile(Some(MslVersion::new(2, 0, 0)))?;
|
let msl = reflect.compile(Some(MslVersion::new(2, 0, 0)))?;
|
||||||
|
|
||||||
|
@ -197,10 +197,10 @@ impl FilterChainMetal {
|
||||||
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
|
let uniform_bindings = reflection.meta.create_binding_map(|param| param.offset());
|
||||||
|
|
||||||
let render_pass_format: MTLPixelFormat =
|
let render_pass_format: MTLPixelFormat =
|
||||||
if let Some(format) = config.get_format_override() {
|
if let Some(format) = config.meta.get_format_override() {
|
||||||
format.into()
|
format.into()
|
||||||
} else {
|
} else {
|
||||||
source.format.into()
|
config.data.format.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
let graphics_pipeline = MetalGraphicsPipeline::new(
|
let graphics_pipeline = MetalGraphicsPipeline::new(
|
||||||
|
@ -217,8 +217,8 @@ impl FilterChainMetal {
|
||||||
reflection,
|
reflection,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
graphics_pipeline,
|
graphics_pipeline,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -498,7 +498,7 @@ impl FilterChainVulkan {
|
||||||
let filters: Vec<error::Result<FilterPass>> = passes
|
let filters: Vec<error::Result<FilterPass>> = passes
|
||||||
.into_par_iter()
|
.into_par_iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, (config, source, mut reflect))| {
|
.map(|(index, (config, mut reflect))| {
|
||||||
let reflection = reflect.reflect(index, semantics)?;
|
let reflection = reflect.reflect(index, semantics)?;
|
||||||
let spirv_words = reflect.compile(None)?;
|
let spirv_words = reflect.compile(None)?;
|
||||||
|
|
||||||
|
@ -520,10 +520,10 @@ impl FilterChainVulkan {
|
||||||
|
|
||||||
let render_pass_format = if use_dynamic_rendering {
|
let render_pass_format = if use_dynamic_rendering {
|
||||||
vk::Format::UNDEFINED
|
vk::Format::UNDEFINED
|
||||||
} else if let Some(format) = config.get_format_override() {
|
} else if let Some(format) = config.meta.get_format_override() {
|
||||||
format.into()
|
format.into()
|
||||||
} else if source.format != ImageFormat::Unknown {
|
} else if config.data.format != ImageFormat::Unknown {
|
||||||
source.format.into()
|
config.data.format.into()
|
||||||
} else {
|
} else {
|
||||||
ImageFormat::R8G8B8A8Unorm.into()
|
ImageFormat::R8G8B8A8Unorm.into()
|
||||||
};
|
};
|
||||||
|
@ -542,8 +542,8 @@ impl FilterChainVulkan {
|
||||||
// compiled: spirv_words,
|
// compiled: spirv_words,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
graphics_pipeline,
|
graphics_pipeline,
|
||||||
// ubo_ring,
|
// ubo_ring,
|
||||||
frames_in_flight,
|
frames_in_flight,
|
||||||
|
|
|
@ -314,7 +314,7 @@ impl FilterChainWgpu {
|
||||||
|
|
||||||
let filters: Vec<error::Result<FilterPass>> = passes_iter
|
let filters: Vec<error::Result<FilterPass>> = passes_iter
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, (config, source, mut reflect))| {
|
.map(|(index, (config, mut reflect))| {
|
||||||
let reflection = reflect.reflect(index, semantics)?;
|
let reflection = reflect.reflect(index, semantics)?;
|
||||||
let wgsl = reflect.compile(NagaLoweringOptions {
|
let wgsl = reflect.compile(NagaLoweringOptions {
|
||||||
write_pcb_as_ubo: true,
|
write_pcb_as_ubo: true,
|
||||||
|
@ -346,10 +346,10 @@ impl FilterChainWgpu {
|
||||||
reflection.meta.create_binding_map(|param| param.offset());
|
reflection.meta.create_binding_map(|param| param.offset());
|
||||||
|
|
||||||
let render_pass_format: Option<TextureFormat> =
|
let render_pass_format: Option<TextureFormat> =
|
||||||
if let Some(format) = config.get_format_override() {
|
if let Some(format) = config.meta.get_format_override() {
|
||||||
format.into()
|
format.into()
|
||||||
} else {
|
} else {
|
||||||
source.format.into()
|
config.data.format.into()
|
||||||
};
|
};
|
||||||
|
|
||||||
let graphics_pipeline = WgpuGraphicsPipeline::new(
|
let graphics_pipeline = WgpuGraphicsPipeline::new(
|
||||||
|
@ -366,8 +366,8 @@ impl FilterChainWgpu {
|
||||||
reflection,
|
reflection,
|
||||||
uniform_storage,
|
uniform_storage,
|
||||||
uniform_bindings,
|
uniform_bindings,
|
||||||
source,
|
source: config.data,
|
||||||
meta: config,
|
meta: config.meta,
|
||||||
graphics_pipeline,
|
graphics_pipeline,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue