mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-02-18 18:02:48 +00:00
[hlsl-out] Implement Access and Unary expressions
This commit is contained in:
parent
d3fe1c978b
commit
9b823c1b60
@ -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),
|
||||
|
@ -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))),
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user