OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "gpu/vulkan/vulkan_image_view.h" | 5 #include "gpu/vulkan/vulkan_image_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gpu/vulkan/vulkan_implementation.h" | 8 #include "gpu/vulkan/vulkan_device_queue.h" |
9 | 9 |
10 namespace gpu { | 10 namespace gpu { |
11 | 11 |
12 namespace { | 12 namespace { |
13 const VkImageAspectFlags kAspectFlags[] = { | 13 const VkImageAspectFlags kAspectFlags[] = { |
14 // IMAGE_TYPE_COLOR, | 14 // IMAGE_TYPE_COLOR, |
15 VK_IMAGE_ASPECT_COLOR_BIT, | 15 VK_IMAGE_ASPECT_COLOR_BIT, |
16 | 16 |
17 // IMAGE_TYPE_DEPTH, | 17 // IMAGE_TYPE_DEPTH, |
18 VK_IMAGE_ASPECT_DEPTH_BIT, | 18 VK_IMAGE_ASPECT_DEPTH_BIT, |
19 | 19 |
20 // IMAGE_TYPE_STENCIL, | 20 // IMAGE_TYPE_STENCIL, |
21 VK_IMAGE_ASPECT_STENCIL_BIT, | 21 VK_IMAGE_ASPECT_STENCIL_BIT, |
22 | 22 |
23 // IMAGE_TYPE_DEPTH_STENCIL, | 23 // IMAGE_TYPE_DEPTH_STENCIL, |
24 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, | 24 VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT, |
25 }; | 25 }; |
26 static_assert(arraysize(kAspectFlags) == VulkanImageView::NUM_IMAGE_TYPES, | 26 static_assert(arraysize(kAspectFlags) == VulkanImageView::NUM_IMAGE_TYPES, |
27 "Array size for kAspectFlags must match image types."); | 27 "Array size for kAspectFlags must match image types."); |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 VulkanImageView::VulkanImageView() {} | 30 VulkanImageView::VulkanImageView(VulkanDeviceQueue* device_queue) |
| 31 : device_queue_(device_queue) {} |
31 | 32 |
32 VulkanImageView::~VulkanImageView() { | 33 VulkanImageView::~VulkanImageView() { |
33 DCHECK_EQ(static_cast<VkImageView>(VK_NULL_HANDLE), handle_); | 34 DCHECK_EQ(static_cast<VkImageView>(VK_NULL_HANDLE), handle_); |
34 DCHECK_EQ(IMAGE_TYPE_INVALID, image_type_); | 35 DCHECK_EQ(IMAGE_TYPE_INVALID, image_type_); |
35 } | 36 } |
36 | 37 |
37 bool VulkanImageView::Initialize(VkImage image, | 38 bool VulkanImageView::Initialize(VkImage image, |
38 VkImageViewType image_view_type, | 39 VkImageViewType image_view_type, |
39 ImageType image_type, | 40 ImageType image_type, |
40 VkFormat format, | 41 VkFormat format, |
(...skipping 15 matching lines...) Expand all Loading... |
56 VkImageViewCreateInfo image_view_create_info = {}; | 57 VkImageViewCreateInfo image_view_create_info = {}; |
57 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; | 58 image_view_create_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO; |
58 image_view_create_info.image = image; | 59 image_view_create_info.image = image; |
59 image_view_create_info.viewType = image_view_type; | 60 image_view_create_info.viewType = image_view_type; |
60 image_view_create_info.format = format; | 61 image_view_create_info.format = format; |
61 image_view_create_info.components = { | 62 image_view_create_info.components = { |
62 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, | 63 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, |
63 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; | 64 VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY}; |
64 image_view_create_info.subresourceRange = image_subresource_range; | 65 image_view_create_info.subresourceRange = image_subresource_range; |
65 | 66 |
66 VkResult result = vkCreateImageView( | 67 VkResult result = |
67 GetVulkanDevice(), &image_view_create_info, nullptr, &handle_); | 68 vkCreateImageView(device_queue_->GetVulkanDevice(), |
| 69 &image_view_create_info, nullptr, &handle_); |
68 if (VK_SUCCESS != result) { | 70 if (VK_SUCCESS != result) { |
69 DLOG(ERROR) << "vkCreateImageView() failed: " << result; | 71 DLOG(ERROR) << "vkCreateImageView() failed: " << result; |
70 return false; | 72 return false; |
71 } | 73 } |
72 | 74 |
73 image_type_ = image_type; | 75 image_type_ = image_type; |
74 width_ = width; | 76 width_ = width; |
75 height_ = height; | 77 height_ = height; |
76 mips_ = num_mips; | 78 mips_ = num_mips; |
77 layers_ = num_layers; | 79 layers_ = num_layers; |
78 return true; | 80 return true; |
79 } | 81 } |
80 | 82 |
81 void VulkanImageView::Destroy() { | 83 void VulkanImageView::Destroy() { |
82 if (VK_NULL_HANDLE != handle_) { | 84 if (VK_NULL_HANDLE != handle_) { |
83 vkDestroyImageView(GetVulkanDevice(), handle_, nullptr); | 85 vkDestroyImageView(device_queue_->GetVulkanDevice(), handle_, nullptr); |
84 image_type_ = IMAGE_TYPE_INVALID; | 86 image_type_ = IMAGE_TYPE_INVALID; |
85 handle_ = VK_NULL_HANDLE; | 87 handle_ = VK_NULL_HANDLE; |
86 } | 88 } |
87 } | 89 } |
88 | 90 |
89 } // namespace gpu | 91 } // namespace gpu |
OLD | NEW |