Given the following block of code, I get an optimization warning in the Burst inspector about a switch statement: “Remark: :0:0: loop not vectorized: loop contains a switch statement”. If I remove this chunk (or simplify it to have no branching) the warning vanishes. I’m guessing this is being optimized into a switch statement, which is then blocking vectorization? Any way I can deal with this on my end?
public static float GetTargetDensity(Vector3 point, Vector3 center, Vector3 normal, DensityShape shape, VoxelEditType editType, float radius, float stretchScale = 0.0f)
{
var density = 0f;
if (shape == DensityShape.Sphere)
{
return SDFHelper.sphere(point - center, radius);
}
if (shape == DensityShape.Ellipsoid)
{
return SDFHelper.ellipsoid(point - center, normal);
}
if (shape == DensityShape.Cube)
{
return SDFHelper.box(point - center, radius);
}
if (shape == DensityShape.Plane)
{
float3 p = (point - center);
float4 n = math.normalize(new float4(normal, 1));
return SDFHelper.plane(p, n);
}
density = 0f;
return density;
}