From b7b7e5fba08399c76fa0763ec3ed49ae120b64d8 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Mon, 22 May 2017 13:23:19 -0400 Subject: [PATCH] Add fixes & test for isConfigTexturable and isConfigRenderable This CL fixes: isConfigTexturable was returning true for: kRG_float for ANGLE ES2 configs isConfigRenderable was returning true for: kAlpha_8 for ANGLE ES2 configs isConfigTexturable and isConfigRenderable were returning true for: SBGRA on ES2 The NexusPlayer was marking RGBA & RG float configs as renderable but not textureable Bug: 720325 Change-Id: If21361870dbdde8f3e09bc9dff3a394f2a329157 Reviewed-on: https://skia-review.googlesource.com/17387 Commit-Queue: Robert Phillips Reviewed-by: Brian Salomon --- include/gpu/GrCaps.h | 2 +- src/gpu/GrGpu.cpp | 1 + src/gpu/gl/GrGLCaps.cpp | 14 ++++++++----- src/gpu/vk/GrVkCaps.cpp | 7 ++++--- tests/GrSurfaceTest.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/IntTextureTest.cpp | 1 + tools/gpu/GrTest.cpp | 2 +- 7 files changed, 70 insertions(+), 10 deletions(-) diff --git a/include/gpu/GrCaps.h b/include/gpu/GrCaps.h index 17b5a23..2fb367d 100644 --- a/include/gpu/GrCaps.h +++ b/include/gpu/GrCaps.h @@ -159,7 +159,7 @@ public: int maxWindowRectangles() const { return fMaxWindowRectangles; } - virtual bool isConfigTexturable(GrPixelConfig config) const = 0; + virtual bool isConfigTexturable(GrPixelConfig) const = 0; virtual bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const = 0; virtual bool canConfigBeImageStorage(GrPixelConfig config) const = 0; diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 0f7645a..c1970af 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -378,6 +378,7 @@ bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int height, GrPixelConfig config, const SkTArray& texels) { SkASSERT(surface); + for (int currentMipLevel = 0; currentMipLevel < texels.count(); currentMipLevel++) { if (!texels[currentMipLevel].fPixels ) { return false; diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 5b6d45a..f4e5062 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -986,9 +986,10 @@ void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrG } else if (fUsesMixedSamples) { fMSFBOType = kMixedSamples_MSFBOType; } else if (ctxInfo.version() >= GR_GL_VER(3,0) || - ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample") || - ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) { + ctxInfo.hasExtension("GL_CHROMIUM_framebuffer_multisample")) { fMSFBOType = kStandard_MSFBOType; + } else if (ctxInfo.hasExtension("GL_ANGLE_framebuffer_multisample")) { + fMSFBOType = kEXT_MSFBOType; } else if (ctxInfo.hasExtension("GL_APPLE_framebuffer_multisample")) { fMSFBOType = kES_Apple_MSFBOType; } @@ -1637,7 +1638,6 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; } fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); - // sBGRA is not a "real" thing in OpenGL, but GPUs support it, and on platforms where // kN32 == BGRA, we need some way to work with it. (The default framebuffer on Windows // is in this format, for example). @@ -1649,10 +1649,11 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, GR_GL_BGRA; fConfigTable[kSBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kSBGRA_8888_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; - if (fSRGBSupport) { + if (fSRGBSupport && kGL_GrGLStandard == standard) { fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | allRenderFlags; } + if (texStorageSupported) { fConfigTable[kSBGRA_8888_GrPixelConfig].fFlags |= ConfigInfo::kCanUseTexStorage_Flag; } @@ -1803,6 +1804,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, // [half] floating point textures became part of the standard in ES3.1 / OGL 3.0. bool hasFPTextures = false; bool hasHalfFPTextures = false; + bool rgIsTexturable = false; // for now we don't support floating point MSAA on ES uint32_t fpRenderFlags = (kGL_GrGLStandard == standard) ? allRenderFlags : nonMSAARenderFlags; @@ -1810,11 +1812,13 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_ARB_texture_float")) { hasFPTextures = true; hasHalfFPTextures = true; + rgIsTexturable = true; } } else { if (version >= GR_GL_VER(3, 1)) { hasFPTextures = true; hasHalfFPTextures = true; + rgIsTexturable = true; } else { if (ctxInfo.hasExtension("GL_OES_texture_float_linear") && ctxInfo.hasExtension("GL_OES_texture_float")) { @@ -1836,7 +1840,7 @@ void GrGLCaps::initConfigTable(const GrContextOptions& contextOptions, fConfigTable[fpconfig].fFormats.fExternalType = GR_GL_FLOAT; fConfigTable[fpconfig].fFormatType = kFloat_FormatType; if (hasFPTextures) { - fConfigTable[fpconfig].fFlags = ConfigInfo::kTextureable_Flag; + fConfigTable[fpconfig].fFlags = rgIsTexturable ? ConfigInfo::kTextureable_Flag : 0; // 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) || diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 9115dae..0e5ccf0 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -318,10 +318,11 @@ void GrVkCaps::ConfigInfo::InitConfigFlags(VkFormatFeatureFlags vkFlags, uint16_ if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { *flags = *flags | kTextureable_Flag; - } - if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { - *flags = *flags | kRenderable_Flag; + // Ganesh assumes that all renderable surfaces are also texturable + if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { + *flags = *flags | kRenderable_Flag; + } } if (SkToBool(VK_FORMAT_FEATURE_BLIT_SRC_BIT & vkFlags)) { diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 99c0bec..19f2df5 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -70,4 +70,57 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { context->getGpu()->deleteTestingOnlyBackendTexture(backendTexHandle); } +#if 0 +// This test checks that the isConfigTexturable and isConfigRenderable are +// consistent with createTexture's result. +DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { + GrContext* context = ctxInfo.grContext(); + const GrCaps* caps = context->caps(); + + GrPixelConfig configs[] = { + kUnknown_GrPixelConfig, + kAlpha_8_GrPixelConfig, + kGray_8_GrPixelConfig, + kRGB_565_GrPixelConfig, + kRGBA_4444_GrPixelConfig, + kRGBA_8888_GrPixelConfig, + kBGRA_8888_GrPixelConfig, + kSRGBA_8888_GrPixelConfig, + kSBGRA_8888_GrPixelConfig, + kRGBA_8888_sint_GrPixelConfig, + kETC1_GrPixelConfig, + kRGBA_float_GrPixelConfig, + kRG_float_GrPixelConfig, + kAlpha_half_GrPixelConfig, + kRGBA_half_GrPixelConfig, + }; + SkASSERT(kGrPixelConfigCnt == SK_ARRAY_COUNT(configs)); + + GrSurfaceDesc desc; + desc.fWidth = 64; + desc.fHeight = 64; + + for (GrPixelConfig config : configs) { + for (GrSurfaceOrigin origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { + desc.fFlags = kNone_GrSurfaceFlags; + desc.fOrigin = origin; + desc.fSampleCnt = 0; + desc.fConfig = config; + + sk_sp tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); + REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigTexturable(desc.fConfig, + desc.fOrigin)); + + desc.fFlags = kRenderTarget_GrSurfaceFlag; + tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); + REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, false)); + + desc.fSampleCnt = 4; + tex = context->resourceProvider()->createTexture(desc, SkBudgeted::kNo); + REPORTER_ASSERT(reporter, SkToBool(tex.get()) == caps->isConfigRenderable(config, true)); + } + } +} +#endif + #endif diff --git a/tests/IntTextureTest.cpp b/tests/IntTextureTest.cpp index 72f05f9..bfd54ad 100644 --- a/tests/IntTextureTest.cpp +++ b/tests/IntTextureTest.cpp @@ -42,6 +42,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(IntTexture, reporter, ctxInfo) { static const size_t kRowBytes = kS * sizeof(int32_t); GrSurfaceDesc desc; + desc.fOrigin = kTopLeft_GrSurfaceOrigin; desc.fConfig = kRGBA_8888_sint_GrPixelConfig; desc.fWidth = kS; desc.fHeight = kS; diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index af1a06f..8a187f6 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -297,7 +297,7 @@ class GrPipeline; class MockCaps : public GrCaps { public: explicit MockCaps(const GrContextOptions& options) : INHERITED(options) {} - bool isConfigTexturable(GrPixelConfig config) const override { return false; } + bool isConfigTexturable(GrPixelConfig) const override { return false; } bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const override { return false; } bool canConfigBeImageStorage(GrPixelConfig) const override { return false; } bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, -- 2.7.4