fmt: run cargo fmt

This commit is contained in:
chyyran 2023-01-15 03:06:09 -05:00
parent 3691f6579c
commit 05ec73a11c
38 changed files with 238 additions and 288 deletions

View file

@ -21,7 +21,7 @@ pub type libra_d3d11_filter_chain_t =
/// A handle to a Vulkan filter chain. /// A handle to a Vulkan filter chain.
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]
pub type libra_vk_filter_chain_t = pub type libra_vk_filter_chain_t =
Option<NonNull<librashader::runtime::vk::capi::FilterChainVulkan>>; Option<NonNull<librashader::runtime::vk::capi::FilterChainVulkan>>;
/// Defines the output viewport for a rendered frame. /// Defines the output viewport for a rendered frame.
#[repr(C)] #[repr(C)]

View file

@ -28,7 +28,10 @@ pub enum LibrashaderError {
#[cfg(feature = "runtime-opengl")] #[cfg(feature = "runtime-opengl")]
#[error("There was an error in the OpenGL filter chain.")] #[error("There was an error in the OpenGL filter chain.")]
OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError), OpenGlFilterError(#[from] librashader::runtime::gl::error::FilterChainError),
#[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] #[cfg(any(
feature = "docsrs",
all(target_os = "windows", feature = "runtime-d3d11")
))]
#[error("There was an error in the D3D11 filter chain.")] #[error("There was an error in the D3D11 filter chain.")]
D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError), D3D11FilterError(#[from] librashader::runtime::d3d11::error::FilterChainError),
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]
@ -111,7 +114,7 @@ pub extern "C" fn libra_error_free(error: *mut libra_error_t) -> i32 {
/// Function pointer definition for libra_error_write /// Function pointer definition for libra_error_write
pub type PFN_libra_error_write = pub type PFN_libra_error_write =
extern "C" fn(error: libra_error_t, out: *mut MaybeUninit<*mut c_char>) -> i32; extern "C" fn(error: libra_error_t, out: *mut MaybeUninit<*mut c_char>) -> i32;
#[no_mangle] #[no_mangle]
/// Writes the error message into `out` /// Writes the error message into `out`
/// ///
@ -174,13 +177,14 @@ impl LibrashaderError {
LibrashaderError::PreprocessError(_) => LIBRA_ERRNO::PREPROCESS_ERROR, LibrashaderError::PreprocessError(_) => LIBRA_ERRNO::PREPROCESS_ERROR,
LibrashaderError::ShaderCompileError(_) | LibrashaderError::ShaderReflectError(_) => { LibrashaderError::ShaderCompileError(_) | LibrashaderError::ShaderReflectError(_) => {
LIBRA_ERRNO::REFLECT_ERROR LIBRA_ERRNO::REFLECT_ERROR
},
LibrashaderError::UnknownShaderParameter(_) => {
LIBRA_ERRNO::SHADER_PARAMETER_ERROR
} }
LibrashaderError::UnknownShaderParameter(_) => LIBRA_ERRNO::SHADER_PARAMETER_ERROR,
#[cfg(feature = "runtime-opengl")] #[cfg(feature = "runtime-opengl")]
LibrashaderError::OpenGlFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, LibrashaderError::OpenGlFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
#[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] #[cfg(any(
feature = "docsrs",
all(target_os = "windows", feature = "runtime-d3d11")
))]
LibrashaderError::D3D11FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, LibrashaderError::D3D11FilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]
LibrashaderError::VulkanFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR, LibrashaderError::VulkanFilterError(_) => LIBRA_ERRNO::RUNTIME_ERROR,

View file

@ -1,6 +1,6 @@
//! The librashader preset C API (`libra_preset_*`). //! The librashader preset C API (`libra_preset_*`).
use crate::ctypes::{libra_shader_preset_t}; use crate::ctypes::libra_shader_preset_t;
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::extern_fn; use crate::ffi::extern_fn;
use librashader::presets::ShaderPreset; use librashader::presets::ShaderPreset;
use std::ffi::{c_char, CStr, CString}; use std::ffi::{c_char, CStr, CString};

View file

@ -1,13 +1,11 @@
use std::ffi::CStr; use crate::ctypes::{libra_d3d11_filter_chain_t, libra_shader_preset_t, libra_viewport_t};
use crate::ctypes::{
libra_d3d11_filter_chain_t, libra_shader_preset_t, libra_viewport_t,
};
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::extern_fn; use crate::ffi::extern_fn;
use librashader::runtime::d3d11::{D3D11InputView, D3D11OutputView}; use librashader::runtime::d3d11::{D3D11InputView, D3D11OutputView};
use std::ffi::c_char;
use std::ffi::CStr;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::ffi::c_char;
use std::slice; use std::slice;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView,

View file

@ -1,19 +1,17 @@
use crate::ctypes::{ use crate::ctypes::{libra_gl_filter_chain_t, libra_shader_preset_t, libra_viewport_t};
libra_gl_filter_chain_t, libra_shader_preset_t, libra_viewport_t,
};
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::extern_fn; use crate::ffi::extern_fn;
use librashader::runtime::gl::{Framebuffer, GLImage}; use librashader::runtime::gl::{Framebuffer, GLImage};
use std::ffi::CStr;
use std::ffi::{c_char, c_void, CString}; use std::ffi::{c_char, c_void, CString};
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::slice; use std::slice;
use std::ffi::CStr;
pub use librashader::runtime::gl::capi::options::FilterChainOptionsGL; pub use librashader::runtime::gl::capi::options::FilterChainOptionsGL;
pub use librashader::runtime::gl::capi::options::FrameOptionsGL; pub use librashader::runtime::gl::capi::options::FrameOptionsGL;
use librashader::runtime::{Size, Viewport};
use librashader::runtime::FilterChainParameters; use librashader::runtime::FilterChainParameters;
use librashader::runtime::{Size, Viewport};
/// A GL function loader that librashader needs to be initialized with. /// A GL function loader that librashader needs to be initialized with.
pub type libra_gl_loader_t = unsafe extern "system" fn(*const c_char) -> *const c_void; pub type libra_gl_loader_t = unsafe extern "system" fn(*const c_char) -> *const c_void;

View file

@ -2,7 +2,10 @@
#[cfg(feature = "runtime-opengl")] #[cfg(feature = "runtime-opengl")]
pub mod gl; pub mod gl;
#[cfg(any(feature = "docsrs", all(target_os = "windows", feature = "runtime-d3d11")))] #[cfg(any(
feature = "docsrs",
all(target_os = "windows", feature = "runtime-d3d11")
))]
pub mod d3d11; pub mod d3d11;
#[cfg(feature = "runtime-vulkan")] #[cfg(feature = "runtime-vulkan")]

View file

