Update the rounding modes to match the spec.
The spec was clarified that a value of .5 rounds towards the even value.
This matches the HLSL `round` method. This CL updates SPIR-V to use the
`RoundEven` GLSL450 call and the `rint` MSL call so they match the spec
requirements.
Change-Id: I97ce2e29b9639ad72b6846b32dbe3abb8d9f6cff
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/42421
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
diff --git a/src/writer/msl/generator_impl.cc b/src/writer/msl/generator_impl.cc
index 1d2c024..a603d07 100644
--- a/src/writer/msl/generator_impl.cc
+++ b/src/writer/msl/generator_impl.cc
@@ -817,7 +817,6 @@
case semantic::IntrinsicType::kNormalize:
case semantic::IntrinsicType::kPow:
case semantic::IntrinsicType::kReflect:
- case semantic::IntrinsicType::kRound:
case semantic::IntrinsicType::kSelect:
case semantic::IntrinsicType::kSin:
case semantic::IntrinsicType::kSinh:
@@ -899,6 +898,9 @@
case semantic::IntrinsicType::kReverseBits:
out += "reverse_bits";
break;
+ case semantic::IntrinsicType::kRound:
+ out += "rint";
+ break;
case semantic::IntrinsicType::kSmoothStep:
out += "smoothstep";
break;
diff --git a/src/writer/msl/generator_impl_import_test.cc b/src/writer/msl/generator_impl_import_test.cc
index 94530aa..4894db3 100644
--- a/src/writer/msl/generator_impl_import_test.cc
+++ b/src/writer/msl/generator_impl_import_test.cc
@@ -85,7 +85,7 @@
MslImportData{"length", "length"},
MslImportData{"log", "log"},
MslImportData{"log2", "log2"},
- MslImportData{"round", "round"},
+ MslImportData{"round", "rint"},
MslImportData{"sign", "sign"},
MslImportData{"sin", "sin"},
MslImportData{"sinh", "sinh"},
diff --git a/src/writer/msl/generator_impl_intrinsic_test.cc b/src/writer/msl/generator_impl_intrinsic_test.cc
index 059c9b5..cd28dce 100644
--- a/src/writer/msl/generator_impl_intrinsic_test.cc
+++ b/src/writer/msl/generator_impl_intrinsic_test.cc
@@ -271,7 +271,7 @@
"metal::reflect"},
IntrinsicData{IntrinsicType::kReverseBits, ParamType::kU32,
"metal::reverse_bits"},
- IntrinsicData{IntrinsicType::kRound, ParamType::kU32, "metal::round"},
+ IntrinsicData{IntrinsicType::kRound, ParamType::kU32, "metal::rint"},
IntrinsicData{IntrinsicType::kSelect, ParamType::kF32, "metal::select"},
IntrinsicData{IntrinsicType::kSign, ParamType::kF32, "metal::sign"},
IntrinsicData{IntrinsicType::kSin, ParamType::kF32, "metal::sin"},
diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc
index d0401da..26b2c8e 100644
--- a/src/writer/spirv/builder.cc
+++ b/src/writer/spirv/builder.cc
@@ -266,7 +266,7 @@
case IntrinsicType::kReflect:
return GLSLstd450Reflect;
case IntrinsicType::kRound:
- return GLSLstd450Round;
+ return GLSLstd450RoundEven;
case IntrinsicType::kSign:
return GLSLstd450FSign;
case IntrinsicType::kSin:
diff --git a/src/writer/spirv/builder_intrinsic_test.cc b/src/writer/spirv/builder_intrinsic_test.cc
index 3f5e17c..613a5a0 100644
--- a/src/writer/spirv/builder_intrinsic_test.cc
+++ b/src/writer/spirv/builder_intrinsic_test.cc
@@ -479,7 +479,7 @@
%7 = OpFunction %6 None %5
%8 = OpLabel
%11 = OpLoad %3 %1
-%9 = OpExtInst %3 %10 Round %11
+%9 = OpExtInst %3 %10 RoundEven %11
OpReturn
OpFunctionEnd
)");
@@ -563,7 +563,7 @@
"InverseSqrt"},
IntrinsicData{"log", "Log"},
IntrinsicData{"log2", "Log2"},
- IntrinsicData{"round", "Round"},
+ IntrinsicData{"round", "RoundEven"},
IntrinsicData{"sign", "FSign"},
IntrinsicData{"sin", "Sin"},
IntrinsicData{"sinh", "Sinh"},