preset: generalize framebuffer format override

This commit is contained in:
chyyran 2023-02-23 01:33:45 -05:00
parent 31235971db
commit c86d39bf5a
5 changed files with 34 additions and 33 deletions

View file

@ -1,3 +1,4 @@
use librashader_common::ImageFormat;
use crate::parse::remove_if; use crate::parse::remove_if;
use crate::parse::value::Value; use crate::parse::value::Value;
use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, TextureConfig}; use crate::{ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPreset, TextureConfig};
@ -112,6 +113,30 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
scale_y = scale; scale_y = scale;
} }
let srgb_frambuffer = shader_values
.iter()
.find_map(|f| match f {
Value::SrgbFramebuffer(_, value) => Some(*value),
_ => None,
})
.unwrap_or(false);
let float_framebuffer = shader_values
.iter()
.find_map(|f| match f {
Value::FloatFramebuffer(_, value) => Some(*value),
_ => None,
})
.unwrap_or(false);
let framebuffer_format = if srgb_frambuffer {
Some(ImageFormat::R8G8B8A8Srgb)
} else if float_framebuffer {
Some(ImageFormat::R16G16B16A16Sfloat)
} else {
None
};
let shader = ShaderPassConfig { let shader = ShaderPassConfig {
id, id,
name, name,
@ -140,20 +165,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
_ => None, _ => None,
}) })
.unwrap_or(0), .unwrap_or(0),
srgb_framebuffer: shader_values framebuffer_format_override: framebuffer_format,
.iter()
.find_map(|f| match f {
Value::SrgbFramebuffer(_, value) => Some(*value),
_ => None,
})
.unwrap_or(false),
float_framebuffer: shader_values
.iter()
.find_map(|f| match f {
Value::FloatFramebuffer(_, value) => Some(*value),
_ => None,
})
.unwrap_or(false),
mipmap_input: shader_values mipmap_input: shader_values
.iter() .iter()
.find_map(|f| match f { .find_map(|f| match f {

View file

@ -19,10 +19,11 @@ pub struct ShaderPassConfig {
pub wrap_mode: WrapMode, pub wrap_mode: WrapMode,
/// The number to which to wrap the frame count before passing it to the uniforms. /// The number to which to wrap the frame count before passing it to the uniforms.
pub frame_count_mod: u32, pub frame_count_mod: u32,
/// Whether or not this shader pass expects an SRGB framebuffer output. /// If the preset overrides the framebuffer format, get the format override.
pub srgb_framebuffer: bool, ///
/// Whether or not this shader pass expects an float framebuffer output. /// The precedence is always SRGB, then float. For quark shaders, this is
pub float_framebuffer: bool, /// specified in the shader manifest.
pub framebuffer_format_override: Option<ImageFormat>,
/// Whether or not to generate mipmaps for the input texture before passing to the shader. /// Whether or not to generate mipmaps for the input texture before passing to the shader.
pub mipmap_input: bool, pub mipmap_input: bool,
/// Specifies the scaling of the output framebuffer for this shader pass. /// Specifies the scaling of the output framebuffer for this shader pass.
@ -30,18 +31,6 @@ pub struct ShaderPassConfig {
} }
impl ShaderPassConfig { impl ShaderPassConfig {
/// If the framebuffer expects a different format than what was defined in the
/// shader source, returns such format.
#[inline(always)]
pub fn get_format_override(&self) -> Option<ImageFormat> {
if self.srgb_framebuffer {
return Some(ImageFormat::R8G8B8A8Srgb);
} else if self.float_framebuffer {
return Some(ImageFormat::R16G16B16A16Sfloat);
}
None
}
#[inline(always)] #[inline(always)]
pub fn get_frame_count(&self, count: usize) -> u32 { pub fn get_frame_count(&self, count: usize) -> u32 {
(if self.frame_count_mod > 0 { (if self.frame_count_mod > 0 {

View file

@ -432,7 +432,7 @@ 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.framebuffer_format_override {
format format
} else if source.format != ImageFormat::Unknown { } else if source.format != ImageFormat::Unknown {
source.format source.format

View file

@ -428,7 +428,7 @@ impl FilterChainVulkan {
let render_pass_format = if !use_render_pass { let render_pass_format = if !use_render_pass {
vk::Format::UNDEFINED vk::Format::UNDEFINED
} else if let Some(format) = config.get_format_override() { } else if let Some(format) = config.framebuffer_format_override {
format.into() format.into()
} else if source.format != ImageFormat::Unknown { } else if source.format != ImageFormat::Unknown {
source.format.into() source.format.into()

View file

@ -13,7 +13,7 @@ pub trait FilterPassMeta {
#[inline(always)] #[inline(always)]
fn get_format(&self) -> ImageFormat { fn get_format(&self) -> ImageFormat {
let fb_format = self.framebuffer_format(); let fb_format = self.framebuffer_format();
if let Some(format) = self.config().get_format_override() { if let Some(format) = self.config().framebuffer_format_override {
format format
} else if fb_format == ImageFormat::Unknown { } else if fb_format == ImageFormat::Unknown {
ImageFormat::R8G8B8A8Unorm ImageFormat::R8G8B8A8Unorm