| Flutter Impeller |

formats_vk.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FORMATS_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FORMATS_VK_H_
7
8 #include <cstdint>
9 #include <ostream>
10
11 #include "fml/logging.h"
12 #include "impeller/base/validation.h"
13 #include "impeller/core/formats.h"
14 #include "impeller/core/shader_types.h"
15 #include "impeller/renderer/backend/vulkan/vk.h"
16 #include "vulkan/vulkan_enums.hpp"
17
18 namespace impeller {
19
20 constexpr std::optional<PixelFormat> VkFormatToImpellerFormat(
21 vk::Format format) {
22 switch (format) {
23 case vk::Format::eR8G8B8A8Unorm:
24 return PixelFormat::kR8G8B8A8UNormInt;
25 case vk::Format::eB8G8R8A8Unorm:
26 return PixelFormat::kB8G8R8A8UNormInt;
27 default:
28 return std::nullopt;
29 }
30 }
31
32 constexpr vk::SampleCountFlagBits ToVKSampleCountFlagBits(SampleCount count) {
33 switch (count) {
34 case SampleCount::kCount1:
35 return vk::SampleCountFlagBits::e1;
36 case SampleCount::kCount4:
37 return vk::SampleCountFlagBits::e4;
38 }
39 FML_UNREACHABLE();
40 }
41
42 constexpr vk::BlendFactor ToVKBlendFactor(BlendFactor factor) {
43 switch (factor) {
44 case BlendFactor::kZero:
45 return vk::BlendFactor::eZero;
46 case BlendFactor::kOne:
47 return vk::BlendFactor::eOne;
48 case BlendFactor::kSourceColor:
49 return vk::BlendFactor::eSrcColor;
50 case BlendFactor::kOneMinusSourceColor:
51 return vk::BlendFactor::eOneMinusSrcColor;
52 case BlendFactor::kSourceAlpha:
53 return vk::BlendFactor::eSrcAlpha;
54 case BlendFactor::kOneMinusSourceAlpha:
55 return vk::BlendFactor::eOneMinusSrcAlpha;
56 case BlendFactor::kDestinationColor:
57 return vk::BlendFactor::eDstColor;
58 case BlendFactor::kOneMinusDestinationColor:
59 return vk::BlendFactor::eOneMinusDstColor;
60 case BlendFactor::kDestinationAlpha:
61 return vk::BlendFactor::eDstAlpha;
62 case BlendFactor::kOneMinusDestinationAlpha:
63 return vk::BlendFactor::eOneMinusDstAlpha;
64 case BlendFactor::kSourceAlphaSaturated:
65 return vk::BlendFactor::eSrcAlphaSaturate;
66 case BlendFactor::kBlendColor:
67 return vk::BlendFactor::eConstantColor;
68 case BlendFactor::kOneMinusBlendColor:
69 return vk::BlendFactor::eOneMinusConstantColor;
70 case BlendFactor::kBlendAlpha:
71 return vk::BlendFactor::eConstantAlpha;
72 case BlendFactor::kOneMinusBlendAlpha:
73 return vk::BlendFactor::eOneMinusConstantAlpha;
74 }
75 FML_UNREACHABLE();
76 }
77
78 constexpr vk::BlendOp ToVKBlendOp(BlendOperation op) {
79 switch (op) {
80 case BlendOperation::kAdd:
81 return vk::BlendOp::eAdd;
82 case BlendOperation::kSubtract:
83 return vk::BlendOp::eSubtract;
84 case BlendOperation::kReverseSubtract:
85 return vk::BlendOp::eReverseSubtract;
86 }
87 FML_UNREACHABLE();
88 }
89
90 constexpr vk::ColorComponentFlags ToVKColorComponentFlags(ColorWriteMask type) {
91 vk::ColorComponentFlags mask;
92
93 if (type & ColorWriteMaskBits::kRed) {
94 mask |= vk::ColorComponentFlagBits::eR;
95 }
96
97 if (type & ColorWriteMaskBits::kGreen) {
98 mask |= vk::ColorComponentFlagBits::eG;
99 }
100
101 if (type & ColorWriteMaskBits::kBlue) {
102 mask |= vk::ColorComponentFlagBits::eB;
103 }
104
105 if (type & ColorWriteMaskBits::kAlpha) {
106 mask |= vk::ColorComponentFlagBits::eA;
107 }
108
109 return mask;
110 }
111
112 constexpr vk::PipelineColorBlendAttachmentState
113 ToVKPipelineColorBlendAttachmentState(const ColorAttachmentDescriptor& desc) {
114 vk::PipelineColorBlendAttachmentState res;
115
116 res.setBlendEnable(desc.blending_enabled);
117
118 res.setSrcColorBlendFactor(ToVKBlendFactor(desc.src_color_blend_factor));
119 res.setColorBlendOp(ToVKBlendOp(desc.color_blend_op));
120 res.setDstColorBlendFactor(ToVKBlendFactor(desc.dst_color_blend_factor));
121
122 res.setSrcAlphaBlendFactor(ToVKBlendFactor(desc.src_alpha_blend_factor));
123 res.setAlphaBlendOp(ToVKBlendOp(desc.alpha_blend_op));
124 res.setDstAlphaBlendFactor(ToVKBlendFactor(desc.dst_alpha_blend_factor));
125
126 res.setColorWriteMask(ToVKColorComponentFlags(desc.write_mask));
127
128 return res;
129 }
130
131 constexpr std::optional<vk::ShaderStageFlagBits> ToVKShaderStageFlagBits(
132 ShaderStage stage) {
133 switch (stage) {
134 case ShaderStage::kUnknown:
135 return std::nullopt;
136 case ShaderStage::kVertex:
137 return vk::ShaderStageFlagBits::eVertex;
138 case ShaderStage::kFragment:
139 return vk::ShaderStageFlagBits::eFragment;
140 case ShaderStage::kCompute:
141 return vk::ShaderStageFlagBits::eCompute;
142 }
143 FML_UNREACHABLE();
144 }
145
146 constexpr vk::Format ToVKImageFormat(PixelFormat format) {
147 switch (format) {
148 case PixelFormat::kUnknown:
149 case PixelFormat::kB10G10R10XR:
150 case PixelFormat::kB10G10R10A10XR:
151 case PixelFormat::kB10G10R10XRSRGB:
152 return vk::Format::eUndefined;
153 case PixelFormat::kA8UNormInt:
154 // TODO(csg): This is incorrect. Don't depend on swizzle support for GLES.
155 return vk::Format::eR8Unorm;
156 case PixelFormat::kR8G8B8A8UNormInt:
157 return vk::Format::eR8G8B8A8Unorm;
158 case PixelFormat::kR8G8B8A8UNormIntSRGB:
159 return vk::Format::eR8G8B8A8Srgb;
160 case PixelFormat::kB8G8R8A8UNormInt:
161 return vk::Format::eB8G8R8A8Unorm;
162 case PixelFormat::kB8G8R8A8UNormIntSRGB:
163 return vk::Format::eB8G8R8A8Srgb;
164 case PixelFormat::kR32G32B32A32Float:
165 return vk::Format::eR32G32B32A32Sfloat;
166 case PixelFormat::kR16G16B16A16Float:
167 return vk::Format::eR16G16B16A16Sfloat;
168 case PixelFormat::kS8UInt:
169 return vk::Format::eS8Uint;
170 case PixelFormat::kD24UnormS8Uint:
171 return vk::Format::eD24UnormS8Uint;
172 case PixelFormat::kD32FloatS8UInt:
173 return vk::Format::eD32SfloatS8Uint;
174 case PixelFormat::kR8UNormInt:
175 return vk::Format::eR8Unorm;
176 case PixelFormat::kR8G8UNormInt:
177 return vk::Format::eR8G8Unorm;
178 }
179
180 FML_UNREACHABLE();
181 }
182
183 constexpr PixelFormat ToPixelFormat(vk::Format format) {
184 switch (format) {
185 case vk::Format::eUndefined:
186 return PixelFormat::kUnknown;
187 case vk::Format::eR8G8B8A8Unorm:
188 return PixelFormat::kR8G8B8A8UNormInt;
189 case vk::Format::eR8G8B8A8Srgb:
190 return PixelFormat::kR8G8B8A8UNormIntSRGB;
191 case vk::Format::eB8G8R8A8Unorm:
192 return PixelFormat::kB8G8R8A8UNormInt;
193 case vk::Format::eB8G8R8A8Srgb:
194 return PixelFormat::kB8G8R8A8UNormIntSRGB;
195 case vk::Format::eR32G32B32A32Sfloat:
196 return PixelFormat::kR32G32B32A32Float;
197 case vk::Format::eR16G16B16A16Sfloat:
198 return PixelFormat::kR16G16B16A16Float;
199 case vk::Format::eS8Uint:
200 return PixelFormat::kS8UInt;
201 case vk::Format::eD24UnormS8Uint:
202 return PixelFormat::kD24UnormS8Uint;
203 case vk::Format::eD32SfloatS8Uint:
204 return PixelFormat::kD32FloatS8UInt;
205 case vk::Format::eR8Unorm:
206 return PixelFormat::kR8UNormInt;
207 case vk::Format::eR8G8Unorm:
208 return PixelFormat::kR8G8UNormInt;
209 default:
210 return PixelFormat::kUnknown;
211 }
212 }
213
214 constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count) {
215 switch (sample_count) {
216 case SampleCount::kCount1:
217 return vk::SampleCountFlagBits::e1;
218 case SampleCount::kCount4:
219 return vk::SampleCountFlagBits::e4;
220 }
221
222 FML_UNREACHABLE();
223 }
224
225 constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter) {
226 switch (filter) {
227 case MinMagFilter::kNearest:
228 return vk::Filter::eNearest;
229 case MinMagFilter::kLinear:
230 return vk::Filter::eLinear;
231 }
232
233 FML_UNREACHABLE();
234 }
235
236 constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter) {
237 switch (filter) {
238 case MipFilter::kBase:
239 case MipFilter::kNearest:
240 return vk::SamplerMipmapMode::eNearest;
241 case MipFilter::kLinear:
242 return vk::SamplerMipmapMode::eLinear;
243 }
244
245 FML_UNREACHABLE();
246 }
247
248 constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(
249 SamplerAddressMode mode) {
250 switch (mode) {
251 case SamplerAddressMode::kRepeat:
252 return vk::SamplerAddressMode::eRepeat;
253 case SamplerAddressMode::kMirror:
254 return vk::SamplerAddressMode::eMirroredRepeat;
255 case SamplerAddressMode::kClampToEdge:
256 return vk::SamplerAddressMode::eClampToEdge;
257 case SamplerAddressMode::kDecal:
258 return vk::SamplerAddressMode::eClampToBorder;
259 }
260
261 FML_UNREACHABLE();
262 }
263
264 constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage) {
265 switch (stage) {
266 case ShaderStage::kUnknown:
267 return vk::ShaderStageFlagBits::eAll;
268 case ShaderStage::kFragment:
269 return vk::ShaderStageFlagBits::eFragment;
270 case ShaderStage::kCompute:
271 return vk::ShaderStageFlagBits::eCompute;
272 case ShaderStage::kVertex:
273 return vk::ShaderStageFlagBits::eVertex;
274 }
275
276 FML_UNREACHABLE();
277 }
278
279 static_assert(static_cast<int>(DescriptorType::kSampledImage) ==
280 static_cast<int>(vk::DescriptorType::eCombinedImageSampler));
281 static_assert(static_cast<int>(DescriptorType::kUniformBuffer) ==
282 static_cast<int>(vk::DescriptorType::eUniformBuffer));
283 static_assert(static_cast<int>(DescriptorType::kStorageBuffer) ==
284 static_cast<int>(vk::DescriptorType::eStorageBuffer));
285 static_assert(static_cast<int>(DescriptorType::kImage) ==
286 static_cast<int>(vk::DescriptorType::eSampledImage));
287 static_assert(static_cast<int>(DescriptorType::kSampler) ==
288 static_cast<int>(vk::DescriptorType::eSampler));
289 static_assert(static_cast<int>(DescriptorType::kInputAttachment) ==
290 static_cast<int>(vk::DescriptorType::eInputAttachment));
291
292 constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) {
293 return static_cast<vk::DescriptorType>(type);
294 }
295
296 constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(
297 const DescriptorSetLayout& layout) {
298 vk::DescriptorSetLayoutBinding binding;
299 binding.binding = layout.binding;
300 binding.descriptorCount = 1u;
301 binding.descriptorType = ToVKDescriptorType(layout.descriptor_type);
302 binding.stageFlags = ToVkShaderStage(layout.shader_stage);
303 return binding;
304 }
305
306 constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action) {
307 switch (load_action) {
308 case LoadAction::kLoad:
309 return vk::AttachmentLoadOp::eLoad;
310 case LoadAction::kClear:
311 return vk::AttachmentLoadOp::eClear;
312 case LoadAction::kDontCare:
313 return vk::AttachmentLoadOp::eDontCare;
314 }
315
316 FML_UNREACHABLE();
317 }
318
319 constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action,
320 bool is_resolve_texture) {
321 switch (store_action) {
322 case StoreAction::kStore:
323 // Both MSAA and resolve textures need to be stored. A resolve is NOT
324 // performed.
325 return vk::AttachmentStoreOp::eStore;
326 case StoreAction::kDontCare:
327 // Both MSAA and resolve textures can be discarded. A resolve is NOT
328 // performed.
329 return vk::AttachmentStoreOp::eDontCare;
330 case StoreAction::kMultisampleResolve:
331 // The resolve texture is stored but the MSAA texture can be discarded. A
332 // resolve IS performed.
333 return is_resolve_texture ? vk::AttachmentStoreOp::eStore
334 : vk::AttachmentStoreOp::eDontCare;
335 case StoreAction::kStoreAndMultisampleResolve:
336 // Both MSAA and resolve textures need to be stored. A resolve IS
337 // performed.
338 return vk::AttachmentStoreOp::eStore;
339 }
340 FML_UNREACHABLE();
341 }
342
343 constexpr bool StoreActionPerformsResolve(StoreAction store_action) {
344 switch (store_action) {
345 case StoreAction::kDontCare:
346 case StoreAction::kStore:
347 return false;
348 case StoreAction::kMultisampleResolve:
349 case StoreAction::kStoreAndMultisampleResolve:
350 return true;
351 }
352 FML_UNREACHABLE();
353 }
354
355 constexpr vk::IndexType ToVKIndexType(IndexType index_type) {
356 switch (index_type) {
357 case IndexType::k16bit:
358 return vk::IndexType::eUint16;
359 case IndexType::k32bit:
360 return vk::IndexType::eUint32;
361 case IndexType::kUnknown:
362 return vk::IndexType::eUint32;
363 case IndexType::kNone:
364 FML_UNREACHABLE();
365 }
366
367 FML_UNREACHABLE();
368 }
369
370 constexpr vk::PolygonMode ToVKPolygonMode(PolygonMode mode) {
371 switch (mode) {
372 case PolygonMode::kFill:
373 return vk::PolygonMode::eFill;
374 case PolygonMode::kLine:
375 return vk::PolygonMode::eLine;
376 }
377 FML_UNREACHABLE();
378 }
379
380 constexpr bool PrimitiveTopologySupportsPrimitiveRestart(
381 PrimitiveType primitive) {
382 switch (primitive) {
383 case PrimitiveType::kTriangleStrip:
384 case PrimitiveType::kLine:
385 case PrimitiveType::kPoint:
386 case PrimitiveType::kTriangleFan:
387 return true;
388 case PrimitiveType::kTriangle:
389 case PrimitiveType::kLineStrip:
390 return false;
391 }
392 FML_UNREACHABLE();
393 }
394
395 constexpr vk::PrimitiveTopology ToVKPrimitiveTopology(PrimitiveType primitive) {
396 switch (primitive) {
397 case PrimitiveType::kTriangle:
398 return vk::PrimitiveTopology::eTriangleList;
399 case PrimitiveType::kTriangleStrip:
400 return vk::PrimitiveTopology::eTriangleStrip;
401 case PrimitiveType::kLine:
402 return vk::PrimitiveTopology::eLineList;
403 case PrimitiveType::kLineStrip:
404 return vk::PrimitiveTopology::eLineStrip;
405 case PrimitiveType::kPoint:
406 return vk::PrimitiveTopology::ePointList;
407 case PrimitiveType::kTriangleFan:
408 return vk::PrimitiveTopology::eTriangleFan;
409 }
410
411 FML_UNREACHABLE();
412 }
413
414 constexpr bool PixelFormatIsDepthStencil(PixelFormat format) {
415 switch (format) {
416 case PixelFormat::kUnknown:
417 case PixelFormat::kA8UNormInt:
418 case PixelFormat::kR8UNormInt:
419 case PixelFormat::kR8G8UNormInt:
420 case PixelFormat::kR8G8B8A8UNormInt:
421 case PixelFormat::kR8G8B8A8UNormIntSRGB:
422 case PixelFormat::kB8G8R8A8UNormInt:
423 case PixelFormat::kB8G8R8A8UNormIntSRGB:
424 case PixelFormat::kR32G32B32A32Float:
425 case PixelFormat::kR16G16B16A16Float:
426 case PixelFormat::kB10G10R10XR:
427 case PixelFormat::kB10G10R10XRSRGB:
428 case PixelFormat::kB10G10R10A10XR:
429 return false;
430 case PixelFormat::kS8UInt:
431 case PixelFormat::kD24UnormS8Uint:
432 case PixelFormat::kD32FloatS8UInt:
433 return true;
434 }
435 return false;
436 }
437
438 static constexpr vk::AttachmentReference kUnusedAttachmentReference = {
439 VK_ATTACHMENT_UNUSED, vk::ImageLayout::eUndefined};
440
441 constexpr vk::CullModeFlags ToVKCullModeFlags(CullMode mode) {
442 switch (mode) {
443 case CullMode::kNone:
444 return vk::CullModeFlagBits::eNone;
445 case CullMode::kFrontFace:
446 return vk::CullModeFlagBits::eFront;
447 case CullMode::kBackFace:
448 return vk::CullModeFlagBits::eBack;
449 }
450 FML_UNREACHABLE();
451 }
452
453 constexpr vk::CompareOp ToVKCompareOp(CompareFunction op) {
454 switch (op) {
455 case CompareFunction::kNever:
456 return vk::CompareOp::eNever;
457 case CompareFunction::kAlways:
458 return vk::CompareOp::eAlways;
459 case CompareFunction::kLess:
460 return vk::CompareOp::eLess;
461 case CompareFunction::kEqual:
462 return vk::CompareOp::eEqual;
463 case CompareFunction::kLessEqual:
464 return vk::CompareOp::eLessOrEqual;
465 case CompareFunction::kGreater:
466 return vk::CompareOp::eGreater;
467 case CompareFunction::kNotEqual:
468 return vk::CompareOp::eNotEqual;
469 case CompareFunction::kGreaterEqual:
470 return vk::CompareOp::eGreaterOrEqual;
471 }
472 FML_UNREACHABLE();
473 }
474
475 constexpr vk::StencilOp ToVKStencilOp(StencilOperation op) {
476 switch (op) {
477 case StencilOperation::kKeep:
478 return vk::StencilOp::eKeep;
479 case StencilOperation::kZero:
480 return vk::StencilOp::eZero;
481 case StencilOperation::kSetToReferenceValue:
482 return vk::StencilOp::eReplace;
483 case StencilOperation::kIncrementClamp:
484 return vk::StencilOp::eIncrementAndClamp;
485 case StencilOperation::kDecrementClamp:
486 return vk::StencilOp::eDecrementAndClamp;
487 case StencilOperation::kInvert:
488 return vk::StencilOp::eInvert;
489 case StencilOperation::kIncrementWrap:
490 return vk::StencilOp::eIncrementAndWrap;
491 case StencilOperation::kDecrementWrap:
492 return vk::StencilOp::eDecrementAndWrap;
493 break;
494 }
495 FML_UNREACHABLE();
496 }
497
498 constexpr vk::StencilOpState ToVKStencilOpState(
499 const StencilAttachmentDescriptor& desc) {
500 vk::StencilOpState state;
501 state.failOp = ToVKStencilOp(desc.stencil_failure);
502 state.passOp = ToVKStencilOp(desc.depth_stencil_pass);
503 state.depthFailOp = ToVKStencilOp(desc.depth_failure);
504 state.compareOp = ToVKCompareOp(desc.stencil_compare);
505 state.compareMask = desc.read_mask;
506 state.writeMask = desc.write_mask;
507 // This is irrelevant as the stencil references are always dynamic state and
508 // will be set in the render pass.
509 state.reference = 1988;
510 return state;
511 }
512
513 constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format) {
514 switch (format) {
515 case PixelFormat::kUnknown:
516 case PixelFormat::kA8UNormInt:
517 case PixelFormat::kR8UNormInt:
518 case PixelFormat::kR8G8UNormInt:
519 case PixelFormat::kR8G8B8A8UNormInt:
520 case PixelFormat::kR8G8B8A8UNormIntSRGB:
521 case PixelFormat::kB8G8R8A8UNormInt:
522 case PixelFormat::kB8G8R8A8UNormIntSRGB:
523 case PixelFormat::kR32G32B32A32Float:
524 case PixelFormat::kR16G16B16A16Float:
525 case PixelFormat::kB10G10R10XR:
526 case PixelFormat::kB10G10R10XRSRGB:
527 case PixelFormat::kB10G10R10A10XR:
528 return vk::ImageAspectFlagBits::eColor;
529 case PixelFormat::kS8UInt:
530 return vk::ImageAspectFlagBits::eStencil;
531 case PixelFormat::kD24UnormS8Uint:
532 case PixelFormat::kD32FloatS8UInt:
533 return vk::ImageAspectFlagBits::eDepth |
534 vk::ImageAspectFlagBits::eStencil;
535 }
536 FML_UNREACHABLE();
537 }
538
539 constexpr uint32_t ToArrayLayerCount(TextureType type) {
540 switch (type) {
541 case TextureType::kTexture2D:
542 case TextureType::kTexture2DMultisample:
543 return 1u;
544 case TextureType::kTextureCube:
545 return 6u;
546 case TextureType::kTextureExternalOES:
547 VALIDATION_LOG
548 << "kTextureExternalOES can not be used with the Vulkan backend.";
549 }
550 FML_UNREACHABLE();
551 }
552
553 constexpr vk::ImageViewType ToVKImageViewType(TextureType type) {
554 switch (type) {
555 case TextureType::kTexture2D:
556 case TextureType::kTexture2DMultisample:
557 return vk::ImageViewType::e2D;
558 case TextureType::kTextureCube:
559 return vk::ImageViewType::eCube;
560 case TextureType::kTextureExternalOES:
561 VALIDATION_LOG
562 << "kTextureExternalOES can not be used with the Vulkan backend.";
563 }
564 FML_UNREACHABLE();
565 }
566
567 constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type) {
568 switch (type) {
569 case TextureType::kTexture2D:
570 case TextureType::kTexture2DMultisample:
571 return {};
572 case TextureType::kTextureCube:
573 return vk::ImageCreateFlagBits::eCubeCompatible;
574 case TextureType::kTextureExternalOES:
575 VALIDATION_LOG
576 << "kTextureExternalOES can not be used with the Vulkan backend.";
577 }
578 FML_UNREACHABLE();
579 }
580
581 vk::PipelineDepthStencilStateCreateInfo ToVKPipelineDepthStencilStateCreateInfo(
582 std::optional<DepthAttachmentDescriptor> depth,
583 std::optional<StencilAttachmentDescriptor> front,
584 std::optional<StencilAttachmentDescriptor> back);
585
586 constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format) {
587 switch (format) {
588 case PixelFormat::kUnknown:
589 return {};
590 case PixelFormat::kA8UNormInt:
591 case PixelFormat::kR8UNormInt:
592 case PixelFormat::kR8G8UNormInt:
593 case PixelFormat::kR8G8B8A8UNormInt:
594 case PixelFormat::kR8G8B8A8UNormIntSRGB:
595 case PixelFormat::kB8G8R8A8UNormInt:
596 case PixelFormat::kB8G8R8A8UNormIntSRGB:
597 case PixelFormat::kR32G32B32A32Float:
598 case PixelFormat::kR16G16B16A16Float:
599 case PixelFormat::kB10G10R10XR:
600 case PixelFormat::kB10G10R10XRSRGB:
601 case PixelFormat::kB10G10R10A10XR:
602 return vk::ImageAspectFlagBits::eColor;
603 case PixelFormat::kS8UInt:
604 return vk::ImageAspectFlagBits::eStencil;
605 case PixelFormat::kD24UnormS8Uint:
606 case PixelFormat::kD32FloatS8UInt:
607 return vk::ImageAspectFlagBits::eDepth |
608 vk::ImageAspectFlagBits::eStencil;
609 }
610 FML_UNREACHABLE();
611 }
612
613 } // namespace impeller
614
615 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FORMATS_VK_H_
type
GLenum type
Definition: blit_command_gles.cc:153
formats.h
e1
Vector3 e1
Definition: line_contents.cc:107
impeller
Definition: allocation.cc:12
impeller::kUnusedAttachmentReference
static constexpr vk::AttachmentReference kUnusedAttachmentReference
Definition: formats_vk.h:438
impeller::BlendFactor
BlendFactor
Definition: formats.h:178
impeller::BlendFactor::kBlendAlpha
@ kBlendAlpha
impeller::BlendFactor::kDestinationColor
@ kDestinationColor
impeller::BlendFactor::kOneMinusBlendColor
@ kOneMinusBlendColor
impeller::BlendFactor::kOneMinusSourceColor
@ kOneMinusSourceColor
impeller::BlendFactor::kOneMinusBlendAlpha
@ kOneMinusBlendAlpha
impeller::BlendFactor::kBlendColor
@ kBlendColor
impeller::BlendFactor::kOne
@ kOne
impeller::BlendFactor::kSourceColor
@ kSourceColor
impeller::BlendFactor::kZero
@ kZero
impeller::BlendFactor::kDestinationAlpha
@ kDestinationAlpha
impeller::BlendFactor::kSourceAlpha
@ kSourceAlpha
impeller::BlendFactor::kOneMinusDestinationAlpha
@ kOneMinusDestinationAlpha
impeller::BlendFactor::kSourceAlphaSaturated
@ kSourceAlphaSaturated
impeller::BlendFactor::kOneMinusSourceAlpha
@ kOneMinusSourceAlpha
impeller::BlendFactor::kOneMinusDestinationColor
@ kOneMinusDestinationColor
impeller::PrimitiveType
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
impeller::PrimitiveType::kPoint
@ kPoint
Draws a point at each input vertex.
impeller::PrimitiveType::kTriangleFan
@ kTriangleFan
impeller::PrimitiveType::kTriangle
@ kTriangle
impeller::PrimitiveType::kLineStrip
@ kLineStrip
impeller::PrimitiveType::kTriangleStrip
@ kTriangleStrip
impeller::PrimitiveType::kLine
@ kLine
impeller::ToVKSamplerAddressMode
constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(SamplerAddressMode mode)
Definition: formats_vk.h:248
impeller::IndexType
IndexType
Definition: formats.h:343
impeller::IndexType::k16bit
@ k16bit
impeller::IndexType::kUnknown
@ kUnknown
impeller::IndexType::kNone
@ kNone
Does not use the index buffer.
impeller::IndexType::k32bit
@ k32bit
impeller::ToVKPipelineColorBlendAttachmentState
constexpr vk::PipelineColorBlendAttachmentState ToVKPipelineColorBlendAttachmentState(const ColorAttachmentDescriptor &desc)
Definition: formats_vk.h:113
impeller::ToPixelFormat
constexpr PixelFormat ToPixelFormat(vk::Format format)
Definition: formats_vk.h:183
impeller::ToVKCompareOp
constexpr vk::CompareOp ToVKCompareOp(CompareFunction op)
Definition: formats_vk.h:453
impeller::ToVKSamplerMipmapMode
constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter)
Definition: formats_vk.h:236
impeller::SamplerAddressMode
SamplerAddressMode
Definition: formats.h:441
impeller::SamplerAddressMode::kDecal
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
impeller::SamplerAddressMode::kRepeat
@ kRepeat
impeller::SamplerAddressMode::kMirror
@ kMirror
impeller::SamplerAddressMode::kClampToEdge
@ kClampToEdge
impeller::StoreActionPerformsResolve
constexpr bool StoreActionPerformsResolve(StoreAction store_action)
Definition: formats_vk.h:343
impeller::ToVKIndexType
constexpr vk::IndexType ToVKIndexType(IndexType index_type)
Definition: formats_vk.h:355
impeller::ToVKDescriptorSetLayoutBinding
constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(const DescriptorSetLayout &layout)
Definition: formats_vk.h:296
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:539
impeller::ToVKSamplerMinMagFilter
constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_vk.h:225
impeller::ToImageAspectFlags
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:586
impeller::ToVKSampleCountFlagBits
constexpr vk::SampleCountFlagBits ToVKSampleCountFlagBits(SampleCount count)
Definition: formats_vk.h:32
impeller::ToVKShaderStageFlagBits
constexpr std::optional< vk::ShaderStageFlagBits > ToVKShaderStageFlagBits(ShaderStage stage)
Definition: formats_vk.h:131
impeller::ToVKAttachmentLoadOp
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action)
Definition: formats_vk.h:306
impeller::ToVKDescriptorType
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type)
Definition: formats_vk.h:292
impeller::ToVKPolygonMode
constexpr vk::PolygonMode ToVKPolygonMode(PolygonMode mode)
Definition: formats_vk.h:370
impeller::CullMode
CullMode
Definition: formats.h:337
impeller::CullMode::kNone
@ kNone
impeller::CullMode::kBackFace
@ kBackFace
impeller::CullMode::kFrontFace
@ kFrontFace
impeller::PixelFormat
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
Definition: formats.h:99
impeller::PixelFormat::kD24UnormS8Uint
@ kD24UnormS8Uint
impeller::PixelFormat::kR8G8B8A8UNormIntSRGB
@ kR8G8B8A8UNormIntSRGB
impeller::PixelFormat::kR8UNormInt
@ kR8UNormInt
impeller::PixelFormat::kUnknown
@ kUnknown
impeller::PixelFormat::kR32G32B32A32Float
@ kR32G32B32A32Float
impeller::PixelFormat::kA8UNormInt
@ kA8UNormInt
impeller::PixelFormat::kB10G10R10A10XR
@ kB10G10R10A10XR
impeller::PixelFormat::kB8G8R8A8UNormInt
@ kB8G8R8A8UNormInt
impeller::PixelFormat::kS8UInt
@ kS8UInt
impeller::PixelFormat::kB10G10R10XRSRGB
@ kB10G10R10XRSRGB
impeller::PixelFormat::kD32FloatS8UInt
@ kD32FloatS8UInt
impeller::PixelFormat::kB10G10R10XR
@ kB10G10R10XR
impeller::PixelFormat::kR8G8UNormInt
@ kR8G8UNormInt
impeller::PixelFormat::kB8G8R8A8UNormIntSRGB
@ kB8G8R8A8UNormIntSRGB
impeller::PixelFormat::kR16G16B16A16Float
@ kR16G16B16A16Float
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::CompareFunction
CompareFunction
Definition: formats.h:552
impeller::CompareFunction::kEqual
@ kEqual
Comparison test passes if new_value == current_value.
impeller::CompareFunction::kLessEqual
@ kLessEqual
Comparison test passes if new_value <= current_value.
impeller::CompareFunction::kGreaterEqual
@ kGreaterEqual
Comparison test passes if new_value >= current_value.
impeller::CompareFunction::kAlways
@ kAlways
Comparison test passes always passes.
impeller::CompareFunction::kLess
@ kLess
Comparison test passes if new_value < current_value.
impeller::CompareFunction::kGreater
@ kGreater
Comparison test passes if new_value > current_value.
impeller::CompareFunction::kNotEqual
@ kNotEqual
Comparison test passes if new_value != current_value.
impeller::CompareFunction::kNever
@ kNever
Comparison test never passes.
impeller::ToVKAttachmentStoreOp
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action, bool is_resolve_texture)
Definition: formats_vk.h:319
impeller::ToVKCullModeFlags
constexpr vk::CullModeFlags ToVKCullModeFlags(CullMode mode)
Definition: formats_vk.h:441
impeller::MipFilter
MipFilter
Options for selecting and filtering between mipmap levels.
Definition: formats.h:425
impeller::MipFilter::kLinear
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
impeller::MipFilter::kBase
@ kBase
The texture is sampled as if it only had a single mipmap level.
impeller::MipFilter::kNearest
@ kNearest
The nearst mipmap level is selected.
impeller::ToVKColorComponentFlags
constexpr vk::ColorComponentFlags ToVKColorComponentFlags(ColorWriteMask type)
Definition: formats_vk.h:90
impeller::StencilOperation
StencilOperation
Definition: formats.h:571
impeller::StencilOperation::kDecrementWrap
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
impeller::StencilOperation::kSetToReferenceValue
@ kSetToReferenceValue
Reset the stencil value to the reference value.
impeller::StencilOperation::kDecrementClamp
@ kDecrementClamp
Decrement the current stencil value by 1. Clamp it to zero.
impeller::StencilOperation::kZero
@ kZero
Reset the stencil value to zero.
impeller::StencilOperation::kIncrementClamp
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
impeller::StencilOperation::kIncrementWrap
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
impeller::StencilOperation::kInvert
@ kInvert
Perform a logical bitwise invert on the current stencil value.
impeller::StencilOperation::kKeep
@ kKeep
Don't modify the current stencil value.
impeller::ToVKBlendFactor
constexpr vk::BlendFactor ToVKBlendFactor(BlendFactor factor)
Definition: formats_vk.h:42
impeller::VkFormatToImpellerFormat
constexpr std::optional< PixelFormat > VkFormatToImpellerFormat(vk::Format format)
Definition: formats_vk.h:20
impeller::TextureType
TextureType
Definition: formats.h:262
impeller::TextureType::kTextureExternalOES
@ kTextureExternalOES
impeller::TextureType::kTexture2DMultisample
@ kTexture2DMultisample
impeller::TextureType::kTexture2D
@ kTexture2D
impeller::TextureType::kTextureCube
@ kTextureCube
impeller::ShaderStage
ShaderStage
Definition: shader_types.h:22
impeller::ShaderStage::kUnknown
@ kUnknown
impeller::ShaderStage::kCompute
@ kCompute
impeller::ShaderStage::kFragment
@ kFragment
impeller::ShaderStage::kVertex
@ kVertex
impeller::PixelFormatIsDepthStencil
constexpr bool PixelFormatIsDepthStencil(PixelFormat format)
Definition: formats_vk.h:414
impeller::ToVKPipelineDepthStencilStateCreateInfo
vk::PipelineDepthStencilStateCreateInfo ToVKPipelineDepthStencilStateCreateInfo(std::optional< DepthAttachmentDescriptor > depth, std::optional< StencilAttachmentDescriptor > front, std::optional< StencilAttachmentDescriptor > back)
Definition: formats_vk.cc:9
impeller::PrimitiveTopologySupportsPrimitiveRestart
constexpr bool PrimitiveTopologySupportsPrimitiveRestart(PrimitiveType primitive)
Definition: formats_vk.h:380
impeller::ToVKImageViewType
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
Definition: formats_vk.h:553
impeller::LoadAction
LoadAction
Definition: formats.h:202
impeller::LoadAction::kDontCare
@ kDontCare
impeller::LoadAction::kLoad
@ kLoad
impeller::LoadAction::kClear
@ kClear
impeller::StoreAction
StoreAction
Definition: formats.h:208
impeller::StoreAction::kStore
@ kStore
impeller::StoreAction::kDontCare
@ kDontCare
impeller::StoreAction::kStoreAndMultisampleResolve
@ kStoreAndMultisampleResolve
impeller::StoreAction::kMultisampleResolve
@ kMultisampleResolve
impeller::ToVKSampleCount
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
Definition: formats_vk.h:214
impeller::ToVKImageFormat
constexpr vk::Format ToVKImageFormat(PixelFormat format)
Definition: formats_vk.h:146
impeller::ToVKStencilOpState
constexpr vk::StencilOpState ToVKStencilOpState(const StencilAttachmentDescriptor &desc)
Definition: formats_vk.h:498
impeller::ToVkShaderStage
constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage)
Definition: formats_vk.h:264
impeller::ToVKPrimitiveTopology
constexpr vk::PrimitiveTopology ToVKPrimitiveTopology(PrimitiveType primitive)
Definition: formats_vk.h:395
impeller::PolygonMode
PolygonMode
Definition: formats.h:389
impeller::PolygonMode::kFill
@ kFill
impeller::PolygonMode::kLine
@ kLine
impeller::ToVKBlendOp
constexpr vk::BlendOp ToVKBlendOp(BlendOperation op)
Definition: formats_vk.h:78
impeller::DescriptorType
DescriptorType
Definition: shader_types.h:158
impeller::DescriptorType::kImage
@ kImage
impeller::DescriptorType::kUniformBuffer
@ kUniformBuffer
impeller::DescriptorType::kSampler
@ kSampler
impeller::DescriptorType::kInputAttachment
@ kInputAttachment
impeller::DescriptorType::kSampledImage
@ kSampledImage
impeller::DescriptorType::kStorageBuffer
@ kStorageBuffer
impeller::ToVKStencilOp
constexpr vk::StencilOp ToVKStencilOp(StencilOperation op)
Definition: formats_vk.h:475
impeller::MinMagFilter
MinMagFilter
Describes how the texture should be sampled when the texture is being shrunk (minified) or expanded (...
Definition: formats.h:415
impeller::MinMagFilter::kLinear
@ kLinear
impeller::MinMagFilter::kNearest
@ kNearest
Select nearest to the sample point. Most widely supported.
impeller::ColorWriteMaskBits::kAlpha
@ kAlpha
impeller::ColorWriteMaskBits::kGreen
@ kGreen
impeller::ColorWriteMaskBits::kBlue
@ kBlue
impeller::ColorWriteMaskBits::kRed
@ kRed
impeller::ToVKImageCreateFlags
constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type)
Definition: formats_vk.h:567
impeller::ToVKImageAspectFlags
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:513
impeller::BlendOperation
BlendOperation
Definition: formats.h:196
impeller::BlendOperation::kSubtract
@ kSubtract
impeller::BlendOperation::kAdd
@ kAdd
impeller::BlendOperation::kReverseSubtract
@ kReverseSubtract
impeller::SampleCount
SampleCount
Definition: formats.h:295
impeller::SampleCount::kCount4
@ kCount4
impeller::SampleCount::kCount1
@ kCount1
shader_types.h
impeller::ColorAttachmentDescriptor
Describe the color attachment that will be used with this pipeline.
Definition: formats.h:518
impeller::ColorAttachmentDescriptor::blending_enabled
bool blending_enabled
Definition: formats.h:520
impeller::ColorAttachmentDescriptor::color_blend_op
BlendOperation color_blend_op
Definition: formats.h:523
impeller::ColorAttachmentDescriptor::dst_color_blend_factor
BlendFactor dst_color_blend_factor
Definition: formats.h:524
impeller::ColorAttachmentDescriptor::write_mask
ColorWriteMask write_mask
Definition: formats.h:530
impeller::ColorAttachmentDescriptor::src_alpha_blend_factor
BlendFactor src_alpha_blend_factor
Definition: formats.h:526
impeller::ColorAttachmentDescriptor::alpha_blend_op
BlendOperation alpha_blend_op
Definition: formats.h:527
impeller::ColorAttachmentDescriptor::src_color_blend_factor
BlendFactor src_color_blend_factor
Definition: formats.h:522
impeller::ColorAttachmentDescriptor::dst_alpha_blend_factor
BlendFactor dst_alpha_blend_factor
Definition: formats.h:528
impeller::DescriptorSetLayout
Definition: shader_types.h:167
impeller::DescriptorSetLayout::descriptor_type
DescriptorType descriptor_type
Definition: shader_types.h:169
impeller::DescriptorSetLayout::shader_stage
ShaderStage shader_stage
Definition: shader_types.h:170
impeller::DescriptorSetLayout::binding
uint32_t binding
Definition: shader_types.h:168
impeller::Mask< ColorWriteMaskBits >
impeller::StencilAttachmentDescriptor
Definition: formats.h:610
impeller::StencilAttachmentDescriptor::stencil_failure
StencilOperation stencil_failure
Definition: formats.h:620
impeller::StencilAttachmentDescriptor::write_mask
uint32_t write_mask
Definition: formats.h:640
impeller::StencilAttachmentDescriptor::stencil_compare
CompareFunction stencil_compare
Definition: formats.h:616
impeller::StencilAttachmentDescriptor::depth_failure
StencilOperation depth_failure
Definition: formats.h:625
impeller::StencilAttachmentDescriptor::depth_stencil_pass
StencilOperation depth_stencil_pass
Definition: formats.h:629
impeller::StencilAttachmentDescriptor::read_mask
uint32_t read_mask
Definition: formats.h:635
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
vk.h