From f14f45b3b1dd334719650e614adbe526358eb66d Mon Sep 17 00:00:00 2001 From: chyyran Date: Tue, 1 Oct 2024 00:22:42 -0400 Subject: [PATCH] rt: separate out meta information for textures --- librashader-presets/src/parse/preset.rs | 18 ++++++++++-------- librashader-presets/src/preset.rs | 18 +++++++++++++----- librashader-reflect/src/reflect/presets.rs | 8 +++++--- librashader-runtime-d3d11/src/filter_chain.rs | 6 +++--- librashader-runtime-d3d12/src/filter_chain.rs | 6 +++--- librashader-runtime-d3d9/src/filter_chain.rs | 2 +- librashader-runtime-d3d9/src/luts.rs | 4 ++-- librashader-runtime-gl/src/gl/gl3/lut_load.rs | 8 ++++---- librashader-runtime-gl/src/gl/gl46/lut_load.rs | 8 ++++---- librashader-runtime-mtl/src/filter_chain.rs | 2 +- librashader-runtime-mtl/src/luts.rs | 4 ++-- librashader-runtime-vk/src/filter_chain.rs | 2 +- librashader-runtime-vk/src/luts.rs | 4 ++-- librashader-runtime-wgpu/src/filter_chain.rs | 11 +++++++++-- librashader-runtime-wgpu/src/luts.rs | 4 ++-- librashader-runtime/src/parameters.rs | 4 ++-- 16 files changed, 64 insertions(+), 45 deletions(-) diff --git a/librashader-presets/src/parse/preset.rs b/librashader-presets/src/parse/preset.rs index 10c93e3..6c3e52e 100644 --- a/librashader-presets/src/parse/preset.rs +++ b/librashader-presets/src/parse/preset.rs @@ -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) -> 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 = + let parameters: Vec = 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") } diff --git a/librashader-presets/src/preset.rs b/librashader-presets/src/preset.rs index 261fe2d..24e27cf 100644 --- a/librashader-presets/src/preset.rs +++ b/librashader-presets/src/preset.rs @@ -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, /// Preset information for each user parameter. - pub parameters: Vec, + pub parameters: Vec, } diff --git a/librashader-reflect/src/reflect/presets.rs b/librashader-reflect/src/reflect/presets.rs index 441da0a..9f3f6e3 100644 --- a/librashader-reflect/src/reflect/presets.rs +++ b/librashader-reflect/src/reflect/presets.rs @@ -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>, ) { 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, diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 7878827..551bc8c 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -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); } diff --git a/librashader-runtime-d3d12/src/filter_chain.rs b/librashader-runtime-d3d12/src/filter_chain.rs index ca96a8d..5cc5d98 100644 --- a/librashader-runtime-d3d12/src/filter_chain.rs +++ b/librashader-runtime-d3d12/src/filter_chain.rs @@ -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); diff --git a/librashader-runtime-d3d9/src/filter_chain.rs b/librashader-runtime-d3d9/src/filter_chain.rs index 5f7a5fe..0e1a76a 100644 --- a/librashader-runtime-d3d9/src/filter_chain.rs +++ b/librashader-runtime-d3d9/src/filter_chain.rs @@ -193,7 +193,7 @@ impl FilterChainD3D9 { .collect::>, 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) diff --git a/librashader-runtime-d3d9/src/luts.rs b/librashader-runtime-d3d9/src/luts.rs index 1fb6b0a..0c67da0 100644 --- a/librashader-runtime-d3d9/src/luts.rs +++ b/librashader-runtime-d3d9/src/luts.rs @@ -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, - config: &TextureConfig, + config: &TextureMeta, ) -> error::Result { let mut texture = None; unsafe { diff --git a/librashader-runtime-gl/src/gl/gl3/lut_load.rs b/librashader-runtime-gl/src/gl/gl3/lut_load.rs index 9284a80..780b126 100644 --- a/librashader-runtime-gl/src/gl/gl3/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl3/lut_load.rs @@ -25,7 +25,7 @@ impl LoadLut for Gl3LutLoad { .collect::, 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, }, ); } diff --git a/librashader-runtime-gl/src/gl/gl46/lut_load.rs b/librashader-runtime-gl/src/gl/gl46/lut_load.rs index 5636298..97489d8 100644 --- a/librashader-runtime-gl/src/gl/gl46/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl46/lut_load.rs @@ -25,7 +25,7 @@ impl LoadLut for Gl46LutLoad { .collect::, 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, }, ); } diff --git a/librashader-runtime-mtl/src/filter_chain.rs b/librashader-runtime-mtl/src/filter_chain.rs index df9f874..35f6ab6 100644 --- a/librashader-runtime-mtl/src/filter_chain.rs +++ b/librashader-runtime-mtl/src/filter_chain.rs @@ -149,7 +149,7 @@ impl FilterChainMetal { .map(|texture| Image::::load(&texture.path, UVDirection::TopLeft)) .collect::>, 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); } diff --git a/librashader-runtime-mtl/src/luts.rs b/librashader-runtime-mtl/src/luts.rs index e822332..2c27012 100644 --- a/librashader-runtime-mtl/src/luts.rs +++ b/librashader-runtime-mtl/src/luts.rs @@ -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, image: Image, - config: &TextureConfig, + config: &TextureMeta, mipmapper: &ProtocolObject, ) -> Result { let descriptor = unsafe { diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index 0ae8b52..8677e1a 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -535,7 +535,7 @@ impl FilterChainVulkan { .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) .collect::>, 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) diff --git a/librashader-runtime-vk/src/luts.rs b/librashader-runtime-vk/src/luts.rs index 28fc782..c5d2ef5 100644 --- a/librashader-runtime-vk/src/luts.rs +++ b/librashader-runtime-vk/src/luts.rs @@ -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, - config: &TextureConfig, + config: &TextureMeta, ) -> error::Result { let image_info = vk::ImageCreateInfo::default() .image_type(vk::ImageType::TYPE_2D) diff --git a/librashader-runtime-wgpu/src/filter_chain.rs b/librashader-runtime-wgpu/src/filter_chain.rs index 396cb52..9491453 100644 --- a/librashader-runtime-wgpu/src/filter_chain.rs +++ b/librashader-runtime-wgpu/src/filter_chain.rs @@ -240,8 +240,15 @@ impl FilterChainWgpu { .map(|texture| Image::load(&texture.path, UVDirection::TopLeft)) .collect::, 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) diff --git a/librashader-runtime-wgpu/src/luts.rs b/librashader-runtime-wgpu/src/luts.rs index 6e2adc8..3b30790 100644 --- a/librashader-runtime-wgpu/src/luts.rs +++ b/librashader-runtime-wgpu/src/luts.rs @@ -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 { diff --git a/librashader-runtime/src/parameters.rs b/librashader-runtime/src/parameters.rs index 10f449b..5ff1aac 100644 --- a/librashader-runtime/src/parameters.rs +++ b/librashader-runtime/src/parameters.rs @@ -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) -> Self { + pub fn new(passes_enabled: usize, parameters: Vec) -> Self { RuntimeParameters { passes_enabled: AtomicUsize::new(passes_enabled), parameters: ArcSwap::new(Arc::new(