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 <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
This commit is contained in:
shrekshao 2020-12-30 19:47:33 +00:00 committed by Commit Bot service account
parent 9a38e5b60d
commit 86980018b3
2 changed files with 8 additions and 7 deletions

View File

@ -20,12 +20,6 @@
#include <cmath> #include <cmath>
namespace {
uint16_t GetClampedMaxAnisotropy(uint16_t value) {
return value >= 1u ? value : 1u;
}
} // anonymous namespace
namespace dawn_native { namespace dawn_native {
MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) { MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) {
@ -54,6 +48,8 @@ namespace dawn_native {
"min, mag, and mipmap filter should be linear when using anisotropic " "min, mag, and mipmap filter should be linear when using anisotropic "
"filtering"); "filtering");
} }
} else if (descriptor->maxAnisotropy == 0u) {
return DAWN_VALIDATION_ERROR("max anisotropy cannot be set to 0");
} }
DAWN_TRY(ValidateFilterMode(descriptor->minFilter)); DAWN_TRY(ValidateFilterMode(descriptor->minFilter));
@ -79,7 +75,7 @@ namespace dawn_native {
mLodMinClamp(descriptor->lodMinClamp), mLodMinClamp(descriptor->lodMinClamp),
mLodMaxClamp(descriptor->lodMaxClamp), mLodMaxClamp(descriptor->lodMaxClamp),
mCompareFunction(descriptor->compare), mCompareFunction(descriptor->compare),
mMaxAnisotropy(GetClampedMaxAnisotropy(descriptor->maxAnisotropy)) { mMaxAnisotropy(descriptor->maxAnisotropy) {
} }
SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag) SamplerBase::SamplerBase(DeviceBase* device, ObjectBase::ErrorTag tag)

View File

@ -61,6 +61,11 @@ namespace {
// when maxAnisotropy > 1, min, mag, mipmap filter should be linear // when maxAnisotropy > 1, min, mag, mipmap filter should be linear
device.CreateSampler(&kValidAnisoSamplerDesc); device.CreateSampler(&kValidAnisoSamplerDesc);
} }
{
wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc;
samplerDesc.maxAnisotropy = 0;
ASSERT_DEVICE_ERROR(device.CreateSampler(&samplerDesc));
}
{ {
wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc; wgpu::SamplerDescriptor samplerDesc = kValidAnisoSamplerDesc;
samplerDesc.minFilter = wgpu::FilterMode::Nearest; samplerDesc.minFilter = wgpu::FilterMode::Nearest;