Add a helper for DisableValidationDecoration

This is slightly different from the other helpers, since this AST node
does not have a source.

Change-Id: I56e72eb0f26f80d52be9e4f51dd42c3d5149cb00
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67644
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price 2021-10-28 15:00:39 +00:00
parent e548db90f6
commit 8d7551cc27
8 changed files with 52 additions and 85 deletions

View File

@ -35,6 +35,7 @@
#include "src/ast/case_statement.h" #include "src/ast/case_statement.h"
#include "src/ast/depth_multisampled_texture.h" #include "src/ast/depth_multisampled_texture.h"
#include "src/ast/depth_texture.h" #include "src/ast/depth_texture.h"
#include "src/ast/disable_validation_decoration.h"
#include "src/ast/external_texture.h" #include "src/ast/external_texture.h"
#include "src/ast/f32.h" #include "src/ast/f32.h"
#include "src/ast/float_literal.h" #include "src/ast/float_literal.h"
@ -2411,6 +2412,15 @@ class ProgramBuilder {
Expr(std::forward<EXPR_Z>(z))); Expr(std::forward<EXPR_Z>(z)));
} }
/// Creates an ast::DisableValidationDecoration
/// @param validation the validation to disable
/// @returns the disable validation decoration pointer
const ast::DisableValidationDecoration* Disable(
ast::DisabledValidation validation) {
return ASTNodes().Create<ast::DisableValidationDecoration>(ID(),
validation);
}
/// Sets the current builder source to `src` /// Sets the current builder source to `src`
/// @param src the Source used for future create() calls /// @param src the Source used for future create() calls
void SetSource(const Source& src) { void SetSource(const Source& src) {

View File

@ -498,16 +498,13 @@ TEST_F(EntryPointParameterDecorationTest, DuplicateDecoration) {
} }
TEST_F(EntryPointParameterDecorationTest, DuplicateInternalDecoration) { TEST_F(EntryPointParameterDecorationTest, DuplicateInternalDecoration) {
auto* s = auto* s = Param("s", ty.sampler(ast::SamplerKind::kSampler),
Param("s", ty.sampler(ast::SamplerKind::kSampler), ast::DecorationList{
ast::DecorationList{ create<ast::BindingDecoration>(0),
create<ast::BindingDecoration>(0), create<ast::GroupDecoration>(0),
create<ast::GroupDecoration>(0), Disable(ast::DisabledValidation::kBindingPointCollision),
ASTNodes().Create<ast::DisableValidationDecoration>( Disable(ast::DisabledValidation::kEntryPointParameter),
ID(), ast::DisabledValidation::kBindingPointCollision), });
ASTNodes().Create<ast::DisableValidationDecoration>(
ID(), ast::DisabledValidation::kEntryPointParameter),
});
Func("f", {s}, ty.void_(), {}, {Stage(ast::PipelineStage::kFragment)}); Func("f", {s}, ty.void_(), {}, {Stage(ast::PipelineStage::kFragment)});
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -531,10 +528,8 @@ TEST_F(EntryPointReturnTypeDecorationTest, DuplicateDecoration) {
TEST_F(EntryPointReturnTypeDecorationTest, DuplicateInternalDecoration) { TEST_F(EntryPointReturnTypeDecorationTest, DuplicateInternalDecoration) {
Func("f", {}, ty.i32(), {Return(1)}, {Stage(ast::PipelineStage::kFragment)}, Func("f", {}, ty.i32(), {Return(1)}, {Stage(ast::PipelineStage::kFragment)},
ast::DecorationList{ ast::DecorationList{
ASTNodes().Create<ast::DisableValidationDecoration>( Disable(ast::DisabledValidation::kBindingPointCollision),
ID(), ast::DisabledValidation::kBindingPointCollision), Disable(ast::DisabledValidation::kEntryPointParameter),
ASTNodes().Create<ast::DisableValidationDecoration>(
ID(), ast::DisabledValidation::kEntryPointParameter),
}); });
EXPECT_TRUE(r()->Resolve()) << r()->error(); EXPECT_TRUE(r()->Resolve()) << r()->error();
@ -1156,7 +1151,6 @@ TEST_F(ResourceDecorationTest, BindingPointOnNonResource) {
} // namespace } // namespace
} // namespace ResourceTests } // namespace ResourceTests
namespace InvariantDecorationTests { namespace InvariantDecorationTests {
namespace { namespace {
using InvariantDecorationTests = ResolverTest; using InvariantDecorationTests = ResolverTest;

View File

@ -140,8 +140,7 @@ void BindingRemapper::Run(CloneContext& ctx, const DataMap& inputs, DataMap&) {
// Add `DisableValidationDecoration`s if required // Add `DisableValidationDecoration`s if required
if (add_collision_deco.count(bp)) { if (add_collision_deco.count(bp)) {
auto* decoration = auto* decoration =
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kBindingPointCollision);
ctx.dst->ID(), ast::DisabledValidation::kBindingPointCollision);
ctx.InsertBefore(var->decorations, *var->decorations.begin(), ctx.InsertBefore(var->decorations, *var->decorations.begin(),
decoration); decoration);
} }

View File

@ -82,10 +82,8 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) {
auto name = ctx.dst->Sym(); auto name = ctx.dst->Sym();
auto* buffer_typename = auto* buffer_typename =
ctx.dst->ty.type_name(ctx.Clone(buffer_type->Declaration()->name)); ctx.dst->ty.type_name(ctx.Clone(buffer_type->Declaration()->name));
auto* disable_validation = auto* disable_validation = ctx.dst->Disable(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
ctx.dst->ID(),
ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
auto* func = ctx.dst->create<ast::Function>( auto* func = ctx.dst->create<ast::Function>(
name, name,
ast::VariableList{ ast::VariableList{

View File

@ -173,8 +173,7 @@ struct CanonicalizeEntryPointIO::State {
// Disable validation for use of the `input` storage class. // Disable validation for use of the `input` storage class.
attributes.push_back( attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kIgnoreStorageClass));
ctx.dst->ID(), ast::DisabledValidation::kIgnoreStorageClass));
// Create the global variable and use its value for the shader input. // Create the global variable and use its value for the shader input.
auto symbol = ctx.dst->Symbols().New(name); auto symbol = ctx.dst->Symbols().New(name);
@ -417,8 +416,7 @@ struct CanonicalizeEntryPointIO::State {
// Disable validation for use of the `output` storage class. // Disable validation for use of the `output` storage class.
ast::DecorationList attributes = std::move(outval.attributes); ast::DecorationList attributes = std::move(outval.attributes);
attributes.push_back( attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kIgnoreStorageClass));
ctx.dst->ID(), ast::DisabledValidation::kIgnoreStorageClass));
// Create the global variable and assign it the output value. // Create the global variable and assign it the output value.
auto name = ctx.dst->Symbols().New(outval.name); auto name = ctx.dst->Symbols().New(outval.name);

View File

@ -451,10 +451,8 @@ struct DecomposeMemoryAccess::State {
return utils::GetOrCreate( return utils::GetOrCreate(
load_funcs, LoadStoreKey{storage_class, buf_ty, el_ty}, [&] { load_funcs, LoadStoreKey{storage_class, buf_ty, el_ty}, [&] {
auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty); auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty);
auto* disable_validation = auto* disable_validation = b.Disable(
b.ASTNodes().Create<ast::DisableValidationDecoration>( ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
b.ID(), ast::DisabledValidation::
kIgnoreConstructibleFunctionParameter);
ast::VariableList params = { ast::VariableList params = {
// Note: The buffer parameter requires the StorageClass in // Note: The buffer parameter requires the StorageClass in
@ -476,8 +474,7 @@ struct DecomposeMemoryAccess::State {
name, params, el_ast_ty, nullptr, name, params, el_ast_ty, nullptr,
ast::DecorationList{ ast::DecorationList{
intrinsic, intrinsic,
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
b.ID(), ast::DisabledValidation::kFunctionHasNoBody),
}, },
ast::DecorationList{}); ast::DecorationList{});
b.AST().AddFunction(func); b.AST().AddFunction(func);
@ -554,10 +551,8 @@ struct DecomposeMemoryAccess::State {
store_funcs, LoadStoreKey{storage_class, buf_ty, el_ty}, [&] { store_funcs, LoadStoreKey{storage_class, buf_ty, el_ty}, [&] {
auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty); auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty);
auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty); auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty);
auto* disable_validation = auto* disable_validation = b.Disable(
b.ASTNodes().Create<ast::DisableValidationDecoration>( ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
b.ID(), ast::DisabledValidation::
kIgnoreConstructibleFunctionParameter);
ast::VariableList params{ ast::VariableList params{
// Note: The buffer parameter requires the StorageClass in // Note: The buffer parameter requires the StorageClass in
// order for HLSL to emit this as a ByteAddressBuffer. // order for HLSL to emit this as a ByteAddressBuffer.
@ -578,8 +573,7 @@ struct DecomposeMemoryAccess::State {
name, params, b.ty.void_(), nullptr, name, params, b.ty.void_(), nullptr,
ast::DecorationList{ ast::DecorationList{
intrinsic, intrinsic,
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
b.ID(), ast::DisabledValidation::kFunctionHasNoBody),
}, },
ast::DecorationList{}); ast::DecorationList{});
b.AST().AddFunction(func); b.AST().AddFunction(func);
@ -655,10 +649,8 @@ struct DecomposeMemoryAccess::State {
auto op = intrinsic->Type(); auto op = intrinsic->Type();
return utils::GetOrCreate(atomic_funcs, AtomicKey{buf_ty, el_ty, op}, [&] { return utils::GetOrCreate(atomic_funcs, AtomicKey{buf_ty, el_ty, op}, [&] {
auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty); auto* buf_ast_ty = CreateASTTypeFor(ctx, buf_ty);
auto* disable_validation = auto* disable_validation = b.Disable(
b.ASTNodes().Create<ast::DisableValidationDecoration>( ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
b.ID(),
ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
// The first parameter to all WGSL atomics is the expression to the // The first parameter to all WGSL atomics is the expression to the
// atomic. This is replaced with two parameters: the buffer and offset. // atomic. This is replaced with two parameters: the buffer and offset.
@ -691,8 +683,7 @@ struct DecomposeMemoryAccess::State {
b.Sym(), params, ret_ty, nullptr, b.Sym(), params, ret_ty, nullptr,
ast::DecorationList{ ast::DecorationList{
atomic, atomic,
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
b.ID(), ast::DisabledValidation::kFunctionHasNoBody),
}, },
ast::DecorationList{}); ast::DecorationList{});

View File

@ -82,8 +82,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix) {
{ {
b.create<ast::StructMemberOffsetDecoration>(16), b.create<ast::StructMemberOffsetDecoration>(16),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -149,8 +148,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformColumn) {
{ {
b.create<ast::StructMemberOffsetDecoration>(16), b.create<ast::StructMemberOffsetDecoration>(16),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -212,8 +210,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadUniformMatrix_DefaultStride) {
{ {
b.create<ast::StructMemberOffsetDecoration>(16), b.create<ast::StructMemberOffsetDecoration>(16),
b.create<ast::StrideDecoration>(8), b.create<ast::StrideDecoration>(8),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -276,8 +273,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageMatrix) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -343,8 +339,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadStorageColumn) {
{ {
b.create<ast::StructMemberOffsetDecoration>(16), b.create<ast::StructMemberOffsetDecoration>(16),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -406,8 +401,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageMatrix) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -474,8 +468,7 @@ TEST_F(DecomposeStridedMatrixTest, WriteStorageColumn) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -543,8 +536,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadWriteViaPointerLets) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}, },
{ {
@ -626,8 +618,7 @@ TEST_F(DecomposeStridedMatrixTest, ReadPrivateMatrix) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate); b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate);
@ -684,8 +675,7 @@ TEST_F(DecomposeStridedMatrixTest, WritePrivateMatrix) {
{ {
b.create<ast::StructMemberOffsetDecoration>(8), b.create<ast::StructMemberOffsetDecoration>(8),
b.create<ast::StrideDecoration>(32), b.create<ast::StrideDecoration>(32),
b.ASTNodes().Create<ast::DisableValidationDecoration>( b.Disable(ast::DisabledValidation::kIgnoreStrideDecoration),
b.ID(), ast::DisabledValidation::kIgnoreStrideDecoration),
}), }),
}); });
b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate); b.Global("s", b.ty.Of(S), ast::StorageClass::kPrivate);

View File

@ -186,9 +186,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// For a texture or sampler variable, redeclare it as an entry point // For a texture or sampler variable, redeclare it as an entry point
// parameter. Disable entry point parameter validation. // parameter. Disable entry point parameter validation.
auto* disable_validation = auto* disable_validation =
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kEntryPointParameter);
ctx.dst->ID(),
ast::DisabledValidation::kEntryPointParameter);
auto decos = ctx.Clone(var->Declaration()->decorations); auto decos = ctx.Clone(var->Declaration()->decorations);
decos.push_back(disable_validation); decos.push_back(disable_validation);
auto* param = ctx.dst->Param(new_var_symbol, store_type(), decos); auto* param = ctx.dst->Param(new_var_symbol, store_type(), decos);
@ -198,14 +196,10 @@ struct ModuleScopeVarToEntryPointParam::State {
// Variables into the Storage and Uniform storage classes are // Variables into the Storage and Uniform storage classes are
// redeclared as entry point parameters with a pointer type. // redeclared as entry point parameters with a pointer type.
auto attributes = ctx.Clone(var->Declaration()->decorations); auto attributes = ctx.Clone(var->Declaration()->decorations);
attributes.push_back(ctx.dst->Disable(
ast::DisabledValidation::kEntryPointParameter));
attributes.push_back( attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kIgnoreStorageClass));
ctx.dst->ID(),
ast::DisabledValidation::kEntryPointParameter));
attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>(
ctx.dst->ID(),
ast::DisabledValidation::kIgnoreStorageClass));
auto* param_type = ctx.dst->ty.pointer( auto* param_type = ctx.dst->ty.pointer(
store_type(), sc, var->Declaration()->declared_access); store_type(), sc, var->Declaration()->declared_access);
auto* param = auto* param =
@ -241,9 +235,7 @@ struct ModuleScopeVarToEntryPointParam::State {
// redeclared at function scope. Disable storage class validation on // redeclared at function scope. Disable storage class validation on
// this variable. // this variable.
auto* disable_validation = auto* disable_validation =
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kIgnoreStorageClass);
ctx.dst->ID(),
ast::DisabledValidation::kIgnoreStorageClass);
auto* constructor = ctx.Clone(var->Declaration()->constructor); auto* constructor = ctx.Clone(var->Declaration()->constructor);
auto* local_var = auto* local_var =
ctx.dst->Var(new_var_symbol, store_type(), sc, constructor, ctx.dst->Var(new_var_symbol, store_type(), sc, constructor,
@ -264,13 +256,9 @@ struct ModuleScopeVarToEntryPointParam::State {
// Disable validation of the parameter's storage class and of // Disable validation of the parameter's storage class and of
// arguments passed it. // arguments passed it.
attributes.push_back( attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kIgnoreStorageClass));
ctx.dst->ID(), attributes.push_back(ctx.dst->Disable(
ast::DisabledValidation::kIgnoreStorageClass)); ast::DisabledValidation::kIgnoreInvalidPointerArgument));
attributes.push_back(
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>(
ctx.dst->ID(),
ast::DisabledValidation::kIgnoreInvalidPointerArgument));
} }
ctx.InsertBack( ctx.InsertBack(
func_ast->params, func_ast->params,
@ -311,8 +299,7 @@ struct ModuleScopeVarToEntryPointParam::State {
auto* param_type = ctx.dst->ty.pointer(ctx.dst->ty.Of(str), auto* param_type = ctx.dst->ty.pointer(ctx.dst->ty.Of(str),
ast::StorageClass::kWorkgroup); ast::StorageClass::kWorkgroup);
auto* disable_validation = auto* disable_validation =
ctx.dst->ASTNodes().Create<ast::DisableValidationDecoration>( ctx.dst->Disable(ast::DisabledValidation::kEntryPointParameter);
ctx.dst->ID(), ast::DisabledValidation::kEntryPointParameter);
auto* param = auto* param =
ctx.dst->Param(workgroup_param(), param_type, {disable_validation}); ctx.dst->Param(workgroup_param(), param_type, {disable_validation});
ctx.InsertFront(func_ast->params, param); ctx.InsertFront(func_ast->params, param);