Improve validation errors for CreateQuerySet

Bug: dawn:563
Change-Id: I7ed446f9fed3e8e9c2fdf367ea8cedcbbff334b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/65561
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2021-09-30 17:55:50 +00:00 committed by Dawn LUCI CQ
parent 200ed613ba
commit 547c4ed0ca
2 changed files with 29 additions and 44 deletions

View File

@ -1297,7 +1297,8 @@ namespace dawn_native {
const QuerySetDescriptor* descriptor) {
DAWN_TRY(ValidateIsAlive());
if (IsValidationEnabled()) {
DAWN_TRY(ValidateQuerySetDescriptor(this, descriptor));
DAWN_TRY_CONTEXT(ValidateQuerySetDescriptor(this, descriptor), "validating %s",
descriptor);
}
return CreateQuerySetImpl(descriptor);
}

View File

@ -40,43 +40,34 @@ namespace dawn_native {
MaybeError ValidateQuerySetDescriptor(DeviceBase* device,
const QuerySetDescriptor* descriptor) {
if (descriptor->nextInChain != nullptr) {
return DAWN_VALIDATION_ERROR("nextInChain must be nullptr");
}
if (descriptor->count > kMaxQueryCount) {
return DAWN_VALIDATION_ERROR("Max query count exceeded");
}
DAWN_INVALID_IF(descriptor->nextInChain != nullptr, "nextInChain must be nullptr");
DAWN_TRY(ValidateQueryType(descriptor->type));
DAWN_INVALID_IF(descriptor->count > kMaxQueryCount,
"Query count (%u) exceeds the maximum query count (%u).", descriptor->count,
kMaxQueryCount);
switch (descriptor->type) {
case wgpu::QueryType::Occlusion:
if (descriptor->pipelineStatisticsCount != 0) {
return DAWN_VALIDATION_ERROR(
"The pipeline statistics should not be set if query type is Occlusion");
}
DAWN_INVALID_IF(descriptor->pipelineStatisticsCount != 0,
"Pipeline statistics specified for a query of type %s.",
descriptor->type);
break;
case wgpu::QueryType::PipelineStatistics: {
// TODO(crbug.com/1177506): Pipeline statistics query is not fully implemented.
// Disallow it as unsafe until the implementaion is completed.
if (device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR(
"Pipeline statistics query is disallowed because it's not fully "
"implemented");
}
DAWN_INVALID_IF(device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs),
"Pipeline statistics queries are disallowed because they are not "
"fully implemented");
if (!device->IsExtensionEnabled(Extension::PipelineStatisticsQuery)) {
return DAWN_VALIDATION_ERROR(
"The pipeline statistics query feature is not supported");
}
DAWN_INVALID_IF(
!device->IsExtensionEnabled(Extension::PipelineStatisticsQuery),
"Pipeline statistics query set created without the extension being enabled.");
if (descriptor->pipelineStatisticsCount == 0) {
return DAWN_VALIDATION_ERROR(
"At least one pipeline statistics is set if query type is "
"PipelineStatistics");
}
DAWN_INVALID_IF(descriptor->pipelineStatisticsCount == 0,
"Pipeline statistics query set created with 0 statistics.");
std::set<wgpu::PipelineStatisticName> pipelineStatisticsSet;
for (uint32_t i = 0; i < descriptor->pipelineStatisticsCount; i++) {
@ -84,27 +75,22 @@ namespace dawn_native {
std::pair<std::set<wgpu::PipelineStatisticName>::iterator, bool> res =
pipelineStatisticsSet.insert((descriptor->pipelineStatistics[i]));
if (!res.second) {
return DAWN_VALIDATION_ERROR("Duplicate pipeline statistics found");
}
DAWN_INVALID_IF(!res.second, "Statistic %s is specified more than once.",
descriptor->pipelineStatistics[i]);
}
} break;
case wgpu::QueryType::Timestamp:
if (!device->IsExtensionEnabled(Extension::TimestampQuery)) {
return DAWN_VALIDATION_ERROR("The timestamp query feature is not supported");
}
DAWN_INVALID_IF(device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs),
"Timestamp queries are disallowed because they may expose precise "
"timing information.");
if (device->IsToggleEnabled(Toggle::DisallowUnsafeAPIs)) {
return DAWN_VALIDATION_ERROR(
"The timestamp query is disallowed because it may expose precise timing "
"information");
}
DAWN_INVALID_IF(!device->IsExtensionEnabled(Extension::TimestampQuery),
"Timestamp query set created without the extension being enabled.");
if (descriptor->pipelineStatisticsCount != 0) {
return DAWN_VALIDATION_ERROR(
"The pipeline statistics should not be set if query type is Timestamp");
}
DAWN_INVALID_IF(descriptor->pipelineStatisticsCount != 0,
"Pipeline statistics specified for a query of type %s.",
descriptor->type);
break;
default:
@ -166,9 +152,7 @@ namespace dawn_native {
MaybeError QuerySetBase::ValidateCanUseInSubmitNow() const {
ASSERT(!IsError());
if (mState == QuerySetState::Destroyed) {
return DAWN_VALIDATION_ERROR("Destroyed query set used in a submit");
}
DAWN_INVALID_IF(mState == QuerySetState::Destroyed, "%s used while destroyed.", this);
return {};
}