reflect: seal ast output mutability after compilation
This commit is contained in:
parent
9cad2b9128
commit
43ec5173c1
|
@ -2,13 +2,13 @@ use crate::back::targets::{GLSL, HLSL};
|
||||||
use crate::back::{CompilerBackend, CompileShader, FromCompilation};
|
use crate::back::{CompilerBackend, CompileShader, FromCompilation};
|
||||||
use crate::error::ShaderReflectError;
|
use crate::error::ShaderReflectError;
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::shaderc::GlslangCompilation;
|
||||||
use crate::reflect::cross::{CompiledAst, GlslReflect, HlslReflect};
|
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
|
||||||
use crate::reflect::ReflectShader;
|
use crate::reflect::ReflectShader;
|
||||||
|
|
||||||
pub type GlVersion = spirv_cross::glsl::Version;
|
pub type GlVersion = spirv_cross::glsl::Version;
|
||||||
pub struct GlslangGlslContext {
|
pub struct GlslangGlslContext {
|
||||||
pub sampler_bindings: Vec<(String, u32)>,
|
pub sampler_bindings: Vec<(String, u32)>,
|
||||||
pub compiler: CompiledAst<spirv_cross::glsl::Target>,
|
pub compiler: CompiledProgram<spirv_cross::glsl::Target>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromCompilation<GlslangCompilation> for GLSL {
|
impl FromCompilation<GlslangCompilation> for GLSL {
|
||||||
|
@ -30,7 +30,7 @@ impl FromCompilation<GlslangCompilation> for GLSL {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GlslangHlslContext {
|
pub struct GlslangHlslContext {
|
||||||
pub compiler: CompiledAst<spirv_cross::hlsl::Target>,
|
pub compiler: CompiledProgram<spirv_cross::hlsl::Target>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::ops::Deref;
|
||||||
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::shaderc::GlslangCompilation;
|
||||||
use crate::reflect::semantics::{BindingStage, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, MemberOffset, PushReflection, ReflectSemantics, ShaderReflection, TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection, ValidateTypeSemantics, VariableMeta, VariableSemanticMap, VariableSemantics};
|
use crate::reflect::semantics::{BindingStage, MAX_BINDINGS_COUNT, MAX_PUSH_BUFFER_SIZE, MemberOffset, PushReflection, ReflectSemantics, ShaderReflection, TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection, ValidateTypeSemantics, VariableMeta, VariableSemanticMap, VariableSemantics};
|
||||||
|
@ -11,6 +12,7 @@ use crate::back::cross::{GlslangGlslContext, GlslangHlslContext};
|
||||||
use crate::back::targets::{GLSL, HLSL};
|
use crate::back::targets::{GLSL, HLSL};
|
||||||
use crate::back::{CompileShader, ShaderCompilerOutput};
|
use crate::back::{CompileShader, ShaderCompilerOutput};
|
||||||
|
|
||||||
|
|
||||||
pub struct CrossReflect<T>
|
pub struct CrossReflect<T>
|
||||||
where
|
where
|
||||||
T: spirv_cross::spirv::Target,
|
T: spirv_cross::spirv::Target,
|
||||||
|
@ -19,12 +21,25 @@ where
|
||||||
fragment: Ast<T>,
|
fragment: Ast<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CompiledAst<T>
|
///! The output of the SPIR-V AST after compilation.
|
||||||
|
///!
|
||||||
|
///! This output is immutable and can not be recompiled later.
|
||||||
|
pub struct CompiledAst<T: spirv_cross::spirv::Target>(Ast<T>);
|
||||||
|
impl<T: spirv_cross::spirv::Target> Deref for CompiledAst<T> {
|
||||||
|
type Target = Ast<T>;
|
||||||
|
|
||||||
|
fn deref(&self) -> &Self::Target {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///! The compiled SPIR-V program after compilation.
|
||||||
|
pub struct CompiledProgram<T>
|
||||||
where
|
where
|
||||||
T: spirv_cross::spirv::Target,
|
T: spirv_cross::spirv::Target,
|
||||||
{
|
{
|
||||||
pub vertex: Ast<T>,
|
pub vertex: CompiledAst<T>,
|
||||||
pub fragment: Ast<T>,
|
pub fragment: CompiledAst<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) type HlslReflect = CrossReflect<hlsl::Target>;
|
pub(crate) type HlslReflect = CrossReflect<hlsl::Target>;
|
||||||
|
@ -803,9 +818,9 @@ impl CompileShader<GLSL> for CrossReflect<glsl::Target> {
|
||||||
fragment: self.fragment.compile()?,
|
fragment: self.fragment.compile()?,
|
||||||
context: GlslangGlslContext {
|
context: GlslangGlslContext {
|
||||||
sampler_bindings: texture_fixups,
|
sampler_bindings: texture_fixups,
|
||||||
compiler: CompiledAst {
|
compiler: CompiledProgram {
|
||||||
vertex: self.vertex,
|
vertex: CompiledAst(self.vertex),
|
||||||
fragment: self.fragment,
|
fragment: CompiledAst(self.fragment),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -830,9 +845,9 @@ impl CompileShader<HLSL> for CrossReflect<hlsl::Target> {
|
||||||
vertex: self.vertex.compile()?,
|
vertex: self.vertex.compile()?,
|
||||||
fragment: self.fragment.compile()?,
|
fragment: self.fragment.compile()?,
|
||||||
context: GlslangHlslContext {
|
context: GlslangHlslContext {
|
||||||
compiler: CompiledAst {
|
compiler: CompiledProgram {
|
||||||
vertex: self.vertex,
|
vertex: CompiledAst(self.vertex),
|
||||||
fragment: self.fragment
|
fragment: CompiledAst(self.fragment)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue