Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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,
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;
45 break;
46 default:
47 aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
48 break;
49 }
50 // Attachments can only expose the top level MIP
51 miplevels = 1;
52 } else {
53 aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
54 }
55 VkImageViewCreateInfo viewInfo = {
57 pNext, // pNext
58 0, // flags
59 image, // image
60 VK_IMAGE_VIEW_TYPE_2D, // viewType
61 format, // format
65 VK_COMPONENT_SWIZZLE_IDENTITY }, // components
66 { aspectFlags, 0, miplevels, 0, 1 }, // subresourceRange
67 };
68
70 VULKAN_CALL_RESULT(sharedCtx,
71 result,
72 CreateImageView(sharedCtx->device(), &viewInfo, nullptr, &imageView));
73 if (result != VK_SUCCESS) {
74 return nullptr;
75 }
76
77 return std::unique_ptr<VulkanImageView>(new VulkanImageView(sharedCtx, imageView, usage,
78 ycbcrConversion));
79}
80
81VulkanImageView::VulkanImageView(const VulkanSharedContext* sharedContext,
82 VkImageView imageView,
85 : fSharedContext(sharedContext)
86 , fImageView(imageView)
87 , fUsage(usage)
88 , fYcbcrConversion(std::move(samplerConversion)) {}
89
91 VULKAN_CALL(fSharedContext->interface(),
92 DestroyImageView(fSharedContext->device(), fImageView, nullptr));
93}
94
95} // 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< VulkanSamplerYcbcrConversion >)
const skgpu::VulkanInterface * interface() const
sk_sp< SkImage > image
Definition examples.cpp:29
GAsyncResult * result
uint32_t uint32_t * format
Definition ref_ptr.h:256
static void usage(char *argv0)
VkSamplerYcbcrConversion conversion
void Usage()
Definition main.cc:42
VkFlags VkImageAspectFlags
@ VK_IMAGE_VIEW_TYPE_2D
@ VK_IMAGE_ASPECT_COLOR_BIT
@ VK_IMAGE_ASPECT_STENCIL_BIT
@ VK_IMAGE_ASPECT_DEPTH_BIT
@ VK_COMPONENT_SWIZZLE_IDENTITY
VkResult
@ VK_SUCCESS
VkFormat
@ VK_FORMAT_D24_UNORM_S8_UINT
@ VK_FORMAT_S8_UINT
@ VK_FORMAT_D32_SFLOAT_S8_UINT
@ VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO
@ VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO