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_image_view.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "gpu/vulkan/vulkan_implementation.h" |
| 9 |
| 10 namespace gpu { |
| 11 |
| 12 namespace { |
| 13 const VkImageAspectFlags kAspectFlags[] = { |
| 14 // IMAGE_TYPE_COLOR, |
| 15 VK_IMAGE_ASPECT_COLOR_BIT, |
| 16 |
| 17 // IMAGE_TYPE_DEPTH, |
| 18 VK_IMAGE_ASPECT_DEPTH_BIT, |
| 19 |
| 20 // IMAGE_TYPE_STENCIL, |
| 21 VK_IMAGE_ASPECT_STENCIL_BIT, |
| 22 |
| 23 // IMAGE_TYPE_DEPTH_STENCIL, |
| 24 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, |
| 25 }; |
| 26 static_assert(arraysize(kAspectFlags) == VulkanImageView::NUM_IMAGE_TYPES, |
| 27 "Array size for kAspectFlags must match image types."); |
| 28 } // namespace |
| 29 |
| 30 VulkanImageView::VulkanImageView() {} |
| 31 |
| 32 VulkanImageView::~VulkanImageView() { |
| 33 DCHECK_EQ(static_cast<VkImageView>(VK_NULL_HANDLE), handle_); |
| 34 DCHECK_EQ(IMAGE_TYPE_INVALID, image_type_); |
| 35 } |
| 36 |
| 37 bool VulkanImageView::Initialize(VkImage image, |
| 38 VkImageViewType image_view_type, |
| 39 ImageType image_type, |
| 40 VkFormat format, |
| 41 uint32_t width, |
| 42 uint32_t height, |
| 43 uint32_t base_mip_level, |
| 44 uint32_t num_mips, |
| 45 uint32_t base_layer_level, |
| 46 uint32_t num_layers) { |
| 47 DCHECK_GT(image_type, IMAGE_TYPE_INVALID); |
| 48 DCHECK_LT(image_type, NUM_IMAGE_TYPES); |
| 49 VkImageSubresourceRange image_subresource_range = {}; |
| 50 image_subresource_range.aspectMask = kAspectFlags[image_type]; |
| 51 image_subresource_range.baseMipLevel = base_mip_level; |
| 52 image_subresource_range.levelCount = num_mips; |
| 53 image_subresource_range.baseArrayLayer = base_layer_level; |
| 54 image_subresource_range.layerCount = num_layers; |
| 55 |
| 56 VkImageViewCreateInfo image_view_create_info = {}; |
| 57 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
| 58 image_view_create_info.image = image; |
| 59 image_view_create_info.viewType = image_view_type; |
| 60 image_view_create_info.format = format; |
| 61 image_view_create_info.components = { |
| 62 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
| 63 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; |
| 64 image_view_create_info.subresourceRange = image_subresource_range; |
| 65 |
| 66 VkResult result = vkCreateImageView( |
| 67 GetVulkanDevice(), &image_view_create_info, nullptr, &handle_); |
| 68 if (VK_SUCCESS != result) { |
| 69 DLOG(ERROR) << "vkCreateImageView() failed: " << result; |
| 70 return false; |
| 71 } |
| 72 |
| 73 image_type_ = image_type; |
| 74 width_ = width; |
| 75 height_ = height; |
| 76 mips_ = num_mips; |
| 77 layers_ = num_layers; |
| 78 return true; |
| 79 } |
| 80 |
| 81 void VulkanImageView::Destroy() { |
| 82 if (VK_NULL_HANDLE != handle_) { |
| 83 vkDestroyImageView(GetVulkanDevice(), handle_, nullptr); |
| 84 image_type_ = IMAGE_TYPE_INVALID; |
| 85 handle_ = VK_NULL_HANDLE; |
| 86 } |
| 87 } |
| 88 |
| 89 } // namespace gpu |
OLD | NEW |