api: remove FilterChain trait

This commit is contained in:
chyyran 2023-01-13 02:32:21 -05:00
parent dc6e8f9a2c
commit abaebe56cc
25 changed files with 116 additions and 238 deletions

View file

@ -7,11 +7,11 @@ pub type libra_shader_preset_t = Option<NonNull<ShaderPreset>>;
pub type libra_error_t = Option<NonNull<LibrashaderError>>;
#[cfg(feature = "runtime-opengl")]
pub type libra_gl_filter_chain_t = Option<NonNull<librashader::runtime::gl::FilterChainGL>>;
pub type libra_gl_filter_chain_t = Option<NonNull<librashader::runtime::gl::FilterChain>>;
#[cfg(feature = "runtime-d3d11")]
pub type libra_d3d11_filter_chain_t =
Option<NonNull<librashader::runtime::d3d11::FilterChainD3D11>>;
Option<NonNull<librashader::runtime::d3d11::FilterChain>>;
/// Parameters for the output viewport.
#[repr(C)]

View file

@ -11,8 +11,8 @@ use windows::Win32::Graphics::Direct3D11::{
ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView,
};
pub use librashader::runtime::d3d11::options::FilterChainOptionsD3D11;
pub use librashader::runtime::d3d11::options::FrameOptionsD3D11;
pub use librashader::runtime::d3d11::options::FilterChainOptions;
pub use librashader::runtime::d3d11::options::FrameOptions;
use librashader::Size;
/// OpenGL parameters for the source image.
@ -42,7 +42,7 @@ impl TryFrom<libra_source_image_d3d11_t> for D3D11ImageView {
pub type PFN_lbr_d3d11_filter_chain_create = unsafe extern "C" fn(
preset: *mut libra_shader_preset_t,
options: *const FilterChainOptionsD3D11,
options: *const FilterChainOptions,
device: *const ID3D11Device,
out: *mut MaybeUninit<libra_d3d11_filter_chain_t>,
) -> libra_error_t;
@ -58,7 +58,7 @@ pub type PFN_lbr_d3d11_filter_chain_create = unsafe extern "C" fn(
#[no_mangle]
pub unsafe extern "C" fn libra_d3d11_filter_chain_create(
preset: *mut libra_shader_preset_t,
options: *const FilterChainOptionsD3D11,
options: *const FilterChainOptions,
device: *const ID3D11Device,
out: *mut MaybeUninit<libra_d3d11_filter_chain_t>,
) -> libra_error_t {
@ -77,7 +77,7 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_create(
Some(unsafe { &*options })
};
let chain = librashader::runtime::d3d11::FilterChainD3D11::load_from_preset(
let chain = librashader::runtime::d3d11::FilterChain::load_from_preset(
unsafe { &*device },
*preset,
options,
@ -98,7 +98,7 @@ pub type PFN_lbr_d3d11_filter_chain_frame = unsafe extern "C" fn(
viewport: libra_viewport_t,
out: *const ID3D11RenderTargetView,
mvp: *const f32,
opt: *const FrameOptionsD3D11,
opt: *const FrameOptions,
) -> libra_error_t;
/// Draw a frame with the given parameters for the given filter chain.
@ -118,7 +118,7 @@ pub unsafe extern "C" fn libra_d3d11_filter_chain_frame(
viewport: libra_viewport_t,
out: *const ID3D11RenderTargetView,
mvp: *const f32,
opt: *const FrameOptionsD3D11,
opt: *const FrameOptions,
) -> libra_error_t {
ffi_body!(mut |chain| {
assert_some_ptr!(mut chain);

View file

@ -3,15 +3,14 @@ use crate::ctypes::{
};
use crate::error::{assert_non_null, assert_some_ptr, LibrashaderError};
use crate::ffi::ffi_body;
use librashader::runtime::gl::{GLImage, Viewport};
use librashader::runtime::FilterChain;
use librashader::runtime::gl::{Framebuffer, GLImage, Viewport};
use std::ffi::{c_char, c_void, CString};
use std::mem::MaybeUninit;
use std::ptr::NonNull;
use std::slice;
pub use librashader::runtime::gl::options::FilterChainOptionsGL;
pub use librashader::runtime::gl::options::FrameOptionsGL;
pub use librashader::runtime::gl::options::FilterChainOptions;
pub use librashader::runtime::gl::options::FrameOptions;
use librashader::Size;
/// A GL function loader that librashader needs to be initialized with.
@ -37,7 +36,7 @@ pub unsafe extern "C" fn libra_gl_init_context(loader: gl_loader_t) -> libra_err
pub type PFN_lbr_gl_filter_chain_create = unsafe extern "C" fn(
preset: *mut libra_shader_preset_t,
options: *const FilterChainOptionsGL,
options: *const FilterChainOptions,
out: *mut MaybeUninit<libra_gl_filter_chain_t>,
) -> libra_error_t;
/// Create the filter chain given the shader preset.
@ -52,7 +51,7 @@ pub type PFN_lbr_gl_filter_chain_create = unsafe extern "C" fn(
#[no_mangle]
pub unsafe extern "C" fn libra_gl_filter_chain_create(
preset: *mut libra_shader_preset_t,
options: *const FilterChainOptionsGL,
options: *const FilterChainOptions,
out: *mut MaybeUninit<libra_gl_filter_chain_t>,
) -> libra_error_t {
ffi_body!({
@ -69,7 +68,7 @@ pub unsafe extern "C" fn libra_gl_filter_chain_create(
Some(unsafe { &*options })
};
let chain = librashader::runtime::gl::FilterChainGL::load_from_preset(*preset, options)?;
let chain = librashader::runtime::gl::FilterChain::load_from_preset(*preset, options)?;
unsafe {
out.write(MaybeUninit::new(NonNull::new(Box::into_raw(Box::new(
@ -121,7 +120,7 @@ pub type PFN_lbr_gl_filter_chain_frame = unsafe extern "C" fn(
viewport: libra_viewport_t,
out: libra_draw_framebuffer_gl_t,
mvp: *const f32,
opt: *const FrameOptionsGL,
opt: *const FrameOptions,
) -> libra_error_t;
/// Draw a frame with the given parameters for the given filter chain.
@ -141,7 +140,7 @@ pub unsafe extern "C" fn libra_gl_filter_chain_frame(
viewport: libra_viewport_t,
out: libra_draw_framebuffer_gl_t,
mvp: *const f32,
opt: *const FrameOptionsGL,
opt: *const FrameOptions,
) -> libra_error_t {
ffi_body!(mut |chain| {
assert_some_ptr!(mut chain);
@ -159,10 +158,11 @@ pub unsafe extern "C" fn libra_gl_filter_chain_frame(
Some(unsafe { opt.read() })
};
let framebuffer = Framebuffer::new_from_raw(out.texture, out.handle, out.format, Size::new(viewport.width, viewport.height), 1);
let viewport = Viewport {
x: viewport.x,
y: viewport.y,
output: &chain.create_framebuffer_raw(out.texture, out.handle, out.format, Size::new(viewport.width, viewport.height), 1),
output: &framebuffer,
mvp,
};
chain.frame(&image, &viewport, frame_count, opt.as_ref())?;

View file

@ -19,7 +19,7 @@ use std::path::Path;
use crate::error::FilterChainError;
use crate::filter_pass::{ConstantBufferBinding, FilterPass};
use crate::framebuffer::OwnedFramebuffer;
use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11};
use crate::options::{FilterChainOptions, FrameOptions};
use crate::quad_render::DrawQuad;
use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet;
@ -47,7 +47,7 @@ type ShaderPassMeta = (
>,
);
pub struct FilterChainD3D11 {
pub struct FilterChain {
pub(crate) common: FilterCommon,
pub(crate) passes: Vec<FilterPass>,
pub(crate) output_framebuffers: Box<[OwnedFramebuffer]>,
@ -74,13 +74,13 @@ pub(crate) struct FilterCommon {
pub disable_mipmaps: bool,
}
impl FilterChainD3D11 {
impl FilterChain {
/// Load the shader preset at the given path into a filter chain.
pub fn load_from_path(
device: &ID3D11Device,
path: impl AsRef<Path>,
options: Option<&FilterChainOptionsD3D11>,
) -> error::Result<FilterChainD3D11> {
options: Option<&FilterChainOptions>,
) -> error::Result<FilterChain> {
// load passes from preset
let preset = ShaderPreset::try_parse(path)?;
Self::load_from_preset(device, preset, options)
@ -90,16 +90,16 @@ impl FilterChainD3D11 {
pub fn load_from_preset(
device: &ID3D11Device,
preset: ShaderPreset,
options: Option<&FilterChainOptionsD3D11>,
) -> error::Result<FilterChainD3D11> {
let (passes, semantics) = FilterChainD3D11::load_preset(preset.shaders, &preset.textures)?;
options: Option<&FilterChainOptions>,
) -> error::Result<FilterChain> {
let (passes, semantics) = FilterChain::load_preset(preset.shaders, &preset.textures)?;
let use_deferred_context = options.map(|f| f.use_deferred_context).unwrap_or(false);
let samplers = SamplerSet::new(device)?;
// initialize passes
let filters = FilterChainD3D11::init_passes(device, passes, &semantics)?;
let filters = FilterChain::init_passes(device, passes, &semantics)?;
let mut immediate_context = None;
unsafe {
@ -154,15 +154,15 @@ impl FilterChainD3D11 {
feedback_textures.resize_with(filters.len(), || None);
// load luts
let luts = FilterChainD3D11::load_luts(device, &current_context, &preset.textures)?;
let luts = FilterChain::load_luts(device, &current_context, &preset.textures)?;
let (history_framebuffers, history_textures) =
FilterChainD3D11::init_history(device, &current_context, &filters)?;
FilterChain::init_history(device, &current_context, &filters)?;
let draw_quad = DrawQuad::new(device, &current_context)?;
// todo: make vbo: d3d11.c 1376
Ok(FilterChainD3D11 {
Ok(FilterChain {
passes: filters,
output_framebuffers: output_framebuffers.into_boxed_slice(),
feedback_framebuffers: feedback_framebuffers.into_boxed_slice(),
@ -194,7 +194,7 @@ impl FilterChainD3D11 {
}
}
impl FilterChainD3D11 {
impl FilterChain {
fn create_constant_buffer(device: &ID3D11Device, size: u32) -> error::Result<ID3D11Buffer> {
unsafe {
let buffer = device.CreateBuffer(
@ -247,7 +247,7 @@ impl FilterChainD3D11 {
)?;
let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 {
let buffer = FilterChainD3D11::create_constant_buffer(device, ubo.size)?;
let buffer = FilterChain::create_constant_buffer(device, ubo.size)?;
Some(ConstantBufferBinding {
binding: ubo.binding,
size: ubo.size,
@ -259,7 +259,7 @@ impl FilterChainD3D11 {
};
let push_cbuffer = if let Some(push) = &reflection.push_constant && push.size != 0 {
let buffer = FilterChainD3D11::create_constant_buffer(device, push.size)?;
let buffer = FilterChain::create_constant_buffer(device, push.size)?;
Some(ConstantBufferBinding {
binding: if ubo_cbuffer.is_some() { 1 } else { 0 },
size: push.size,
@ -468,7 +468,7 @@ impl FilterChainD3D11 {
input: D3D11ImageView,
viewport: &Viewport,
frame_count: usize,
options: Option<&FrameOptionsD3D11>,
options: Option<&FrameOptions>,
) -> error::Result<()> {
let passes = &mut self.passes[0..self.common.config.passes_enabled];
if let Some(options) = options {
@ -612,20 +612,3 @@ impl FilterChainD3D11 {
Ok(())
}
}
impl librashader_runtime::filter_chain::FilterChain for FilterChainD3D11 {
type Error = FilterChainError;
type Input<'a> = D3D11ImageView;
type Viewport<'a> = Viewport<'a>;
type FrameOptions = FrameOptionsD3D11;
fn frame<'a>(
&mut self,
input: Self::Input<'a>,
viewport: &Self::Viewport<'a>,
frame_count: usize,
options: Option<&Self::FrameOptions>,
) -> Result<(), Self::Error> {
self.frame(input, viewport, frame_count, options)
}
}

View file

@ -225,9 +225,9 @@ pub mod d3d11_hello_triangle {
use super::*;
use std::path::Path;
use crate::filter_chain::FilterChainD3D11;
use crate::filter_chain::FilterChain;
use crate::options::FilterChainOptionsD3D11;
use crate::options::FilterChainOptions;
use crate::texture::D3D11ImageView;
use crate::viewport::Viewport;
use librashader_common::Size;
@ -239,7 +239,7 @@ pub mod d3d11_hello_triangle {
pub device: ID3D11Device,
pub context: ID3D11DeviceContext,
pub resources: Option<Resources>,
pub filter: FilterChainD3D11,
pub filter: FilterChain,
}
pub struct Resources {
@ -266,10 +266,10 @@ pub mod d3d11_hello_triangle {
impl Sample {
pub(crate) fn new(
filter: impl AsRef<Path>,
filter_options: Option<&FilterChainOptionsD3D11>,
filter_options: Option<&FilterChainOptions>,
) -> Result<Self> {
let (dxgi_factory, device, context) = create_device()?;
let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap();
let filter = FilterChain::load_from_path(&device, filter, filter_options).unwrap();
Ok(Sample {
filter,
dxgi_factory,

View file

@ -17,21 +17,21 @@ mod texture;
mod util;
mod viewport;
pub use filter_chain::FilterChainD3D11;
pub use filter_chain::FilterChain;
pub use texture::D3D11ImageView;
pub use viewport::Viewport;
#[cfg(test)]
mod tests {
use super::*;
use crate::options::FilterChainOptionsD3D11;
use crate::options::FilterChainOptions;
#[test]
fn triangle_d3d11() {
let sample = hello_triangle::d3d11_hello_triangle::Sample::new(
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
// "../test/basic.slangp",
Some(&FilterChainOptionsD3D11 {
Some(&FilterChainOptions {
use_deferred_context: false,
force_no_mipmaps: false,
}),

View file

@ -1,7 +1,7 @@
/// Options for each Direct3D11 shader frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FrameOptionsD3D11 {
pub struct FrameOptions {
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of the frame. 1 should be vertical.
@ -11,7 +11,7 @@ pub struct FrameOptionsD3D11 {
/// Options for Direct3D11 filter chain creation.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FilterChainOptionsD3D11 {
pub struct FilterChainOptions {
/// Use a deferred context to record shader rendering state.
///
/// The deferred context will be executed on the immediate context

View file

@ -1,8 +1,8 @@
use crate::FilterChainD3D11;
use crate::FilterChain;
use librashader_runtime::parameters::FilterChainParameters;
use std::collections::hash_map::Iter;
impl FilterChainParameters for FilterChainD3D11 {
impl FilterChainParameters for FilterChain {
fn get_enabled_pass_count(&self) -> usize {
self.common.config.passes_enabled
}

View file

@ -2,7 +2,7 @@ use crate::binding::{GlUniformStorage, UniformLocation, VariableLocation};
use crate::error::FilterChainError;
use crate::filter_pass::FilterPass;
use crate::gl::{DrawQuad, Framebuffer, FramebufferInterface, GLInterface, LoadLut, UboRing};
use crate::options::{FilterChainOptionsGL, FrameOptionsGL};
use crate::options::{FilterChainOptions, FrameOptions};
use crate::render_target::RenderTarget;
use crate::samplers::SamplerSet;
use crate::texture::Texture;
@ -88,20 +88,10 @@ type ShaderPassMeta = (
);
impl<T: GLInterface> FilterChainImpl<T> {
pub(crate) fn create_framebuffer_raw(
&self,
texture: GLuint,
handle: GLuint,
format: GLenum,
size: Size<u32>,
miplevels: u32,
) -> Framebuffer {
T::FramebufferInterface::new_from_raw(texture, handle, format, size, miplevels)
}
/// Load a filter chain from a pre-parsed `ShaderPreset`.
pub(crate) fn load_from_preset(
preset: ShaderPreset,
options: Option<&FilterChainOptionsGL>,
options: Option<&FilterChainOptions>,
) -> error::Result<Self> {
let (passes, semantics) = Self::load_preset(preset.shaders, &preset.textures)?;
@ -431,7 +421,7 @@ impl<T: GLInterface> FilterChainImpl<T> {
count: usize,
viewport: &Viewport,
input: &GLImage,
options: Option<&FrameOptionsGL>,
options: Option<&FrameOptions>,
) -> error::Result<()> {
// limit number of passes to those enabled.
let passes = &mut self.passes[0..self.common.config.passes_enabled];

View file

@ -5,7 +5,7 @@ use std::path::Path;
use crate::error::{FilterChainError, Result};
use crate::filter_chain::filter_impl::FilterChainImpl;
use crate::filter_chain::inner::FilterChainDispatch;
use crate::options::{FilterChainOptionsGL, FrameOptionsGL};
use crate::options::{FilterChainOptions, FrameOptions};
use crate::{Framebuffer, GLImage, Viewport};
use librashader_presets::ShaderPreset;
@ -16,31 +16,14 @@ mod parameters;
pub(crate) use filter_impl::FilterCommon;
use librashader_common::Size;
pub struct FilterChainGL {
pub struct FilterChain {
pub(in crate::filter_chain) filter: FilterChainDispatch,
}
impl FilterChainGL {
pub fn create_framebuffer_raw(
&self,
texture: GLuint,
handle: GLuint,
format: GLenum,
size: Size<u32>,
miplevels: u32,
) -> Framebuffer {
match &self.filter {
FilterChainDispatch::DirectStateAccess(p) => {
p.create_framebuffer_raw(texture, handle, format, size, miplevels)
}
FilterChainDispatch::Compatibility(p) => {
p.create_framebuffer_raw(texture, handle, format, size, miplevels)
}
}
}
impl FilterChain {
pub fn load_from_preset(
preset: ShaderPreset,
options: Option<&FilterChainOptionsGL>,
options: Option<&FilterChainOptions>,
) -> Result<Self> {
let result = catch_unwind(|| {
if let Some(options) = options && options.use_dsa {
@ -63,7 +46,7 @@ impl FilterChainGL {
/// Load the shader preset at the given path into a filter chain.
pub fn load_from_path(
path: impl AsRef<Path>,
options: Option<&FilterChainOptionsGL>,
options: Option<&FilterChainOptions>,
) -> Result<Self> {
// load passes from preset
let preset = ShaderPreset::try_parse(path)?;
@ -72,13 +55,14 @@ impl FilterChainGL {
/// Process a frame with the input image.
///
/// When this frame returns, GL_FRAMEBUFFER is bound to 0 if not using Direct State Access.
pub(crate) fn frame(
/// When this frame returns, `GL_FRAMEBUFFER` is bound to 0 if not using Direct State Access.
/// Otherwise, it is untouched.
pub fn frame(
&mut self,
input: &GLImage,
viewport: &Viewport,
frame_count: usize,
options: Option<&FrameOptionsGL>,
options: Option<&FrameOptions>,
) -> Result<()> {
match &mut self.filter {
FilterChainDispatch::DirectStateAccess(p) => {
@ -88,20 +72,3 @@ impl FilterChainGL {
}
}
}
impl librashader_runtime::filter_chain::FilterChain for FilterChainGL {
type Error = FilterChainError;
type Input<'a> = &'a GLImage;
type Viewport<'a> = Viewport<'a>;
type FrameOptions = FrameOptionsGL;
fn frame<'a>(
&mut self,
input: Self::Input<'a>,
viewport: &Self::Viewport<'a>,
frame_count: usize,
options: Option<&Self::FrameOptions>,
) -> std::result::Result<(), Self::Error> {
self.frame(input, viewport, frame_count, options)
}
}

View file

@ -1,7 +1,7 @@
use crate::filter_chain::filter_impl::FilterChainImpl;
use crate::filter_chain::inner::FilterChainDispatch;
use crate::gl::GLInterface;
use crate::FilterChainGL;
use crate::FilterChain;
use librashader_runtime::parameters::FilterChainParameters;
use std::collections::hash_map::Iter;
@ -23,7 +23,7 @@ impl AsMut<dyn FilterChainParameters + 'static> for FilterChainDispatch {
}
}
impl FilterChainParameters for FilterChainGL {
impl FilterChainParameters for FilterChain {
fn get_enabled_pass_count(&self) -> usize {
self.filter.as_ref().get_enabled_pass_count()
}

View file

@ -9,35 +9,44 @@ use librashader_presets::Scale2D;
#[derive(Debug)]
pub struct Framebuffer {
pub image: GLuint,
pub handle: GLuint,
pub size: Size<u32>,
pub format: GLenum,
pub max_levels: u32,
pub mip_levels: u32,
pub is_raw: bool,
pub(crate) image: GLuint,
pub(crate) handle: GLuint,
pub(crate) size: Size<u32>,
pub(crate) format: GLenum,
pub(crate) max_levels: u32,
pub(crate) mip_levels: u32,
pub(crate) is_raw: bool,
}
impl Framebuffer {
pub fn new<T: FramebufferInterface>(max_levels: u32) -> Self {
pub(crate) fn new<T: FramebufferInterface>(max_levels: u32) -> Self {
T::new(max_levels)
}
pub fn new_from_raw<T: FramebufferInterface>(
/// Create a framebuffer from an already initialized texture and framebuffer.
pub fn new_from_raw(
texture: GLuint,
handle: GLuint,
fbo: GLuint,
format: GLenum,
size: Size<u32>,
mip_levels: u32,
) -> Self {
T::new_from_raw(texture, handle, format, size, mip_levels)
miplevels: u32,
) -> Framebuffer {
Framebuffer {
image: texture,
size,
format,
max_levels: miplevels,
mip_levels: miplevels,
handle: fbo,
is_raw: true,
}
}
pub fn clear<T: FramebufferInterface, const REBIND: bool>(&self) {
pub(crate) fn clear<T: FramebufferInterface, const REBIND: bool>(&self) {
T::clear::<REBIND>(self)
}
pub fn scale<T: FramebufferInterface>(
pub(crate) fn scale<T: FramebufferInterface>(
&mut self,
scaling: Scale2D,
format: ImageFormat,
@ -49,11 +58,11 @@ impl Framebuffer {
T::scale(self, scaling, format, viewport, original, source, mipmap)
}
pub fn copy_from<T: FramebufferInterface>(&mut self, image: &GLImage) -> Result<()> {
pub(crate) fn copy_from<T: FramebufferInterface>(&mut self, image: &GLImage) -> Result<()> {
T::copy_from(self, image)
}
pub fn as_texture(&self, filter: FilterMode, wrap_mode: WrapMode) -> Texture {
pub(crate) fn as_texture(&self, filter: FilterMode, wrap_mode: WrapMode) -> Texture {
Texture {
image: GLImage {
handle: self.image,
@ -70,6 +79,10 @@ impl Framebuffer {
impl Drop for Framebuffer {
fn drop(&mut self) {
if self.is_raw {
return;
}
unsafe {
if self.handle != 0 {
gl::DeleteFramebuffers(1, &self.handle);

View file

@ -34,23 +34,6 @@ impl FramebufferInterface for Gl3Framebuffer {
is_raw: false,
}
}
fn new_from_raw(
texture: GLuint,
handle: GLuint,
format: GLenum,
size: Size<u32>,
miplevels: u32,
) -> Framebuffer {
Framebuffer {
image: texture,
size,
format,
max_levels: miplevels,
mip_levels: miplevels,
handle,
is_raw: true,
}
}
fn scale(
fb: &mut Framebuffer,

View file

@ -7,7 +7,7 @@ use glfw::{Context, Glfw, Window, WindowEvent};
use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
use librashader_common::Size;
use crate::filter_chain::FilterChainGL;
use crate::filter_chain::FilterChain;
use crate::framebuffer::GLImage;
use crate::gl::gl3::CompatibilityGL;
use crate::gl::{FramebufferInterface, GLInterface};
@ -268,7 +268,7 @@ pub fn do_loop(
events: Receiver<(f64, WindowEvent)>,
triangle_program: GLuint,
triangle_vao: GLuint,
filter: &mut FilterChainGL,
filter: &mut FilterChain,
) {
let mut framecount = 0;
let mut rendered_framebuffer = 0;

View file

@ -32,24 +32,7 @@ impl FramebufferInterface for Gl46Framebuffer {
is_raw: false,
}
}
fn new_from_raw(
texture: GLuint,
handle: GLuint,
format: GLenum,
size: Size<u32>,
miplevels: u32,
) -> Framebuffer {
Framebuffer {
image: texture,
size,
format,
max_levels: miplevels,
mip_levels: miplevels,
handle,
is_raw: true,
}
}
fn scale(
fb: &mut Framebuffer,
scaling: Scale2D,

View file

@ -7,7 +7,7 @@ use glfw::{Context, Glfw, Window, WindowEvent};
use gl::types::{GLchar, GLenum, GLint, GLsizei, GLuint};
use librashader_common::Size;
use crate::filter_chain::FilterChainGL;
use crate::filter_chain::FilterChain;
use crate::framebuffer::GLImage;
use crate::gl::gl46::DirectStateAccessGL;
use crate::gl::{FramebufferInterface, GLInterface};
@ -259,7 +259,7 @@ pub fn do_loop(
events: Receiver<(f64, WindowEvent)>,
triangle_program: GLuint,
triangle_vao: GLuint,
filter: &mut FilterChainGL,
filter: &mut FilterChain,
) {
let mut framecount = 0;
let mut rendered_framebuffer = 0;

View file

@ -38,13 +38,6 @@ pub trait UboRing<const SIZE: usize> {
pub trait FramebufferInterface {
fn new(max_levels: u32) -> Framebuffer;
fn new_from_raw(
texture: GLuint,
handle: GLuint,
format: GLenum,
size: Size<u32>,
miplevels: u32,
) -> Framebuffer;
fn scale(
fb: &mut Framebuffer,
scaling: Scale2D,

View file

@ -18,22 +18,22 @@ pub mod options;
mod viewport;
pub use crate::gl::Framebuffer;
pub use filter_chain::FilterChainGL;
pub use filter_chain::FilterChain;
pub use framebuffer::GLImage;
pub use viewport::Viewport;
#[cfg(test)]
mod tests {
use super::*;
use crate::filter_chain::FilterChainGL;
use crate::options::FilterChainOptionsGL;
use crate::filter_chain::FilterChain;
use crate::options::FilterChainOptions;
#[test]
fn triangle_gl() {
let (glfw, window, events, shader, vao) = gl::gl3::hello_triangle::setup();
let mut filter = FilterChainGL::load_from_path(
let mut filter = FilterChain::load_from_path(
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
Some(&FilterChainOptionsGL {
Some(&FilterChainOptions {
gl_version: 0,
use_dsa: false,
force_no_mipmaps: false,
@ -47,10 +47,10 @@ mod tests {
#[test]
fn triangle_gl46() {
let (glfw, window, events, shader, vao) = gl::gl46::hello_triangle::setup();
let mut filter = FilterChainGL::load_from_path(
let mut filter = FilterChain::load_from_path(
// "../test/slang-shaders/vhs/VHSPro.slangp",
"../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",
Some(&FilterChainOptionsGL {
Some(&FilterChainOptions {
gl_version: 0,
use_dsa: true,
force_no_mipmaps: false,

View file

@ -1,7 +1,7 @@
/// Options for each OpenGL shader frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FrameOptionsGL {
pub struct FrameOptions {
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of the frame. 1 should be vertical.
@ -11,7 +11,7 @@ pub struct FrameOptionsGL {
/// Options for filter chain creation.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FilterChainOptionsGL {
pub struct FilterChainOptions {
/// The GLSL version. Should be at least `330`.
pub gl_version: u16,
/// Whether or not to use the Direct State Access APIs. Only available on OpenGL 4.5+.

View file

@ -27,7 +27,7 @@ use librashader_runtime::uniforms::UniformStorage;
use rustc_hash::FxHashMap;
use std::collections::VecDeque;
use std::path::Path;
use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan};
use crate::options::{FilterChainOptions, FrameOptions};
pub struct Vulkan {
pub(crate) device: ash::Device,
@ -44,7 +44,7 @@ type ShaderPassMeta = (
/// A collection of handles needed to access the Vulkan instance.
#[derive(Clone)]
pub struct VulkanInfo {
pub struct VulkanInstance {
/// A `VkDevice` handle.
pub device: vk::Device,
/// A `VkInstance` handle.
@ -55,10 +55,10 @@ pub struct VulkanInfo {
pub get_instance_proc_addr: vk::PFN_vkGetInstanceProcAddr,
}
impl TryFrom<VulkanInfo> for Vulkan {
impl TryFrom<VulkanInstance> for Vulkan {
type Error = FilterChainError;
fn try_from(vulkan: VulkanInfo) -> Result<Self, FilterChainError> {
fn try_from(vulkan: VulkanInstance) -> Result<Self, FilterChainError> {
unsafe {
let instance = ash::Instance::load(
&vk::StaticFn {
@ -179,7 +179,7 @@ impl FilterChainVulkan {
pub fn load_from_path(
vulkan: impl TryInto<Vulkan, Error = FilterChainError>,
path: impl AsRef<Path>,
options: Option<&FilterChainOptionsVulkan>,
options: Option<&FilterChainOptions>,
) -> error::Result<FilterChainVulkan> {
// load passes from preset
let preset = ShaderPreset::try_parse(path)?;
@ -189,7 +189,7 @@ impl FilterChainVulkan {
pub fn load_from_preset(
vulkan: impl TryInto<Vulkan, Error = FilterChainError>,
preset: ShaderPreset,
options: Option<&FilterChainOptionsVulkan>,
options: Option<&FilterChainOptions>,
) -> error::Result<FilterChainVulkan> {
let (passes, semantics) = FilterChainVulkan::load_preset(preset.shaders, &preset.textures)?;
let device = vulkan.try_into()?;
@ -565,7 +565,7 @@ impl FilterChainVulkan {
viewport: &Viewport,
input: &VulkanImage,
cmd: vk::CommandBuffer,
options: Option<FrameOptionsVulkan>,
options: Option<FrameOptions>,
) -> error::Result<FrameIntermediates> {
// limit number of passes to those enabled.
let passes = &mut self.passes[0..self.common.config.passes_enabled];

View file

@ -23,7 +23,7 @@ mod vulkan_state;
pub use filter_chain::FrameIntermediates;
pub use filter_chain::FilterChainVulkan;
pub use filter_chain::Vulkan;
pub use filter_chain::VulkanInfo;
pub use filter_chain::VulkanInstance;
pub use texture::VulkanImage;
pub use viewport::Viewport;

View file

@ -1,7 +1,7 @@
/// Options for each Vulkan shader frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FrameOptionsVulkan {
pub struct FrameOptions {
/// Whether or not to clear the history buffers.
pub clear_history: bool,
/// The direction of the frame. 1 should be vertical.
@ -11,7 +11,7 @@ pub struct FrameOptionsVulkan {
/// Options for filter chain creation.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct FilterChainOptionsVulkan {
pub struct FilterChainOptions {
/// Whether or not to explicitly disable mipmap generation regardless of shader preset settings.
pub force_no_mipmaps: bool,
}

View file

@ -1,30 +0,0 @@
use std::error::Error;
/// Common trait for filter chains.
pub trait FilterChain {
/// The error type for a filter chain.
type Error: Error;
/// The type for the input surface to apply a filter chain to.
type Input<'a>;
/// The type for the output surface, including viewport information, to output the result of a
/// filter chain to.
type Viewport<'a>;
/// The per-frame options to pass to the filter chain.
type FrameOptions;
/// Process a frame with the input image.
///
/// The output image should be written to the viewport. It is expected that the viewport
/// contains some sort of handle with interior mutability to a GPU buffer, e.g. a
/// `RenderTargetView`, `vkImage`, or a texture `GLuint`.
fn frame<'a>(
&mut self,
input: Self::Input<'a>,
viewport: &Self::Viewport<'a>,
frame_count: usize,
options: Option<&Self::FrameOptions>,
) -> Result<(), Self::Error>;
}

View file

@ -13,9 +13,6 @@ pub mod uniforms;
/// Parameter reflection helpers and traits.
pub mod parameters;
/// Filter chain helpers and traits.
pub mod filter_chain;
/// Image handling helpers.
pub mod image;

View file

@ -7,7 +7,7 @@
//!
//! ## Usage
//! The core objects in librashader are the [`ShaderPreset`](crate::presets::ShaderPreset) and the
//! [`FilterChain`](crate::runtime::FilterChain), the implementation of which is runtime dependent.
//! filter chain implementations.
//!
//! The basic workflow involves parsing a `ShaderPreset`, which can then be used to construct
//! a `FilterChain`. All shaders will then be compiled, after which `FilterChain::frame` can be
@ -91,7 +91,6 @@ pub mod reflect {
/// Shader runtimes to execute a filter chain on a GPU surface.
#[cfg(feature = "runtime")]
pub mod runtime {
pub use librashader_runtime::filter_chain::FilterChain;
pub use librashader_runtime::parameters::FilterChainParameters;
#[cfg(feature = "gl")]