rt: move image into runtime

This commit is contained in:
chyyran 2022-12-01 17:11:42 -05:00
parent ba41055a58
commit 1665770615
17 changed files with 26 additions and 21 deletions

2
Cargo.lock generated
View file

@ -426,7 +426,6 @@ name = "librashader-common"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.1"
dependencies = [ dependencies = [
"gl", "gl",
"image",
"num-traits", "num-traits",
"windows", "windows",
] ]
@ -472,6 +471,7 @@ name = "librashader-runtime"
version = "0.1.0-alpha.1" version = "0.1.0-alpha.1"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"image",
"librashader-common", "librashader-common",
"librashader-preprocess", "librashader-preprocess",
"librashader-presets", "librashader-presets",

View file

@ -19,7 +19,6 @@ dxgi = ["windows"]
[dependencies] [dependencies]
gl = { version = "0.14.0", optional = true } gl = { version = "0.14.0", optional = true }
image = "0.24.5"
num-traits = "0.2.15" num-traits = "0.2.15"
[dependencies.windows] [dependencies.windows]

View file

@ -10,9 +10,6 @@ pub mod dxgi;
#[cfg(feature = "d3d11")] #[cfg(feature = "d3d11")]
pub mod d3d11; pub mod d3d11;
/// Image handing helpers.
pub mod image;
use num_traits::AsPrimitive; use num_traits::AsPrimitive;
use std::convert::Infallible; use std::convert::Infallible;
use std::str::FromStr; use std::str::FromStr;

View file

@ -20,6 +20,7 @@ pub(crate) fn remove_if<T>(values: &mut Vec<T>, f: impl FnMut(&T) -> bool) -> Op
} }
impl ShaderPreset { impl ShaderPreset {
/// Try to parse the shader preset at the given path.
pub fn try_parse(path: impl AsRef<Path>) -> Result<ShaderPreset, ParsePresetError> { pub fn try_parse(path: impl AsRef<Path>) -> Result<ShaderPreset, ParsePresetError> {
let values = parse_preset(path)?; let values = parse_preset(path)?;
Ok(resolve_values(values)) Ok(resolve_values(values))

View file

@ -12,7 +12,7 @@ keywords = ["shader", "retroarch", "SPIR-V"]
description = "RetroArch shaders for all." description = "RetroArch shaders for all."
[dependencies] [dependencies]
shaderc = { version = "0.8.0" } shaderc = { version = "0.8.0", features = [] }
spirv_cross = { version = "0.23.1", features = [ "glsl", "hlsl" ] } spirv_cross = { version = "0.23.1", features = [ "glsl", "hlsl" ] }
@ -30,5 +30,6 @@ rspirv-reflect = { git = "https://github.com/Traverse-Research/rspirv-reflect",
[features] [features]
default = [] default = []
unstable-rust-pipeline = [ "naga", "rspirv", "rspirv-reflect" ] unstable-rust-pipeline = [ "naga", "rspirv", "rspirv-reflect" ]
standalone = ["shaderc/build-from-source"]
[dev-dependencies] [dev-dependencies]

View file

@ -1,4 +1,4 @@
use librashader_common::image::ImageError; use librashader_runtime::image::ImageError;
use librashader_preprocess::PreprocessError; use librashader_preprocess::PreprocessError;
use librashader_presets::ParsePresetError; use librashader_presets::ParsePresetError;
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};

View file

@ -1,5 +1,5 @@
use crate::texture::{DxImageView, LutTexture, Texture}; 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_common::{ImageFormat, Size};
use librashader_preprocess::ShaderSource; use librashader_preprocess::ShaderSource;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig}; use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};

View file

@ -5,7 +5,7 @@ use librashader_common::{ImageFormat, Size};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use windows::core::Interface; use windows::core::Interface;
use windows::Win32::Graphics::Direct3D::D3D_SRV_DIMENSION_TEXTURE2D; 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}; use windows::Win32::Graphics::Dxgi::Common::{DXGI_FORMAT, DXGI_SAMPLE_DESC};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]

View file

