James Price | 6251598 | 2022-11-09 15:40:06 +0000 | [diff] [blame] | 1 | // 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 | |
| 20 | namespace 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 Price | 744d0eb | 2022-11-09 19:58:59 +0000 | [diff] [blame] | 28 | /// |
| 29 | /// @note Depends on the following transforms to have been run first: |
| 30 | /// * PromoteSideEffectsToDecl |
| 31 | /// * ExpandCompoundAssignment |
James Price | 6251598 | 2022-11-09 15:40:06 +0000 | [diff] [blame] | 32 | class 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_ |