diff --git a/Cargo.lock b/Cargo.lock index c63fb92..b115dc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,7 +426,6 @@ name = "librashader-common" version = "0.1.0-alpha.1" dependencies = [ "gl", - "image", "num-traits", "windows", ] @@ -472,6 +471,7 @@ name = "librashader-runtime" version = "0.1.0-alpha.1" dependencies = [ "bytemuck", + "image", "librashader-common", "librashader-preprocess", "librashader-presets", diff --git a/librashader-common/Cargo.toml b/librashader-common/Cargo.toml index 18a917e..7b8ccdc 100644 --- a/librashader-common/Cargo.toml +++ b/librashader-common/Cargo.toml @@ -19,7 +19,6 @@ dxgi = ["windows"] [dependencies] gl = { version = "0.14.0", optional = true } -image = "0.24.5" num-traits = "0.2.15" [dependencies.windows] diff --git a/librashader-common/src/lib.rs b/librashader-common/src/lib.rs index 6222029..7f0b96c 100644 --- a/librashader-common/src/lib.rs +++ b/librashader-common/src/lib.rs @@ -10,9 +10,6 @@ pub mod dxgi; #[cfg(feature = "d3d11")] pub mod d3d11; -/// Image handing helpers. -pub mod image; - use num_traits::AsPrimitive; use std::convert::Infallible; use std::str::FromStr; diff --git a/librashader-presets/src/parse/mod.rs b/librashader-presets/src/parse/mod.rs index f25544e..ee1f0ed 100644 --- a/librashader-presets/src/parse/mod.rs +++ b/librashader-presets/src/parse/mod.rs @@ -20,6 +20,7 @@ pub(crate) fn remove_if(values: &mut Vec, f: impl FnMut(&T) -> bool) -> Op } impl ShaderPreset { + /// Try to parse the shader preset at the given path. pub fn try_parse(path: impl AsRef) -> Result { let values = parse_preset(path)?; Ok(resolve_values(values)) diff --git a/librashader-reflect/Cargo.toml b/librashader-reflect/Cargo.toml index a14e84f..1d93848 100644 --- a/librashader-reflect/Cargo.toml +++ b/librashader-reflect/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["shader", "retroarch", "SPIR-V"] description = "RetroArch shaders for all." [dependencies] -shaderc = { version = "0.8.0" } +shaderc = { version = "0.8.0", features = [] } spirv_cross = { version = "0.23.1", features = [ "glsl", "hlsl" ] } @@ -30,5 +30,6 @@ rspirv-reflect = { git = "https://github.com/Traverse-Research/rspirv-reflect", [features] default = [] unstable-rust-pipeline = [ "naga", "rspirv", "rspirv-reflect" ] +standalone = ["shaderc/build-from-source"] [dev-dependencies] diff --git a/librashader-runtime-d3d11/src/error.rs b/librashader-runtime-d3d11/src/error.rs index d0c8c9c..5ab48b3 100644 --- a/librashader-runtime-d3d11/src/error.rs +++ b/librashader-runtime-d3d11/src/error.rs @@ -1,4 +1,4 @@ -use librashader_common::image::ImageError; +use librashader_runtime::image::ImageError; use librashader_preprocess::PreprocessError; use librashader_presets::ParsePresetError; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index 0d045cd..1007232 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -1,5 +1,5 @@ use crate::texture::{DxImageView, LutTexture, Texture}; -use librashader_common::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, UVDirection}; use librashader_common::{ImageFormat, Size}; use librashader_preprocess::ShaderSource; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; diff --git a/librashader-runtime-d3d11/src/framebuffer.rs b/librashader-runtime-d3d11/src/framebuffer.rs index 610c019..cd96fac 100644 --- a/librashader-runtime-d3d11/src/framebuffer.rs +++ b/librashader-runtime-d3d11/src/framebuffer.rs @@ -5,7 +5,7 @@ use librashader_common::{ImageFormat, Size}; use librashader_presets::Scale2D; use windows::core::Interface; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; -use windows::Win32::Graphics::Direct3D11::{ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Texture2D, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE, D3D11_FORMAT_SUPPORT_RENDER_TARGET, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE, D3D11_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0, D3D11_RTV_DIMENSION_TEXTURE2D, D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV, D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_VIEWPORT, D3D11_RESOURCE_MISC_GENERATE_MIPS, D3D11_BOX, ID3D11DeviceContext}; +use windows::Win32::Graphics::Direct3D11::{ID3D11Device, ID3D11RenderTargetView, ID3D11ShaderResourceView, ID3D11Texture2D, D3D11_BIND_RENDER_TARGET, D3D11_BIND_SHADER_RESOURCE, D3D11_CPU_ACCESS_WRITE, D3D11_FORMAT_SUPPORT_RENDER_TARGET, D3D11_FORMAT_SUPPORT_SHADER_SAMPLE, D3D11_FORMAT_SUPPORT_TEXTURE2D, D3D11_RENDER_TARGET_VIEW_DESC, D3D11_RENDER_TARGET_VIEW_DESC_0, D3D11_RTV_DIMENSION_TEXTURE2D, D3D11_SHADER_RESOURCE_VIEW_DESC, D3D11_SHADER_RESOURCE_VIEW_DESC_0, D3D11_TEX2D_RTV, D3D11_TEX2D_SRV, D3D11_TEXTURE2D_DESC, D3D11_USAGE_DEFAULT, D3D11_VIEWPORT, D3D11_RESOURCE_MISC_GENERATE_MIPS, ID3D11DeviceContext}; use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC}; #[derive(Debug, Clone)] diff --git a/librashader-runtime-d3d11/src/lib.rs b/librashader-runtime-d3d11/src/lib.rs index 032730e..28cec50 100644 --- a/librashader-runtime-d3d11/src/lib.rs +++ b/librashader-runtime-d3d11/src/lib.rs @@ -23,7 +23,6 @@ pub use texture::DxImageView; #[cfg(test)] mod tests { - use crate::options::FilterChainOptions; use super::*; #[test] diff --git a/librashader-runtime-d3d11/src/texture.rs b/librashader-runtime-d3d11/src/texture.rs index acfa41b..5ce604a 100644 --- a/librashader-runtime-d3d11/src/texture.rs +++ b/librashader-runtime-d3d11/src/texture.rs @@ -1,4 +1,4 @@ -use librashader_common::image::Image; +use librashader_runtime::image::Image; use librashader_common::{FilterMode, Size, WrapMode}; use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; use windows::Win32::Graphics::Direct3D11::{ diff --git a/librashader-runtime-gl/src/error.rs b/librashader-runtime-gl/src/error.rs index a970341..254105f 100644 --- a/librashader-runtime-gl/src/error.rs +++ b/librashader-runtime-gl/src/error.rs @@ -1,5 +1,5 @@ use gl::types::GLenum; -use librashader_common::image::ImageError; +use librashader_runtime::image::ImageError; use librashader_preprocess::PreprocessError; use librashader_presets::ParsePresetError; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; diff --git a/librashader-runtime-gl/src/gl/gl3/draw_quad.rs b/librashader-runtime-gl/src/gl/gl3/draw_quad.rs index 61ae562..7ed2a4d 100644 --- a/librashader-runtime-gl/src/gl/gl3/draw_quad.rs +++ b/librashader-runtime-gl/src/gl/gl3/draw_quad.rs @@ -67,10 +67,10 @@ impl DrawQuad for Gl3DrawQuad { fn unbind_vertices(&self) { unsafe { - gl::BindVertexArray(0); - gl::BindBuffer(gl::ARRAY_BUFFER, 0); gl::DisableVertexAttribArray(0); gl::DisableVertexAttribArray(1); + gl::BindVertexArray(0); + gl::BindBuffer(gl::ARRAY_BUFFER, 0); } } } diff --git a/librashader-runtime-gl/src/gl/gl3/lut_load.rs b/librashader-runtime-gl/src/gl/gl3/lut_load.rs index f18bd41..0eff49c 100644 --- a/librashader-runtime-gl/src/gl/gl3/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl3/lut_load.rs @@ -3,7 +3,7 @@ use crate::framebuffer::GLImage; use crate::gl::LoadLut; use crate::texture::Texture; use gl::types::{GLsizei, GLuint}; -use librashader_common::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, UVDirection}; use librashader_common::Size; use librashader_presets::TextureConfig; use rustc_hash::FxHashMap; diff --git a/librashader-runtime-gl/src/gl/gl46/lut_load.rs b/librashader-runtime-gl/src/gl/gl46/lut_load.rs index 2f65076..01617c4 100644 --- a/librashader-runtime-gl/src/gl/gl46/lut_load.rs +++ b/librashader-runtime-gl/src/gl/gl46/lut_load.rs @@ -3,7 +3,7 @@ use crate::framebuffer::GLImage; use crate::gl::LoadLut; use crate::texture::Texture; use gl::types::{GLsizei, GLuint}; -use librashader_common::image::{Image, UVDirection}; +use librashader_runtime::image::{Image, UVDirection}; use librashader_common::Size; use librashader_presets::TextureConfig; use rustc_hash::FxHashMap; diff --git a/librashader-runtime/Cargo.toml b/librashader-runtime/Cargo.toml index 11dca02..99cf806 100644 --- a/librashader-runtime/Cargo.toml +++ b/librashader-runtime/Cargo.toml @@ -19,3 +19,4 @@ librashader-reflect = { path = "../librashader-reflect", version = "0.1.0-alpha. bytemuck = "1.12.3" rustc-hash = "1.1.0" num-traits = "0.2.15" +image = "0.24.5" diff --git a/librashader-common/src/image.rs b/librashader-runtime/src/image.rs similarity index 74% rename from librashader-common/src/image.rs rename to librashader-runtime/src/image.rs index a01dfec..af20495 100644 --- a/librashader-common/src/image.rs +++ b/librashader-runtime/src/image.rs @@ -1,3 +1,6 @@ +use librashader_common::Size; +pub use image::ImageError; + use std::path::Path; pub struct Image { @@ -6,16 +9,21 @@ pub struct Image { pub pitch: usize, } +/// The direction of UV coordinates to load the image for. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum UVDirection { + /// Origin is at the top left (Direct3D, Vulkan) TopLeft, + /// Origin is at the bottom left (OpenGL) BottomLeft, } + impl Image { + /// Load the image from the path as RGBA8. pub fn load(path: impl AsRef, direction: UVDirection) -> Result { let mut image = image::open(path.as_ref())?; - if direction == BottomLeft { + if direction == UVDirection::BottomLeft { image = image.flipv(); } @@ -35,7 +43,3 @@ impl Image { }) } } - -use crate::Size; -pub use image::ImageError; -use crate::image::UVDirection::BottomLeft; diff --git a/librashader-runtime/src/lib.rs b/librashader-runtime/src/lib.rs index 8bd48ff..93cf8a8 100644 --- a/librashader-runtime/src/lib.rs +++ b/librashader-runtime/src/lib.rs @@ -14,3 +14,6 @@ pub mod parameters; /// Filter chain helpers and traits. pub mod filter_chain; + +/// Image handling helpers. +pub mod image;