OLD | NEW |
(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_set.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "gpu/vulkan/vulkan_descriptor_layout.h" |
| 9 #include "gpu/vulkan/vulkan_descriptor_pool.h" |
| 10 #include "gpu/vulkan/vulkan_device_queue.h" |
| 11 |
| 12 namespace gpu { |
| 13 |
| 14 VulkanDescriptorSet::~VulkanDescriptorSet() { |
| 15 DCHECK_EQ(static_cast<VkDescriptorSet>(VK_NULL_HANDLE), handle_); |
| 16 descriptor_pool_->DecrementDescriptorSetCount(); |
| 17 } |
| 18 |
| 19 bool VulkanDescriptorSet::Initialize(const VulkanDescriptorLayout* layout) { |
| 20 VkResult result = VK_SUCCESS; |
| 21 VkDevice device = device_queue_->GetVulkanDevice(); |
| 22 |
| 23 VkDescriptorSetLayout layout_handle = layout->handle(); |
| 24 |
| 25 VkDescriptorSetAllocateInfo set_allocate_info = {}; |
| 26 set_allocate_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; |
| 27 set_allocate_info.descriptorPool = descriptor_pool_->handle(); |
| 28 set_allocate_info.descriptorSetCount = 1; |
| 29 set_allocate_info.pSetLayouts = &layout_handle; |
| 30 |
| 31 result = vkAllocateDescriptorSets(device, &set_allocate_info, &handle_); |
| 32 if (VK_SUCCESS != result) { |
| 33 DLOG(ERROR) << "vkAllocateDescriptorSets() failed: " << result; |
| 34 return false; |
| 35 } |
| 36 |
| 37 return true; |
| 38 } |
| 39 |
| 40 void VulkanDescriptorSet::Destroy() { |
| 41 VkDevice device = device_queue_->GetVulkanDevice(); |
| 42 if (VK_NULL_HANDLE != handle_) { |
| 43 vkFreeDescriptorSets(device, descriptor_pool_->handle(), 1, &handle_); |
| 44 handle_ = VK_NULL_HANDLE; |
| 45 } |
| 46 } |
| 47 |
| 48 void VulkanDescriptorSet::WriteToDescriptorSet( |
| 49 uint32_t dst_binding, |
| 50 uint32_t dst_array_element, |
| 51 uint32_t descriptor_count, |
| 52 VkDescriptorType descriptor_type, |
| 53 const VkDescriptorImageInfo* image_info, |
| 54 const VkDescriptorBufferInfo* buffer_info, |
| 55 const VkBufferView* texel_buffer_view) { |
| 56 VkWriteDescriptorSet write_descriptor_set = {}; |
| 57 write_descriptor_set.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET; |
| 58 write_descriptor_set.dstSet = handle_; |
| 59 write_descriptor_set.dstBinding = dst_binding; |
| 60 write_descriptor_set.dstArrayElement = dst_array_element; |
| 61 write_descriptor_set.descriptorCount = descriptor_count; |
| 62 write_descriptor_set.descriptorType = descriptor_type; |
| 63 write_descriptor_set.pImageInfo = image_info; |
| 64 write_descriptor_set.pBufferInfo = buffer_info; |
| 65 write_descriptor_set.pTexelBufferView = texel_buffer_view; |
| 66 |
| 67 vkUpdateDescriptorSets(device_queue_->GetVulkanDevice(), 1, |
| 68 &write_descriptor_set, 0, nullptr); |
| 69 } |
| 70 |
| 71 void VulkanDescriptorSet::CopyFromDescriptorSet( |
| 72 const VulkanDescriptorSet* source_set, |
| 73 uint32_t src_binding, |
| 74 uint32_t src_array_element, |
| 75 uint32_t dst_binding, |
| 76 uint32_t dst_array_element, |
| 77 uint32_t descriptor_count) { |
| 78 VkCopyDescriptorSet copy_descriptor_set = {}; |
| 79 copy_descriptor_set.sType = VK_STRUCTURE_TYPE_COPY_DESCRIPTOR_SET; |
| 80 copy_descriptor_set.srcSet = source_set->handle(); |
| 81 copy_descriptor_set.srcBinding = src_binding; |
| 82 copy_descriptor_set.srcArrayElement = src_array_element; |
| 83 copy_descriptor_set.dstSet = handle_; |
| 84 copy_descriptor_set.dstBinding = dst_binding; |
| 85 copy_descriptor_set.dstArrayElement = dst_array_element; |
| 86 copy_descriptor_set.descriptorCount = descriptor_count; |
| 87 |
| 88 vkUpdateDescriptorSets(device_queue_->GetVulkanDevice(), 0, nullptr, 1, |
| 89 ©_descriptor_set); |
| 90 } |
| 91 |
| 92 VulkanDescriptorSet::VulkanDescriptorSet(VulkanDeviceQueue* device_queue, |
| 93 VulkanDescriptorPool* descriptor_pool) |
| 94 : device_queue_(device_queue), descriptor_pool_(descriptor_pool) { |
| 95 descriptor_pool_->IncrementDescriptorSetCount(); |
| 96 } |
| 97 |
| 98 } // namespace gpu |
OLD | NEW |