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 "common/ityp_array.h" 20 #include "common/ityp_bitset.h" 21 #include "dawn_native/BindingInfo.h" 22 #include "dawn_native/CachedObject.h" 23 #include "dawn_native/Error.h" 24 #include "dawn_native/Forward.h" 25 #include "dawn_native/ObjectBase.h" 26 27 #include "dawn_native/dawn_platform.h" 28 29 #include <array> 30 #include <bitset> 31 32 namespace dawn_native { 33 34 MaybeError ValidatePipelineLayoutDescriptor( 35 DeviceBase*, 36 const PipelineLayoutDescriptor* descriptor, 37 PipelineCompatibilityToken pipelineCompatibilityToken = PipelineCompatibilityToken(0)); 38 39 using BindGroupLayoutArray = 40 ityp::array<BindGroupIndex, Ref<BindGroupLayoutBase>, kMaxBindGroups>; 41 using BindGroupLayoutMask = ityp::bitset<BindGroupIndex, kMaxBindGroups>; 42 43 struct StageAndDescriptor { 44 SingleShaderStage shaderStage; 45 ShaderModuleBase* module; 46 std::string entryPoint; 47 uint32_t constantCount = 0u; 48 ConstantEntry const* constants = nullptr; 49 }; 50 51 class PipelineLayoutBase : public ApiObjectBase, public CachedObject { 52 public: 53 PipelineLayoutBase(DeviceBase* device, 54 const PipelineLayoutDescriptor* descriptor, 55 ApiObjectBase::UntrackedByDeviceTag tag); 56 PipelineLayoutBase(DeviceBase* device, const PipelineLayoutDescriptor* descriptor); 57 ~PipelineLayoutBase() override; 58 59 static PipelineLayoutBase* MakeError(DeviceBase* device); 60 static ResultOrError<Ref<PipelineLayoutBase>> CreateDefault( 61 DeviceBase* device, 62 std::vector<StageAndDescriptor> stages); 63 64 ObjectType GetType() const override; 65 66 const BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group) const; 67 BindGroupLayoutBase* GetBindGroupLayout(BindGroupIndex group); 68 const BindGroupLayoutMask& GetBindGroupLayoutsMask() const; 69 70 // Utility functions to compute inherited bind groups. 71 // Returns the inherited bind groups as a mask. 72 BindGroupLayoutMask InheritedGroupsMask(const PipelineLayoutBase* other) const; 73 74 // Returns the index of the first incompatible bind group in the range 75 // [0, kMaxBindGroups] 76 BindGroupIndex GroupsInheritUpTo(const PipelineLayoutBase* other) const; 77 78 // Functions necessary for the unordered_set<PipelineLayoutBase*>-based cache. 79 size_t ComputeContentHash() override; 80 81 struct EqualityFunc { 82 bool operator()(const PipelineLayoutBase* a, const PipelineLayoutBase* b) const; 83 }; 84 85 protected: 86 // Constructor used only for mocking and testing. 87 PipelineLayoutBase(DeviceBase* device); 88 PipelineLayoutBase(DeviceBase* device, ObjectBase::ErrorTag tag); 89 void DestroyImpl() override; 90 91 BindGroupLayoutArray mBindGroupLayouts; 92 BindGroupLayoutMask mMask; 93 }; 94 95 } // namespace dawn_native 96 97 #endif // DAWNNATIVE_PIPELINELAYOUT_H_ 98