| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrVkImageView.h" | 8 #include "GrVkImageView.h" |
| 9 #include "GrVkGpu.h" | 9 #include "GrVkGpu.h" |
| 10 #include "GrVkUtil.h" | 10 #include "GrVkUtil.h" |
| 11 | 11 |
| 12 const GrVkImageView* GrVkImageView::Create(GrVkGpu* gpu, VkImage image, VkFormat
format, | 12 const GrVkImageView* GrVkImageView::Create(const GrVkGpu* gpu, VkImage image, Vk
Format format, |
| 13 Type viewType) { | 13 Type viewType, uint32_t miplevels) { |
| 14 VkImageView imageView; | 14 VkImageView imageView; |
| 15 | 15 |
| 16 // Create the VkImageView | 16 // Create the VkImageView |
| 17 VkImageViewCreateInfo viewInfo = { | 17 VkImageViewCreateInfo viewInfo = { |
| 18 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType | 18 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType |
| 19 NULL, // pNext | 19 NULL, // pNext |
| 20 0, // flags | 20 0, // flags |
| 21 image, // image | 21 image, // image |
| 22 VK_IMAGE_VIEW_TYPE_2D, // viewType | 22 VK_IMAGE_VIEW_TYPE_2D, // viewType |
| 23 format, // format | 23 format, // format |
| 24 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, | 24 { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, |
| 25 VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A }, // components | 25 VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A }, // components |
| 26 { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 }, // subresourceRa
nge | 26 { VK_IMAGE_ASPECT_COLOR_BIT, 0, miplevels, 0, 1 }, // subresourceRa
nge |
| 27 }; | 27 }; |
| 28 if (kStencil_Type == viewType) { | 28 if (kStencil_Type == viewType) { |
| 29 viewInfo.components.r = VK_COMPONENT_SWIZZLE_ZERO; | 29 viewInfo.components.r = VK_COMPONENT_SWIZZLE_ZERO; |
| 30 viewInfo.components.g = VK_COMPONENT_SWIZZLE_ZERO; | 30 viewInfo.components.g = VK_COMPONENT_SWIZZLE_ZERO; |
| 31 viewInfo.components.b = VK_COMPONENT_SWIZZLE_ZERO; | 31 viewInfo.components.b = VK_COMPONENT_SWIZZLE_ZERO; |
| 32 viewInfo.components.a = VK_COMPONENT_SWIZZLE_ZERO; | 32 viewInfo.components.a = VK_COMPONENT_SWIZZLE_ZERO; |
| 33 viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; | 33 viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 34 } | 34 } |
| 35 | 35 |
| 36 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateImageView(gpu->device(),
&viewInfo, | 36 VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateImageView(gpu->device(),
&viewInfo, |
| 37 nullptr, &imag
eView)); | 37 nullptr, &imag
eView)); |
| 38 if (err) { | 38 if (err) { |
| 39 return nullptr; | 39 return nullptr; |
| 40 } | 40 } |
| 41 | 41 |
| 42 return new GrVkImageView(imageView); | 42 return new GrVkImageView(imageView); |
| 43 } | 43 } |
| 44 | 44 |
| 45 void GrVkImageView::freeGPUData(const GrVkGpu* gpu) const { | 45 void GrVkImageView::freeGPUData(const GrVkGpu* gpu) const { |
| 46 GR_VK_CALL(gpu->vkInterface(), DestroyImageView(gpu->device(), fImageView, n
ullptr)); | 46 GR_VK_CALL(gpu->vkInterface(), DestroyImageView(gpu->device(), fImageView, n
ullptr)); |
| 47 } | 47 } |
| OLD | NEW |