Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VulkanTypes.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC.
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#ifndef skgpu_VulkanTypes_DEFINED
9#define skgpu_VulkanTypes_DEFINED
10
13
14#include <cstddef>
15#include <functional>
16#include <string>
17#include <vector>
18
19#ifndef VK_VERSION_1_1
20#error Skia requires the use of Vulkan 1.1 headers
21#endif
22
23namespace skgpu {
24
25using VulkanGetProc = std::function<PFN_vkVoidFunction(
26 const char*, // function name
27 VkInstance, // instance or VK_NULL_HANDLE
28 VkDevice // device or VK_NULL_HANDLE
29 )>;
30
31typedef intptr_t VulkanBackendMemory;
32
33/**
34 * Types for interacting with Vulkan resources created externally to Skia.
35 */
37 // can be VK_NULL_HANDLE iff is an RT and is borrowed
38 VkDeviceMemory fMemory = VK_NULL_HANDLE;
40 VkDeviceSize fSize = 0; // this can be indeterminate iff Tex uses borrow semantics
41 uint32_t fFlags = 0;
42 // handle to memory allocated via skgpu::VulkanMemoryAllocator.
44
45 enum Flag {
46 kNoncoherent_Flag = 0x1, // memory must be flushed to device after mapping
47 kMappable_Flag = 0x2, // memory is able to be mapped.
48 kLazilyAllocated_Flag = 0x4, // memory was created with lazy allocation
49 };
50
51 bool operator==(const VulkanAlloc& that) const {
52 return fMemory == that.fMemory && fOffset == that.fOffset && fSize == that.fSize &&
53 fFlags == that.fFlags && fUsesSystemHeap == that.fUsesSystemHeap;
54 }
55
56private:
57 bool fUsesSystemHeap = false;
58};
59
60// Used to pass in the necessary information to create a VkSamplerYcbcrConversion object for an
61// VkExternalFormatANDROID.
63 bool operator==(const VulkanYcbcrConversionInfo& that) const {
64 // Invalid objects are not required to have all other fields initialized or matching.
65 if (!this->isValid() && !that.isValid()) {
66 return true;
67 }
68
69 // Note that we do not need to check for fFormatFeatures equality. This is because the
70 // Vulkan spec dictates that Android hardware buffers with the same external format must
71 // have the same support for key features. See
72 // https://docs.vulkan.org/spec/latest/chapters/memory.html#_android_hardware_buffer_external_memory
73 // for more details.
74 return this->fFormat == that.fFormat &&
75 this->fExternalFormat == that.fExternalFormat &&
76 this->fYcbcrModel == that.fYcbcrModel &&
77 this->fYcbcrRange == that.fYcbcrRange &&
78 this->fXChromaOffset == that.fXChromaOffset &&
79 this->fYChromaOffset == that.fYChromaOffset &&
80 this->fChromaFilter == that.fChromaFilter &&
82 this->fComponents.r == that.fComponents.r &&
83 this->fComponents.g == that.fComponents.g &&
84 this->fComponents.b == that.fComponents.b &&
85 this->fComponents.a == that.fComponents.a;
86 }
87 bool operator!=(const VulkanYcbcrConversionInfo& that) const { return !(*this == that); }
88
93
94 uint32_t nonFormatInfoAsUInt32() const {
95 static_assert(kComponentAShift + kComponentBits <= 32);
96
107
108 bool usesExternalFormat = fFormat == VK_FORMAT_UNDEFINED;
109
110 return ((static_cast<uint32_t>(usesExternalFormat ) << kUsesExternalFormatShift) |
111 (static_cast<uint32_t>(fYcbcrModel ) << kYcbcrModelShift ) |
112 (static_cast<uint32_t>(fYcbcrRange ) << kYcbcrRangeShift ) |
113 (static_cast<uint32_t>(fXChromaOffset ) << kXChromaOffsetShift ) |
114 (static_cast<uint32_t>(fYChromaOffset ) << kYChromaOffsetShift ) |
115 (static_cast<uint32_t>(fChromaFilter ) << kChromaFilterShift ) |
116 (static_cast<uint32_t>(fForceExplicitReconstruction) << kForceExplicitReconShift) |
117 (static_cast<uint32_t>(fComponents.r ) << kComponentRShift ) |
118 (static_cast<uint32_t>(fComponents.g ) << kComponentGShift ) |
119 (static_cast<uint32_t>(fComponents.b ) << kComponentBShift ) |
120 (static_cast<uint32_t>(fComponents.a ) << kComponentAShift ));
121 }
122
123 // Format of the source image. Must be set to VK_FORMAT_UNDEFINED for external images or
124 // a valid image format otherwise.
126
127 // The external format. Must be non-zero for external images, zero otherwise.
128 // Should be compatible to be used in a VkExternalFormatANDROID struct.
129 uint64_t fExternalFormat = 0;
130
137
138 // For external images format features here should be those returned by a call to
139 // vkAndroidHardwareBufferFormatPropertiesANDROID
141
142 // This is ignored when fExternalFormat is non-zero.
147
148 static constexpr int kUsesExternalFormatBits = 1;
149 static constexpr int kYcbcrModelBits = 3;
150 static constexpr int kYcbcrRangeBits = 1;
151 static constexpr int kXChromaOffsetBits = 1;
152 static constexpr int kYChromaOffsetBits = 1;
153 static constexpr int kChromaFilterBits = 1;
154 static constexpr int kForceExplicitReconBits = 1;
155 static constexpr int kComponentBits = 3;
156
157 static constexpr int kUsesExternalFormatShift = 0;
169};
170
173 const std::string& description,
174 const std::vector<VkDeviceFaultAddressInfoEXT>& addressInfos,
175 const std::vector<VkDeviceFaultVendorInfoEXT>& vendorInfos,
176 const std::vector<std::byte>& vendorBinaryData);
177
178} // namespace skgpu
179
180#endif // skgpu_VulkanTypes_DEFINED
#define SkASSERT(cond)
Definition SkAssert.h:116
intptr_t VulkanBackendMemory
Definition VulkanTypes.h:31
void * VulkanDeviceLostContext
std::function< PFN_vkVoidFunction(const char *, VkInstance, VkDevice)> VulkanGetProc
Definition VulkanTypes.h:29
void(* VulkanDeviceLostProc)(VulkanDeviceLostContext faultContext, const std::string &description, const std::vector< VkDeviceFaultAddressInfoEXT > &addressInfos, const std::vector< VkDeviceFaultVendorInfoEXT > &vendorInfos, const std::vector< std::byte > &vendorBinaryData)
VkComponentSwizzle r
VkComponentSwizzle a
VkComponentSwizzle g
VkComponentSwizzle b
bool operator==(const VulkanAlloc &that) const
Definition VulkanTypes.h:51
VkDeviceSize fSize
Definition VulkanTypes.h:40
VulkanBackendMemory fBackendMemory
Definition VulkanTypes.h:43
VkDeviceMemory fMemory
Definition VulkanTypes.h:38
VkDeviceSize fOffset
Definition VulkanTypes.h:39
static constexpr int kForceExplicitReconShift
static constexpr int kComponentBits
static constexpr int kYcbcrModelBits
static constexpr int kChromaFilterShift
static constexpr int kXChromaOffsetBits
static constexpr int kComponentAShift
static constexpr int kChromaFilterBits
static constexpr int kYcbcrModelShift
VkSamplerYcbcrRange fYcbcrRange
VkSamplerYcbcrModelConversion fYcbcrModel
static constexpr int kForceExplicitReconBits
static constexpr int kXChromaOffsetShift
static constexpr int kYChromaOffsetBits
static constexpr int kComponentRShift
static constexpr int kYcbcrRangeBits
uint32_t nonFormatInfoAsUInt32() const
Definition VulkanTypes.h:94
static constexpr int kUsesExternalFormatBits
static constexpr int kYcbcrRangeShift
static constexpr int kYChromaOffsetShift
bool operator==(const VulkanYcbcrConversionInfo &that) const
Definition VulkanTypes.h:63
bool operator!=(const VulkanYcbcrConversionInfo &that) const
Definition VulkanTypes.h:87
static constexpr int kComponentBShift
static constexpr int kUsesExternalFormatShift
static constexpr int kComponentGShift
VkFormatFeatureFlags fFormatFeatures
uint64_t VkDeviceSize
Definition vulkan_core.h:96
VkSamplerYcbcrModelConversion
@ VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY
VkChromaLocation
@ VK_CHROMA_LOCATION_COSITED_EVEN
@ VK_COMPONENT_SWIZZLE_IDENTITY
VkFlags VkFormatFeatureFlags
VkSamplerYcbcrRange
@ VK_SAMPLER_YCBCR_RANGE_ITU_FULL
VkFilter
@ VK_FILTER_NEAREST
void(VKAPI_PTR * PFN_vkVoidFunction)(void)
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
VkFormat
@ VK_FORMAT_UNDEFINED
uint32_t VkBool32
Definition vulkan_core.h:94