Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions impeller/core/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ enum class PixelFormat {
kB10G10R10A10XR,
// Depth and stencil formats.
kS8UInt,
kD24UnormS8Uint,
kD32FloatS8UInt,
};

Expand Down Expand Up @@ -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";
}
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/gles/texture_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions impeller/renderer/backend/metal/formats_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions impeller/renderer/backend/metal/formats_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "impeller/renderer/backend/metal/formats_mtl.h"
#include <Metal/Metal.h>

#include <memory>

Expand Down Expand Up @@ -109,6 +110,15 @@
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;
Expand Down
7 changes: 6 additions & 1 deletion impeller/renderer/backend/vulkan/capabilities_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions impeller/renderer/backend/vulkan/formats_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down