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