@ -23,7 +23,6 @@ pub use texture::DxImageView;
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::options::FilterChainOptions;
use super::*; use super::*;
#[test] #[test]

View file

@ -1,4 +1,4 @@
use librashader_common::image::Image; use librashader_runtime::image::Image;
use librashader_common::{FilterMode, Size, WrapMode}; use librashader_common::{FilterMode, Size, WrapMode};
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::{

View file

@ -1,5 +1,5 @@
use gl::types::GLenum; use gl::types::GLenum;
use librashader_common::image::ImageError; use librashader_runtime::image::ImageError;
use librashader_preprocess::PreprocessError; use librashader_preprocess::PreprocessError;
use librashader_presets::ParsePresetError; use librashader_presets::ParsePresetError;
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError}; use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};

View file

@ -67,10 +67,10 @@ impl DrawQuad for Gl3DrawQuad {
fn unbind_vertices(&self) { fn unbind_vertices(&self) {
unsafe { unsafe {
gl::BindVertexArray(0);
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
gl::DisableVertexAttribArray(0); gl::DisableVertexAttribArray(0);
gl::DisableVertexAttribArray(1); gl::DisableVertexAttribArray(1);
gl::BindVertexArray(0);
gl::BindBuffer(gl::ARRAY_BUFFER, 0);
} }
} }
} }

View file

@ -3,7 +3,7 @@ use crate::framebuffer::GLImage;
use crate::gl::LoadLut; use crate::gl::LoadLut;
use crate::texture::Texture; use crate::texture::Texture;
use gl::types::{GLsizei, GLuint}; use gl::types::{GLsizei, GLuint};
use librashader_common::image::{Image, UVDirection}; use librashader_runtime::image::{Image, UVDirection};
use librashader_common::Size; use librashader_common::Size;
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;

View file

@ -3,7 +3,7 @@ use crate::framebuffer::GLImage;
use crate::gl::LoadLut; use crate::gl::LoadLut;
use crate::texture::Texture; use crate::texture::Texture;
use gl::types::{GLsizei, GLuint}; use gl::types::{GLsizei, GLuint};
use librashader_common::image::{Image, UVDirection}; use librashader_runtime::image::{Image, UVDirection};
use librashader_common::Size; use librashader_common::Size;
use librashader_presets::TextureConfig; use librashader_presets::TextureConfig;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;

View file

@ -19,3 +19,4 @@ librashader-reflect = { path = "../librashader-reflect", version = "0.1.0-alpha.
bytemuck = "1.12.3" bytemuck = "1.12.3"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
num-traits = "0.2.15" num-traits = "0.2.15"
image = "0.24.5"

View file

@ -1,3 +1,6 @@
use librashader_common::Size;
pub use image::ImageError;
use std::path::Path; use std::path::Path;
pub struct Image { pub struct Image {
@ -6,16 +9,21 @@ pub struct Image {
pub pitch: usize, pub pitch: usize,
} }
/// The direction of UV coordinates to load the image for.
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum UVDirection { pub enum UVDirection {
/// Origin is at the top left (Direct3D, Vulkan)
TopLeft, TopLeft,
/// Origin is at the bottom left (OpenGL)
BottomLeft, BottomLeft,
} }
impl Image { impl Image {
/// Load the image from the path as RGBA8.
pub fn load(path: impl AsRef<Path>, direction: UVDirection) -> Result<Self, ImageError> { pub fn load(path: impl AsRef<Path>, direction: UVDirection) -> Result<Self, ImageError> {
let mut image = image::open(path.as_ref())?; let mut image = image::open(path.as_ref())?;
if direction == BottomLeft { if direction == UVDirection::BottomLeft {
image = image.flipv(); image = image.flipv();
} }
@ -35,7 +43,3 @@ impl Image {
}) })
} }
} }
use crate::Size;
pub use image::ImageError;
use crate::image::UVDirection::BottomLeft;

View file

@ -14,3 +14,6 @@ pub mod parameters;
/// Filter chain helpers and traits. /// Filter chain helpers and traits.
pub mod filter_chain; pub mod filter_chain;
/// Image handling helpers.
pub mod image;