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>
This commit is contained in:
Shrek Shao 2022-09-14 13:13:07 +00:00 committed by Dawn LUCI CQ
parent a0b64c7e64
commit b74ca3f8e0
2 changed files with 37 additions and 0 deletions

View File

@ -67,6 +67,9 @@ MaybeError ValidateProgrammableStage(DeviceBase* device,
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) {

View File

@ -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 @@ TEST_F(ComputePipelineOverridableConstantsValidationTest, ConstantsIdentifierUni
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);
}
}