aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-07-21 08:03:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-21 08:03:14 -0700
commit63e99f7a03b2ac90ae7a00232674fd39c0bdcc68 (patch)
tree9fcb7021404fdae422202dfff1e4a4e12106fb8c /src/gpu/gl
parent3f8540346df30f2b681bcffd42edac15d609aec4 (diff)
Allow GrGLEffects to produce variable length keys.
R=robertphillips@google.com, jvanverth@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/385713005
Diffstat (limited to 'src/gpu/gl')
-rw-r--r--src/gpu/gl/GrGLEffect.h15
-rw-r--r--src/gpu/gl/GrGLProgramDesc.h18
-rw-r--r--src/gpu/gl/GrGLProgramEffects.cpp41
-rw-r--r--src/gpu/gl/GrGLProgramEffects.h23
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.h1
-rw-r--r--src/gpu/gl/GrGLVertexEffect.h4
6 files changed, 48 insertions, 54 deletions
diff --git a/src/gpu/gl/GrGLEffect.h b/src/gpu/gl/GrGLEffect.h
index 0727372e62..f9235db238 100644
--- a/src/gpu/gl/GrGLEffect.h
+++ b/src/gpu/gl/GrGLEffect.h
@@ -20,7 +20,7 @@ class GrGLShaderBuilder;
include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the
GLSL code that implements a GrEffect and for uploading uniforms at draw time. If they don't
always emit the same GLSL code, they must have a function:
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&)
+ static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*)
that is used to implement a program cache. When two GrEffects produce the same key this means
that their GrGLEffects would emit the same GLSL code.
@@ -39,7 +39,6 @@ class GrGLVertexEffect;
class GrGLEffect {
public:
- typedef GrBackendEffectFactory::EffectKey EffectKey;
typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
typedef GrGLProgramEffects::TextureSampler TextureSampler;
typedef GrGLProgramEffects::TextureSamplerArray TextureSamplerArray;
@@ -58,8 +57,6 @@ public:
@param builder Interface used to emit code in the shaders.
@param drawEffect A wrapper on the effect that generated this program stage.
@param key The key that was computed by GenKey() from the generating GrEffect.
- Only the bits indicated by GrBackendEffectFactory::kEffectKeyBits are
- guaranteed to match the value produced by GenKey();
@param outputColor A predefined vec4 in the FS in which the stage should place its output
color (or coverage).
@param inputColor A vec4 that holds the input color to the stage in the FS. This may be
@@ -73,24 +70,24 @@ public:
*/
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
- EffectKey key,
+ const GrEffectKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) = 0;
/** A GrGLEffect instance can be reused with any GrEffect that produces the same stage
- key; this function reads data from a stage and uploads any uniform variables required
- by the shaders created in emitCode(). The GrEffect installed in the GrEffectStage is
+ key; this function reads data from a GrEffect and uploads any uniform variables required
+ by the shaders created in emitCode(). The GrEffect installed in the GrDrawEffect is
guaranteed to be of the same type that created this GrGLEffect and to have an identical
- EffectKey as the one that created this GrGLEffect. Effects that use local coords have
+ effect key as the one that created this GrGLEffect. Effects that use local coords have
to consider whether the GrEffectStage's coord change matrix should be used. When explicit
local coordinates are used it can be ignored. */
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) {}
const char* name() const { return fFactory.name(); }
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
+ static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuilder*) {}
/** Used by the system when generating shader code, to see if this effect can be downcasted to
the internal GrGLVertexEffect type */
diff --git a/src/gpu/gl/GrGLProgramDesc.h b/src/gpu/gl/GrGLProgramDesc.h
index c8aae19503..a8d27ab269 100644
--- a/src/gpu/gl/GrGLProgramDesc.h
+++ b/src/gpu/gl/GrGLProgramDesc.h
@@ -24,9 +24,7 @@ class GrGpuGL;
/** This class describes a program to generate. It also serves as a program cache key. Very little
- of this is GL-specific. There is the generation of GrGLEffect::EffectKeys and the dst-read part
- of the key set by GrGLShaderBuilder. If the interfaces that set those portions were abstracted
- to be API-neutral then so could this class. */
+ of this is GL-specific. The GL-specific parts could be factored out into a subclass. */
class GrGLProgramDesc {
public:
GrGLProgramDesc() {}
@@ -196,8 +194,6 @@ private:
return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
}
- typedef GrBackendEffectFactory::EffectKey EffectKey;
-
KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); }
// Shared code between setRandom() and Build().
@@ -227,13 +223,17 @@ private:
fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects();
}
- EffectKey get(int index) const {
- const uint16_t* offsets = reinterpret_cast<const uint16_t*>(
+ GrEffectKey get(int index) const {
+ const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*>(
fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset);
// We store two uint16_ts per effect, one for the offset to the effect's key and one for
// its length. Here we just need the offset.
- uint16_t offset = offsets[2 * (fBaseIndex + index)];
- return *reinterpret_cast<const EffectKey*>(fDesc->fKey.begin() + offset);
+ uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0];
+ uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1];
+ // Currently effects must add to the key in units of uint32_t.
+ SkASSERT(0 == (length % sizeof(uint32_t)));
+ return GrEffectKey(reinterpret_cast<const uint32_t*>(fDesc->fKey.begin() + offset),
+ length / sizeof(uint32_t));
}
private:
const GrGLProgramDesc* fDesc;
diff --git a/src/gpu/gl/GrGLProgramEffects.cpp b/src/gpu/gl/GrGLProgramEffects.cpp
index 9936aa54ad..05b15013c2 100644
--- a/src/gpu/gl/GrGLProgramEffects.cpp
+++ b/src/gpu/gl/GrGLProgramEffects.cpp
@@ -12,7 +12,6 @@
#include "gl/GrGLVertexEffect.h"
#include "gl/GrGpuGL.h"
-typedef GrGLProgramEffects::EffectKey EffectKey;
typedef GrGLProgramEffects::TransformedCoords TransformedCoords;
typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
typedef GrGLProgramEffects::TextureSampler TextureSampler;
@@ -69,7 +68,7 @@ inline bool swizzle_requires_alpha_remapping(const GrGLCaps& caps,
/**
* Retrieves the matrix type from transformKey for the transform at transformIdx.
*/
-MatrixType get_matrix_type(EffectKey transformKey, int transformIdx) {
+MatrixType get_matrix_type(uint32_t transformKey, int transformIdx) {
return static_cast<MatrixType>(
(transformKey >> (kTransformKeyBits * transformIdx)) & kMatrixTypeKeyMask);
}
@@ -79,7 +78,7 @@ MatrixType get_matrix_type(EffectKey transformKey, int transformIdx) {
* the same coordinate set as the original GrCoordTransform if the position and local coords are
* identical for this program.
*/
-GrCoordSet get_source_coords(EffectKey transformKey, int transformIdx) {
+GrCoordSet get_source_coords(uint32_t transformKey, int transformIdx) {
return (transformKey >> (kTransformKeyBits * transformIdx)) & kPositionCoords_Flag ?
kPosition_GrCoordSet :
kLocal_GrCoordSet;
@@ -117,9 +116,9 @@ SkMatrix get_transform_matrix(const GrDrawEffect& drawEffect, int transformIdx)
bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps,
GrEffectKeyBuilder* b) {
- EffectKey textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
- EffectKey transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
- EffectKey attribKey = GrGLProgramEffects::GenAttribKey(drawEffect);
+ uint32_t textureKey = GrGLProgramEffects::GenTextureKey(drawEffect, caps);
+ uint32_t transformKey = GrGLProgramEffects::GenTransformKey(drawEffect);
+ uint32_t attribKey = GrGLProgramEffects::GenAttribKey(drawEffect);
uint32_t classID = drawEffect.effect()->getFactory().effectClassID();
// Currently we allow 16 bits for each of the above portions of the meta-key. Fail if they
@@ -135,24 +134,24 @@ bool GrGLProgramEffects::GenEffectMetaKey(const GrDrawEffect& drawEffect, const
return true;
}
-EffectKey GrGLProgramEffects::GenAttribKey(const GrDrawEffect& drawEffect) {
- EffectKey key = 0;
+uint32_t GrGLProgramEffects::GenAttribKey(const GrDrawEffect& drawEffect) {
+ uint32_t key = 0;
int numAttributes = drawEffect.getVertexAttribIndexCount();
SkASSERT(numAttributes <= 2);
const int* attributeIndices = drawEffect.getVertexAttribIndices();
for (int a = 0; a < numAttributes; ++a) {
- EffectKey value = attributeIndices[a] << 3 * a;
+ uint32_t value = attributeIndices[a] << 3 * a;
SkASSERT(0 == (value & key)); // keys for each attribute ought not to overlap
key |= value;
}
return key;
}
-EffectKey GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) {
- EffectKey totalKey = 0;
+uint32_t GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) {
+ uint32_t totalKey = 0;
int numTransforms = drawEffect.effect()->numTransforms();
for (int t = 0; t < numTransforms; ++t) {
- EffectKey key = 0;
+ uint32_t key = 0;
const GrCoordTransform& coordTransform = drawEffect.effect()->coordTransform(t);
SkMatrix::TypeMask type0 = coordTransform.getMatrix().getType();
SkMatrix::TypeMask type1;
@@ -182,8 +181,8 @@ EffectKey GrGLProgramEffects::GenTransformKey(const GrDrawEffect& drawEffect) {
return totalKey;
}
-EffectKey GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps) {
- EffectKey key = 0;
+uint32_t GrGLProgramEffects::GenTextureKey(const GrDrawEffect& drawEffect, const GrGLCaps& caps) {
+ uint32_t key = 0;
int numTextures = drawEffect.effect()->numTextures();
for (int t = 0; t < numTextures; ++t) {
const GrTextureAccess& access = drawEffect.effect()->textureAccess(t);
@@ -250,7 +249,7 @@ void GrGLProgramEffects::bindTextures(GrGpuGL* gpu, const GrEffect* effect, int
void GrGLVertexProgramEffects::emitEffect(GrGLFullShaderBuilder* builder,
const GrEffectStage& stage,
- EffectKey key,
+ const GrEffectKey& key,
const char* outColor,
const char* inColor,
int stageIndex) {
@@ -301,7 +300,7 @@ void GrGLVertexProgramEffects::emitTransforms(GrGLFullShaderBuilder* builder,
const GrDrawEffect& drawEffect,
TransformedCoordsArray* outCoords) {
SkTArray<Transform, true>& transforms = fTransforms.push_back();
- EffectKey totalKey = GenTransformKey(drawEffect);
+ uint32_t totalKey = GenTransformKey(drawEffect);
int numTransforms = drawEffect.effect()->numTransforms();
transforms.push_back_n(numTransforms);
for (int t = 0; t < numTransforms; t++) {
@@ -396,7 +395,7 @@ GrGLVertexProgramEffectsBuilder::GrGLVertexProgramEffectsBuilder(GrGLFullShaderB
}
void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
- GrGLProgramEffects::EffectKey key,
+ const GrEffectKey& key,
const char* outColor,
const char* inColor,
int stageIndex) {
@@ -408,7 +407,7 @@ void GrGLVertexProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
void GrGLPathTexGenProgramEffects::emitEffect(GrGLFragmentOnlyShaderBuilder* builder,
const GrEffectStage& stage,
- EffectKey key,
+ const GrEffectKey& key,
const char* outColor,
const char* inColor,
int stageIndex) {
@@ -439,7 +438,7 @@ void GrGLPathTexGenProgramEffects::setupPathTexGen(GrGLFragmentOnlyShaderBuilder
const GrDrawEffect& drawEffect,
TransformedCoordsArray* outCoords) {
int numTransforms = drawEffect.effect()->numTransforms();
- EffectKey totalKey = GenTransformKey(drawEffect);
+ uint32_t totalKey = GenTransformKey(drawEffect);
int texCoordIndex = builder->addTexCoordSets(numTransforms);
SkNEW_APPEND_TO_TARRAY(&fTransforms, Transforms, (totalKey, texCoordIndex));
SkString name;
@@ -469,7 +468,7 @@ void GrGLPathTexGenProgramEffects::setData(GrGpuGL* gpu,
void GrGLPathTexGenProgramEffects::setPathTexGenState(GrGpuGL* gpu,
const GrDrawEffect& drawEffect,
int effectIdx) {
- EffectKey totalKey = fTransforms[effectIdx].fTransformKey;
+ uint32_t totalKey = fTransforms[effectIdx].fTransformKey;
int texCoordIndex = fTransforms[effectIdx].fTexCoordIndex;
int numTransforms = drawEffect.effect()->numTransforms();
for (int t = 0; t < numTransforms; ++t) {
@@ -502,7 +501,7 @@ GrGLPathTexGenProgramEffectsBuilder::GrGLPathTexGenProgramEffectsBuilder(
}
void GrGLPathTexGenProgramEffectsBuilder::emitEffect(const GrEffectStage& stage,
- GrGLProgramEffects::EffectKey key,
+ const GrEffectKey& key,
const char* outColor,
const char* inColor,
int stageIndex) {
diff --git a/src/gpu/gl/GrGLProgramEffects.h b/src/gpu/gl/GrGLProgramEffects.h
index c4d884392a..c9ba9135a9 100644
--- a/src/gpu/gl/GrGLProgramEffects.h
+++ b/src/gpu/gl/GrGLProgramEffects.h
@@ -27,7 +27,6 @@ class GrGLFragmentOnlyShaderBuilder;
*/
class GrGLProgramEffects : public SkRefCnt {
public:
- typedef GrBackendEffectFactory::EffectKey EffectKey;
typedef GrGLUniformManager::UniformHandle UniformHandle;
/**
@@ -104,9 +103,9 @@ protected:
/**
* Helpers for GenEffectMetaKey.
*/
- static EffectKey GenAttribKey(const GrDrawEffect&);
- static EffectKey GenTransformKey(const GrDrawEffect&);
- static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
+ static uint32_t GenAttribKey(const GrDrawEffect&);
+ static uint32_t GenTransformKey(const GrDrawEffect&);
+ static uint32_t GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
GrGLProgramEffects(int reserveCount)
: fGLEffects(reserveCount)
@@ -149,7 +148,7 @@ public:
* Emits the effect's shader code, and stores the necessary uniforms internally.
*/
virtual void emitEffect(const GrEffectStage&,
- GrGLProgramEffects::EffectKey,
+ const GrEffectKey&,
const char* outColor,
const char* inColor,
int stageIndex) = 0;
@@ -181,7 +180,7 @@ private:
*/
void emitEffect(GrGLFullShaderBuilder*,
const GrEffectStage&,
- GrGLProgramEffects::EffectKey,
+ const GrEffectKey&,
const char* outColor,
const char* inColor,
int stageIndex);
@@ -228,7 +227,7 @@ public:
virtual ~GrGLVertexProgramEffectsBuilder() { }
virtual void emitEffect(const GrEffectStage&,
- GrGLProgramEffects::EffectKey,
+ const GrEffectKey&,
const char* outColor,
const char* inColor,
int stageIndex) SK_OVERRIDE;
@@ -272,7 +271,7 @@ private:
*/
void emitEffect(GrGLFragmentOnlyShaderBuilder*,
const GrEffectStage&,
- GrGLProgramEffects::EffectKey,
+ const GrEffectKey&,
const char* outColor,
const char* inColor,
int stageIndex);
@@ -295,10 +294,10 @@ private:
void setPathTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx);
struct Transforms {
- Transforms(EffectKey transformKey, int texCoordIndex)
+ Transforms(uint32_t transformKey, int texCoordIndex)
: fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {}
- EffectKey fTransformKey;
- int fTexCoordIndex;
+ uint32_t fTransformKey;
+ int fTexCoordIndex;
};
SkTArray<Transforms> fTransforms;
@@ -315,7 +314,7 @@ public:
virtual ~GrGLPathTexGenProgramEffectsBuilder() { }
virtual void emitEffect(const GrEffectStage&,
- GrGLProgramEffects::EffectKey,
+ const GrEffectKey&,
const char* outColor,
const char* inColor,
int stageIndex) SK_OVERRIDE;
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index c28cd0999b..73e9a8f803 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -31,7 +31,6 @@ class GrGLProgramDesc;
class GrGLShaderBuilder {
public:
typedef GrTAllocator<GrGLShaderVar> VarArray;
- typedef GrBackendEffectFactory::EffectKey EffectKey;
typedef GrGLProgramEffects::TextureSampler TextureSampler;
typedef GrGLProgramEffects::TransformedCoordsArray TransformedCoordsArray;
typedef GrGLUniformManager::BuilderUniform BuilderUniform;
diff --git a/src/gpu/gl/GrGLVertexEffect.h b/src/gpu/gl/GrGLVertexEffect.h
index 40b4b34004..eba1fbe795 100644
--- a/src/gpu/gl/GrGLVertexEffect.h
+++ b/src/gpu/gl/GrGLVertexEffect.h
@@ -26,7 +26,7 @@ public:
*/
virtual void emitCode(GrGLFullShaderBuilder* builder,
const GrDrawEffect& drawEffect,
- EffectKey key,
+ const GrEffectKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,
@@ -37,7 +37,7 @@ public:
*/
virtual void emitCode(GrGLShaderBuilder* builder,
const GrDrawEffect& drawEffect,
- EffectKey key,
+ const GrEffectKey& key,
const char* outputColor,
const char* inputColor,
const TransformedCoordsArray& coords,