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_FEATURES_H_ 16 #define DAWNNATIVE_FEATURES_H_ 17 18 #include <bitset> 19 #include <unordered_map> 20 #include <vector> 21 22 #include "dawn_native/DawnNative.h" 23 24 namespace dawn_native { 25 26 enum class Feature { 27 TextureCompressionBC, 28 TextureCompressionETC2, 29 TextureCompressionASTC, 30 ShaderFloat16, 31 PipelineStatisticsQuery, 32 TimestampQuery, 33 DepthClamping, 34 Depth24UnormStencil8, 35 Depth32FloatStencil8, 36 37 // Dawn-specific 38 DawnInternalUsages, 39 MultiPlanarFormats, 40 41 EnumCount, 42 InvalidEnum = EnumCount, 43 FeatureMin = TextureCompressionBC, 44 }; 45 46 // A wrapper of the bitset to store if an feature is enabled or not. This wrapper provides the 47 // convenience to convert the enums of enum class Feature to the indices of a bitset. 48 struct FeaturesSet { 49 std::bitset<static_cast<size_t>(Feature::EnumCount)> featuresBitSet; 50 51 void EnableFeature(Feature feature); 52 bool IsEnabled(Feature feature) const; 53 std::vector<const char*> GetEnabledFeatureNames() const; 54 void InitializeDeviceProperties(WGPUDeviceProperties* properties) const; 55 }; 56 57 const char* FeatureEnumToName(Feature feature); 58 59 class FeaturesInfo { 60 public: 61 FeaturesInfo(); 62 63 // Used to query the details of an feature. Return nullptr if featureName is not a valid 64 // name of an feature supported in Dawn 65 const FeatureInfo* GetFeatureInfo(const char* featureName) const; 66 Feature FeatureNameToEnum(const char* featureName) const; 67 FeaturesSet FeatureNamesToFeaturesSet( 68 const std::vector<const char*>& requiredFeatures) const; 69 70 private: 71 std::unordered_map<std::string, Feature> mFeatureNameToEnumMap; 72 }; 73 74 } // namespace dawn_native 75 76 #endif // DAWNNATIVE_FEATURES_H_ 77