5 #ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FORMATS_VK_H_
6 #define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_FORMATS_VK_H_
11 #include "fml/logging.h"
16 #include "vulkan/vulkan_enums.hpp"
23 case vk::Format::eR8G8B8A8Unorm:
25 case vk::Format::eB8G8R8A8Unorm:
37 return vk::SampleCountFlagBits::e4;
45 return vk::BlendFactor::eZero;
47 return vk::BlendFactor::eOne;
49 return vk::BlendFactor::eSrcColor;
51 return vk::BlendFactor::eOneMinusSrcColor;
53 return vk::BlendFactor::eSrcAlpha;
55 return vk::BlendFactor::eOneMinusSrcAlpha;
57 return vk::BlendFactor::eDstColor;
59 return vk::BlendFactor::eOneMinusDstColor;
61 return vk::BlendFactor::eDstAlpha;
63 return vk::BlendFactor::eOneMinusDstAlpha;
65 return vk::BlendFactor::eSrcAlphaSaturate;
67 return vk::BlendFactor::eConstantColor;
69 return vk::BlendFactor::eOneMinusConstantColor;
71 return vk::BlendFactor::eConstantAlpha;
73 return vk::BlendFactor::eOneMinusConstantAlpha;
81 return vk::BlendOp::eAdd;
83 return vk::BlendOp::eSubtract;
85 return vk::BlendOp::eReverseSubtract;
91 vk::ColorComponentFlags mask;
94 mask |= vk::ColorComponentFlagBits::eR;
98 mask |= vk::ColorComponentFlagBits::eG;
102 mask |= vk::ColorComponentFlagBits::eB;
106 mask |= vk::ColorComponentFlagBits::eA;
112 constexpr vk::PipelineColorBlendAttachmentState
114 vk::PipelineColorBlendAttachmentState res;
137 return vk::ShaderStageFlagBits::eVertex;
139 return vk::ShaderStageFlagBits::eFragment;
141 return vk::ShaderStageFlagBits::eCompute;
152 return vk::Format::eUndefined;
155 return vk::Format::eR8Unorm;
157 return vk::Format::eR8G8B8A8Unorm;
159 return vk::Format::eR8G8B8A8Srgb;
161 return vk::Format::eB8G8R8A8Unorm;
163 return vk::Format::eB8G8R8A8Srgb;
165 return vk::Format::eR32G32B32A32Sfloat;
167 return vk::Format::eR16G16B16A16Sfloat;
169 return vk::Format::eS8Uint;
171 return vk::Format::eD24UnormS8Uint;
173 return vk::Format::eD32SfloatS8Uint;
175 return vk::Format::eR8Unorm;
177 return vk::Format::eR8G8Unorm;
185 case vk::Format::eUndefined:
187 case vk::Format::eR8G8B8A8Unorm:
189 case vk::Format::eR8G8B8A8Srgb:
191 case vk::Format::eB8G8R8A8Unorm:
193 case vk::Format::eB8G8R8A8Srgb:
195 case vk::Format::eR32G32B32A32Sfloat:
197 case vk::Format::eR16G16B16A16Sfloat:
199 case vk::Format::eS8Uint:
201 case vk::Format::eD24UnormS8Uint:
203 case vk::Format::eD32SfloatS8Uint:
205 case vk::Format::eR8Unorm:
207 case vk::Format::eR8G8Unorm:
215 switch (sample_count) {
219 return vk::SampleCountFlagBits::e4;
228 return vk::Filter::eNearest;
230 return vk::Filter::eLinear;
240 return vk::SamplerMipmapMode::eNearest;
242 return vk::SamplerMipmapMode::eLinear;
252 return vk::SamplerAddressMode::eRepeat;
254 return vk::SamplerAddressMode::eMirroredRepeat;
256 return vk::SamplerAddressMode::eClampToEdge;
258 return vk::SamplerAddressMode::eClampToBorder;
267 return vk::ShaderStageFlagBits::eAll;
269 return vk::ShaderStageFlagBits::eFragment;
271 return vk::ShaderStageFlagBits::eCompute;
273 return vk::ShaderStageFlagBits::eVertex;
280 static_cast<int>(vk::DescriptorType::eCombinedImageSampler));
282 static_cast<int>(vk::DescriptorType::eUniformBuffer));
284 static_cast<int>(vk::DescriptorType::eStorageBuffer));
286 static_cast<int>(vk::DescriptorType::eSampledImage));
288 static_cast<int>(vk::DescriptorType::eSampler));
290 static_cast<int>(vk::DescriptorType::eInputAttachment));
298 vk::DescriptorSetLayoutBinding binding;
299 binding.binding = layout.
binding;
300 binding.descriptorCount = 1u;
307 switch (load_action) {
309 return vk::AttachmentLoadOp::eLoad;
311 return vk::AttachmentLoadOp::eClear;
313 return vk::AttachmentLoadOp::eDontCare;
320 bool is_resolve_texture) {
321 switch (store_action) {
325 return vk::AttachmentStoreOp::eStore;
329 return vk::AttachmentStoreOp::eDontCare;
333 return is_resolve_texture ? vk::AttachmentStoreOp::eStore
334 : vk::AttachmentStoreOp::eDontCare;
338 return vk::AttachmentStoreOp::eStore;
344 switch (store_action) {
356 switch (index_type) {
358 return vk::IndexType::eUint16;
360 return vk::IndexType::eUint32;
362 return vk::IndexType::eUint32;
373 return vk::PolygonMode::eFill;
375 return vk::PolygonMode::eLine;
398 return vk::PrimitiveTopology::eTriangleList;
400 return vk::PrimitiveTopology::eTriangleStrip;
402 return vk::PrimitiveTopology::eLineList;
404 return vk::PrimitiveTopology::eLineStrip;
406 return vk::PrimitiveTopology::ePointList;
408 return vk::PrimitiveTopology::eTriangleFan;
439 VK_ATTACHMENT_UNUSED, vk::ImageLayout::eUndefined};
444 return vk::CullModeFlagBits::eNone;
446 return vk::CullModeFlagBits::eFront;
448 return vk::CullModeFlagBits::eBack;
456 return vk::CompareOp::eNever;
458 return vk::CompareOp::eAlways;
460 return vk::CompareOp::eLess;
462 return vk::CompareOp::eEqual;
464 return vk::CompareOp::eLessOrEqual;
466 return vk::CompareOp::eGreater;
468 return vk::CompareOp::eNotEqual;
470 return vk::CompareOp::eGreaterOrEqual;
478 return vk::StencilOp::eKeep;
480 return vk::StencilOp::eZero;
482 return vk::StencilOp::eReplace;
484 return vk::StencilOp::eIncrementAndClamp;
486 return vk::StencilOp::eDecrementAndClamp;
488 return vk::StencilOp::eInvert;
490 return vk::StencilOp::eIncrementAndWrap;
492 return vk::StencilOp::eDecrementAndWrap;
500 vk::StencilOpState state;
509 state.reference = 1988;
528 return vk::ImageAspectFlagBits::eColor;
530 return vk::ImageAspectFlagBits::eStencil;
533 return vk::ImageAspectFlagBits::eDepth |
534 vk::ImageAspectFlagBits::eStencil;
548 <<
"kTextureExternalOES can not be used with the Vulkan backend.";
557 return vk::ImageViewType::e2D;
559 return vk::ImageViewType::eCube;
562 <<
"kTextureExternalOES can not be used with the Vulkan backend.";
573 return vk::ImageCreateFlagBits::eCubeCompatible;
576 <<
"kTextureExternalOES can not be used with the Vulkan backend.";
582 std::optional<DepthAttachmentDescriptor> depth,
583 std::optional<StencilAttachmentDescriptor> front,
584 std::optional<StencilAttachmentDescriptor> back);
602 return vk::ImageAspectFlagBits::eColor;
604 return vk::ImageAspectFlagBits::eStencil;
607 return vk::ImageAspectFlagBits::eDepth |
608 vk::ImageAspectFlagBits::eStencil;
@ kNone
Does not use the index buffer.
static constexpr vk::AttachmentReference kUnusedAttachmentReference
@ kOneMinusDestinationAlpha
@ kOneMinusDestinationColor
PrimitiveType
Decides how backend draws pixels based on input vertices.
@ kPoint
Draws a point at each input vertex.
constexpr vk::SamplerAddressMode ToVKSamplerAddressMode(SamplerAddressMode mode)
constexpr vk::PipelineColorBlendAttachmentState ToVKPipelineColorBlendAttachmentState(const ColorAttachmentDescriptor &desc)
constexpr PixelFormat ToPixelFormat(vk::Format format)
constexpr vk::CompareOp ToVKCompareOp(CompareFunction op)
constexpr vk::SamplerMipmapMode ToVKSamplerMipmapMode(MipFilter filter)
@ kDecal
decal sampling mode is only supported on devices that pass the Capabilities.SupportsDecalSamplerAddre...
constexpr bool StoreActionPerformsResolve(StoreAction store_action)
constexpr vk::IndexType ToVKIndexType(IndexType index_type)
constexpr vk::DescriptorSetLayoutBinding ToVKDescriptorSetLayoutBinding(const DescriptorSetLayout &layout)
constexpr uint32_t ToArrayLayerCount(TextureType type)
constexpr vk::Filter ToVKSamplerMinMagFilter(MinMagFilter filter)
constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format)
constexpr vk::SampleCountFlagBits ToVKSampleCountFlagBits(SampleCount count)
constexpr std::optional< vk::ShaderStageFlagBits > ToVKShaderStageFlagBits(ShaderStage stage)
constexpr vk::AttachmentLoadOp ToVKAttachmentLoadOp(LoadAction load_action)
constexpr vk::DescriptorType ToVKDescriptorType(DescriptorType type)
constexpr vk::PolygonMode ToVKPolygonMode(PolygonMode mode)
PixelFormat
The Pixel formats supported by Impeller. The naming convention denotes the usage of the component,...
@ kEqual
Comparison test passes if new_value == current_value.
@ kLessEqual
Comparison test passes if new_value <= current_value.
@ kGreaterEqual
Comparison test passes if new_value >= current_value.
@ kAlways
Comparison test passes always passes.
@ kLess
Comparison test passes if new_value < current_value.
@ kGreater
Comparison test passes if new_value > current_value.
@ kNotEqual
Comparison test passes if new_value != current_value.
@ kNever
Comparison test never passes.
constexpr vk::AttachmentStoreOp ToVKAttachmentStoreOp(StoreAction store_action, bool is_resolve_texture)
constexpr vk::CullModeFlags ToVKCullModeFlags(CullMode mode)
MipFilter
Options for selecting and filtering between mipmap levels.
@ kLinear
Sample from the two nearest mip levels and linearly interpolate.
@ kBase
The texture is sampled as if it only had a single mipmap level.
@ kNearest
The nearst mipmap level is selected.
constexpr vk::ColorComponentFlags ToVKColorComponentFlags(ColorWriteMask type)
@ kDecrementWrap
Decrement the current stencil value by 1. If at zero, set to maximum.
@ kSetToReferenceValue
Reset the stencil value to the reference value.
@ kDecrementClamp
Decrement the current stencil value by 1. Clamp it to zero.
@ kZero
Reset the stencil value to zero.
@ kIncrementClamp
Increment the current stencil value by 1. Clamp it to the maximum.
@ kIncrementWrap
Increment the current stencil value by 1. If at maximum, set to zero.
@ kInvert
Perform a logical bitwise invert on the current stencil value.
@ kKeep
Don't modify the current stencil value.
constexpr vk::BlendFactor ToVKBlendFactor(BlendFactor factor)
constexpr std::optional< PixelFormat > VkFormatToImpellerFormat(vk::Format format)
constexpr bool PixelFormatIsDepthStencil(PixelFormat format)
vk::PipelineDepthStencilStateCreateInfo ToVKPipelineDepthStencilStateCreateInfo(std::optional< DepthAttachmentDescriptor > depth, std::optional< StencilAttachmentDescriptor > front, std::optional< StencilAttachmentDescriptor > back)
constexpr bool PrimitiveTopologySupportsPrimitiveRestart(PrimitiveType primitive)
constexpr vk::ImageViewType ToVKImageViewType(TextureType type)
@ kStoreAndMultisampleResolve
constexpr vk::SampleCountFlagBits ToVKSampleCount(SampleCount sample_count)
constexpr vk::Format ToVKImageFormat(PixelFormat format)
constexpr vk::StencilOpState ToVKStencilOpState(const StencilAttachmentDescriptor &desc)
constexpr vk::ShaderStageFlags ToVkShaderStage(ShaderStage stage)
constexpr vk::PrimitiveTopology ToVKPrimitiveTopology(PrimitiveType primitive)
constexpr vk::BlendOp ToVKBlendOp(BlendOperation op)
constexpr vk::StencilOp ToVKStencilOp(StencilOperation op)
MinMagFilter
Describes how the texture should be sampled when the texture is being shrunk (minified) or expanded (...
@ kNearest
Select nearest to the sample point. Most widely supported.
constexpr vk::ImageCreateFlags ToVKImageCreateFlags(TextureType type)
constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format)
Describe the color attachment that will be used with this pipeline.
BlendOperation color_blend_op
BlendFactor dst_color_blend_factor
ColorWriteMask write_mask
BlendFactor src_alpha_blend_factor
BlendOperation alpha_blend_op
BlendFactor src_color_blend_factor
BlendFactor dst_alpha_blend_factor
DescriptorType descriptor_type
StencilOperation stencil_failure
CompareFunction stencil_compare
StencilOperation depth_failure
StencilOperation depth_stencil_pass