Flutter Engine
The Flutter Engine
VulkanImageView.cpp
Go to the documentation of this file.
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
9
14
15namespace skgpu::graphite {
16
17std::unique_ptr<const VulkanImageView> VulkanImageView::Make(
18 const VulkanSharedContext* sharedCtx,
19 VkImage image,
22 uint32_t miplevels,
23 sk_sp<VulkanYcbcrConversion> ycbcrConversion) {
24
25 void* pNext = nullptr;
26 VkSamplerYcbcrConversionInfo conversionInfo;
27 if (ycbcrConversion) {
29 conversionInfo.pNext = nullptr;
30 conversionInfo.conversion = ycbcrConversion->ycbcrConversion();
31 pNext = &conversionInfo;
32 }
33
34 VkImageView imageView;
35 // Create the VkImageView
36 VkImageAspectFlags aspectFlags;
38 switch (format) {
40 aspectFlags = VK_IMAGE_ASPECT_STENCIL_BIT;
41 break;
44 aspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
45 break;
49 break;
50 default:
51 aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
52 break;
53 }
54 // Attachments can only expose the top level MIP
55 miplevels = 1;
56 } else {
57 aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
58 }
59 VkImageViewCreateInfo viewInfo = {
61 pNext, // pNext
62 0, // flags
63 image, // image
64 VK_IMAGE_VIEW_TYPE_2D, // viewType
65 format, // format
69 VK_COMPONENT_SWIZZLE_IDENTITY }, // components
70 { aspectFlags, 0, miplevels, 0, 1 }, // subresourceRange
71 };
72
74 VULKAN_CALL_RESULT(sharedCtx,
75 result,
76 CreateImageView(sharedCtx->device(), &viewInfo, nullptr, &imageView));
77 if (result != VK_SUCCESS) {
78 return nullptr;
79 }
80
81 return std::unique_ptr<VulkanImageView>(new VulkanImageView(sharedCtx, imageView, usage,
82 ycbcrConversion));
83}
84
85VulkanImageView::VulkanImageView(const VulkanSharedContext* sharedContext,
86 VkImageView imageView,
88 sk_sp<VulkanYcbcrConversion> ycbcrConversion)
89 : fSharedContext(sharedContext)
90 , fImageView(imageView)
91 , fUsage(usage)
92 , fYcbcrConversion(std::move(ycbcrConversion)) {}
93
95 VULKAN_CALL(fSharedContext->interface(),
96 DestroyImageView(fSharedContext->device(), fImageView, nullptr));
97}
98
99} // namespace skgpu::graphite
#define VULKAN_CALL(IFACE, X)
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
static std::unique_ptr< const VulkanImageView > Make(const VulkanSharedContext *sharedContext, VkImage image, VkFormat format, Usage usage, uint32_t miplevels, sk_sp< VulkanYcbcrConversion >)
const skgpu::VulkanInterface * interface() const
GAsyncResult * result
uint32_t uint32_t * format
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Definition: ref_ptr.h:256
static void usage(char *argv0)
VkSamplerYcbcrConversion conversion
Definition: vulkan_core.h:5438
void Usage()
Definition: main.cc:42
VkFlags VkImageAspectFlags
Definition: vulkan_core.h:2256
@ VK_IMAGE_VIEW_TYPE_2D
Definition: vulkan_core.h:1831
@ VK_IMAGE_ASPECT_COLOR_BIT
Definition: vulkan_core.h:2238
@ VK_IMAGE_ASPECT_STENCIL_BIT
Definition: vulkan_core.h:2240
@ VK_IMAGE_ASPECT_DEPTH_BIT
Definition: vulkan_core.h:2239
@ VK_COMPONENT_SWIZZLE_IDENTITY
Definition: vulkan_core.h:1819
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
VkFormat
Definition: vulkan_core.h:1458
@ VK_FORMAT_D24_UNORM_S8_UINT
Definition: vulkan_core.h:1588
@ VK_FORMAT_D32_SFLOAT
Definition: vulkan_core.h:1585
@ VK_FORMAT_S8_UINT
Definition: vulkan_core.h:1586
@ VK_FORMAT_D16_UNORM
Definition: vulkan_core.h:1583
@ VK_FORMAT_D32_SFLOAT_S8_UINT
Definition: vulkan_core.h:1589
@ VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO
Definition: vulkan_core.h:293
@ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO
Definition: vulkan_core.h:217