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_PIPELINELAYOUT_H_ 16 #define DAWNNATIVE_PIPELINELAYOUT_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 ValidatePipelineLayoutDescriptor(DeviceBase*, 31 const PipelineLayoutDescriptor* descriptor); 32 33 using BindGroupLayoutArray = std::array<Ref<BindGroupLayoutBase>, kMaxBindGroups>; 34 35 class PipelineLayoutBase : public ObjectBase { 36 public: 37 PipelineLayoutBase(DeviceBase* device, 38 const PipelineLayoutDescriptor* descriptor, 39 bool blueprint = false); 40 ~PipelineLayoutBase() override; 41 42 static PipelineLayoutBase* MakeError(DeviceBase* device); 43 44 const BindGroupLayoutBase* GetBindGroupLayout(size_t group) const; 45 const std::bitset<kMaxBindGroups> GetBindGroupLayoutsMask() const; 46 47 // Utility functions to compute inherited bind groups. 48 // Returns the inherited bind groups as a mask. 49 std::bitset<kMaxBindGroups> InheritedGroupsMask(const PipelineLayoutBase* other) const; 50 51 // Returns the index of the first incompatible bind group in the range 52 // [1, kMaxBindGroups + 1] 53 uint32_t GroupsInheritUpTo(const PipelineLayoutBase* other) const; 54 55 // Functors necessary for the unordered_set<PipelineLayoutBase*>-based cache. 56 struct HashFunc { 57 size_t operator()(const PipelineLayoutBase* pl) const; 58 }; 59 struct EqualityFunc { 60 bool operator()(const PipelineLayoutBase* a, const PipelineLayoutBase* b) const; 61 }; 62 63 protected: 64 PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag); 65 66 BindGroupLayoutArray mBindGroupLayouts; 67 std::bitset<kMaxBindGroups> mMask; 68 bool mIsBlueprint = false; 69 }; 70 71 } // namespace dawn_native 72 73 #endif // DAWNNATIVE_PIPELINELAYOUT_H_ 74