fmt: run clippy

This commit is contained in:
chyyran 2022-11-11 01:53:02 -05:00
parent 41f721aa6d
commit f3d0b2acae
12 changed files with 31 additions and 49 deletions

View file

@ -1,9 +1,9 @@
use crate::back::targets::{CompilerBackend, FromCompilation, GLSL, HLSL};
use crate::back::CompileShader;
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::error::ShaderReflectError;
use crate::front::shaderc::GlslangCompilation;
use crate::reflect::cross::{GlslReflect, HlslReflect};
use crate::reflect::{ReflectShader, ShaderReflection};
use crate::reflect::ReflectShader;
pub type GlVersion = spirv_cross::glsl::Version;
impl FromCompilation<GlslangCompilation> for GLSL {

View file

@ -2,14 +2,12 @@ pub mod cross;
pub mod targets;
use std::fmt::Debug;
use rustc_hash::FxHashMap;
pub use targets::CompileShader;
use crate::reflect::semantics::{SemanticMap, TextureSemantics};
use crate::reflect::UniformSemantic;
#[derive(Debug)]
pub struct CompiledShader<Source, Context = ()> {
pub vertex: Source,
pub fragment: Source,
pub struct ShaderCompilerOutput<T, Context = ()> {
pub vertex: T,
pub fragment: T,
pub context: Context,
}

View file

@ -1,7 +1,6 @@
use crate::back::CompiledShader;
use crate::back::ShaderCompilerOutput;
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::reflect::{ReflectSemantics, ReflectShader, ShaderReflection};
use std::marker::PhantomData;
pub trait OutputTarget {
type Output;
@ -43,7 +42,7 @@ pub trait CompileShader<T: OutputTarget> {
fn compile(
&mut self,
options: Self::Options,
) -> Result<CompiledShader<T::Output, T::AdditionalContext>, ShaderCompileError>;
) -> Result<ShaderCompilerOutput<T::Output, T::AdditionalContext>, ShaderCompileError>;
}
impl<T> ReflectShader for CompilerBackend<T>
@ -69,16 +68,16 @@ where
fn compile(
&mut self,
options: Self::Options,
) -> Result<CompiledShader<E::Output, E::AdditionalContext>, ShaderCompileError> {
) -> Result<ShaderCompilerOutput<E::Output, E::AdditionalContext>, ShaderCompileError> {
self.backend.compile(options)
}
}
mod test {
use crate::back::targets::{CompilerBackend, FromCompilation, GLSL};
use crate::back::targets::{FromCompilation, GLSL};
use crate::front::shaderc::GlslangCompilation;
pub fn huh(value: GlslangCompilation) {
let x = GLSL::from_compilation(value).unwrap();
let _x = GLSL::from_compilation(value).unwrap();
}
}

View file

@ -1,22 +1,20 @@
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
use crate::front::shaderc::GlslangCompilation;
use crate::reflect::semantics::{
BindingStage, MemberOffset, PushReflection, SemanticMap, ShaderReflection, TextureImage,
TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection, ValidateTypeSemantics,
VariableMeta, VariableSemantics, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
BindingStage, MemberOffset, PushReflection, ShaderReflection, TextureImage, TextureSemantics,
TextureSizeMeta, TypeInfo, UboReflection, ValidateTypeSemantics, VariableMeta,
VariableSemantics, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
};
use crate::reflect::{
ReflectMeta, ReflectSemantics, ReflectShader, TextureSemanticMap, UniformSemantic,
VariableSemanticMap,
ReflectMeta, ReflectSemantics, ReflectShader, TextureSemanticMap, VariableSemanticMap,
};
use rustc_hash::FxHashMap;
use spirv_cross::hlsl::ShaderModel;
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};
use spirv_cross::{glsl, hlsl, ErrorCode};
use crate::back::targets::{GLSL, HLSL};
use crate::back::{CompileShader, CompiledShader};
use std::str::FromStr;
use crate::back::{CompileShader, ShaderCompilerOutput};
pub struct CrossReflect<T>
where
@ -99,8 +97,8 @@ where
let vertex_module = Module::from_words(value.vertex.as_binary());
let fragment_module = Module::from_words(value.fragment.as_binary());
let mut vertex = Ast::parse(&vertex_module)?;
let mut fragment = Ast::parse(&fragment_module)?;
let vertex = Ast::parse(&vertex_module)?;
let fragment = Ast::parse(&fragment_module)?;
Ok(CrossReflect { vertex, fragment })
}
@ -681,7 +679,7 @@ impl CompileShader<GLSL> for CrossReflect<glsl::Target> {
fn compile(
&mut self,
version: Self::Options,
) -> Result<CompiledShader<String, Vec<u32>>, ShaderCompileError> {
) -> Result<ShaderCompilerOutput<String, Vec<u32>>, ShaderCompileError> {
let mut options: glsl::CompilerOptions = Default::default();
options.version = version;
options.fragment.default_float_precision = glsl::Precision::High;
@ -796,7 +794,7 @@ impl CompileShader<GLSL> for CrossReflect<glsl::Target> {
texture_fixups.push(binding);
}
Ok(CompiledShader {
Ok(ShaderCompilerOutput {
vertex: self.vertex.compile()?,
fragment: self.fragment.compile()?,
context: texture_fixups,
@ -810,14 +808,14 @@ impl CompileShader<HLSL> for CrossReflect<hlsl::Target> {
fn compile(
&mut self,
_options: Self::Options,
) -> Result<CompiledShader<String>, ShaderCompileError> {
) -> Result<ShaderCompilerOutput<String>, ShaderCompileError> {
let mut options = hlsl::CompilerOptions::default();
options.shader_model = ShaderModel::V5_0;
self.vertex.set_compiler_options(&options)?;
self.fragment.set_compiler_options(&options)?;
Ok(CompiledShader {
Ok(ShaderCompilerOutput {
vertex: self.vertex.compile()?,
fragment: self.fragment.compile()?,
context: (),

View file

@ -4,7 +4,7 @@ use std::path::Path;
use rustc_hash::FxHashMap;
use librashader::ShaderSource;
use librashader_presets::ShaderPassConfig;
use librashader_reflect::back::{CompileShader, ShaderCompiler};
use librashader_reflect::back::{CompileShader};
use librashader_reflect::back::targets::{FromCompilation, HLSL};
use librashader_reflect::front::shaderc::GlslangCompilation;
use librashader_reflect::reflect::cross::{CrossReflect};

View file

@ -94,27 +94,20 @@ pub fn load(path: impl AsRef<Path>) -> Result<(), Box<dyn Error>>{
let mut compiled = Vec::new();
for (index, (config, source, reflect)) in passes.iter_mut().enumerate() {
let reflection = reflect.reflect(index as u32, &semantics)
.unwrap();
let glsl = reflect.compile(GlVersion::V4_60)
.unwrap();
eprintln!("{:#}", glsl.vertex);
eprintln!("{:#}", glsl.fragment);
let reflection = reflect.reflect(index as u32, &semantics)?;
let glsl = reflect.compile(GlVersion::V4_60)?;
// shader_gl3: 1375
// reflection.meta.texture_meta.get(&SemanticMap {
// semantics: TextureSemantics::PassOutput,
// index: 0
// }).unwrap().binding;
reflection.meta.texture_meta.get(&SemanticMap {
semantics: TextureSemantics::Source,
index: 0
}).unwrap().binding;
compiled.push(glsl);
reflections.push(reflection);
}
// todo: build gl semantics
// shader_gl3:188

View file

@ -1 +0,0 @@
This file has an mtime of when this was started.

View file

@ -1 +0,0 @@
{"rustc":13014424268511301986,"features":"[]","target":5709258604770305642,"profile":1021633075455700787,"path":13800204036534426481,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\librashader-presets-1efad29917dd9fd7\\dep-test-lib-librashader-presets"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}

View file

@ -1 +0,0 @@
This file has an mtime of when this was started.

View file

@ -1 +0,0 @@
{"rustc":13014424268511301986,"features":"[]","target":5709258604770305642,"profile":7309141686862299243,"path":13800204036534426481,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug\\.fingerprint\\librashader-presets-63cd868267815af8\\dep-lib-librashader-presets"}}],"rustflags":[],"metadata":7797948686568424061,"config":2202906307356721367,"compile_kind":0}