Block NaN and Inf constants value as invalid
Bug: chromium:1362412
Change-Id: Ie3b8c447677ebb4bc12177a5dc4fd92d9033a359
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/102280
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Shrek Shao <shrekshao@google.com>
diff --git a/src/dawn/native/Pipeline.cpp b/src/dawn/native/Pipeline.cpp
index dc55f63..78604f3 100644
--- a/src/dawn/native/Pipeline.cpp
+++ b/src/dawn/native/Pipeline.cpp
@@ -67,6 +67,9 @@
DAWN_INVALID_IF(metadata.overrides.count(constants[i].key) == 0,
"Pipeline overridable constant \"%s\" not found in %s.", constants[i].key,
module);
+ DAWN_INVALID_IF(!std::isfinite(constants[i].value),
+ "Pipeline overridable constant \"%s\" with value (%f) is not finite",
+ constants[i].key, constants[i].value);
if (stageInitializedConstantIdentifiers.count(constants[i].key) == 0) {
if (metadata.uninitializedOverrides.count(constants[i].key) > 0) {
diff --git a/src/dawn/tests/unittests/validation/OverridableConstantsValidationTests.cpp b/src/dawn/tests/unittests/validation/OverridableConstantsValidationTests.cpp
index c0f9eec..4fd3150 100644
--- a/src/dawn/tests/unittests/validation/OverridableConstantsValidationTests.cpp
+++ b/src/dawn/tests/unittests/validation/OverridableConstantsValidationTests.cpp
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+#include <limits>
#include <vector>
#include "dawn/common/Constants.h"
@@ -217,3 +218,36 @@
ASSERT_DEVICE_ERROR(TestCreatePipeline(constants));
}
}
+
+// Test that values like NaN and Inf are treated as invalid.
+TEST_F(ComputePipelineOverridableConstantsValidationTest, InvalidValue) {
+ SetUpShadersWithDefaultValueConstants();
+ {
+ // Error:: NaN
+ std::vector<wgpu::ConstantEntry> constants{{nullptr, "c3", std::nan("")}};
+ ASSERT_DEVICE_ERROR(TestCreatePipeline(constants));
+ }
+ {
+ // Error:: -NaN
+ std::vector<wgpu::ConstantEntry> constants{{nullptr, "c3", -std::nan("")}};
+ ASSERT_DEVICE_ERROR(TestCreatePipeline(constants));
+ }
+ {
+ // Error:: Inf
+ std::vector<wgpu::ConstantEntry> constants{
+ {nullptr, "c3", std::numeric_limits<double>::infinity()}};
+ ASSERT_DEVICE_ERROR(TestCreatePipeline(constants));
+ }
+ {
+ // Error:: -Inf
+ std::vector<wgpu::ConstantEntry> constants{
+ {nullptr, "c3", -std::numeric_limits<double>::infinity()}};
+ ASSERT_DEVICE_ERROR(TestCreatePipeline(constants));
+ }
+ {
+ // Valid:: Max
+ std::vector<wgpu::ConstantEntry> constants{
+ {nullptr, "c3", std::numeric_limits<double>::max()}};
+ TestCreatePipeline(constants);
+ }
+}