Skip to content

Commit fa7e196

Browse files
authored
[Impeller] Fix glyph atlas uploads and renders (flutter#37691)
Fixes flutter/flutter#115461
1 parent 832aae2 commit fa7e196

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

impeller/renderer/backend/vulkan/allocator_vk.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
1313
#include "impeller/renderer/backend/vulkan/formats_vk.h"
1414
#include "impeller/renderer/backend/vulkan/texture_vk.h"
15+
#include "impeller/renderer/formats.h"
1516

1617
namespace impeller {
1718

@@ -146,6 +147,15 @@ std::shared_ptr<Texture> AllocatorVK::OnCreateTexture(
146147
view_create_info.subresourceRange.levelCount = image_create_info.mipLevels;
147148
view_create_info.subresourceRange.layerCount = image_create_info.arrayLayers;
148149

150+
// Vulkan does not have an image format that is equivalent to
151+
// `MTLPixelFormatA8Unorm`, so we use `R8Unorm` instead. Given that the
152+
// shaders expect that alpha channel to be set in the cases, we swizzle.
153+
// See: https://github.com/flutter/flutter/issues/115461 for more details.
154+
if (desc.format == PixelFormat::kA8UNormInt) {
155+
view_create_info.components.a = vk::ComponentSwizzle::eR;
156+
view_create_info.components.r = vk::ComponentSwizzle::eA;
157+
}
158+
149159
auto img_view_res = device_.createImageView(view_create_info);
150160
if (img_view_res.result != vk::Result::eSuccess) {
151161
VALIDATION_LOG << "Unable to create an image view: "

impeller/renderer/backend/vulkan/formats_vk.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
139139
case PixelFormat::kUnknown:
140140
return vk::Format::eUndefined;
141141
case PixelFormat::kA8UNormInt:
142-
return vk::Format::eA8B8G8R8UnormPack32;
142+
return vk::Format::eR8Unorm;
143143
case PixelFormat::kR8G8B8A8UNormInt:
144144
return vk::Format::eR8G8B8A8Unorm;
145145
case PixelFormat::kR8G8B8A8UNormIntSRGB:
@@ -164,9 +164,6 @@ constexpr PixelFormat ToPixelFormat(vk::Format format) {
164164
case vk::Format::eUndefined:
165165
return PixelFormat::kUnknown;
166166

167-
case vk::Format::eA8B8G8R8UnormPack32:
168-
return PixelFormat::kA8UNormInt;
169-
170167
case vk::Format::eR8G8B8A8Unorm:
171168
return PixelFormat::kR8G8B8A8UNormInt;
172169

0 commit comments

Comments
 (0)