[hlsl-out] Add enum with supported shader models

This commit is contained in:
Gordon-F
2021-06-23 20:55:24 +03:00
committed by Dzmitry Malyshau
parent c9a782f8d6
commit 391983459a
3 changed files with 18 additions and 25 deletions

View File

@@ -103,10 +103,16 @@ fn main() {
};
}
"shader-model" => {
use naga::back::hlsl::{ShaderModel, DEFAULT_SHADER_MODEL};
use naga::back::hlsl::ShaderModel;
let string = args.next().unwrap();
params.hlsl.shader_model =
ShaderModel::new(string.parse().unwrap_or(DEFAULT_SHADER_MODEL));
let sm_numb = string.parse::<u16>().unwrap();
let sm = match string.parse().unwrap() {
50 => ShaderModel::V5_0,
51 => ShaderModel::V5_1,
60 => ShaderModel::V6_0,
_ => panic!("Unsupported shader model: {}", sm_numb),
};
params.hlsl.shader_model = sm;
}
other => log::warn!("Unknown parameter: {}", other),
}

View File

@@ -6,20 +6,13 @@ use thiserror::Error;
pub use writer::Writer;
pub const DEFAULT_SHADER_MODEL: u16 = 50;
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
pub struct ShaderModel(u16);
impl ShaderModel {
pub fn new(shader_model: u16) -> Self {
Self(shader_model)
}
}
impl Default for ShaderModel {
fn default() -> Self {
Self(DEFAULT_SHADER_MODEL)
}
/// A HLSL shader model version.
#[allow(non_snake_case, non_camel_case_types)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum ShaderModel {
V5_0,
V5_1,
V6_0,
}
/// Structure that contains the configuration used in the [`Writer`](Writer)
@@ -38,7 +31,7 @@ pub struct Options {
impl Default for Options {
fn default() -> Self {
Options {
shader_model: ShaderModel(50),
shader_model: ShaderModel::V5_0,
vertex_entry_point_name: String::from("vert_main"),
fragment_entry_point_name: String::from("frag_main"),
compute_entry_point_name: String::from("comp_main"),
@@ -50,8 +43,6 @@ impl Default for Options {
pub enum Error {
#[error(transparent)]
IoError(#[from] FmtError),
#[error("Shader model {0:?} is not supported")]
UnsupportedShaderModel(ShaderModel),
#[error("A scalar with an unsupported width was requested: {0:?} {1:?}")]
UnsupportedScalar(crate::ScalarKind, crate::Bytes),
#[error("{0}")]

View File

@@ -1,6 +1,6 @@
//TODO: temp
#![allow(dead_code)]
use super::{Error, Options, ShaderModel};
use super::{Error, Options};
use crate::{
back,
proc::{self, NameKey},
@@ -55,10 +55,6 @@ impl<'a, W: Write> Writer<'a, W> {
}
pub fn write(&mut self, module: &Module, info: &valid::ModuleInfo) -> BackendResult {
if self.options.shader_model < ShaderModel::default() {
return Err(Error::UnsupportedShaderModel(self.options.shader_model));
}
self.reset(module);
// Write all constants