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 #include "src/gpu/ganesh/vk/GrVkImageView.h"
8
9 #include "include/gpu/vk/VulkanTypes.h"
10 #include "include/private/base/SkAssert.h"
11 #include "src/gpu/ganesh/vk/GrVkCaps.h"
12 #include "src/gpu/ganesh/vk/GrVkGpu.h"
13 #include "src/gpu/ganesh/vk/GrVkResourceProvider.h"
14 #include "src/gpu/ganesh/vk/GrVkSamplerYcbcrConversion.h"
15 #include "src/gpu/ganesh/vk/GrVkUtil.h"
16
Make(GrVkGpu * gpu,VkImage image,VkFormat format,Type viewType,uint32_t miplevels,const skgpu::VulkanYcbcrConversionInfo & ycbcrInfo)17 sk_sp<const GrVkImageView> GrVkImageView::Make(GrVkGpu* gpu,
18 VkImage image,
19 VkFormat format,
20 Type viewType,
21 uint32_t miplevels,
22 const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo) {
23 void* pNext = nullptr;
24 VkSamplerYcbcrConversionInfo conversionInfo;
25 GrVkSamplerYcbcrConversion* ycbcrConversion = nullptr;
26
27 if (ycbcrInfo.isValid()) {
28 SkASSERT(gpu->vkCaps().supportsYcbcrConversion() && format == ycbcrInfo.fFormat);
29
30 ycbcrConversion =
31 gpu->resourceProvider().findOrCreateCompatibleSamplerYcbcrConversion(ycbcrInfo);
32 if (!ycbcrConversion) {
33 return nullptr;
34 }
35
36 conversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO;
37 conversionInfo.pNext = nullptr;
38 conversionInfo.conversion = ycbcrConversion->ycbcrConversion();
39 pNext = &conversionInfo;
40 }
41
42 VkImageView imageView;
43 // Create the VkImageView
44 VkImageViewCreateInfo viewInfo = {
45 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType
46 pNext, // pNext
47 0, // flags
48 image, // image
49 VK_IMAGE_VIEW_TYPE_2D, // viewType
50 format, // format
51 { VK_COMPONENT_SWIZZLE_IDENTITY,
52 VK_COMPONENT_SWIZZLE_IDENTITY,
53 VK_COMPONENT_SWIZZLE_IDENTITY,
54 VK_COMPONENT_SWIZZLE_IDENTITY }, // components
55 { VK_IMAGE_ASPECT_COLOR_BIT, 0, miplevels, 0, 1 }, // subresourceRange
56 };
57 if (kStencil_Type == viewType) {
58 viewInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT;
59 }
60
61 VkResult err;
62 GR_VK_CALL_RESULT(gpu, err, CreateImageView(gpu->device(), &viewInfo, nullptr, &imageView));
63 if (err) {
64 return nullptr;
65 }
66
67 return sk_sp<const GrVkImageView>(new GrVkImageView(gpu, imageView, ycbcrConversion));
68 }
69
freeGPUData() const70 void GrVkImageView::freeGPUData() const {
71 GR_VK_CALL(fGpu->vkInterface(), DestroyImageView(fGpu->device(), fImageView, nullptr));
72
73 if (fYcbcrConversion) {
74 fYcbcrConversion->unref();
75 }
76 }
77
78