mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-24 00:11:11 +01:00
[wgsl-in] eagerly evaluate const-expressions
[wgsl-in] support const-expressions in attributes allow `Splat` as an evaluated const-expression type
This commit is contained in:
1 parent
c5d884fca8
commit
a730236b68
44 files changed
+2917
-2770
No files matched your search
+17
-14
@@ -2078,6 +2078,19 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
Expression::Splat { size, value } => {
|
||||
// hlsl is not supported one value constructor
|
||||
// if we write, for example, int4(0), dxc returns error:
|
||||
// error: too few elements in vector initialization (expected 4 elements, have 1)
|
||||
let number_of_components = match size {
|
||||
crate::VectorSize::Bi => "xx",
|
||||
crate::VectorSize::Tri => "xxx",
|
||||
crate::VectorSize::Quad => "xxxx",
|
||||
};
|
||||
write!(self.out, "(")?;
|
||||
write_expression(self, value)?;
|
||||
write!(self.out, ").{number_of_components}")?
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
@@ -2135,7 +2148,8 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
Expression::Literal(_)
|
||||
| Expression::Constant(_)
|
||||
| Expression::ZeroValue(_)
|
||||
| Expression::Compose { .. } => {
|
||||
| Expression::Compose { .. }
|
||||
| Expression::Splat { .. } => {
|
||||
self.write_possibly_const_expression(
|
||||
module,
|
||||
expr,
|
||||
@@ -2423,7 +2437,9 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
|
||||
if let Some(offset) = offset {
|
||||
write!(self.out, ", ")?;
|
||||
write!(self.out, "int2(")?; // work around https://github.com/microsoft/DirectXShaderCompiler/issues/5082#issuecomment-1540147807
|
||||
self.write_const_expression(module, offset)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
|
||||
write!(self.out, ")")?;
|
||||
@@ -3154,19 +3170,6 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
self.write_expr(module, argument, func_ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
Expression::Splat { size, value } => {
|
||||
// hlsl is not supported one value constructor
|
||||
// if we write, for example, int4(0), dxc returns error:
|
||||
// error: too few elements in vector initialization (expected 4 elements, have 1)
|
||||
let number_of_components = match size {
|
||||
crate::VectorSize::Bi => "xx",
|
||||
crate::VectorSize::Tri => "xxx",
|
||||
crate::VectorSize::Quad => "xxxx",
|
||||
};
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(module, value, func_ctx)?;
|
||||
write!(self.out, ").{number_of_components}")?
|
||||
}
|
||||
Expression::Select {
|
||||
condition,
|
||||
accept,
|
||||
|
||||
Reference in new issue
Block a user