rt: separate out meta information for textures
This commit is contained in:
parent
859d16e64e
commit
f14f45b3b1
|
@ -1,8 +1,8 @@
|
||||||
use crate::parse::remove_if;
|
use crate::parse::remove_if;
|
||||||
use crate::parse::value::Value;
|
use crate::parse::value::Value;
|
||||||
use crate::{
|
use crate::{
|
||||||
ParameterConfig, Scale2D, Scaling, ShaderPassConfig, ShaderPassMeta, ShaderPreset,
|
ParameterMeta, Scale2D, Scaling, ShaderPassConfig, ShaderPassMeta, ShaderPreset, TextureConfig,
|
||||||
TextureConfig,
|
TextureMeta,
|
||||||
};
|
};
|
||||||
use vec_extract_if_polyfill::MakeExtractIf;
|
use vec_extract_if_polyfill::MakeExtractIf;
|
||||||
|
|
||||||
|
@ -19,22 +19,24 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
||||||
} = value
|
} = value
|
||||||
{
|
{
|
||||||
TextureConfig {
|
TextureConfig {
|
||||||
name,
|
|
||||||
path,
|
path,
|
||||||
|
meta: TextureMeta {
|
||||||
|
name,
|
||||||
wrap_mode,
|
wrap_mode,
|
||||||
filter_mode,
|
filter_mode,
|
||||||
mipmap,
|
mipmap,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unreachable!("values should all be of type Texture")
|
unreachable!("values should all be of type Texture")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let parameters: Vec<ParameterConfig> =
|
let parameters: Vec<ParameterMeta> =
|
||||||
MakeExtractIf::extract_if(&mut values, |f| matches!(*f, Value::Parameter { .. }))
|
MakeExtractIf::extract_if(&mut values, |f| matches!(*f, Value::Parameter { .. }))
|
||||||
.map(|value| {
|
.map(|value| {
|
||||||
if let Value::Parameter(name, value) = value {
|
if let Value::Parameter(name, value) = value {
|
||||||
ParameterConfig { name, value }
|
ParameterMeta { name, value }
|
||||||
} else {
|
} else {
|
||||||
unreachable!("values should be all of type parameters")
|
unreachable!("values should be all of type parameters")
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,22 +164,30 @@ pub struct Scale2D {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct TextureConfig {
|
pub struct TextureConfig {
|
||||||
/// The name of the texture.
|
|
||||||
pub name: ShortString,
|
|
||||||
/// The fully qualified path to the texture.
|
/// The fully qualified path to the texture.
|
||||||
pub path: PathBuf,
|
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.
|
/// The wrap (addressing) mode to use when sampling the texture.
|
||||||
pub wrap_mode: WrapMode,
|
pub wrap_mode: WrapMode,
|
||||||
/// The filter mode to use when sampling the texture.
|
/// The filter mode to use when sampling the texture.
|
||||||
pub filter_mode: FilterMode,
|
pub filter_mode: FilterMode,
|
||||||
/// Whether or not to generate mipmaps for this texture.
|
/// Whether to generate mipmaps for this texture.
|
||||||
pub mipmap: bool,
|
pub mipmap: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Configuration options for a shader parameter.
|
/// Configuration options for a shader parameter.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||||
pub struct ParameterConfig {
|
pub struct ParameterMeta {
|
||||||
/// The name of the parameter.
|
/// The name of the parameter.
|
||||||
pub name: ShortString,
|
pub name: ShortString,
|
||||||
/// The value it is set to in the preset.
|
/// The value it is set to in the preset.
|
||||||
|
@ -208,5 +216,5 @@ pub struct ShaderPreset {
|
||||||
pub textures: Vec<TextureConfig>,
|
pub textures: Vec<TextureConfig>,
|
||||||
|
|
||||||
/// Preset information for each user parameter.
|
/// Preset information for each user parameter.
|
||||||
pub parameters: Vec<ParameterConfig>,
|
pub parameters: Vec<ParameterMeta>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,9 @@ use crate::reflect::semantics::{
|
||||||
};
|
};
|
||||||
use librashader_common::map::{FastHashMap, ShortString};
|
use librashader_common::map::{FastHashMap, ShortString};
|
||||||
use librashader_preprocess::{PreprocessError, ShaderSource};
|
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.
|
/// Artifacts of a reflected and compiled shader pass.
|
||||||
///
|
///
|
||||||
|
@ -194,11 +196,11 @@ fn insert_lut_semantics(
|
||||||
texture_semantics: &mut FastHashMap<ShortString, Semantic<TextureSemantics>>,
|
texture_semantics: &mut FastHashMap<ShortString, Semantic<TextureSemantics>>,
|
||||||
) {
|
) {
|
||||||
for (index, texture) in textures.iter().enumerate() {
|
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");
|
size_semantic.push_str("Size");
|
||||||
|
|
||||||
texture_semantics.insert(
|
texture_semantics.insert(
|
||||||
texture.name.clone(),
|
texture.meta.name.clone(),
|
||||||
Semantic {
|
Semantic {
|
||||||
semantics: TextureSemantics::User,
|
semantics: TextureSemantics::User,
|
||||||
index,
|
index,
|
||||||
|
|
|
@ -375,7 +375,7 @@ impl FilterChainD3D11 {
|
||||||
Height: image.size.height,
|
Height: image.size.height,
|
||||||
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
Format: DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||||
Usage: D3D11_USAGE_DEFAULT,
|
Usage: D3D11_USAGE_DEFAULT,
|
||||||
MiscFlags: if texture.mipmap {
|
MiscFlags: if texture.meta.mipmap {
|
||||||
D3D11_RESOURCE_MISC_GENERATE_MIPS.0 as u32
|
D3D11_RESOURCE_MISC_GENERATE_MIPS.0 as u32
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -388,8 +388,8 @@ impl FilterChainD3D11 {
|
||||||
context,
|
context,
|
||||||
&image,
|
&image,
|
||||||
desc,
|
desc,
|
||||||
texture.filter_mode,
|
texture.meta.filter_mode,
|
||||||
texture.wrap_mode,
|
texture.meta.wrap_mode,
|
||||||
)?;
|
)?;
|
||||||
luts.insert(index, texture);
|
luts.insert(index, texture);
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,9 +448,9 @@ impl FilterChainD3D12 {
|
||||||
staging_heap,
|
staging_heap,
|
||||||
cmd,
|
cmd,
|
||||||
&image,
|
&image,
|
||||||
texture.filter_mode,
|
texture.meta.filter_mode,
|
||||||
texture.wrap_mode,
|
texture.meta.wrap_mode,
|
||||||
texture.mipmap,
|
texture.meta.mipmap,
|
||||||
gc,
|
gc,
|
||||||
)?;
|
)?;
|
||||||
luts.insert(index, texture);
|
luts.insert(index, texture);
|
||||||
|
|
|
@ -193,7 +193,7 @@ impl FilterChainD3D9 {
|
||||||
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
||||||
|
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
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);
|
luts.insert(index, texture);
|
||||||
}
|
}
|
||||||
Ok(luts)
|
Ok(luts)
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::error;
|
||||||
use crate::error::assume_d3d_init;
|
use crate::error::assume_d3d_init;
|
||||||
use crate::texture::D3D9InputTexture;
|
use crate::texture::D3D9InputTexture;
|
||||||
|
|
||||||
use librashader_presets::TextureConfig;
|
use librashader_presets::{TextureConfig, TextureMeta};
|
||||||
use librashader_runtime::image::{Image, BGRA8};
|
use librashader_runtime::image::{Image, BGRA8};
|
||||||
|
|
||||||
use windows::Win32::Graphics::Direct3D9::{
|
use windows::Win32::Graphics::Direct3D9::{
|
||||||
|
@ -22,7 +22,7 @@ impl LutTexture {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: &IDirect3DDevice9,
|
device: &IDirect3DDevice9,
|
||||||
source: &Image<BGRA8>,
|
source: &Image<BGRA8>,
|
||||||
config: &TextureConfig,
|
config: &TextureMeta,
|
||||||
) -> error::Result<LutTexture> {
|
) -> error::Result<LutTexture> {
|
||||||
let mut texture = None;
|
let mut texture = None;
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl LoadLut for Gl3LutLoad {
|
||||||
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
|
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
|
||||||
|
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
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()
|
image.size.calculate_miplevels()
|
||||||
} else {
|
} else {
|
||||||
1u32
|
1u32
|
||||||
|
@ -76,9 +76,9 @@ impl LoadLut for Gl3LutLoad {
|
||||||
format: glow::RGBA8,
|
format: glow::RGBA8,
|
||||||
size: image.size,
|
size: image.size,
|
||||||
},
|
},
|
||||||
filter: texture.filter_mode,
|
filter: texture.meta.filter_mode,
|
||||||
mip_filter: texture.filter_mode,
|
mip_filter: texture.meta.filter_mode,
|
||||||
wrap_mode: texture.wrap_mode,
|
wrap_mode: texture.meta.wrap_mode,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ impl LoadLut for Gl46LutLoad {
|
||||||
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
|
.collect::<std::result::Result<Vec<Image>, ImageError>>()?;
|
||||||
|
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
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()
|
image.size.calculate_miplevels()
|
||||||
} else {
|
} else {
|
||||||
1u32
|
1u32
|
||||||
|
@ -75,9 +75,9 @@ impl LoadLut for Gl46LutLoad {
|
||||||
format: glow::RGBA8,
|
format: glow::RGBA8,
|
||||||
size: image.size,
|
size: image.size,
|
||||||
},
|
},
|
||||||
filter: texture.filter_mode,
|
filter: texture.meta.filter_mode,
|
||||||
mip_filter: texture.filter_mode,
|
mip_filter: texture.meta.filter_mode,
|
||||||
wrap_mode: texture.wrap_mode,
|
wrap_mode: texture.meta.wrap_mode,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ impl FilterChainMetal {
|
||||||
.map(|texture| Image::<BGRA8>::load(&texture.path, UVDirection::TopLeft))
|
.map(|texture| Image::<BGRA8>::load(&texture.path, UVDirection::TopLeft))
|
||||||
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
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);
|
luts.insert(index, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::error::{FilterChainError, Result};
|
use crate::error::{FilterChainError, Result};
|
||||||
use crate::texture::InputTexture;
|
use crate::texture::InputTexture;
|
||||||
use librashader_presets::TextureConfig;
|
use librashader_presets::{TextureConfig, TextureMeta};
|
||||||
use librashader_runtime::image::{Image, BGRA8};
|
use librashader_runtime::image::{Image, BGRA8};
|
||||||
use librashader_runtime::scaling::MipmapSize;
|
use librashader_runtime::scaling::MipmapSize;
|
||||||
use objc2::runtime::ProtocolObject;
|
use objc2::runtime::ProtocolObject;
|
||||||
|
@ -23,7 +23,7 @@ impl LutTexture {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: &ProtocolObject<dyn MTLDevice>,
|
device: &ProtocolObject<dyn MTLDevice>,
|
||||||
image: Image<BGRA8>,
|
image: Image<BGRA8>,
|
||||||
config: &TextureConfig,
|
config: &TextureMeta,
|
||||||
mipmapper: &ProtocolObject<dyn MTLBlitCommandEncoder>,
|
mipmapper: &ProtocolObject<dyn MTLBlitCommandEncoder>,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let descriptor = unsafe {
|
let descriptor = unsafe {
|
||||||
|
|
|
@ -535,7 +535,7 @@ impl FilterChainVulkan {
|
||||||
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
|
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
|
||||||
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
.collect::<Result<Vec<Image<BGRA8>>, ImageError>>()?;
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
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);
|
luts.insert(index, texture);
|
||||||
}
|
}
|
||||||
Ok(luts)
|
Ok(luts)
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::memory::{VulkanBuffer, VulkanImageMemory};
|
||||||
use crate::texture::{InputImage, VulkanImage};
|
use crate::texture::{InputImage, VulkanImage};
|
||||||
use crate::{error, util};
|
use crate::{error, util};
|
||||||
use ash::vk;
|
use ash::vk;
|
||||||
use librashader_presets::TextureConfig;
|
use librashader_presets::{TextureConfig, TextureMeta};
|
||||||
use librashader_runtime::image::{Image, BGRA8};
|
use librashader_runtime::image::{Image, BGRA8};
|
||||||
use librashader_runtime::scaling::MipmapSize;
|
use librashader_runtime::scaling::MipmapSize;
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ impl LutTexture {
|
||||||
vulkan: &VulkanObjects,
|
vulkan: &VulkanObjects,
|
||||||
cmd: vk::CommandBuffer,
|
cmd: vk::CommandBuffer,
|
||||||
image: Image<BGRA8>,
|
image: Image<BGRA8>,
|
||||||
config: &TextureConfig,
|
config: &TextureMeta,
|
||||||
) -> error::Result<LutTexture> {
|
) -> error::Result<LutTexture> {
|
||||||
let image_info = vk::ImageCreateInfo::default()
|
let image_info = vk::ImageCreateInfo::default()
|
||||||
.image_type(vk::ImageType::TYPE_2D)
|
.image_type(vk::ImageType::TYPE_2D)
|
||||||
|
|
|
@ -240,8 +240,15 @@ impl FilterChainWgpu {
|
||||||
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
|
.map(|texture| Image::load(&texture.path, UVDirection::TopLeft))
|
||||||
.collect::<Result<Vec<Image>, ImageError>>()?;
|
.collect::<Result<Vec<Image>, ImageError>>()?;
|
||||||
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
for (index, (texture, image)) in textures.iter().zip(images).enumerate() {
|
||||||
let texture =
|
let texture = LutTexture::new(
|
||||||
LutTexture::new(device, queue, cmd, image, texture, mipmapper, sampler_set);
|
device,
|
||||||
|
queue,
|
||||||
|
cmd,
|
||||||
|
image,
|
||||||
|
&texture.meta,
|
||||||
|
mipmapper,
|
||||||
|
sampler_set,
|
||||||
|
);
|
||||||
luts.insert(index, texture);
|
luts.insert(index, texture);
|
||||||
}
|
}
|
||||||
Ok(luts)
|
Ok(luts)
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::mipmap::MipmapGen;
|
||||||
use crate::samplers::SamplerSet;
|
use crate::samplers::SamplerSet;
|
||||||
use crate::texture::InputImage;
|
use crate::texture::InputImage;
|
||||||
use librashader_common::{Size, WrapMode};
|
use librashader_common::{Size, WrapMode};
|
||||||
use librashader_presets::TextureConfig;
|
use librashader_presets::{TextureConfig, TextureMeta};
|
||||||
use librashader_runtime::image::Image;
|
use librashader_runtime::image::Image;
|
||||||
use librashader_runtime::scaling::MipmapSize;
|
use librashader_runtime::scaling::MipmapSize;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -21,7 +21,7 @@ impl LutTexture {
|
||||||
queue: &wgpu::Queue,
|
queue: &wgpu::Queue,
|
||||||
cmd: &mut wgpu::CommandEncoder,
|
cmd: &mut wgpu::CommandEncoder,
|
||||||
image: Image,
|
image: Image,
|
||||||
config: &TextureConfig,
|
config: &TextureMeta,
|
||||||
mipmapper: &mut MipmapGen,
|
mipmapper: &mut MipmapGen,
|
||||||
sampler_set: &SamplerSet,
|
sampler_set: &SamplerSet,
|
||||||
) -> LutTexture {
|
) -> LutTexture {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use arc_swap::ArcSwap;
|
use arc_swap::ArcSwap;
|
||||||
use librashader_common::map::{FastHashMap, ShortString};
|
use librashader_common::map::{FastHashMap, ShortString};
|
||||||
use librashader_presets::ParameterConfig;
|
use librashader_presets::ParameterMeta;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ pub struct RuntimeParameters {
|
||||||
impl RuntimeParameters {
|
impl RuntimeParameters {
|
||||||
/// Create a new instance of runtime parameters from a `Vec` of
|
/// Create a new instance of runtime parameters from a `Vec` of
|
||||||
/// shader parameters from a [`ShaderPreset`](librashader_presets::ShaderPreset).
|
/// 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 {
|
RuntimeParameters {
|
||||||
passes_enabled: AtomicUsize::new(passes_enabled),
|
passes_enabled: AtomicUsize::new(passes_enabled),
|
||||||
parameters: ArcSwap::new(Arc::new(
|
parameters: ArcSwap::new(Arc::new(
|
||||||
|
|
Loading…
Reference in a new issue