• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 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 #include "dawn_native/vulkan/PipelineLayoutVk.h"
16 
17 #include "common/BitSetIterator.h"
18 #include "dawn_native/vulkan/BindGroupLayoutVk.h"
19 #include "dawn_native/vulkan/DeviceVk.h"
20 #include "dawn_native/vulkan/FencedDeleter.h"
21 #include "dawn_native/vulkan/UtilsVulkan.h"
22 #include "dawn_native/vulkan/VulkanError.h"
23 
24 namespace dawn_native { namespace vulkan {
25 
26     // static
Create(Device * device,const PipelineLayoutDescriptor * descriptor)27     ResultOrError<Ref<PipelineLayout>> PipelineLayout::Create(
28         Device* device,
29         const PipelineLayoutDescriptor* descriptor) {
30         Ref<PipelineLayout> layout = AcquireRef(new PipelineLayout(device, descriptor));
31         DAWN_TRY(layout->Initialize());
32         return layout;
33     }
34 
Initialize()35     MaybeError PipelineLayout::Initialize() {
36         // Compute the array of VkDescriptorSetLayouts that will be chained in the create info.
37         // TODO(crbug.com/dawn/277) Vulkan doesn't allow holes in this array, should we expose
38         // this constraints at the Dawn level?
39         uint32_t numSetLayouts = 0;
40         std::array<VkDescriptorSetLayout, kMaxBindGroups> setLayouts;
41         for (BindGroupIndex setIndex : IterateBitSet(GetBindGroupLayoutsMask())) {
42             setLayouts[numSetLayouts] = ToBackend(GetBindGroupLayout(setIndex))->GetHandle();
43             numSetLayouts++;
44         }
45 
46         VkPipelineLayoutCreateInfo createInfo;
47         createInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
48         createInfo.pNext = nullptr;
49         createInfo.flags = 0;
50         createInfo.setLayoutCount = numSetLayouts;
51         createInfo.pSetLayouts = AsVkArray(setLayouts.data());
52         createInfo.pushConstantRangeCount = 0;
53         createInfo.pPushConstantRanges = nullptr;
54 
55         Device* device = ToBackend(GetDevice());
56         DAWN_TRY(CheckVkSuccess(
57             device->fn.CreatePipelineLayout(device->GetVkDevice(), &createInfo, nullptr, &*mHandle),
58             "CreatePipelineLayout"));
59 
60         SetLabelImpl();
61 
62         return {};
63     }
64 
65     PipelineLayout::~PipelineLayout() = default;
66 
DestroyImpl()67     void PipelineLayout::DestroyImpl() {
68         PipelineLayoutBase::DestroyImpl();
69         if (mHandle != VK_NULL_HANDLE) {
70             ToBackend(GetDevice())->GetFencedDeleter()->DeleteWhenUnused(mHandle);
71             mHandle = VK_NULL_HANDLE;
72         }
73     }
74 
GetHandle() const75     VkPipelineLayout PipelineLayout::GetHandle() const {
76         return mHandle;
77     }
78 
SetLabelImpl()79     void PipelineLayout::SetLabelImpl() {
80         SetDebugName(ToBackend(GetDevice()), VK_OBJECT_TYPE_PIPELINE_LAYOUT,
81                      reinterpret_cast<uint64_t&>(mHandle), "Dawn_PipelineLayout", GetLabel());
82     }
83 
84 }}  // namespace dawn_native::vulkan
85