Make aggressive shader opts an option in GrUserConfig.h. Currently just controls whether color=white optimization is applied (eliminates reading color varying and modulation by color). This was already a compile time option just not exposed through user config.
git-svn-id: http://skia.googlecode.com/svn/trunk@754 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrConfig.h b/gpu/include/GrConfig.h
index 4c5ddd6..2fa0164 100644
--- a/gpu/include/GrConfig.h
+++ b/gpu/include/GrConfig.h
@@ -305,10 +305,25 @@
#define GR_GL_LOG_CALLS 0
#endif
+/**
+ * GR_STATIC_RECT_VB controls whether rects are drawn by issuing a vertex
+ * for each corner or using a static vb that is positioned by modifying the
+ * view / texture matrix.
+ */
#if !defined(GR_STATIC_RECT_VB)
#define GR_STATIC_RECT_VB 0
#endif
+/**
+ * GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
+ * for special cases. On systems where program changes are expensive this
+ * may not be advantageous. Consecutive draws may no longer use the same
+ * program.
+ */
+#if !defined(GR_AGGRESSIVE_SHADER_OPTS)
+ #define GR_AGGRESSIVE_SHADER_OPTS 0
+#endif
+
///////////////////////////////////////////////////////////////////////////////
// tail section:
//
diff --git a/gpu/include/GrUserConfig.h b/gpu/include/GrUserConfig.h
index 3484760..155dc8c 100644
--- a/gpu/include/GrUserConfig.h
+++ b/gpu/include/GrUserConfig.h
@@ -59,6 +59,12 @@
*/
//#define GR_STATIC_RECT_VB 1
+/*
+ * This causes more aggressive shader optimization. May hurt performance if
+ * switching shaders is expensive.
+ */
+//#define GR_AGGRESSIVE_SHADER_OPTS 1
+
///////////////////////////////////////////////////////////////////////////////
/*
* temporary flags (may go away soon)
diff --git a/gpu/src/GrGpuGLShaders2.cpp b/gpu/src/GrGpuGLShaders2.cpp
index 82d7d27..9aa327a 100644
--- a/gpu/src/GrGpuGLShaders2.cpp
+++ b/gpu/src/GrGpuGLShaders2.cpp
@@ -27,8 +27,6 @@
#define ATTRIBUTE_MATRIX 0
-#define SKIP_COLOR_MODULATE_OPT 0
-
#define PRINT_SHADERS 0
#define SKIP_CACHE_CHECK true
@@ -985,23 +983,23 @@
// Must initialize all fields or cache will have false negatives!
desc->fVertexLayout = fGeometrySrc.fVertexLayout;
+
+ desc->fOptFlags = 0;
+ if (kPoints_PrimitiveType != primType) {
+ desc->fOptFlags |= ProgramDesc::kNotPoints_OptFlagBit;
+ }
+#if GR_AGGRESSIVE_SHADER_OPTS
+ if (!(desc->fVertexLayout & kColor_VertexLayoutBit) &&
+ (0xffffffff == fCurrDrawState.fColor)) {
+ desc->fOptFlags |= ProgramDesc::kVertexColorAllOnes_OptFlagBit;
+ }
+#endif
+
for (int s = 0; s < kNumStages; ++s) {
StageDesc& stage = desc->fStages[s];
stage.fEnabled = VertexUsesStage(s, fGeometrySrc.fVertexLayout);
- if (primType != kPoints_PrimitiveType) {
- desc->fOptFlags = ProgramDesc::kNotPoints_OptFlagBit;
- } else {
- desc->fOptFlags = 0;
- }
- #if SKIP_COLOR_MODULATE_OPT
- if (!(desc->fVertexLayout & kColor_VertexLayoutBit) &&
- (0xffffffff == fCurrDrawState.fColor)) {
- desc->fOptFlags |= ProgramDesc::kVertexColorAllOnes_OptFlagBit;
- }
- #endif
-
if (stage.fEnabled) {
GrGLTexture* texture = (GrGLTexture*) fCurrDrawState.fTextures[s];
GrAssert(NULL != texture);