diff options
author | 2013-10-21 14:48:23 +0000 | |
---|---|---|
committer | 2013-10-21 14:48:23 +0000 | |
commit | 8e919add406c5d20918a7f0ca811317312e6ce67 (patch) | |
tree | ccf88d598957c568910be6f2455763bbaa435372 | |
parent | 15455b2a13e9c673ea41a32ca9205bbc21415abc (diff) |
Fix GrProgramsTest to not generate tests with too many TexCoord references
Make GrProgramsTest check how many texture coordinate sets are
available and select random effects up until the amount runs out.
Otherwise, following effect sequence would fail the shader compilation
when Skia is compiled with nv_path_rendering on (eg. when fixed
function codepath is used):
* Stage 0: TextureDomain (1 texcoord)
* Stage 1: Convolution (1 texcoord)
* Stage 2: Bitmap Alpha Threshold (2 texcoords)
* Stage 3: DisplacementMap (2 texcoords)
* Stage 4: Config Conversion (1 texcoords)
* Stage 5: Two-Point Conical Gradient (2 texcoords)
This would use more texture coordinate sets than 8, which is fairly
common amount currently.
R=bsalomon@google.com, cdalton@nvidia.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/32403002
git-svn-id: http://skia.googlecode.com/svn/trunk@11881 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.cpp | 7 | ||||
-rw-r--r-- | src/gpu/gl/GrGLShaderBuilder.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 4 | ||||
-rw-r--r-- | tests/GLProgramsTest.cpp | 21 |
6 files changed, 34 insertions, 6 deletions
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index b0435928eb..c1b3a31218 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -51,9 +51,7 @@ GrGLProgram::GrGLProgram(GrGpuGL* gpu, fColorFilterColor = GrColor_ILLEGAL; if (fDesc.getHeader().fHasVertexCode || - !fGpu->glCaps().fixedFunctionSupport() || - !fGpu->glCaps().pathRenderingSupport()) { - + !fGpu->shouldUseFixedFunctionTexturing()) { GrGLFullShaderBuilder fullBuilder(fGpu, fUniformManager, fDesc); if (this->genProgram(&fullBuilder, colorStages, coverageStages)) { fUniformHandles.fViewMatrixUni = fullBuilder.getViewMatrixUniform(); diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp index 71942404e7..4d8df4e3b7 100644 --- a/src/gpu/gl/GrGLShaderBuilder.cpp +++ b/src/gpu/gl/GrGLShaderBuilder.cpp @@ -943,6 +943,13 @@ GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu, SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fCoverageInput); } +int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) { + int firstFreeCoordSet = fNumTexCoordSets; + fNumTexCoordSets += count; + SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fNumTexCoordSets); + return firstFreeCoordSet; +} + GrGLProgramEffects* GrGLFragmentOnlyShaderBuilder::createAndEmitEffects( const GrEffectStage* effectStages[], const EffectKey effectKeys[], diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h index d7ba58e077..3eff1df050 100644 --- a/src/gpu/gl/GrGLShaderBuilder.h +++ b/src/gpu/gl/GrGLShaderBuilder.h @@ -439,7 +439,7 @@ public: GrGLFragmentOnlyShaderBuilder(GrGpuGL*, GrGLUniformManager&, const GrGLProgramDesc&); int getNumTexCoordSets() const { return fNumTexCoordSets; } - int addTexCoordSets(int count) { return (fNumTexCoordSets += count) - count; } + int addTexCoordSets(int count); virtual GrGLProgramEffects* createAndEmitEffects( const GrEffectStage* effectStages[], diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 1fd6f7dd45..108979dffc 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -2108,6 +2108,7 @@ void GrGpuGL::enableTexGen(int unitIdx, SkASSERT(this->glCaps().fixedFunctionSupport()); SkASSERT(this->caps()->pathRenderingSupport()); SkASSERT(components >= kS_TexGenComponents && components <= kSTR_TexGenComponents); + SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= unitIdx); if (GR_GL_OBJECT_LINEAR == fHWTexGenSettings[unitIdx].fMode && components == fHWTexGenSettings[unitIdx].fNumComponents && @@ -2180,6 +2181,7 @@ void GrGpuGL::enableTexGen(int unitIdx, TexGenComponents components, const SkMat void GrGpuGL::disableUnusedTexGen(int numUsedTexCoordSets) { SkASSERT(this->glCaps().fixedFunctionSupport()); + SkASSERT(this->glCaps().maxFixedFunctionTextureCoords() >= numUsedTexCoordSets); for (int i = numUsedTexCoordSets; i < fHWActiveTexGenSets; i++) { if (0 == fHWTexGenSettings[i].fNumComponents) { diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 65e82077bc..5ff34aec22 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -50,6 +50,10 @@ public: void enableTexGen(int unitIdx, TexGenComponents, const GrGLfloat* coefficients); void enableTexGen(int unitIdx, TexGenComponents, const SkMatrix& matrix); void disableUnusedTexGen(int numUsedTexCoordSets); + bool shouldUseFixedFunctionTexturing() const { + return this->glCaps().fixedFunctionSupport() && + this->glCaps().pathRenderingSupport(); + } bool programUnitTest(int maxStages); diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 13d0d2ee5b..12107f4356 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -158,6 +158,7 @@ bool GrGpuGL::programUnitTest(int maxStages) { GrGLProgramDesc pdesc; int currAttribIndex = 1; // we need to always leave room for position + int currTextureCoordSet = 0; int attribIndices[2]; GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; @@ -167,7 +168,9 @@ bool GrGpuGL::programUnitTest(int maxStages) { SkAutoSTMalloc<8, const GrEffectStage*> stages(numStages); - for (int s = 0; s < numStages; ++s) { + bool useFixedFunctionTexturing = this->shouldUseFixedFunctionTexturing(); + + for (int s = 0; s < numStages;) { SkAutoTUnref<const GrEffectRef> effect(GrEffectTestFactory::CreateStage( &random, this->getContext(), @@ -178,15 +181,29 @@ bool GrGpuGL::programUnitTest(int maxStages) { // If adding this effect would exceed the max attrib count then generate a // new random effect. if (currAttribIndex + numAttribs > GrDrawState::kMaxVertexAttribCnt) { - --s; continue; } + + + // If adding this effect would exceed the max texture coord set count then generate a + // new random effect. + if (useFixedFunctionTexturing && !(*effect)->hasVertexCode()) { + int numTransforms = (*effect)->numTransforms(); + if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) { + continue; + } + currTextureCoordSet += numTransforms; + } + + useFixedFunctionTexturing = useFixedFunctionTexturing && !(*effect)->hasVertexCode(); + for (int i = 0; i < numAttribs; ++i) { attribIndices[i] = currAttribIndex++; } GrEffectStage* stage = SkNEW_ARGS(GrEffectStage, (effect.get(), attribIndices[0], attribIndices[1])); stages[s] = stage; + ++s; } const GrTexture* dstTexture = random.nextBool() ? dummyTextures[0] : dummyTextures[1]; pdesc.setRandom(&random, |