Improve validation errors for Sampler

Bug: dawn:563
Change-Id: I4bc774fd89c1a0b7adfca2b5bd7734751257b18b
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65800
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2021-10-05 01:09:00 +00:00 committed by Dawn LUCI CQ
parent a089e8c4f2
commit 575a198764
2 changed files with 21 additions and 22 deletions

View File

@ -1388,7 +1388,8 @@ namespace dawn_native {
DAWN_TRY(ValidateIsAlive()); DAWN_TRY(ValidateIsAlive());
descriptor = descriptor != nullptr ? descriptor : &defaultDescriptor; descriptor = descriptor != nullptr ? descriptor : &defaultDescriptor;
if (IsValidationEnabled()) { if (IsValidationEnabled()) {
DAWN_TRY(ValidateSamplerDescriptor(this, descriptor)); DAWN_TRY_CONTEXT(ValidateSamplerDescriptor(this, descriptor), "validating %s",
descriptor);
} }
return GetOrCreateSampler(descriptor); return GetOrCreateSampler(descriptor);
} }

View File

@ -23,33 +23,31 @@
namespace dawn_native { namespace dawn_native {
MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) { MaybeError ValidateSamplerDescriptor(DeviceBase*, const SamplerDescriptor* descriptor) {
if (descriptor->nextInChain != nullptr) { DAWN_INVALID_IF(descriptor->nextInChain != nullptr, "nextInChain must be nullptr");
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
}
if (std::isnan(descriptor->lodMinClamp) || std::isnan(descriptor->lodMaxClamp)) { DAWN_INVALID_IF(std::isnan(descriptor->lodMinClamp) || std::isnan(descriptor->lodMaxClamp),
return DAWN_VALIDATION_ERROR("LOD clamp bounds must not be NaN"); "LOD clamp bounds [%f, %f] contain a NaN.", descriptor->lodMinClamp,
} descriptor->lodMaxClamp);
if (descriptor->lodMinClamp < 0 || descriptor->lodMaxClamp < 0) { DAWN_INVALID_IF(descriptor->lodMinClamp < 0 || descriptor->lodMaxClamp < 0,
return DAWN_VALIDATION_ERROR("LOD clamp bounds must be positive"); "LOD clamp bounds [%f, %f] contain contain a negative number.",
} descriptor->lodMinClamp, descriptor->lodMaxClamp);
if (descriptor->lodMinClamp > descriptor->lodMaxClamp) { DAWN_INVALID_IF(descriptor->lodMinClamp > descriptor->lodMaxClamp,
return DAWN_VALIDATION_ERROR( "LOD min clamp (%f) is larger than the max clamp (%f).",
"Min lod clamp value cannot greater than max lod clamp value"); descriptor->lodMinClamp, descriptor->lodMaxClamp);
}
if (descriptor->maxAnisotropy > 1) { if (descriptor->maxAnisotropy > 1) {
if (descriptor->minFilter != wgpu::FilterMode::Linear || DAWN_INVALID_IF(descriptor->minFilter != wgpu::FilterMode::Linear ||
descriptor->magFilter != wgpu::FilterMode::Linear || descriptor->magFilter != wgpu::FilterMode::Linear ||
descriptor->mipmapFilter != wgpu::FilterMode::Linear) { descriptor->mipmapFilter != wgpu::FilterMode::Linear,
return DAWN_VALIDATION_ERROR( "One of minFilter (%s), magFilter (%s) or mipmapFilter (%s) is not %s "
"min, mag, and mipmap filter should be linear when using anisotropic " "while using anisotropic filter (maxAnisotropy is %f)",
"filtering"); descriptor->magFilter, descriptor->minFilter, descriptor->mipmapFilter,
} wgpu::FilterMode::Linear, descriptor->maxAnisotropy);
} else if (descriptor->maxAnisotropy == 0u) { } else if (descriptor->maxAnisotropy == 0u) {
return DAWN_VALIDATION_ERROR("max anisotropy cannot be set to 0"); return DAWN_FORMAT_VALIDATION_ERROR("Max anisotropy (%f) is less than 1.",
descriptor->maxAnisotropy);
} }
DAWN_TRY(ValidateFilterMode(descriptor->minFilter)); DAWN_TRY(ValidateFilterMode(descriptor->minFilter));