/src/skia/src/gpu/graphite/vk/VulkanImageView.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2023 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/graphite/vk/VulkanImageView.h" |
9 | | |
10 | | #include "src/gpu/graphite/vk/VulkanGraphiteUtilsPriv.h" |
11 | | #include "src/gpu/graphite/vk/VulkanResourceProvider.h" |
12 | | #include "src/gpu/graphite/vk/VulkanSamplerYcbcrConversion.h" |
13 | | #include "src/gpu/graphite/vk/VulkanSharedContext.h" |
14 | | |
15 | | namespace skgpu::graphite { |
16 | | |
17 | | std::unique_ptr<const VulkanImageView> VulkanImageView::Make( |
18 | | const VulkanSharedContext* sharedCtx, |
19 | | VkImage image, |
20 | | VkFormat format, |
21 | | Usage usage, |
22 | | uint32_t miplevels, |
23 | 0 | sk_sp<VulkanSamplerYcbcrConversion> ycbcrConversion) { |
24 | |
|
25 | 0 | void* pNext = nullptr; |
26 | 0 | VkSamplerYcbcrConversionInfo conversionInfo; |
27 | 0 | if (ycbcrConversion) { |
28 | 0 | conversionInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO; |
29 | 0 | conversionInfo.pNext = nullptr; |
30 | 0 | conversionInfo.conversion = ycbcrConversion->ycbcrConversion(); |
31 | 0 | pNext = &conversionInfo; |
32 | 0 | } |
33 | |
|
34 | 0 | VkImageView imageView; |
35 | | // Create the VkImageView |
36 | 0 | VkImageAspectFlags aspectFlags; |
37 | 0 | if (Usage::kAttachment == usage) { |
38 | 0 | switch (format) { |
39 | 0 | case VK_FORMAT_S8_UINT: |
40 | 0 | aspectFlags = VK_IMAGE_ASPECT_STENCIL_BIT; |
41 | 0 | break; |
42 | 0 | case VK_FORMAT_D24_UNORM_S8_UINT: |
43 | 0 | case VK_FORMAT_D32_SFLOAT_S8_UINT: |
44 | 0 | aspectFlags = VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_DEPTH_BIT; |
45 | 0 | break; |
46 | 0 | default: |
47 | 0 | aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT; |
48 | 0 | break; |
49 | 0 | } |
50 | | // Attachments can only expose the top level MIP |
51 | 0 | miplevels = 1; |
52 | 0 | } else { |
53 | 0 | aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT; |
54 | 0 | } |
55 | 0 | VkImageViewCreateInfo viewInfo = { |
56 | 0 | VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // sType |
57 | 0 | pNext, // pNext |
58 | 0 | 0, // flags |
59 | 0 | image, // image |
60 | 0 | VK_IMAGE_VIEW_TYPE_2D, // viewType |
61 | 0 | format, // format |
62 | 0 | { VK_COMPONENT_SWIZZLE_IDENTITY, |
63 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY, |
64 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY, |
65 | 0 | VK_COMPONENT_SWIZZLE_IDENTITY }, // components |
66 | 0 | { aspectFlags, 0, miplevels, 0, 1 }, // subresourceRange |
67 | 0 | }; |
68 | |
|
69 | 0 | VkResult result; |
70 | 0 | VULKAN_CALL_RESULT(sharedCtx, |
71 | 0 | result, |
72 | 0 | CreateImageView(sharedCtx->device(), &viewInfo, nullptr, &imageView)); |
73 | 0 | if (result != VK_SUCCESS) { |
74 | 0 | return nullptr; |
75 | 0 | } |
76 | | |
77 | 0 | return std::unique_ptr<VulkanImageView>(new VulkanImageView(sharedCtx, imageView, usage, |
78 | 0 | ycbcrConversion)); |
79 | 0 | } Unexecuted instantiation: skgpu::graphite::VulkanImageView::Make(skgpu::graphite::VulkanSharedContext const*, VkImage_T*, VkFormat, skgpu::graphite::VulkanImageView::Usage, unsigned int, sk_sp<skgpu::graphite::VulkanSamplerYcbcrConversion>) Unexecuted instantiation: skgpu::graphite::VulkanImageView::Make(skgpu::graphite::VulkanSharedContext const*, VkImage_T*, VkFormat, skgpu::graphite::VulkanImageView::Usage, unsigned int, sk_sp<skgpu::graphite::VulkanSamplerYcbcrConversion>) |
80 | | |
81 | | VulkanImageView::VulkanImageView(const VulkanSharedContext* sharedContext, |
82 | | VkImageView imageView, |
83 | | Usage usage, |
84 | | sk_sp<VulkanSamplerYcbcrConversion> samplerConversion) |
85 | | : fSharedContext(sharedContext) |
86 | | , fImageView(imageView) |
87 | | , fUsage(usage) |
88 | 0 | , fYcbcrConversion(std::move(samplerConversion)) {} |
89 | | |
90 | 0 | VulkanImageView::~VulkanImageView() { |
91 | 0 | VULKAN_CALL(fSharedContext->interface(), |
92 | 0 | DestroyImageView(fSharedContext->device(), fImageView, nullptr)); |
93 | 0 | } |
94 | | |
95 | | } // namespace skgpu::graphite |