validation: simplify validating function parameters
Bug: tint:931 tint:930 Change-Id: I04789218a33d1cf53862d42b83c39fc09e7ad4e4 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/56620 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com> Commit-Queue: Sarah Mashayekhi <sarahmashay@google.com>
This commit is contained in:
parent
885488da41
commit
a8f58efc67
|
@ -122,6 +122,14 @@ bool IsValidationDisabled(const ast::DecorationList& decorations,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @returns true if the decoration list does not contains a
|
||||||
|
/// ast::DisableValidationDecoration with the validation mode equal to
|
||||||
|
/// `validation`
|
||||||
|
bool IsValidationEnabled(const ast::DecorationList& decorations,
|
||||||
|
ast::DisabledValidation validation) {
|
||||||
|
return !IsValidationDisabled(decorations, validation);
|
||||||
|
}
|
||||||
|
|
||||||
// Helper to stringify a pipeline IO decoration.
|
// Helper to stringify a pipeline IO decoration.
|
||||||
std::string deco_to_str(const ast::Decoration* deco) {
|
std::string deco_to_str(const ast::Decoration* deco) {
|
||||||
std::stringstream str;
|
std::stringstream str;
|
||||||
|
@ -880,8 +888,8 @@ bool Resolver::ValidateVariable(const VariableInfo* info) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsValidationDisabled(var->decorations(),
|
if (IsValidationEnabled(var->decorations(),
|
||||||
ast::DisabledValidation::kIgnoreStorageClass) &&
|
ast::DisabledValidation::kIgnoreStorageClass) &&
|
||||||
(var->declared_storage_class() == ast::StorageClass::kInput ||
|
(var->declared_storage_class() == ast::StorageClass::kInput ||
|
||||||
var->declared_storage_class() == ast::StorageClass::kOutput)) {
|
var->declared_storage_class() == ast::StorageClass::kOutput)) {
|
||||||
AddError("invalid use of input/output storage class", var->source());
|
AddError("invalid use of input/output storage class", var->source());
|
||||||
|
@ -910,10 +918,7 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto* deco : info->declaration->decorations()) {
|
for (auto* deco : info->declaration->decorations()) {
|
||||||
if (!func->IsEntryPoint() &&
|
if (!func->IsEntryPoint() && !deco->Is<ast::InternalDecoration>()) {
|
||||||
!IsValidationDisabled(
|
|
||||||
info->declaration->decorations(),
|
|
||||||
ast::DisabledValidation::kIgnoreAtomicFunctionParameter)) {
|
|
||||||
AddError("decoration is not valid for function parameters",
|
AddError("decoration is not valid for function parameters",
|
||||||
deco->source());
|
deco->source());
|
||||||
return false;
|
return false;
|
||||||
|
@ -929,12 +934,12 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func,
|
||||||
}
|
}
|
||||||
} else if (!deco->IsAnyOf<ast::LocationDecoration,
|
} else if (!deco->IsAnyOf<ast::LocationDecoration,
|
||||||
ast::InternalDecoration>() &&
|
ast::InternalDecoration>() &&
|
||||||
!(IsValidationDisabled(
|
(IsValidationEnabled(
|
||||||
info->declaration->decorations(),
|
info->declaration->decorations(),
|
||||||
ast::DisabledValidation::kEntryPointParameter) ||
|
ast::DisabledValidation::kEntryPointParameter) &&
|
||||||
IsValidationDisabled(info->declaration->decorations(),
|
IsValidationEnabled(
|
||||||
ast::DisabledValidation::
|
info->declaration->decorations(),
|
||||||
kIgnoreAtomicFunctionParameter))) {
|
ast::DisabledValidation::kIgnoreAtomicFunctionParameter))) {
|
||||||
AddError("decoration is not valid for function parameters",
|
AddError("decoration is not valid for function parameters",
|
||||||
deco->source());
|
deco->source());
|
||||||
return false;
|
return false;
|
||||||
|
@ -956,7 +961,7 @@ bool Resolver::ValidateFunctionParameter(const ast::Function* func,
|
||||||
|
|
||||||
if (IsPlain(info->type)) {
|
if (IsPlain(info->type)) {
|
||||||
if (!IsAtomicFreePlain(info->type) &&
|
if (!IsAtomicFreePlain(info->type) &&
|
||||||
!IsValidationDisabled(
|
IsValidationEnabled(
|
||||||
info->declaration->decorations(),
|
info->declaration->decorations(),
|
||||||
ast::DisabledValidation::kIgnoreAtomicFunctionParameter)) {
|
ast::DisabledValidation::kIgnoreAtomicFunctionParameter)) {
|
||||||
AddError("store type of function parameter must be an atomic-free type",
|
AddError("store type of function parameter must be an atomic-free type",
|
||||||
|
@ -1094,7 +1099,7 @@ bool Resolver::ValidateFunction(const ast::Function* func,
|
||||||
func->source());
|
func->source());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!IsValidationDisabled(
|
} else if (IsValidationEnabled(
|
||||||
func->decorations(),
|
func->decorations(),
|
||||||
ast::DisabledValidation::kFunctionHasNoBody)) {
|
ast::DisabledValidation::kFunctionHasNoBody)) {
|
||||||
TINT_ICE(Resolver, diagnostics_)
|
TINT_ICE(Resolver, diagnostics_)
|
||||||
|
@ -1211,7 +1216,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func,
|
||||||
pipeline_io_attribute->source());
|
pipeline_io_attribute->source());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (!IsValidationDisabled(
|
} else if (IsValidationEnabled(
|
||||||
decos, ast::DisabledValidation::kEntryPointParameter)) {
|
decos, ast::DisabledValidation::kEntryPointParameter)) {
|
||||||
if (!pipeline_io_attribute) {
|
if (!pipeline_io_attribute) {
|
||||||
std::string err = "missing entry point IO attribute";
|
std::string err = "missing entry point IO attribute";
|
||||||
|
@ -1352,12 +1357,10 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func,
|
||||||
auto bp = var_info->binding_point;
|
auto bp = var_info->binding_point;
|
||||||
auto res = binding_points.emplace(bp, var_info->declaration);
|
auto res = binding_points.emplace(bp, var_info->declaration);
|
||||||
if (!res.second &&
|
if (!res.second &&
|
||||||
!IsValidationDisabled(
|
IsValidationEnabled(var_info->declaration->decorations(),
|
||||||
var_info->declaration->decorations(),
|
ast::DisabledValidation::kBindingPointCollision) &&
|
||||||
ast::DisabledValidation::kBindingPointCollision) &&
|
IsValidationEnabled(res.first->second->decorations(),
|
||||||
!IsValidationDisabled(
|
ast::DisabledValidation::kBindingPointCollision)) {
|
||||||
res.first->second->decorations(),
|
|
||||||
ast::DisabledValidation::kBindingPointCollision)) {
|
|
||||||
// https://gpuweb.github.io/gpuweb/wgsl/#resource-interface
|
// https://gpuweb.github.io/gpuweb/wgsl/#resource-interface
|
||||||
// Bindings must not alias within a shader stage: two different
|
// Bindings must not alias within a shader stage: two different
|
||||||
// variables in the resource interface of a given shader must not have
|
// variables in the resource interface of a given shader must not have
|
||||||
|
@ -2848,8 +2851,8 @@ bool Resolver::VariableDeclStatement(const ast::VariableDeclStatement* stmt) {
|
||||||
|
|
||||||
if (!var->is_const()) {
|
if (!var->is_const()) {
|
||||||
if (info->storage_class != ast::StorageClass::kFunction &&
|
if (info->storage_class != ast::StorageClass::kFunction &&
|
||||||
!IsValidationDisabled(var->decorations(),
|
IsValidationEnabled(var->decorations(),
|
||||||
ast::DisabledValidation::kIgnoreStorageClass)) {
|
ast::DisabledValidation::kIgnoreStorageClass)) {
|
||||||
if (info->storage_class != ast::StorageClass::kNone) {
|
if (info->storage_class != ast::StorageClass::kNone) {
|
||||||
AddError("function variable has a non-function storage class",
|
AddError("function variable has a non-function storage class",
|
||||||
stmt->source());
|
stmt->source());
|
||||||
|
|
Loading…
Reference in New Issue