[Metal] Impl Expression::Splat (#738)

* [Metal] Impl `Expression::Splat`

* Add changes to the snapshots

* Apply suggestions
This commit is contained in:
Ashley
2021-04-20 17:41:13 +02:00
committed by GitHub
parent a4ac7b38b2
commit b08dfe5146
5 changed files with 17 additions and 8 deletions

View File

@@ -608,8 +608,17 @@ impl<W: Write> Writer<W> {
};
write!(self.out, "{}", coco)?;
}
crate::Expression::Splat { size: _, value } => {
self.put_expression(value, context, is_scoped)?;
crate::Expression::Splat { size, value } => {
let scalar_kind = match *context.resolve_type(value) {
crate::TypeInner::Scalar { kind, .. } => kind,
_ => return Err(Error::Validation)
};
let scalar = scalar_kind_string(scalar_kind);
let size = vector_size_string(size);
write!(self.out, "{}{}(", scalar, size)?;
self.put_expression(value, context, true)?;
write!(self.out, ")")?;
}
crate::Expression::Compose { ty, ref components } => {
let inner = &context.module.types[ty].inner;

View File

@@ -11,5 +11,5 @@ struct fooOutput {
vertex fooOutput foo(
metal::uint vi [[vertex_id]]
) {
return fooOutput { static_cast<float4>(type3 {1, 2, 3, 4, 5}[vi]) };
return fooOutput { static_cast<float4>(int4(type3 {1, 2, 3, 4, 5}[vi])) };
}

View File

@@ -73,10 +73,10 @@ kernel void main1(
}
}
if (cMassCount > 0) {
cMass = (cMass / static_cast<float>(cMassCount)) - vPos;
cMass = (cMass / float2(static_cast<float>(cMassCount))) - vPos;
}
if (cVelCount > 0) {
cVel = cVel / static_cast<float>(cVelCount);
cVel = cVel / float2(static_cast<float>(cVelCount));
}
vVel = ((vVel + (cMass * params.rule1Scale)) + (colVel * params.rule2Scale)) + (cVel * params.rule3Scale);
vVel = metal::normalize(vVel) * metal::clamp(metal::length(vVel), 0.0, 0.1);

View File

@@ -7,6 +7,6 @@ struct splatOutput {
};
vertex splatOutput splat(
) {
metal::float2 _e10 = ((1.0 + 2.0) - 3.0) / 4.0;
return splatOutput { metal::float4(_e10.x, _e10.y, _e10.x, _e10.y) + static_cast<float4>(5 % 2) };
metal::float2 _e10 = ((float2(1.0) + float2(2.0)) - float2(3.0)) / float2(4.0);
return splatOutput { metal::float4(_e10.x, _e10.y, _e10.x, _e10.y) + static_cast<float4>(int4(5) % int4(2)) };
}

View File

@@ -25,7 +25,7 @@ float fetch_shadow(
if (homogeneous_coords.w <= 0.0) {
return 1.0;
}
float _e28 = t_shadow.sample_compare(sampler_shadow, ((metal::float2(homogeneous_coords.x, homogeneous_coords.y) * metal::float2(0.5, -0.5)) / homogeneous_coords.w) + metal::float2(0.5, 0.5), static_cast<int>(light_id), homogeneous_coords.z / homogeneous_coords.w);
float _e28 = t_shadow.sample_compare(sampler_shadow, ((metal::float2(homogeneous_coords.x, homogeneous_coords.y) * metal::float2(0.5, -0.5)) / float2(homogeneous_coords.w)) + metal::float2(0.5, 0.5), static_cast<int>(light_id), homogeneous_coords.z / homogeneous_coords.w);
return _e28;
}