api: clean up spirv-cross related apis
This commit is contained in:
parent
acca9ce6f6
commit
479015d223
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -630,6 +630,7 @@ dependencies = [
|
|||
"librashader-runtime-d3d11",
|
||||
"librashader-runtime-gl",
|
||||
"librashader-runtime-vk",
|
||||
"spirv_cross",
|
||||
"windows",
|
||||
]
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ pub enum PreprocessError {
|
|||
/// The given pragma was declared multiple times with differing values.
|
||||
#[error("duplicate pragma found")]
|
||||
DuplicatePragmaError(String),
|
||||
/// The imaged format requested by the shader was unknown or not supported.
|
||||
/// The image format requested by the shader was unknown or not supported.
|
||||
#[error("shader format is unknown or not found")]
|
||||
UnknownImageFormat,
|
||||
/// The stage declared by the shader source was not `vertex` or `fragment`.
|
||||
|
|
|
@ -20,7 +20,7 @@ impl FromCompilation<GlslangCompilation> for GLSL {
|
|||
type Target = GLSL;
|
||||
type Options = GlslVersion;
|
||||
type Context = CrossGlslContext;
|
||||
type Output = impl CompileShader<Self::Target, Options = GlslVersion, Context = CrossGlslContext>
|
||||
type Output = impl CompileShader<Self::Target, Options = GlslVersion, Context = Self::Context>
|
||||
+ ReflectShader;
|
||||
|
||||
fn from_compilation(
|
||||
|
@ -34,7 +34,8 @@ impl FromCompilation<GlslangCompilation> for GLSL {
|
|||
|
||||
/// The context for a HLSL compilation via spirv-cross.
|
||||
pub struct CrossHlslContext {
|
||||
pub compiler: CompiledProgram<spirv_cross::hlsl::Target>,
|
||||
/// The compiled HLSL program.
|
||||
pub artifact: CompiledProgram<spirv_cross::hlsl::Target>,
|
||||
}
|
||||
|
||||
impl FromCompilation<GlslangCompilation> for HLSL {
|
||||
|
|
|
@ -17,8 +17,8 @@ impl FromCompilation<GlslangCompilation> for SPIRV {
|
|||
type Target = SPIRV;
|
||||
type Options = Option<()>;
|
||||
type Context = ();
|
||||
type Output =
|
||||
impl CompileShader<Self::Target, Options = Option<()>, Context = ()> + ReflectShader;
|
||||
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context>
|
||||
+ ReflectShader;
|
||||
|
||||
fn from_compilation(
|
||||
compile: GlslangCompilation,
|
||||
|
|
|
@ -18,7 +18,7 @@ use crate::back::targets::{GLSL, HLSL};
|
|||
use crate::back::{CompileShader, ShaderCompilerOutput};
|
||||
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
|
||||
|
||||
pub struct CrossReflect<T>
|
||||
pub(crate) struct CrossReflect<T>
|
||||
where
|
||||
T: spirv_cross::spirv::Target,
|
||||
{
|
||||
|
@ -26,9 +26,9 @@ where
|
|||
fragment: Ast<T>,
|
||||
}
|
||||
|
||||
///! The output of the SPIR-V AST after compilation.
|
||||
///!
|
||||
///! This output is immutable and can not be recompiled later.
|
||||
///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>;
|
||||
|
@ -38,7 +38,7 @@ impl<T: spirv_cross::spirv::Target> Deref for CompiledAst<T> {
|
|||
}
|
||||
}
|
||||
|
||||
///! The compiled SPIR-V program after compilation.
|
||||
/// The compiled SPIR-V program after compilation.
|
||||
pub struct CompiledProgram<T>
|
||||
where
|
||||
T: spirv_cross::spirv::Target,
|
||||
|
@ -820,7 +820,7 @@ impl CompileShader<HLSL> for CrossReflect<hlsl::Target> {
|
|||
vertex: self.vertex.compile()?,
|
||||
fragment: self.fragment.compile()?,
|
||||
context: CrossHlslContext {
|
||||
compiler: CompiledProgram {
|
||||
artifact: CompiledProgram {
|
||||
vertex: CompiledAst(self.vertex),
|
||||
fragment: CompiledAst(self.fragment),
|
||||
},
|
||||
|
|
|
@ -23,6 +23,7 @@ librashader-runtime-gl = { path = "../librashader-runtime-gl", version = "0.1.0-
|
|||
librashader-runtime-vk = { path = "../librashader-runtime-vk", version = "0.1.0-beta.7", optional = true }
|
||||
|
||||
ash = { version = "0.37.1+1.3.235", optional = true }
|
||||
spirv_cross = { version = "0.23.1", optional = true, features = ["glsl"] }
|
||||
|
||||
[dependencies.windows]
|
||||
version = "0.44.0"
|
||||
|
@ -33,7 +34,7 @@ optional = true
|
|||
|
||||
[features]
|
||||
default = ["gl", "d3d11", "vk", "reflect", "preprocess", "presets" ]
|
||||
gl = [ "runtime", "librashader-common/opengl", "librashader-runtime-gl" ]
|
||||
gl = [ "runtime", "librashader-common/opengl", "librashader-runtime-gl", "spirv_cross" ]
|
||||
d3d11 = [ "runtime", "librashader-common/d3d11", "librashader-runtime-d3d11", "windows" ]
|
||||
vk = ["runtime", "librashader-common/vulkan", "librashader-runtime-vk", "ash" ]
|
||||
runtime = []
|
||||
|
|
|
@ -82,7 +82,25 @@ pub mod reflect {
|
|||
targets::OutputTarget, CompileShader, CompilerBackend, FromCompilation,
|
||||
ShaderCompilerOutput,
|
||||
};
|
||||
pub use librashader_reflect::front::shaderc::GlslangCompilation;
|
||||
|
||||
/// Reflection via SPIRV-Cross.
|
||||
pub mod cross {
|
||||
pub use librashader_reflect::front::shaderc::GlslangCompilation;
|
||||
|
||||
#[cfg(feature = "gl")]
|
||||
/// The version of GLSL to compile to.
|
||||
pub use spirv_cross::glsl::Version as GlslVersion;
|
||||
|
||||
#[cfg(feature = "gl")]
|
||||
pub use librashader_reflect::back::cross::CrossGlslContext;
|
||||
|
||||
#[cfg(any(feature = "d3d11", feature = "d3d12"))]
|
||||
pub use librashader_reflect::back::cross::CrossHlslContext;
|
||||
|
||||
pub use librashader_reflect::reflect::cross::CompiledAst;
|
||||
|
||||
pub use librashader_reflect::reflect::cross::CompiledProgram;
|
||||
}
|
||||
pub use librashader_reflect::reflect::semantics::BindingMeta;
|
||||
|
||||
/// Helpers to deal with image loading.
|
||||
|
|
Loading…
Reference in a new issue