| 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 case PixelFormat::kR32Float:
179 return vk::Format::eR32Sfloat;
180 }
181
182 FML_UNREACHABLE();
183 }
184
185 constexpr PixelFormat ToPixelFormat(vk::Format format) {
186 switch (format) {
187 case vk::Format::eUndefined:
188 return PixelFormat::kUnknown;
189 case vk::Format::eR8G8B8A8Unorm:
190 return PixelFormat::kR8G8B8A8UNormInt;
191 case vk::Format::eR8G8B8A8Srgb:
192 return PixelFormat::kR8G8B8A8UNormIntSRGB;
193 case vk::Format::eB8G8R8A8Unorm:
194 return PixelFormat::kB8G8R8A8UNormInt;
195 case vk::Format::eB8G8R8A8Srgb:
196 return PixelFormat::kB8G8R8A8UNormIntSRGB;
197 case vk::Format::eR32G32B32A32Sfloat:
198 return PixelFormat::kR32G32B32A32Float;
199 case vk::Format::eR16G16B16A16Sfloat:
200 return PixelFormat::kR16G16B16A16Float;
201 case vk::Format::eS8Uint:
202 return PixelFormat::kS8UInt;
203 case vk::Format::eD24UnormS8Uint:
204 return PixelFormat::kD24UnormS8Uint;
205 case vk::Format::eD32SfloatS8Uint:
206 return PixelFormat::kD32FloatS8UInt;
207 case vk::Format::eR8Unorm:
208 return PixelFormat::kR8UNormInt;
209 case vk::Format::eR8G8Unorm:
210 return PixelFormat::kR8G8UNormInt;
211 default:
212 return PixelFormat::kUnknown;
213 }
214 }
215
216 constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count) {
217 switch (sample_count) {
218 case SampleCount::kCount1:
219 return vk::SampleCountFlagBits::e1;
220 case SampleCount::kCount4:
221 return vk::SampleCountFlagBits::e4;
222 }
223
224 FML_UNREACHABLE();
225 }
226
227 constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter) {
228 switch (filter) {
229 case MinMagFilter::kNearest:
230 return vk::Filter::eNearest;
231 case MinMagFilter::kLinear:
232 return vk::Filter::eLinear;
233 }
234
235 FML_UNREACHABLE();
236 }
237
238 constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter) {
239 switch (filter) {
240 case MipFilter::kBase:
241 case MipFilter::kNearest:
242 return vk::SamplerMipmapMode::eNearest;
243 case MipFilter::kLinear:
244 return vk::SamplerMipmapMode::eLinear;
245 }
246
247 FML_UNREACHABLE();
248 }
249
250 constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(
251 SamplerAddressMode mode) {
252 switch (mode) {
253 case SamplerAddressMode::kRepeat:
254 return vk::SamplerAddressMode::eRepeat;
255 case SamplerAddressMode::kMirror:
256 return vk::SamplerAddressMode::eMirroredRepeat;
257 case SamplerAddressMode::kClampToEdge:
258 return vk::SamplerAddressMode::eClampToEdge;
259 case SamplerAddressMode::kDecal:
260 return vk::SamplerAddressMode::eClampToBorder;
261 }
262
263 FML_UNREACHABLE();
264 }
265
266 constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage) {
267 switch (stage) {
268 case ShaderStage::kUnknown:
269 return vk::ShaderStageFlagBits::eAll;
270 case ShaderStage::kFragment:
271 return vk::ShaderStageFlagBits::eFragment;
272 case ShaderStage::kCompute:
273 return vk::ShaderStageFlagBits::eCompute;
274 case ShaderStage::kVertex:
275 return vk::ShaderStageFlagBits::eVertex;
276 }
277
278 FML_UNREACHABLE();
279 }
280
281 static_assert(static_cast<int>(DescriptorType::kSampledImage) ==
282 static_cast<int>(vk::DescriptorType::eCombinedImageSampler));
283 static_assert(static_cast<int>(DescriptorType::kUniformBuffer) ==
284 static_cast<int>(vk::DescriptorType::eUniformBuffer));
285 static_assert(static_cast<int>(DescriptorType::kStorageBuffer) ==
286 static_cast<int>(vk::DescriptorType::eStorageBuffer));
287 static_assert(static_cast<int>(DescriptorType::kImage) ==
288 static_cast<int>(vk::DescriptorType::eSampledImage));
289 static_assert(static_cast<int>(DescriptorType::kSampler) ==
290 static_cast<int>(vk::DescriptorType::eSampler));
291 static_assert(static_cast<int>(DescriptorType::kInputAttachment) ==
292 static_cast<int>(vk::DescriptorType::eInputAttachment));
293
294 constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type) {
295 return static_cast<vk::DescriptorType>(type);
296 }
297
298 constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(
299 const DescriptorSetLayout& layout) {
300 vk::DescriptorSetLayoutBinding binding;
301 binding.binding = layout.binding;
302 binding.descriptorCount = 1u;
303 binding.descriptorType = ToVKDescriptorType(layout.descriptor_type);
304 binding.stageFlags = ToVkShaderStage(layout.shader_stage);
305 return binding;
306 }
307
308 constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action) {
309 switch (load_action) {
310 case LoadAction::kLoad:
311 return vk::AttachmentLoadOp::eLoad;
312 case LoadAction::kClear:
313 return vk::AttachmentLoadOp::eClear;
314 case LoadAction::kDontCare:
315 return vk::AttachmentLoadOp::eDontCare;
316 }
317
318 FML_UNREACHABLE();
319 }
320
321 constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action,
322 bool is_resolve_texture) {
323 switch (store_action) {
324 case StoreAction::kStore:
325 // Both MSAA and resolve textures need to be stored. A resolve is NOT
326 // performed.
327 return vk::AttachmentStoreOp::eStore;
328 case StoreAction::kDontCare:
329 // Both MSAA and resolve textures can be discarded. A resolve is NOT
330 // performed.
331 return vk::AttachmentStoreOp::eDontCare;
332 case StoreAction::kMultisampleResolve:
333 // The resolve texture is stored but the MSAA texture can be discarded. A
334 // resolve IS performed.
335 return is_resolve_texture ? vk::AttachmentStoreOp::eStore
336 : vk::AttachmentStoreOp::eDontCare;
337 case StoreAction::kStoreAndMultisampleResolve:
338 // Both MSAA and resolve textures need to be stored. A resolve IS
339 // performed.
340 return vk::AttachmentStoreOp::eStore;
341 }
342 FML_UNREACHABLE();
343 }
344
345 constexpr bool StoreActionPerformsResolve(StoreAction store_action) {
346 switch (store_action) {
347 case StoreAction::kDontCare:
348 case StoreAction::kStore:
349 return false;
350 case StoreAction::kMultisampleResolve:
351 case StoreAction::kStoreAndMultisampleResolve:
352 return true;
353 }
354 FML_UNREACHABLE();
355 }
356
357 constexpr vk::IndexType ToVKIndexType(IndexType index_type) {
358 switch (index_type) {
359 case IndexType::k16bit:
360 return vk::IndexType::eUint16;
361 case IndexType::k32bit:
362 return vk::IndexType::eUint32;
363 case IndexType::kUnknown:
364 return vk::IndexType::eUint32;
365 case IndexType::kNone:
366 FML_UNREACHABLE();
367 }
368
369 FML_UNREACHABLE();
370 }
371
372 constexpr vk::PolygonMode ToVKPolygonMode(PolygonMode mode) {
373 switch (mode) {
374 case PolygonMode::kFill:
375 return vk::PolygonMode::eFill;
376 case PolygonMode::kLine:
377 return vk::PolygonMode::eLine;
378 }
379 FML_UNREACHABLE();
380 }
381
382 constexpr bool PrimitiveTopologySupportsPrimitiveRestart(
383 PrimitiveType primitive) {
384 switch (primitive) {
385 case PrimitiveType::kTriangleStrip:
386 case PrimitiveType::kLine:
387 case PrimitiveType::kPoint:
388 case PrimitiveType::kTriangleFan:
389 return true;
390 case PrimitiveType::kTriangle:
391 case PrimitiveType::kLineStrip:
392 return false;
393 }
394 FML_UNREACHABLE();
395 }
396
397 constexpr vk::PrimitiveTopology ToVKPrimitiveTopology(PrimitiveType primitive) {
398 switch (primitive) {
399 case PrimitiveType::kTriangle:
400 return vk::PrimitiveTopology::eTriangleList;
401 case PrimitiveType::kTriangleStrip:
402 return vk::PrimitiveTopology::eTriangleStrip;
403 case PrimitiveType::kLine:
404 return vk::PrimitiveTopology::eLineList;
405 case PrimitiveType::kLineStrip:
406 return vk::PrimitiveTopology::eLineStrip;
407 case PrimitiveType::kPoint:
408 return vk::PrimitiveTopology::ePointList;
409 case PrimitiveType::kTriangleFan:
410 return vk::PrimitiveTopology::eTriangleFan;
411 }
412
413 FML_UNREACHABLE();
414 }
415
416 constexpr bool PixelFormatIsDepthStencil(PixelFormat format) {
417 switch (format) {
418 case PixelFormat::kUnknown:
419 case PixelFormat::kA8UNormInt:
420 case PixelFormat::kR8UNormInt:
421 case PixelFormat::kR8G8UNormInt:
422 case PixelFormat::kR8G8B8A8UNormInt:
423 case PixelFormat::kR8G8B8A8UNormIntSRGB:
424 case PixelFormat::kB8G8R8A8UNormInt:
425 case PixelFormat::kB8G8R8A8UNormIntSRGB:
426 case PixelFormat::kR32G32B32A32Float:
427 case PixelFormat::kR16G16B16A16Float:
428 case PixelFormat::kB10G10R10XR:
429 case PixelFormat::kB10G10R10XRSRGB:
430 case PixelFormat::kB10G10R10A10XR:
431 case PixelFormat::kR32Float:
432 return false;
433 case PixelFormat::kS8UInt:
434 case PixelFormat::kD24UnormS8Uint:
435 case PixelFormat::kD32FloatS8UInt:
436 return true;
437 }
438 return false;
439 }
440
441 static constexpr vk::AttachmentReference kUnusedAttachmentReference = {
442 VK_ATTACHMENT_UNUSED, vk::ImageLayout::eUndefined};
443
444 constexpr vk::CullModeFlags ToVKCullModeFlags(CullMode mode) {
445 switch (mode) {
446 case CullMode::kNone:
447 return vk::CullModeFlagBits::eNone;
448 case CullMode::kFrontFace:
449 return vk::CullModeFlagBits::eFront;
450 case CullMode::kBackFace:
451 return vk::CullModeFlagBits::eBack;
452 }
453 FML_UNREACHABLE();
454 }
455
456 constexpr vk::CompareOp ToVKCompareOp(CompareFunction op) {
457 switch (op) {
458 case CompareFunction::kNever:
459 return vk::CompareOp::eNever;
460 case CompareFunction::kAlways:
461 return vk::CompareOp::eAlways;
462 case CompareFunction::kLess:
463 return vk::CompareOp::eLess;
464 case CompareFunction::kEqual:
465 return vk::CompareOp::eEqual;
466 case CompareFunction::kLessEqual:
467 return vk::CompareOp::eLessOrEqual;
468 case CompareFunction::kGreater:
469 return vk::CompareOp::eGreater;
470 case CompareFunction::kNotEqual:
471 return vk::CompareOp::eNotEqual;
472 case CompareFunction::kGreaterEqual:
473 return vk::CompareOp::eGreaterOrEqual;
474 }
475 FML_UNREACHABLE();
476 }
477
478 constexpr vk::StencilOp ToVKStencilOp(StencilOperation op) {
479 switch (op) {
480 case StencilOperation::kKeep:
481 return vk::StencilOp::eKeep;
482 case StencilOperation::kZero:
483 return vk::StencilOp::eZero;
484 case StencilOperation::kSetToReferenceValue:
485 return vk::StencilOp::eReplace;
486 case StencilOperation::kIncrementClamp:
487 return vk::StencilOp::eIncrementAndClamp;
488 case StencilOperation::kDecrementClamp:
489 return vk::StencilOp::eDecrementAndClamp;
490 case StencilOperation::kInvert:
491 return vk::StencilOp::eInvert;
492 case StencilOperation::kIncrementWrap:
493 return vk::StencilOp::eIncrementAndWrap;
494 case StencilOperation::kDecrementWrap:
495 return vk::StencilOp::eDecrementAndWrap;
496 break;
497 }
498 FML_UNREACHABLE();
499 }
500
501 constexpr vk::StencilOpState ToVKStencilOpState(
502 const StencilAttachmentDescriptor& desc) {
503 vk::StencilOpState state;
504 state.failOp = ToVKStencilOp(desc.stencil_failure);
505 state.passOp = ToVKStencilOp(desc.depth_stencil_pass);
506 state.depthFailOp = ToVKStencilOp(desc.depth_failure);
507 state.compareOp = ToVKCompareOp(desc.stencil_compare);
508 state.compareMask = desc.read_mask;
509 state.writeMask = desc.write_mask;
510 // This is irrelevant as the stencil references are always dynamic state and
511 // will be set in the render pass.
512 state.reference = 1988;
513 return state;
514 }
515
516 constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format) {
517 switch (format) {
518 case PixelFormat::kUnknown:
519 case PixelFormat::kA8UNormInt:
520 case PixelFormat::kR8UNormInt:
521 case PixelFormat::kR8G8UNormInt:
522 case PixelFormat::kR8G8B8A8UNormInt:
523 case PixelFormat::kR8G8B8A8UNormIntSRGB:
524 case PixelFormat::kB8G8R8A8UNormInt:
525 case PixelFormat::kB8G8R8A8UNormIntSRGB:
526 case PixelFormat::kR32G32B32A32Float:
527 case PixelFormat::kR16G16B16A16Float:
528 case PixelFormat::kB10G10R10XR:
529 case PixelFormat::kB10G10R10XRSRGB:
530 case PixelFormat::kB10G10R10A10XR:
531 case PixelFormat::kR32Float:
532 return vk::ImageAspectFlagBits::eColor;
533 case PixelFormat::kS8UInt:
534 return vk::ImageAspectFlagBits::eStencil;
535 case PixelFormat::kD24UnormS8Uint:
536 case PixelFormat::kD32FloatS8UInt:
537 return vk::ImageAspectFlagBits::eDepth |
538 vk::ImageAspectFlagBits::eStencil;
539 }
540 FML_UNREACHABLE();
541 }
542
543 constexpr uint32_t ToArrayLayerCount(TextureType type) {
544 switch (type) {
545 case TextureType::kTexture2D:
546 case TextureType::kTexture2DMultisample:
547 return 1u;
548 case TextureType::kTextureCube:
549 return 6u;
550 case TextureType::kTextureExternalOES:
551 VALIDATION_LOG
552 << "kTextureExternalOES can not be used with the Vulkan backend.";
553 }
554 FML_UNREACHABLE();
555 }
556
557 constexpr vk::ImageViewType ToVKImageViewType(TextureType type) {
558 switch (type) {
559 case TextureType::kTexture2D:
560 case TextureType::kTexture2DMultisample:
561 return vk::ImageViewType::e2D;
562 case TextureType::kTextureCube:
563 return vk::ImageViewType::eCube;
564 case TextureType::kTextureExternalOES:
565 VALIDATION_LOG
566 << "kTextureExternalOES can not be used with the Vulkan backend.";
567 }
568 FML_UNREACHABLE();
569 }
570
571 constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type) {
572 switch (type) {
573 case TextureType::kTexture2D:
574 case TextureType::kTexture2DMultisample:
575 return {};
576 case TextureType::kTextureCube:
577 return vk::ImageCreateFlagBits::eCubeCompatible;
578 case TextureType::kTextureExternalOES:
579 VALIDATION_LOG
580 << "kTextureExternalOES can not be used with the Vulkan backend.";
581 }
582 FML_UNREACHABLE();
583 }
584
585 vk::PipelineDepthStencilStateCreateInfo ToVKPipelineDepthStencilStateCreateInfo(
586 std::optional<DepthAttachmentDescriptor> depth,
587 std::optional<StencilAttachmentDescriptor> front,
588 std::optional<StencilAttachmentDescriptor> back);
589
590 constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format) {
591 switch (format) {
592 case PixelFormat::kUnknown:
593 return {};
594 case PixelFormat::kA8UNormInt:
595 case PixelFormat::kR8UNormInt:
596 case PixelFormat::kR8G8UNormInt:
597 case PixelFormat::kR8G8B8A8UNormInt:
598 case PixelFormat::kR8G8B8A8UNormIntSRGB:
599 case PixelFormat::kB8G8R8A8UNormInt:
600 case PixelFormat::kB8G8R8A8UNormIntSRGB:
601 case PixelFormat::kR32G32B32A32Float:
602 case PixelFormat::kR16G16B16A16Float:
603 case PixelFormat::kB10G10R10XR:
604 case PixelFormat::kB10G10R10XRSRGB:
605 case PixelFormat::kB10G10R10A10XR:
606 case PixelFormat::kR32Float:
607 return vk::ImageAspectFlagBits::eColor;
608 case PixelFormat::kS8UInt:
609 return vk::ImageAspectFlagBits::eStencil;
610 case PixelFormat::kD24UnormS8Uint:
611 case PixelFormat::kD32FloatS8UInt:
612 return vk::ImageAspectFlagBits::eDepth |
613 vk::ImageAspectFlagBits::eStencil;
614 }
615 FML_UNREACHABLE();
616 }
617
618 } // namespace impeller
619
620 #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:441
impeller::BlendFactor
BlendFactor
Definition: formats.h:181
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:355
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:250
impeller::IndexType
IndexType
Definition: formats.h:346
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:185
impeller::ToVKCompareOp
constexpr vk::CompareOp ToVKCompareOp(CompareFunction op)
Definition: formats_vk.h:456
impeller::ToVKSamplerMipmapMode
constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter)
Definition: formats_vk.h:238
impeller::SamplerAddressMode
SamplerAddressMode
Definition: formats.h:444
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:345
impeller::ToVKIndexType
constexpr vk::IndexType ToVKIndexType(IndexType index_type)
Definition: formats_vk.h:357
impeller::ToVKDescriptorSetLayoutBinding
constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(const DescriptorSetLayout &layout)
Definition: formats_vk.h:298
impeller::ToArrayLayerCount
constexpr uint32_t ToArrayLayerCount(TextureType type)
Definition: formats_vk.h:543
impeller::ToVKSamplerMinMagFilter
constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter)
Definition: formats_vk.h:227
impeller::ToImageAspectFlags
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:590
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:308
impeller::ToVKDescriptorType
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type)
Definition: formats_vk.h:294
impeller::ToVKPolygonMode
constexpr vk::PolygonMode ToVKPolygonMode(PolygonMode mode)
Definition: formats_vk.h:372
impeller::CullMode
CullMode
Definition: formats.h:340
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::kR32Float
@ kR32Float
impeller::PixelFormat::kR8G8B8A8UNormInt
@ kR8G8B8A8UNormInt
impeller::CompareFunction
CompareFunction
Definition: formats.h:556
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:321
impeller::ToVKCullModeFlags
constexpr vk::CullModeFlags ToVKCullModeFlags(CullMode mode)
Definition: formats_vk.h:444
impeller::MipFilter
MipFilter
Options for selecting and filtering between mipmap levels.
Definition: formats.h:428
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:575
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:265
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:416
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:382
impeller::ToVKImageViewType
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
Definition: formats_vk.h:557
impeller::LoadAction
LoadAction
Definition: formats.h:205
impeller::LoadAction::kDontCare
@ kDontCare
impeller::LoadAction::kLoad
@ kLoad
impeller::LoadAction::kClear
@ kClear
impeller::StoreAction
StoreAction
Definition: formats.h:211
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:216
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:501
impeller::ToVkShaderStage
constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage)
Definition: formats_vk.h:266
impeller::ToVKPrimitiveTopology
constexpr vk::PrimitiveTopology ToVKPrimitiveTopology(PrimitiveType primitive)
Definition: formats_vk.h:397
impeller::PolygonMode
PolygonMode
Definition: formats.h:392
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:478
impeller::MinMagFilter
MinMagFilter
Describes how the texture should be sampled when the texture is being shrunk (minified) or expanded (...
Definition: formats.h:418
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:571
impeller::ToVKImageAspectFlags
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Definition: formats_vk.h:516
impeller::BlendOperation
BlendOperation
Definition: formats.h:199
impeller::BlendOperation::kSubtract
@ kSubtract
impeller::BlendOperation::kAdd
@ kAdd
impeller::BlendOperation::kReverseSubtract
@ kReverseSubtract
impeller::SampleCount
SampleCount
Definition: formats.h:298
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:522
impeller::ColorAttachmentDescriptor::blending_enabled
bool blending_enabled
Definition: formats.h:524
impeller::ColorAttachmentDescriptor::color_blend_op
BlendOperation color_blend_op
Definition: formats.h:527
impeller::ColorAttachmentDescriptor::dst_color_blend_factor
BlendFactor dst_color_blend_factor
Definition: formats.h:528
impeller::ColorAttachmentDescriptor::write_mask
ColorWriteMask write_mask
Definition: formats.h:534
impeller::ColorAttachmentDescriptor::src_alpha_blend_factor
BlendFactor src_alpha_blend_factor
Definition: formats.h:530
impeller::ColorAttachmentDescriptor::alpha_blend_op
BlendOperation alpha_blend_op
Definition: formats.h:531
impeller::ColorAttachmentDescriptor::src_color_blend_factor
BlendFactor src_color_blend_factor
Definition: formats.h:526
impeller::ColorAttachmentDescriptor::dst_alpha_blend_factor
BlendFactor dst_alpha_blend_factor
Definition: formats.h:532
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:614
impeller::StencilAttachmentDescriptor::stencil_failure
StencilOperation stencil_failure
Definition: formats.h:624
impeller::StencilAttachmentDescriptor::write_mask
uint32_t write_mask
Definition: formats.h:644
impeller::StencilAttachmentDescriptor::stencil_compare
CompareFunction stencil_compare
Definition: formats.h:620
impeller::StencilAttachmentDescriptor::depth_failure
StencilOperation depth_failure
Definition: formats.h:629
impeller::StencilAttachmentDescriptor::depth_stencil_pass
StencilOperation depth_stencil_pass
Definition: formats.h:633
impeller::StencilAttachmentDescriptor::read_mask
uint32_t read_mask
Definition: formats.h:639
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91
vk.h