[hlsl-out] simplify write_default_init

This commit is contained in:
teoxoy
2023-01-05 12:28:57 +01:00
committed by Teodor Tanasoaia
parent e5121ca012
commit a42857d291
2 changed files with 6 additions and 22 deletions

View File

@@ -2842,28 +2842,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
/// Helper function that write default zero initialization
fn write_default_init(&mut self, module: &Module, ty: Handle<crate::Type>) -> BackendResult {
match module.types[ty].inner {
TypeInner::Array {
size: crate::ArraySize::Constant(const_handle),
base,
..
} => {
write!(self.out, "{{")?;
let count = module.constants[const_handle].to_array_length().unwrap();
for i in 0..count {
if i != 0 {
write!(self.out, ",")?;
}
self.write_default_init(module, base)?;
}
write!(self.out, "}}")?;
}
_ => {
write!(self.out, "(")?;
self.write_type(module, ty)?;
write!(self.out, ")0")?;
}
write!(self.out, "(")?;
self.write_type(module, ty)?;
if let TypeInner::Array { base, size, .. } = module.types[ty].inner {
self.write_array_size(module, base, size)?;
}
write!(self.out, ")0")?;
Ok(())
}

View File

@@ -253,7 +253,7 @@ ret_Constructarray5_int_ Constructarray5_int_(int arg0, int arg1, int arg2, int
float4 foo_vert(uint vi : SV_VertexID) : SV_Position
{
float foo = (float)0;
int c2_[5] = {(int)0,(int)0,(int)0,(int)0,(int)0};
int c2_[5] = (int[5])0;
foo = 0.0;
float baz_1 = foo;