[Impeller] Fix stencil buffer format selection on Vulkan backend, add support for D24UnormS8Uint (flutter/engine#45025)
Vulkan was checking for D24 and using D32. This is part of the problem on the Samsung A02. There is still some other problem. Fixes https://github.com/flutter/flutter/issues/133188
This commit is contained in:
@@ -107,6 +107,7 @@ enum class PixelFormat {
|
||||
kB10G10R10A10XR,
|
||||
// Depth and stencil formats.
|
||||
kS8UInt,
|
||||
kD24UnormS8Uint,
|
||||
kD32FloatS8UInt,
|
||||
};
|
||||
|
||||
@@ -140,6 +141,8 @@ constexpr const char* PixelFormatToString(PixelFormat format) {
|
||||
return "B10G10R10A10XR";
|
||||
case PixelFormat::kS8UInt:
|
||||
return "S8UInt";
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
return "D24UnormS8Uint";
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return "D32FloatS8UInt";
|
||||
}
|
||||
@@ -410,6 +413,8 @@ constexpr size_t BytesPerPixelForPixelFormat(PixelFormat format) {
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
case PixelFormat::kB10G10R10XR:
|
||||
return 4u;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
return 4u;
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return 5u;
|
||||
case PixelFormat::kR16G16B16A16Float:
|
||||
|
||||
@@ -119,6 +119,7 @@ struct TexImage2DData {
|
||||
break;
|
||||
case PixelFormat::kUnknown:
|
||||
case PixelFormat::kS8UInt:
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
case PixelFormat::kR8UNormInt:
|
||||
case PixelFormat::kR8G8UNormInt:
|
||||
@@ -167,6 +168,7 @@ struct TexImage2DData {
|
||||
case PixelFormat::kB8G8R8A8UNormInt:
|
||||
case PixelFormat::kB8G8R8A8UNormIntSRGB:
|
||||
case PixelFormat::kS8UInt:
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
case PixelFormat::kR8UNormInt:
|
||||
case PixelFormat::kR8G8UNormInt:
|
||||
@@ -314,6 +316,8 @@ static std::optional<GLenum> ToRenderBufferFormat(PixelFormat format) {
|
||||
return GL_RGBA16F;
|
||||
case PixelFormat::kS8UInt:
|
||||
return GL_STENCIL_INDEX8;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
return GL_DEPTH24_STENCIL8;
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return GL_DEPTH32F_STENCIL8;
|
||||
case PixelFormat::kUnknown:
|
||||
|
||||
@@ -36,6 +36,10 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
|
||||
return PixelFormat::kR16G16B16A16Float;
|
||||
case MTLPixelFormatStencil8:
|
||||
return PixelFormat::kS8UInt;
|
||||
#if !FML_OS_IOS
|
||||
case MTLPixelFormatDepth24Unorm_Stencil8:
|
||||
return PixelFormat::kD24UnormS8Uint;
|
||||
#endif // FML_OS_IOS
|
||||
case MTLPixelFormatDepth32Float_Stencil8:
|
||||
return PixelFormat::kD32FloatS8UInt;
|
||||
case MTLPixelFormatBGR10_XR_sRGB:
|
||||
@@ -50,6 +54,11 @@ constexpr PixelFormat FromMTLPixelFormat(MTLPixelFormat format) {
|
||||
return PixelFormat::kUnknown;
|
||||
}
|
||||
|
||||
/// Safe accessor for MTLPixelFormatDepth24Unorm_Stencil8.
|
||||
/// Returns PixelFormat::kUnknown if MTLPixelFormatDepth24Unorm_Stencil8 isn't
|
||||
/// supported.
|
||||
MTLPixelFormat SafeMTLPixelFormatDepth24Unorm_Stencil8();
|
||||
|
||||
/// Safe accessor for MTLPixelFormatBGR10_XR_sRGB.
|
||||
/// Returns PixelFormat::kUnknown if MTLPixelFormatBGR10_XR_sRGB isn't
|
||||
/// supported.
|
||||
@@ -87,6 +96,8 @@ constexpr MTLPixelFormat ToMTLPixelFormat(PixelFormat format) {
|
||||
return MTLPixelFormatRGBA16Float;
|
||||
case PixelFormat::kS8UInt:
|
||||
return MTLPixelFormatStencil8;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
return SafeMTLPixelFormatDepth24Unorm_Stencil8();
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return MTLPixelFormatDepth32Float_Stencil8;
|
||||
case PixelFormat::kB10G10R10XRSRGB:
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "impeller/renderer/backend/metal/formats_mtl.h"
|
||||
#include <Metal/Metal.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@@ -109,6 +110,15 @@ MTLTextureDescriptor* ToMTLTextureDescriptor(const TextureDescriptor& desc) {
|
||||
return mtl_desc;
|
||||
}
|
||||
|
||||
MTLPixelFormat SafeMTLPixelFormatDepth24Unorm_Stencil8() {
|
||||
#if !FML_OS_IOS
|
||||
if (@available(macOS 10.11, *)) {
|
||||
return MTLPixelFormatDepth24Unorm_Stencil8;
|
||||
}
|
||||
#endif // FML_OS_IOS
|
||||
return MTLPixelFormatInvalid;
|
||||
}
|
||||
|
||||
MTLPixelFormat SafeMTLPixelFormatBGR10_XR_sRGB() {
|
||||
if (@available(iOS 11, macOS 11.0, *)) {
|
||||
return MTLPixelFormatBGR10_XR_sRGB;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "impeller/base/validation.h"
|
||||
#include "impeller/core/formats.h"
|
||||
#include "impeller/renderer/backend/vulkan/vk.h"
|
||||
|
||||
namespace impeller {
|
||||
@@ -250,6 +251,7 @@ static bool PhysicalDeviceSupportsRequiredFormats(
|
||||
HasSuitableColorFormat(device, vk::Format::eB8G8R8A8Unorm);
|
||||
const auto has_depth_stencil_format =
|
||||
HasSuitableDepthStencilFormat(device, vk::Format::eS8Uint) ||
|
||||
HasSuitableDepthStencilFormat(device, vk::Format::eD32SfloatS8Uint) ||
|
||||
HasSuitableDepthStencilFormat(device, vk::Format::eD24UnormS8Uint);
|
||||
return has_color_format && has_depth_stencil_format;
|
||||
}
|
||||
@@ -337,8 +339,11 @@ bool CapabilitiesVK::SetPhysicalDevice(const vk::PhysicalDevice& device) {
|
||||
if (HasSuitableDepthStencilFormat(device, vk::Format::eS8Uint)) {
|
||||
depth_stencil_format_ = PixelFormat::kS8UInt;
|
||||
} else if (HasSuitableDepthStencilFormat(device,
|
||||
vk::Format::eD24UnormS8Uint)) {
|
||||
vk::Format::eD32SfloatS8Uint)) {
|
||||
depth_stencil_format_ = PixelFormat::kD32FloatS8UInt;
|
||||
} else if (HasSuitableDepthStencilFormat(device,
|
||||
vk::Format::eD24UnormS8Uint)) {
|
||||
depth_stencil_format_ = PixelFormat::kD24UnormS8Uint;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -157,6 +157,8 @@ constexpr vk::Format ToVKImageFormat(PixelFormat format) {
|
||||
return vk::Format::eR16G16B16A16Sfloat;
|
||||
case PixelFormat::kS8UInt:
|
||||
return vk::Format::eS8Uint;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
return vk::Format::eD24UnormS8Uint;
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return vk::Format::eD32SfloatS8Uint;
|
||||
case PixelFormat::kR8UNormInt:
|
||||
@@ -186,6 +188,8 @@ constexpr PixelFormat ToPixelFormat(vk::Format format) {
|
||||
return PixelFormat::kR16G16B16A16Float;
|
||||
case vk::Format::eS8Uint:
|
||||
return PixelFormat::kS8UInt;
|
||||
case vk::Format::eD24UnormS8Uint:
|
||||
return PixelFormat::kD24UnormS8Uint;
|
||||
case vk::Format::eD32SfloatS8Uint:
|
||||
return PixelFormat::kD32FloatS8UInt;
|
||||
case vk::Format::eR8Unorm:
|
||||
@@ -385,6 +389,7 @@ constexpr bool PixelFormatIsDepthStencil(PixelFormat format) {
|
||||
case PixelFormat::kB10G10R10A10XR:
|
||||
return false;
|
||||
case PixelFormat::kS8UInt:
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return true;
|
||||
}
|
||||
@@ -416,6 +421,7 @@ constexpr AttachmentKind AttachmentKindFromFormat(PixelFormat format) {
|
||||
return AttachmentKind::kColor;
|
||||
case PixelFormat::kS8UInt:
|
||||
return AttachmentKind::kStencil;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return AttachmentKind::kDepthStencil;
|
||||
}
|
||||
@@ -574,6 +580,7 @@ constexpr vk::ImageAspectFlags ToVKImageAspectFlags(PixelFormat format) {
|
||||
return vk::ImageAspectFlagBits::eColor;
|
||||
case PixelFormat::kS8UInt:
|
||||
return vk::ImageAspectFlagBits::eStencil;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return vk::ImageAspectFlagBits::eDepth |
|
||||
vk::ImageAspectFlagBits::eStencil;
|
||||
@@ -647,6 +654,7 @@ constexpr vk::ImageAspectFlags ToImageAspectFlags(PixelFormat format) {
|
||||
return vk::ImageAspectFlagBits::eColor;
|
||||
case PixelFormat::kS8UInt:
|
||||
return vk::ImageAspectFlagBits::eStencil;
|
||||
case PixelFormat::kD24UnormS8Uint:
|
||||
case PixelFormat::kD32FloatS8UInt:
|
||||
return vk::ImageAspectFlagBits::eDepth |
|
||||
vk::ImageAspectFlagBits::eStencil;
|
||||
|
||||
Reference in New Issue
Block a user