From 9b823c1b60c6df40cc0b2fecada891b1c209bea5 Mon Sep 17 00:00:00 2001 From: Gordon-F Date: Mon, 21 Jun 2021 23:32:32 +0300 Subject: [PATCH] [hlsl-out] Implement Access and Unary expressions --- src/back/hlsl/mod.rs | 2 +- src/back/hlsl/writer.rs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/back/hlsl/mod.rs b/src/back/hlsl/mod.rs index 3b94239a05..5825f59905 100644 --- a/src/back/hlsl/mod.rs +++ b/src/back/hlsl/mod.rs @@ -50,7 +50,7 @@ impl Default for Options { pub enum Error { #[error(transparent)] IoError(#[from] FmtError), - #[error("BuiltIn {0:?} is not supported")] + #[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), diff --git a/src/back/hlsl/writer.rs b/src/back/hlsl/writer.rs index e2af05f64b..aa81c9d6d6 100644 --- a/src/back/hlsl/writer.rs +++ b/src/back/hlsl/writer.rs @@ -937,6 +937,38 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, "{}", name)?; } Expression::Load { pointer } => self.write_expr(module, pointer, func_ctx)?, + Expression::Access { base, index } => { + self.write_expr(module, base, func_ctx)?; + write!(self.out, "[")?; + self.write_expr(module, index, func_ctx)?; + write!(self.out, "]")? + } + Expression::Unary { op, expr } => { + // https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-operators#unary-operators + write!( + self.out, + "({} ", + match op { + crate::UnaryOperator::Negate => "-", + crate::UnaryOperator::Not => + match *func_ctx.info[expr].ty.inner_with(&module.types) { + TypeInner::Scalar { + kind: ScalarKind::Bool, + .. + } => "!", + ref other => + return Err(Error::Custom(format!( + "Cannot apply not to type {:?}", + other + ))), + }, + } + )?; + + self.write_expr(module, expr, func_ctx)?; + + write!(self.out, ")")? + } _ => return Err(Error::Unimplemented(format!("write_expr {:?}", expression))), }