@ -1,27 +1,25 @@
use std::ffi::{c_char, c_void}; use crate::ctypes::{libra_shader_preset_t, libra_viewport_t, libra_vk_filter_chain_t};
use crate::ctypes::{
libra_vk_filter_chain_t, libra_shader_preset_t, libra_viewport_t,
};
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError}; use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::extern_fn; use crate::ffi::extern_fn;
use librashader::runtime::vk::{VulkanImage, VulkanInstance}; use librashader::runtime::vk::{VulkanImage, VulkanInstance};
use std::ffi::CStr;
use std::ffi::{c_char, c_void};
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::ptr::NonNull; use std::ptr::NonNull;
use std::slice; use std::slice;
use std::ffi::CStr;
pub use librashader::runtime::vk::capi::options::FilterChainOptionsVulkan; pub use librashader::runtime::vk::capi::options::FilterChainOptionsVulkan;
pub use librashader::runtime::vk::capi::options::FrameOptionsVulkan; pub use librashader::runtime::vk::capi::options::FrameOptionsVulkan;
use librashader::runtime::{Size, Viewport};
use librashader::runtime::FilterChainParameters; use librashader::runtime::FilterChainParameters;
use librashader::runtime::{Size, Viewport};
use ash::vk; use ash::vk;
pub use ash::vk::PFN_vkGetInstanceProcAddr; pub use ash::vk::PFN_vkGetInstanceProcAddr;
/// A Vulkan instance function loader that the Vulkan filter chain needs to be initialized with. /// A Vulkan instance function loader that the Vulkan filter chain needs to be initialized with.
pub type libra_PFN_vkGetInstanceProcAddr = unsafe extern "system" fn(instance: *mut c_void, p_name: *const c_char); pub type libra_PFN_vkGetInstanceProcAddr =
unsafe extern "system" fn(instance: *mut c_void, p_name: *const c_char);
/// Vulkan parameters for the source image. /// Vulkan parameters for the source image.
#[repr(C)] #[repr(C)]
@ -49,7 +47,7 @@ pub struct libra_device_vk_t {
/// for the device attached to the instance that will perform rendering. /// for the device attached to the instance that will perform rendering.
pub device: vk::Device, pub device: vk::Device,
/// The entry loader for the Vulkan library. /// The entry loader for the Vulkan library.
pub entry: vk::PFN_vkGetInstanceProcAddr pub entry: vk::PFN_vkGetInstanceProcAddr,
} }
impl From<libra_image_vk_t> for VulkanImage { impl From<libra_image_vk_t> for VulkanImage {
@ -165,7 +163,6 @@ extern_fn! {
} }
} }
extern_fn! { extern_fn! {
/// Sets a parameter for the filter chain. /// Sets a parameter for the filter chain.
/// ///

View file

@ -9,4 +9,4 @@ pub struct Viewport<'a, T> {
pub mvp: Option<&'a [f32; 16]>, pub mvp: Option<&'a [f32; 16]>,
/// The output handle to render the final image to. /// The output handle to render the final image to.
pub output: T, pub output: T,
} }

View file

@ -1,4 +1,4 @@
use crate::texture::{D3D11InputView, LutTexture, InputTexture}; use crate::texture::{D3D11InputView, InputTexture, LutTexture};
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
@ -24,7 +24,7 @@ use crate::quad_render::DrawQuad;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::util::d3d11_compile_bound_shader; use crate::util::d3d11_compile_bound_shader;
use crate::{D3D11OutputView, error, util}; use crate::{error, util, D3D11OutputView};
use librashader_runtime::uniforms::UniformStorage; use librashader_runtime::uniforms::UniformStorage;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC, ID3D11Buffer, ID3D11Device, ID3D11DeviceContext, D3D11_BIND_CONSTANT_BUFFER, D3D11_BUFFER_DESC,

View file

