rt: separate out meta information for textures

This commit is contained in:
chyyran 2024-10-01 00:22:42 -04:00 committed by Ronny Chan
parent 859d16e64e
commit f14f45b3b1
16 changed files with 64 additions and 45 deletions

View file

@ -1,8 +1,8 @@
use crate::parse::remove_if;
use crate::parse::value::Value;
use crate::{
ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPassMeta, ShaderPreset,
TextureConfig,
ParameterMeta, Scale2D, Scaling, ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig,
TextureMeta,
};
use vec_extract_if_polyfill::MakeExtractIf;
@ -19,22 +19,24 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
} = value
{
TextureConfig {
name,
path,
wrap_mode,
filter_mode,
mipmap,
meta: TextureMeta {
name,
wrap_mode,
filter_mode,
mipmap,
},
}
} else {
unreachable!("values should all be of type Texture")
}
})
.collect();
let parameters: Vec<ParameterConfig> =
let parameters: Vec<ParameterMeta> =
MakeExtractIf::extract_if(&mut values, |f| matches!(*f, Value::Parameter { .. }))
.map(|value| {
if let Value::Parameter(name, value) = value {
ParameterConfig { name, value }
ParameterMeta { name, value }
} else {
unreachable!("values should be all of type parameters")
}

View file

@ -164,22 +164,30 @@ pub struct Scale2D {
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextureConfig {
/// The name of the texture.
pub name: ShortString,
/// The fully qualified path to the texture.
pub path: PathBuf,
/// Meta information about the texture.
pub meta: TextureMeta,
}
/// Configuration options for a lookup texture used in the shader.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TextureMeta {
/// The name of the texture.
pub name: ShortString,
/// The wrap (addressing) mode to use when sampling the texture.
pub wrap_mode: WrapMode,
/// The filter mode to use when sampling the texture.
pub filter_mode: FilterMode,
/// Whether or not to generate mipmaps for this texture.
/// Whether to generate mipmaps for this texture.
pub mipmap: bool,
}
/// Configuration options for a shader parameter.
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParameterConfig {
pub struct ParameterMeta {
/// The name of the parameter.
pub name: ShortString,
/// The value it is set to in the preset.
@ -208,5 +216,5 @@ pub struct ShaderPreset {
pub textures: Vec<TextureConfig>,
/// Preset information for each user parameter.
pub parameters: Vec<ParameterConfig>,
pub parameters: Vec<ParameterMeta>,
}

View file

@ -7,7 +7,9 @@ use crate::reflect::semantics::{
};
use librashader_common::map::{FastHashMap, ShortString};
use librashader_preprocess::{PreprocessError, ShaderSource};
use librashader_presets::{ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig};
use librashader_presets::{
ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig, TextureMeta,
};
/// Artifacts of a reflected and compiled shader pass.
///
@ -194,11 +196,11 @@ fn insert_lut_semantics(
texture_semantics: &mut FastHashMap<ShortString, Semantic<TextureSemantics>>,
) {
for (index, texture) in textures.iter().enumerate() {
let mut size_semantic = texture.name.clone();
let mut size_semantic = texture.meta.name.clone();
size_semantic.push_str("Size");
texture_semantics.insert(
texture.name.clone(),
texture.meta.name.clone(),
Semantic {
semantics: TextureSemantics::User,
index,

View file

@ -375,7 +375,7 @@ impl FilterChainD3D11 {
Height: image.size.height,
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
Usage: D3D11_USAGE_DEFAULT,
MiscFlags: if texture.mipmap {
MiscFlags: if texture.meta.mipmap {
D3D11_RESOURCE_MISC_GENERATE_MIPS.0 as u32
} else {
0
@ -388,8 +388,8 @@ impl FilterChainD3D11 {
context,
&image,
desc,
texture.filter_mode,
texture.wrap_mode,
texture.meta.filter_mode,
texture.meta.wrap_mode,
)?;
luts.insert(index, texture);
}

View file

@ -448,9 +448,9 @@ impl FilterChainD3D12 {
staging_heap,
cmd,
&image,
texture.filter_mode,
texture.wrap_mode,
texture.mipmap,
texture.meta.filter_mode,
texture.meta.wrap_mode,
texture.meta.mipmap,
gc,
)?;
luts.insert(index, texture);

View file

@ -193,7 +193,7 @@ impl FilterChainD3D9 {
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(device, &image, &texture)?;
let texture = LutTexture::new(device, &image, &texture.meta)?;
luts.insert(index, texture);
}
Ok(luts)

View file

@ -2,7 +2,7 @@ use crate::error;
use crate::error::assume_d3d_init;
use crate::texture::D3D9InputTexture;
use librashader_presets::TextureConfig;
use librashader_presets::{TextureConfig, TextureMeta};
use librashader_runtime::image::{Image, BGRA8};
use windows::Win32::Graphics::Direct3D9::{
@ -22,7 +22,7 @@ impl LutTexture {
pub fn new(
device: &IDirect3DDevice9,
source: &Image<BGRA8>,
config: &TextureConfig,
config: &TextureMeta,
) -> error::Result<LutTexture> {
let mut texture = None;
unsafe {

View file

@ -25,7 +25,7 @@ impl LoadLut for Gl3LutLoad {
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap {
let levels = if texture.meta.mipmap {
image.size.calculate_miplevels()
} else {
1u32
@ -76,9 +76,9 @@ impl LoadLut for Gl3LutLoad {
format: glow::RGBA8,
size: image.size,
},
filter: texture.filter_mode,
mip_filter: texture.filter_mode,
wrap_mode: texture.wrap_mode,
filter: texture.meta.filter_mode,
mip_filter: texture.meta.filter_mode,
wrap_mode: texture.meta.wrap_mode,
},
);
}

View file

@ -25,7 +25,7 @@ impl LoadLut for Gl46LutLoad {
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let levels = if texture.mipmap {
let levels = if texture.meta.mipmap {
image.size.calculate_miplevels()
} else {
1u32
@ -75,9 +75,9 @@ impl LoadLut for Gl46LutLoad {
format: glow::RGBA8,
size: image.size,
},
filter: texture.filter_mode,
mip_filter: texture.filter_mode,
wrap_mode: texture.wrap_mode,
filter: texture.meta.filter_mode,
mip_filter: texture.meta.filter_mode,
wrap_mode: texture.meta.wrap_mode,
},
);
}

View file

@ -149,7 +149,7 @@ impl FilterChainMetal {
.map(|texture| Image::<BGRA8>::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(device, image, texture, &mipmapper)?;
let texture = LutTexture::new(device, image, &texture.meta, &mipmapper)?;
luts.insert(index, texture);
}

View file

@ -1,6 +1,6 @@
use crate::error::{FilterChainError, Result};
use crate::texture::InputTexture;
use librashader_presets::TextureConfig;
use librashader_presets::{TextureConfig, TextureMeta};
use librashader_runtime::image::{Image, BGRA8};
use librashader_runtime::scaling::MipmapSize;
use objc2::runtime::ProtocolObject;
@ -23,7 +23,7 @@ impl LutTexture {
pub fn new(
device: &ProtocolObject<dyn MTLDevice>,
image: Image<BGRA8>,
config: &TextureConfig,
config: &TextureMeta,
mipmapper: &ProtocolObject<dyn MTLBlitCommandEncoder>,
) -> Result<Self> {
let descriptor = unsafe {

View file

@ -535,7 +535,7 @@ impl FilterChainVulkan {
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture = LutTexture::new(vulkan, command_buffer, image, texture)?;
let texture = LutTexture::new(vulkan, command_buffer, image, &texture.meta)?;
luts.insert(index, texture);
}
Ok(luts)

View file

@ -3,7 +3,7 @@ use crate::memory::{VulkanBuffer, VulkanImageMemory};
use crate::texture::{InputImage, VulkanImage};
use crate::{error, util};
use ash::vk;
use librashader_presets::TextureConfig;
use librashader_presets::{TextureConfig, TextureMeta};
use librashader_runtime::image::{Image, BGRA8};
use librashader_runtime::scaling::MipmapSize;
@ -18,7 +18,7 @@ impl LutTexture {
vulkan: &VulkanObjects,
cmd: vk::CommandBuffer,
image: Image<BGRA8>,
config: &TextureConfig,
config: &TextureMeta,
) -> error::Result<LutTexture> {
let image_info = vk::ImageCreateInfo::default()
.image_type(vk::ImageType::TYPE_2D)

View file

@ -240,8 +240,15 @@ impl FilterChainWgpu {
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
.collect::<Result<Vec<Image>, ImageError>>()?;
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
let texture =
LutTexture::new(device, queue, cmd, image, texture, mipmapper, sampler_set);
let texture = LutTexture::new(
device,
queue,
cmd,
image,
&texture.meta,
mipmapper,
sampler_set,
);
luts.insert(index, texture);
}
Ok(luts)

View file

@ -2,7 +2,7 @@ use crate::mipmap::MipmapGen;
use crate::samplers::SamplerSet;
use crate::texture::InputImage;
use librashader_common::{Size, WrapMode};
use librashader_presets::TextureConfig;
use librashader_presets::{TextureConfig, TextureMeta};
use librashader_runtime::image::Image;
use librashader_runtime::scaling::MipmapSize;
use std::sync::Arc;
@ -21,7 +21,7 @@ impl LutTexture {
queue: &wgpu::Queue,
cmd: &mut wgpu::CommandEncoder,
image: Image,
config: &TextureConfig,
config: &TextureMeta,
mipmapper: &mut MipmapGen,
sampler_set: &SamplerSet,
) -> LutTexture {

View file

@ -1,6 +1,6 @@
use arc_swap::ArcSwap;
use librashader_common::map::{FastHashMap, ShortString};
use librashader_presets::ParameterConfig;
use librashader_presets::ParameterMeta;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
@ -22,7 +22,7 @@ pub struct RuntimeParameters {
impl RuntimeParameters {
/// Create a new instance of runtime parameters from a `Vec` of
/// shader parameters from a [`ShaderPreset`](librashader_presets::ShaderPreset).
pub fn new(passes_enabled: usize, parameters: Vec<ParameterConfig>) -> Self {
pub fn new(passes_enabled: usize, parameters: Vec<ParameterMeta>) -> Self {
RuntimeParameters {
passes_enabled: AtomicUsize::new(passes_enabled),
parameters: ArcSwap::new(Arc::new(