Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "GrVkImageView.h" |
| 9 | #include "GrVkGpu.h" |
| 10 | #include "GrVkUtil.h" |
| 11 | |
Greg Daniel | f4bf973 | 2018-12-03 14:34:28 +0000 | [diff] [blame] | 12 | const GrVkImageView* GrVkImageView::Create(const GrVkGpu* gpu, VkImage image, VkFormat format, |
| 13 | Type viewType, uint32_t miplevels) { |
Greg Daniel | 6cd7490 | 2018-11-29 13:30:08 -0500 | [diff] [blame] | 14 | VkImageView imageView; |
Greg Daniel | f4bf973 | 2018-12-03 14:34:28 +0000 | [diff] [blame] | 15 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 16 | // Create the VkImageView |
| 17 | VkImageViewCreateInfo viewInfo = { |
| 18 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType |
Greg Daniel | f4bf973 | 2018-12-03 14:34:28 +0000 | [diff] [blame] | 19 | NULL, // pNext |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 20 | 0, // flags |
| 21 | image, // image |
| 22 | VK_IMAGE_VIEW_TYPE_2D, // viewType |
| 23 | format, // format |
egdaniel | e7f2fe4 | 2016-07-01 08:03:02 -0700 | [diff] [blame] | 24 | { VK_COMPONENT_SWIZZLE_IDENTITY, |
| 25 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 26 | VK_COMPONENT_SWIZZLE_IDENTITY, |
| 27 | VK_COMPONENT_SWIZZLE_IDENTITY }, // components |
jvanverth | 6234006 | 2016-04-26 08:01:44 -0700 | [diff] [blame] | 28 | { VK_IMAGE_ASPECT_COLOR_BIT, 0, miplevels, 0, 1 }, // subresourceRange |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 29 | }; |
| 30 | if (kStencil_Type == viewType) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 31 | viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; |
| 32 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 33 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 34 | VkResult err = GR_VK_CALL(gpu->vkInterface(), CreateImageView(gpu->device(), &viewInfo, |
| 35 | nullptr, &imageView)); |
| 36 | if (err) { |
| 37 | return nullptr; |
| 38 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 39 | |
Greg Daniel | f4bf973 | 2018-12-03 14:34:28 +0000 | [diff] [blame] | 40 | return new GrVkImageView(imageView); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void GrVkImageView::freeGPUData(const GrVkGpu* gpu) const { |
| 44 | GR_VK_CALL(gpu->vkInterface(), DestroyImageView(gpu->device(), fImageView, nullptr)); |
| 45 | } |