From 69e5785d9f00f08513423833a39cbb8d5e35a72e Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Wed, 5 Dec 2018 13:38:59 -0500 Subject: [PATCH] Add RG_88 texture format Bug: skia:7903 Change-Id: I69b65fc1cfcc2cc5045bb3b75395f9a256ade278 Reviewed-on: https://skia-review.googlesource.com/c/172979 Reviewed-by: Brian Salomon Reviewed-by: Robert Phillips Commit-Queue: Jim Van Verth --- include/private/GrTypesPriv.h | 18 ++++++++++++++++++ src/gpu/GrCaps.cpp | 1 + src/gpu/GrContext.cpp | 2 ++ src/gpu/GrSwizzle.h | 1 + src/gpu/SkGr.cpp | 1 + src/gpu/gl/GrGLCaps.cpp | 30 +++++++++++++++++++++++++----- src/gpu/gl/GrGLGpu.cpp | 1 + src/gpu/mtl/GrMtlUtil.mm | 5 +++++ src/gpu/vk/GrVkCaps.cpp | 3 +++ src/gpu/vk/GrVkUtil.cpp | 6 ++++++ tests/GrSurfaceTest.cpp | 1 + 11 files changed, 64 insertions(+), 5 deletions(-) diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index c14e337459..85df63771f 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -42,6 +42,7 @@ enum GrPixelConfig { kRGBA_4444_GrPixelConfig, kRGBA_8888_GrPixelConfig, kRGB_888_GrPixelConfig, + kRG_88_GrPixelConfig, kBGRA_8888_GrPixelConfig, kSRGBA_8888_GrPixelConfig, kSBGRA_8888_GrPixelConfig, @@ -962,6 +963,7 @@ static inline GrSRGBEncoded GrPixelConfigIsSRGBEncoded(GrPixelConfig config) { case kRGB_565_GrPixelConfig: case kRGBA_4444_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kRGBA_8888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kRGBA_1010102_GrPixelConfig: @@ -991,6 +993,7 @@ static inline size_t GrBytesPerPixel(GrPixelConfig config) { return 1; case kRGB_565_GrPixelConfig: case kRGBA_4444_GrPixelConfig: + case kRG_88_GrPixelConfig: case kAlpha_half_GrPixelConfig: case kAlpha_half_as_Red_GrPixelConfig: return 2; @@ -1018,6 +1021,7 @@ static inline bool GrPixelConfigIsOpaque(GrPixelConfig config) { switch (config) { case kRGB_565_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kGray_8_GrPixelConfig: case kGray_8_as_Lum_GrPixelConfig: case kGray_8_as_Red_GrPixelConfig: @@ -1059,6 +1063,7 @@ static inline bool GrPixelConfigIsAlphaOnly(GrPixelConfig config) { case kRGBA_4444_GrPixelConfig: case kRGBA_8888_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kSRGBA_8888_GrPixelConfig: case kSBGRA_8888_GrPixelConfig: @@ -1084,6 +1089,7 @@ static inline bool GrPixelConfigIsFloatingPoint(GrPixelConfig config) { case kRGB_565_GrPixelConfig: case kRGBA_4444_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kRGBA_8888_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kSRGBA_8888_GrPixelConfig: @@ -1117,6 +1123,7 @@ static inline GrSLPrecision GrSLSamplerPrecision(GrPixelConfig config) { case kRGBA_4444_GrPixelConfig: case kRGBA_8888_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kBGRA_8888_GrPixelConfig: case kSRGBA_8888_GrPixelConfig: case kSBGRA_8888_GrPixelConfig: @@ -1148,6 +1155,7 @@ enum class GrColorType { kABGR_4444, // This name differs from SkColorType. kARGB_4444_SkColorType is misnamed. kRGBA_8888, kRGB_888x, + kRG_88, kBGRA_8888, kRGBA_1010102, kGray_8, @@ -1165,6 +1173,7 @@ static inline SkColorType GrColorTypeToSkColorType(GrColorType ct) { case GrColorType::kABGR_4444: return kARGB_4444_SkColorType; case GrColorType::kRGBA_8888: return kRGBA_8888_SkColorType; case GrColorType::kRGB_888x: return kRGB_888x_SkColorType; + case GrColorType::kRG_88: return kUnknown_SkColorType; case GrColorType::kBGRA_8888: return kBGRA_8888_SkColorType; case GrColorType::kRGBA_1010102: return kRGBA_1010102_SkColorType; case GrColorType::kGray_8: return kGray_8_SkColorType; @@ -1204,6 +1213,8 @@ static inline uint32_t GrColorTypeComponentFlags(GrColorType ct) { case GrColorType::kABGR_4444: return kRGBA_SkColorTypeComponentFlags; case GrColorType::kRGBA_8888: return kRGBA_SkColorTypeComponentFlags; case GrColorType::kRGB_888x: return kRGB_SkColorTypeComponentFlags; + case GrColorType::kRG_88: return kRed_SkColorTypeComponentFlag | + kGreen_SkColorTypeComponentFlag; case GrColorType::kBGRA_8888: return kRGBA_SkColorTypeComponentFlags; case GrColorType::kRGBA_1010102: return kRGBA_SkColorTypeComponentFlags; case GrColorType::kGray_8: return kGray_SkColorTypeComponentFlag; @@ -1233,6 +1244,7 @@ static inline int GrColorTypeBytesPerPixel(GrColorType ct) { case GrColorType::kABGR_4444: return 2; case GrColorType::kRGBA_8888: return 4; case GrColorType::kRGB_888x: return 4; + case GrColorType::kRG_88: return 2; case GrColorType::kBGRA_8888: return 4; case GrColorType::kRGBA_1010102: return 4; case GrColorType::kGray_8: return 1; @@ -1269,6 +1281,9 @@ static inline GrColorType GrPixelConfigToColorTypeAndEncoding(GrPixelConfig conf case kRGB_888_GrPixelConfig: *srgbEncoded = GrSRGBEncoded::kNo; return GrColorType::kRGB_888x; + case kRG_88_GrPixelConfig: + *srgbEncoded = GrSRGBEncoded::kNo; + return GrColorType::kRG_88; case kBGRA_8888_GrPixelConfig: *srgbEncoded = GrSRGBEncoded::kNo; return GrColorType::kBGRA_8888; @@ -1346,6 +1361,9 @@ static inline GrPixelConfig GrColorTypeToPixelConfig(GrColorType config, case GrColorType::kRGB_888x: return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig : kRGB_888_GrPixelConfig; + case GrColorType::kRG_88: + return (GrSRGBEncoded::kYes == srgbEncoded) ? kUnknown_GrPixelConfig + : kRG_88_GrPixelConfig; case GrColorType::kBGRA_8888: return (GrSRGBEncoded::kYes == srgbEncoded) ? kSBGRA_8888_GrPixelConfig diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index 562a7fce92..3fc09b462f 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -122,6 +122,7 @@ static const char* pixel_config_name(GrPixelConfig config) { case kRGBA_4444_GrPixelConfig: return "RGBA444"; case kRGBA_8888_GrPixelConfig: return "RGBA8888"; case kRGB_888_GrPixelConfig: return "RGB888"; + case kRG_88_GrPixelConfig: return "RG88"; case kBGRA_8888_GrPixelConfig: return "BGRA8888"; case kSRGBA_8888_GrPixelConfig: return "SRGBA8888"; case kSBGRA_8888_GrPixelConfig: return "SBGRA8888"; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 1b2d13c775..a9e1be1f6c 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -404,6 +404,7 @@ static bool valid_premul_config(GrPixelConfig config) { case kRGBA_4444_GrPixelConfig: return true; case kRGBA_8888_GrPixelConfig: return true; case kRGB_888_GrPixelConfig: return false; + case kRG_88_GrPixelConfig: return false; case kBGRA_8888_GrPixelConfig: return true; case kSRGBA_8888_GrPixelConfig: return true; case kSBGRA_8888_GrPixelConfig: return true; @@ -430,6 +431,7 @@ static bool valid_premul_color_type(GrColorType ct) { case GrColorType::kABGR_4444: return true; case GrColorType::kRGBA_8888: return true; case GrColorType::kRGB_888x: return false; + case GrColorType::kRG_88: return false; case GrColorType::kBGRA_8888: return true; case GrColorType::kRGBA_1010102: return true; case GrColorType::kGray_8: return false; diff --git a/src/gpu/GrSwizzle.h b/src/gpu/GrSwizzle.h index 51e01ef432..109c3a63d8 100644 --- a/src/gpu/GrSwizzle.h +++ b/src/gpu/GrSwizzle.h @@ -80,6 +80,7 @@ public: static constexpr GrSwizzle RRRR() { return GrSwizzle("rrrr"); } static constexpr GrSwizzle RRRA() { return GrSwizzle("rrra"); } static constexpr GrSwizzle BGRA() { return GrSwizzle("bgra"); } + static constexpr GrSwizzle RGRG() { return GrSwizzle("rgrg"); } private: char fSwiz[5]; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index e51925efae..261c1f9bca 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -342,6 +342,7 @@ static inline int32_t dither_range_type_for_config(GrPixelConfig dstConfig) { case kGray_8_as_Red_GrPixelConfig: case kRGBA_8888_GrPixelConfig: case kRGB_888_GrPixelConfig: + case kRG_88_GrPixelConfig: case kBGRA_8888_GrPixelConfig: return 0; case kRGB_565_GrPixelConfig: diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index f90a1b0cbf..5f1fdbfb17 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -1299,7 +1299,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, ES 2.0 color renderable: RGBA4, RGB5_A1, RGB565 - GL_EXT_texture_rg adds support for R8, RG5 as a color render target + GL_EXT_texture_rg adds support for R8, RG8 as a color render target GL_OES_rgb8_rgba8 adds support for RGB8 and RGBA8 GL_ARM_rgba8 adds support for RGBA8 (but not RGB8) GL_EXT_texture_format_BGRA8888 does not add renderbuffer support @@ -1463,6 +1463,27 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kRGB_888_GrPixelConfig].fFlags = 0; } + // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format + // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions. + bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0); + + fConfigTable[kRG_88_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RG; + fConfigTable[kRG_88_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RG8; + fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = + GR_GL_RG; + fConfigTable[kRG_88_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; + fConfigTable[kRG_88_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; + if (textureRedSupport) { + fConfigTable[kRG_88_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | allRenderFlags; + // ES2 Command Buffer does not allow TexStorage with RG8_EXT + if (texStorageSupported && !isCommandBufferES2) { + fConfigTable[kRG_88_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; + } + } else { + fConfigTable[kRG_88_GrPixelConfig].fFlags = 0; + } + fConfigTable[kRG_88_GrPixelConfig].fSwizzle = GrSwizzle::RGRG(); + fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat[kReadPixels_ExternalFormatUsage] = GR_GL_BGRA; fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; @@ -1556,10 +1577,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fSRGBSupport = false; } - // ES2 Command Buffer has several TexStorage restrictions. It appears to fail for any format - // not explicitly allowed by GL_EXT_texture_storage, particularly those from other extensions. - bool isCommandBufferES2 = kChromium_GrGLDriver == ctxInfo.driver() && version < GR_GL_VER(3, 0); - uint32_t srgbRenderFlags = allRenderFlags; if (disableSRGBRenderWithMSAAForMacAMD) { srgbRenderFlags &= ~ConfigInfo::kRenderableWithMSAA_Flag; @@ -2966,6 +2983,9 @@ static bool get_yuva_config(GrGLenum format, GrPixelConfig* config) { case GR_GL_R8: *config = kAlpha_8_as_Red_GrPixelConfig; break; + case GR_GL_RG8: + *config = kRG_88_GrPixelConfig; + break; case GR_GL_RGBA8: *config = kRGBA_8888_GrPixelConfig; break; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index d344c3b44c..66c5fab5ab 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -834,6 +834,7 @@ static inline GrGLint config_alignment(GrPixelConfig config) { return 1; case kRGB_565_GrPixelConfig: case kRGBA_4444_GrPixelConfig: + case kRG_88_GrPixelConfig: case kAlpha_half_GrPixelConfig: case kAlpha_half_as_Red_GrPixelConfig: case kRGBA_half_GrPixelConfig: diff --git a/src/gpu/mtl/GrMtlUtil.mm b/src/gpu/mtl/GrMtlUtil.mm index f544421adc..c897d07262 100644 --- a/src/gpu/mtl/GrMtlUtil.mm +++ b/src/gpu/mtl/GrMtlUtil.mm @@ -33,6 +33,9 @@ bool GrPixelConfigToMTLFormat(GrPixelConfig config, MTLPixelFormat* format) { case kRGB_888_GrPixelConfig: // TODO: MTLPixelFormatRGB8Unorm return false; + case kRG_88_GrPixelConfig: + // TODO: MTLPixelFormatRG8Unorm + return false; case kBGRA_8888_GrPixelConfig: *format = MTLPixelFormatBGRA8Unorm; return true; @@ -107,6 +110,8 @@ GrPixelConfig GrMTLFormatToPixelConfig(MTLPixelFormat format) { case MTLPixelFormatABGR4Unorm: return kRGBA_4444_GrPixelConfig; #endif + case MTLPixelFormatRG8Unorm: + return kRG_88_GrPixelConfig; case MTLPixelFormatR8Unorm: // We currently set this to be Alpha_8 and have no way to go to Gray_8 return kAlpha_8_GrPixelConfig; diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 75911b6fde..bd35eb9c95 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -837,6 +837,9 @@ static bool get_yuva_config(VkFormat vkFormat, GrPixelConfig* config) { case VK_FORMAT_R8G8B8_UNORM: *config = kRGB_888_GrPixelConfig; break; + case VK_FORMAT_R8G8_UNORM: + *config = kRG_88_GrPixelConfig; + break; case VK_FORMAT_B8G8R8A8_UNORM: *config = kBGRA_8888_GrPixelConfig; break; diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index 674a1b9df8..6a51359b9e 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -25,6 +25,9 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { case kRGB_888_GrPixelConfig: *format = VK_FORMAT_R8G8B8_UNORM; return true; + case kRG_88_GrPixelConfig: + *format = VK_FORMAT_R8G8_UNORM; + return true; case kBGRA_8888_GrPixelConfig: *format = VK_FORMAT_B8G8R8A8_UNORM; return true; @@ -88,6 +91,8 @@ bool GrVkFormatPixelConfigPairIsValid(VkFormat format, GrPixelConfig config) { return kSBGRA_8888_GrPixelConfig == config; case VK_FORMAT_R8G8B8_UNORM: return kRGB_888_GrPixelConfig == config; + case VK_FORMAT_R8G8_UNORM: + return kRG_88_GrPixelConfig == config; case VK_FORMAT_A2B10G10R10_UNORM_PACK32: return kRGBA_1010102_GrPixelConfig == config; case VK_FORMAT_R5G6B5_UNORM_PACK16: @@ -124,6 +129,7 @@ bool GrVkFormatIsSupported(VkFormat format) { case VK_FORMAT_B8G8R8A8_SRGB: case VK_FORMAT_R8G8B8A8_SINT: case VK_FORMAT_R8G8B8_UNORM: + case VK_FORMAT_R8G8_UNORM: case VK_FORMAT_A2B10G10R10_UNORM_PACK32: case VK_FORMAT_R5G6B5_UNORM_PACK16: case VK_FORMAT_B4G4R4A4_UNORM_PACK16: diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 693fc54f42..39cfbc4679 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -86,6 +86,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { kRGBA_4444_GrPixelConfig, kRGBA_8888_GrPixelConfig, kRGB_888_GrPixelConfig, + kRG_88_GrPixelConfig, kBGRA_8888_GrPixelConfig, kSRGBA_8888_GrPixelConfig, kSBGRA_8888_GrPixelConfig,