From 86980018b3f2786aeb5ded1220ec94bc927fa6b2 Mon Sep 17 00:00:00 2001 From: shrekshao Date: Wed, 30 Dec 2020 19:47:33 +0000 Subject: [PATCH] Invalidate sampler with maxAnisotropy = 0 Bug: dawn:568 Change-Id: Ic0eee693a91153e2447c8f9830919f74c08fde48 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/36320 Reviewed-by: Austin Eng Commit-Queue: Shrek Shao --- src/dawn_native/Sampler.cpp | 10 +++------- .../unittests/validation/SamplerValidationTests.cpp | 5 +++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/dawn_native/Sampler.cpp b/src/dawn_native/Sampler.cpp index 3a75cb1301..a2dcaabd3b 100644 --- a/src/dawn_native/Sampler.cpp +++ b/src/dawn_native/Sampler.cpp @@ -20,12 +20,6 @@ #include -namespace { - uint16_t GetClampedMaxAnisotropy(uint16_t value) { - return value >= 1u ? value : 1u; - } -} // anonymous namespace - namespace dawn_native { MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) { @@ -54,6 +48,8 @@ namespace dawn_native { "min, mag, and mipmap filter should be linear when using anisotropic " "filtering"); } + } else if (descriptor->maxAnisotropy == 0u) { + return DAWN_VALIDATION_ERROR("max anisotropy cannot be set to 0"); } DAWN_TRY(ValidateFilterMode(descriptor->minFilter)); @@ -79,7 +75,7 @@ namespace dawn_native { mLodMinClamp(descriptor->lodMinClamp), mLodMaxClamp(descriptor->lodMaxClamp), mCompareFunction(descriptor->compare), - mMaxAnisotropy(GetClampedMaxAnisotropy(descriptor->maxAnisotropy)) { + mMaxAnisotropy(descriptor->maxAnisotropy) { } SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag) diff --git a/src/tests/unittests/validation/SamplerValidationTests.cpp b/src/tests/unittests/validation/SamplerValidationTests.cpp index 60e2564042..9a8c0be6fd 100644 --- a/src/tests/unittests/validation/SamplerValidationTests.cpp +++ b/src/tests/unittests/validation/SamplerValidationTests.cpp @@ -61,6 +61,11 @@ namespace { // when maxAnisotropy > 1, min, mag, mipmap filter should be linear device.CreateSampler(&kValidAnisoSamplerDesc); } + { + wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; + samplerDesc.maxAnisotropy = 0; + ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc)); + } { wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; samplerDesc.minFilter = wgpu::FilterMode::Nearest;