reflect: expose HLSL SM version

This commit is contained in:
chyyran 2023-02-01 18:58:21 -05:00
parent e66c2a628f
commit 5d260e77d5
2 changed files with 9 additions and 5 deletions

View file

@ -8,6 +8,9 @@ use crate::reflect::ReflectShader;
/// The GLSL version to use.
pub type GlslVersion = spirv_cross::glsl::Version;
/// The HLSL shader model version to use
pub type HlslVersion = spirv_cross::hlsl::ShaderModel;
/// The context for a GLSL compilation via spirv-cross.
pub struct CrossGlslContext {
/// A map of bindings of sampler names to binding locations.
@ -40,7 +43,7 @@ pub struct CrossHlslContext {
impl FromCompilation<GlslangCompilation> for HLSL {
type Target = HLSL;
type Options = Option<()>;
type Options = Option<HlslVersion>;
type Context = CrossHlslContext;
type Output = impl CompileShader<Self::Target, Options = Self::Options, Context = Self::Context>
+ ReflectShader;

View file

@ -13,7 +13,7 @@ use spirv_cross::hlsl::ShaderModel;
use spirv_cross::spirv::{Ast, Decoration, Module, Resource, ShaderResources, Type};
use spirv_cross::{glsl, hlsl, ErrorCode};
use crate::back::cross::{CrossGlslContext, CrossHlslContext};
use crate::back::cross::{CrossGlslContext, CrossHlslContext, HlslVersion};
use crate::back::targets::{GLSL, HLSL};
use crate::back::{CompileShader, ShaderCompilerOutput};
use crate::reflect::helper::{SemanticErrorBlame, TextureData, UboData};
@ -823,15 +823,16 @@ impl CompileShader<GLSL> for CrossReflect<glsl::Target> {
}
impl CompileShader<HLSL> for CrossReflect<hlsl::Target> {
type Options = Option<()>;
type Options = Option<HlslVersion>;
type Context = CrossHlslContext;
fn compile(
mut self,
_options: Self::Options,
options: Self::Options,
) -> Result<ShaderCompilerOutput<String, CrossHlslContext>, ShaderCompileError> {
let sm = options.unwrap_or(ShaderModel::V5_0);
let mut options = hlsl::CompilerOptions::default();
options.shader_model = ShaderModel::V5_0;
options.shader_model = sm;
self.vertex.set_compiler_options(&options)?;
self.fragment.set_compiler_options(&options)?;