resolver: Validate pipline stage use for intrinsics

Use the new [[stage()]] decorations in intrinsics.def to validate that intrinsics are only called from the correct pipeline stages.

Fixed: tint:657
Change-Id: I9efda26369c45c6f816bdaa53408d3909db403a1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53084
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: David Neto <dneto@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2021-06-03 16:07:34 +00:00
committed by Tint LUCI CQ
parent 7b366475ed
commit 71786c99b3
21 changed files with 611 additions and 148 deletions

View File

@@ -89,8 +89,11 @@ bool IsBarrierIntrinsic(IntrinsicType i) {
Intrinsic::Intrinsic(IntrinsicType type,
sem::Type* return_type,
const ParameterList& parameters)
: Base(return_type, parameters), type_(type) {}
const ParameterList& parameters,
PipelineStageSet supported_stages)
: Base(return_type, parameters),
type_(type),
supported_stages_(supported_stages) {}
Intrinsic::~Intrinsic() = default;

View File

@@ -19,6 +19,7 @@
#include "src/sem/call_target.h"
#include "src/sem/intrinsic_type.h"
#include "src/sem/pipeline_stage_set.h"
namespace tint {
namespace sem {
@@ -75,9 +76,12 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @param type the intrinsic type
/// @param return_type the return type for the intrinsic call
/// @param parameters the parameters for the intrinsic overload
/// @param supported_stages the pipeline stages that this intrinsic can be
/// used in
Intrinsic(IntrinsicType type,
sem::Type* return_type,
const ParameterList& parameters);
const ParameterList& parameters,
PipelineStageSet supported_stages);
/// Destructor
~Intrinsic() override;
@@ -85,6 +89,9 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
/// @return the type of the intrinsic
IntrinsicType Type() const { return type_; }
/// @return the pipeline stages that this intrinsic can be used in
PipelineStageSet SupportedStages() const { return supported_stages_; }
/// @returns the name of the intrinsic function type. The spelling, including
/// case, matches the name in the WGSL spec.
const char* str() const;
@@ -118,6 +125,7 @@ class Intrinsic : public Castable<Intrinsic, CallTarget> {
private:
IntrinsicType const type_;
PipelineStageSet const supported_stages_;
};
/// Emits the name of the intrinsic function type. The spelling, including case,

View File

@@ -0,0 +1,29 @@
// Copyright 2021 The Tint Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SRC_SEM_PIPELINE_STAGE_SET_H_
#define SRC_SEM_PIPELINE_STAGE_SET_H_
#include "src/ast/pipeline_stage.h"
#include "src/utils/enum_set.h"
namespace tint {
namespace sem {
using PipelineStageSet = utils::EnumSet<ast::PipelineStage>;
} // namespace sem
} // namespace tint
#endif // SRC_SEM_PIPELINE_STAGE_SET_H_