Skip to content

Commit

Permalink
[Impeller] Fix glyph atlas uploads and renders (flutter#37691)
Browse files Browse the repository at this point in the history
  • Loading branch information
iskakaushik authored Nov 17, 2022
1 parent 832aae2 commit fa7e196
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 10 additions & 0 deletions impeller/renderer/backend/vulkan/allocator_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "impeller/renderer/backend/vulkan/device_buffer_vk.h"
#include "impeller/renderer/backend/vulkan/formats_vk.h"
#include "impeller/renderer/backend/vulkan/texture_vk.h"
#include "impeller/renderer/formats.h"

namespace impeller {

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

// Vulkan does not have an image format that is equivalent to
// `MTLPixelFormatA8Unorm`, so we use `R8Unorm` instead. Given that the
// shaders expect that alpha channel to be set in the cases, we swizzle.
// See: https://github.com/flutter/flutter/issues/115461 for more details.
if (desc.format == PixelFormat::kA8UNormInt) {
view_create_info.components.a = vk::ComponentSwizzle::eR;
view_create_info.components.r = vk::ComponentSwizzle::eA;
}

auto img_view_res = device_.createImageView(view_create_info);
if (img_view_res.result != vk::Result::eSuccess) {
VALIDATION_LOG << "Unable to create an image view: "
Expand Down
5 changes: 1 addition & 4 deletions impeller/renderer/backend/vulkan/formats_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
case PixelFormat::kUnknown:
return vk::Format::eUndefined;
case PixelFormat::kA8UNormInt:
return vk::Format::eA8B8G8R8UnormPack32;
return vk::Format::eR8Unorm;
case PixelFormat::kR8G8B8A8UNormInt:
return vk::Format::eR8G8B8A8Unorm;
case PixelFormat::kR8G8B8A8UNormIntSRGB:
Expand All @@ -164,9 +164,6 @@ constexpr PixelFormat ToPixelFormat(vk::Format format) {
case vk::Format::eUndefined:
return PixelFormat::kUnknown;

case vk::Format::eA8B8G8R8UnormPack32:
return PixelFormat::kA8UNormInt;

case vk::Format::eR8G8B8A8Unorm:
return PixelFormat::kR8G8B8A8UNormInt;

Expand Down

0 comments on commit fa7e196

Please sign in to comment.