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