blob: ba87febfd11f65ed3f41d144c873488f3a49a3b8 [file] [log] [blame]
James Price62515982022-11-09 15:40:06 +00001// Copyright 2022 The Tint Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SRC_TINT_TRANSFORM_DEMOTE_TO_HELPER_H_
16#define SRC_TINT_TRANSFORM_DEMOTE_TO_HELPER_H_
17
18#include "src/tint/transform/transform.h"
19
20namespace tint::transform {
21
22/// Implement demote-to-helper semantics for discard statements.
23///
24/// For backend targets that implement discard by terminating the invocation, we need to change the
25/// program to ensure that discarding the fragment does not affect uniformity with respect to
26/// derivative operations. We do this by setting a global flag and masking all writes to storage
27/// buffers and textures.
James Price744d0eb2022-11-09 19:58:59 +000028///
29/// @note Depends on the following transforms to have been run first:
30/// * PromoteSideEffectsToDecl
31/// * ExpandCompoundAssignment
James Price62515982022-11-09 15:40:06 +000032class DemoteToHelper final : public Castable<DemoteToHelper, Transform> {
33 public:
34 /// Constructor
35 DemoteToHelper();
36 /// Destructor
37 ~DemoteToHelper() override;
38
39 /// @copydoc Transform::Apply
40 ApplyResult Apply(const Program* program,
41 const DataMap& inputs,
42 DataMap& outputs) const override;
43};
44
45} // namespace tint::transform
46
47#endif // SRC_TINT_TRANSFORM_DEMOTE_TO_HELPER_H_