reflect: allow specifying output toolchain
This commit is contained in:
parent
252f685967
commit
b98d86a940
|
@ -66,11 +66,14 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(target_os = "windows", feature = "d3d"))]
|
#[cfg(all(target_os = "windows", feature = "d3d"))]
|
||||||
impl FromCompilation<CachedCompilation<SpirvCompilation>> for DXIL {
|
impl<T> FromCompilation<CachedCompilation<SpirvCompilation>, T> for DXIL
|
||||||
type Target = <DXIL as FromCompilation<SpirvCompilation>>::Target;
|
where
|
||||||
type Options = <DXIL as FromCompilation<SpirvCompilation>>::Options;
|
DXIL: FromCompilation<SpirvCompilation, T>,
|
||||||
type Context = <DXIL as FromCompilation<SpirvCompilation>>::Context;
|
{
|
||||||
type Output = <DXIL as FromCompilation<SpirvCompilation>>::Output;
|
type Target = <DXIL as FromCompilation<SpirvCompilation, T>>::Target;
|
||||||
|
type Options = <DXIL as FromCompilation<SpirvCompilation, T>>::Options;
|
||||||
|
type Context = <DXIL as FromCompilation<SpirvCompilation, T>>::Context;
|
||||||
|
type Output = <DXIL as FromCompilation<SpirvCompilation, T>>::Output;
|
||||||
|
|
||||||
fn from_compilation(
|
fn from_compilation(
|
||||||
compile: CachedCompilation<SpirvCompilation>,
|
compile: CachedCompilation<SpirvCompilation>,
|
||||||
|
@ -79,11 +82,14 @@ impl FromCompilation<CachedCompilation<SpirvCompilation>> for DXIL {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<CachedCompilation<SpirvCompilation>> for HLSL {
|
impl<T> FromCompilation<CachedCompilation<SpirvCompilation>, T> for HLSL
|
||||||
type Target = <HLSL as FromCompilation<SpirvCompilation>>::Target;
|
where
|
||||||
type Options = <HLSL as FromCompilation<SpirvCompilation>>::Options;
|
HLSL: FromCompilation<SpirvCompilation, T>,
|
||||||
type Context = <HLSL as FromCompilation<SpirvCompilation>>::Context;
|
{
|
||||||
type Output = <HLSL as FromCompilation<SpirvCompilation>>::Output;
|
type Target = <HLSL as FromCompilation<SpirvCompilation, T>>::Target;
|
||||||
|
type Options = <HLSL as FromCompilation<SpirvCompilation, T>>::Options;
|
||||||
|
type Context = <HLSL as FromCompilation<SpirvCompilation, T>>::Context;
|
||||||
|
type Output = <HLSL as FromCompilation<SpirvCompilation, T>>::Output;
|
||||||
|
|
||||||
fn from_compilation(
|
fn from_compilation(
|
||||||
compile: CachedCompilation<SpirvCompilation>,
|
compile: CachedCompilation<SpirvCompilation>,
|
||||||
|
@ -92,11 +98,14 @@ impl FromCompilation<CachedCompilation<SpirvCompilation>> for HLSL {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<CachedCompilation<SpirvCompilation>> for GLSL {
|
impl<T> FromCompilation<CachedCompilation<SpirvCompilation>, T> for GLSL
|
||||||
type Target = <GLSL as FromCompilation<SpirvCompilation>>::Target;
|
where
|
||||||
type Options = <GLSL as FromCompilation<SpirvCompilation>>::Options;
|
GLSL: FromCompilation<SpirvCompilation, T>,
|
||||||
type Context = <GLSL as FromCompilation<SpirvCompilation>>::Context;
|
{
|
||||||
type Output = <GLSL as FromCompilation<SpirvCompilation>>::Output;
|
type Target = <GLSL as FromCompilation<SpirvCompilation, T>>::Target;
|
||||||
|
type Options = <GLSL as FromCompilation<SpirvCompilation, T>>::Options;
|
||||||
|
type Context = <GLSL as FromCompilation<SpirvCompilation, T>>::Context;
|
||||||
|
type Output = <GLSL as FromCompilation<SpirvCompilation, T>>::Output;
|
||||||
|
|
||||||
fn from_compilation(
|
fn from_compilation(
|
||||||
compile: CachedCompilation<SpirvCompilation>,
|
compile: CachedCompilation<SpirvCompilation>,
|
||||||
|
@ -105,11 +114,14 @@ impl FromCompilation<CachedCompilation<SpirvCompilation>> for GLSL {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<CachedCompilation<SpirvCompilation>> for SPIRV {
|
impl<T> FromCompilation<CachedCompilation<SpirvCompilation>, T> for SPIRV
|
||||||
type Target = <SPIRV as FromCompilation<SpirvCompilation>>::Target;
|
where
|
||||||
type Options = <SPIRV as FromCompilation<SpirvCompilation>>::Options;
|
SPIRV: FromCompilation<SpirvCompilation, T>,
|
||||||
type Context = <SPIRV as FromCompilation<SpirvCompilation>>::Context;
|
{
|
||||||
type Output = <SPIRV as FromCompilation<SpirvCompilation>>::Output;
|
type Target = <SPIRV as FromCompilation<SpirvCompilation, T>>::Target;
|
||||||
|
type Options = <SPIRV as FromCompilation<SpirvCompilation, T>>::Options;
|
||||||
|
type Context = <SPIRV as FromCompilation<SpirvCompilation, T>>::Context;
|
||||||
|
type Output = <SPIRV as FromCompilation<SpirvCompilation, T>>::Output;
|
||||||
|
|
||||||
fn from_compilation(
|
fn from_compilation(
|
||||||
compile: CachedCompilation<SpirvCompilation>,
|
compile: CachedCompilation<SpirvCompilation>,
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::back::targets::{GLSL, HLSL};
|
||||||
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
|
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
|
||||||
use crate::error::ShaderReflectError;
|
use crate::error::ShaderReflectError;
|
||||||
use crate::front::SpirvCompilation;
|
use crate::front::SpirvCompilation;
|
||||||
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect, SpirvCross};
|
use crate::reflect::cross::{CompiledProgram, SpirvCross};
|
||||||
use crate::reflect::{ReflectShader, ShaderOutputCompiler};
|
use crate::reflect::{ReflectShader, ShaderOutputCompiler};
|
||||||
|
|
||||||
/// The GLSL version to target.
|
/// The GLSL version to target.
|
||||||
|
@ -19,7 +19,7 @@ pub struct CrossGlslContext {
|
||||||
pub artifact: CompiledProgram<spirv_cross::glsl::Target>,
|
pub artifact: CompiledProgram<spirv_cross::glsl::Target>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<SpirvCompilation> for GLSL {
|
impl FromCompilation<SpirvCompilation, SpirvCross<GLSL>> for GLSL {
|
||||||
type Target = GLSL;
|
type Target = GLSL;
|
||||||
type Options = GlslVersion;
|
type Options = GlslVersion;
|
||||||
type Context = CrossGlslContext;
|
type Context = CrossGlslContext;
|
||||||
|
@ -30,9 +30,7 @@ impl FromCompilation<SpirvCompilation> for GLSL {
|
||||||
compile: SpirvCompilation,
|
compile: SpirvCompilation,
|
||||||
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
||||||
let backend = SpirvCross::<GLSL>::create_reflection(compile)?;
|
let backend = SpirvCross::<GLSL>::create_reflection(compile)?;
|
||||||
Ok(CompilerBackend {
|
Ok(CompilerBackend { backend })
|
||||||
backend,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +40,7 @@ pub struct CrossHlslContext {
|
||||||
pub artifact: CompiledProgram<spirv_cross::hlsl::Target>,
|
pub artifact: CompiledProgram<spirv_cross::hlsl::Target>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<SpirvCompilation> for HLSL {
|
impl FromCompilation<SpirvCompilation, SpirvCross<HLSL>> for HLSL {
|
||||||
type Target = HLSL;
|
type Target = HLSL;
|
||||||
type Options = Option<HlslShaderModel>;
|
type Options = Option<HlslShaderModel>;
|
||||||
type Context = CrossHlslContext;
|
type Context = CrossHlslContext;
|
||||||
|
|
|
@ -9,14 +9,14 @@ use spirv_to_dxil::{
|
||||||
use crate::back::targets::{OutputTarget, DXIL};
|
use crate::back::targets::{OutputTarget, DXIL};
|
||||||
use crate::error::{ShaderCompileError, ShaderReflectError};
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::SpirvCompilation;
|
use crate::front::SpirvCompilation;
|
||||||
use crate::reflect::cross::GlslReflect;
|
use crate::reflect::cross::{GlslReflect, SpirvCross};
|
||||||
use crate::reflect::{ReflectShader, ShaderOutputCompiler};
|
use crate::reflect::ReflectShader;
|
||||||
|
|
||||||
impl OutputTarget for DXIL {
|
impl OutputTarget for DXIL {
|
||||||
type Output = DxilObject;
|
type Output = DxilObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<SpirvCompilation> for DXIL {
|
impl FromCompilation<SpirvCompilation, SpirvCross<DXIL>> for DXIL {
|
||||||
type Target = DXIL;
|
type Target = DXIL;
|
||||||
type Options = Option<ShaderModel>;
|
type Options = Option<ShaderModel>;
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
@ -26,7 +26,7 @@ impl FromCompilation<SpirvCompilation> for DXIL {
|
||||||
fn from_compilation(
|
fn from_compilation(
|
||||||
compile: SpirvCompilation,
|
compile: SpirvCompilation,
|
||||||
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
|
||||||
let reflect = GlslReflect::new().create_reflection(compile)?;
|
let reflect = GlslReflect::try_from(&compile)?;
|
||||||
let vertex = compile.vertex;
|
let vertex = compile.vertex;
|
||||||
let fragment = compile.fragment;
|
let fragment = compile.fragment;
|
||||||
Ok(CompilerBackend {
|
Ok(CompilerBackend {
|
||||||
|
|
|
@ -42,26 +42,26 @@ pub trait CompileShader<T: OutputTarget> {
|
||||||
///
|
///
|
||||||
/// This trait is automatically implemented for reflected outputs that have [`FromCompilation`](crate::back::FromCompilation) implement
|
/// This trait is automatically implemented for reflected outputs that have [`FromCompilation`](crate::back::FromCompilation) implement
|
||||||
/// for a given target that also implement [`CompileShader`](crate::back::CompileShader) for that target.
|
/// for a given target that also implement [`CompileShader`](crate::back::CompileShader) for that target.
|
||||||
pub trait CompileReflectShader<T: OutputTarget, C>:
|
pub trait CompileReflectShader<T: OutputTarget, C, O>:
|
||||||
CompileShader<
|
CompileShader<
|
||||||
T,
|
T,
|
||||||
Options = <T as FromCompilation<C>>::Options,
|
Options = <T as FromCompilation<C, O>>::Options,
|
||||||
Context = <T as FromCompilation<C>>::Context,
|
Context = <T as FromCompilation<C, O>>::Context,
|
||||||
> + ReflectShader
|
> + ReflectShader
|
||||||
where
|
where
|
||||||
T: FromCompilation<C>,
|
T: FromCompilation<C, O>,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, C, O> CompileReflectShader<T, C> for O
|
impl<T, C, O, R> CompileReflectShader<T, C, R> for O
|
||||||
where
|
where
|
||||||
T: OutputTarget,
|
T: OutputTarget,
|
||||||
T: FromCompilation<C>,
|
T: FromCompilation<C, R>,
|
||||||
O: ReflectShader,
|
O: ReflectShader,
|
||||||
O: CompileShader<
|
O: CompileShader<
|
||||||
T,
|
T,
|
||||||
Options = <T as FromCompilation<C>>::Options,
|
Options = <T as FromCompilation<C, R>>::Options,
|
||||||
Context = <T as FromCompilation<C>>::Context,
|
Context = <T as FromCompilation<C, R>>::Context,
|
||||||
>,
|
>,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait for reflectable compilations that can be transformed into an object ready for reflection or compilation.
|
/// A trait for reflectable compilations that can be transformed into an object ready for reflection or compilation.
|
||||||
pub trait FromCompilation<T> {
|
pub trait FromCompilation<T, R> {
|
||||||
/// The target that the transformed object is expected to compile for.
|
/// The target that the transformed object is expected to compile for.
|
||||||
type Target: OutputTarget;
|
type Target: OutputTarget;
|
||||||
/// Options provided to the compiler.
|
/// Options provided to the compiler.
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::back::targets::SPIRV;
|
||||||
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
|
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
|
||||||
use crate::error::{ShaderCompileError, ShaderReflectError};
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::SpirvCompilation;
|
use crate::front::SpirvCompilation;
|
||||||
use crate::reflect::cross::GlslReflect;
|
use crate::reflect::cross::{GlslReflect, SpirvCross};
|
||||||
use crate::reflect::semantics::ShaderSemantics;
|
use crate::reflect::semantics::ShaderSemantics;
|
||||||
use crate::reflect::{ReflectShader, ShaderReflection};
|
use crate::reflect::{ReflectShader, ShaderReflection};
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ pub(crate) struct WriteSpirV {
|
||||||
pub(crate) fragment: Vec<u32>,
|
pub(crate) fragment: Vec<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<SpirvCompilation> for SPIRV {
|
impl FromCompilation<SpirvCompilation, SpirvCross<SPIRV>> for SPIRV {
|
||||||
type Target = SPIRV;
|
type Target = SPIRV;
|
||||||
type Options = Option<()>;
|
type Options = Option<()>;
|
||||||
type Context = ();
|
type Context = ();
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub struct WgslCompileOptions {
|
||||||
pub sampler_bind_group: u32,
|
pub sampler_bind_group: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<SpirvCompilation> for WGSL {
|
impl FromCompilation<SpirvCompilation, Naga> for WGSL {
|
||||||
type Target = WGSL;
|
type Target = WGSL;
|
||||||
type Options = WgslCompileOptions;
|
type Options = WgslCompileOptions;
|
||||||
type Context = NagaWgslContext;
|
type Context = NagaWgslContext;
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::SpirvCompilation;
|
use crate::front::SpirvCompilation;
|
||||||
use crate::reflect::semantics::{
|
use crate::reflect::semantics::{
|
||||||
|
@ -9,18 +7,19 @@ use crate::reflect::semantics::{
|
||||||
MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
|
MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE,
|
||||||
};
|
};
|
||||||
use crate::reflect::{align_uniform_size, ReflectShader, ShaderOutputCompiler};
|
use crate::reflect::{align_uniform_size, ReflectShader, ShaderOutputCompiler};
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};
|
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};
|
||||||
use spirv_cross::{glsl, hlsl, ErrorCode};
|
use spirv_cross::{glsl, hlsl, ErrorCode};
|
||||||
|
|
||||||
use crate::back::cross::{CrossGlslContext, CrossHlslContext, HlslShaderModel};
|
use crate::back::cross::{CrossGlslContext, CrossHlslContext, HlslShaderModel};
|
||||||
use crate::back::targets::{GLSL, HLSL, OutputTarget};
|
use crate::back::targets::{OutputTarget, DXIL, GLSL, HLSL, SPIRV};
|
||||||
use crate::back::{CompileShader, ShaderCompilerOutput};
|
use crate::back::{CompileShader, ShaderCompilerOutput};
|
||||||
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
|
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
|
||||||
|
|
||||||
|
trait SpirvCrossTarget {
|
||||||
pub trait SpirvCrossTarget {
|
|
||||||
type CrossTarget: spirv_cross::spirv::Target;
|
type CrossTarget: spirv_cross::spirv::Target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,14 +27,21 @@ impl SpirvCrossTarget for HLSL {
|
||||||
type CrossTarget = spirv_cross::hlsl::Target;
|
type CrossTarget = spirv_cross::hlsl::Target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpirvCrossTarget for SPIRV {
|
||||||
|
type CrossTarget = spirv_cross::glsl::Target;
|
||||||
|
}
|
||||||
|
|
||||||
impl SpirvCrossTarget for GLSL {
|
impl SpirvCrossTarget for GLSL {
|
||||||
type CrossTarget = spirv_cross::glsl::Target;
|
type CrossTarget = spirv_cross::glsl::Target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SpirvCrossTarget for DXIL {
|
||||||
|
type CrossTarget = spirv_cross::glsl::Target;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(private_bounds)]
|
||||||
pub struct SpirvCross<T: OutputTarget + SpirvCrossTarget>(PhantomData<T>);
|
pub struct SpirvCross<T: OutputTarget + SpirvCrossTarget>(PhantomData<T>);
|
||||||
|
|
||||||
pub(crate) type HlslReflect = CrossReflect<hlsl::Target>;
|
|
||||||
pub(crate) type GlslReflect = CrossReflect<glsl::Target>;
|
pub(crate) type GlslReflect = CrossReflect<glsl::Target>;
|
||||||
|
|
||||||
impl<T: OutputTarget + SpirvCrossTarget, Opt, Ctx>
|
impl<T: OutputTarget + SpirvCrossTarget, Opt, Ctx>
|
||||||
|
@ -43,15 +49,21 @@ ShaderOutputCompiler<SpirvCompilation, T, Opt, Ctx> for SpirvCross<T>
|
||||||
// where Spv: spirv_cross::spirv::Target,
|
// where Spv: spirv_cross::spirv::Target,
|
||||||
// Ast<Spv>: spirv_cross::spirv::Compile<Spv>,
|
// Ast<Spv>: spirv_cross::spirv::Compile<Spv>,
|
||||||
// Ast<Spv>: spirv_cross::spirv::Parse<Spv>,
|
// Ast<Spv>: spirv_cross::spirv::Parse<Spv>,
|
||||||
where CrossReflect<<T as SpirvCrossTarget>::CrossTarget>
|
where
|
||||||
: CompileShader<T, Options = Opt, Context=Ctx>,
|
CrossReflect<<T as SpirvCrossTarget>::CrossTarget>:
|
||||||
|
CompileShader<T, Options = Opt, Context = Ctx>,
|
||||||
<T as SpirvCrossTarget>::CrossTarget: spirv_cross::spirv::Target,
|
<T as SpirvCrossTarget>::CrossTarget: spirv_cross::spirv::Target,
|
||||||
Ast<<T as SpirvCrossTarget>::CrossTarget>: spirv_cross::spirv::Compile<<T as SpirvCrossTarget>::CrossTarget>,
|
Ast<<T as SpirvCrossTarget>::CrossTarget>:
|
||||||
Ast<<T as SpirvCrossTarget>::CrossTarget>: spirv_cross::spirv::Parse<<T as SpirvCrossTarget>::CrossTarget>,
|
spirv_cross::spirv::Compile<<T as SpirvCrossTarget>::CrossTarget>,
|
||||||
|
Ast<<T as SpirvCrossTarget>::CrossTarget>:
|
||||||
|
spirv_cross::spirv::Parse<<T as SpirvCrossTarget>::CrossTarget>,
|
||||||
{
|
{
|
||||||
fn create_reflection(compiled: SpirvCompilation)
|
fn create_reflection(
|
||||||
-> Result<impl ReflectShader + CompileShader<T, Options = Opt, Context = Ctx>,
|
compiled: SpirvCompilation,
|
||||||
ShaderReflectError> {
|
) -> Result<
|
||||||
|
impl ReflectShader + CompileShader<T, Options = Opt, Context = Ctx>,
|
||||||
|
ShaderReflectError,
|
||||||
|
> {
|
||||||
let compiled = compiled.borrow();
|
let compiled = compiled.borrow();
|
||||||
let vertex_module = Module::from_words(&compiled.vertex);
|
let vertex_module = Module::from_words(&compiled.vertex);
|
||||||
let fragment_module = Module::from_words(&compiled.fragment);
|
let fragment_module = Module::from_words(&compiled.fragment);
|
||||||
|
@ -65,9 +77,11 @@ where CrossReflect<<T as SpirvCrossTarget>::CrossTarget>
|
||||||
|
|
||||||
// This is "probably" OK.
|
// This is "probably" OK.
|
||||||
unsafe impl<T: Send + spirv_cross::spirv::Target> Send for CrossReflect<T>
|
unsafe impl<T: Send + spirv_cross::spirv::Target> Send for CrossReflect<T>
|
||||||
where Ast<T>: spirv_cross::spirv::Compile<T>,
|
where
|
||||||
|
Ast<T>: spirv_cross::spirv::Compile<T>,
|
||||||
Ast<T>: spirv_cross::spirv::Parse<T>,
|
Ast<T>: spirv_cross::spirv::Parse<T>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct CrossReflect<T>
|
pub(crate) struct CrossReflect<T>
|
||||||
where
|
where
|
||||||
|
@ -100,8 +114,6 @@ where
|
||||||
pub fragment: CompiledAst<T>,
|
pub fragment: CompiledAst<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl ValidateTypeSemantics<Type> for UniqueSemantics {
|
impl ValidateTypeSemantics<Type> for UniqueSemantics {
|
||||||
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
|
fn validate_type(&self, ty: &Type) -> Option<TypeInfo> {
|
||||||
let (Type::Float {
|
let (Type::Float {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::borrow::Borrow;
|
|
||||||
use crate::error::ShaderReflectError;
|
use crate::error::ShaderReflectError;
|
||||||
use semantics::ShaderSemantics;
|
use semantics::ShaderSemantics;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
mod lower_samplers;
|
mod lower_samplers;
|
||||||
|
|
||||||
use std::borrow::Borrow;
|
|
||||||
use crate::error::{SemanticsErrorKind, ShaderReflectError};
|
use crate::error::{SemanticsErrorKind, ShaderReflectError};
|
||||||
|
use std::borrow::Borrow;
|
||||||
|
|
||||||
use crate::back::targets::OutputTarget;
|
use crate::back::targets::OutputTarget;
|
||||||
use crate::back::CompileShader;
|
use crate::back::CompileShader;
|
||||||
|
@ -36,7 +36,7 @@ where
|
||||||
compile: SpirvCompilation,
|
compile: SpirvCompilation,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
impl ReflectShader + CompileShader<T, Options = Opt, Context = Ctx>,
|
impl ReflectShader + CompileShader<T, Options = Opt, Context = Ctx>,
|
||||||
ShaderReflectError
|
ShaderReflectError,
|
||||||
> {
|
> {
|
||||||
fn lower_fragment_shader(words: &[u32]) -> Vec<u32> {
|
fn lower_fragment_shader(words: &[u32]) -> Vec<u32> {
|
||||||
let mut loader = rspirv::dr::Loader::new();
|
let mut loader = rspirv::dr::Loader::new();
|
||||||
|
|
|
@ -18,11 +18,12 @@ use rustc_hash::FxHashMap;
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// #![feature(type_alias_impl_trait)]
|
/// #![feature(type_alias_impl_trait)]
|
||||||
/// use librashader_reflect::back::CompileReflectShader;
|
/// use librashader_reflect::back::CompileReflectShader;
|
||||||
/// use librashader_reflect::back::targets::SPIRV;
|
/// use librashader_reflect::back::targets::{GLSL, SPIRV};
|
||||||
/// use librashader_reflect::front::SpirvCompilation;
|
/// use librashader_reflect::front::SpirvCompilation;
|
||||||
|
/// use librashader_reflect::reflect::cross::SpirvCross;
|
||||||
/// use librashader_reflect::reflect::presets::ShaderPassArtifact;
|
/// use librashader_reflect::reflect::presets::ShaderPassArtifact;
|
||||||
///
|
///
|
||||||
/// type VulkanPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation>>;
|
/// type VulkanPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross<GLSL>>>;
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// This allows a runtime to not name the backing type of the compiled artifact if not necessary.
|
/// This allows a runtime to not name the backing type of the compiled artifact if not necessary.
|
||||||
|
@ -35,12 +36,12 @@ impl<T: OutputTarget> CompilePresetTarget for T {}
|
||||||
pub trait CompilePresetTarget: OutputTarget {
|
pub trait CompilePresetTarget: OutputTarget {
|
||||||
/// Compile passes of a shader preset given the applicable
|
/// Compile passes of a shader preset given the applicable
|
||||||
/// shader output target, compilation type, and resulting error.
|
/// shader output target, compilation type, and resulting error.
|
||||||
fn compile_preset_passes<C, I, E>(
|
fn compile_preset_passes<C, I, R, E>(
|
||||||
passes: Vec<ShaderPassConfig>,
|
passes: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
Vec<ShaderPassArtifact<<Self as FromCompilation<I>>::Output>>,
|
Vec<ShaderPassArtifact<<Self as FromCompilation<I, R>>::Output>>,
|
||||||
ShaderSemantics,
|
ShaderSemantics,
|
||||||
),
|
),
|
||||||
E,
|
E,
|
||||||
|
@ -48,24 +49,24 @@ pub trait CompilePresetTarget: OutputTarget {
|
||||||
where
|
where
|
||||||
I: ShaderReflectObject,
|
I: ShaderReflectObject,
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
Self: FromCompilation<I>,
|
Self: FromCompilation<I, R>,
|
||||||
C: ShaderInputCompiler<I>,
|
C: ShaderInputCompiler<I>,
|
||||||
E: From<PreprocessError>,
|
E: From<PreprocessError>,
|
||||||
E: From<ShaderReflectError>,
|
E: From<ShaderReflectError>,
|
||||||
E: From<ShaderCompileError>,
|
E: From<ShaderCompileError>,
|
||||||
{
|
{
|
||||||
compile_preset_passes::<Self, C, I, E>(passes, textures)
|
compile_preset_passes::<Self, C, I, R, E>(passes, textures)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile passes of a shader preset given the applicable
|
/// Compile passes of a shader preset given the applicable
|
||||||
/// shader output target, compilation type, and resulting error.
|
/// shader output target, compilation type, and resulting error.
|
||||||
fn compile_preset_passes<T, C, I, E>(
|
fn compile_preset_passes<T, C, I, R, E>(
|
||||||
passes: Vec<ShaderPassConfig>,
|
passes: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
Vec<ShaderPassArtifact<<T as FromCompilation<I>>::Output>>,
|
Vec<ShaderPassArtifact<<T as FromCompilation<I, R>>::Output>>,
|
||||||
ShaderSemantics,
|
ShaderSemantics,
|
||||||
),
|
),
|
||||||
E,
|
E,
|
||||||
|
@ -73,7 +74,7 @@ fn compile_preset_passes<T, C, I, E>(
|
||||||
where
|
where
|
||||||
I: ShaderReflectObject,
|
I: ShaderReflectObject,
|
||||||
T: OutputTarget,
|
T: OutputTarget,
|
||||||
T: FromCompilation<I>,
|
T: FromCompilation<I, R>,
|
||||||
C: ShaderInputCompiler<I>,
|
C: ShaderInputCompiler<I>,
|
||||||
E: From<PreprocessError>,
|
E: From<PreprocessError>,
|
||||||
E: From<ShaderReflectError>,
|
E: From<ShaderReflectError>,
|
||||||
|
|
|
@ -25,6 +25,7 @@ use crate::{error, util, D3D11OutputView};
|
||||||
use librashader_cache::cache_shader_object;
|
use librashader_cache::cache_shader_object;
|
||||||
use librashader_cache::CachedCompilation;
|
use librashader_cache::CachedCompilation;
|
||||||
use librashader_presets::context::VideoDriver;
|
use librashader_presets::context::VideoDriver;
|
||||||
|
use librashader_reflect::reflect::cross::SpirvCross;
|
||||||
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
||||||
use librashader_runtime::binding::{BindingUtil, TextureInput};
|
use librashader_runtime::binding::{BindingUtil, TextureInput};
|
||||||
use librashader_runtime::framebuffer::FramebufferInit;
|
use librashader_runtime::framebuffer::FramebufferInit;
|
||||||
|
@ -73,18 +74,22 @@ pub(crate) struct FilterCommon {
|
||||||
pub(crate) draw_quad: DrawQuad,
|
pub(crate) draw_quad: DrawQuad,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation> + Send>;
|
type ShaderPassMeta =
|
||||||
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross<HLSL>> + Send>;
|
||||||
fn compile_passes(
|
fn compile_passes(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) = if !disable_cache {
|
let (passes, semantics) = if !disable_cache {
|
||||||
HLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
|
HLSL::compile_preset_passes::<
|
||||||
shaders, &textures,
|
Glslang,
|
||||||
)?
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross<HLSL>,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, SpirvCross<HLSL>, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
|
@ -48,6 +48,7 @@ use windows::Win32::System::Threading::{CreateEventA, WaitForSingleObject, INFIN
|
||||||
|
|
||||||
use librashader_cache::CachedCompilation;
|
use librashader_cache::CachedCompilation;
|
||||||
use librashader_presets::context::VideoDriver;
|
use librashader_presets::context::VideoDriver;
|
||||||
|
use librashader_reflect::reflect::cross::SpirvCross;
|
||||||
use librashader_runtime::framebuffer::FramebufferInit;
|
use librashader_runtime::framebuffer::FramebufferInit;
|
||||||
use librashader_runtime::render_target::RenderTarget;
|
use librashader_runtime::render_target::RenderTarget;
|
||||||
use librashader_runtime::scaling::ScaleFramebuffer;
|
use librashader_runtime::scaling::ScaleFramebuffer;
|
||||||
|
@ -145,18 +146,21 @@ impl Drop for FrameResiduals {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DxilShaderPassMeta =
|
type DxilShaderPassMeta =
|
||||||
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation> + Send>;
|
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation, SpirvCross<DXIL>> + Send>;
|
||||||
fn compile_passes_dxil(
|
fn compile_passes_dxil(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) = if !disable_cache {
|
let (passes, semantics) = if !disable_cache {
|
||||||
DXIL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
|
DXIL::compile_preset_passes::<
|
||||||
shaders, &textures,
|
Glslang,
|
||||||
)?
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross<DXIL>,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
DXIL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
DXIL::compile_preset_passes::<Glslang, SpirvCompilation, SpirvCross<DXIL>, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
@ -164,18 +168,21 @@ fn compile_passes_dxil(
|
||||||
Ok((passes, semantics))
|
Ok((passes, semantics))
|
||||||
}
|
}
|
||||||
type HlslShaderPassMeta =
|
type HlslShaderPassMeta =
|
||||||
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation> + Send>;
|
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation, SpirvCross<HLSL>> + Send>;
|
||||||
fn compile_passes_hlsl(
|
fn compile_passes_hlsl(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) = if !disable_cache {
|
let (passes, semantics) = if !disable_cache {
|
||||||
HLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
|
HLSL::compile_preset_passes::<
|
||||||
shaders, &textures,
|
Glslang,
|
||||||
)?
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross<HLSL>,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, SpirvCross<HLSL>, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
|
@ -20,6 +20,7 @@ use librashader_reflect::front::{Glslang, SpirvCompilation};
|
||||||
use librashader_reflect::reflect::semantics::{ShaderSemantics, UniformMeta};
|
use librashader_reflect::reflect::semantics::{ShaderSemantics, UniformMeta};
|
||||||
|
|
||||||
use librashader_cache::CachedCompilation;
|
use librashader_cache::CachedCompilation;
|
||||||
|
use librashader_reflect::reflect::cross::SpirvCross;
|
||||||
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
||||||
use librashader_reflect::reflect::ReflectShader;
|
use librashader_reflect::reflect::ReflectShader;
|
||||||
use librashader_runtime::binding::BindingUtil;
|
use librashader_runtime::binding::BindingUtil;
|
||||||
|
@ -97,18 +98,22 @@ impl<T: GLInterface> FilterChainImpl<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation>>;
|
type ShaderPassMeta =
|
||||||
|
ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation, SpirvCross<GLSL>>>;
|
||||||
fn compile_passes(
|
fn compile_passes(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
disable_cache: bool,
|
disable_cache: bool,
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) = if !disable_cache {
|
let (passes, semantics) = if !disable_cache {
|
||||||
GLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
|
GLSL::compile_preset_passes::<
|
||||||
shaders, &textures,
|
Glslang,
|
||||||
)?
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross<GLSL>,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
GLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
GLSL::compile_preset_passes::<Glslang, SpirvCompilation, SpirvCross<GLSL>, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
|
@ -34,6 +34,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use librashader_cache::CachedCompilation;
|
use librashader_cache::CachedCompilation;
|
||||||
use librashader_presets::context::VideoDriver;
|
use librashader_presets::context::VideoDriver;
|
||||||
|
use librashader_reflect::reflect::cross::SpirvCross;
|
||||||
use librashader_runtime::framebuffer::FramebufferInit;
|
use librashader_runtime::framebuffer::FramebufferInit;
|
||||||
use librashader_runtime::render_target::RenderTarget;
|
use librashader_runtime::render_target::RenderTarget;
|
||||||
use librashader_runtime::scaling::ScaleFramebuffer;
|
use librashader_runtime::scaling::ScaleFramebuffer;
|
||||||
|
@ -207,7 +208,9 @@ impl Drop for FrameResiduals {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation> + Send>;
|
type ShaderPassMeta = ShaderPassArtifact<
|
||||||
|
impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross<SPIRV>> + Send,
|
||||||
|
>;
|
||||||
fn compile_passes(
|
fn compile_passes(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
|
@ -217,12 +220,16 @@ fn compile_passes(
|
||||||
SPIRV::compile_preset_passes::<
|
SPIRV::compile_preset_passes::<
|
||||||
Glslang,
|
Glslang,
|
||||||
CachedCompilation<SpirvCompilation>,
|
CachedCompilation<SpirvCompilation>,
|
||||||
|
SpirvCross<SPIRV>,
|
||||||
FilterChainError,
|
FilterChainError,
|
||||||
>(shaders, &textures)?
|
>(shaders, &textures)?
|
||||||
} else {
|
} else {
|
||||||
SPIRV::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
SPIRV::compile_preset_passes::<
|
||||||
shaders, &textures,
|
Glslang,
|
||||||
)?
|
SpirvCompilation,
|
||||||
|
SpirvCross<SPIRV>,
|
||||||
|
FilterChainError,
|
||||||
|
>(shaders, &textures)?
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((passes, semantics))
|
Ok((passes, semantics))
|
||||||
|
|
|
@ -21,6 +21,7 @@ use crate::buffer::WgpuStagedBuffer;
|
||||||
use crate::draw_quad::DrawQuad;
|
use crate::draw_quad::DrawQuad;
|
||||||
use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode};
|
use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode};
|
||||||
use librashader_reflect::back::wgsl::WgslCompileOptions;
|
use librashader_reflect::back::wgsl::WgslCompileOptions;
|
||||||
|
use librashader_reflect::reflect::naga::Naga;
|
||||||
use librashader_runtime::framebuffer::FramebufferInit;
|
use librashader_runtime::framebuffer::FramebufferInit;
|
||||||
use librashader_runtime::render_target::RenderTarget;
|
use librashader_runtime::render_target::RenderTarget;
|
||||||
use librashader_runtime::scaling::ScaleFramebuffer;
|
use librashader_runtime::scaling::ScaleFramebuffer;
|
||||||
|
@ -37,13 +38,14 @@ use crate::options::{FilterChainOptionsWgpu, FrameOptionsWgpu};
|
||||||
use crate::samplers::SamplerSet;
|
use crate::samplers::SamplerSet;
|
||||||
use crate::texture::{InputImage, OwnedImage};
|
use crate::texture::{InputImage, OwnedImage};
|
||||||
|
|
||||||
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation> + Send>;
|
type ShaderPassMeta =
|
||||||
|
ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation, Naga> + Send>;
|
||||||
fn compile_passes(
|
fn compile_passes(
|
||||||
shaders: Vec<ShaderPassConfig>,
|
shaders: Vec<ShaderPassConfig>,
|
||||||
textures: &[TextureConfig],
|
textures: &[TextureConfig],
|
||||||
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
|
||||||
let (passes, semantics) =
|
let (passes, semantics) =
|
||||||
WGSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(
|
WGSL::compile_preset_passes::<Glslang, SpirvCompilation, Naga, FilterChainError>(
|
||||||
shaders, &textures,
|
shaders, &textures,
|
||||||
)?;
|
)?;
|
||||||
Ok((passes, semantics))
|
Ok((passes, semantics))
|
||||||
|
|
Loading…
Reference in a new issue