Compare commits
3 commits
71584cd9af
...
0974254c0e
Author | SHA1 | Date | |
---|---|---|---|
Alex Janka | 0974254c0e | ||
923bc165b2 | |||
44aa5fab7d |
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -1343,9 +1343,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glslang"
|
name = "glslang"
|
||||||
version = "0.2.3"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ffa3b9c49e9b4270061e25e7e3946d979a9394a21ac51edcb72e7c17874d3a54"
|
checksum = "c5df6491e5d4c222a6373b892c1bea8d697fca0c087890f64f0e2975b3f8bb48"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glslang-sys",
|
"glslang-sys",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
@ -1355,9 +1355,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glslang-sys"
|
name = "glslang-sys"
|
||||||
version = "0.2.1"
|
version = "0.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3c81cefc876b4fd65354162037a464768bc5bada8b02d93b64e18186ae5cb7e"
|
checksum = "6d76f2d75ad6e8a12c26e77ed6443a9369ef7957daf361e751c3489a97f8b816"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"glob",
|
"glob",
|
||||||
|
@ -1843,7 +1843,7 @@ dependencies = [
|
||||||
name = "librashader-reflect"
|
name = "librashader-reflect"
|
||||||
version = "0.2.0-beta.7"
|
version = "0.2.0-beta.7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 2.4.2",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"glslang",
|
"glslang",
|
||||||
"indexmap 2.2.2",
|
"indexmap 2.2.2",
|
||||||
|
|
|
@ -32,6 +32,12 @@ use num_traits::AsPrimitive;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum ShaderStorage {
|
||||||
|
Path(std::path::PathBuf),
|
||||||
|
String(String),
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
|
||||||
/// Supported image formats for textures.
|
/// Supported image formats for textures.
|
||||||
|
|
|
@ -17,7 +17,6 @@ use crate::include::read_source;
|
||||||
pub use error::*;
|
pub use error::*;
|
||||||
use librashader_common::ImageFormat;
|
use librashader_common::ImageFormat;
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
/// The source file for a single shader pass.
|
/// The source file for a single shader pass.
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
@ -58,8 +57,8 @@ pub struct ShaderParameter {
|
||||||
impl ShaderSource {
|
impl ShaderSource {
|
||||||
/// Load the source file at the given path, resolving includes relative to the location of the
|
/// Load the source file at the given path, resolving includes relative to the location of the
|
||||||
/// source file.
|
/// source file.
|
||||||
pub fn load(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
|
pub fn load(file: &librashader_common::ShaderStorage) -> Result<ShaderSource, PreprocessError> {
|
||||||
load_shader_source(path)
|
load_shader_source(file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +77,14 @@ impl SourceOutput for String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
|
pub(crate) fn load_shader_source(
|
||||||
let source = read_source(path)?;
|
file: &librashader_common::ShaderStorage,
|
||||||
|
) -> Result<ShaderSource, PreprocessError> {
|
||||||
|
let source = match file {
|
||||||
|
librashader_common::ShaderStorage::Path(path) => read_source(path)?,
|
||||||
|
librashader_common::ShaderStorage::String(s) => s.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
let meta = pragma::parse_pragma_meta(&source)?;
|
let meta = pragma::parse_pragma_meta(&source)?;
|
||||||
let text = stage::process_stages(&source)?;
|
let text = stage::process_stages(&source)?;
|
||||||
let parameters = FxHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p)));
|
let parameters = FxHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p)));
|
||||||
|
|
|
@ -115,7 +115,7 @@ pub fn resolve_values(mut values: Vec<Value>) -> ShaderPreset {
|
||||||
|
|
||||||
let shader = ShaderPassConfig {
|
let shader = ShaderPassConfig {
|
||||||
id,
|
id,
|
||||||
name,
|
name: librashader_common::ShaderStorage::Path(name),
|
||||||
alias: shader_values.iter().find_map(|f| match f {
|
alias: shader_values.iter().find_map(|f| match f {
|
||||||
Value::Alias(_, value) => Some(value.to_string()),
|
Value::Alias(_, value) => Some(value.to_string()),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub struct ShaderPassConfig {
|
||||||
/// The index of the shader pass relative to its parent preset.
|
/// The index of the shader pass relative to its parent preset.
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
/// The fully qualified path to the shader pass source file.
|
/// The fully qualified path to the shader pass source file.
|
||||||
pub name: PathBuf,
|
pub name: librashader_common::ShaderStorage,
|
||||||
/// The alias of the shader pass if available.
|
/// The alias of the shader pass if available.
|
||||||
pub alias: Option<String>,
|
pub alias: Option<String>,
|
||||||
/// The filtering mode that this shader pass should expect.
|
/// The filtering mode that this shader pass should expect.
|
||||||
|
|
|
@ -12,11 +12,11 @@ keywords = ["shader", "retroarch", "SPIR-V"]
|
||||||
description = "RetroArch shaders for all."
|
description = "RetroArch shaders for all."
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
glslang = "0.2"
|
glslang = "0.3"
|
||||||
bytemuck = "1.13.0"
|
bytemuck = "1.13.0"
|
||||||
|
|
||||||
thiserror = "1.0.37"
|
thiserror = "1.0.37"
|
||||||
bitflags = "1.3.2"
|
bitflags = "2.4.2"
|
||||||
rustc-hash = "1.1.0"
|
rustc-hash = "1.1.0"
|
||||||
|
|
||||||
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.7" }
|
librashader-common = { path = "../librashader-common", version = "0.2.0-beta.7" }
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
use glslang::{CompilerOptions, ShaderInput};
|
||||||
use crate::error::ShaderCompileError;
|
use crate::error::ShaderCompileError;
|
||||||
use glslang::input::{CompilerOptions, ShaderInput};
|
|
||||||
use glslang::limits::ResourceLimits;
|
|
||||||
use librashader_preprocess::ShaderSource;
|
use librashader_preprocess::ShaderSource;
|
||||||
|
|
||||||
#[cfg(feature = "serialize")]
|
#[cfg(feature = "serialize")]
|
||||||
|
@ -34,28 +33,31 @@ pub(crate) fn compile_spirv(
|
||||||
source: &ShaderSource,
|
source: &ShaderSource,
|
||||||
) -> Result<GlslangCompilation, ShaderCompileError> {
|
) -> Result<GlslangCompilation, ShaderCompileError> {
|
||||||
let compiler = glslang::Compiler::acquire().ok_or(ShaderCompileError::CompilerInitError)?;
|
let compiler = glslang::Compiler::acquire().ok_or(ShaderCompileError::CompilerInitError)?;
|
||||||
|
let options = CompilerOptions {
|
||||||
|
source_language: glslang::SourceLanguage::GLSL,
|
||||||
|
target: glslang::Target::Vulkan {
|
||||||
|
version: glslang::VulkanVersion::Vulkan1_0,
|
||||||
|
spirv_version: glslang::SpirvVersion::SPIRV1_0
|
||||||
|
},
|
||||||
|
version_profile: None,
|
||||||
|
};
|
||||||
|
|
||||||
let limits = ResourceLimits::default();
|
let vertex = glslang::ShaderSource::from(source.vertex.as_str());
|
||||||
let options = CompilerOptions::default();
|
|
||||||
|
|
||||||
let vertex = glslang::input::ShaderSource::from(source.vertex.as_str());
|
|
||||||
let vertex = ShaderInput::new(
|
let vertex = ShaderInput::new(
|
||||||
&vertex,
|
&vertex,
|
||||||
&limits,
|
|
||||||
glslang::ShaderStage::Vertex,
|
glslang::ShaderStage::Vertex,
|
||||||
&options,
|
&options,
|
||||||
None,
|
None,
|
||||||
);
|
)?;
|
||||||
let vertex = compiler.create_shader(vertex)?;
|
let vertex = compiler.create_shader(vertex)?;
|
||||||
|
|
||||||
let fragment = glslang::input::ShaderSource::from(source.fragment.as_str());
|
let fragment = glslang::ShaderSource::from(source.fragment.as_str());
|
||||||
let fragment = ShaderInput::new(
|
let fragment = ShaderInput::new(
|
||||||
&fragment,
|
&fragment,
|
||||||
&limits,
|
|
||||||
glslang::ShaderStage::Fragment,
|
glslang::ShaderStage::Fragment,
|
||||||
&options,
|
&options,
|
||||||
None,
|
None,
|
||||||
);
|
)?;
|
||||||
let fragment = compiler.create_shader(fragment)?;
|
let fragment = compiler.create_shader(fragment)?;
|
||||||
|
|
||||||
let vertex = Vec::from(vertex.compile()?);
|
let vertex = Vec::from(vertex.compile()?);
|
||||||
|
|
|
@ -162,6 +162,7 @@ pub struct Semantic<T, I = usize> {
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
/// The pipeline stage for which a uniform is bound.
|
/// The pipeline stage for which a uniform is bound.
|
||||||
|
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
|
||||||
pub struct BindingStage: u8 {
|
pub struct BindingStage: u8 {
|
||||||
const NONE = 0b00000000;
|
const NONE = 0b00000000;
|
||||||
const VERTEX = 0b00000001;
|
const VERTEX = 0b00000001;
|
||||||
|
|
|
@ -186,9 +186,6 @@ impl Drop for RawVulkanBuffer {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
ManuallyDrop::drop(&mut self.buffer);
|
ManuallyDrop::drop(&mut self.buffer);
|
||||||
if self.buffer.handle != vk::Buffer::null() {
|
|
||||||
self.buffer.device.destroy_buffer(self.buffer.handle, None);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue