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