• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Dawn 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 DAWNNATIVE_TOGGLES_H_
16 #define DAWNNATIVE_TOGGLES_H_
17 
18 #include <bitset>
19 
20 #include "dawn_native/DawnNative.h"
21 
22 namespace dawn_native {
23 
24     enum class Toggle {
25         EmulateStoreAndMSAAResolve,
26         NonzeroClearResourcesOnCreationForTesting,
27         AlwaysResolveIntoZeroLevelAndLayer,
28         LazyClearResourceOnFirstUse,
29 
30         EnumCount,
31         InvalidEnum = EnumCount,
32     };
33 
34     // A wrapper of the bitset to store if a toggle is enabled or not. This wrapper provides the
35     // convenience to convert the enums of enum class Toggle to the indices of a bitset.
36     struct TogglesSet {
37         std::bitset<static_cast<size_t>(Toggle::EnumCount)> toggleBitset;
38 
SetToggleTogglesSet39         void SetToggle(Toggle toggle, bool enabled) {
40             ASSERT(toggle != Toggle::InvalidEnum);
41             const size_t toggleIndex = static_cast<size_t>(toggle);
42             toggleBitset.set(toggleIndex, enabled);
43         }
44 
IsEnabledTogglesSet45         bool IsEnabled(Toggle toggle) const {
46             ASSERT(toggle != Toggle::InvalidEnum);
47             const size_t toggleIndex = static_cast<size_t>(toggle);
48             return toggleBitset.test(toggleIndex);
49         }
50     };
51 
52 }  // namespace dawn_native
53 
54 #endif  // DAWNNATIVE_TOGGLES_H_
55