From 45d03fbfb8345007197171f1363fa10d0fc7abe0 Mon Sep 17 00:00:00 2001 From: chyyran Date: Fri, 13 Jan 2023 16:55:50 -0500 Subject: [PATCH] capi: resolve name conflicts due to conflicting struct names in each module --- librashader-capi/src/ctypes.rs | 4 +- .../src/runtime/d3d11/filter_chain.rs | 10 ++-- .../src/runtime/gl/filter_chain.rs | 10 ++-- librashader-runtime-d3d11/src/filter_chain.rs | 32 +++++------ .../src/hello_triangle.rs | 10 ++-- librashader-runtime-d3d11/src/lib.rs | 6 +- librashader-runtime-d3d11/src/options.rs | 4 +- librashader-runtime-d3d11/src/parameters.rs | 4 +- .../src/filter_chain/filter_impl.rs | 10 ++-- .../src/filter_chain/mod.rs | 16 +++--- .../src/filter_chain/parameters.rs | 4 +- .../src/gl/gl3/hello_triangle.rs | 4 +- .../src/gl/gl46/hello_triangle.rs | 4 +- librashader-runtime-gl/src/lib.rs | 14 ++--- librashader-runtime-gl/src/options.rs | 4 +- librashader-runtime-vk/src/filter_chain.rs | 24 ++++---- .../src/hello_triangle/mod.rs | 8 +-- librashader-runtime-vk/src/lib.rs | 6 +- librashader-runtime-vk/src/options.rs | 4 +- librashader-runtime-vk/src/parameters.rs | 4 +- librashader/src/lib.rs | 57 ++++++++++++++++++- 21 files changed, 145 insertions(+), 94 deletions(-) diff --git a/librashader-capi/src/ctypes.rs b/librashader-capi/src/ctypes.rs index 96810d3..d9b8f2f 100644 --- a/librashader-capi/src/ctypes.rs +++ b/librashader-capi/src/ctypes.rs @@ -7,11 +7,11 @@ pub type libra_shader_preset_t = Option>; pub type libra_error_t = Option>; #[cfg(feature = "runtime-opengl")] -pub type libra_gl_filter_chain_t = Option>; +pub type libra_gl_filter_chain_t = Option>; #[cfg(feature = "runtime-d3d11")] pub type libra_d3d11_filter_chain_t = - Option>; + Option>; /// Parameters for the output viewport. #[repr(C)] diff --git a/librashader-capi/src/runtime/d3d11/filter_chain.rs b/librashader-capi/src/runtime/d3d11/filter_chain.rs index 2f8f5ef..8347569 100644 --- a/librashader-capi/src/runtime/d3d11/filter_chain.rs +++ b/librashader-capi/src/runtime/d3d11/filter_chain.rs @@ -11,8 +11,8 @@ use windows::Win32::Graphics::Direct3D11::{ ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, }; -pub use librashader::runtime::d3d11::options::FilterChainOptions; -pub use librashader::runtime::d3d11::options::FrameOptions; +pub use librashader::runtime::d3d11::capi::options::FilterChainOptionsD3D11; +pub use librashader::runtime::d3d11::capi::options::FrameOptionsD3D11; use librashader::runtime::{Size, Viewport}; @@ -53,7 +53,7 @@ extern_fn! { /// - `out` must be aligned, but may be null, invalid, or uninitialized. fn libra_d3d11_filter_chain_create( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptions, + options: *const FilterChainOptionsD3D11, device: *const ID3D11Device, out: *mut MaybeUninit ) { @@ -71,7 +71,7 @@ extern_fn! { Some(unsafe { &*options }) }; - let chain = librashader::runtime::d3d11::FilterChain::load_from_preset( + let chain = librashader::runtime::d3d11::capi::FilterChainD3D11::load_from_preset( unsafe { &*device }, *preset, options, @@ -102,7 +102,7 @@ extern_fn! { viewport: libra_viewport_t, out: *const ID3D11RenderTargetView, mvp: *const f32, - opt: *const FrameOptions + opt: *const FrameOptionsD3D11 ) mut |chain| { assert_some_ptr!(mut chain); assert_non_null!(out); diff --git a/librashader-capi/src/runtime/gl/filter_chain.rs b/librashader-capi/src/runtime/gl/filter_chain.rs index 08599d7..df6b99d 100644 --- a/librashader-capi/src/runtime/gl/filter_chain.rs +++ b/librashader-capi/src/runtime/gl/filter_chain.rs @@ -9,8 +9,8 @@ use std::mem::MaybeUninit; use std::ptr::NonNull; use std::slice; -pub use librashader::runtime::gl::options::FilterChainOptions; -pub use librashader::runtime::gl::options::FrameOptions; +pub use librashader::runtime::gl::capi::options::FilterChainOptionsGL; +pub use librashader::runtime::gl::capi::options::FrameOptionsGL; use librashader::runtime::{Size, Viewport}; /// A GL function loader that librashader needs to be initialized with. @@ -81,7 +81,7 @@ extern_fn! { /// - `out` must be aligned, but may be null, invalid, or uninitialized. fn libra_gl_filter_chain_create( preset: *mut libra_shader_preset_t, - options: *const FilterChainOptions, + options: *const FilterChainOptionsGL, out: *mut MaybeUninit ) { assert_non_null!(preset); @@ -97,7 +97,7 @@ extern_fn! { Some(unsafe { &*options }) }; - let chain = librashader::runtime::gl::FilterChain::load_from_preset(*preset, options)?; + let chain = librashader::runtime::gl::capi::FilterChainGL::load_from_preset(*preset, options)?; unsafe { out.write(MaybeUninit::new(NonNull::new(Box::into_raw(Box::new( @@ -124,7 +124,7 @@ extern_fn! { viewport: libra_viewport_t, out: libra_draw_framebuffer_gl_t, mvp: *const f32, - opt: *const FrameOptions + opt: *const FrameOptionsGL ) mut |chain| { assert_some_ptr!(mut chain); let image: GLImage = image.into(); diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 616edd9..255be81 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -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::{FilterChainOptions, FrameOptions}; +use crate::options::{FilterChainOptionsD3D11, FrameOptionsD3D11}; use crate::quad_render::DrawQuad; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; @@ -47,7 +47,7 @@ type ShaderPassMeta = ( ); /// A Direct3D 11 filter chain. -pub struct FilterChain { +pub struct FilterChainD3D11 { pub(crate) common: FilterCommon, pub(crate) passes: Vec, pub(crate) output_framebuffers: Box<[OwnedFramebuffer]>, @@ -74,13 +74,13 @@ pub(crate) struct FilterCommon { pub disable_mipmaps: bool, } -impl FilterChain { +impl FilterChainD3D11 { /// Load the shader preset at the given path into a filter chain. pub fn load_from_path( device: &ID3D11Device, path: impl AsRef, - options: Option<&FilterChainOptions>, - ) -> error::Result { + options: Option<&FilterChainOptionsD3D11>, + ) -> error::Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; Self::load_from_preset(device, preset, options) @@ -90,16 +90,16 @@ impl FilterChain { pub fn load_from_preset( device: &ID3D11Device, preset: ShaderPreset, - options: Option<&FilterChainOptions>, - ) -> error::Result { - let (passes, semantics) = FilterChain::load_preset(preset.shaders, &preset.textures)?; + options: Option<&FilterChainOptionsD3D11>, + ) -> error::Result { + let (passes, semantics) = FilterChainD3D11::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 = FilterChain::init_passes(device, passes, &semantics)?; + let filters = FilterChainD3D11::init_passes(device, passes, &semantics)?; let mut immediate_context = None; unsafe { @@ -154,15 +154,15 @@ impl FilterChain { feedback_textures.resize_with(filters.len(), || None); // load luts - let luts = FilterChain::load_luts(device, ¤t_context, &preset.textures)?; + let luts = FilterChainD3D11::load_luts(device, ¤t_context, &preset.textures)?; let (history_framebuffers, history_textures) = - FilterChain::init_history(device, ¤t_context, &filters)?; + FilterChainD3D11::init_history(device, ¤t_context, &filters)?; let draw_quad = DrawQuad::new(device, ¤t_context)?; // todo: make vbo: d3d11.c 1376 - Ok(FilterChain { + Ok(FilterChainD3D11 { passes: filters, output_framebuffers: output_framebuffers.into_boxed_slice(), feedback_framebuffers: feedback_framebuffers.into_boxed_slice(), @@ -194,7 +194,7 @@ impl FilterChain { } } -impl FilterChain { +impl FilterChainD3D11 { fn create_constant_buffer(device: &ID3D11Device, size: u32) -> error::Result { unsafe { let buffer = device.CreateBuffer( @@ -247,7 +247,7 @@ impl FilterChain { )?; let ubo_cbuffer = if let Some(ubo) = &reflection.ubo && ubo.size != 0 { - let buffer = FilterChain::create_constant_buffer(device, ubo.size)?; + let buffer = FilterChainD3D11::create_constant_buffer(device, ubo.size)?; Some(ConstantBufferBinding { binding: ubo.binding, size: ubo.size, @@ -259,7 +259,7 @@ impl FilterChain { }; let push_cbuffer = if let Some(push) = &reflection.push_constant && push.size != 0 { - let buffer = FilterChain::create_constant_buffer(device, push.size)?; + let buffer = FilterChainD3D11::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 FilterChain { input: D3D11InputView, viewport: &Viewport, frame_count: usize, - options: Option<&FrameOptions>, + options: Option<&FrameOptionsD3D11>, ) -> error::Result<()> { let passes = &mut self.passes[0..self.common.config.passes_enabled]; if let Some(options) = options { diff --git a/librashader-runtime-d3d11/src/hello_triangle.rs b/librashader-runtime-d3d11/src/hello_triangle.rs index 7f76b2c..e99442d 100644 --- a/librashader-runtime-d3d11/src/hello_triangle.rs +++ b/librashader-runtime-d3d11/src/hello_triangle.rs @@ -225,9 +225,9 @@ pub mod d3d11_hello_triangle { use super::*; use std::path::Path; - use crate::filter_chain::FilterChain; + use crate::filter_chain::FilterChainD3D11; - use crate::options::FilterChainOptions; + use crate::options::FilterChainOptionsD3D11; use crate::texture::D3D11InputView; use crate::viewport::Viewport; use librashader_common::{Size, Viewport}; @@ -240,7 +240,7 @@ pub mod d3d11_hello_triangle { pub device: ID3D11Device, pub context: ID3D11DeviceContext, pub resources: Option, - pub filter: FilterChain, + pub filter: FilterChainD3D11, } pub struct Resources { @@ -267,10 +267,10 @@ pub mod d3d11_hello_triangle { impl Sample { pub(crate) fn new( filter: impl AsRef, - filter_options: Option<&FilterChainOptions>, + filter_options: Option<&FilterChainOptionsD3D11>, ) -> Result { let (dxgi_factory, device, context) = create_device()?; - let filter = FilterChain::load_from_path(&device, filter, filter_options).unwrap(); + let filter = FilterChainD3D11::load_from_path(&device, filter, filter_options).unwrap(); Ok(Sample { filter, dxgi_factory, diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 86add14..ee0c180 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -16,21 +16,21 @@ mod samplers; mod texture; mod util; -pub use filter_chain::FilterChain; +pub use filter_chain::FilterChainD3D11; pub use texture::D3D11InputView; pub use texture::D3D11OutputView; #[cfg(test)] mod tests { use super::*; - use crate::options::FilterChainOptions; + use crate::options::FilterChainOptionsD3D11; #[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(&FilterChainOptions { + Some(&FilterChainOptionsD3D11 { use_deferred_context: false, force_no_mipmaps: false, }), diff --git a/librashader-runtime-d3d11/src/options.rs b/librashader-runtime-d3d11/src/options.rs index aa0c7de..db7a6a9 100644 --- a/librashader-runtime-d3d11/src/options.rs +++ b/librashader-runtime-d3d11/src/options.rs @@ -3,7 +3,7 @@ /// Options for each Direct3D11 shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptions { +pub struct FrameOptionsD3D11 { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -13,7 +13,7 @@ pub struct FrameOptions { /// Options for Direct3D11 filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptions { +pub struct FilterChainOptionsD3D11 { /// Use a deferred context to record shader rendering state. /// /// The deferred context will be executed on the immediate context diff --git a/librashader-runtime-d3d11/src/parameters.rs b/librashader-runtime-d3d11/src/parameters.rs index 9211f6c..f2e1b92 100644 --- a/librashader-runtime-d3d11/src/parameters.rs +++ b/librashader-runtime-d3d11/src/parameters.rs @@ -1,8 +1,8 @@ -use crate::FilterChain; +use crate::FilterChainD3D11; use librashader_runtime::parameters::FilterChainParameters; use std::collections::hash_map::Iter; -impl FilterChainParameters for FilterChain { +impl FilterChainParameters for FilterChainD3D11 { fn get_enabled_pass_count(&self) -> usize { self.common.config.passes_enabled } diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index cefa2e6..ae7bd49 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -2,14 +2,14 @@ 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::{FilterChainOptions, FrameOptions}; +use crate::options::{FilterChainOptionsGL, FrameOptionsGL}; use crate::render_target::RenderTarget; use crate::samplers::SamplerSet; use crate::texture::Texture; use crate::util::{gl_get_version, gl_u16_to_version}; use crate::{error, util, GLImage}; -use gl::types::{GLenum, GLint, GLuint}; -use librashader_common::{FilterMode, Size, Viewport, WrapMode}; +use gl::types::{GLint, GLuint}; +use librashader_common::{FilterMode, Viewport, WrapMode}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_reflect::back::cross::{CrossGlslContext, GlslVersion}; @@ -91,7 +91,7 @@ impl FilterChainImpl { /// Load a filter chain from a pre-parsed `ShaderPreset`. pub(crate) fn load_from_preset( preset: ShaderPreset, - options: Option<&FilterChainOptions>, + options: Option<&FilterChainOptionsGL>, ) -> error::Result { let (passes, semantics) = Self::load_preset(preset.shaders, &preset.textures)?; @@ -421,7 +421,7 @@ impl FilterChainImpl { count: usize, viewport: &Viewport<&Framebuffer>, input: &GLImage, - options: Option<&FrameOptions>, + options: Option<&FrameOptionsGL>, ) -> error::Result<()> { // limit number of passes to those enabled. let passes = &mut self.passes[0..self.common.config.passes_enabled]; diff --git a/librashader-runtime-gl/src/filter_chain/mod.rs b/librashader-runtime-gl/src/filter_chain/mod.rs index 0078d64..569977f 100644 --- a/librashader-runtime-gl/src/filter_chain/mod.rs +++ b/librashader-runtime-gl/src/filter_chain/mod.rs @@ -1,11 +1,11 @@ -use gl::types::{GLenum, GLuint}; + use std::panic::catch_unwind; 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::{FilterChainOptions, FrameOptions}; +use crate::options::{FilterChainOptionsGL, FrameOptionsGL}; use crate::{Framebuffer, GLImage}; use librashader_presets::ShaderPreset; @@ -14,18 +14,18 @@ mod inner; mod parameters; pub(crate) use filter_impl::FilterCommon; -use librashader_common::{Size, Viewport}; +use librashader_common::{Viewport}; /// An OpenGL filter chain. -pub struct FilterChain { +pub struct FilterChainGL { pub(in crate::filter_chain) filter: FilterChainDispatch, } -impl FilterChain { +impl FilterChainGL { /// Load a filter chain from a pre-parsed `ShaderPreset`. pub fn load_from_preset( preset: ShaderPreset, - options: Option<&FilterChainOptions>, + options: Option<&FilterChainOptionsGL>, ) -> Result { let result = catch_unwind(|| { if let Some(options) = options && options.use_dsa { @@ -48,7 +48,7 @@ impl FilterChain { /// Load the shader preset at the given path into a filter chain. pub fn load_from_path( path: impl AsRef, - options: Option<&FilterChainOptions>, + options: Option<&FilterChainOptionsGL>, ) -> Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; @@ -64,7 +64,7 @@ impl FilterChain { input: &GLImage, viewport: &Viewport<&Framebuffer>, frame_count: usize, - options: Option<&FrameOptions>, + options: Option<&FrameOptionsGL>, ) -> Result<()> { match &mut self.filter { FilterChainDispatch::DirectStateAccess(p) => { diff --git a/librashader-runtime-gl/src/filter_chain/parameters.rs b/librashader-runtime-gl/src/filter_chain/parameters.rs index 4eba994..670aee6 100644 --- a/librashader-runtime-gl/src/filter_chain/parameters.rs +++ b/librashader-runtime-gl/src/filter_chain/parameters.rs @@ -1,7 +1,7 @@ use crate::filter_chain::filter_impl::FilterChainImpl; use crate::filter_chain::inner::FilterChainDispatch; use crate::gl::GLInterface; -use crate::FilterChain; +use crate::FilterChainGL; use librashader_runtime::parameters::FilterChainParameters; use std::collections::hash_map::Iter; @@ -23,7 +23,7 @@ impl AsMut for FilterChainDispatch { } } -impl FilterChainParameters for FilterChain { +impl FilterChainParameters for FilterChainGL { fn get_enabled_pass_count(&self) -> usize { self.filter.as_ref().get_enabled_pass_count() } diff --git a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs index 51c494f..7df8ee2 100644 --- a/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl3/hello_triangle.rs @@ -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::FilterChain; +use crate::filter_chain::FilterChainGL; 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 FilterChain, + filter: &mut FilterChainGL, ) { let mut framecount = 0; let mut rendered_framebuffer = 0; diff --git a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs index 5fae0c1..7b89075 100644 --- a/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs +++ b/librashader-runtime-gl/src/gl/gl46/hello_triangle.rs @@ -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::FilterChain; +use crate::filter_chain::FilterChainGL; 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 FilterChain, + filter: &mut FilterChainGL, ) { let mut framecount = 0; let mut rendered_framebuffer = 0; diff --git a/librashader-runtime-gl/src/lib.rs b/librashader-runtime-gl/src/lib.rs index ecc9452..5f27a70 100644 --- a/librashader-runtime-gl/src/lib.rs +++ b/librashader-runtime-gl/src/lib.rs @@ -17,21 +17,21 @@ pub mod error; pub mod options; pub use crate::gl::Framebuffer; -pub use filter_chain::FilterChain; +pub use filter_chain::FilterChainGL; pub use framebuffer::GLImage; #[cfg(test)] mod tests { use super::*; - use crate::filter_chain::FilterChain; - use crate::options::FilterChainOptions; + use crate::filter_chain::FilterChainGL; + use crate::options::FilterChainOptionsGL; #[test] fn triangle_gl() { let (glfw, window, events, shader, vao) = gl::gl3::hello_triangle::setup(); - let mut filter = FilterChain::load_from_path( + let mut filter = FilterChainGL::load_from_path( "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - Some(&FilterChainOptions { + Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: false, force_no_mipmaps: false, @@ -45,10 +45,10 @@ mod tests { #[test] fn triangle_gl46() { let (glfw, window, events, shader, vao) = gl::gl46::hello_triangle::setup(); - let mut filter = FilterChain::load_from_path( + let mut filter = FilterChainGL::load_from_path( // "../test/slang-shaders/vhs/VHSPro.slangp", "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", - Some(&FilterChainOptions { + Some(&FilterChainOptionsGL { gl_version: 0, use_dsa: true, force_no_mipmaps: false, diff --git a/librashader-runtime-gl/src/options.rs b/librashader-runtime-gl/src/options.rs index 1a06844..084d964 100644 --- a/librashader-runtime-gl/src/options.rs +++ b/librashader-runtime-gl/src/options.rs @@ -3,7 +3,7 @@ /// Options for each OpenGL shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptions { +pub struct FrameOptionsGL { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -13,7 +13,7 @@ pub struct FrameOptions { /// Options for filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptions { +pub struct FilterChainOptionsGL { /// 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+. diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index a42ce49..ee7492a 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -26,7 +26,7 @@ use librashader_runtime::uniforms::UniformStorage; use rustc_hash::FxHashMap; use std::collections::VecDeque; use std::path::Path; -use crate::options::{FilterChainOptions, FrameOptions}; +use crate::options::{FilterChainOptionsVulkan, FrameOptionsVulkan}; /// A Vulkan device and metadata that is required by the shader runtime. pub struct VulkanDevice { @@ -112,7 +112,7 @@ impl TryFrom<(vk::PhysicalDevice, ash::Instance, ash::Device)> for VulkanDevice } /// A Vulkan filter chain. -pub struct FilterChain { +pub struct FilterChainVulkan { pub(crate) common: FilterCommon, passes: Box<[FilterPass]>, vulkan: VulkanDevice, @@ -188,13 +188,13 @@ impl Drop for FrameResiduals { } } -impl FilterChain { +impl FilterChainVulkan { /// Load the shader preset at the given path into a filter chain. pub fn load_from_path( vulkan: impl TryInto, path: impl AsRef, - options: Option<&FilterChainOptions>, - ) -> error::Result { + options: Option<&FilterChainOptionsVulkan>, + ) -> error::Result { // load passes from preset let preset = ShaderPreset::try_parse(path)?; Self::load_from_preset(vulkan, preset, options) @@ -204,9 +204,9 @@ impl FilterChain { pub fn load_from_preset( vulkan: impl TryInto, preset: ShaderPreset, - options: Option<&FilterChainOptions>, - ) -> error::Result { - let (passes, semantics) = FilterChain::load_preset(preset.shaders, &preset.textures)?; + options: Option<&FilterChainOptionsVulkan>, + ) -> error::Result { + let (passes, semantics) = FilterChainVulkan::load_preset(preset.shaders, &preset.textures)?; let device = vulkan.try_into()?; let mut frames_in_flight = options.map(|o| o.frames_in_flight).unwrap_or(0); @@ -217,11 +217,11 @@ impl FilterChain { // initialize passes let filters = Self::init_passes(&device, passes, &semantics, frames_in_flight)?; - let luts = FilterChain::load_luts(&device, &preset.textures)?; + let luts = FilterChainVulkan::load_luts(&device, &preset.textures)?; let samplers = SamplerSet::new(&device.device)?; let (history_framebuffers, history_textures) = - FilterChain::init_history(&device, &filters)?; + FilterChainVulkan::init_history(&device, &filters)?; let mut output_framebuffers = Vec::new(); output_framebuffers.resize_with(filters.len(), || { @@ -246,7 +246,7 @@ impl FilterChain { let mut intermediates = Vec::new(); intermediates.resize_with(frames_in_flight as usize, || FrameResiduals::new(&device.device)); - Ok(FilterChain { + Ok(FilterChainVulkan { common: FilterCommon { luts, samplers, @@ -584,7 +584,7 @@ impl FilterChain { viewport: &Viewport, input: &VulkanImage, cmd: vk::CommandBuffer, - options: Option, + options: Option, ) -> error::Result<()> { let intermediates = &mut self.residuals[count % self.residuals.len()]; intermediates.dispose(); diff --git a/librashader-runtime-vk/src/hello_triangle/mod.rs b/librashader-runtime-vk/src/hello_triangle/mod.rs index 7f81901..9362d10 100644 --- a/librashader-runtime-vk/src/hello_triangle/mod.rs +++ b/librashader-runtime-vk/src/hello_triangle/mod.rs @@ -8,7 +8,7 @@ mod swapchain; mod syncobjects; pub mod vulkan_base; -use crate::filter_chain::{FilterChain, VulkanDevice}; +use crate::filter_chain::{FilterChainVulkan, VulkanDevice}; use crate::hello_triangle::command::VulkanCommandPool; use crate::hello_triangle::framebuffer::VulkanFramebuffer; use crate::hello_triangle::pipeline::VulkanPipeline; @@ -48,7 +48,7 @@ impl VulkanWindow { event_loop: EventLoop<()>, window: winit::window::Window, vulkan: VulkanDraw, - mut filter_chain: FilterChain, + mut filter_chain: FilterChainVulkan, ) { let mut counter = 0; event_loop.run(move |event, _, control_flow| match event { @@ -136,7 +136,7 @@ impl VulkanWindow { vulkan.base.device.cmd_end_render_pass(cmd); } - fn draw_frame(frame: usize, vulkan: &VulkanDraw, filter: &mut FilterChain) { + fn draw_frame(frame: usize, vulkan: &VulkanDraw, filter: &mut FilterChainVulkan) { let index = frame % MAX_FRAMES_IN_FLIGHT; let in_flight = [vulkan.sync.in_flight[index]]; let image_available = [vulkan.sync.image_available[index]]; @@ -370,7 +370,7 @@ pub struct VulkanDraw { pub sync: SyncObjects, } -pub fn main(vulkan: VulkanBase, filter_chain: FilterChain) { +pub fn main(vulkan: VulkanBase, filter_chain: FilterChainVulkan) { let event_loop = EventLoopBuilder::new() .with_any_thread(true) .with_dpi_aware(true) diff --git a/librashader-runtime-vk/src/lib.rs b/librashader-runtime-vk/src/lib.rs index 3a57aca..2362094 100644 --- a/librashader-runtime-vk/src/lib.rs +++ b/librashader-runtime-vk/src/lib.rs @@ -19,7 +19,7 @@ mod util; mod vulkan_primitives; mod vulkan_state; -pub use filter_chain::FilterChain; +pub use filter_chain::FilterChainVulkan; pub use filter_chain::VulkanDevice; pub use filter_chain::VulkanInstance; pub use texture::VulkanImage; @@ -30,7 +30,7 @@ pub mod options; #[cfg(test)] mod tests { use super::*; - use crate::filter_chain::FilterChain; + use crate::filter_chain::FilterChainVulkan; use crate::hello_triangle::vulkan_base::VulkanBase; #[test] @@ -38,7 +38,7 @@ mod tests { let entry = unsafe { ash::Entry::load().unwrap() }; let base = VulkanBase::new(entry).unwrap(); dbg!("finished"); - let mut filter = FilterChain::load_from_path( + let mut filter = FilterChainVulkan::load_from_path( &base, // "../test/slang-shaders/border/gameboy-player/gameboy-player-crt-royale.slangp", "../test/slang-shaders/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", diff --git a/librashader-runtime-vk/src/options.rs b/librashader-runtime-vk/src/options.rs index 87f0733..8d9db85 100644 --- a/librashader-runtime-vk/src/options.rs +++ b/librashader-runtime-vk/src/options.rs @@ -3,7 +3,7 @@ /// Options for each Vulkan shader frame. #[repr(C)] #[derive(Debug, Clone)] -pub struct FrameOptions { +pub struct FrameOptionsVulkan { /// Whether or not to clear the history buffers. pub clear_history: bool, /// The direction of the frame. 1 should be vertical. @@ -13,7 +13,7 @@ pub struct FrameOptions { /// Options for filter chain creation. #[repr(C)] #[derive(Debug, Clone)] -pub struct FilterChainOptions { +pub struct FilterChainOptionsVulkan { /// The number of frames in flight to keep. If zero, defaults to three. pub frames_in_flight: u32, /// Whether or not to explicitly disable mipmap generation regardless of shader preset settings. diff --git a/librashader-runtime-vk/src/parameters.rs b/librashader-runtime-vk/src/parameters.rs index 9211f6c..8f36634 100644 --- a/librashader-runtime-vk/src/parameters.rs +++ b/librashader-runtime-vk/src/parameters.rs @@ -1,8 +1,8 @@ -use crate::FilterChain; +use crate::FilterChainVulkan; use librashader_runtime::parameters::FilterChainParameters; use std::collections::hash_map::Iter; -impl FilterChainParameters for FilterChain { +impl FilterChainParameters for FilterChainVulkan { fn get_enabled_pass_count(&self) -> usize { self.common.config.passes_enabled } diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 772a762..faf332d 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -100,22 +100,73 @@ pub mod runtime { /// Note that the OpenGL runtime requires `gl` to be /// initialized with [`gl::load_with`](https://docs.rs/gl/0.14.0/gl/fn.load_with.html). pub mod gl { - pub use librashader_runtime_gl::*; + pub use librashader_runtime_gl::{ + options::{ + FilterChainOptionsGL as FilterChainOptions, + FrameOptionsGL as FrameOptions, + }, + FilterChainGL as FilterChain, + Framebuffer, GLImage, + error + }; + + #[doc(hidden)] + /// Re-exports names to deal with C API conflicts. + /// + /// This is internal to librashader-capi and is exempt from semantic versioning. + pub mod capi { + pub use librashader_runtime_gl::*; + } } #[cfg(feature = "d3d11")] /// Shader runtime for Direct3D 11. pub mod d3d11 { - pub use librashader_runtime_d3d11::*; + pub use librashader_runtime_d3d11::{ + options::{ + FilterChainOptionsD3D11 as FilterChainOptions, + FrameOptionsD3D11 as FrameOptions, + }, + FilterChainD3D11 as FilterChain, + D3D11InputView, D3D11OutputView, + error + }; + + #[doc(hidden)] + /// Re-exports names to deal with C API conflicts. + /// + /// This is internal to librashader-capi and is exempt from semantic versioning. + pub mod capi { + pub use librashader_runtime_d3d11::*; + } } #[cfg(feature = "vk")] /// Shader runtime for Vulkan 1.3+. pub mod vk { - pub use librashader_runtime_vk::*; + pub use librashader_runtime_vk::{ + options::{ + FilterChainOptionsVulkan as FilterChainOptions, + FrameOptionsVulkan as FrameOptions, + }, + FilterChainVulkan as FilterChain, + VulkanImage, VulkanDevice, VulkanInstance, + error + }; + + #[doc(hidden)] + /// Re-exports names to deal with C API conflicts. + /// + /// This is internal to librashader-capi and is exempt from semantic versioning. + pub mod capi { + pub use librashader_runtime_vk::*; + } } #[doc(hidden)] + /// Helper methods for runtimes. + /// + /// This is internal to librashader runtimes and is exempt from semantic versioning. pub mod helper { pub use librashader_runtime::semantics::insert_lut_semantics; pub use librashader_runtime::semantics::insert_pass_semantics;