@ -11,15 +11,15 @@ use librashader_reflect::reflect::semantics::{
use librashader_reflect::reflect::ShaderReflection; use librashader_reflect::reflect::ShaderReflection;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use librashader_runtime::binding::{BindSemantics, TextureInput};
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Buffer, ID3D11InputLayout, ID3D11PixelShader, ID3D11SamplerState, ID3D11Buffer, ID3D11InputLayout, ID3D11PixelShader, ID3D11SamplerState,
ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD, ID3D11ShaderResourceView, ID3D11VertexShader, D3D11_MAP_WRITE_DISCARD,
}; };
use librashader_runtime::binding::{BindSemantics, TextureInput};
use crate::{D3D11OutputView, error};
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::{error, D3D11OutputView};
use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess}; use librashader_runtime::uniforms::{UniformStorage, UniformStorageAccess};
pub struct ConstantBufferBinding { pub struct ConstantBufferBinding {
@ -60,14 +60,20 @@ impl TextureInput for InputTexture {
impl BindSemantics for FilterPass { impl BindSemantics for FilterPass {
type InputTexture = InputTexture; type InputTexture = InputTexture;
type SamplerSet = SamplerSet; type SamplerSet = SamplerSet;
type DescriptorSet<'a> = (&'a mut [Option<ID3D11ShaderResourceView>; 16], &'a mut [Option<ID3D11SamplerState>; 16]); type DescriptorSet<'a> = (
&'a mut [Option<ID3D11ShaderResourceView>; 16],
&'a mut [Option<ID3D11SamplerState>; 16],
);
type DeviceContext = (); type DeviceContext = ();
type UniformOffset = MemberOffset; type UniformOffset = MemberOffset;
fn bind_texture<'a>( fn bind_texture<'a>(
descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, descriptors: &mut Self::DescriptorSet<'a>,
binding: &TextureBinding, texture: &Self::InputTexture, samplers: &Self::SamplerSet,
_device: &Self::DeviceContext) { binding: &TextureBinding,
texture: &Self::InputTexture,
_device: &Self::DeviceContext,
) {
let (texture_binding, sampler_binding) = descriptors; let (texture_binding, sampler_binding) = descriptors;
texture_binding[binding.binding as usize] = Some(texture.view.handle.clone()); texture_binding[binding.binding as usize] = Some(texture.view.handle.clone());
sampler_binding[binding.binding as usize] = sampler_binding[binding.binding as usize] =
@ -110,7 +116,10 @@ impl FilterPass {
frame_direction: i32, frame_direction: i32,
fb_size: Size<u32>, fb_size: Size<u32>,
viewport_size: Size<u32>, viewport_size: Size<u32>,
mut descriptors: (&'a mut [Option<ID3D11ShaderResourceView>; 16], &'a mut [Option<ID3D11SamplerState>; 16]), mut descriptors: (
&'a mut [Option<ID3D11ShaderResourceView>; 16],
&'a mut [Option<ID3D11SamplerState>; 16],
),
original: &InputTexture, original: &InputTexture,
source: &InputTexture, source: &InputTexture,
) { ) {
@ -128,16 +137,14 @@ impl FilterPass {
source, source,
&self.uniform_bindings, &self.uniform_bindings,
&self.reflection.meta.texture_meta, &self.reflection.meta.texture_meta,
parent.output_textures[0..pass_index].iter() parent.output_textures[0..pass_index]
.iter()
.map(|o| o.as_ref()), .map(|o| o.as_ref()),
parent.feedback_textures.iter() parent.feedback_textures.iter().map(|o| o.as_ref()),
.map(|o| o.as_ref()), parent.history_textures.iter().map(|o| o.as_ref()),
parent.history_textures.iter() parent.luts.iter().map(|(u, i)| (*u, i.as_ref())),
.map(|o| o.as_ref()),
parent.luts.iter()
.map(|(u, i)| (*u, i.as_ref())),
&self.source.parameters, &self.source.parameters,
&parent.config.parameters &parent.config.parameters,
); );
} }

View file

@ -229,10 +229,10 @@ pub mod d3d11_hello_triangle {
use crate::options::FilterChainOptionsD3D11; use crate::options::FilterChainOptionsD3D11;
use crate::texture::D3D11InputView; use crate::texture::D3D11InputView;
use crate::D3D11OutputView;
use librashader_common::{Size, Viewport}; use librashader_common::{Size, Viewport};
use std::slice; use std::slice;
use std::time::Instant; use std::time::Instant;
use crate::D3D11OutputView;
pub struct Sample { pub struct Sample {
pub dxgi_factory: IDXGIFactory4, pub dxgi_factory: IDXGIFactory4,

View file

@ -1,7 +1,7 @@
use crate::framebuffer::OutputFramebuffer; use crate::framebuffer::OutputFramebuffer;
use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT;
use librashader_common::Viewport;
use crate::D3D11OutputView; use crate::D3D11OutputView;
use librashader_common::Viewport;
use windows::Win32::Graphics::Direct3D11::D3D11_VIEWPORT;
#[rustfmt::skip] #[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[ static DEFAULT_MVP: &[f32; 16] = &[

View file

@ -2,18 +2,18 @@ use librashader_common::{FilterMode, Size, WrapMode};
use librashader_runtime::image::Image; use librashader_runtime::image::Image;
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D;
use windows::Win32::Graphics::Direct3D11::{ use windows::Win32::Graphics::Direct3D11::{
ID3D11Device, ID3D11DeviceContext, ID3D11ShaderResourceView, ID3D11RenderTargetView, ID3D11Texture2D, D3D11_BIND_FLAG, ID3D11Device, ID3D11DeviceContext, ID3D11RenderTargetView, ID3D11ShaderResourceView,
D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_BOX, D3D11_CPU_ACCESS_FLAG, ID3D11Texture2D, D3D11_BIND_FLAG, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE,
D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_BOX, D3D11_CPU_ACCESS_FLAG, D3D11_CPU_ACCESS_WRITE, D3D11_RESOURCE_MISC_FLAG,
D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_SHADER_RESOURCE_VIEW_DESC,
D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_SUBRESOURCE_DATA, D3D11_TEX2D_SRV,
D3D11_TEXTURE2D_DESC, D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING,
}; };
use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC; use windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC;
use crate::error::Result; use crate::error::Result;
use crate::framebuffer::OwnedFramebuffer; use crate::framebuffer::OwnedFramebuffer;
/// An image view for use as a shader resource. /// An image view for use as a shader resource.
/// ///
/// Contains an `ID3D11ShaderResourceView`, and a size. /// Contains an `ID3D11ShaderResourceView`, and a size.

View file

@ -29,7 +29,7 @@ pub enum FilterChainError {
#[error("opengl could not link program")] #[error("opengl could not link program")]
GLLinkError, GLLinkError,
#[error("opengl could not compile program")] #[error("opengl could not compile program")]
GlCompileError GlCompileError,
} }
/// Result type for OpenGL filter chains. /// Result type for OpenGL filter chains.

View file

@ -227,7 +227,8 @@ impl<T: GLInterface> FilterChainImpl<T> {
// todo: split this out. // todo: split this out.
let (program, ubo_location) = unsafe { let (program, ubo_location) = unsafe {
let vertex = util::gl_compile_shader(gl::VERTEX_SHADER, glsl.vertex.as_str())?; let vertex = util::gl_compile_shader(gl::VERTEX_SHADER, glsl.vertex.as_str())?;
let fragment = util::gl_compile_shader(gl::FRAGMENT_SHADER, glsl.fragment.as_str())?; let fragment =
util::gl_compile_shader(gl::FRAGMENT_SHADER, glsl.fragment.as_str())?;
let program = gl::CreateProgram(); let program = gl::CreateProgram();
gl::AttachShader(program, vertex); gl::AttachShader(program, vertex);
@ -304,21 +305,30 @@ impl<T: GLInterface> FilterChainImpl<T> {
for param in reflection.meta.parameter_meta.values() { for param in reflection.meta.parameter_meta.values() {
uniform_bindings.insert( uniform_bindings.insert(
UniformBinding::Parameter(param.id.clone()), UniformBinding::Parameter(param.id.clone()),
UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), UniformOffset::new(
Self::reflect_uniform_location(program, param),
param.offset,
),
); );
} }
for (semantics, param) in &reflection.meta.unique_meta { for (semantics, param) in &reflection.meta.unique_meta {
uniform_bindings.insert( uniform_bindings.insert(
UniformBinding::SemanticVariable(*semantics), UniformBinding::SemanticVariable(*semantics),
UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), UniformOffset::new(
Self::reflect_uniform_location(program, param),
param.offset,
),
); );
} }
for (semantics, param) in &reflection.meta.texture_size_meta { for (semantics, param) in &reflection.meta.texture_size_meta {
uniform_bindings.insert( uniform_bindings.insert(
UniformBinding::TextureSize(*semantics), UniformBinding::TextureSize(*semantics),
UniformOffset::new(Self::reflect_uniform_location(program, param), param.offset), UniformOffset::new(
Self::reflect_uniform_location(program, param),
param.offset,
),
); );
} }

View file

@ -1,4 +1,3 @@
use std::panic::catch_unwind; use std::panic::catch_unwind;
use std::path::Path; use std::path::Path;
@ -14,7 +13,7 @@ mod inner;
mod parameters; mod parameters;
pub(crate) use filter_impl::FilterCommon; pub(crate) use filter_impl::FilterCommon;
use librashader_common::{Viewport}; use librashader_common::Viewport;
/// An OpenGL filter chain. /// An OpenGL filter chain.
pub struct FilterChainGL { pub struct FilterChainGL {

View file

@ -6,30 +6,29 @@ use librashader_reflect::reflect::ShaderReflection;
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::ShaderPassConfig; use librashader_presets::ShaderPassConfig;
use librashader_reflect::reflect::semantics::{MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics}; use librashader_reflect::reflect::semantics::{
use rustc_hash::FxHashMap; MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
};
use librashader_runtime::binding::{BindSemantics, ContextOffset, TextureInput}; use librashader_runtime::binding::{BindSemantics, ContextOffset, TextureInput};
use rustc_hash::FxHashMap;
use crate::binding::{GlUniformBinder, GlUniformStorage, UniformLocation, VariableLocation}; use crate::binding::{GlUniformBinder, GlUniformStorage, UniformLocation, VariableLocation};
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::Framebuffer;
use crate::gl::{BindTexture, GLInterface, UboRing}; use crate::gl::{BindTexture, GLInterface, UboRing};
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::Framebuffer;
use crate::texture::InputTexture; use crate::texture::InputTexture;
pub struct UniformOffset { pub struct UniformOffset {
pub location: VariableLocation, pub location: VariableLocation,
pub offset: MemberOffset pub offset: MemberOffset,
} }
impl UniformOffset { impl UniformOffset {
pub fn new(location: VariableLocation, offset: MemberOffset) -> Self { pub fn new(location: VariableLocation, offset: MemberOffset) -> Self {
Self { Self { location, offset }
location,
offset
}
} }
} }
@ -69,9 +68,12 @@ impl<T: GLInterface> BindSemantics<GlUniformBinder, UniformLocation<GLint>> for
type UniformOffset = UniformOffset; type UniformOffset = UniformOffset;
fn bind_texture<'a>( fn bind_texture<'a>(
_descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, _descriptors: &mut Self::DescriptorSet<'a>,
binding: &TextureBinding, texture: &Self::InputTexture, samplers: &Self::SamplerSet,
_device: &Self::DeviceContext) { binding: &TextureBinding,
texture: &Self::InputTexture,
_device: &Self::DeviceContext,
) {
T::BindTexture::bind_texture(&samplers, binding, texture); T::BindTexture::bind_texture(&samplers, binding, texture);
} }
} }
@ -186,16 +188,14 @@ impl<T: GLInterface> FilterPass<T> {
source, source,
&self.uniform_bindings, &self.uniform_bindings,
&self.reflection.meta.texture_meta, &self.reflection.meta.texture_meta,
parent.output_textures[0..pass_index].iter() parent.output_textures[0..pass_index]
.iter()
.map(|o| o.bound()), .map(|o| o.bound()),
parent.feedback_textures.iter() parent.feedback_textures.iter().map(|o| o.bound()),
.map(|o| o.bound()), parent.history_textures.iter().map(|o| o.bound()),
parent.history_textures.iter() parent.luts.iter().map(|(u, i)| (*u, i)),
.map(|o| o.bound()),
parent.luts.iter()
.map(|(u, i)| (*u, i)),
&self.source.parameters, &self.source.parameters,
&parent.config.parameters &parent.config.parameters,
); );
} }
} }

View file

@ -6,7 +6,6 @@ use gl::types::{GLenum, GLuint};
use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
/// A handle to an OpenGL FBO and its backing texture with format and size information. /// A handle to an OpenGL FBO and its backing texture with format and size information.
/// ///
/// Generally for use as render targets. /// Generally for use as render targets.

View file

@ -8,10 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
use librashader_common::{Size, Viewport}; use librashader_common::{Size, Viewport};
use crate::filter_chain::FilterChainGL; use crate::filter_chain::FilterChainGL;
use crate::Framebuffer;
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::gl::gl3::CompatibilityGL; use crate::gl::gl3::CompatibilityGL;
use crate::gl::{FramebufferInterface, GLInterface}; use crate::gl::{FramebufferInterface, GLInterface};
use crate::Framebuffer;
const WIDTH: u32 = 800; const WIDTH: u32 = 800;
const HEIGHT: u32 = 600; const HEIGHT: u32 = 600;

View file

@ -8,10 +8,10 @@ use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
use librashader_common::{Size, Viewport}; use librashader_common::{Size, Viewport};
use crate::filter_chain::FilterChainGL; use crate::filter_chain::FilterChainGL;
use crate::Framebuffer;
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use crate::gl::gl46::DirectStateAccessGL; use crate::gl::gl46::DirectStateAccessGL;
use crate::gl::{FramebufferInterface, GLInterface}; use crate::gl::{FramebufferInterface, GLInterface};
use crate::Framebuffer;
const WIDTH: u32 = 800; const WIDTH: u32 = 800;
const HEIGHT: u32 = 600; const HEIGHT: u32 = 600;

View file

@ -1,5 +1,5 @@
use librashader_common::Viewport;
use crate::gl::Framebuffer; use crate::gl::Framebuffer;
use librashader_common::Viewport;
#[rustfmt::skip] #[rustfmt::skip]
static DEFAULT_MVP: &[f32; 16] = &[ static DEFAULT_MVP: &[f32; 16] = &[

View file

@ -1,5 +1,5 @@
use gl::types::GLuint;
use crate::framebuffer::GLImage; use crate::framebuffer::GLImage;
use gl::types::GLuint;
use librashader_common::{FilterMode, WrapMode}; use librashader_common::{FilterMode, WrapMode};
#[derive(Default, Debug, Copy, Clone)] #[derive(Default, Debug, Copy, Clone)]
@ -29,4 +29,4 @@ impl AsRef<InputTexture> for InputTexture {
fn as_ref(&self) -> &InputTexture { fn as_ref(&self) -> &InputTexture {
self self
} }
} }

View file

@ -1,8 +1,8 @@
use gl::types::{GLenum, GLuint}; use gl::types::{GLenum, GLuint};
use librashader_reflect::back::cross::GlslVersion;
use crate::error; use crate::error;
use crate::error::FilterChainError; use crate::error::FilterChainError;
use librashader_reflect::back::cross::GlslVersion;
pub unsafe fn gl_compile_shader(stage: GLenum, source: &str) -> error::Result<GLuint> { pub unsafe fn gl_compile_shader(stage: GLenum, source: &str) -> error::Result<GLuint> {
let shader = gl::CreateShader(stage); let shader = gl::CreateShader(stage);

View file

@ -3,6 +3,7 @@ use crate::error::FilterChainError;
use crate::filter_pass::FilterPass; use crate::filter_pass::FilterPass;
use crate::framebuffer::OutputImage; use crate::framebuffer::OutputImage;
use crate::luts::LutTexture; use crate::luts::LutTexture;
use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan};
use crate::queue_selection::get_graphics_queue; use crate::queue_selection::get_graphics_queue;
use crate::render_target::{RenderTarget, DEFAULT_MVP}; use crate::render_target::{RenderTarget, DEFAULT_MVP};
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
@ -27,7 +28,6 @@ use rustc_hash::FxHashMap;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan};
/// A Vulkan device and metadata that is required by the shader runtime. /// A Vulkan device and metadata that is required by the shader runtime.
pub struct VulkanObjects { pub struct VulkanObjects {
@ -78,7 +78,7 @@ impl TryFrom<VulkanInstance> for VulkanObjects {
instance.get_physical_device_memory_properties(vulkan.physical_device); instance.get_physical_device_memory_properties(vulkan.physical_device);
Ok(VulkanObjects { Ok(VulkanObjects {
device: Arc::new(device), device: Arc::new(device),
queue, queue,
pipeline_cache, pipeline_cache,
memory_properties, memory_properties,
@ -91,11 +91,14 @@ impl TryFrom<VulkanInstance> for VulkanObjects {
impl TryFrom<(vk::PhysicalDevice, ash::Instance, Arc<ash::Device>)> for VulkanObjects { impl TryFrom<(vk::PhysicalDevice, ash::Instance, Arc<ash::Device>)> for VulkanObjects {
type Error = FilterChainError; type Error = FilterChainError;
fn try_from(value: (vk::PhysicalDevice, ash::Instance, Arc<ash::Device>)) -> error::Result<Self> { fn try_from(
value: (vk::PhysicalDevice, ash::Instance, Arc<ash::Device>),
) -> error::Result<Self> {
unsafe { unsafe {
let device = value.2; let device = value.2;
let pipeline_cache = device.create_pipeline_cache(&vk::PipelineCacheCreateInfo::default(), None)?; let pipeline_cache =
device.create_pipeline_cache(&vk::PipelineCacheCreateInfo::default(), None)?;
let queue = get_graphics_queue(&value.1, &device, value.0); let queue = get_graphics_queue(&value.1, &device, value.0);
@ -245,7 +248,9 @@ impl FilterChainVulkan {
feedback_textures.resize_with(filters.len(), || None); feedback_textures.resize_with(filters.len(), || None);
let mut intermediates = Vec::new(); let mut intermediates = Vec::new();
intermediates.resize_with(frames_in_flight as usize, || FrameResiduals::new(&device.device)); intermediates.resize_with(frames_in_flight as usize, || {
FrameResiduals::new(&device.device)
});
Ok(FilterChainVulkan { Ok(FilterChainVulkan {
common: FilterCommon { common: FilterCommon {

View file

@ -1,11 +1,10 @@
use std::sync::Arc;
use crate::{error, VulkanImage};
use crate::filter_chain::FilterCommon; use crate::filter_chain::FilterCommon;
use crate::render_target::RenderTarget; use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet; use crate::samplers::SamplerSet;
use crate::texture::InputImage; use crate::texture::InputImage;
use crate::ubo_ring::VkUboRing; use crate::ubo_ring::VkUboRing;
use crate::vulkan_state::VulkanGraphicsPipeline; use crate::vulkan_state::VulkanGraphicsPipeline;
use crate::{error, VulkanImage};
use ash::vk; use ash::vk;
use librashader_common::{ImageFormat, Size, Viewport}; use librashader_common::{ImageFormat, Size, Viewport};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
@ -14,9 +13,12 @@ use librashader_reflect::reflect::semantics::{
BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics, BindingStage, MemberOffset, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
}; };
use librashader_reflect::reflect::ShaderReflection; use librashader_reflect::reflect::ShaderReflection;
use librashader_runtime::uniforms::{BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess};
use rustc_hash::FxHashMap;
use librashader_runtime::binding::{BindSemantics, TextureInput}; use librashader_runtime::binding::{BindSemantics, TextureInput};
use librashader_runtime::uniforms::{
BindUniform, NoUniformBinder, UniformStorage, UniformStorageAccess,
};
use rustc_hash::FxHashMap;
use std::sync::Arc;
pub struct FilterPass { pub struct FilterPass {
pub device: Arc<ash::Device>, pub device: Arc<ash::Device>,
@ -45,8 +47,12 @@ impl BindSemantics for FilterPass {
type UniformOffset = MemberOffset; type UniformOffset = MemberOffset;
fn bind_texture<'a>( fn bind_texture<'a>(
descriptors: &mut Self::DescriptorSet<'a>, samplers: &Self::SamplerSet, descriptors: &mut Self::DescriptorSet<'a>,
binding: &TextureBinding, texture: &Self::InputTexture, device: &Self::DeviceContext) { samplers: &Self::SamplerSet,
binding: &TextureBinding,
texture: &Self::InputTexture,
device: &Self::DeviceContext,
) {
let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter); let sampler = samplers.get(texture.wrap_mode, texture.filter_mode, texture.mip_filter);
let image_info = [vk::DescriptorImageInfo::builder() let image_info = [vk::DescriptorImageInfo::builder()
.sampler(sampler.handle) .sampler(sampler.handle)
@ -244,16 +250,14 @@ impl FilterPass {
source, source,
&self.uniform_bindings, &self.uniform_bindings,
&self.reflection.meta.texture_meta, &self.reflection.meta.texture_meta,
parent.output_inputs[0..pass_index].iter() parent.output_inputs[0..pass_index]
.iter()
.map(|o| o.as_ref()), .map(|o| o.as_ref()),
parent.feedback_inputs.iter() parent.feedback_inputs.iter().map(|o| o.as_ref()),
.map(|o| o.as_ref()), parent.history_textures.iter().map(|o| o.as_ref()),
parent.history_textures.iter() parent.luts.iter().map(|(u, i)| (*u, i.as_ref())),
.map(|o| o.as_ref()),
parent.luts.iter()
.map(|(u, i)| (*u, i.as_ref())),
&self.source.parameters, &self.source.parameters,
&parent.config.parameters &parent.config.parameters,
); );
} }
} }

View file

@ -1,9 +1,9 @@
use std::sync::Arc;
use crate::filter_chain::VulkanObjects; use crate::filter_chain::VulkanObjects;
use crate::texture::VulkanImage; use crate::texture::VulkanImage;
use crate::{error, util}; use crate::{error, util};
use ash::vk; use ash::vk;
use librashader_common::Size; use librashader_common::Size;
use std::sync::Arc;
#[derive(Clone)] #[derive(Clone)]
pub(crate) struct OutputImage { pub(crate) struct OutputImage {

View file

@ -1,8 +1,8 @@
use std::sync::Arc;
use crate::hello_triangle::physicaldevice::find_queue_family; use crate::hello_triangle::physicaldevice::find_queue_family;
use crate::hello_triangle::vulkan_base::VulkanBase; use crate::hello_triangle::vulkan_base::VulkanBase;
use ash::prelude::VkResult; use ash::prelude::VkResult;
use ash::vk; use ash::vk;
use std::sync::Arc;
pub struct VulkanCommandPool { pub struct VulkanCommandPool {
pool: vk::CommandPool, pool: vk::CommandPool,

View file

@ -20,11 +20,11 @@ use crate::texture::VulkanImage;
use crate::util; use crate::util;
use ash::vk; use ash::vk;
use ash::vk::{Handle, RenderingInfo}; use ash::vk::{Handle, RenderingInfo};
use librashader_common::Viewport;
use std::ffi::CString; use std::ffi::CString;
use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent}; use winit::event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent};
use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder}; use winit::event_loop::{ControlFlow, EventLoop, EventLoopBuilder};
use winit::platform::windows::EventLoopBuilderExtWindows; use winit::platform::windows::EventLoopBuilderExtWindows;
use librashader_common::Viewport;
// Constants // Constants
const WINDOW_TITLE: &'static str = "librashader Vulkan"; const WINDOW_TITLE: &'static str = "librashader Vulkan";
@ -210,7 +210,7 @@ impl VulkanWindow {
// vk::QUEUE_FAMILY_IGNORED // vk::QUEUE_FAMILY_IGNORED
// ); // );
filter filter
.frame( .frame(
&VulkanImage { &VulkanImage {
size: vulkan.swapchain.extent.into(), size: vulkan.swapchain.extent.into(),

View file

@ -109,11 +109,14 @@ impl VulkanSwapchain {
let alloc_info = vk::MemoryAllocateInfo::builder() let alloc_info = vk::MemoryAllocateInfo::builder()
.allocation_size(mem_reqs.size) .allocation_size(mem_reqs.size)
.memory_type_index(find_vulkan_memory_type( .memory_type_index(
&base.mem_props, find_vulkan_memory_type(
mem_reqs.memory_type_bits, &base.mem_props,
vk::MemoryPropertyFlags::DEVICE_LOCAL, mem_reqs.memory_type_bits,
).unwrap()) vk::MemoryPropertyFlags::DEVICE_LOCAL,
)
.unwrap(),
)
.build(); .build();
// todo: optimize by reusing existing memory. // todo: optimize by reusing existing memory.

View file

@ -20,8 +20,8 @@ mod vulkan_primitives;
mod vulkan_state; mod vulkan_state;
pub use filter_chain::FilterChainVulkan; pub use filter_chain::FilterChainVulkan;
pub use filter_chain::VulkanObjects;
pub use filter_chain::VulkanInstance; pub use filter_chain::VulkanInstance;
pub use filter_chain::VulkanObjects;
pub use texture::VulkanImage; pub use texture::VulkanImage;
pub mod error; pub mod error;

View file

@ -254,4 +254,4 @@ impl AsRef<InputImage> for LutTexture {
fn as_ref(&self) -> &InputImage { fn as_ref(&self) -> &InputImage {
&self.image &self.image
} }
} }

View file

@ -19,4 +19,3 @@ pub struct FilterChainOptionsVulkan {
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings. /// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
pub force_no_mipmaps: bool, pub force_no_mipmaps: bool,
} }

View file

@ -1,8 +1,8 @@
use std::sync::Arc;
use crate::error; use crate::error;
use ash::vk; use ash::vk;
use librashader_common::{FilterMode, WrapMode}; use librashader_common::{FilterMode, WrapMode};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::sync::Arc;
pub struct VulkanSampler { pub struct VulkanSampler {
pub handle: vk::Sampler, pub handle: vk::Sampler,

View file

@ -1,9 +1,9 @@
use std::sync::Arc;
use crate::filter_chain::VulkanObjects; use crate::filter_chain::VulkanObjects;
use crate::util::find_vulkan_memory_type; use crate::util::find_vulkan_memory_type;
use crate::vulkan_primitives::VulkanImageMemory; use crate::vulkan_primitives::VulkanImageMemory;
use crate::{error, util}; use crate::{error, util};
use ash::vk; use ash::vk;
use std::sync::Arc;
use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
@ -532,4 +532,4 @@ impl AsRef<InputImage> for InputImage {
fn as_ref(&self) -> &InputImage { fn as_ref(&self) -> &InputImage {
&self &self
} }
} }

View file

@ -1,9 +1,9 @@
use std::sync::Arc;
use crate::error; use crate::error;
use crate::vulkan_primitives::VulkanBuffer; use crate::vulkan_primitives::VulkanBuffer;
use ash::vk; use ash::vk;
use librashader_runtime::ringbuffer::{BoxRingBuffer, RingBuffer}; use librashader_runtime::ringbuffer::{BoxRingBuffer, RingBuffer};
use librashader_runtime::uniforms::UniformStorageAccess; use librashader_runtime::uniforms::UniformStorageAccess;
use std::sync::Arc;
pub struct VkUboRing { pub struct VkUboRing {
ring: BoxRingBuffer<VulkanBuffer>, ring: BoxRingBuffer<VulkanBuffer>,

View file

@ -1,8 +1,8 @@
use ash::vk; use ash::vk;
use librashader_reflect::reflect::semantics::BindingStage;
use crate::error; use crate::error;
use crate::error::FilterChainError; use crate::error::FilterChainError;
use librashader_reflect::reflect::semantics::BindingStage;
pub fn binding_stage_to_vulkan_stage(stage_mask: BindingStage) -> vk::ShaderStageFlags { pub fn binding_stage_to_vulkan_stage(stage_mask: BindingStage) -> vk::ShaderStageFlags {
let mut mask = vk::ShaderStageFlags::default(); let mut mask = vk::ShaderStageFlags::default();
@ -33,7 +33,11 @@ pub fn find_vulkan_memory_type(
if host_reqs == vk::MemoryPropertyFlags::empty() { if host_reqs == vk::MemoryPropertyFlags::empty() {
Err(FilterChainError::VulkanMemoryError(device_reqs)) Err(FilterChainError::VulkanMemoryError(device_reqs))
} else { } else {
Ok(find_vulkan_memory_type(props, device_reqs, vk::MemoryPropertyFlags::empty())?) Ok(find_vulkan_memory_type(
props,
device_reqs,
vk::MemoryPropertyFlags::empty(),
)?)
} }
} }

View file

@ -1,9 +1,11 @@
use std::collections::HashMap; use crate::uniforms::{BindUniform, NoUniformBinder, UniformStorage};
use std::hash::BuildHasher;
use librashader_common::Size; use librashader_common::Size;
use librashader_preprocess::ShaderParameter; use librashader_preprocess::ShaderParameter;
use librashader_reflect::reflect::semantics::{MemberOffset, Semantic, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics}; use librashader_reflect::reflect::semantics::{
use crate::uniforms::{BindUniform, NoUniformBinder, UniformStorage}; MemberOffset, Semantic, TextureBinding, TextureSemantics, UniformBinding, UniqueSemantics,
};
use std::collections::HashMap;
use std::hash::BuildHasher;
/// Trait for input textures used during uniform binding, /// Trait for input textures used during uniform binding,
pub trait TextureInput { pub trait TextureInput {
@ -13,12 +15,12 @@ pub trait TextureInput {
/// A uniform member offset with context that needs to be resolved. /// A uniform member offset with context that needs to be resolved.
pub trait ContextOffset<H, C> pub trait ContextOffset<H, C>
where where
H: BindUniform<C, f32>, H: BindUniform<C, f32>,
H: BindUniform<C, u32>, H: BindUniform<C, u32>,
H: BindUniform<C, i32>, H: BindUniform<C, i32>,
H: for<'a> BindUniform<C, &'a [f32; 4]>, H: for<'a> BindUniform<C, &'a [f32; 4]>,
H: for<'a> BindUniform<C, &'a [f32; 16]>, H: for<'a> BindUniform<C, &'a [f32; 16]>,
{ {
/// Gets the `MemberOffset` part of the offset. /// Gets the `MemberOffset` part of the offset.
fn offset(&self) -> MemberOffset; fn offset(&self) -> MemberOffset;
@ -28,12 +30,12 @@ pub trait ContextOffset<H, C>
} }
impl<H> ContextOffset<H, Option<()>> for MemberOffset impl<H> ContextOffset<H, Option<()>> for MemberOffset
where where
H: BindUniform<Option<()>, f32>, H: BindUniform<Option<()>, f32>,
H: BindUniform<Option<()>, u32>, H: BindUniform<Option<()>, u32>,
H: BindUniform<Option<()>, i32>, H: BindUniform<Option<()>, i32>,
H: for<'a> BindUniform<Option<()>, &'a [f32; 4]>, H: for<'a> BindUniform<Option<()>, &'a [f32; 4]>,
H: for<'a> BindUniform<Option<()>, &'a [f32; 16]>, H: for<'a> BindUniform<Option<()>, &'a [f32; 16]>,
{ {
fn offset(&self) -> MemberOffset { fn offset(&self) -> MemberOffset {
*self *self
@ -45,13 +47,13 @@ impl<H> ContextOffset<H, Option<()>> for MemberOffset
} }
/// Trait that abstracts binding of semantics to shader uniforms. /// Trait that abstracts binding of semantics to shader uniforms.
pub trait BindSemantics<H=NoUniformBinder, C=Option<()>> pub trait BindSemantics<H = NoUniformBinder, C = Option<()>>
where where
H: BindUniform<C, f32>, H: BindUniform<C, f32>,
H: BindUniform<C, u32>, H: BindUniform<C, u32>,
H: BindUniform<C, i32>, H: BindUniform<C, i32>,
H: for<'b> BindUniform<C, &'b [f32; 4]>, H: for<'b> BindUniform<C, &'b [f32; 4]>,
H: for<'b> BindUniform<C, &'b [f32; 16]> H: for<'b> BindUniform<C, &'b [f32; 16]>,
{ {
/// The type of the input texture used for semantic binding. /// The type of the input texture used for semantic binding.
type InputTexture: TextureInput; type InputTexture: TextureInput;
@ -68,14 +70,13 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
/// The type of uniform offsets to use. /// The type of uniform offsets to use.
type UniformOffset: ContextOffset<H, C>; type UniformOffset: ContextOffset<H, C>;
/// Bind a texture to the input descriptor set /// Bind a texture to the input descriptor set
fn bind_texture<'a>( fn bind_texture<'a>(
descriptors: &mut Self::DescriptorSet<'a>, descriptors: &mut Self::DescriptorSet<'a>,
samplers: &Self::SamplerSet, samplers: &Self::SamplerSet,
binding: &TextureBinding, binding: &TextureBinding,
texture: &Self::InputTexture, texture: &Self::InputTexture,
device: &Self::DeviceContext device: &Self::DeviceContext,
); );
#[clippy::allow(too_many_arguments)] #[clippy::allow(too_many_arguments)]
@ -100,8 +101,7 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
lookup_textures: impl Iterator<Item = (usize, impl AsRef<Self::InputTexture>)>, lookup_textures: impl Iterator<Item = (usize, impl AsRef<Self::InputTexture>)>,
parameter_defaults: &[ShaderParameter], parameter_defaults: &[ShaderParameter],
runtime_parameters: &HashMap<String, f32, impl BuildHasher>, runtime_parameters: &HashMap<String, f32, impl BuildHasher>,
) ) {
{
// Bind MVP // Bind MVP
if let Some(offset) = uniform_bindings.get(&UniqueSemantics::MVP.into()) { if let Some(offset) = uniform_bindings.get(&UniqueSemantics::MVP.into()) {
uniform_storage.bind_mat4(offset.offset(), mvp, offset.context()); uniform_storage.bind_mat4(offset.offset(), mvp, offset.context());
@ -113,90 +113,53 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
} }
// bind FinalViewportSize // bind FinalViewportSize
if let Some(offset) = uniform_bindings if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FinalViewport.into()) {
.get(&UniqueSemantics::FinalViewport.into())
{
uniform_storage.bind_vec4(offset.offset(), viewport_size, offset.context()); uniform_storage.bind_vec4(offset.offset(), viewport_size, offset.context());
} }
// bind FrameCount // bind FrameCount
if let Some(offset) = uniform_bindings if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FrameCount.into()) {
.get(&UniqueSemantics::FrameCount.into())
{
uniform_storage.bind_scalar(offset.offset(), frame_count, offset.context()); uniform_storage.bind_scalar(offset.offset(), frame_count, offset.context());
} }
// bind FrameDirection // bind FrameDirection
if let Some(offset) = uniform_bindings if let Some(offset) = uniform_bindings.get(&UniqueSemantics::FrameDirection.into()) {
.get(&UniqueSemantics::FrameDirection.into()) uniform_storage.bind_scalar(offset.offset(), frame_direction, offset.context());
{
uniform_storage
.bind_scalar(offset.offset(), frame_direction, offset.context());
} }
// bind Original sampler // bind Original sampler
if let Some(binding) = texture_meta if let Some(binding) = texture_meta.get(&TextureSemantics::Original.semantics(0)) {
.get(&TextureSemantics::Original.semantics(0)) Self::bind_texture(descriptor_set, sampler_set, binding, original, device);
{
Self::bind_texture(
descriptor_set,
sampler_set,
binding,
original,
device
);
} }
// bind OriginalSize // bind OriginalSize
if let Some(offset) = uniform_bindings if let Some(offset) = uniform_bindings.get(&TextureSemantics::Original.semantics(0).into())
.get(&TextureSemantics::Original.semantics(0).into())
{ {
uniform_storage uniform_storage.bind_vec4(offset.offset(), original.size(), offset.context());
.bind_vec4(offset.offset(), original.size(), offset.context());
} }
// bind Source sampler // bind Source sampler
if let Some(binding) = texture_meta if let Some(binding) = texture_meta.get(&TextureSemantics::Source.semantics(0)) {
.get(&TextureSemantics::Source.semantics(0)) Self::bind_texture(descriptor_set, sampler_set, binding, source, device);
{
Self::bind_texture(
descriptor_set,
sampler_set,
binding,
source,
device
);
} }
// bind SourcelSize // bind SourcelSize
if let Some(offset) = uniform_bindings if let Some(offset) = uniform_bindings.get(&TextureSemantics::Source.semantics(0).into()) {
.get(&TextureSemantics::Source.semantics(0).into()) uniform_storage.bind_vec4(offset.offset(), source.size(), offset.context());
{
uniform_storage
.bind_vec4(offset.offset(), source.size(), offset.context());
} }
// OriginalHistory0 aliases OriginalHistory // OriginalHistory0 aliases OriginalHistory
// bind OriginalHistory0 sampler // bind OriginalHistory0 sampler
if let Some(binding) = texture_meta if let Some(binding) = texture_meta.get(&TextureSemantics::OriginalHistory.semantics(0)) {
.get(&TextureSemantics::OriginalHistory.semantics(0)) Self::bind_texture(descriptor_set, sampler_set, binding, original, device);
{
Self::bind_texture(
descriptor_set,
sampler_set,
binding,
original,
device
);
} }
// bind OriginalHistory0Size // bind OriginalHistory0Size
if let Some(offset) = uniform_bindings if let Some(offset) =
.get(&TextureSemantics::OriginalHistory.semantics(0).into()) uniform_bindings.get(&TextureSemantics::OriginalHistory.semantics(0).into())
{ {
uniform_storage uniform_storage.bind_vec4(offset.offset(), original.size(), offset.context());
.bind_vec4(offset.offset(), original.size(), offset.context());
} }
// bind OriginalHistory1-.. // bind OriginalHistory1-..
@ -207,16 +170,10 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
let history = history.as_ref(); let history = history.as_ref();
if let Some(binding) = texture_meta if let Some(binding) =
.get(&TextureSemantics::OriginalHistory.semantics(index + 1)) texture_meta.get(&TextureSemantics::OriginalHistory.semantics(index + 1))
{ {
Self::bind_texture( Self::bind_texture(descriptor_set, sampler_set, binding, history, device);
descriptor_set,
sampler_set,
binding,
history,
device
);
} }
if let Some(offset) = uniform_bindings.get( if let Some(offset) = uniform_bindings.get(
@ -224,8 +181,7 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
.semantics(index + 1) .semantics(index + 1)
.into(), .into(),
) { ) {
uniform_storage uniform_storage.bind_vec4(offset.offset(), history.size(), offset.context());
.bind_vec4(offset.offset(), history.size(), offset.context());
} }
} }
@ -239,25 +195,15 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
let output = output.as_ref(); let output = output.as_ref();
if let Some(binding) = texture_meta if let Some(binding) = texture_meta.get(&TextureSemantics::PassOutput.semantics(index))
.get(&TextureSemantics::PassOutput.semantics(index))
{ {
Self::bind_texture( Self::bind_texture(descriptor_set, sampler_set, binding, output, device);
descriptor_set,
sampler_set,
binding,
output,
device
);
} }
if let Some(offset) = uniform_bindings.get( if let Some(offset) =
&TextureSemantics::PassOutput uniform_bindings.get(&TextureSemantics::PassOutput.semantics(index).into())
.semantics(index) {
.into(), uniform_storage.bind_vec4(offset.offset(), output.size(), offset.context());
) {
uniform_storage
.bind_vec4(offset.offset(), output.size(), offset.context());
} }
} }
@ -269,31 +215,21 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
let feedback = output.as_ref(); let feedback = output.as_ref();
if let Some(binding) = texture_meta if let Some(binding) =
.get(&TextureSemantics::PassFeedback.semantics(index)) texture_meta.get(&TextureSemantics::PassFeedback.semantics(index))
{ {
Self::bind_texture( Self::bind_texture(descriptor_set, sampler_set, binding, feedback, device);
descriptor_set,
sampler_set,
binding,
feedback,
device
);
} }
if let Some(offset) = uniform_bindings.get( if let Some(offset) =
&TextureSemantics::PassFeedback uniform_bindings.get(&TextureSemantics::PassFeedback.semantics(index).into())
.semantics(index) {
.into(), uniform_storage.bind_vec4(offset.offset(), feedback.size(), offset.context());
) {
uniform_storage
.bind_vec4(offset.offset(), feedback.size(), offset.context());
} }
} }
// bind User parameters // bind User parameters
for (id, offset) in for (id, offset) in uniform_bindings
uniform_bindings
.iter() .iter()
.filter_map(|(binding, value)| match binding { .filter_map(|(binding, value)| match binding {
UniformBinding::Parameter(id) => Some((id, value)), UniformBinding::Parameter(id) => Some((id, value)),
@ -302,7 +238,8 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
{ {
let id = id.as_str(); let id = id.as_str();
let default = parameter_defaults.iter() let default = parameter_defaults
.iter()
.find(|&p| p.id == id) .find(|&p| p.id == id)
.map(|f| f.initial) .map(|f| f.initial)
.unwrap_or(0f32); .unwrap_or(0f32);
@ -315,24 +252,15 @@ pub trait BindSemantics<H=NoUniformBinder, C=Option<()>>
// bind luts // bind luts
for (index, lut) in lookup_textures { for (index, lut) in lookup_textures {
let lut = lut.as_ref(); let lut = lut.as_ref();
if let Some(binding) = texture_meta if let Some(binding) = texture_meta.get(&TextureSemantics::User.semantics(index)) {
.get(&TextureSemantics::User.semantics(index)) Self::bind_texture(descriptor_set, sampler_set, binding, lut, device);
{
Self::bind_texture(
descriptor_set,
sampler_set,
binding,
lut,
device
);
} }
if let Some(offset) = uniform_bindings if let Some(offset) =
.get(&TextureSemantics::User.semantics(index).into()) uniform_bindings.get(&TextureSemantics::User.semantics(index).into())
{ {
uniform_storage uniform_storage.bind_vec4(offset.offset(), lut.size(), offset.context());
.bind_vec4(offset.offset(), lut.size(), offset.context());
} }
} }
} }
} }

View file

@ -69,9 +69,9 @@ pub mod preprocess {
pub mod reflect { pub mod reflect {
/// Supported shader compiler targets. /// Supported shader compiler targets.
pub mod targets { pub mod targets {
pub use librashader_reflect::back::targets::SPIRV;
pub use librashader_reflect::back::targets::GLSL; pub use librashader_reflect::back::targets::GLSL;
pub use librashader_reflect::back::targets::HLSL; pub use librashader_reflect::back::targets::HLSL;
pub use librashader_reflect::back::targets::SPIRV;
} }
pub use librashader_reflect::error::*; pub use librashader_reflect::error::*;
@ -94,8 +94,8 @@ pub mod reflect {
/// Shader runtimes to execute a filter chain on a GPU surface. /// Shader runtimes to execute a filter chain on a GPU surface.
#[cfg(feature = "runtime")] #[cfg(feature = "runtime")]
pub mod runtime { pub mod runtime {
pub use librashader_common::{Size, Viewport};
pub use librashader_runtime::parameters::FilterChainParameters; pub use librashader_runtime::parameters::FilterChainParameters;
pub use librashader_common::{Viewport, Size};
#[cfg(feature = "gl")] #[cfg(feature = "gl")]
/// Shader runtime for OpenGL 3.3+. /// Shader runtime for OpenGL 3.3+.
@ -104,13 +104,9 @@ pub mod runtime {
/// initialized with [`gl::load_with`](https://docs.rs/gl/0.14.0/gl/fn.load_with.html). /// initialized with [`gl::load_with`](https://docs.rs/gl/0.14.0/gl/fn.load_with.html).
pub mod gl { pub mod gl {
pub use librashader_runtime_gl::{ pub use librashader_runtime_gl::{
options::{ error,
FilterChainOptionsGL as FilterChainOptions, options::{FilterChainOptionsGL as FilterChainOptions, FrameOptionsGL as FrameOptions},
FrameOptionsGL as FrameOptions, FilterChainGL as FilterChain, Framebuffer, GLImage,
},
FilterChainGL as FilterChain,
Framebuffer, GLImage,
error
}; };
#[doc(hidden)] #[doc(hidden)]
@ -126,13 +122,11 @@ pub mod runtime {
/// Shader runtime for Direct3D 11. /// Shader runtime for Direct3D 11.
pub mod d3d11 { pub mod d3d11 {
pub use librashader_runtime_d3d11::{ pub use librashader_runtime_d3d11::{
error,
options::{ options::{
FilterChainOptionsD3D11 as FilterChainOptions, FilterChainOptionsD3D11 as FilterChainOptions, FrameOptionsD3D11 as FrameOptions,
FrameOptionsD3D11 as FrameOptions,
}, },
FilterChainD3D11 as FilterChain, D3D11InputView, D3D11OutputView, FilterChainD3D11 as FilterChain,
D3D11InputView, D3D11OutputView,
error
}; };
#[doc(hidden)] #[doc(hidden)]
@ -148,13 +142,11 @@ pub mod runtime {
/// Shader runtime for Vulkan 1.3+. /// Shader runtime for Vulkan 1.3+.
pub mod vk { pub mod vk {
pub use librashader_runtime_vk::{ pub use librashader_runtime_vk::{
error,
options::{ options::{
FilterChainOptionsVulkan as FilterChainOptions, FilterChainOptionsVulkan as FilterChainOptions, FrameOptionsVulkan as FrameOptions,
FrameOptionsVulkan as FrameOptions,
}, },
FilterChainVulkan as FilterChain, FilterChainVulkan as FilterChain, VulkanImage, VulkanInstance, VulkanObjects,
VulkanImage, VulkanObjects, VulkanInstance,
error
}; };
#[doc(hidden)] #[doc(hidden)]