diff options
author | csmartdalton <csmartdalton@google.com> | 2017-02-08 16:14:11 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-10 16:44:43 +0000 |
commit | 6aa0e1150ecf7eb5462744a32c356a0006d63c9e (patch) | |
tree | 94c8931b45f8962830d47c02234c0d50bdfeb2a8 /src/gpu | |
parent | 1cad749b09d8f4e9a828805ad3a6b2de8c1f6bf6 (diff) |
Add support for RG float textures
Adds kRG_float_GrPixelConfig.
Also removes default labels from switches on GrPixelConfig, in order
to help guide future enumerals to handle them properly.
BUG=skia:
Change-Id: Ie80b9413b4002b666df3ef1a7a8ea4c9c29ce43b
Reviewed-on: https://skia-review.googlesource.com/8226
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrCaps.cpp | 71 | ||||
-rw-r--r-- | src/gpu/GrShaderCaps.cpp | 3 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 68 | ||||
-rw-r--r-- | src/gpu/gl/GrGLDefines.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 9 | ||||
-rw-r--r-- | src/gpu/vk/GrVkUtil.cpp | 6 |
6 files changed, 83 insertions, 76 deletions
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index 92c22b5fd2..25bcbe9ff3 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -9,6 +9,31 @@ #include "GrContextOptions.h" #include "GrWindowRectangles.h" +static const char* pixel_config_name(GrPixelConfig config) { + switch (config) { + case kUnknown_GrPixelConfig: return "Unknown"; + case kAlpha_8_GrPixelConfig: return "Alpha8"; + case kGray_8_GrPixelConfig: return "Gray8"; + case kRGB_565_GrPixelConfig: return "RGB565"; + case kRGBA_4444_GrPixelConfig: return "RGBA444"; + case kRGBA_8888_GrPixelConfig: return "RGBA8888"; + case kBGRA_8888_GrPixelConfig: return "BGRA8888"; + case kSRGBA_8888_GrPixelConfig: return "SRGBA8888"; + case kSBGRA_8888_GrPixelConfig: return "SBGRA8888"; + case kRGBA_8888_sint_GrPixelConfig: return "RGBA8888_sint"; + case kETC1_GrPixelConfig: return "ETC1"; + case kLATC_GrPixelConfig: return "LATC"; + case kR11_EAC_GrPixelConfig: return "R11EAC"; + case kASTC_12x12_GrPixelConfig: return "ASTC12x12"; + case kRGBA_float_GrPixelConfig: return "RGBAFloat"; + case kRG_float_GrPixelConfig: return "RGFloat"; + case kAlpha_half_GrPixelConfig: return "AlphaHalf"; + case kRGBA_half_GrPixelConfig: return "RGBAHalf"; + } + SkFAIL("Invalid pixel config"); + return "<invalid>"; +} + GrCaps::GrCaps(const GrContextOptions& options) { fMipMapSupport = false; fNPOTTextureTileSupport = false; @@ -167,61 +192,23 @@ SkString GrCaps::dump() const { r.appendf("Map Buffer Support : %s\n", map_flags_to_string(fMapBufferFlags).c_str()); - static const char* kConfigNames[] = { - "Unknown", // kUnknown_GrPixelConfig - "Alpha8", // kAlpha_8_GrPixelConfig, - "Gray8", // kGray_8_GrPixelConfig, - "RGB565", // kRGB_565_GrPixelConfig, - "RGBA444", // kRGBA_4444_GrPixelConfig, - "RGBA8888", // kRGBA_8888_GrPixelConfig, - "BGRA8888", // kBGRA_8888_GrPixelConfig, - "SRGBA8888", // kSRGBA_8888_GrPixelConfig, - "SBGRA8888", // kSBGRA_8888_GrPixelConfig, - "RGBA8888_sint", // kRGBA_8888_sint_GrPixelConfig, - "ETC1", // kETC1_GrPixelConfig, - "LATC", // kLATC_GrPixelConfig, - "R11EAC", // kR11_EAC_GrPixelConfig, - "ASTC12x12", // kASTC_12x12_GrPixelConfig, - "RGBAFloat", // kRGBA_float_GrPixelConfig - "AlphaHalf", // kAlpha_half_GrPixelConfig - "RGBAHalf", // kRGBA_half_GrPixelConfig - }; - GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); - GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); - GR_STATIC_ASSERT(2 == kGray_8_GrPixelConfig); - GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); - GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); - GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); - GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); - GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); - GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig); - GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig); - GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig); - GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig); - GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig); - GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig); - GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig); - GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig); - GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig); - GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); - SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false)); SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true)); - for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { + for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { GrPixelConfig config = static_cast<GrPixelConfig>(i); r.appendf("%s is renderable: %s, with MSAA: %s\n", - kConfigNames[i], + pixel_config_name(config), gNY[this->isConfigRenderable(config, false)], gNY[this->isConfigRenderable(config, true)]); } SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); - for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { + for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { GrPixelConfig config = static_cast<GrPixelConfig>(i); r.appendf("%s is uploadable to a texture: %s\n", - kConfigNames[i], + pixel_config_name(config), gNY[this->isConfigTexturable(config)]); } diff --git a/src/gpu/GrShaderCaps.cpp b/src/gpu/GrShaderCaps.cpp index 54cd3e53cd..8d26b96920 100644 --- a/src/gpu/GrShaderCaps.cpp +++ b/src/gpu/GrShaderCaps.cpp @@ -216,10 +216,11 @@ void GrShaderCaps::initSamplerPrecisionTable() { table[kR11_EAC_GrPixelConfig] = lowp; table[kASTC_12x12_GrPixelConfig] = lowp; table[kRGBA_float_GrPixelConfig] = kHigh_GrSLPrecision; + table[kRG_float_GrPixelConfig] = kHigh_GrSLPrecision; table[kAlpha_half_GrPixelConfig] = mediump; table[kRGBA_half_GrPixelConfig] = mediump; - GR_STATIC_ASSERT(17 == kGrPixelConfigCnt); + GR_STATIC_ASSERT(18 == kGrPixelConfigCnt); } } diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index cd3f478b8a..c9a24c0c0b 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -932,8 +932,9 @@ bool GrGLCaps::readPixelsSupported(GrPixelConfig surfaceConfig, // The manual does not seem to fully match the spec as the spec allows integer formats // when the bound color buffer is an integer buffer. It doesn't specify which integer // formats are allowed, so perhaps all of them are. We only use GL_RGBA_INTEGER currently. - if (readFormat != GR_GL_RED && readFormat != GR_GL_RGB && readFormat != GR_GL_RGBA && - readFormat != GR_GL_BGRA && readFormat != GR_GL_RGBA_INTEGER) { + if (readFormat != GR_GL_RED && readFormat != GR_GL_RG && readFormat != GR_GL_RGB && + readFormat != GR_GL_RGBA && readFormat != GR_GL_BGRA && + readFormat != GR_GL_RGBA_INTEGER) { return false; } // There is also a set of allowed types, but all the types we use are in the set: @@ -1819,39 +1820,32 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, } } - fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; - fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA32F; - fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = - GR_GL_RGBA; - fConfigTable[kRGBA_float_GrPixelConfig].fFormats.fExternalType = GR_GL_FLOAT; - fConfigTable[kRGBA_float_GrPixelConfig].fFormatType = kFloat_FormatType; - if (hasFPTextures) { - fConfigTable[kRGBA_float_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; - // For now we only enable rendering to float on desktop, because on ES we'd have to solve - // many precision issues and no clients actually want this yet. - if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) || - ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) { - fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags; + for (auto fpconfig : {kRGBA_float_GrPixelConfig, kRG_float_GrPixelConfig}) { + const GrGLenum format = kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA : GR_GL_RG; + fConfigTable[fpconfig].fFormats.fBaseInternalFormat = format; + fConfigTable[fpconfig].fFormats.fSizedInternalFormat = + kRGBA_float_GrPixelConfig == fpconfig ? GR_GL_RGBA32F : GR_GL_RG32F; + fConfigTable[fpconfig].fFormats.fExternalFormat[kOther_ExternalFormatUsage] = format; + fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT; + fConfigTable[fpconfig].fFormatType = kFloat_FormatType; + if (hasFPTextures) { + fConfigTable[fpconfig].fFlags = ConfigInfo::kTextureable_Flag; + // For now we only enable rendering to float on desktop, because on ES we'd have to + // solve many precision issues and no clients actually want this yet. + if (kGL_GrGLStandard == standard /* || version >= GR_GL_VER(3,2) || + ctxInfo.hasExtension("GL_EXT_color_buffer_float")*/) { + fConfigTable[fpconfig].fFlags |= fpRenderFlags; + } } - } - if (texStorageSupported) { - fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; - } - if (texelBufferSupport) { - fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; - } - fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); - - if (hasHalfFPTextures) { - fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; - // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for - // GL_RED internal format. - if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) || - (this->textureRedSupport() && - ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) { - fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags; + if (texStorageSupported) { + fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; + } + if (texelBufferSupport) { + fConfigTable[fpconfig].fFlags |= ConfigInfo::kCanUseWithTexelBuffer_Flag; } + fConfigTable[fpconfig].fSwizzle = GrSwizzle::RGBA(); } + if (this->textureRedSupport()) { fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED; fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F; @@ -1882,6 +1876,16 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, if (texStorageSupported) { fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; } + if (hasHalfFPTextures) { + fConfigTable[kAlpha_half_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; + // ES requires either 3.2 or the combination of EXT_color_buffer_half_float and support for + // GL_RED internal format. + if (kGL_GrGLStandard == standard || version >= GR_GL_VER(3, 2) || + (this->textureRedSupport() && + ctxInfo.hasExtension("GL_EXT_color_buffer_half_float"))) { + fConfigTable[kAlpha_half_GrPixelConfig].fFlags |= fpRenderFlags; + } + } fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA16F; diff --git a/src/gpu/gl/GrGLDefines.h b/src/gpu/gl/GrGLDefines.h index 54b6d74843..997726cc01 100644 --- a/src/gpu/gl/GrGLDefines.h +++ b/src/gpu/gl/GrGLDefines.h @@ -432,6 +432,7 @@ #define GR_GL_RGB_INTEGER 0x8D98 #define GR_GL_SRGB 0x8C40 #define GR_GL_RGBA 0x1908 +#define GR_GL_RG 0x8227 #define GR_GL_SRGB_ALPHA 0x8C42 #define GR_GL_RGBA_INTEGER 0x8D99 #define GR_GL_BGRA 0x80E1 @@ -513,6 +514,7 @@ #define GR_GL_SRGB8_ALPHA8 0x8C43 #define GR_GL_RGBA16F 0x881A #define GR_GL_RGBA32F 0x8814 +#define GR_GL_RG32F 0x8230 /* RGBA integer sized formats */ #define GR_GL_RGBA8I 0x8D8E diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index b9b87a16b5..102eddf3ea 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -942,10 +942,17 @@ static inline GrGLint config_alignment(GrPixelConfig config) { case kSBGRA_8888_GrPixelConfig: case kRGBA_8888_sint_GrPixelConfig: case kRGBA_float_GrPixelConfig: + case kRG_float_GrPixelConfig: return 4; - default: + case kUnknown_GrPixelConfig: + case kETC1_GrPixelConfig: + case kLATC_GrPixelConfig: + case kR11_EAC_GrPixelConfig: + case kASTC_12x12_GrPixelConfig: return 0; } + SkFAIL("Invalid pixel config"); + return 0; } static inline GrGLenum check_alloc_error(const GrSurfaceDesc& desc, diff --git a/src/gpu/vk/GrVkUtil.cpp b/src/gpu/vk/GrVkUtil.cpp index da73e5a860..ad477e3907 100644 --- a/src/gpu/vk/GrVkUtil.cpp +++ b/src/gpu/vk/GrVkUtil.cpp @@ -64,6 +64,9 @@ bool GrPixelConfigToVkFormat(GrPixelConfig config, VkFormat* format) { case kRGBA_float_GrPixelConfig: *format = VK_FORMAT_R32G32B32A32_SFLOAT; return true; + case kRG_float_GrPixelConfig: + *format = VK_FORMAT_R32G32_SFLOAT; + return true; case kRGBA_half_GrPixelConfig: *format = VK_FORMAT_R16G16B16A16_SFLOAT; return true; @@ -120,6 +123,9 @@ bool GrVkFormatToPixelConfig(VkFormat format, GrPixelConfig* config) { case VK_FORMAT_R32G32B32A32_SFLOAT: *config = kRGBA_float_GrPixelConfig; break; + case VK_FORMAT_R32G32_SFLOAT: + *config = kRG_float_GrPixelConfig; + break; case VK_FORMAT_R16G16B16A16_SFLOAT: *config = kRGBA_half_GrPixelConfig; break; |