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_pack::PassResource;
|
||||
use librashader_preprocess::{PreprocessError, ShaderSource};
|
||||
use librashader_presets::{PassMeta, ShaderPreset, TextureMeta};
|
||||
use librashader_presets::{ShaderPreset, TextureMeta};
|
||||
|
||||
/// 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.
|
||||
pub type ShaderPassArtifact<T> = (PassMeta, ShaderSource, CompilerBackend<T>);
|
||||
pub type ShaderPassArtifact<T> = (PassResource, CompilerBackend<T>);
|
||||
|
||||
impl<T: OutputTarget> CompilePresetTarget for T {}
|
||||
|
||||
|
@ -38,7 +38,7 @@ pub trait CompilePresetTarget: OutputTarget {
|
|||
/// Compile passes of a shader preset given the applicable
|
||||
/// shader output target, compilation type, and resulting error.
|
||||
fn compile_preset_passes<'a, I, R, E>(
|
||||
passes: Vec<PassResource>,
|
||||
passes: impl IntoIterator<Item = PassResource>,
|
||||
textures: impl Iterator<Item = &'a TextureMeta>,
|
||||
) -> Result<
|
||||
(
|
||||
|
@ -63,7 +63,7 @@ pub trait CompilePresetTarget: OutputTarget {
|
|||
/// Compile passes of a shader preset given the applicable
|
||||
/// shader output target, compilation type, and resulting error.
|
||||
fn compile_preset_passes<'a, T, I, R, E>(
|
||||
passes: Vec<PassResource>,
|
||||
passes: impl IntoIterator<Item = PassResource>,
|
||||
textures: impl Iterator<Item = &'a TextureMeta>,
|
||||
) -> Result<
|
||||
(
|
||||
|
@ -85,11 +85,11 @@ where
|
|||
let mut texture_semantics: FastHashMap<ShortString, Semantic<TextureSemantics>> =
|
||||
Default::default();
|
||||
|
||||
let passes = passes
|
||||
let artifacts = passes
|
||||
.into_iter()
|
||||
.map(|shader| {
|
||||
let source = shader.data;
|
||||
let compiled = I::Compiler::compile(&source)?;
|
||||
let source = &shader.data;
|
||||
let compiled = I::Compiler::compile(source)?;
|
||||
let reflect = T::from_compilation(compiled)?;
|
||||
|
||||
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(
|
||||
&mut uniform_semantics,
|
||||
&mut texture_semantics,
|
||||
meta.alias.as_ref(),
|
||||
meta.id as usize,
|
||||
pass.meta.alias.as_ref(),
|
||||
pass.meta.id as usize,
|
||||
);
|
||||
insert_pass_semantics(
|
||||
&mut uniform_semantics,
|
||||
&mut texture_semantics,
|
||||
source.name.as_ref(),
|
||||
meta.id as usize,
|
||||
pass.data.name.as_ref(),
|
||||
pass.meta.id as usize,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ where
|
|||
texture_semantics,
|
||||
};
|
||||
|
||||
Ok((passes, semantics))
|
||||
Ok((artifacts, semantics))
|
||||
}
|
||||
|
||||
/// Insert the available semantics for the input pass config into the provided semantic maps.
|
||||
|
|
|
@ -282,7 +282,7 @@ impl FilterChainD3D11 {
|
|||
let device_is_singlethreaded =
|
||||
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 hlsl = reflect.compile(None)?;
|
||||
|
||||
|
@ -365,8 +365,8 @@ impl FilterChainD3D11 {
|
|||
uniform_storage,
|
||||
uniform_buffer: ubo_cbuffer,
|
||||
push_buffer: push_cbuffer,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -565,10 +565,7 @@ impl FilterChainD3D12 {
|
|||
|dxc,
|
||||
(
|
||||
index,
|
||||
(
|
||||
(((config, source, mut dxil), (_, _, mut hlsl)), mut texture_heap),
|
||||
mut sampler_heap,
|
||||
),
|
||||
((((config, mut dxil), (_, mut hlsl)), mut texture_heap), mut sampler_heap),
|
||||
)| {
|
||||
let Ok((validator, library, compiler)) = dxc else {
|
||||
return Err(FilterChainError::Direct3DOperationError(
|
||||
|
@ -581,10 +578,10 @@ impl FilterChainD3D12 {
|
|||
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
|
||||
} else if source.format != ImageFormat::Unknown {
|
||||
source.format
|
||||
} else if config.data.format != ImageFormat::Unknown {
|
||||
config.data.format
|
||||
} else {
|
||||
ImageFormat::R8G8B8A8Unorm
|
||||
}
|
||||
|
@ -650,10 +647,10 @@ impl FilterChainD3D12 {
|
|||
uniform_bindings,
|
||||
uniform_storage,
|
||||
pipeline: graphics_pipeline,
|
||||
meta: config,
|
||||
meta: config.meta,
|
||||
texture_heap,
|
||||
sampler_heap,
|
||||
source,
|
||||
source: config.data,
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
|
@ -107,7 +107,7 @@ impl FilterChainD3D9 {
|
|||
semantics: &ShaderSemantics,
|
||||
disable_cache: bool,
|
||||
) -> 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 hlsl = reflect.compile(Some(HlslShaderModel::ShaderModel3_0))?;
|
||||
|
||||
|
@ -174,8 +174,8 @@ impl FilterChainD3D9 {
|
|||
uniform_bindings,
|
||||
uniform_storage,
|
||||
gl_halfpixel,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
let mut filters = Vec::new();
|
||||
|
||||
// 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 glsl = reflect.compile(version)?;
|
||||
|
||||
|
@ -257,8 +257,8 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
|||
ubo_ring,
|
||||
uniform_storage,
|
||||
uniform_bindings,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ impl FilterChainMetal {
|
|||
let filters: Vec<error::Result<FilterPass>> = passes
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, (config, source, mut reflect))| {
|
||||
.map(|(index, (config, mut reflect))| {
|
||||
let reflection = reflect.reflect(index, semantics)?;
|
||||
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 render_pass_format: MTLPixelFormat =
|
||||
if let Some(format) = config.get_format_override() {
|
||||
if let Some(format) = config.meta.get_format_override() {
|
||||
format.into()
|
||||
} else {
|
||||
source.format.into()
|
||||
config.data.format.into()
|
||||
};
|
||||
|
||||
let graphics_pipeline = MetalGraphicsPipeline::new(
|
||||
|
@ -217,8 +217,8 @@ impl FilterChainMetal {
|
|||
reflection,
|
||||
uniform_storage,
|
||||
uniform_bindings,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
graphics_pipeline,
|
||||
})
|
||||
})
|
||||
|
|
|
@ -498,7 +498,7 @@ impl FilterChainVulkan {
|
|||
let filters: Vec<error::Result<FilterPass>> = passes
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(|(index, (config, source, mut reflect))| {
|
||||
.map(|(index, (config, mut reflect))| {
|
||||
let reflection = reflect.reflect(index, semantics)?;
|
||||
let spirv_words = reflect.compile(None)?;
|
||||
|
||||
|
@ -520,10 +520,10 @@ impl FilterChainVulkan {
|
|||
|
||||
let render_pass_format = if use_dynamic_rendering {
|
||||
vk::Format::UNDEFINED
|
||||
} else if let Some(format) = config.get_format_override() {
|
||||
} else if let Some(format) = config.meta.get_format_override() {
|
||||
format.into()
|
||||
} else if source.format != ImageFormat::Unknown {
|
||||
source.format.into()
|
||||
} else if config.data.format != ImageFormat::Unknown {
|
||||
config.data.format.into()
|
||||
} else {
|
||||
ImageFormat::R8G8B8A8Unorm.into()
|
||||
};
|
||||
|
@ -542,8 +542,8 @@ impl FilterChainVulkan {
|
|||
// compiled: spirv_words,
|
||||
uniform_storage,
|
||||
uniform_bindings,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
graphics_pipeline,
|
||||
// ubo_ring,
|
||||
frames_in_flight,
|
||||
|
|
|
@ -314,7 +314,7 @@ impl FilterChainWgpu {
|
|||
|
||||
let filters: Vec<error::Result<FilterPass>> = passes_iter
|
||||
.enumerate()
|
||||
.map(|(index, (config, source, mut reflect))| {
|
||||
.map(|(index, (config, mut reflect))| {
|
||||
let reflection = reflect.reflect(index, semantics)?;
|
||||
let wgsl = reflect.compile(NagaLoweringOptions {
|
||||
write_pcb_as_ubo: true,
|
||||
|
@ -346,10 +346,10 @@ impl FilterChainWgpu {
|
|||
reflection.meta.create_binding_map(|param| param.offset());
|
||||
|
||||
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()
|
||||
} else {
|
||||
source.format.into()
|
||||
config.data.format.into()
|
||||
};
|
||||
|
||||
let graphics_pipeline = WgpuGraphicsPipeline::new(
|
||||
|
@ -366,8 +366,8 @@ impl FilterChainWgpu {
|
|||
reflection,
|
||||
uniform_storage,
|
||||
uniform_bindings,
|
||||
source,
|
||||
meta: config,
|
||||
source: config.data,
|
||||
meta: config.meta,
|
||||
graphics_pipeline,
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue