aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/GrTBackendEffectFactory.h
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-07-11 10:01:02 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-11 10:01:02 -0700
commit848faf00ec33d39ab3e31e9a11d805cae6ac6562 (patch)
tree3bc20e70f262fb5a7864796e890512b8006518ef /include/gpu/GrTBackendEffectFactory.h
parent6ca0b6a46cbe9bef3e2b9b9db813ec864efd62de (diff)
This moves us towards variable length effect keys. The overall program key now allows for it. After the header it stores an array of offsets to effect keys. This allows us to grab the effect keys to pass to effects when they generate code. It also ensures that we can't get a collision by sets of keys that are different lengths but are the same when appended together.
R=robertphillips@google.com, jvanverth@google.com, egdaniel@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/356513003
Diffstat (limited to 'include/gpu/GrTBackendEffectFactory.h')
-rw-r--r--include/gpu/GrTBackendEffectFactory.h45
1 files changed, 18 insertions, 27 deletions
diff --git a/include/gpu/GrTBackendEffectFactory.h b/include/gpu/GrTBackendEffectFactory.h
index fd14b4fa8e..cd4c0a49e9 100644
--- a/include/gpu/GrTBackendEffectFactory.h
+++ b/include/gpu/GrTBackendEffectFactory.h
@@ -26,39 +26,30 @@ public:
*/
virtual const char* name() const SK_OVERRIDE { return EffectClass::Name(); }
- /** Returns a value that identifies the GLSL shader code generated by
- a GrEffect. This enables caching of generated shaders. Part of the
- id identifies the GrEffect subclass. The remainder is based
- on the aspects of the GrEffect object's configuration that affect
- GLSL code generation. */
- virtual EffectKey glEffectKey(const GrDrawEffect& drawEffect,
- const GrGLCaps& caps) const SK_OVERRIDE {
+ /** Generates an effect's key. This enables caching of generated shaders. Part of the
+ id identifies the GrEffect subclass. The remainder is based on the aspects of the
+ GrEffect object's configuration that affect GLSL code generation. If this fails
+ then program generation should be aborted. Failure occurs if the effect uses more
+ transforms, attributes, or textures than the key has space for. */
+ virtual bool getGLEffectKey(const GrDrawEffect& drawEffect,
+ const GrGLCaps& caps,
+ GrEffectKeyBuilder* b) const SK_OVERRIDE {
SkASSERT(kIllegalEffectClassID != fEffectClassID);
EffectKey effectKey = GLEffect::GenKey(drawEffect, caps);
EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect);
-#ifdef SK_DEBUG
- static const EffectKey kIllegalEffectKeyMask = (uint16_t) (~((1U << kEffectKeyBits) - 1));
- SkASSERT(!(kIllegalEffectKeyMask & effectKey));
-
- static const EffectKey kIllegalTextureKeyMask = (uint16_t) (~((1U << kTextureKeyBits) - 1));
- SkASSERT(!(kIllegalTextureKeyMask & textureKey));
-
- static const EffectKey kIllegalTransformKeyMask = (uint16_t) (~((1U << kTransformKeyBits) - 1));
- SkASSERT(!(kIllegalTransformKeyMask & transformKey));
-
- static const EffectKey kIllegalAttribKeyMask = (uint16_t) (~((1U << kAttribKeyBits) - 1));
- SkASSERT(!(kIllegalAttribKeyMask & textureKey));
+ static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
+ if ((textureKey | transformKey | attribKey | fEffectClassID) & kMetaKeyInvalidMask) {
+ return false;
+ }
- static const EffectKey kIllegalClassIDMask = (uint16_t) (~((1U << kClassIDBits) - 1));
- SkASSERT(!(kIllegalClassIDMask & fEffectClassID));
-#endif
- return (fEffectClassID << (kEffectKeyBits+kTextureKeyBits+kTransformKeyBits+kAttribKeyBits)) |
- (attribKey << (kEffectKeyBits+kTextureKeyBits+kTransformKeyBits)) |
- (transformKey << (kEffectKeyBits+kTextureKeyBits)) |
- (textureKey << kEffectKeyBits) |
- (effectKey);
+ // effectKey must be first because it is what will be returned by
+ // GrGLProgramDesc::EffectKeyProvider and passed to the GrGLEffect as its key.
+ b->add32(effectKey);
+ b->add32(textureKey << 16 | transformKey);
+ b->add32(fEffectClassID << 16 | attribKey);
+ return true;
}
/** Returns a new instance of the appropriate *GL* implementation class