1 // Copyright 2017 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_BINDGROUPLAYOUT_H_ 16 #define DAWNNATIVE_BINDGROUPLAYOUT_H_ 17 18 #include "common/Constants.h" 19 #include "dawn_native/Error.h" 20 #include "dawn_native/Forward.h" 21 #include "dawn_native/ObjectBase.h" 22 23 #include "dawn_native/dawn_platform.h" 24 25 #include <array> 26 #include <bitset> 27 28 namespace dawn_native { 29 30 MaybeError ValidateBindGroupLayoutDescriptor(DeviceBase*, 31 const BindGroupLayoutDescriptor* descriptor); 32 33 class BindGroupLayoutBase : public ObjectBase { 34 public: 35 BindGroupLayoutBase(DeviceBase* device, 36 const BindGroupLayoutDescriptor* descriptor, 37 bool blueprint = false); 38 ~BindGroupLayoutBase() override; 39 40 static BindGroupLayoutBase* MakeError(DeviceBase* device); 41 42 struct LayoutBindingInfo { 43 std::array<dawn::ShaderStageBit, kMaxBindingsPerGroup> visibilities; 44 std::array<dawn::BindingType, kMaxBindingsPerGroup> types; 45 std::bitset<kMaxBindingsPerGroup> dynamic; 46 std::bitset<kMaxBindingsPerGroup> multisampled; 47 std::bitset<kMaxBindingsPerGroup> mask; 48 }; 49 const LayoutBindingInfo& GetBindingInfo() const; 50 51 // Functors necessary for the unordered_set<BGLBase*>-based cache. 52 struct HashFunc { 53 size_t operator()(const BindGroupLayoutBase* bgl) const; 54 }; 55 struct EqualityFunc { 56 bool operator()(const BindGroupLayoutBase* a, const BindGroupLayoutBase* b) const; 57 }; 58 59 uint32_t GetDynamicBufferCount() const; 60 61 private: 62 BindGroupLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag); 63 64 LayoutBindingInfo mBindingInfo; 65 bool mIsBlueprint = false; 66 uint32_t mDynamicBufferCount = 0; 67 }; 68 69 } // namespace dawn_native 70 71 #endif // DAWNNATIVE_BINDGROUPLAYOUT_H_ 72