Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: gpu/vulkan/vulkan_descriptor_pool.cc

Issue 1989013002: Added Vulkan Descriptor Sets and Samplers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "gpu/vulkan/vulkan_descriptor_pool.h"
6
7 #include "base/logging.h"
8 #include "base/memory/ptr_util.h"
9 #include "gpu/vulkan/vulkan_descriptor_set.h"
10 #include "gpu/vulkan/vulkan_device_queue.h"
11
12 namespace gpu {
13
14 VulkanDescriptorPool::VulkanDescriptorPool(VulkanDeviceQueue* device_queue)
15 : device_queue_(device_queue) {}
16
17 VulkanDescriptorPool::~VulkanDescriptorPool() {
18 DCHECK_EQ(static_cast<VkDescriptorPool>(VK_NULL_HANDLE), handle_);
19 DCHECK_EQ(0u, descriptor_count_);
20 }
21
22 bool VulkanDescriptorPool::Initialize(
23 uint32_t max_descriptor_sets,
24 const std::vector<VkDescriptorPoolSize>& pool_sizes) {
25 DCHECK_EQ(static_cast<VkDescriptorPool>(VK_NULL_HANDLE), handle_);
26 max_descriptor_sets_ = max_descriptor_sets;
27
28 VkDescriptorPoolCreateInfo descriptor_pool_create_info = {};
29 descriptor_pool_create_info.sType =
30 VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
31 descriptor_pool_create_info.flags =
32 VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
33 descriptor_pool_create_info.maxSets = max_descriptor_sets;
34 descriptor_pool_create_info.poolSizeCount =
35 static_cast<uint32_t>(pool_sizes.size());
36 descriptor_pool_create_info.pPoolSizes = pool_sizes.data();
37
38 VkResult result =
39 vkCreateDescriptorPool(device_queue_->GetVulkanDevice(),
40 &descriptor_pool_create_info, nullptr, &handle_);
41 if (VK_SUCCESS != result) {
42 DLOG(ERROR) << "vkCreateDescriptorPool() failed: " << result;
43 return false;
44 }
45
46 return true;
47 }
48
49 void VulkanDescriptorPool::Destroy() {
50 DCHECK_EQ(0u, descriptor_count_);
51 if (VK_NULL_HANDLE != handle_) {
52 vkDestroyDescriptorPool(device_queue_->GetVulkanDevice(), handle_, nullptr);
53 handle_ = VK_NULL_HANDLE;
54 }
55
56 max_descriptor_sets_ = 0;
57 descriptor_count_ = 0;
piman 2016/05/18 19:02:18 nit: it's already 0 (see DCHECK)
David Yen 2016/05/18 21:08:35 Done.
58 }
59
60 std::unique_ptr<VulkanDescriptorSet> VulkanDescriptorPool::CreateDescriptorSet(
61 const std::vector<VkDescriptorSetLayoutBinding>& layout) {
62 std::unique_ptr<VulkanDescriptorSet> descriptor_set(
63 new VulkanDescriptorSet(device_queue_, this));
64 if (!descriptor_set->Initialize(layout)) {
65 return nullptr;
66 }
67 return descriptor_set;
68 }
69
70 void VulkanDescriptorPool::IncrementDescriptorSetCount() {
71 DCHECK_LT(descriptor_count_, max_descriptor_sets_);
72 descriptor_count_++;
73 }
74
75 void VulkanDescriptorPool::DecrementDescriptorSetCount() {
76 DCHECK_LT(0u, descriptor_count_);
77 descriptor_count_--;
78 }
79
80 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698