diff options
author | 2016-01-08 12:11:39 -0800 | |
---|---|---|
committer | 2016-01-08 12:11:39 -0800 | |
commit | 3183a4136364cfe18b3584302e71ea528a018401 (patch) | |
tree | 00dc9f7509516757e84de9c311a413743af1275f /src/gpu/gl | |
parent | defa0daa6a0f4e97a3527a522ae602c6771a7c80 (diff) |
Revert of Add a class representing texture swizzle. (patchset #6 id:100001 of https://codereview.chromium.org/1567733005/ )
Reason for revert:
Shader compilation failures when implicitly converting vec4 to float.
https://uberchromegw.corp.google.com/i/client.skia/builders/Test-Win8-MSVC-ShuttleA-GPU-GTX960-x86_64-Debug/builds/3266/steps/dm/logs/stdio
https://uberchromegw.corp.google.com/i/client.skia.android/builders/Test-Android-GCC-Nexus6-GPU-Adreno420-Arm7-Debug/builds/3154/steps/dm/logs/stdio
Original issue's description:
> Add a class representing texture swizzle.
>
> Store config swizzle GrGLCaps and shader swizzles in GrGLSLCaps.
>
> Remove GrTextureAccess's swizzle and update users of it to swizzle in their shader code.
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1567733005
>
> Committed: https://skia.googlesource.com/skia/+/1a1efeacf7cc94a8c2977114dfe230fed3efc105
TBR=egdaniel@google.com,bsalomon@google.com
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.chromium.org/1569393002
Diffstat (limited to 'src/gpu/gl')
-rw-r--r-- | src/gpu/gl/GrGLCaps.cpp | 92 | ||||
-rw-r--r-- | src/gpu/gl/GrGLCaps.h | 19 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 10 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDesc.cpp | 53 |
4 files changed, 87 insertions, 87 deletions
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 99ed042139..923c392d31 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -42,7 +42,6 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions, fIsCoreProfile = false; fBindFragDataLocationSupport = false; fExternalTextureSupport = false; - fTextureSwizzleSupport = false; fSRGBWriteControl = false; fRGBA8888PixelsOpsAreSlow = false; fPartialFBOReadIsSlow = false; @@ -219,16 +218,6 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, } } - if (kGL_GrGLStandard == standard) { - if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) { - fTextureSwizzleSupport = true; - } - } else { - if (version >= GR_GL_VER(3,0)) { - fTextureSwizzleSupport = true; - } - } - #ifdef SK_BUILD_FOR_WIN // We're assuming that on Windows Chromium we're using ANGLE. bool isANGLE = kANGLE_GrGLDriver == ctxInfo.driver() || @@ -448,14 +437,11 @@ void GrGLCaps::init(const GrContextOptions& contextOptions, } this->initShaderPrecisionTable(ctxInfo, gli, glslCaps); - - if (contextOptions.fUseShaderSwizzling) { - fTextureSwizzleSupport = false; - } - - // Requires fTextureRedSupport, fTextureSwizzleSupport, msaa support, ES compatibility have - // already been detected. - this->initConfigTable(ctxInfo, gli, glslCaps); + // Requires fTexutreSwizzleSupport and fTextureRedSupport to be set before this point. + this->initConfigSwizzleTable(ctxInfo, glslCaps); + // Requires various members are already correctly initialized (e.g. fTextureRedSupport, + // msaa support). + this->initConfigTable(ctxInfo, gli); this->applyOptionsOverrides(contextOptions); glslCaps->applyOptionsOverrides(contextOptions); @@ -880,8 +866,6 @@ SkString GrGLCaps::dump() const { r.appendf("RGBA 8888 pixel ops are slow: %s\n", (fRGBA8888PixelsOpsAreSlow ? "YES" : "NO")); r.appendf("Partial FBO read is slow: %s\n", (fPartialFBOReadIsSlow ? "YES" : "NO")); r.appendf("Bind uniform location support: %s\n", (fBindUniformLocationSupport ? "YES" : "NO")); - r.appendf("External texture support: %s\n", (fExternalTextureSupport ? "YES" : "NO")); - r.appendf("Texture swizzle support: %s\n", (fTextureSwizzleSupport ? "YES" : "NO")); r.append("Configs\n-------\n"); for (int i = 0; i < kGrPixelConfigCnt; ++i) { @@ -984,12 +968,49 @@ void GrGLCaps::initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, } } +void GrGLCaps::initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps) { + GrGLStandard standard = ctxInfo.standard(); + GrGLVersion version = ctxInfo.version(); + + glslCaps->fMustSwizzleInShader = true; + if (kGL_GrGLStandard == standard) { + if (version >= GR_GL_VER(3,3) || ctxInfo.hasExtension("GL_ARB_texture_swizzle")) { + glslCaps->fMustSwizzleInShader = false; + } + } else { + if (version >= GR_GL_VER(3,0)) { + glslCaps->fMustSwizzleInShader = false; + } + } + + glslCaps->fConfigSwizzle[kUnknown_GrPixelConfig] = nullptr; + if (fTextureRedSupport) { + glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "rrrr"; + glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "rrrr"; + } else { + glslCaps->fConfigSwizzle[kAlpha_8_GrPixelConfig] = "aaaa"; + glslCaps->fConfigSwizzle[kAlpha_half_GrPixelConfig] = "aaaa"; + } + glslCaps->fConfigSwizzle[kIndex_8_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kRGB_565_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kRGBA_4444_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kRGBA_8888_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kBGRA_8888_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kSRGBA_8888_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kETC1_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kLATC_GrPixelConfig] = "rrrr"; + glslCaps->fConfigSwizzle[kR11_EAC_GrPixelConfig] = "rrrr"; + glslCaps->fConfigSwizzle[kASTC_12x12_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kRGBA_float_GrPixelConfig] = "rgba"; + glslCaps->fConfigSwizzle[kRGBA_half_GrPixelConfig] = "rgba"; + +} + bool GrGLCaps::bgraIsInternalFormat() const { return fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fBaseInternalFormat == GR_GL_BGRA; } -void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli, - GrGLSLCaps* glslCaps) { +void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* gli) { /* Comments on renderability of configs on various GL versions. OpenGL < 3.0: @@ -1072,7 +1093,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalFormat = 0; fConfigTable[kUnknown_GrPixelConfig].fFormats.fExternalType = 0; fConfigTable[kUnknown_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; - fConfigTable[kUnknown_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_8888_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA8; @@ -1089,7 +1109,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kRGBA_8888_GrPixelConfig].fFlags |= allRenderFlags; } } - fConfigTable[kRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalFormat= GR_GL_BGRA; fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; @@ -1125,7 +1144,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa } } } - fConfigTable[kBGRA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); // We only enable srgb support if both textures and FBOs support srgb. bool srgbSupport = false; @@ -1159,7 +1177,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kSRGBA_8888_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag | allRenderFlags; } - fConfigTable[kSRGBA_8888_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kRGB_565_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGB; if (this->ES2CompatibilitySupport()) { @@ -1178,7 +1195,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa } else { fConfigTable[kRGB_565_GrPixelConfig].fFlags |= allRenderFlags; } - fConfigTable[kRGB_565_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RGBA; fConfigTable[kRGBA_4444_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_RGBA4; @@ -1193,18 +1209,15 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa } else { fConfigTable[kRGBA_4444_GrPixelConfig].fFlags |= allRenderFlags; } - fConfigTable[kRGBA_4444_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); if (this->textureRedSupport()) { fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED; fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R8; fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RED; - fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); } else { fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA; fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA8; fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalFormat = GR_GL_ALPHA; - fConfigTable[kAlpha_8_GrPixelConfig].fSwizzle = GrSwizzle::AAAA(); } fConfigTable[kAlpha_8_GrPixelConfig].fFormats.fExternalType = GR_GL_UNSIGNED_BYTE; fConfigTable[kAlpha_8_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; @@ -1260,18 +1273,15 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kRGBA_float_GrPixelConfig].fFlags |= fpRenderFlags; } } - fConfigTable[kRGBA_float_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); if (this->textureRedSupport()) { fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_RED; fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_R16F; fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_RED; - fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); } else { fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_ALPHA; fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_ALPHA16F; fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalFormat = GR_GL_ALPHA; - fConfigTable[kAlpha_half_GrPixelConfig].fSwizzle = GrSwizzle::AAAA(); } if (kGL_GrGLStandard == ctxInfo.standard() || ctxInfo.version() >= GR_GL_VER(3, 0)) { fConfigTable[kAlpha_half_GrPixelConfig].fFormats.fExternalType = GR_GL_HALF_FLOAT; @@ -1307,7 +1317,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kRGBA_half_GrPixelConfig].fFlags |= fpRenderFlags; } } - fConfigTable[kRGBA_half_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); // Compressed texture support @@ -1341,7 +1350,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa } } } - fConfigTable[kIndex_8_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); // May change the internal format based on extensions. fConfigTable[kLATC_GrPixelConfig].fFormats.fBaseInternalFormat = @@ -1370,7 +1378,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalFormat = 0; fConfigTable[kLATC_GrPixelConfig].fFormats.fExternalType = 0; fConfigTable[kLATC_GrPixelConfig].fFormatType = kNormalizedFixedPoint_FormatType; - fConfigTable[kLATC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); fConfigTable[kETC1_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; fConfigTable[kETC1_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; @@ -1390,7 +1397,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kETC1_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; } } - fConfigTable[kETC1_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_R11_EAC; fConfigTable[kR11_EAC_GrPixelConfig].fFormats.fSizedInternalFormat = GR_GL_COMPRESSED_R11_EAC; @@ -1402,7 +1408,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa if (kGLES_GrGLStandard == standard && version >= GR_GL_VER(3,0)) { fConfigTable[kR11_EAC_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; } - fConfigTable[kR11_EAC_GrPixelConfig].fSwizzle = GrSwizzle::RRRR(); fConfigTable[kASTC_12x12_GrPixelConfig].fFormats.fBaseInternalFormat = GR_GL_COMPRESSED_RGBA_ASTC_12x12; @@ -1416,7 +1421,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa ctxInfo.hasExtension("GL_OES_texture_compression_astc")) { fConfigTable[kASTC_12x12_GrPixelConfig].fFlags = ConfigInfo::kTextureable_Flag; } - fConfigTable[kASTC_12x12_GrPixelConfig].fSwizzle = GrSwizzle::RGBA(); // Bulk populate the texture internal/external formats here and then deal with exceptions below. @@ -1454,14 +1458,6 @@ void GrGLCaps::initConfigTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa fConfigTable[kBGRA_8888_GrPixelConfig].fFormats.fInternalFormatTexImage = GR_GL_BGRA; } - // If we don't have texture swizzle support then the shader generator must insert the - // swizzle into shader code. - if (!this->textureSwizzleSupport()) { - for (int i = 0; i < kGrPixelConfigCnt; ++i) { - glslCaps->fConfigTextureSwizzle[i] = fConfigTable[i].fSwizzle; - } - } - #ifdef SK_DEBUG // Make sure we initialized everything. ConfigFormats defaultEntry; diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index db60ad273a..a650348a13 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -9,10 +9,9 @@ #ifndef GrGLCaps_DEFINED #define GrGLCaps_DEFINED -#include "glsl/GrGLSL.h" #include "GrCaps.h" +#include "glsl/GrGLSL.h" #include "GrGLStencilAttachment.h" -#include "GrSwizzle.h" #include "SkChecksum.h" #include "SkTHash.h" #include "SkTArray.h" @@ -143,11 +142,6 @@ public: return fConfigTable[config].fFormats; } - /** Returns the mapping between GrPixelConfig components and GL internal format components. */ - const GrSwizzle& configSwizzle(GrPixelConfig config) const { - return fConfigTable[config].fSwizzle; - } - /** * Gets an array of legal stencil formats. These formats are not guaranteed * to be supported by the driver but are legal GLenum names given the GL @@ -313,9 +307,6 @@ public: /// Are textures with GL_TEXTURE_EXTERNAL_OES type supported. bool externalTextureSupport() const { return fExternalTextureSupport; } - /// GL_ARB_texture_swizzle - bool textureSwizzleSupport() const { return fTextureSwizzleSupport; } - /** * Is there support for enabling/disabling sRGB writes for sRGB-capable color attachments? * If false this does not mean sRGB is not supported but rather that if it is supported @@ -344,12 +335,15 @@ private: void initBlendEqationSupport(const GrGLContextInfo&); void initStencilFormats(const GrGLContextInfo&); // This must be called after initFSAASupport(). - void initConfigTable(const GrGLContextInfo&, const GrGLInterface* gli, GrGLSLCaps* glslCaps); + void initConfigTable(const GrGLContextInfo&, const GrGLInterface* gli); void initShaderPrecisionTable(const GrGLContextInfo& ctxInfo, const GrGLInterface* intf, GrGLSLCaps* glslCaps); + void initConfigSwizzleTable(const GrGLContextInfo& ctxInfo, GrGLSLCaps* glslCaps); + + SkTArray<StencilFormat, true> fStencilFormats; int fMaxFragmentUniformVectors; @@ -382,7 +376,6 @@ private: bool fPartialFBOReadIsSlow : 1; bool fBindUniformLocationSupport : 1; bool fExternalTextureSupport : 1; - bool fTextureSwizzleSupport : 1; /** Number type of the components (with out considering number of bits.) */ enum FormatType { @@ -425,8 +418,6 @@ private: kRenderableWithMSAA_Flag = 0x8, }; uint32_t fFlags; - - GrSwizzle fSwizzle; }; ConfigInfo fConfigTable[kGrPixelConfigCnt]; diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index e0b7d4aca5..49b8f3acb8 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2485,11 +2485,11 @@ static GrGLenum get_component_enum_from_char(char component) { /** If texture swizzling is available using tex parameters then it is preferred over mangling the generated shader code. This potentially allows greater reuse of cached shaders. */ static void get_tex_param_swizzle(GrPixelConfig config, - const GrGLCaps& caps, + const GrGLSLCaps& caps, GrGLenum* glSwizzle) { - const GrSwizzle& swizzle = caps.configSwizzle(config); + const char* swizzle = caps.getSwizzleMap(config); for (int i = 0; i < 4; ++i) { - glSwizzle[i] = get_component_enum_from_char(swizzle.c_str()[i]); + glSwizzle[i] = get_component_enum_from_char(swizzle[i]); } } @@ -2558,7 +2558,7 @@ void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur newTexParams.fWrapS = tile_to_gl_wrap(params.getTileModeX()); newTexParams.fWrapT = tile_to_gl_wrap(params.getTileModeY()); - get_tex_param_swizzle(texture->config(), this->glCaps(), newTexParams.fSwizzleRGBA); + get_tex_param_swizzle(texture->config(), *this->glCaps().glslCaps(), newTexParams.fSwizzleRGBA); if (setAll || newTexParams.fMagFilter != oldTexParams.fMagFilter) { this->setTextureUnit(unitIdx); GL_CALL(TexParameteri(target, GR_GL_TEXTURE_MAG_FILTER, newTexParams.fMagFilter)); @@ -2575,7 +2575,7 @@ void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTextur this->setTextureUnit(unitIdx); GL_CALL(TexParameteri(target, GR_GL_TEXTURE_WRAP_T, newTexParams.fWrapT)); } - if (this->glCaps().textureSwizzleSupport() && + if (!this->glCaps().glslCaps()->mustSwizzleInShader() && (setAll || memcmp(newTexParams.fSwizzleRGBA, oldTexParams.fSwizzleRGBA, sizeof(newTexParams.fSwizzleRGBA)))) { diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp index 032562550c..81f92eb243 100644 --- a/src/gpu/gl/GrGLProgramDesc.cpp +++ b/src/gpu/gl/GrGLProgramDesc.cpp @@ -13,23 +13,36 @@ #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" +/** + * Do we need to either map r,g,b->a or a->r. configComponentMask indicates which channels are + * present in the texture's config. swizzleComponentMask indicates the channels present in the + * shader swizzle. + */ +static bool swizzle_requires_alpha_remapping(const GrGLSLCaps& caps, GrPixelConfig config) { + if (!caps.mustSwizzleInShader()) { + // Any remapping is handled using texture swizzling not shader modifications. + return false; + } + const char* swizzleMap = caps.getSwizzleMap(config); + + return SkToBool(memcmp(swizzleMap, "rgba", 4)); +} -static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, - const GrGLSLCaps& caps) { +static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) { + uint32_t key = 0; int numTextures = proc.numTextures(); - // Need two bytes per key (swizzle and target). - int word32Count = (proc.numTextures() + 1) / 2; - if (0 == word32Count) { - return; - } - uint16_t* k16 = SkTCast<uint16_t*>(b->add32n(word32Count)); - for (int i = 0; i < numTextures; ++i) { - const GrTextureAccess& access = proc.textureAccess(i); - bool isExternal = (GR_GL_TEXTURE_EXTERNAL == - static_cast<GrGLTexture*>(access.getTexture())->target()); - k16[i] = caps.configTextureSwizzle(access.getTexture()->config()).asKey() | - (isExternal ? 0xFF00 : 0x0000); + int shift = 0; + for (int t = 0; t < numTextures; ++t) { + const GrTextureAccess& access = proc.textureAccess(t); + if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture()->config())) { + key |= 1 << shift; + } + if (GR_GL_TEXTURE_EXTERNAL == static_cast<GrGLTexture*>(access.getTexture())->target()) { + key |= 2 << shift; + } + shift += 2; } + return key; } /** @@ -38,14 +51,15 @@ static void add_texture_key(GrProcessorKeyBuilder* b, const GrProcessor& proc, * in its key (e.g. the pixel format of textures used). So we create a meta-key for * every effect using this function. It is also responsible for inserting the effect's class ID * which must be different for every GrProcessor subclass. It can fail if an effect uses too many - * transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share this - * function because it is hairy, though FPs do not have attribs, and GPs do not have transforms + * textures, transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share + * this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms */ static bool gen_meta_key(const GrProcessor& proc, const GrGLCaps& caps, uint32_t transformKey, GrProcessorKeyBuilder* b) { size_t processorKeySize = b->size(); + uint32_t textureKey = gen_texture_key(proc, caps); uint32_t classID = proc.classID(); // Currently we allow 16 bits for the class id and the overall processor key size. @@ -54,11 +68,10 @@ static bool gen_meta_key(const GrProcessor& proc, return false; } - add_texture_key(b, proc, *caps.glslCaps()); - - uint32_t* key = b->add32n(2); + uint32_t* key = b->add32n(3); key[0] = (classID << 16) | SkToU32(processorKeySize); - key[1] = transformKey; + key[1] = textureKey; + key[2] = transformKey; return true; } |