mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Inline identifiers into format strings.
[Since Rust 1.58], Rust format strings have been able to "capture
arguments simply by writing {ident} in the string." Clippy 1.67 made
the corresponding warning, `uninlined_format_args`, warn-by-default.
Inlined arguments seem more readable, so Naga should adopt them.
[Since Rust 1.58]: https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1580-2022-01-13
This commit is contained in:
committed by
Teodor Tanasoaia
parent
26dca556a9
commit
ca99d8bcbc
@@ -99,8 +99,7 @@ impl FromStr for BoundsCheckPolicyArg {
|
||||
"unchecked" => BoundsCheckPolicy::Unchecked,
|
||||
_ => {
|
||||
return Err(format!(
|
||||
"Invalid value for --index-bounds-check-policy: {}",
|
||||
s
|
||||
"Invalid value for --index-bounds-check-policy: {s}"
|
||||
))
|
||||
}
|
||||
}))
|
||||
@@ -120,7 +119,7 @@ impl FromStr for ShaderModelArg {
|
||||
"50" => ShaderModel::V5_0,
|
||||
"51" => ShaderModel::V5_1,
|
||||
"60" => ShaderModel::V6_0,
|
||||
_ => return Err(format!("Invalid value for --shader-model: {}", s)),
|
||||
_ => return Err(format!("Invalid value for --shader-model: {s}")),
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -139,7 +138,7 @@ impl FromStr for GlslProfileArg {
|
||||
} else if s.starts_with("es") {
|
||||
Version::new_gles(s[2..].parse().unwrap_or(310))
|
||||
} else {
|
||||
return Err(format!("Unknown profile: {}", s));
|
||||
return Err(format!("Unknown profile: {s}"));
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -163,7 +162,7 @@ trait PrettyResult {
|
||||
}
|
||||
|
||||
fn print_err(error: &dyn Error) {
|
||||
eprint!("{}", error);
|
||||
eprint!("{error}");
|
||||
|
||||
let mut e = error.source();
|
||||
if e.is_some() {
|
||||
@@ -173,7 +172,7 @@ fn print_err(error: &dyn Error) {
|
||||
}
|
||||
|
||||
while let Some(source) = e {
|
||||
eprintln!("\t{}", source);
|
||||
eprintln!("\t{source}");
|
||||
e = source.source();
|
||||
}
|
||||
}
|
||||
@@ -366,10 +365,10 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
use std::io::Write;
|
||||
|
||||
let mut file = fs::File::create(output_path)?;
|
||||
writeln!(file, "{:#?}", module)?;
|
||||
writeln!(file, "{module:#?}")?;
|
||||
if let Some(ref info) = info {
|
||||
writeln!(file)?;
|
||||
writeln!(file, "{:#?}", info)?;
|
||||
writeln!(file, "{info:#?}")?;
|
||||
}
|
||||
}
|
||||
"bin" => {
|
||||
@@ -515,7 +514,7 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fs::write(output_path, wgsl)?;
|
||||
}
|
||||
other => {
|
||||
println!("Unknown output extension: {}", other);
|
||||
println!("Unknown output extension: {other}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,15 +304,13 @@ fn write_fun(
|
||||
for (index, label) in sg.nodes.into_iter().enumerate() {
|
||||
writeln!(
|
||||
output,
|
||||
"\t\t{}_s{} [ shape=square label=\"{}\" ]",
|
||||
prefix, index, label,
|
||||
"\t\t{prefix}_s{index} [ shape=square label=\"{label}\" ]",
|
||||
)?;
|
||||
}
|
||||
for (from, to, label) in sg.flow {
|
||||
writeln!(
|
||||
output,
|
||||
"\t\t{}_s{} -> {}_s{} [ arrowhead=tee label=\"{}\" ]",
|
||||
prefix, from, prefix, to, label,
|
||||
"\t\t{prefix}_s{from} -> {prefix}_s{to} [ arrowhead=tee label=\"{label}\" ]",
|
||||
)?;
|
||||
}
|
||||
for (from, to, label, color_id) in sg.jumps {
|
||||
@@ -384,12 +382,12 @@ fn write_function_expressions(
|
||||
}
|
||||
E::AccessIndex { base, index } => {
|
||||
edges.insert("base", base);
|
||||
(format!("AccessIndex[{}]", index).into(), 1)
|
||||
(format!("AccessIndex[{index}]").into(), 1)
|
||||
}
|
||||
E::Constant(_) => ("Constant".into(), 2),
|
||||
E::Splat { size, value } => {
|
||||
edges.insert("value", value);
|
||||
(format!("Splat{:?}", size).into(), 3)
|
||||
(format!("Splat{size:?}").into(), 3)
|
||||
}
|
||||
E::Swizzle {
|
||||
size,
|
||||
@@ -403,7 +401,7 @@ fn write_function_expressions(
|
||||
payload = Some(Payload::Arguments(components));
|
||||
("Compose".into(), 3)
|
||||
}
|
||||
E::FunctionArgument(index) => (format!("Argument[{}]", index).into(), 1),
|
||||
E::FunctionArgument(index) => (format!("Argument[{index}]").into(), 1),
|
||||
E::GlobalVariable(h) => {
|
||||
payload = Some(Payload::Global(h));
|
||||
("Global".into(), 2)
|
||||
@@ -450,7 +448,7 @@ fn write_function_expressions(
|
||||
edges.insert("depth_ref", expr);
|
||||
}
|
||||
let string = match gather {
|
||||
Some(component) => Cow::Owned(format!("ImageGather{:?}", component)),
|
||||
Some(component) => Cow::Owned(format!("ImageGather{component:?}")),
|
||||
_ => Cow::Borrowed("ImageSample"),
|
||||
};
|
||||
(string, 5)
|
||||
@@ -484,18 +482,18 @@ fn write_function_expressions(
|
||||
}
|
||||
Cow::from("ImageSize")
|
||||
}
|
||||
_ => Cow::Owned(format!("{:?}", query)),
|
||||
_ => Cow::Owned(format!("{query:?}")),
|
||||
};
|
||||
(args, 7)
|
||||
}
|
||||
E::Unary { op, expr } => {
|
||||
edges.insert("expr", expr);
|
||||
(format!("{:?}", op).into(), 6)
|
||||
(format!("{op:?}").into(), 6)
|
||||
}
|
||||
E::Binary { op, left, right } => {
|
||||
edges.insert("left", left);
|
||||
edges.insert("right", right);
|
||||
(format!("{:?}", op).into(), 6)
|
||||
(format!("{op:?}").into(), 6)
|
||||
}
|
||||
E::Select {
|
||||
condition,
|
||||
@@ -509,11 +507,11 @@ fn write_function_expressions(
|
||||
}
|
||||
E::Derivative { axis, expr } => {
|
||||
edges.insert("", expr);
|
||||
(format!("d{:?}", axis).into(), 8)
|
||||
(format!("d{axis:?}").into(), 8)
|
||||
}
|
||||
E::Relational { fun, argument } => {
|
||||
edges.insert("arg", argument);
|
||||
(format!("{:?}", fun).into(), 6)
|
||||
(format!("{fun:?}").into(), 6)
|
||||
}
|
||||
E::Math {
|
||||
fun,
|
||||
@@ -532,7 +530,7 @@ fn write_function_expressions(
|
||||
if let Some(expr) = arg3 {
|
||||
edges.insert("arg3", expr);
|
||||
}
|
||||
(format!("{:?}", fun).into(), 7)
|
||||
(format!("{fun:?}").into(), 7)
|
||||
}
|
||||
E::As {
|
||||
kind,
|
||||
@@ -541,8 +539,8 @@ fn write_function_expressions(
|
||||
} => {
|
||||
edges.insert("", expr);
|
||||
let string = match convert {
|
||||
Some(width) => format!("Convert<{:?},{}>", kind, width),
|
||||
None => format!("Bitcast<{:?}>", kind),
|
||||
Some(width) => format!("Convert<{kind:?},{width}>"),
|
||||
None => format!("Bitcast<{kind:?}>"),
|
||||
};
|
||||
(string.into(), 3)
|
||||
}
|
||||
@@ -644,7 +642,7 @@ pub fn write(
|
||||
|
||||
for (handle, fun) in module.functions.iter() {
|
||||
let prefix = format!("f{}", handle.index());
|
||||
writeln!(output, "\tsubgraph cluster_{} {{", prefix)?;
|
||||
writeln!(output, "\tsubgraph cluster_{prefix} {{")?;
|
||||
writeln!(
|
||||
output,
|
||||
"\t\tlabel=\"Function{:?}/'{}'\"",
|
||||
@@ -656,8 +654,8 @@ pub fn write(
|
||||
writeln!(output, "\t}}")?;
|
||||
}
|
||||
for (ep_index, ep) in module.entry_points.iter().enumerate() {
|
||||
let prefix = format!("ep{}", ep_index);
|
||||
writeln!(output, "\tsubgraph cluster_{} {{", prefix)?;
|
||||
let prefix = format!("ep{ep_index}");
|
||||
writeln!(output, "\tsubgraph cluster_{prefix} {{")?;
|
||||
writeln!(output, "\t\tlabel=\"{:?}/'{}'\"", ep.stage, ep.name)?;
|
||||
let info = mod_info.map(|a| a.get_entry_point(ep_index));
|
||||
write_fun(&mut output, prefix, &ep.function, info, &options)?;
|
||||
|
||||
@@ -198,8 +198,8 @@ impl PartialOrd for Version {
|
||||
impl fmt::Display for Version {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
Version::Desktop(v) => write!(f, "{} core", v),
|
||||
Version::Embedded { version: v, .. } => write!(f, "{} es", v),
|
||||
Version::Desktop(v) => write!(f, "{v} core"),
|
||||
Version::Embedded { version: v, .. } => write!(f, "{v} es"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,7 +327,7 @@ impl fmt::Display for VaryingName<'_> {
|
||||
// fragment to pipeline
|
||||
(ShaderStage::Fragment, true) => "fs2p",
|
||||
};
|
||||
write!(f, "_{}_location{}", prefix, location,)
|
||||
write!(f, "_{prefix}_location{location}",)
|
||||
}
|
||||
crate::Binding::BuiltIn(built_in) => {
|
||||
write!(
|
||||
@@ -563,7 +563,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Cd::LessEqual => "less",
|
||||
Cd::Unchanged => "unchanged",
|
||||
};
|
||||
writeln!(self.out, "layout (depth_{}) out float gl_FragDepth;", depth)?;
|
||||
writeln!(self.out, "layout (depth_{depth}) out float gl_FragDepth;")?;
|
||||
}
|
||||
writeln!(self.out)?;
|
||||
} else {
|
||||
@@ -576,7 +576,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
if self.entry_point.stage == ShaderStage::Vertex && self.options.version.is_webgl() {
|
||||
if let Some(multiview) = self.multiview.as_ref() {
|
||||
writeln!(self.out, "layout(num_views = {}) in;", multiview)?;
|
||||
writeln!(self.out, "layout(num_views = {multiview}) in;")?;
|
||||
writeln!(self.out)?;
|
||||
}
|
||||
}
|
||||
@@ -597,7 +597,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
.is_dynamically_sized(&self.module.types)
|
||||
{
|
||||
let name = &self.names[&NameKey::Type(handle)];
|
||||
write!(self.out, "struct {} ", name)?;
|
||||
write!(self.out, "struct {name} ")?;
|
||||
self.write_struct_body(handle, members)?;
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
@@ -653,7 +653,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if layout_binding.is_some() || storage_format_access.is_some() {
|
||||
write!(self.out, "layout(")?;
|
||||
if let Some(binding) = layout_binding {
|
||||
write!(self.out, "binding = {}", binding)?;
|
||||
write!(self.out, "binding = {binding}")?;
|
||||
}
|
||||
if let Some((format, _)) = storage_format_access {
|
||||
let format_str = glsl_storage_format(format);
|
||||
@@ -661,7 +661,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Some(_) => ",",
|
||||
None => "",
|
||||
};
|
||||
write!(self.out, "{}{}", separator, format_str)?;
|
||||
write!(self.out, "{separator}{format_str}")?;
|
||||
}
|
||||
write!(self.out, ") ")?;
|
||||
}
|
||||
@@ -683,7 +683,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// Finally write the name and end the global with a `;`
|
||||
// The leading space is important
|
||||
let global_name = self.get_global_name(handle, global);
|
||||
writeln!(self.out, " {};", global_name)?;
|
||||
writeln!(self.out, " {global_name};")?;
|
||||
writeln!(self.out)?;
|
||||
|
||||
self.reflection_names_globals.insert(handle, global_name);
|
||||
@@ -717,7 +717,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
self.write_type(ty)?;
|
||||
}
|
||||
};
|
||||
write!(self.out, " {} = ", name)?;
|
||||
write!(self.out, " {name} = ")?;
|
||||
self.write_constant(handle)?;
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
@@ -777,11 +777,11 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Uint(size),
|
||||
} => write!(self.out, "{}", size)?,
|
||||
} => write!(self.out, "{size}")?,
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Sint(size),
|
||||
} => write!(self.out, "{}", size)?,
|
||||
} => write!(self.out, "{size}")?,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
@@ -865,7 +865,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
| TypeInner::Image { .. }
|
||||
| TypeInner::Sampler { .. }
|
||||
| TypeInner::BindingArray { .. } => {
|
||||
return Err(Error::Custom(format!("Unable to write type {:?}", inner)))
|
||||
return Err(Error::Custom(format!("Unable to write type {inner:?}")))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,7 +890,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
TypeInner::Struct { .. } => {
|
||||
// Get the struct name
|
||||
let name = &self.names[&NameKey::Type(ty)];
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
// glsl array has the size separated from the base type
|
||||
@@ -972,7 +972,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
crate::AddressSpace::Uniform => "std140, ",
|
||||
_ => "",
|
||||
};
|
||||
write!(self.out, "layout({}binding = {}) ", layout, binding)?
|
||||
write!(self.out, "layout({layout}binding = {binding}) ")?
|
||||
}
|
||||
None => {
|
||||
log::debug!("unassigned binding for {:?}", global.name);
|
||||
@@ -991,7 +991,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
|
||||
if let Some(storage_qualifier) = glsl_storage_qualifier(global.space) {
|
||||
write!(self.out, "{} ", storage_qualifier)?;
|
||||
write!(self.out, "{storage_qualifier} ")?;
|
||||
}
|
||||
|
||||
match global.space {
|
||||
@@ -1071,7 +1071,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
self.block_id.generate(),
|
||||
self.entry_point.stage,
|
||||
);
|
||||
write!(self.out, "{} ", block_name)?;
|
||||
write!(self.out, "{block_name} ")?;
|
||||
self.reflection_names_globals.insert(handle, block_name);
|
||||
|
||||
match self.module.types[global.ty].inner {
|
||||
@@ -1272,7 +1272,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
// Write the I/O locations, if allowed
|
||||
if self.options.version.supports_explicit_locations() || !emit_interpolation_and_auxiliary {
|
||||
write!(self.out, "layout(location = {}) ", location)?;
|
||||
write!(self.out, "layout(location = {location}) ")?;
|
||||
}
|
||||
|
||||
// Write the interpolation qualifier.
|
||||
@@ -1290,7 +1290,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if let Some(sampling) = sampling {
|
||||
if emit_interpolation_and_auxiliary {
|
||||
if let Some(qualifier) = glsl_sampling(sampling) {
|
||||
write!(self.out, "{} ", qualifier)?;
|
||||
write!(self.out, "{qualifier} ")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1314,7 +1314,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
output,
|
||||
targetting_webgl: self.options.version.is_webgl(),
|
||||
};
|
||||
writeln!(self.out, " {};", vname)?;
|
||||
writeln!(self.out, " {vname};")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1366,7 +1366,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
back::FunctionType::Function(handle) => &self.names[&NameKey::Function(handle)],
|
||||
back::FunctionType::EntryPoint(_) => "main",
|
||||
};
|
||||
write!(self.out, " {}(", function_name)?;
|
||||
write!(self.out, " {function_name}(")?;
|
||||
|
||||
// Write the comma separated argument list
|
||||
//
|
||||
@@ -1448,7 +1448,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
write!(self.out, "{}", back::INDENT)?;
|
||||
self.write_type(arg.ty)?;
|
||||
let name = &self.names[&NameKey::EntryPointArgument(ep_index, index as u32)];
|
||||
write!(self.out, " {}", name)?;
|
||||
write!(self.out, " {name}")?;
|
||||
write!(self.out, " = ")?;
|
||||
match self.module.types[arg.ty].inner {
|
||||
crate::TypeInner::Struct { ref members, .. } => {
|
||||
@@ -1464,7 +1464,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if index != 0 {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
write!(self.out, "{}", varying_name)?;
|
||||
write!(self.out, "{varying_name}")?;
|
||||
}
|
||||
writeln!(self.out, ");")?;
|
||||
}
|
||||
@@ -1475,7 +1475,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
output: false,
|
||||
targetting_webgl: self.options.version.is_webgl(),
|
||||
};
|
||||
writeln!(self.out, "{};", varying_name)?;
|
||||
writeln!(self.out, "{varying_name};")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1547,8 +1547,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}if (gl_GlobalInvocationID == uvec3(0u)) {{",
|
||||
level
|
||||
"{level}if (gl_GlobalInvocationID == uvec3(0u)) {{"
|
||||
)?;
|
||||
|
||||
for (handle, var) in vars {
|
||||
@@ -1558,7 +1557,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?;
|
||||
writeln!(self.out, "{level}}}")?;
|
||||
self.write_barrier(crate::Barrier::WORK_GROUP, level)?;
|
||||
}
|
||||
|
||||
@@ -1607,17 +1606,17 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
ref value,
|
||||
} => match *value {
|
||||
// Signed integers don't need anything special
|
||||
Sv::Sint(int) => write!(self.out, "{}", int)?,
|
||||
Sv::Sint(int) => write!(self.out, "{int}")?,
|
||||
// Unsigned integers need a `u` at the end
|
||||
//
|
||||
// While `core` doesn't necessarily need it, it's allowed and since `es` needs it we
|
||||
// always write it as the extra branch wouldn't have any benefit in readability
|
||||
Sv::Uint(int) => write!(self.out, "{}u", int)?,
|
||||
Sv::Uint(int) => write!(self.out, "{int}u")?,
|
||||
// Floats are written using `Debug` instead of `Display` because it always appends the
|
||||
// decimal part even it's zero which is needed for a valid glsl float constant
|
||||
Sv::Float(float) => write!(self.out, "{:?}", float)?,
|
||||
Sv::Float(float) => write!(self.out, "{float:?}")?,
|
||||
// Booleans are either `true` or `false` so nothing special needs to be done
|
||||
Sv::Bool(boolean) => write!(self.out, "{}", boolean)?,
|
||||
Sv::Bool(boolean) => write!(self.out, "{boolean}")?,
|
||||
},
|
||||
// Composite constant are created using the same syntax as compose
|
||||
// `type(components)` where `components` is a comma separated list of constants
|
||||
@@ -1662,13 +1661,13 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// it shouldn't produce large expressions.
|
||||
self.write_expr(arg, ctx)?;
|
||||
// Access the current component on the first vector
|
||||
write!(self.out, ".{} * ", component)?;
|
||||
write!(self.out, ".{component} * ")?;
|
||||
// Write the second vector expression, this expression is marked to be
|
||||
// cached so unless it can't be cached (for example, it's a Constant)
|
||||
// it shouldn't produce large expressions.
|
||||
self.write_expr(arg1, ctx)?;
|
||||
// Access the current component on the second vector
|
||||
write!(self.out, ".{}", component)?;
|
||||
write!(self.out, ".{component}")?;
|
||||
}
|
||||
|
||||
write!(self.out, ")")?;
|
||||
@@ -1787,14 +1786,14 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
} = *ctx.info[image].ty.inner_with(&self.module.types)
|
||||
{
|
||||
if let proc::BoundsCheckPolicy::Restrict = self.policies.image {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_clamped_lod(ctx, handle, image, level_expr)?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(name) = expr_name {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_named_expr(handle, name, ctx)?;
|
||||
}
|
||||
}
|
||||
@@ -1803,13 +1802,13 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// We could also just print the statements but this is more readable and maps more
|
||||
// closely to the IR
|
||||
Statement::Block(ref block) => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "{{")?;
|
||||
for sta in block.iter() {
|
||||
// Increase the indentation to help with readability
|
||||
self.write_stmt(sta, ctx, level.next())?
|
||||
}
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// Ifs are written as in C:
|
||||
// ```
|
||||
@@ -1824,7 +1823,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
ref accept,
|
||||
ref reject,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "if (")?;
|
||||
self.write_expr(condition, ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
@@ -1837,7 +1836,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// If there are no statements in the reject block we skip writing it
|
||||
// This is only for readability
|
||||
if !reject.is_empty() {
|
||||
writeln!(self.out, "{}}} else {{", level)?;
|
||||
writeln!(self.out, "{level}}} else {{")?;
|
||||
|
||||
for sta in reject {
|
||||
// Increase indentation to help with readability
|
||||
@@ -1845,7 +1844,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// Switch are written as in C:
|
||||
// ```
|
||||
@@ -1868,7 +1867,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
ref cases,
|
||||
} => {
|
||||
// Start the switch
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "switch(")?;
|
||||
self.write_expr(selector, ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
@@ -1885,9 +1884,9 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
for case in cases {
|
||||
match case.value {
|
||||
crate::SwitchValue::Integer(value) => {
|
||||
write!(self.out, "{}case {}{}:", l2, value, type_postfix)?
|
||||
write!(self.out, "{l2}case {value}{type_postfix}:")?
|
||||
}
|
||||
crate::SwitchValue::Default => write!(self.out, "{}default:", l2)?,
|
||||
crate::SwitchValue::Default => write!(self.out, "{l2}default:")?,
|
||||
}
|
||||
|
||||
let write_block_braces = !(case.fall_through && case.body.is_empty());
|
||||
@@ -1906,11 +1905,11 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
|
||||
if write_block_braces {
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
writeln!(self.out, "{l2}}}")?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// Loops in naga IR are based on wgsl loops, glsl can emulate the behaviour by using a
|
||||
// while true loop and appending the continuing block to the body resulting on:
|
||||
@@ -1929,45 +1928,45 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
} => {
|
||||
if !continuing.is_empty() || break_if.is_some() {
|
||||
let gate_name = self.namer.call("loop_init");
|
||||
writeln!(self.out, "{}bool {} = true;", level, gate_name)?;
|
||||
writeln!(self.out, "{}while(true) {{", level)?;
|
||||
writeln!(self.out, "{level}bool {gate_name} = true;")?;
|
||||
writeln!(self.out, "{level}while(true) {{")?;
|
||||
let l2 = level.next();
|
||||
let l3 = l2.next();
|
||||
writeln!(self.out, "{}if (!{}) {{", l2, gate_name)?;
|
||||
writeln!(self.out, "{l2}if (!{gate_name}) {{")?;
|
||||
for sta in continuing {
|
||||
self.write_stmt(sta, ctx, l3)?;
|
||||
}
|
||||
if let Some(condition) = break_if {
|
||||
write!(self.out, "{}if (", l3)?;
|
||||
write!(self.out, "{l3}if (")?;
|
||||
self.write_expr(condition, ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
writeln!(self.out, "{}break;", l3.next())?;
|
||||
writeln!(self.out, "{}}}", l3)?;
|
||||
writeln!(self.out, "{l3}}}")?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
writeln!(self.out, "{l2}}}")?;
|
||||
writeln!(self.out, "{}{} = false;", level.next(), gate_name)?;
|
||||
} else {
|
||||
writeln!(self.out, "{}while(true) {{", level)?;
|
||||
writeln!(self.out, "{level}while(true) {{")?;
|
||||
}
|
||||
for sta in body {
|
||||
self.write_stmt(sta, ctx, level.next())?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// Break, continue and return as written as in C
|
||||
// `break;`
|
||||
Statement::Break => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "break;")?
|
||||
}
|
||||
// `continue;`
|
||||
Statement::Continue => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "continue;")?
|
||||
}
|
||||
// `return expr;`, `expr` is optional
|
||||
Statement::Return { value } => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
match ctx.ty {
|
||||
back::FunctionType::Function(_) => {
|
||||
write!(self.out, "return")?;
|
||||
@@ -1995,7 +1994,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
)?;
|
||||
self.write_expr(value, ctx)?;
|
||||
writeln!(self.out, ";")?;
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
Some(return_struct)
|
||||
}
|
||||
_ => None,
|
||||
@@ -2024,10 +2023,10 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
output: true,
|
||||
targetting_webgl: self.options.version.is_webgl(),
|
||||
};
|
||||
write!(self.out, "{} = ", varying_name)?;
|
||||
write!(self.out, "{varying_name} = ")?;
|
||||
|
||||
if let Some(struct_name) = temp_struct_name {
|
||||
write!(self.out, "{}", struct_name)?;
|
||||
write!(self.out, "{struct_name}")?;
|
||||
} else {
|
||||
self.write_expr(value, ctx)?;
|
||||
}
|
||||
@@ -2039,7 +2038,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
&self.names
|
||||
[&NameKey::StructMember(result.ty, index as u32)]
|
||||
)?;
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
@@ -2049,10 +2048,10 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
output: true,
|
||||
targetting_webgl: self.options.version.is_webgl(),
|
||||
};
|
||||
write!(self.out, "{} = ", name)?;
|
||||
write!(self.out, "{name} = ")?;
|
||||
self.write_expr(value, ctx)?;
|
||||
writeln!(self.out, ";")?;
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2069,7 +2068,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
self.out,
|
||||
"gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);",
|
||||
)?;
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
}
|
||||
}
|
||||
writeln!(self.out, "return;")?;
|
||||
@@ -2079,13 +2078,13 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// This is one of the places were glsl adds to the syntax of C in this case the discard
|
||||
// keyword which ceases all further processing in a fragment shader, it's called OpKill
|
||||
// in spir-v that's why it's called `Statement::Kill`
|
||||
Statement::Kill => writeln!(self.out, "{}discard;", level)?,
|
||||
Statement::Kill => writeln!(self.out, "{level}discard;")?,
|
||||
Statement::Barrier(flags) => {
|
||||
self.write_barrier(flags, level)?;
|
||||
}
|
||||
// Stores in glsl are just variable assignments written as `pointer = value;`
|
||||
Statement::Store { pointer, value } => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_expr(pointer, ctx)?;
|
||||
write!(self.out, " = ")?;
|
||||
self.write_expr(value, ctx)?;
|
||||
@@ -2098,7 +2097,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
array_index,
|
||||
value,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_image_store(ctx, image, coordinate, array_index, value)?
|
||||
}
|
||||
// A `Call` is written `name(arguments)` where `arguments` is a comma separated expressions list
|
||||
@@ -2107,12 +2106,12 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
ref arguments,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
if let Some(expr) = result {
|
||||
let name = format!("{}{}", back::BAKE_PREFIX, expr.index());
|
||||
let result = self.module.functions[function].result.as_ref().unwrap();
|
||||
self.write_type(result.ty)?;
|
||||
write!(self.out, " {} = ", name)?;
|
||||
write!(self.out, " {name} = ")?;
|
||||
self.named_expressions.insert(expr, name);
|
||||
}
|
||||
write!(self.out, "{}(", &self.names[&NameKey::Function(function)])?;
|
||||
@@ -2136,15 +2135,15 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
value,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
|
||||
let res_ty = ctx.info[result].ty.inner_with(&self.module.types);
|
||||
self.write_value_type(res_ty)?;
|
||||
write!(self.out, " {} = ", res_name)?;
|
||||
write!(self.out, " {res_name} = ")?;
|
||||
self.named_expressions.insert(result, res_name);
|
||||
|
||||
let fun_str = fun.to_glsl();
|
||||
write!(self.out, "atomic{}(", fun_str)?;
|
||||
write!(self.out, "atomic{fun_str}(")?;
|
||||
self.write_expr(pointer, ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
// handle the special cases
|
||||
@@ -2180,7 +2179,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
use crate::Expression;
|
||||
|
||||
if let Some(name) = self.named_expressions.get(&expr) {
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -2215,7 +2214,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
TypeInner::Matrix { .. }
|
||||
| TypeInner::Array { .. }
|
||||
| TypeInner::ValuePointer { .. } => write!(self.out, "[{}]", index)?,
|
||||
| TypeInner::ValuePointer { .. } => write!(self.out, "[{index}]")?,
|
||||
TypeInner::Struct { .. } => {
|
||||
// This will never panic in case the type is a `Struct`, this is not true
|
||||
// for other types so we can only check while inside this match arm
|
||||
@@ -2227,7 +2226,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
&self.names[&NameKey::StructMember(ty, index)]
|
||||
)?
|
||||
}
|
||||
ref other => return Err(Error::Custom(format!("Cannot index {:?}", other))),
|
||||
ref other => return Err(Error::Custom(format!("Cannot index {other:?}"))),
|
||||
}
|
||||
}
|
||||
// Constants are delegated to `write_constant`
|
||||
@@ -2353,7 +2352,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
None => "",
|
||||
};
|
||||
|
||||
write!(self.out, "{}{}(", fun_name, offset_name)?;
|
||||
write!(self.out, "{fun_name}{offset_name}(")?;
|
||||
|
||||
// Write the image that will be used
|
||||
self.write_expr(image, ctx)?;
|
||||
@@ -2413,7 +2412,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
crate::ImageDimension::Cube => 3,
|
||||
_ => 2,
|
||||
};
|
||||
write!(self.out, ", vec{}(0.0), vec{}(0.0)", vec_dim, vec_dim)?;
|
||||
write!(self.out, ", vec{vec_dim}(0.0), vec{vec_dim}(0.0)")?;
|
||||
} else if gather.is_none() {
|
||||
write!(self.out, ", 0.0")?;
|
||||
}
|
||||
@@ -2538,7 +2537,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
ImageClass::Sampled { .. } | ImageClass::Depth { .. } => "textureSize",
|
||||
ImageClass::Storage { .. } => "imageSize",
|
||||
};
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(image, ctx)?;
|
||||
// All textureSize calls requires an lod argument
|
||||
// except for multisampled samplers
|
||||
@@ -2557,7 +2556,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
ImageClass::Storage { .. } => "imageSamples",
|
||||
};
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(image, ctx)?;
|
||||
write!(self.out, ")",)?;
|
||||
}
|
||||
@@ -2586,14 +2585,13 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Some(Sk::Bool) => "!",
|
||||
ref other => {
|
||||
return Err(Error::Custom(format!(
|
||||
"Cannot apply not to type {:?}",
|
||||
other
|
||||
"Cannot apply not to type {other:?}"
|
||||
)))
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
write!(self.out, "{}(", operator)?;
|
||||
write!(self.out, "{operator}(")?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2667,7 +2665,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Bo::NotEqual => "notEqual(",
|
||||
_ => unreachable!(),
|
||||
};
|
||||
write!(self.out, "{}", op_str)?;
|
||||
write!(self.out, "{op_str}")?;
|
||||
self.write_expr(left, ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(right, ctx)?;
|
||||
@@ -2802,7 +2800,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
Rf::All => "all",
|
||||
Rf::Any => "any",
|
||||
};
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
|
||||
self.write_expr(argument, ctx)?;
|
||||
|
||||
@@ -2987,7 +2985,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
|
||||
// Cast to int if the function needs it
|
||||
if arg_might_need_uint_to_int {
|
||||
@@ -3199,7 +3197,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
// constructor notation (NOTE: the inner `ivec` can also be a scalar, this
|
||||
// is important for 1D arrayed images).
|
||||
Some(layer_expr) => {
|
||||
write!(self.out, "ivec{}(", vector_size)?;
|
||||
write!(self.out, "ivec{vector_size}(")?;
|
||||
self.write_expr(coordinate, ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
// If we are replacing sampler1D with sampler2D we also need
|
||||
@@ -3229,7 +3227,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
} else if uvec_size.is_some() {
|
||||
match uvec_size {
|
||||
Some(None) => write!(self.out, "int(")?,
|
||||
Some(Some(size)) => write!(self.out, "ivec{}(", size)?,
|
||||
Some(Some(size)) => write!(self.out, "ivec{size}(")?,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@@ -3442,7 +3440,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
|
||||
// Begin the call to the function used to load the texel
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(image, ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
|
||||
@@ -3463,7 +3461,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if vector_size == 1 {
|
||||
write!(self.out, ", 0")?;
|
||||
} else {
|
||||
write!(self.out, ", ivec{}(0)", vector_size)?;
|
||||
write!(self.out, ", ivec{vector_size}(0)")?;
|
||||
}
|
||||
// Start the `textureSize` call to use as the max value.
|
||||
write!(self.out, ", textureSize(")?;
|
||||
@@ -3487,7 +3485,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
if vector_size == 1 {
|
||||
write!(self.out, " - 1")?;
|
||||
} else {
|
||||
write!(self.out, " - ivec{}(1)", vector_size)?;
|
||||
write!(self.out, " - ivec{vector_size}(1)")?;
|
||||
}
|
||||
|
||||
// Close the `clamp` call
|
||||
@@ -3563,7 +3561,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
proc::TypeResolution::Handle(ty_handle) => match self.module.types[ty_handle].inner {
|
||||
TypeInner::Struct { .. } => {
|
||||
let ty_name = &self.names[&NameKey::Type(ty_handle)];
|
||||
write!(self.out, "{}", ty_name)?;
|
||||
write!(self.out, "{ty_name}")?;
|
||||
}
|
||||
_ => {
|
||||
self.write_type(ty_handle)?;
|
||||
@@ -3577,7 +3575,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
let base_ty_res = &ctx.info[handle].ty;
|
||||
let resolved = base_ty_res.inner_with(&self.module.types);
|
||||
|
||||
write!(self.out, " {}", name)?;
|
||||
write!(self.out, " {name}")?;
|
||||
if let TypeInner::Array { base, size, .. } = *resolved {
|
||||
self.write_array_size(base, size)?;
|
||||
}
|
||||
@@ -3629,7 +3627,7 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
}
|
||||
TypeInner::Struct { ref members, .. } => {
|
||||
let name = &self.names[&NameKey::Type(ty)];
|
||||
write!(self.out, "{}(", name)?;
|
||||
write!(self.out, "{name}(")?;
|
||||
for (i, member) in members.iter().enumerate() {
|
||||
self.write_zero_init_value(member.ty)?;
|
||||
if i != members.len().saturating_sub(1) {
|
||||
@@ -3660,12 +3658,12 @@ impl<'a, W: Write> Writer<'a, W> {
|
||||
/// OpenGL always requires a call to the `barrier()` function after a `memoryBarrier*()`
|
||||
fn write_barrier(&mut self, flags: crate::Barrier, level: back::Level) -> BackendResult {
|
||||
if flags.contains(crate::Barrier::STORAGE) {
|
||||
writeln!(self.out, "{}memoryBarrierBuffer();", level)?;
|
||||
writeln!(self.out, "{level}memoryBarrierBuffer();")?;
|
||||
}
|
||||
if flags.contains(crate::Barrier::WORK_GROUP) {
|
||||
writeln!(self.out, "{}memoryBarrierShared();", level)?;
|
||||
writeln!(self.out, "{level}memoryBarrierShared();")?;
|
||||
}
|
||||
writeln!(self.out, "{}barrier();", level)?;
|
||||
writeln!(self.out, "{level}barrier();")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -175,10 +175,10 @@ impl crate::BuiltIn {
|
||||
// in `Writer::write_expr`.
|
||||
Self::NumWorkGroups => "SV_GroupID",
|
||||
Self::BaseInstance | Self::BaseVertex | Self::WorkGroupSize => {
|
||||
return Err(Error::Unimplemented(format!("builtin {:?}", self)))
|
||||
return Err(Error::Unimplemented(format!("builtin {self:?}")))
|
||||
}
|
||||
Self::ViewIndex | Self::PointCoord => {
|
||||
return Err(Error::Custom(format!("Unsupported builtin {:?}", self)))
|
||||
return Err(Error::Custom(format!("Unsupported builtin {self:?}")))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -125,20 +125,20 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
};
|
||||
let dim_str = dim.to_hlsl_str();
|
||||
let arrayed_str = if arrayed { "Array" } else { "" };
|
||||
write!(self.out, "{}Texture{}{}", access_str, dim_str, arrayed_str)?;
|
||||
write!(self.out, "{access_str}Texture{dim_str}{arrayed_str}")?;
|
||||
match class {
|
||||
crate::ImageClass::Depth { multi } => {
|
||||
let multi_str = if multi { "MS" } else { "" };
|
||||
write!(self.out, "{}<float>", multi_str)?
|
||||
write!(self.out, "{multi_str}<float>")?
|
||||
}
|
||||
crate::ImageClass::Sampled { kind, multi } => {
|
||||
let multi_str = if multi { "MS" } else { "" };
|
||||
let scalar_kind_str = kind.to_hlsl_str(4)?;
|
||||
write!(self.out, "{}<{}4>", multi_str, scalar_kind_str)?
|
||||
write!(self.out, "{multi_str}<{scalar_kind_str}4>")?
|
||||
}
|
||||
crate::ImageClass::Storage { format, .. } => {
|
||||
let storage_format_str = format.to_hlsl_str();
|
||||
write!(self.out, "<{}>", storage_format_str)?
|
||||
write!(self.out, "<{storage_format_str}>")?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -149,7 +149,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
query: WrappedArrayLength,
|
||||
) -> BackendResult {
|
||||
let access_str = if query.writable { "RW" } else { "" };
|
||||
write!(self.out, "NagaBufferLength{}", access_str,)?;
|
||||
write!(self.out, "NagaBufferLength{access_str}",)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -180,22 +180,20 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
let access_str = if wal.writable { "RW" } else { "" };
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}ByteAddressBuffer {})",
|
||||
access_str, ARGUMENT_VARIABLE_NAME
|
||||
"{access_str}ByteAddressBuffer {ARGUMENT_VARIABLE_NAME})"
|
||||
)?;
|
||||
// Write function body
|
||||
writeln!(self.out, "{{")?;
|
||||
|
||||
// Write `GetDimensions` function.
|
||||
writeln!(self.out, "{}uint {};", INDENT, RETURN_VARIABLE_NAME)?;
|
||||
writeln!(self.out, "{INDENT}uint {RETURN_VARIABLE_NAME};")?;
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}{}.GetDimensions({});",
|
||||
INDENT, ARGUMENT_VARIABLE_NAME, RETURN_VARIABLE_NAME
|
||||
"{INDENT}{ARGUMENT_VARIABLE_NAME}.GetDimensions({RETURN_VARIABLE_NAME});"
|
||||
)?;
|
||||
|
||||
// Write return value
|
||||
writeln!(self.out, "{}return {};", INDENT, RETURN_VARIABLE_NAME)?;
|
||||
writeln!(self.out, "{INDENT}return {RETURN_VARIABLE_NAME};")?;
|
||||
|
||||
// End of function body
|
||||
writeln!(self.out, "}}")?;
|
||||
@@ -226,11 +224,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
ImageQuery::NumSamples => "NumSamples",
|
||||
};
|
||||
|
||||
write!(
|
||||
self.out,
|
||||
"Naga{}{}{}{}",
|
||||
class_str, query_str, dim_str, arrayed_str
|
||||
)?;
|
||||
write!(self.out, "Naga{class_str}{query_str}{dim_str}{arrayed_str}")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -264,10 +258,10 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
write!(self.out, "(")?;
|
||||
// Texture always first parameter
|
||||
self.write_image_type(wiq.dim, wiq.arrayed, wiq.class)?;
|
||||
write!(self.out, " {}", ARGUMENT_VARIABLE_NAME)?;
|
||||
write!(self.out, " {ARGUMENT_VARIABLE_NAME}")?;
|
||||
// Mipmap is a second parameter if exists
|
||||
if let ImageQuery::SizeLevel = wiq.query {
|
||||
write!(self.out, ", uint {}", MIP_LEVEL_PARAM)?;
|
||||
write!(self.out, ", uint {MIP_LEVEL_PARAM}")?;
|
||||
}
|
||||
writeln!(self.out, ")")?;
|
||||
|
||||
@@ -303,15 +297,11 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
};
|
||||
|
||||
// Write `GetDimensions` function.
|
||||
writeln!(self.out, "{}uint4 {};", INDENT, RETURN_VARIABLE_NAME)?;
|
||||
write!(
|
||||
self.out,
|
||||
"{}{}.GetDimensions(",
|
||||
INDENT, ARGUMENT_VARIABLE_NAME
|
||||
)?;
|
||||
writeln!(self.out, "{INDENT}uint4 {RETURN_VARIABLE_NAME};")?;
|
||||
write!(self.out, "{INDENT}{ARGUMENT_VARIABLE_NAME}.GetDimensions(")?;
|
||||
match wiq.query {
|
||||
ImageQuery::SizeLevel => {
|
||||
write!(self.out, "{}, ", MIP_LEVEL_PARAM)?;
|
||||
write!(self.out, "{MIP_LEVEL_PARAM}, ")?;
|
||||
}
|
||||
_ => match wiq.class {
|
||||
crate::ImageClass::Sampled { multi: true, .. }
|
||||
@@ -325,7 +315,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
}
|
||||
|
||||
for component in COMPONENTS[..number_of_params - 1].iter() {
|
||||
write!(self.out, "{}.{}, ", RETURN_VARIABLE_NAME, component)?;
|
||||
write!(self.out, "{RETURN_VARIABLE_NAME}.{component}, ")?;
|
||||
}
|
||||
|
||||
// write last parameter without comma and space for last parameter
|
||||
@@ -341,8 +331,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// Write return value
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}return {}.{};",
|
||||
INDENT, RETURN_VARIABLE_NAME, ret_swizzle
|
||||
"{INDENT}return {RETURN_VARIABLE_NAME}.{ret_swizzle};"
|
||||
)?;
|
||||
|
||||
// End of function body
|
||||
@@ -364,7 +353,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
&module.constants,
|
||||
&self.names,
|
||||
)?;
|
||||
write!(self.out, "Construct{}", name)?;
|
||||
write!(self.out, "Construct{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -404,7 +393,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
self.write_type(module, ty)?;
|
||||
write!(self.out, " {}{}", ARGUMENT_VARIABLE_NAME, i)?;
|
||||
write!(self.out, " {ARGUMENT_VARIABLE_NAME}{i}")?;
|
||||
if let crate::TypeInner::Array { base, size, .. } = module.types[ty].inner {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
@@ -440,8 +429,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
let struct_name = &self.names[&NameKey::Type(constructor.ty)];
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}{} {} = ({})0;",
|
||||
INDENT, struct_name, RETURN_VARIABLE_NAME, struct_name
|
||||
"{INDENT}{struct_name} {RETURN_VARIABLE_NAME} = ({struct_name})0;"
|
||||
)?;
|
||||
for (i, member) in members.iter().enumerate() {
|
||||
let field_name = &self.names[&NameKey::StructMember(constructor.ty, i as u32)];
|
||||
@@ -455,14 +443,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
for j in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}{}.{}_{} = {}{}[{}];",
|
||||
INDENT,
|
||||
RETURN_VARIABLE_NAME,
|
||||
field_name,
|
||||
j,
|
||||
ARGUMENT_VARIABLE_NAME,
|
||||
i,
|
||||
j
|
||||
"{INDENT}{RETURN_VARIABLE_NAME}.{field_name}_{j} = {ARGUMENT_VARIABLE_NAME}{i}[{j}];"
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -484,16 +465,11 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
if let crate::TypeInner::Array { base, size, .. } = *other {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
writeln!(self.out, "){}{};", ARGUMENT_VARIABLE_NAME, i,)?;
|
||||
writeln!(self.out, "){ARGUMENT_VARIABLE_NAME}{i};",)?;
|
||||
} else {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}{}.{} = {}{};",
|
||||
INDENT,
|
||||
RETURN_VARIABLE_NAME,
|
||||
field_name,
|
||||
ARGUMENT_VARIABLE_NAME,
|
||||
i,
|
||||
"{INDENT}{RETURN_VARIABLE_NAME}.{field_name} = {ARGUMENT_VARIABLE_NAME}{i};",
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -505,9 +481,9 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
size: crate::ArraySize::Constant(size),
|
||||
..
|
||||
} => {
|
||||
write!(self.out, "{}", INDENT)?;
|
||||
write!(self.out, "{INDENT}")?;
|
||||
self.write_type(module, base)?;
|
||||
write!(self.out, " {}", RETURN_VARIABLE_NAME)?;
|
||||
write!(self.out, " {RETURN_VARIABLE_NAME}")?;
|
||||
self.write_array_size(module, base, crate::ArraySize::Constant(size))?;
|
||||
write!(self.out, " = {{ ")?;
|
||||
let count = module.constants[size].to_array_length().unwrap();
|
||||
@@ -515,7 +491,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
if i != 0 {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
write!(self.out, "{}{}", ARGUMENT_VARIABLE_NAME, i)?;
|
||||
write!(self.out, "{ARGUMENT_VARIABLE_NAME}{i}")?;
|
||||
}
|
||||
writeln!(self.out, " }};",)?;
|
||||
}
|
||||
@@ -523,7 +499,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
}
|
||||
|
||||
// Write return value
|
||||
writeln!(self.out, "{}return {};", INDENT, RETURN_VARIABLE_NAME)?;
|
||||
writeln!(self.out, "{INDENT}return {RETURN_VARIABLE_NAME};")?;
|
||||
|
||||
// End of function body
|
||||
writeln!(self.out, "}}")?;
|
||||
@@ -539,7 +515,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
let name = &self.names[&NameKey::Type(access.ty)];
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
write!(self.out, "GetMat{}On{}", field_name, name)?;
|
||||
write!(self.out, "GetMat{field_name}On{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -566,17 +542,13 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// Write function parameters
|
||||
write!(self.out, "(")?;
|
||||
let struct_name = &self.names[&NameKey::Type(access.ty)];
|
||||
write!(
|
||||
self.out,
|
||||
"{} {}",
|
||||
struct_name, STRUCT_ARGUMENT_VARIABLE_NAME
|
||||
)?;
|
||||
write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}")?;
|
||||
|
||||
// Write function body
|
||||
writeln!(self.out, ") {{")?;
|
||||
|
||||
// Write return value
|
||||
write!(self.out, "{}return ", INDENT)?;
|
||||
write!(self.out, "{INDENT}return ")?;
|
||||
self.write_value_type(module, ret_ty)?;
|
||||
write!(self.out, "(")?;
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
@@ -586,11 +558,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
if i != 0 {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
write!(
|
||||
self.out,
|
||||
"{}.{}_{}",
|
||||
STRUCT_ARGUMENT_VARIABLE_NAME, field_name, i
|
||||
)?;
|
||||
write!(self.out, "{STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i}")?;
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
@@ -611,7 +579,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
let name = &self.names[&NameKey::Type(access.ty)];
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
write!(self.out, "SetMat{}On{}", field_name, name)?;
|
||||
write!(self.out, "SetMat{field_name}On{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -633,17 +601,13 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// Write function parameters
|
||||
write!(self.out, "(")?;
|
||||
let struct_name = &self.names[&NameKey::Type(access.ty)];
|
||||
write!(
|
||||
self.out,
|
||||
"{} {}, ",
|
||||
struct_name, STRUCT_ARGUMENT_VARIABLE_NAME
|
||||
)?;
|
||||
write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?;
|
||||
let member = match module.types[access.ty].inner {
|
||||
crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize],
|
||||
_ => unreachable!(),
|
||||
};
|
||||
self.write_type(module, member.ty)?;
|
||||
write!(self.out, " {}", MATRIX_ARGUMENT_VARIABLE_NAME)?;
|
||||
write!(self.out, " {MATRIX_ARGUMENT_VARIABLE_NAME}")?;
|
||||
// Write function body
|
||||
writeln!(self.out, ") {{")?;
|
||||
|
||||
@@ -654,13 +618,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}{}.{}_{} = {}[{}];",
|
||||
INDENT,
|
||||
STRUCT_ARGUMENT_VARIABLE_NAME,
|
||||
field_name,
|
||||
i,
|
||||
MATRIX_ARGUMENT_VARIABLE_NAME,
|
||||
i
|
||||
"{INDENT}{STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i} = {MATRIX_ARGUMENT_VARIABLE_NAME}[{i}];"
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -681,7 +639,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
let name = &self.names[&NameKey::Type(access.ty)];
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
write!(self.out, "SetMatVec{}On{}", field_name, name)?;
|
||||
write!(self.out, "SetMatVec{field_name}On{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -704,11 +662,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// Write function parameters
|
||||
write!(self.out, "(")?;
|
||||
let struct_name = &self.names[&NameKey::Type(access.ty)];
|
||||
write!(
|
||||
self.out,
|
||||
"{} {}, ",
|
||||
struct_name, STRUCT_ARGUMENT_VARIABLE_NAME
|
||||
)?;
|
||||
write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?;
|
||||
let member = match module.types[access.ty].inner {
|
||||
crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize],
|
||||
_ => unreachable!(),
|
||||
@@ -724,8 +678,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
self.write_value_type(module, &vec_ty)?;
|
||||
write!(
|
||||
self.out,
|
||||
" {}, uint {}",
|
||||
VECTOR_ARGUMENT_VARIABLE_NAME, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME
|
||||
" {VECTOR_ARGUMENT_VARIABLE_NAME}, uint {MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}"
|
||||
)?;
|
||||
|
||||
// Write function body
|
||||
@@ -733,8 +686,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}switch({}) {{",
|
||||
INDENT, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME
|
||||
"{INDENT}switch({MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}) {{"
|
||||
)?;
|
||||
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
@@ -744,20 +696,14 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}case {}: {{ {}.{}_{} = {}; break; }}",
|
||||
INDENT,
|
||||
i,
|
||||
STRUCT_ARGUMENT_VARIABLE_NAME,
|
||||
field_name,
|
||||
i,
|
||||
VECTOR_ARGUMENT_VARIABLE_NAME
|
||||
"{INDENT}case {i}: {{ {STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i} = {VECTOR_ARGUMENT_VARIABLE_NAME}; break; }}"
|
||||
)?;
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}}}")?;
|
||||
|
||||
// End of function body
|
||||
writeln!(self.out, "}}")?;
|
||||
@@ -773,7 +719,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
let name = &self.names[&NameKey::Type(access.ty)];
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
write!(self.out, "SetMatScalar{}On{}", field_name, name)?;
|
||||
write!(self.out, "SetMatScalar{field_name}On{name}")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -797,11 +743,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// Write function parameters
|
||||
write!(self.out, "(")?;
|
||||
let struct_name = &self.names[&NameKey::Type(access.ty)];
|
||||
write!(
|
||||
self.out,
|
||||
"{} {}, ",
|
||||
struct_name, STRUCT_ARGUMENT_VARIABLE_NAME
|
||||
)?;
|
||||
write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?;
|
||||
let member = match module.types[access.ty].inner {
|
||||
crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize],
|
||||
_ => unreachable!(),
|
||||
@@ -816,10 +758,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
self.write_value_type(module, &scalar_ty)?;
|
||||
write!(
|
||||
self.out,
|
||||
" {}, uint {}, uint {}",
|
||||
SCALAR_ARGUMENT_VARIABLE_NAME,
|
||||
MATRIX_INDEX_ARGUMENT_VARIABLE_NAME,
|
||||
VECTOR_INDEX_ARGUMENT_VARIABLE_NAME
|
||||
" {SCALAR_ARGUMENT_VARIABLE_NAME}, uint {MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}, uint {VECTOR_INDEX_ARGUMENT_VARIABLE_NAME}"
|
||||
)?;
|
||||
|
||||
// Write function body
|
||||
@@ -827,8 +766,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}switch({}) {{",
|
||||
INDENT, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME
|
||||
"{INDENT}switch({MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}) {{"
|
||||
)?;
|
||||
|
||||
let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)];
|
||||
@@ -838,21 +776,14 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}case {}: {{ {}.{}_{}[{}] = {}; break; }}",
|
||||
INDENT,
|
||||
i,
|
||||
STRUCT_ARGUMENT_VARIABLE_NAME,
|
||||
field_name,
|
||||
i,
|
||||
VECTOR_INDEX_ARGUMENT_VARIABLE_NAME,
|
||||
SCALAR_ARGUMENT_VARIABLE_NAME
|
||||
"{INDENT}case {i}: {{ {STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i}[{VECTOR_INDEX_ARGUMENT_VARIABLE_NAME}] = {SCALAR_ARGUMENT_VARIABLE_NAME}; break; }}"
|
||||
)?;
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}}}")?;
|
||||
|
||||
// End of function body
|
||||
writeln!(self.out, "}}")?;
|
||||
@@ -1088,7 +1019,7 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
// typedef
|
||||
write!(self.out, "typedef struct {{ ")?;
|
||||
for i in 0..columns as u8 {
|
||||
write!(self.out, "float2 _{}; ", i)?;
|
||||
write!(self.out, "float2 _{i}; ")?;
|
||||
}
|
||||
writeln!(self.out, "}} __mat{}x2;", columns as u8)?;
|
||||
|
||||
@@ -1098,12 +1029,12 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
"float2 __get_col_of_mat{}x2(__mat{}x2 mat, uint idx) {{",
|
||||
columns as u8, columns as u8
|
||||
)?;
|
||||
writeln!(self.out, "{}switch(idx) {{", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}switch(idx) {{")?;
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(self.out, "{}case {}: {{ return mat._{}; }}", INDENT, i, i)?;
|
||||
writeln!(self.out, "{INDENT}case {i}: {{ return mat._{i}; }}")?;
|
||||
}
|
||||
writeln!(self.out, "{}default: {{ return (float2)0; }}", INDENT)?;
|
||||
writeln!(self.out, "{}}}", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}default: {{ return (float2)0; }}")?;
|
||||
writeln!(self.out, "{INDENT}}}")?;
|
||||
writeln!(self.out, "}}")?;
|
||||
|
||||
// __set_col_of_mat
|
||||
@@ -1112,15 +1043,11 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
"void __set_col_of_mat{}x2(__mat{}x2 mat, uint idx, float2 value) {{",
|
||||
columns as u8, columns as u8
|
||||
)?;
|
||||
writeln!(self.out, "{}switch(idx) {{", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}switch(idx) {{")?;
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}case {}: {{ mat._{} = value; break; }}",
|
||||
INDENT, i, i
|
||||
)?;
|
||||
writeln!(self.out, "{INDENT}case {i}: {{ mat._{i} = value; break; }}")?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}}}")?;
|
||||
writeln!(self.out, "}}")?;
|
||||
|
||||
// __set_el_of_mat
|
||||
@@ -1129,15 +1056,14 @@ impl<'a, W: Write> super::Writer<'a, W> {
|
||||
"void __set_el_of_mat{}x2(__mat{}x2 mat, uint idx, uint vec_idx, float value) {{",
|
||||
columns as u8, columns as u8
|
||||
)?;
|
||||
writeln!(self.out, "{}switch(idx) {{", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}switch(idx) {{")?;
|
||||
for i in 0..columns as u8 {
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}case {}: {{ mat._{}[vec_idx] = value; break; }}",
|
||||
INDENT, i, i
|
||||
"{INDENT}case {i}: {{ mat._{i}[vec_idx] = value; break; }}"
|
||||
)?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", INDENT)?;
|
||||
writeln!(self.out, "{INDENT}}}")?;
|
||||
writeln!(self.out, "}}")?;
|
||||
|
||||
writeln!(self.out)?;
|
||||
|
||||
@@ -53,11 +53,11 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
}
|
||||
match *access {
|
||||
SubAccess::Offset(offset) => {
|
||||
write!(self.out, "{}", offset)?;
|
||||
write!(self.out, "{offset}")?;
|
||||
}
|
||||
SubAccess::Index { value, stride } => {
|
||||
self.write_expr(module, value, func_ctx)?;
|
||||
write!(self.out, "*{}", stride)?;
|
||||
write!(self.out, "*{stride}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
let chain = mem::take(&mut self.temp_access_chain);
|
||||
let var_name = &self.names[&NameKey::GlobalVariable(var_handle)];
|
||||
let cast = kind.to_hlsl_cast();
|
||||
write!(self.out, "{}({}.Load(", cast, var_name)?;
|
||||
write!(self.out, "{cast}({var_name}.Load(")?;
|
||||
self.write_storage_address(module, &chain, func_ctx)?;
|
||||
write!(self.out, "))")?;
|
||||
self.temp_access_chain = chain;
|
||||
@@ -183,14 +183,14 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
depth,
|
||||
index,
|
||||
ty: _,
|
||||
} => write!(self.out, "{}{}[{}]", STORE_TEMP_NAME, depth, index)?,
|
||||
} => write!(self.out, "{STORE_TEMP_NAME}{depth}[{index}]")?,
|
||||
StoreValue::TempAccess {
|
||||
depth,
|
||||
base,
|
||||
member_index,
|
||||
} => {
|
||||
let name = &self.names[&NameKey::StructMember(base, member_index)];
|
||||
write!(self.out, "{}{}.{}", STORE_TEMP_NAME, depth, name)?
|
||||
write!(self.out, "{STORE_TEMP_NAME}{depth}.{name}")?
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -233,7 +233,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
// working around the borrow checker in `self.write_expr`
|
||||
let chain = mem::take(&mut self.temp_access_chain);
|
||||
let var_name = &self.names[&NameKey::GlobalVariable(var_handle)];
|
||||
write!(self.out, "{}{}.Store(", level, var_name)?;
|
||||
write!(self.out, "{level}{var_name}.Store(")?;
|
||||
self.write_storage_address(module, &chain, func_ctx)?;
|
||||
write!(self.out, ", asuint(")?;
|
||||
self.write_store_value(module, &value, func_ctx)?;
|
||||
@@ -257,7 +257,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
width,
|
||||
} => {
|
||||
// first, assign the value to a temporary
|
||||
writeln!(self.out, "{}{{", level)?;
|
||||
writeln!(self.out, "{level}{{")?;
|
||||
let depth = level.0 + 1;
|
||||
write!(
|
||||
self.out,
|
||||
@@ -293,7 +293,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
self.temp_access_chain.pop();
|
||||
}
|
||||
// done
|
||||
writeln!(self.out, "{}}}", level)?;
|
||||
writeln!(self.out, "{level}}}")?;
|
||||
}
|
||||
crate::TypeInner::Array {
|
||||
base,
|
||||
@@ -301,11 +301,11 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
..
|
||||
} => {
|
||||
// first, assign the value to a temporary
|
||||
writeln!(self.out, "{}{{", level)?;
|
||||
writeln!(self.out, "{level}{{")?;
|
||||
write!(self.out, "{}", level.next())?;
|
||||
self.write_value_type(module, &module.types[base].inner)?;
|
||||
let depth = level.next().0;
|
||||
write!(self.out, " {}{}", STORE_TEMP_NAME, depth)?;
|
||||
write!(self.out, " {STORE_TEMP_NAME}{depth}")?;
|
||||
self.write_array_size(module, base, crate::ArraySize::Constant(const_handle))?;
|
||||
write!(self.out, " = ")?;
|
||||
self.write_store_value(module, &value, func_ctx)?;
|
||||
@@ -324,11 +324,11 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
self.temp_access_chain.pop();
|
||||
}
|
||||
// done
|
||||
writeln!(self.out, "{}}}", level)?;
|
||||
writeln!(self.out, "{level}}}")?;
|
||||
}
|
||||
crate::TypeInner::Struct { ref members, .. } => {
|
||||
// first, assign the value to a temporary
|
||||
writeln!(self.out, "{}{{", level)?;
|
||||
writeln!(self.out, "{level}{{")?;
|
||||
let depth = level.next().0;
|
||||
let struct_ty = ty_resolution.handle().unwrap();
|
||||
let struct_name = &self.names[&NameKey::Type(struct_ty)];
|
||||
@@ -355,7 +355,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
self.temp_access_chain.pop();
|
||||
}
|
||||
// done
|
||||
writeln!(self.out, "{}}}", level)?;
|
||||
writeln!(self.out, "{level}}}")?;
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@@ -386,10 +386,7 @@ impl<W: fmt::Write> super::Writer<'_, W> {
|
||||
(base, AccessIndex::Constant(index))
|
||||
}
|
||||
ref other => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"Pointer access of {:?}",
|
||||
other
|
||||
)))
|
||||
return Err(Error::Unimplemented(format!("Pointer access of {other:?}")))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
|
||||
// Write special constants, if needed
|
||||
if let Some(ref bt) = self.options.special_constants_binding {
|
||||
writeln!(self.out, "struct {} {{", SPECIAL_CBUF_TYPE)?;
|
||||
writeln!(self.out, "struct {SPECIAL_CBUF_TYPE} {{")?;
|
||||
writeln!(self.out, "{}int {};", back::INDENT, SPECIAL_BASE_VERTEX)?;
|
||||
writeln!(self.out, "{}int {};", back::INDENT, SPECIAL_BASE_INSTANCE)?;
|
||||
writeln!(self.out, "{}uint {};", back::INDENT, SPECIAL_OTHER)?;
|
||||
@@ -320,13 +320,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
} => {
|
||||
if let Some(interpolation) = interpolation {
|
||||
if let Some(string) = interpolation.to_hlsl_str() {
|
||||
write!(self.out, "{} ", string)?
|
||||
write!(self.out, "{string} ")?
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(sampling) = sampling {
|
||||
if let Some(string) = sampling.to_hlsl_str() {
|
||||
write!(self.out, "{} ", string)?
|
||||
write!(self.out, "{string} ")?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -346,13 +346,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
match *binding {
|
||||
crate::Binding::BuiltIn(builtin) => {
|
||||
let builtin_str = builtin.to_hlsl_str()?;
|
||||
write!(self.out, " : {}", builtin_str)?;
|
||||
write!(self.out, " : {builtin_str}")?;
|
||||
}
|
||||
crate::Binding::Location { location, .. } => {
|
||||
if stage == Some((crate::ShaderStage::Fragment, Io::Output)) {
|
||||
write!(self.out, " : SV_Target{}", location)?;
|
||||
write!(self.out, " : SV_Target{location}")?;
|
||||
} else {
|
||||
write!(self.out, " : {}{}", LOCATION_SEMANTIC, location)?;
|
||||
write!(self.out, " : {LOCATION_SEMANTIC}{location}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -372,7 +372,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// interfaces to match with regards to order.
|
||||
members.sort_by_key(|m| InterfaceKey::new(m.binding.as_ref()));
|
||||
|
||||
write!(self.out, "struct {}", struct_name)?;
|
||||
write!(self.out, "struct {struct_name}")?;
|
||||
writeln!(self.out, " {{")?;
|
||||
for m in members.iter() {
|
||||
write!(self.out, "{}", back::INDENT)?;
|
||||
@@ -416,7 +416,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
stage: ShaderStage,
|
||||
entry_point_name: &str,
|
||||
) -> Result<EntryPointBinding, Error> {
|
||||
let struct_name = format!("{:?}Input_{}", stage, entry_point_name);
|
||||
let struct_name = format!("{stage:?}Input_{entry_point_name}");
|
||||
|
||||
let mut fake_members = Vec::new();
|
||||
for arg in func.arguments.iter() {
|
||||
@@ -459,7 +459,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
stage: ShaderStage,
|
||||
entry_point_name: &str,
|
||||
) -> Result<EntryPointBinding, Error> {
|
||||
let struct_name = format!("{:?}Output_{}", stage, entry_point_name);
|
||||
let struct_name = format!("{stage:?}Output_{entry_point_name}");
|
||||
|
||||
let mut fake_members = Vec::new();
|
||||
let empty = [];
|
||||
@@ -526,7 +526,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, "{}", back::INDENT)?;
|
||||
self.write_type(module, arg.ty)?;
|
||||
let arg_name = &self.names[&NameKey::EntryPointArgument(ep_index, arg_index as u32)];
|
||||
write!(self.out, " {}", arg_name)?;
|
||||
write!(self.out, " {arg_name}")?;
|
||||
match module.types[arg.ty].inner {
|
||||
TypeInner::Array { base, size, .. } => {
|
||||
self.write_array_size(module, base, size)?;
|
||||
@@ -602,7 +602,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
} else {
|
||||
("", "t")
|
||||
};
|
||||
write!(self.out, "{}ByteAddressBuffer", prefix)?;
|
||||
write!(self.out, "{prefix}ByteAddressBuffer")?;
|
||||
register
|
||||
}
|
||||
crate::AddressSpace::Handle => {
|
||||
@@ -645,7 +645,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
|
||||
let name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
write!(self.out, " {}", name)?;
|
||||
write!(self.out, " {name}")?;
|
||||
|
||||
// Push constants need to be assigned a binding explicitly by the consumer
|
||||
// since naga has no way to know the binding from the shader alone
|
||||
@@ -669,7 +669,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// need to write the binding array size if the type was emitted with `write_type`
|
||||
if let TypeInner::BindingArray { base, size, .. } = module.types[global.ty].inner {
|
||||
if let Some(overridden_size) = bt.binding_array_size {
|
||||
write!(self.out, "[{}]", overridden_size)?;
|
||||
write!(self.out, "[{overridden_size}]")?;
|
||||
} else {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
@@ -743,24 +743,24 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
crate::ScalarValue::Bool(_) => "bool",
|
||||
};
|
||||
let name = &self.names[&NameKey::Constant(handle)];
|
||||
write!(self.out, "{} {} = ", ty_str, name)?;
|
||||
write!(self.out, "{ty_str} {name} = ")?;
|
||||
|
||||
// Second match required to avoid heap allocation by `format!()`
|
||||
match *value {
|
||||
crate::ScalarValue::Sint(value) => write!(self.out, "{}", value)?,
|
||||
crate::ScalarValue::Uint(value) => write!(self.out, "{}", value)?,
|
||||
crate::ScalarValue::Sint(value) => write!(self.out, "{value}")?,
|
||||
crate::ScalarValue::Uint(value) => write!(self.out, "{value}")?,
|
||||
crate::ScalarValue::Float(value) => {
|
||||
// Floats are written using `Debug` instead of `Display` because it always appends the
|
||||
// decimal part even it's zero
|
||||
write!(self.out, "{:?}", value)?
|
||||
write!(self.out, "{value:?}")?
|
||||
}
|
||||
crate::ScalarValue::Bool(value) => write!(self.out, "{}", value)?,
|
||||
crate::ScalarValue::Bool(value) => write!(self.out, "{value}")?,
|
||||
};
|
||||
}
|
||||
crate::ConstantInner::Composite { ty, ref components } => {
|
||||
self.write_type(module, ty)?;
|
||||
let name = &self.names[&NameKey::Constant(handle)];
|
||||
write!(self.out, " {} = ", name)?;
|
||||
write!(self.out, " {name} = ")?;
|
||||
self.write_composite_constant(module, ty, components)?;
|
||||
}
|
||||
}
|
||||
@@ -782,7 +782,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
match size {
|
||||
crate::ArraySize::Constant(const_handle) => {
|
||||
let size = module.constants[const_handle].to_array_length().unwrap();
|
||||
write!(self.out, "{}", size)?;
|
||||
write!(self.out, "{size}")?;
|
||||
}
|
||||
crate::ArraySize::Dynamic => {}
|
||||
}
|
||||
@@ -815,7 +815,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
) -> BackendResult {
|
||||
// Write struct name
|
||||
let struct_name = &self.names[&NameKey::Type(handle)];
|
||||
writeln!(self.out, "struct {} {{", struct_name)?;
|
||||
writeln!(self.out, "struct {struct_name} {{")?;
|
||||
|
||||
let mut last_offset = 0;
|
||||
for (index, member) in members.iter().enumerate() {
|
||||
@@ -1011,7 +1011,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
} else {
|
||||
"SamplerState"
|
||||
};
|
||||
write!(self.out, "{}", sampler)?;
|
||||
write!(self.out, "{sampler}")?;
|
||||
}
|
||||
// HLSL arrays are written as `type name[size]`
|
||||
// Current code is written arrays only as `[size]`
|
||||
@@ -1019,12 +1019,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
TypeInner::Array { base, size, .. } | TypeInner::BindingArray { base, size } => {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_value_type {:?}",
|
||||
inner
|
||||
)))
|
||||
}
|
||||
_ => return Err(Error::Unimplemented(format!("write_value_type {inner:?}"))),
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -1075,7 +1070,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
|
||||
// Write function name
|
||||
write!(self.out, " {}(", name)?;
|
||||
write!(self.out, " {name}(")?;
|
||||
|
||||
let need_workgroup_variables_initialization =
|
||||
self.need_workgroup_variables_initialization(func_ctx, module);
|
||||
@@ -1103,7 +1098,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
&self.names[&NameKey::FunctionArgument(handle, index as u32)];
|
||||
|
||||
// Write argument name. Space is important.
|
||||
write!(self.out, " {}", argument_name)?;
|
||||
write!(self.out, " {argument_name}")?;
|
||||
if let TypeInner::Array { base, size, .. } = module.types[arg.ty].inner {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
@@ -1123,7 +1118,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
let argument_name =
|
||||
&self.names[&NameKey::EntryPointArgument(ep_index, index as u32)];
|
||||
|
||||
write!(self.out, " {}", argument_name)?;
|
||||
write!(self.out, " {argument_name}")?;
|
||||
if let TypeInner::Array { base, size, .. } = module.types[arg.ty].inner {
|
||||
self.write_array_size(module, base, size)?;
|
||||
}
|
||||
@@ -1242,8 +1237,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
|
||||
writeln!(
|
||||
self.out,
|
||||
"{}if (all(__global_invocation_id == uint3(0u, 0u, 0u))) {{",
|
||||
level
|
||||
"{level}if (all(__global_invocation_id == uint3(0u, 0u, 0u))) {{"
|
||||
)?;
|
||||
|
||||
let vars = module.global_variables.iter().filter(|&(handle, var)| {
|
||||
@@ -1257,7 +1251,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?;
|
||||
writeln!(self.out, "{level}}}")?;
|
||||
self.write_barrier(crate::Barrier::WORK_GROUP, level)
|
||||
}
|
||||
|
||||
@@ -1302,20 +1296,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
};
|
||||
|
||||
if let Some(name) = expr_name {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_named_expr(module, handle, name, func_ctx)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: copy-paste from glsl-out
|
||||
Statement::Block(ref block) => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "{{")?;
|
||||
for sta in block.iter() {
|
||||
// Increase the indentation to help with readability
|
||||
self.write_stmt(module, sta, func_ctx, level.next())?
|
||||
}
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// TODO: copy-paste from glsl-out
|
||||
Statement::If {
|
||||
@@ -1323,7 +1317,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
ref accept,
|
||||
ref reject,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "if (")?;
|
||||
self.write_expr(module, condition, func_ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
@@ -1337,7 +1331,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// If there are no statements in the reject block we skip writing it
|
||||
// This is only for readability
|
||||
if !reject.is_empty() {
|
||||
writeln!(self.out, "{}}} else {{", level)?;
|
||||
writeln!(self.out, "{level}}} else {{")?;
|
||||
|
||||
for sta in reject {
|
||||
// Increase indentation to help with readability
|
||||
@@ -1345,12 +1339,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
// TODO: copy-paste from glsl-out
|
||||
Statement::Kill => writeln!(self.out, "{}discard;", level)?,
|
||||
Statement::Kill => writeln!(self.out, "{level}discard;")?,
|
||||
Statement::Return { value: None } => {
|
||||
writeln!(self.out, "{}return;", level)?;
|
||||
writeln!(self.out, "{level}return;")?;
|
||||
}
|
||||
Statement::Return { value: Some(expr) } => {
|
||||
let base_ty_res = &func_ctx.info[expr].ty;
|
||||
@@ -1364,11 +1358,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
let ty = base_ty_res.handle().unwrap();
|
||||
let struct_name = &self.names[&NameKey::Type(ty)];
|
||||
let variable_name = self.namer.call(&struct_name.to_lowercase());
|
||||
write!(
|
||||
self.out,
|
||||
"{}const {} {} = ",
|
||||
level, struct_name, variable_name,
|
||||
)?;
|
||||
write!(self.out, "{level}const {struct_name} {variable_name} = ",)?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
writeln!(self.out, ";")?;
|
||||
|
||||
@@ -1392,16 +1382,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, ", ")?;
|
||||
}
|
||||
let member_name = &self.names[&NameKey::StructMember(ty, m.index)];
|
||||
write!(self.out, "{}.{}", variable_name, member_name)?;
|
||||
write!(self.out, "{variable_name}.{member_name}")?;
|
||||
}
|
||||
writeln!(self.out, " }};")?;
|
||||
final_name
|
||||
}
|
||||
None => variable_name,
|
||||
};
|
||||
writeln!(self.out, "{}return {};", level, final_name)?;
|
||||
writeln!(self.out, "{level}return {final_name};")?;
|
||||
} else {
|
||||
write!(self.out, "{}return ", level)?;
|
||||
write!(self.out, "{level}return ")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
writeln!(self.out, ";")?
|
||||
}
|
||||
@@ -1507,7 +1497,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
}
|
||||
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
|
||||
if let Some(MatrixAccess { index, base }) = matrix {
|
||||
let base_ty_res = &func_ctx.info[base].ty;
|
||||
@@ -1530,7 +1520,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, "[")?;
|
||||
match scalar_index {
|
||||
Index::Static(index) => {
|
||||
write!(self.out, "{}", index)?;
|
||||
write!(self.out, "{index}")?;
|
||||
}
|
||||
Index::Expression(index) => {
|
||||
self.write_expr(module, index, func_ctx)?;
|
||||
@@ -1571,7 +1561,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, ", ")?;
|
||||
match scalar_index {
|
||||
Index::Static(index) => {
|
||||
write!(self.out, "{}", index)?;
|
||||
write!(self.out, "{index}")?;
|
||||
}
|
||||
Index::Expression(index) => {
|
||||
self.write_expr(module, index, func_ctx)?;
|
||||
@@ -1665,7 +1655,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, ", ")?;
|
||||
match scalar_index {
|
||||
Index::Static(index) => {
|
||||
write!(self.out, "{}", index)?;
|
||||
write!(self.out, "{index}")?;
|
||||
}
|
||||
Index::Expression(index) => {
|
||||
self.write_expr(module, index, func_ctx)?;
|
||||
@@ -1719,33 +1709,33 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
let l2 = level.next();
|
||||
if !continuing.is_empty() || break_if.is_some() {
|
||||
let gate_name = self.namer.call("loop_init");
|
||||
writeln!(self.out, "{}bool {} = true;", level, gate_name)?;
|
||||
writeln!(self.out, "{}while(true) {{", level)?;
|
||||
writeln!(self.out, "{}if (!{}) {{", l2, gate_name)?;
|
||||
writeln!(self.out, "{level}bool {gate_name} = true;")?;
|
||||
writeln!(self.out, "{level}while(true) {{")?;
|
||||
writeln!(self.out, "{l2}if (!{gate_name}) {{")?;
|
||||
let l3 = l2.next();
|
||||
for sta in continuing.iter() {
|
||||
self.write_stmt(module, sta, func_ctx, l3)?;
|
||||
}
|
||||
if let Some(condition) = break_if {
|
||||
write!(self.out, "{}if (", l3)?;
|
||||
write!(self.out, "{l3}if (")?;
|
||||
self.write_expr(module, condition, func_ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
writeln!(self.out, "{}break;", l3.next())?;
|
||||
writeln!(self.out, "{}}}", l3)?;
|
||||
writeln!(self.out, "{l3}}}")?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
writeln!(self.out, "{}{} = false;", l2, gate_name)?;
|
||||
writeln!(self.out, "{l2}}}")?;
|
||||
writeln!(self.out, "{l2}{gate_name} = false;")?;
|
||||
} else {
|
||||
writeln!(self.out, "{}while(true) {{", level)?;
|
||||
writeln!(self.out, "{level}while(true) {{")?;
|
||||
}
|
||||
|
||||
for sta in body.iter() {
|
||||
self.write_stmt(module, sta, func_ctx, l2)?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
Statement::Break => writeln!(self.out, "{}break;", level)?,
|
||||
Statement::Continue => writeln!(self.out, "{}continue;", level)?,
|
||||
Statement::Break => writeln!(self.out, "{level}break;")?,
|
||||
Statement::Continue => writeln!(self.out, "{level}continue;")?,
|
||||
Statement::Barrier(barrier) => {
|
||||
self.write_barrier(barrier, level)?;
|
||||
}
|
||||
@@ -1755,7 +1745,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
array_index,
|
||||
value,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
|
||||
write!(self.out, "[")?;
|
||||
@@ -1780,7 +1770,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
ref arguments,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
if let Some(expr) = result {
|
||||
write!(self.out, "const ")?;
|
||||
let name = format!("{}{}", back::BAKE_PREFIX, expr.index());
|
||||
@@ -1791,11 +1781,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
self.write_value_type(module, value)?
|
||||
}
|
||||
};
|
||||
write!(self.out, " {} = ", name)?;
|
||||
write!(self.out, " {name} = ")?;
|
||||
self.named_expressions.insert(expr, name);
|
||||
}
|
||||
let func_name = &self.names[&NameKey::Function(function)];
|
||||
write!(self.out, "{}(", func_name)?;
|
||||
write!(self.out, "{func_name}(")?;
|
||||
for (index, argument) in arguments.iter().enumerate() {
|
||||
self.write_expr(module, *argument, func_ctx)?;
|
||||
// Only write a comma if isn't the last element
|
||||
@@ -1812,7 +1802,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
value,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
|
||||
match func_ctx.info[result].ty {
|
||||
proc::TypeResolution::Handle(handle) => self.write_type(module, handle)?,
|
||||
@@ -1827,11 +1817,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
let var_name = &self.names[&NameKey::GlobalVariable(var_handle)];
|
||||
|
||||
let fun_str = fun.to_hlsl_suffix();
|
||||
write!(
|
||||
self.out,
|
||||
" {}; {}.Interlocked{}(",
|
||||
res_name, var_name, fun_str
|
||||
)?;
|
||||
write!(self.out, " {res_name}; {var_name}.Interlocked{fun_str}(")?;
|
||||
self.write_storage_address(module, &chain, func_ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
// handle the special cases
|
||||
@@ -1846,7 +1832,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
_ => {}
|
||||
}
|
||||
self.write_expr(module, value, func_ctx)?;
|
||||
writeln!(self.out, ", {});", res_name)?;
|
||||
writeln!(self.out, ", {res_name});")?;
|
||||
self.temp_access_chain = chain;
|
||||
self.named_expressions.insert(result, res_name);
|
||||
}
|
||||
@@ -1855,7 +1841,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
ref cases,
|
||||
} => {
|
||||
// Start the switch
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "switch(")?;
|
||||
self.write_expr(module, selector, func_ctx)?;
|
||||
writeln!(self.out, ") {{")?;
|
||||
@@ -1873,13 +1859,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
|
||||
for (i, case) in cases.iter().enumerate() {
|
||||
match case.value {
|
||||
crate::SwitchValue::Integer(value) => write!(
|
||||
self.out,
|
||||
"{}case {}{}:",
|
||||
indent_level_1, value, type_postfix
|
||||
)?,
|
||||
crate::SwitchValue::Integer(value) => {
|
||||
write!(self.out, "{indent_level_1}case {value}{type_postfix}:")?
|
||||
}
|
||||
crate::SwitchValue::Default => {
|
||||
write!(self.out, "{}default:", indent_level_1)?
|
||||
write!(self.out, "{indent_level_1}default:")?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1923,16 +1907,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
.unwrap();
|
||||
let indent_level_3 = indent_level_2.next();
|
||||
for case in &cases[i..=end_case_idx] {
|
||||
writeln!(self.out, "{}{{", indent_level_2)?;
|
||||
writeln!(self.out, "{indent_level_2}{{")?;
|
||||
for sta in case.body.iter() {
|
||||
self.write_stmt(module, sta, func_ctx, indent_level_3)?;
|
||||
}
|
||||
writeln!(self.out, "{}}}", indent_level_2)?;
|
||||
writeln!(self.out, "{indent_level_2}}}")?;
|
||||
}
|
||||
|
||||
let last_case = &cases[end_case_idx];
|
||||
if last_case.body.last().map_or(true, |s| !s.is_terminator()) {
|
||||
writeln!(self.out, "{}break;", indent_level_2)?;
|
||||
writeln!(self.out, "{indent_level_2}break;")?;
|
||||
}
|
||||
} else {
|
||||
for sta in case.body.iter() {
|
||||
@@ -1941,16 +1925,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
if !case.fall_through
|
||||
&& case.body.last().map_or(true, |s| !s.is_terminator())
|
||||
{
|
||||
writeln!(self.out, "{}break;", indent_level_2)?;
|
||||
writeln!(self.out, "{indent_level_2}break;")?;
|
||||
}
|
||||
}
|
||||
|
||||
if write_block_braces {
|
||||
writeln!(self.out, "{}}}", indent_level_1)?;
|
||||
writeln!(self.out, "{indent_level_1}}}")?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1977,15 +1961,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
};
|
||||
let closing_bracket = match ff_input {
|
||||
Some(crate::BuiltIn::VertexIndex) => {
|
||||
write!(self.out, "({}.{} + ", SPECIAL_CBUF_VAR, SPECIAL_BASE_VERTEX)?;
|
||||
write!(self.out, "({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_VERTEX} + ")?;
|
||||
")"
|
||||
}
|
||||
Some(crate::BuiltIn::InstanceIndex) => {
|
||||
write!(
|
||||
self.out,
|
||||
"({}.{} + ",
|
||||
SPECIAL_CBUF_VAR, SPECIAL_BASE_INSTANCE,
|
||||
)?;
|
||||
write!(self.out, "({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_INSTANCE} + ",)?;
|
||||
")"
|
||||
}
|
||||
Some(crate::BuiltIn::NumWorkGroups) => {
|
||||
@@ -1994,13 +1974,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
// of workgroups, which we are using here.
|
||||
write!(
|
||||
self.out,
|
||||
"uint3({}.{}, {}.{}, {}.{})",
|
||||
SPECIAL_CBUF_VAR,
|
||||
SPECIAL_BASE_VERTEX,
|
||||
SPECIAL_CBUF_VAR,
|
||||
SPECIAL_BASE_INSTANCE,
|
||||
SPECIAL_CBUF_VAR,
|
||||
SPECIAL_OTHER,
|
||||
"uint3({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_VERTEX}, {SPECIAL_CBUF_VAR}.{SPECIAL_BASE_INSTANCE}, {SPECIAL_CBUF_VAR}.{SPECIAL_OTHER})",
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
@@ -2008,7 +1982,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
};
|
||||
|
||||
if let Some(name) = self.named_expressions.get(&expr) {
|
||||
write!(self.out, "{}{}", name, closing_bracket)?;
|
||||
write!(self.out, "{name}{closing_bracket}")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -2177,7 +2151,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
TypeInner::Matrix { .. }
|
||||
| TypeInner::Array { .. }
|
||||
| TypeInner::BindingArray { .. } => write!(writer.out, "[{}]", index)?,
|
||||
| TypeInner::BindingArray { .. } => write!(writer.out, "[{index}]")?,
|
||||
TypeInner::Struct { .. } => {
|
||||
// This will never panic in case the type is a `Struct`, this is not true
|
||||
// for other types so we can only check while inside this match arm
|
||||
@@ -2190,7 +2164,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
)?
|
||||
}
|
||||
ref other => {
|
||||
return Err(Error::Custom(format!("Cannot index {:?}", other)))
|
||||
return Err(Error::Custom(format!("Cannot index {other:?}")))
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -2205,7 +2179,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}) = get_inner_matrix_of_struct_array_member(module, base, func_ctx, true)
|
||||
{
|
||||
self.write_expr(module, base, func_ctx)?;
|
||||
write!(self.out, "._{}", index)?;
|
||||
write!(self.out, "._{index}")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -2257,7 +2231,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
};
|
||||
let name = &self.names[&key];
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
}
|
||||
Expression::ImageSample {
|
||||
image,
|
||||
@@ -2289,11 +2263,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
};
|
||||
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
write!(
|
||||
self.out,
|
||||
".{}{}{}{}(",
|
||||
base_str, cmp_str, component_str, level_str
|
||||
)?;
|
||||
write!(self.out, ".{base_str}{cmp_str}{component_str}{level_str}(")?;
|
||||
self.write_expr(module, sampler, func_ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
self.write_texture_coordinates(
|
||||
@@ -2399,7 +2369,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
crate::AddressSpace::Storage { .. } => {}
|
||||
_ => {
|
||||
let name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
}
|
||||
},
|
||||
Expression::LocalVariable(handle) => {
|
||||
@@ -2470,13 +2440,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
Some(Sk::Bool) => "!",
|
||||
ref other => {
|
||||
return Err(Error::Custom(format!(
|
||||
"Cannot apply not to type {:?}",
|
||||
other
|
||||
"Cannot apply not to type {other:?}"
|
||||
)))
|
||||
}
|
||||
},
|
||||
};
|
||||
write!(self.out, "{}(", op_str)?;
|
||||
write!(self.out, "{op_str}(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
@@ -2511,8 +2480,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::as {:?}",
|
||||
inner
|
||||
"write_expr expression::as {inner:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
@@ -2606,7 +2574,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
Mf::FindLsb => Function::Regular("firstbitlow"),
|
||||
Mf::FindMsb => Function::Regular("firstbithigh"),
|
||||
Mf::Unpack2x16float => Function::Unpack2x16float,
|
||||
_ => return Err(Error::Unimplemented(format!("write_expr_math {:?}", fun))),
|
||||
_ => return Err(Error::Unimplemented(format!("write_expr_math {fun:?}"))),
|
||||
};
|
||||
|
||||
match fun {
|
||||
@@ -2637,7 +2605,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, ") >> 16))")?;
|
||||
}
|
||||
Function::Regular(fun_name) => {
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(module, arg, func_ctx)?;
|
||||
if let Some(arg) = arg1 {
|
||||
write!(self.out, ", ")?;
|
||||
@@ -2659,11 +2627,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
.inner_with(&module.types)
|
||||
.scalar_kind();
|
||||
if let Some(ScalarKind::Sint) = *scalar_kind {
|
||||
write!(self.out, "asint({}(asuint(", fun_name)?;
|
||||
write!(self.out, "asint({fun_name}(asuint(")?;
|
||||
self.write_expr(module, arg, func_ctx)?;
|
||||
write!(self.out, ")))")?;
|
||||
} else {
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(module, arg, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
@@ -2718,7 +2686,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
write!(self.out, "((")?;
|
||||
self.write_wrapped_array_length_function_name(wrapped_array_length)?;
|
||||
let var_name = &self.names[&NameKey::GlobalVariable(var_handle)];
|
||||
write!(self.out, "({}) - {}) / {})", var_name, offset, stride)?
|
||||
write!(self.out, "({var_name}) - {offset}) / {stride})")?
|
||||
}
|
||||
Expression::Derivative { axis, expr } => {
|
||||
use crate::DerivativeAxis as Da;
|
||||
@@ -2728,7 +2696,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
Da::Y => "ddy",
|
||||
Da::Width => "fwidth",
|
||||
};
|
||||
write!(self.out, "{}(", fun_str)?;
|
||||
write!(self.out, "{fun_str}(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
@@ -2743,7 +2711,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
Rf::IsFinite => "isfinite",
|
||||
Rf::IsNormal => "isnormal",
|
||||
};
|
||||
write!(self.out, "{}(", fun_str)?;
|
||||
write!(self.out, "{fun_str}(")?;
|
||||
self.write_expr(module, argument, func_ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
@@ -2758,7 +2726,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
};
|
||||
write!(self.out, "(")?;
|
||||
self.write_expr(module, value, func_ctx)?;
|
||||
write!(self.out, ").{}", number_of_components)?
|
||||
write!(self.out, ").{number_of_components}")?
|
||||
}
|
||||
Expression::Select {
|
||||
condition,
|
||||
@@ -2778,7 +2746,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
}
|
||||
|
||||
if !closing_bracket.is_empty() {
|
||||
write!(self.out, "{}", closing_bracket)?;
|
||||
write!(self.out, "{closing_bracket}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -2848,12 +2816,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
use crate::ScalarValue as Sv;
|
||||
|
||||
match value {
|
||||
Sv::Sint(value) => write!(self.out, "{}", value)?,
|
||||
Sv::Uint(value) => write!(self.out, "{}u", value)?,
|
||||
Sv::Sint(value) => write!(self.out, "{value}")?,
|
||||
Sv::Uint(value) => write!(self.out, "{value}u")?,
|
||||
// Floats are written using `Debug` instead of `Display` because it always appends the
|
||||
// decimal part even it's zero
|
||||
Sv::Float(value) => write!(self.out, "{:?}", value)?,
|
||||
Sv::Bool(value) => write!(self.out, "{}", value)?,
|
||||
Sv::Float(value) => write!(self.out, "{value:?}")?,
|
||||
Sv::Bool(value) => write!(self.out, "{value}")?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -2870,7 +2838,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
proc::TypeResolution::Handle(ty_handle) => match module.types[ty_handle].inner {
|
||||
TypeInner::Struct { .. } => {
|
||||
let ty_name = &self.names[&NameKey::Type(ty_handle)];
|
||||
write!(self.out, "{}", ty_name)?;
|
||||
write!(self.out, "{ty_name}")?;
|
||||
}
|
||||
_ => {
|
||||
self.write_type(module, ty_handle)?;
|
||||
@@ -2884,7 +2852,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
let base_ty_res = &ctx.info[handle].ty;
|
||||
let resolved = base_ty_res.inner_with(&module.types);
|
||||
|
||||
write!(self.out, " {}", name)?;
|
||||
write!(self.out, " {name}")?;
|
||||
// If rhs is a array type, we should write array size
|
||||
if let TypeInner::Array { base, size, .. } = *resolved {
|
||||
self.write_array_size(module, base, size)?;
|
||||
@@ -2910,10 +2878,10 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
|
||||
|
||||
fn write_barrier(&mut self, barrier: crate::Barrier, level: back::Level) -> BackendResult {
|
||||
if barrier.contains(crate::Barrier::STORAGE) {
|
||||
writeln!(self.out, "{}DeviceMemoryBarrierWithGroupSync();", level)?;
|
||||
writeln!(self.out, "{level}DeviceMemoryBarrierWithGroupSync();")?;
|
||||
}
|
||||
if barrier.contains(crate::Barrier::WORK_GROUP) {
|
||||
writeln!(self.out, "{}GroupMemoryBarrierWithGroupSync();", level)?;
|
||||
writeln!(self.out, "{level}GroupMemoryBarrierWithGroupSync();")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -412,16 +412,16 @@ impl ResolvedBinding {
|
||||
return Err(Error::UnsupportedBuiltIn(built_in))
|
||||
}
|
||||
};
|
||||
write!(out, "{}", name)?;
|
||||
write!(out, "{name}")?;
|
||||
}
|
||||
Self::Attribute(index) => write!(out, "attribute({})", index)?,
|
||||
Self::Color(index) => write!(out, "color({})", index)?,
|
||||
Self::Attribute(index) => write!(out, "attribute({index})")?,
|
||||
Self::Color(index) => write!(out, "color({index})")?,
|
||||
Self::User {
|
||||
prefix,
|
||||
index,
|
||||
interpolation,
|
||||
} => {
|
||||
write!(out, "user({}{})", prefix, index)?;
|
||||
write!(out, "user({prefix}{index})")?;
|
||||
if let Some(interpolation) = interpolation {
|
||||
write!(out, ", ")?;
|
||||
interpolation.try_fmt(out)?;
|
||||
@@ -429,11 +429,11 @@ impl ResolvedBinding {
|
||||
}
|
||||
Self::Resource(ref target) => {
|
||||
if let Some(id) = target.buffer {
|
||||
write!(out, "buffer({})", id)?;
|
||||
write!(out, "buffer({id})")?;
|
||||
} else if let Some(id) = target.texture {
|
||||
write!(out, "texture({})", id)?;
|
||||
write!(out, "texture({id})")?;
|
||||
} else if let Some(BindSamplerTarget::Resource(id)) = target.sampler {
|
||||
write!(out, "sampler({})", id)?;
|
||||
write!(out, "sampler({id})")?;
|
||||
} else {
|
||||
return Err(Error::UnimplementedBindTarget(target.clone()));
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -187,12 +187,12 @@ impl<W: Write> Writer<W> {
|
||||
use crate::ScalarValue as Sv;
|
||||
|
||||
match value {
|
||||
Sv::Sint(value) => write!(self.out, "{}", value)?,
|
||||
Sv::Uint(value) => write!(self.out, "{}u", value)?,
|
||||
Sv::Sint(value) => write!(self.out, "{value}")?,
|
||||
Sv::Uint(value) => write!(self.out, "{value}u")?,
|
||||
// Floats are written using `Debug` instead of `Display` because it always appends the
|
||||
// decimal part even it's zero
|
||||
Sv::Float(value) => write!(self.out, "{:?}", value)?,
|
||||
Sv::Bool(value) => write!(self.out, "{}", value)?,
|
||||
Sv::Float(value) => write!(self.out, "{value:?}")?,
|
||||
Sv::Bool(value) => write!(self.out, "{value}")?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -211,7 +211,7 @@ impl<W: Write> Writer<W> {
|
||||
ShaderStage::Vertex => "VertexOutput",
|
||||
};
|
||||
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -238,7 +238,7 @@ impl<W: Write> Writer<W> {
|
||||
};
|
||||
|
||||
// Write function name
|
||||
write!(self.out, "fn {}(", func_name)?;
|
||||
write!(self.out, "fn {func_name}(")?;
|
||||
|
||||
// Write function arguments
|
||||
for (index, arg) in func.arguments.iter().enumerate() {
|
||||
@@ -259,7 +259,7 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
};
|
||||
|
||||
write!(self.out, "{}: ", argument_name)?;
|
||||
write!(self.out, "{argument_name}: ")?;
|
||||
// Write argument type
|
||||
self.write_type(module, arg.ty)?;
|
||||
if index < func.arguments.len() - 1 {
|
||||
@@ -333,10 +333,10 @@ impl<W: Write> Writer<W> {
|
||||
fn write_attributes(&mut self, attributes: &[Attribute]) -> BackendResult {
|
||||
for attribute in attributes {
|
||||
match *attribute {
|
||||
Attribute::Location(id) => write!(self.out, "@location({}) ", id)?,
|
||||
Attribute::Location(id) => write!(self.out, "@location({id}) ")?,
|
||||
Attribute::BuiltIn(builtin_attrib) => {
|
||||
if let Some(builtin) = builtin_str(builtin_attrib) {
|
||||
write!(self.out, "@builtin({}) ", builtin)?;
|
||||
write!(self.out, "@builtin({builtin}) ")?;
|
||||
} else {
|
||||
log::warn!("Unsupported builtin attribute: {:?}", builtin_attrib);
|
||||
}
|
||||
@@ -347,7 +347,7 @@ impl<W: Write> Writer<W> {
|
||||
ShaderStage::Fragment => "fragment",
|
||||
ShaderStage::Compute => "compute",
|
||||
};
|
||||
write!(self.out, "@{} ", stage_str)?;
|
||||
write!(self.out, "@{stage_str} ")?;
|
||||
}
|
||||
Attribute::WorkGroupSize(size) => {
|
||||
write!(
|
||||
@@ -356,8 +356,8 @@ impl<W: Write> Writer<W> {
|
||||
size[0], size[1], size[2]
|
||||
)?;
|
||||
}
|
||||
Attribute::Binding(id) => write!(self.out, "@binding({}) ", id)?,
|
||||
Attribute::Group(id) => write!(self.out, "@group({}) ", id)?,
|
||||
Attribute::Binding(id) => write!(self.out, "@binding({id}) ")?,
|
||||
Attribute::Group(id) => write!(self.out, "@group({id}) ")?,
|
||||
Attribute::Invariant => write!(self.out, "@invariant ")?,
|
||||
Attribute::Interpolate(interpolation, sampling) => {
|
||||
if sampling.is_some() && sampling != Some(crate::Sampling::Center) {
|
||||
@@ -419,7 +419,7 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
// Write struct member name and type
|
||||
let member_name = &self.names[&NameKey::StructMember(handle, index as u32)];
|
||||
write!(self.out, "{}: ", member_name)?;
|
||||
write!(self.out, "{member_name}: ")?;
|
||||
self.write_type(module, member.ty)?;
|
||||
write!(self.out, ",")?;
|
||||
writeln!(self.out)?;
|
||||
@@ -500,12 +500,11 @@ impl<W: Write> Writer<W> {
|
||||
};
|
||||
write!(
|
||||
self.out,
|
||||
"texture_{}{}{}{}",
|
||||
class_str, multisampled_str, dim_str, arrayed_str
|
||||
"texture_{class_str}{multisampled_str}{dim_str}{arrayed_str}"
|
||||
)?;
|
||||
|
||||
if !format_str.is_empty() {
|
||||
write!(self.out, "<{}{}>", format_str, storage_str)?;
|
||||
write!(self.out, "<{format_str}{storage_str}>")?;
|
||||
}
|
||||
}
|
||||
TypeInner::Scalar { kind, width } => {
|
||||
@@ -569,12 +568,12 @@ impl<W: Write> Writer<W> {
|
||||
// Naga IR never produces pointers to handles, so it doesn't matter much
|
||||
// how we write such a type. Just write it as the base type alone.
|
||||
if let Some(space) = address {
|
||||
write!(self.out, "ptr<{}, ", space)?;
|
||||
write!(self.out, "ptr<{space}, ")?;
|
||||
}
|
||||
self.write_type(module, base)?;
|
||||
if address.is_some() {
|
||||
if let Some(access) = maybe_access {
|
||||
write!(self.out, ", {}", access)?;
|
||||
write!(self.out, ", {access}")?;
|
||||
}
|
||||
write!(self.out, ">")?;
|
||||
}
|
||||
@@ -589,13 +588,12 @@ impl<W: Write> Writer<W> {
|
||||
if let Some(space) = address {
|
||||
write!(self.out, "ptr<{}, {}", space, scalar_kind_str(kind, width))?;
|
||||
if let Some(access) = maybe_access {
|
||||
write!(self.out, ", {}", access)?;
|
||||
write!(self.out, ", {access}")?;
|
||||
}
|
||||
write!(self.out, ">")?;
|
||||
} else {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"ValuePointer to AddressSpace::Handle {:?}",
|
||||
inner
|
||||
"ValuePointer to AddressSpace::Handle {inner:?}"
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -615,22 +613,18 @@ impl<W: Write> Writer<W> {
|
||||
scalar_kind_str(kind, width)
|
||||
)?;
|
||||
if let Some(access) = maybe_access {
|
||||
write!(self.out, ", {}", access)?;
|
||||
write!(self.out, ", {access}")?;
|
||||
}
|
||||
write!(self.out, ">")?;
|
||||
} else {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"ValuePointer to AddressSpace::Handle {:?}",
|
||||
inner
|
||||
"ValuePointer to AddressSpace::Handle {inner:?}"
|
||||
)));
|
||||
}
|
||||
write!(self.out, ">")?;
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_value_type {:?}",
|
||||
inner
|
||||
)));
|
||||
return Err(Error::Unimplemented(format!("write_value_type {inner:?}")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +654,7 @@ impl<W: Write> Writer<W> {
|
||||
// Also, we use sanitized names! It defense backend from generating variable with name from reserved keywords.
|
||||
Some(self.namer.call(name))
|
||||
} else if info.ref_count == 0 {
|
||||
write!(self.out, "{}_ = ", level)?;
|
||||
write!(self.out, "{level}_ = ")?;
|
||||
self.write_expr(module, handle, func_ctx)?;
|
||||
writeln!(self.out, ";")?;
|
||||
continue;
|
||||
@@ -698,7 +692,7 @@ impl<W: Write> Writer<W> {
|
||||
};
|
||||
|
||||
if let Some(name) = expr_name {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
self.start_named_expr(module, handle, func_ctx, &name)?;
|
||||
self.write_expr(module, handle, func_ctx)?;
|
||||
self.named_expressions.insert(handle, name);
|
||||
@@ -712,7 +706,7 @@ impl<W: Write> Writer<W> {
|
||||
ref accept,
|
||||
ref reject,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "if ")?;
|
||||
self.write_expr(module, condition, func_ctx)?;
|
||||
writeln!(self.out, " {{")?;
|
||||
@@ -726,7 +720,7 @@ impl<W: Write> Writer<W> {
|
||||
// If there are no statements in the reject block we skip writing it
|
||||
// This is only for readability
|
||||
if !reject.is_empty() {
|
||||
writeln!(self.out, "{}}} else {{", level)?;
|
||||
writeln!(self.out, "{level}}} else {{")?;
|
||||
|
||||
for sta in reject {
|
||||
// Increase indentation to help with readability
|
||||
@@ -734,10 +728,10 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
Statement::Return { value } => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "return")?;
|
||||
if let Some(return_value) = value {
|
||||
// The leading space is important
|
||||
@@ -748,7 +742,7 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
// TODO: copy-paste from glsl-out
|
||||
Statement::Kill => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "discard;")?
|
||||
}
|
||||
Statement::Store { pointer, value } => {
|
||||
@@ -760,7 +754,7 @@ impl<W: Write> Writer<W> {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
|
||||
let is_atomic = match *func_ctx.info[pointer].ty.inner_with(&module.types) {
|
||||
crate::TypeInner::Pointer { base, .. } => match module.types[base].inner {
|
||||
@@ -792,14 +786,14 @@ impl<W: Write> Writer<W> {
|
||||
ref arguments,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
if let Some(expr) = result {
|
||||
let name = format!("{}{}", back::BAKE_PREFIX, expr.index());
|
||||
self.start_named_expr(module, expr, func_ctx, &name)?;
|
||||
self.named_expressions.insert(expr, name);
|
||||
}
|
||||
let func_name = &self.names[&NameKey::Function(function)];
|
||||
write!(self.out, "{}(", func_name)?;
|
||||
write!(self.out, "{func_name}(")?;
|
||||
for (index, &argument) in arguments.iter().enumerate() {
|
||||
self.write_expr(module, argument, func_ctx)?;
|
||||
// Only write a comma if isn't the last element
|
||||
@@ -816,13 +810,13 @@ impl<W: Write> Writer<W> {
|
||||
value,
|
||||
result,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
let res_name = format!("{}{}", back::BAKE_PREFIX, result.index());
|
||||
self.start_named_expr(module, result, func_ctx, &res_name)?;
|
||||
self.named_expressions.insert(result, res_name);
|
||||
|
||||
let fun_str = fun.to_wgsl();
|
||||
write!(self.out, "atomic{}(", fun_str)?;
|
||||
write!(self.out, "atomic{fun_str}(")?;
|
||||
self.write_expr(module, pointer, func_ctx)?;
|
||||
if let crate::AtomicFunction::Exchange { compare: Some(cmp) } = *fun {
|
||||
write!(self.out, ", ")?;
|
||||
@@ -838,7 +832,7 @@ impl<W: Write> Writer<W> {
|
||||
array_index,
|
||||
value,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "textureStore(")?;
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
@@ -853,20 +847,20 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
// TODO: copy-paste from glsl-out
|
||||
Statement::Block(ref block) => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "{{")?;
|
||||
for sta in block.iter() {
|
||||
// Increase the indentation to help with readability
|
||||
self.write_stmt(module, sta, func_ctx, level.next())?
|
||||
}
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
Statement::Switch {
|
||||
selector,
|
||||
ref cases,
|
||||
} => {
|
||||
// Start the switch
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
write!(self.out, "switch ")?;
|
||||
self.write_expr(module, selector, func_ctx)?;
|
||||
writeln!(self.out, " {{")?;
|
||||
@@ -892,16 +886,16 @@ impl<W: Write> Writer<W> {
|
||||
match case.value {
|
||||
crate::SwitchValue::Integer(value) => {
|
||||
if new_case {
|
||||
write!(self.out, "{}case ", l2)?;
|
||||
write!(self.out, "{l2}case ")?;
|
||||
}
|
||||
write!(self.out, "{}{}", value, type_postfix)?;
|
||||
write!(self.out, "{value}{type_postfix}")?;
|
||||
}
|
||||
crate::SwitchValue::Default => {
|
||||
if new_case {
|
||||
if case.fall_through {
|
||||
write!(self.out, "{}case ", l2)?;
|
||||
write!(self.out, "{l2}case ")?;
|
||||
} else {
|
||||
write!(self.out, "{}", l2)?;
|
||||
write!(self.out, "{l2}")?;
|
||||
}
|
||||
}
|
||||
write!(self.out, "default")?;
|
||||
@@ -921,18 +915,18 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
|
||||
if !case.fall_through {
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
writeln!(self.out, "{l2}}}")?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
Statement::Loop {
|
||||
ref body,
|
||||
ref continuing,
|
||||
break_if,
|
||||
} => {
|
||||
write!(self.out, "{}", level)?;
|
||||
write!(self.out, "{level}")?;
|
||||
writeln!(self.out, "loop {{")?;
|
||||
|
||||
let l2 = level.next();
|
||||
@@ -945,7 +939,7 @@ impl<W: Write> Writer<W> {
|
||||
// so even if `continuing` is empty we must generate it if a
|
||||
// `break if` exists
|
||||
if !continuing.is_empty() || break_if.is_some() {
|
||||
writeln!(self.out, "{}continuing {{", l2)?;
|
||||
writeln!(self.out, "{l2}continuing {{")?;
|
||||
for sta in continuing.iter() {
|
||||
self.write_stmt(module, sta, func_ctx, l2.next())?;
|
||||
}
|
||||
@@ -960,24 +954,24 @@ impl<W: Write> Writer<W> {
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", l2)?;
|
||||
writeln!(self.out, "{l2}}}")?;
|
||||
}
|
||||
|
||||
writeln!(self.out, "{}}}", level)?
|
||||
writeln!(self.out, "{level}}}")?
|
||||
}
|
||||
Statement::Break => {
|
||||
writeln!(self.out, "{}break;", level)?;
|
||||
writeln!(self.out, "{level}break;")?;
|
||||
}
|
||||
Statement::Continue => {
|
||||
writeln!(self.out, "{}continue;", level)?;
|
||||
writeln!(self.out, "{level}continue;")?;
|
||||
}
|
||||
Statement::Barrier(barrier) => {
|
||||
if barrier.contains(crate::Barrier::STORAGE) {
|
||||
writeln!(self.out, "{}storageBarrier();", level)?;
|
||||
writeln!(self.out, "{level}storageBarrier();")?;
|
||||
}
|
||||
|
||||
if barrier.contains(crate::Barrier::WORK_GROUP) {
|
||||
writeln!(self.out, "{}workgroupBarrier();", level)?;
|
||||
writeln!(self.out, "{level}workgroupBarrier();")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1052,7 +1046,7 @@ impl<W: Write> Writer<W> {
|
||||
name: &str,
|
||||
) -> BackendResult {
|
||||
// Write variable name
|
||||
write!(self.out, "let {}", name)?;
|
||||
write!(self.out, "let {name}")?;
|
||||
if self.flags.contains(WriterFlags::EXPLICIT_TYPES) {
|
||||
write!(self.out, ": ")?;
|
||||
let ty = &func_ctx.info[handle].ty;
|
||||
@@ -1139,7 +1133,7 @@ impl<W: Write> Writer<W> {
|
||||
use crate::Expression;
|
||||
|
||||
if let Some(name) = self.named_expressions.get(&expr) {
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@@ -1203,7 +1197,7 @@ impl<W: Write> Writer<W> {
|
||||
Expression::FunctionArgument(pos) => {
|
||||
let name_key = func_ctx.argument_key(pos);
|
||||
let name = &self.names[&name_key];
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
}
|
||||
Expression::Binary { op, left, right } => {
|
||||
write!(self.out, "(")?;
|
||||
@@ -1240,7 +1234,7 @@ impl<W: Write> Writer<W> {
|
||||
TypeInner::Matrix { .. }
|
||||
| TypeInner::Array { .. }
|
||||
| TypeInner::BindingArray { .. }
|
||||
| TypeInner::ValuePointer { .. } => write!(self.out, "[{}]", index)?,
|
||||
| TypeInner::ValuePointer { .. } => write!(self.out, "[{index}]")?,
|
||||
TypeInner::Struct { .. } => {
|
||||
// This will never panic in case the type is a `Struct`, this is not true
|
||||
// for other types so we can only check while inside this match arm
|
||||
@@ -1252,7 +1246,7 @@ impl<W: Write> Writer<W> {
|
||||
&self.names[&NameKey::StructMember(ty, index)]
|
||||
)?
|
||||
}
|
||||
ref other => return Err(Error::Custom(format!("Cannot index {:?}", other))),
|
||||
ref other => return Err(Error::Custom(format!("Cannot index {other:?}"))),
|
||||
}
|
||||
}
|
||||
Expression::ImageSample {
|
||||
@@ -1278,7 +1272,7 @@ impl<W: Write> Writer<W> {
|
||||
Sl::Gradient { .. } => "Grad",
|
||||
};
|
||||
|
||||
write!(self.out, "textureSample{}{}(", suffix_cmp, suffix_level)?;
|
||||
write!(self.out, "textureSample{suffix_cmp}{suffix_level}(")?;
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
write!(self.out, ", ")?;
|
||||
self.write_expr(module, sampler, func_ctx)?;
|
||||
@@ -1341,7 +1335,7 @@ impl<W: Write> Writer<W> {
|
||||
None => "",
|
||||
};
|
||||
|
||||
write!(self.out, "textureGather{}(", suffix_cmp)?;
|
||||
write!(self.out, "textureGather{suffix_cmp}(")?;
|
||||
match *func_ctx.info[image].ty.inner_with(&module.types) {
|
||||
TypeInner::Image {
|
||||
class: crate::ImageClass::Depth { multi: _ },
|
||||
@@ -1384,7 +1378,7 @@ impl<W: Write> Writer<W> {
|
||||
Iq::NumSamples => "textureNumSamples",
|
||||
};
|
||||
|
||||
write!(self.out, "{}(", texture_function)?;
|
||||
write!(self.out, "{texture_function}(")?;
|
||||
self.write_expr(module, image, func_ctx)?;
|
||||
if let Iq::Size { level: Some(level) } = query {
|
||||
write!(self.out, ", ")?;
|
||||
@@ -1415,7 +1409,7 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
Expression::GlobalVariable(handle) => {
|
||||
let name = &self.names[&NameKey::GlobalVariable(handle)];
|
||||
write!(self.out, "{}", name)?;
|
||||
write!(self.out, "{name}")?;
|
||||
}
|
||||
Expression::As {
|
||||
expr,
|
||||
@@ -1443,27 +1437,22 @@ impl<W: Write> Writer<W> {
|
||||
let vector_size_str = back::vector_size_str(size);
|
||||
let scalar_kind_str = scalar_kind_str(kind, convert.unwrap_or(width));
|
||||
if convert.is_some() {
|
||||
write!(self.out, "vec{}<{}>", vector_size_str, scalar_kind_str)?;
|
||||
write!(self.out, "vec{vector_size_str}<{scalar_kind_str}>")?;
|
||||
} else {
|
||||
write!(
|
||||
self.out,
|
||||
"bitcast<vec{}<{}>>",
|
||||
vector_size_str, scalar_kind_str
|
||||
)?;
|
||||
write!(self.out, "bitcast<vec{vector_size_str}<{scalar_kind_str}>>")?;
|
||||
}
|
||||
}
|
||||
TypeInner::Scalar { width, .. } => {
|
||||
let scalar_kind_str = scalar_kind_str(kind, convert.unwrap_or(width));
|
||||
if convert.is_some() {
|
||||
write!(self.out, "{}", scalar_kind_str)?
|
||||
write!(self.out, "{scalar_kind_str}")?
|
||||
} else {
|
||||
write!(self.out, "bitcast<{}>", scalar_kind_str)?
|
||||
write!(self.out, "bitcast<{scalar_kind_str}>")?
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::as {:?}",
|
||||
inner
|
||||
"write_expr expression::as {inner:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
@@ -1477,15 +1466,14 @@ impl<W: Write> Writer<W> {
|
||||
crate::TypeInner::Scalar { kind, width } => (kind, width),
|
||||
_ => {
|
||||
return Err(Error::Unimplemented(format!(
|
||||
"write_expr expression::splat {:?}",
|
||||
inner
|
||||
"write_expr expression::splat {inner:?}"
|
||||
)));
|
||||
}
|
||||
};
|
||||
let scalar = scalar_kind_str(scalar_kind, scalar_width);
|
||||
let size = back::vector_size_str(size);
|
||||
|
||||
write!(self.out, "vec{}<{}>(", size, scalar)?;
|
||||
write!(self.out, "vec{size}<{scalar}>(")?;
|
||||
self.write_expr(module, value, func_ctx)?;
|
||||
write!(self.out, ")")?;
|
||||
}
|
||||
@@ -1615,7 +1603,7 @@ impl<W: Write> Writer<W> {
|
||||
|
||||
match function {
|
||||
Function::Regular(fun_name) => {
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
self.write_expr(module, arg, func_ctx)?;
|
||||
for arg in IntoIterator::into_iter([arg1, arg2, arg3]).flatten() {
|
||||
write!(self.out, ", ")?;
|
||||
@@ -1651,7 +1639,7 @@ impl<W: Write> Writer<W> {
|
||||
}
|
||||
};
|
||||
|
||||
write!(self.out, "{}(", unary)?;
|
||||
write!(self.out, "{unary}(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
|
||||
write!(self.out, ")")?
|
||||
@@ -1677,7 +1665,7 @@ impl<W: Write> Writer<W> {
|
||||
Da::Y => "dpdy",
|
||||
Da::Width => "fwidth",
|
||||
};
|
||||
write!(self.out, "{}(", op)?;
|
||||
write!(self.out, "{op}(")?;
|
||||
self.write_expr(module, expr, func_ctx)?;
|
||||
write!(self.out, ")")?
|
||||
}
|
||||
@@ -1689,7 +1677,7 @@ impl<W: Write> Writer<W> {
|
||||
Rf::Any => "any",
|
||||
_ => return Err(Error::UnsupportedRelationalFunction(fun)),
|
||||
};
|
||||
write!(self.out, "{}(", fun_name)?;
|
||||
write!(self.out, "{fun_name}(")?;
|
||||
|
||||
self.write_expr(module, argument, func_ctx)?;
|
||||
|
||||
@@ -1724,9 +1712,9 @@ impl<W: Write> Writer<W> {
|
||||
write!(self.out, "var")?;
|
||||
let (address, maybe_access) = address_space_str(global.space);
|
||||
if let Some(space) = address {
|
||||
write!(self.out, "<{}", space)?;
|
||||
write!(self.out, "<{space}")?;
|
||||
if let Some(access) = maybe_access {
|
||||
write!(self.out, ", {}", access)?;
|
||||
write!(self.out, ", {access}")?;
|
||||
}
|
||||
write!(self.out, ">")?;
|
||||
}
|
||||
@@ -1826,22 +1814,22 @@ impl<W: Write> Writer<W> {
|
||||
} => {
|
||||
let name = &self.names[&NameKey::Constant(handle)];
|
||||
// First write only constant name
|
||||
write!(self.out, "const {}: ", name)?;
|
||||
write!(self.out, "const {name}: ")?;
|
||||
// Next write constant type and value
|
||||
match *value {
|
||||
crate::ScalarValue::Sint(value) => {
|
||||
write!(self.out, "i32 = {}", value)?;
|
||||
write!(self.out, "i32 = {value}")?;
|
||||
}
|
||||
crate::ScalarValue::Uint(value) => {
|
||||
write!(self.out, "u32 = {}u", value)?;
|
||||
write!(self.out, "u32 = {value}u")?;
|
||||
}
|
||||
crate::ScalarValue::Float(value) => {
|
||||
// Floats are written using `Debug` instead of `Display` because it always appends the
|
||||
// decimal part even it's zero
|
||||
write!(self.out, "f32 = {:?}", value)?;
|
||||
write!(self.out, "f32 = {value:?}")?;
|
||||
}
|
||||
crate::ScalarValue::Bool(value) => {
|
||||
write!(self.out, "bool = {}", value)?;
|
||||
write!(self.out, "bool = {value}")?;
|
||||
}
|
||||
};
|
||||
// End with semicolon
|
||||
@@ -1850,7 +1838,7 @@ impl<W: Write> Writer<W> {
|
||||
crate::ConstantInner::Composite { ty, ref components } => {
|
||||
let name = &self.names[&NameKey::Constant(handle)];
|
||||
// First write only constant name
|
||||
write!(self.out, "const {}: ", name)?;
|
||||
write!(self.out, "const {name}: ")?;
|
||||
// Next write constant type
|
||||
self.write_type(module, ty)?;
|
||||
|
||||
|
||||
@@ -241,8 +241,7 @@ impl<'a> ConstantSolver<'a> {
|
||||
),
|
||||
_ => {
|
||||
return Err(ConstantSolvingError::NotImplemented(format!(
|
||||
"{:?} applied to vector values",
|
||||
fun
|
||||
"{fun:?} applied to vector values"
|
||||
)))
|
||||
}
|
||||
};
|
||||
@@ -250,7 +249,7 @@ impl<'a> ConstantSolver<'a> {
|
||||
let inner = ConstantInner::Scalar { width, value };
|
||||
Ok(self.register_constant(inner, span))
|
||||
}
|
||||
_ => Err(ConstantSolvingError::NotImplemented(format!("{:?}", fun))),
|
||||
_ => Err(ConstantSolvingError::NotImplemented(format!("{fun:?}"))),
|
||||
}
|
||||
}
|
||||
Expression::As {
|
||||
|
||||
@@ -591,8 +591,7 @@ impl Context {
|
||||
parser.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!(
|
||||
"Cannot apply operation to {:?} and {:?}",
|
||||
left_inner, right_inner
|
||||
"Cannot apply operation to {left_inner:?} and {right_inner:?}"
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@@ -823,8 +822,7 @@ impl Context {
|
||||
parser.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!(
|
||||
"Cannot apply operation to {:?} and {:?}",
|
||||
left_inner, right_inner
|
||||
"Cannot apply operation to {left_inner:?} and {right_inner:?}"
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@@ -914,8 +912,7 @@ impl Context {
|
||||
parser.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!(
|
||||
"Cannot apply operation to {:?} and {:?}",
|
||||
left_inner, right_inner
|
||||
"Cannot apply operation to {left_inner:?} and {right_inner:?}"
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@@ -1383,7 +1380,7 @@ impl Context {
|
||||
_ => {
|
||||
return Err(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!("unknown method '{}'", name).into(),
|
||||
format!("unknown method '{name}'").into(),
|
||||
),
|
||||
meta,
|
||||
});
|
||||
|
||||
@@ -43,7 +43,7 @@ impl From<TokenValue> for ExpectedToken {
|
||||
impl std::fmt::Display for ExpectedToken {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match *self {
|
||||
ExpectedToken::Token(ref token) => write!(f, "{:?}", token),
|
||||
ExpectedToken::Token(ref token) => write!(f, "{token:?}"),
|
||||
ExpectedToken::TypeName => write!(f, "a type"),
|
||||
ExpectedToken::Identifier => write!(f, "identifier"),
|
||||
ExpectedToken::IntLiteral => write!(f, "integer literal"),
|
||||
|
||||
@@ -721,8 +721,7 @@ impl Parser {
|
||||
self.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!(
|
||||
"'{}': image needs {:?} access but only {:?} was provided",
|
||||
name, overload_access, call_access
|
||||
"'{name}': image needs {overload_access:?} access but only {call_access:?} was provided"
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@@ -829,14 +828,14 @@ impl Parser {
|
||||
if ambiguous {
|
||||
self.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!("Ambiguous best function for '{}'", name).into(),
|
||||
format!("Ambiguous best function for '{name}'").into(),
|
||||
),
|
||||
meta,
|
||||
})
|
||||
}
|
||||
|
||||
let overload = maybe_overload.ok_or_else(|| Error {
|
||||
kind: ErrorKind::SemanticError(format!("Unknown function '{}'", name).into()),
|
||||
kind: ErrorKind::SemanticError(format!("Unknown function '{name}'").into()),
|
||||
meta,
|
||||
})?;
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ impl Parser {
|
||||
ctx.typifier
|
||||
.grow(expr, &ctx.expressions, &resolve_ctx)
|
||||
.map_err(|error| Error {
|
||||
kind: ErrorKind::SemanticError(format!("Can't resolve type: {:?}", error).into()),
|
||||
kind: ErrorKind::SemanticError(format!("Can't resolve type: {error:?}").into()),
|
||||
meta,
|
||||
})
|
||||
}
|
||||
@@ -322,7 +322,7 @@ impl Parser {
|
||||
ctx.typifier
|
||||
.invalidate(expr, &ctx.expressions, &resolve_ctx)
|
||||
.map_err(|error| Error {
|
||||
kind: ErrorKind::SemanticError(format!("Can't resolve type: {:?}", error).into()),
|
||||
kind: ErrorKind::SemanticError(format!("Can't resolve type: {error:?}").into()),
|
||||
meta,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -317,8 +317,7 @@ impl Parser {
|
||||
kind:
|
||||
ErrorKind::SemanticError(
|
||||
format!(
|
||||
"swizzle cannot have duplicate components in left-hand-side expression for \"{:?}\"",
|
||||
name
|
||||
"swizzle cannot have duplicate components in left-hand-side expression for \"{name:?}\""
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
@@ -379,7 +378,7 @@ impl Parser {
|
||||
_ => {
|
||||
self.errors.push(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!("Bad swizzle size for \"{:?}\"", name).into(),
|
||||
format!("Bad swizzle size for \"{name:?}\"").into(),
|
||||
),
|
||||
meta,
|
||||
});
|
||||
@@ -413,7 +412,7 @@ impl Parser {
|
||||
} else {
|
||||
Err(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!("Invalid swizzle for vector \"{}\"", name).into(),
|
||||
format!("Invalid swizzle for vector \"{name}\"").into(),
|
||||
),
|
||||
meta,
|
||||
})
|
||||
@@ -421,7 +420,7 @@ impl Parser {
|
||||
}
|
||||
_ => Err(Error {
|
||||
kind: ErrorKind::SemanticError(
|
||||
format!("Can't lookup field on this type \"{}\"", name).into(),
|
||||
format!("Can't lookup field on this type \"{name}\"").into(),
|
||||
),
|
||||
meta,
|
||||
}),
|
||||
|
||||
@@ -170,7 +170,7 @@ impl<I: Iterator<Item = u32>> super::Parser<I> {
|
||||
None => format!("block_ctx.Fun-{}.txt", module.functions.len()),
|
||||
};
|
||||
let dest = prefix.join(dump_suffix);
|
||||
let dump = format!("{:#?}", block_ctx);
|
||||
let dump = format!("{block_ctx:#?}");
|
||||
if let Err(e) = std::fs::write(&dest, dump) {
|
||||
log::error!("Unable to dump the block context into {:?}: {}", dest, e);
|
||||
}
|
||||
|
||||
@@ -1378,7 +1378,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
let result_type_id = self.next()?;
|
||||
let result_id = self.next()?;
|
||||
|
||||
let name = format!("phi_{}", result_id);
|
||||
let name = format!("phi_{result_id}");
|
||||
let local = ctx.local_arena.append(
|
||||
crate::LocalVariable {
|
||||
name: Some(name),
|
||||
|
||||
@@ -218,20 +218,20 @@ impl<'a> Error<'a> {
|
||||
let expected_str = match expected {
|
||||
ExpectedToken::Token(token) => {
|
||||
match token {
|
||||
Token::Separator(c) => format!("'{}'", c),
|
||||
Token::Paren(c) => format!("'{}'", c),
|
||||
Token::Separator(c) => format!("'{c}'"),
|
||||
Token::Paren(c) => format!("'{c}'"),
|
||||
Token::Attribute => "@".to_string(),
|
||||
Token::Number(_) => "number".to_string(),
|
||||
Token::Word(s) => s.to_string(),
|
||||
Token::Operation(c) => format!("operation ('{}')", c),
|
||||
Token::LogicalOperation(c) => format!("logical operation ('{}')", c),
|
||||
Token::ShiftOperation(c) => format!("bitshift ('{}{}')", c, c),
|
||||
Token::AssignmentOperation(c) if c=='<' || c=='>' => format!("bitshift ('{}{}=')", c, c),
|
||||
Token::AssignmentOperation(c) => format!("operation ('{}=')", c),
|
||||
Token::Operation(c) => format!("operation ('{c}')"),
|
||||
Token::LogicalOperation(c) => format!("logical operation ('{c}')"),
|
||||
Token::ShiftOperation(c) => format!("bitshift ('{c}{c}')"),
|
||||
Token::AssignmentOperation(c) if c=='<' || c=='>' => format!("bitshift ('{c}{c}=')"),
|
||||
Token::AssignmentOperation(c) => format!("operation ('{c}=')"),
|
||||
Token::IncrementOperation => "increment operation".to_string(),
|
||||
Token::DecrementOperation => "decrement operation".to_string(),
|
||||
Token::Arrow => "->".to_string(),
|
||||
Token::Unknown(c) => format!("unknown ('{}')", c),
|
||||
Token::Unknown(c) => format!("unknown ('{c}')"),
|
||||
Token::Trivia => "trivia".to_string(),
|
||||
Token::End => "end".to_string(),
|
||||
}
|
||||
@@ -261,7 +261,7 @@ impl<'a> Error<'a> {
|
||||
"expected {}, found '{}'",
|
||||
expected_str, &source[unexpected_span],
|
||||
),
|
||||
labels: vec![(unexpected_span, format!("expected {}", expected_str).into())],
|
||||
labels: vec![(unexpected_span, format!("expected {expected_str}").into())],
|
||||
notes: vec![],
|
||||
}
|
||||
}
|
||||
@@ -305,7 +305,7 @@ impl<'a> Error<'a> {
|
||||
notes: vec![],
|
||||
},
|
||||
Error::UnknownIdent(ident_span, ident) => ParseError {
|
||||
message: format!("no definition in scope for identifier: '{}'", ident),
|
||||
message: format!("no definition in scope for identifier: '{ident}'"),
|
||||
labels: vec![(ident_span, "unknown identifier".into())],
|
||||
notes: vec![],
|
||||
},
|
||||
@@ -342,7 +342,7 @@ impl<'a> Error<'a> {
|
||||
ref from_type,
|
||||
ref to_type,
|
||||
} => {
|
||||
let msg = format!("cannot cast a {} to a {}", from_type, to_type);
|
||||
let msg = format!("cannot cast a {from_type} to a {to_type}");
|
||||
ParseError {
|
||||
message: msg.clone(),
|
||||
labels: vec![(span, msg.into())],
|
||||
@@ -376,10 +376,7 @@ impl<'a> Error<'a> {
|
||||
notes: vec![],
|
||||
},
|
||||
Error::InvalidConstructorComponentType(bad_span, component) => ParseError {
|
||||
message: format!(
|
||||
"invalid type for constructor component at index [{}]",
|
||||
component
|
||||
),
|
||||
message: format!("invalid type for constructor component at index [{component}]"),
|
||||
labels: vec![(bad_span, "invalid component type".into())],
|
||||
notes: vec![],
|
||||
},
|
||||
@@ -435,13 +432,13 @@ impl<'a> Error<'a> {
|
||||
notes: vec![],
|
||||
},
|
||||
Error::SizeAttributeTooLow(bad_span, min_size) => ParseError {
|
||||
message: format!("struct member size must be at least {}", min_size),
|
||||
labels: vec![(bad_span, format!("must be at least {}", min_size).into())],
|
||||
message: format!("struct member size must be at least {min_size}"),
|
||||
labels: vec![(bad_span, format!("must be at least {min_size}").into())],
|
||||
notes: vec![],
|
||||
},
|
||||
Error::AlignAttributeTooLow(bad_span, min_align) => ParseError {
|
||||
message: format!("struct member alignment must be at least {}", min_align),
|
||||
labels: vec![(bad_span, format!("must be at least {}", min_align).into())],
|
||||
message: format!("struct member alignment must be at least {min_align}"),
|
||||
labels: vec![(bad_span, format!("must be at least {min_align}").into())],
|
||||
notes: vec![],
|
||||
},
|
||||
Error::NonPowerOfTwoAlignAttribute(bad_span) => ParseError {
|
||||
@@ -512,7 +509,7 @@ impl<'a> Error<'a> {
|
||||
notes: vec![],
|
||||
},
|
||||
Error::NotReference(what, span) => ParseError {
|
||||
message: format!("{} must be a reference", what),
|
||||
message: format!("{what} must be a reference"),
|
||||
labels: vec![(span, "expression is not a reference".into())],
|
||||
notes: vec![],
|
||||
},
|
||||
@@ -532,7 +529,7 @@ impl<'a> Error<'a> {
|
||||
},
|
||||
},
|
||||
Error::Pointer(what, span) => ParseError {
|
||||
message: format!("{} must not be a pointer", what),
|
||||
message: format!("{what} must not be a pointer"),
|
||||
labels: vec![(span, "expression is a pointer".into())],
|
||||
notes: vec![],
|
||||
},
|
||||
@@ -733,7 +730,7 @@ impl crate::TypeInner {
|
||||
Ti::Pointer { base, .. } => {
|
||||
let base = &types[base];
|
||||
let name = base.name.as_deref().unwrap_or("unknown");
|
||||
format!("ptr<{}>", name)
|
||||
format!("ptr<{name}>")
|
||||
}
|
||||
Ti::ValuePointer { kind, width, .. } => {
|
||||
format!("ptr<{}>", kind.to_wgsl(width))
|
||||
@@ -758,9 +755,9 @@ impl crate::TypeInner {
|
||||
} => size.to_string(),
|
||||
_ => "?".to_string(),
|
||||
});
|
||||
format!("array<{}, {}>", base, size)
|
||||
format!("array<{base}, {size}>")
|
||||
}
|
||||
crate::ArraySize::Dynamic => format!("array<{}>", base),
|
||||
crate::ArraySize::Dynamic => format!("array<{base}>"),
|
||||
}
|
||||
}
|
||||
Ti::Struct { .. } => {
|
||||
@@ -794,7 +791,7 @@ impl crate::TypeInner {
|
||||
// The lexer has already verified this, so we can safely assume it here.
|
||||
// https://gpuweb.github.io/gpuweb/wgsl/#sampled-texture-type
|
||||
let element_type = kind.to_wgsl(4);
|
||||
format!("<{}>", element_type)
|
||||
format!("<{element_type}>")
|
||||
}
|
||||
crate::ImageClass::Depth { multi: _ } => String::new(),
|
||||
crate::ImageClass::Storage { format, access } => {
|
||||
@@ -806,10 +803,7 @@ impl crate::TypeInner {
|
||||
}
|
||||
};
|
||||
|
||||
format!(
|
||||
"texture{}{}{}{}",
|
||||
class_suffix, dim_suffix, array_suffix, type_in_brackets
|
||||
)
|
||||
format!("texture{class_suffix}{dim_suffix}{array_suffix}{type_in_brackets}")
|
||||
}
|
||||
Ti::Sampler { .. } => "sampler".to_string(),
|
||||
Ti::BindingArray { base, size, .. } => {
|
||||
@@ -818,9 +812,9 @@ impl crate::TypeInner {
|
||||
match size {
|
||||
crate::ArraySize::Constant(size) => {
|
||||
let size = constants[size].name.as_deref().unwrap_or("unknown");
|
||||
format!("binding_array<{}, {}>", base, size)
|
||||
format!("binding_array<{base}, {size}>")
|
||||
}
|
||||
crate::ArraySize::Dynamic => format!("binding_array<{}>", base),
|
||||
crate::ArraySize::Dynamic => format!("binding_array<{base}>"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1681,7 +1675,7 @@ impl ParseError {
|
||||
.with_notes(
|
||||
self.notes
|
||||
.iter()
|
||||
.map(|note| format!("note: {}", note))
|
||||
.map(|note| format!("note: {note}"))
|
||||
.collect(),
|
||||
);
|
||||
diagnostic
|
||||
|
||||
@@ -317,7 +317,7 @@ fn parse_hex_float_missing_period(
|
||||
exponent: &str,
|
||||
kind: Option<FloatKind>,
|
||||
) -> Result<Number, NumberError> {
|
||||
let hexf_input = format!("{}.{}", significand, exponent);
|
||||
let hexf_input = format!("{significand}.{exponent}");
|
||||
parse_hex_float(&hexf_input, kind)
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ fn parse_hex_int(
|
||||
kind: Option<IntKind>,
|
||||
) -> Result<Number, NumberError> {
|
||||
let digits_with_sign = if is_negative {
|
||||
Cow::Owned(format!("-{}", digits))
|
||||
Cow::Owned(format!("-{digits}"))
|
||||
} else {
|
||||
Cow::Borrowed(digits)
|
||||
};
|
||||
|
||||
@@ -64,7 +64,7 @@ impl Namer {
|
||||
|
||||
for prefix in &self.reserved_prefixes {
|
||||
if base.starts_with(prefix) {
|
||||
return format!("gen_{}", base).into();
|
||||
return format!("gen_{base}").into();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,11 +210,11 @@ impl Namer {
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Sint(v),
|
||||
} => write!(temp, "const_{}i", v),
|
||||
} => write!(temp, "const_{v}i"),
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Uint(v),
|
||||
} => write!(temp, "const_{}u", v),
|
||||
} => write!(temp, "const_{v}u"),
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Float(v),
|
||||
@@ -237,7 +237,7 @@ impl Namer {
|
||||
crate::ConstantInner::Scalar {
|
||||
width: _,
|
||||
value: crate::ScalarValue::Bool(v),
|
||||
} => write!(temp, "const_{}", v),
|
||||
} => write!(temp, "const_{v}"),
|
||||
crate::ConstantInner::Composite { ty, components: _ } => {
|
||||
write!(temp, "const_{}", output[&NameKey::Type(ty)])
|
||||
}
|
||||
|
||||
@@ -601,8 +601,7 @@ impl<'a> ResolveContext<'a> {
|
||||
(&Ti::Vector { .. }, &Ti::Vector { .. }) => res_left.clone(),
|
||||
(tl, tr) => {
|
||||
return Err(ResolveError::IncompatibleOperands(format!(
|
||||
"{:?} * {:?}",
|
||||
tl, tr
|
||||
"{tl:?} * {tr:?}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
@@ -622,8 +621,7 @@ impl<'a> ResolveContext<'a> {
|
||||
Ti::Vector { size, .. } => Ti::Vector { size, kind, width },
|
||||
ref other => {
|
||||
return Err(ResolveError::IncompatibleOperands(format!(
|
||||
"{:?}({:?}, _)",
|
||||
op, other
|
||||
"{op:?}({other:?}, _)"
|
||||
)))
|
||||
}
|
||||
};
|
||||
@@ -660,8 +658,7 @@ impl<'a> ResolveContext<'a> {
|
||||
}),
|
||||
ref other => {
|
||||
return Err(ResolveError::IncompatibleOperands(format!(
|
||||
"{:?}({:?})",
|
||||
fun, other
|
||||
"{fun:?}({other:?})"
|
||||
)))
|
||||
}
|
||||
},
|
||||
@@ -722,18 +719,18 @@ impl<'a> ResolveContext<'a> {
|
||||
} => TypeResolution::Value(Ti::Scalar { kind, width }),
|
||||
ref other =>
|
||||
return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?}, _)", fun, other)
|
||||
format!("{fun:?}({other:?}, _)")
|
||||
)),
|
||||
},
|
||||
Mf::Outer => {
|
||||
let arg1 = arg1.ok_or_else(|| ResolveError::IncompatibleOperands(
|
||||
format!("{:?}(_, None)", fun)
|
||||
format!("{fun:?}(_, None)")
|
||||
))?;
|
||||
match (res_arg.inner_with(types), past(arg1)?.inner_with(types)) {
|
||||
(&Ti::Vector {kind: _, size: columns,width}, &Ti::Vector{ size: rows, .. }) => TypeResolution::Value(Ti::Matrix { columns, rows, width }),
|
||||
(left, right) =>
|
||||
return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?}, {:?})", fun, left, right)
|
||||
format!("{fun:?}({left:?}, {right:?})")
|
||||
)),
|
||||
}
|
||||
},
|
||||
@@ -743,7 +740,7 @@ impl<'a> ResolveContext<'a> {
|
||||
Ti::Scalar {width,kind} |
|
||||
Ti::Vector {width,kind,size:_} => TypeResolution::Value(Ti::Scalar { kind, width }),
|
||||
ref other => return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?})", fun, other)
|
||||
format!("{fun:?}({other:?})")
|
||||
)),
|
||||
},
|
||||
Mf::Normalize |
|
||||
@@ -769,7 +766,7 @@ impl<'a> ResolveContext<'a> {
|
||||
width,
|
||||
}),
|
||||
ref other => return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?})", fun, other)
|
||||
format!("{fun:?}({other:?})")
|
||||
)),
|
||||
},
|
||||
Mf::Inverse => match *res_arg.inner_with(types) {
|
||||
@@ -783,7 +780,7 @@ impl<'a> ResolveContext<'a> {
|
||||
width,
|
||||
}),
|
||||
ref other => return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?})", fun, other)
|
||||
format!("{fun:?}({other:?})")
|
||||
)),
|
||||
},
|
||||
Mf::Determinant => match *res_arg.inner_with(types) {
|
||||
@@ -792,7 +789,7 @@ impl<'a> ResolveContext<'a> {
|
||||
..
|
||||
} => TypeResolution::Value(Ti::Scalar { kind: crate::ScalarKind::Float, width }),
|
||||
ref other => return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?})", fun, other)
|
||||
format!("{fun:?}({other:?})")
|
||||
)),
|
||||
},
|
||||
// bits
|
||||
@@ -807,7 +804,7 @@ impl<'a> ResolveContext<'a> {
|
||||
Ti::Vector { size, kind: kind @ (crate::ScalarKind::Sint | crate::ScalarKind::Uint), width } =>
|
||||
TypeResolution::Value(Ti::Vector { size, kind, width }),
|
||||
ref other => return Err(ResolveError::IncompatibleOperands(
|
||||
format!("{:?}({:?})", fun, other)
|
||||
format!("{fun:?}({other:?})")
|
||||
)),
|
||||
},
|
||||
// data packing
|
||||
@@ -853,8 +850,7 @@ impl<'a> ResolveContext<'a> {
|
||||
}),
|
||||
ref other => {
|
||||
return Err(ResolveError::IncompatibleOperands(format!(
|
||||
"{:?} as {:?}",
|
||||
other, kind
|
||||
"{other:?} as {kind:?}"
|
||||
)))
|
||||
}
|
||||
},
|
||||
|
||||
@@ -90,7 +90,7 @@ struct Parameters {
|
||||
#[allow(unused_variables)]
|
||||
fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
let params = match fs::read_to_string(format!("{}/{}/{}.param.ron", root, BASE_DIR_IN, name)) {
|
||||
let params = match fs::read_to_string(format!("{root}/{BASE_DIR_IN}/{name}.param.ron")) {
|
||||
Ok(string) => ron::de::from_str(&string).expect("Couldn't parse param file"),
|
||||
Err(_) => Parameters::default(),
|
||||
};
|
||||
@@ -108,7 +108,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
|
||||
if targets.contains(Targets::IR) {
|
||||
let config = ron::ser::PrettyConfig::default().new_line("\n".to_string());
|
||||
let string = ron::ser::to_string_pretty(module, config).unwrap();
|
||||
fs::write(dest.join(format!("ir/{}.ron", name)), string).unwrap();
|
||||
fs::write(dest.join(format!("ir/{name}.ron")), string).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
|
||||
if targets.contains(Targets::ANALYSIS) {
|
||||
let config = ron::ser::PrettyConfig::default().new_line("\n".to_string());
|
||||
let string = ron::ser::to_string_pretty(&info, config).unwrap();
|
||||
fs::write(dest.join(format!("analysis/{}.info.ron", name)), string).unwrap();
|
||||
fs::write(dest.join(format!("analysis/{name}.info.ron")), string).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
|
||||
{
|
||||
if targets.contains(Targets::DOT) {
|
||||
let string = naga::back::dot::write(module, Some(&info), Default::default()).unwrap();
|
||||
fs::write(dest.join(format!("dot/{}.dot", name)), string).unwrap();
|
||||
fs::write(dest.join(format!("dot/{name}.dot")), string).unwrap();
|
||||
}
|
||||
}
|
||||
#[cfg(all(feature = "deserialize", feature = "hlsl-out"))]
|
||||
@@ -248,7 +248,7 @@ fn write_output_spv(
|
||||
let dis = rspirv::dr::load_words(spv)
|
||||
.expect("Produced invalid SPIR-V")
|
||||
.disassemble();
|
||||
fs::write(destination.join(format!("spv/{}.spvasm", file_name)), dis).unwrap();
|
||||
fs::write(destination.join(format!("spv/{file_name}.spvasm")), dis).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,7 +269,7 @@ fn write_output_msl(
|
||||
let mut options = options.clone();
|
||||
options.bounds_check_policies = bounds_check_policies;
|
||||
let (string, tr_info) = msl::write_string(module, info, &options, pipeline_options)
|
||||
.unwrap_or_else(|err| panic!("Metal write failed: {}", err));
|
||||
.unwrap_or_else(|err| panic!("Metal write failed: {err}"));
|
||||
|
||||
for (ep, result) in module.entry_points.iter().zip(tr_info.entry_point_names) {
|
||||
if let Err(error) = result {
|
||||
@@ -277,7 +277,7 @@ fn write_output_msl(
|
||||
}
|
||||
}
|
||||
|
||||
fs::write(destination.join(format!("msl/{}.msl", file_name)), string).unwrap();
|
||||
fs::write(destination.join(format!("msl/{file_name}.msl")), string).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "glsl-out")]
|
||||
@@ -316,7 +316,7 @@ fn write_output_glsl(
|
||||
writer.write().expect("GLSL write failed");
|
||||
|
||||
fs::write(
|
||||
destination.join(format!("glsl/{}.{}.{:?}.glsl", file_name, ep_name, stage)),
|
||||
destination.join(format!("glsl/{file_name}.{ep_name}.{stage:?}.glsl")),
|
||||
buffer,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -339,7 +339,7 @@ fn write_output_hlsl(
|
||||
let mut writer = hlsl::Writer::new(&mut buffer, options);
|
||||
let reflection_info = writer.write(module, info).expect("HLSL write failed");
|
||||
|
||||
fs::write(destination.join(format!("hlsl/{}.hlsl", file_name)), buffer).unwrap();
|
||||
fs::write(destination.join(format!("hlsl/{file_name}.hlsl")), buffer).unwrap();
|
||||
|
||||
// We need a config file for validation script
|
||||
// This file contains an info about profiles (shader stages) contains inside generated shader
|
||||
@@ -387,15 +387,10 @@ fn write_output_hlsl(
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(
|
||||
config_str,
|
||||
"{})\n{})\n{})",
|
||||
vertex_str, fragment_str, compute_str
|
||||
)
|
||||
.unwrap();
|
||||
writeln!(config_str, "{vertex_str})\n{fragment_str})\n{compute_str})").unwrap();
|
||||
|
||||
fs::write(
|
||||
destination.join(format!("hlsl/{}.hlsl.config", file_name)),
|
||||
destination.join(format!("hlsl/{file_name}.hlsl.config")),
|
||||
config_str,
|
||||
)
|
||||
.unwrap();
|
||||
@@ -418,7 +413,7 @@ fn write_output_wgsl(
|
||||
|
||||
let string = wgsl::write_string(module, info, flags).expect("WGSL write failed");
|
||||
|
||||
fs::write(destination.join(format!("wgsl/{}.wgsl", file_name)), string).unwrap();
|
||||
fs::write(destination.join(format!("wgsl/{file_name}.wgsl")), string).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
@@ -564,9 +559,9 @@ fn convert_wgsl() {
|
||||
];
|
||||
|
||||
for &(name, targets) in inputs.iter() {
|
||||
println!("Processing '{}'", name);
|
||||
println!("Processing '{name}'");
|
||||
// WGSL shaders lives in root dir as a privileged.
|
||||
let file = fs::read_to_string(format!("{}/{}/{}.wgsl", root, BASE_DIR_IN, name))
|
||||
let file = fs::read_to_string(format!("{root}/{BASE_DIR_IN}/{name}.wgsl"))
|
||||
.expect("Couldn't find wgsl file");
|
||||
match naga::front::wgsl::parse_str(&file) {
|
||||
Ok(module) => check_targets(&module, name, targets),
|
||||
@@ -581,8 +576,7 @@ fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) {
|
||||
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
let module = naga::front::spv::parse_u8_slice(
|
||||
&fs::read(format!("{}/{}/spv/{}.spv", root, BASE_DIR_IN, name))
|
||||
.expect("Couldn't find spv file"),
|
||||
&fs::read(format!("{root}/{BASE_DIR_IN}/spv/{name}.spv")).expect("Couldn't find spv file"),
|
||||
&naga::front::spv::Options {
|
||||
adjust_coordinate_space,
|
||||
strict_capabilities: false,
|
||||
@@ -627,7 +621,7 @@ fn convert_spv_all() {
|
||||
#[test]
|
||||
fn convert_glsl_variations_check() {
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
let file = fs::read_to_string(format!("{}/{}/variations.glsl", root, BASE_DIR_IN))
|
||||
let file = fs::read_to_string(format!("{root}/{BASE_DIR_IN}/variations.glsl"))
|
||||
.expect("Couldn't find glsl file");
|
||||
let mut parser = naga::front::glsl::Parser::default();
|
||||
let module = parser
|
||||
@@ -650,7 +644,7 @@ fn convert_glsl_folder() {
|
||||
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
|
||||
for entry in std::fs::read_dir(format!("{}/{}/glsl", root, BASE_DIR_IN)).unwrap() {
|
||||
for entry in std::fs::read_dir(format!("{root}/{BASE_DIR_IN}/glsl")).unwrap() {
|
||||
let entry = entry.unwrap();
|
||||
let file_name = entry.file_name().into_string().unwrap();
|
||||
|
||||
@@ -658,7 +652,7 @@ fn convert_glsl_folder() {
|
||||
// No needed to validate ron files
|
||||
continue;
|
||||
}
|
||||
println!("Processing {}", file_name);
|
||||
println!("Processing {file_name}");
|
||||
|
||||
let mut parser = naga::front::glsl::Parser::default();
|
||||
let module = parser
|
||||
@@ -668,7 +662,7 @@ fn convert_glsl_folder() {
|
||||
"vert" => naga::ShaderStage::Vertex,
|
||||
"frag" => naga::ShaderStage::Fragment,
|
||||
"comp" => naga::ShaderStage::Compute,
|
||||
ext => panic!("Unknown extension for glsl file {}", ext),
|
||||
ext => panic!("Unknown extension for glsl file {ext}"),
|
||||
},
|
||||
defines: Default::default(),
|
||||
},
|
||||
|
||||
@@ -40,10 +40,7 @@ fn require_and_forbid(required: &[Ca], forbidden: &[Ca], source: &str) {
|
||||
.cloned()
|
||||
.collect();
|
||||
if !missing_caps.is_empty() {
|
||||
panic!(
|
||||
"shader code should have requested these caps: {:?}\n\n{}",
|
||||
missing_caps, source
|
||||
);
|
||||
panic!("shader code should have requested these caps: {missing_caps:?}\n\n{source}");
|
||||
}
|
||||
|
||||
let forbidden_caps: Vec<_> = forbidden
|
||||
@@ -52,10 +49,7 @@ fn require_and_forbid(required: &[Ca], forbidden: &[Ca], source: &str) {
|
||||
.cloned()
|
||||
.collect();
|
||||
if !forbidden_caps.is_empty() {
|
||||
panic!(
|
||||
"shader code should not have requested these caps: {:?}\n\n{}",
|
||||
forbidden_caps, source
|
||||
);
|
||||
panic!("shader code should not have requested these caps: {forbidden_caps:?}\n\n{source}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ fn check(input: &str, snapshot: &str) {
|
||||
if output != snapshot {
|
||||
for diff in diff::lines(&output, snapshot) {
|
||||
match diff {
|
||||
diff::Result::Left(l) => println!("-{}", l),
|
||||
diff::Result::Both(l, _) => println!(" {}", l),
|
||||
diff::Result::Right(r) => println!("+{}", r),
|
||||
diff::Result::Left(l) => println!("-{l}"),
|
||||
diff::Result::Both(l, _) => println!(" {l}"),
|
||||
diff::Result::Right(r) => println!("+{r}"),
|
||||
}
|
||||
}
|
||||
panic!("Error snapshot failed");
|
||||
@@ -1419,16 +1419,12 @@ fn wrong_access_mode() {
|
||||
#[test]
|
||||
fn io_shareable_types() {
|
||||
for numeric in "i32 u32 f32".split_whitespace() {
|
||||
let types = format!(
|
||||
"{} vec2<{}> vec3<{}> vec4<{}>",
|
||||
numeric, numeric, numeric, numeric
|
||||
);
|
||||
let types = format!("{numeric} vec2<{numeric}> vec3<{numeric}> vec4<{numeric}>");
|
||||
for ty in types.split_whitespace() {
|
||||
check_one_validation! {
|
||||
&format!("@vertex
|
||||
fn f(@location(0) arg: {}) -> @builtin(position) vec4<f32>
|
||||
{{ return vec4<f32>(0.0); }}",
|
||||
ty),
|
||||
fn f(@location(0) arg: {ty}) -> @builtin(position) vec4<f32>
|
||||
{{ return vec4<f32>(0.0); }}"),
|
||||
Ok(_module)
|
||||
}
|
||||
}
|
||||
@@ -1443,9 +1439,8 @@ fn io_shareable_types() {
|
||||
{
|
||||
check_one_validation! {
|
||||
&format!("@vertex
|
||||
fn f(@location(0) arg: {}) -> @builtin(position) vec4<f32>
|
||||
{{ return vec4<f32>(0.0); }}",
|
||||
ty),
|
||||
fn f(@location(0) arg: {ty}) -> @builtin(position) vec4<f32>
|
||||
{{ return vec4<f32>(0.0); }}"),
|
||||
Err(
|
||||
naga::valid::ValidationError::EntryPoint {
|
||||
stage: naga::ShaderStage::Vertex,
|
||||
@@ -1474,9 +1469,8 @@ fn host_shareable_types() {
|
||||
for ty in types.split_whitespace() {
|
||||
check_one_validation! {
|
||||
&format!("struct AStruct {{ member: array<mat4x4<f32>, 8> }};
|
||||
@group(0) @binding(0) var<uniform> ubuf: {};
|
||||
@group(0) @binding(1) var<storage> sbuf: {};",
|
||||
ty, ty),
|
||||
@group(0) @binding(0) var<uniform> ubuf: {ty};
|
||||
@group(0) @binding(1) var<storage> sbuf: {ty};"),
|
||||
Ok(_module)
|
||||
}
|
||||
}
|
||||
@@ -1489,8 +1483,7 @@ fn host_shareable_types() {
|
||||
for ty in types.split_whitespace() {
|
||||
check_one_validation! {
|
||||
&format!("struct AStruct {{ member: array<atomic<u32>, 8> }};
|
||||
@group(0) @binding(1) var<storage> sbuf: {};",
|
||||
ty),
|
||||
@group(0) @binding(1) var<storage> sbuf: {ty};"),
|
||||
Ok(_module)
|
||||
}
|
||||
}
|
||||
@@ -1498,7 +1491,7 @@ fn host_shareable_types() {
|
||||
// Types that are neither host-shareable nor constructible.
|
||||
for ty in "bool ptr<storage,i32>".split_whitespace() {
|
||||
check_one_validation! {
|
||||
&format!("@group(0) @binding(0) var<storage> sbuf: {};", ty),
|
||||
&format!("@group(0) @binding(0) var<storage> sbuf: {ty};"),
|
||||
Err(
|
||||
naga::valid::ValidationError::GlobalVariable {
|
||||
name,
|
||||
@@ -1510,7 +1503,7 @@ fn host_shareable_types() {
|
||||
}
|
||||
|
||||
check_one_validation! {
|
||||
&format!("@group(0) @binding(0) var<uniform> ubuf: {};", ty),
|
||||
&format!("@group(0) @binding(0) var<uniform> ubuf: {ty};"),
|
||||
Err(naga::valid::ValidationError::GlobalVariable {
|
||||
name,
|
||||
handle: _,
|
||||
|
||||
Reference in New Issue
Block a user