Index: src/gpu/gl/GrGLShaderBuilder.cpp |
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp |
index d6679dcc953b167bff549b4f5030da2d8cebf251..fe9a66ae42ff328871c5de08ad38ca92c3e0bb4b 100644 |
--- a/src/gpu/gl/GrGLShaderBuilder.cpp |
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp |
@@ -89,25 +89,6 @@ static const char kDstCopyColorName[] = "_dstColor"; |
/////////////////////////////////////////////////////////////////////////////// |
-bool GrGLShaderBuilder::GenProgram(GrGpuGL* gpu, |
- GrGLProgramDataManager* pdman, |
- const GrGLProgramDesc& desc, |
- const GrEffectStage* inColorStages[], |
- const GrEffectStage* inCoverageStages[], |
- GenProgramOutput* output) { |
- SkAutoTDelete<GrGLShaderBuilder> builder; |
- if (desc.getHeader().fHasVertexCode ||!gpu->shouldUseFixedFunctionTexturing()) { |
- builder.reset(SkNEW_ARGS(GrGLFullShaderBuilder, (gpu, pdman, desc))); |
- } else { |
- builder.reset(SkNEW_ARGS(GrGLFragmentOnlyShaderBuilder, (gpu, pdman, desc))); |
- } |
- if (builder->genProgram(inColorStages, inCoverageStages)) { |
- *output = builder->getOutput(); |
- return true; |
- } |
- return false; |
-} |
- |
bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
const GrEffectStage* coverageStages[]) { |
const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); |
@@ -125,13 +106,13 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
} else { |
configMask = kRGBA_GrColorComponentFlags; |
} |
- fOutput.fUniformHandles.fDstCopySamplerUni = |
+ fUniformHandles.fDstCopySamplerUni = |
this->addUniform(kFragment_Visibility, kSampler2D_GrSLType, "DstCopySampler", |
&dstCopySamplerName); |
- fOutput.fUniformHandles.fDstCopyTopLeftUni = |
+ fUniformHandles.fDstCopyTopLeftUni = |
this->addUniform(kFragment_Visibility, kVec2f_GrSLType, "DstCopyUpperLeft", |
&dstCopyTopLeftName); |
- fOutput.fUniformHandles.fDstCopyScaleUni = |
+ fUniformHandles.fDstCopyScaleUni = |
this->addUniform(kFragment_Visibility, kVec2f_GrSLType, "DstCopyCoordScale", |
&dstCopyCoordScaleName); |
const char* fragPos = this->fragmentPosition(); |
@@ -159,7 +140,7 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
if (GrGLProgramDesc::kUniform_ColorInput == header.fColorInput) { |
const char* name; |
- fOutput.fUniformHandles.fColorUni = |
+ fUniformHandles.fColorUni = |
this->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec4f_GrSLType, "Color", |
&name); |
inputColor = GrGLSLExpr4(name); |
@@ -167,7 +148,7 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) { |
const char* name; |
- fOutput.fUniformHandles.fCoverageUni = |
+ fUniformHandles.fCoverageUni = |
this->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec4f_GrSLType, "Coverage", |
&name); |
inputCoverage = GrGLSLExpr4(name); |
@@ -189,17 +170,17 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
GrGLProgramDesc::EffectKeyProvider colorKeyProvider( |
&this->desc(), GrGLProgramDesc::EffectKeyProvider::kColor_EffectType); |
- fOutput.fColorEffects.reset(this->createAndEmitEffects(colorStages, |
- this->desc().numColorEffects(), |
- colorKeyProvider, |
- &inputColor)); |
+ fColorEffects.reset(this->createAndEmitEffects(colorStages, |
+ this->desc().numColorEffects(), |
+ colorKeyProvider, |
+ &inputColor)); |
GrGLProgramDesc::EffectKeyProvider coverageKeyProvider( |
&this->desc(), GrGLProgramDesc::EffectKeyProvider::kCoverage_EffectType); |
- fOutput.fCoverageEffects.reset(this->createAndEmitEffects(coverageStages, |
- this->desc().numCoverageEffects(), |
- coverageKeyProvider, |
- &inputCoverage)); |
+ fCoverageEffects.reset(this->createAndEmitEffects(coverageStages, |
+ this->desc().numCoverageEffects(), |
+ coverageKeyProvider, |
+ &inputCoverage)); |
this->emitCodeAfterEffects(); |
@@ -247,11 +228,12 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
////////////////////////////////////////////////////////////////////////////// |
GrGLShaderBuilder::GrGLShaderBuilder(GrGpuGL* gpu, |
- GrGLProgramDataManager* programResourceManager, |
const GrGLProgramDesc& desc) |
- : fDesc(desc) |
+ : fHasVertexShader(false) |
+ , fTexCoordSetCnt(0) |
+ , fProgramID(0) |
+ , fDesc(desc) |
, fGpu(gpu) |
- , fProgramDataManager(SkRef(programResourceManager)) |
, fFSFeaturesAddedMask(0) |
, fFSInputs(kVarsPerBlock) |
, fFSOutputs(kMaxFSOutputs) |
@@ -315,7 +297,7 @@ const char* GrGLShaderBuilder::dstColor() { |
this->addFSFeature(1 << (kLastGLSLPrivateFeature + 1), |
fGpu->glCaps().fbFetchExtensionString()); |
return fGpu->glCaps().fbFetchColorName(); |
- } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { |
+ } else if (fUniformHandles.fDstCopySamplerUni.isValid()) { |
return kDstCopyColorName; |
} else { |
return ""; |
@@ -405,13 +387,7 @@ GrGLProgramDataManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_ |
SkASSERT(0 == (~kVisibilityMask & visibility)); |
SkASSERT(0 != visibility); |
- BuilderUniform& uni = fUniforms.push_back(); |
- UniformHandle h = GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(fUniforms.count() - 1); |
- SkDEBUGCODE(UniformHandle h2 =) |
- fProgramDataManager->appendUniform(type, count); |
- // We expect the uniform manager to initially have no uniforms and that all uniforms are added |
- // by this function. Therefore, the handles should match. |
- SkASSERT(h2 == h); |
+ UniformInfo& uni = fUniforms.push_back(); |
uni.fVariable.setType(type); |
uni.fVariable.setTypeModifier(GrGLShaderVar::kUniform_TypeModifier); |
this->nameVariable(uni.fVariable.accessName(), 'u', name); |
@@ -429,8 +405,7 @@ GrGLProgramDataManager::UniformHandle GrGLShaderBuilder::addUniformArray(uint32_ |
if (NULL != outName) { |
*outName = uni.fVariable.c_str(); |
} |
- |
- return h; |
+ return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(fUniforms.count() - 1); |
} |
SkString GrGLShaderBuilder::ensureFSCoords2D(const TransformedCoordsArray& coords, int index) { |
@@ -483,10 +458,10 @@ const char* GrGLShaderBuilder::fragmentPosition() { |
// temporarily change the stage index because we're inserting non-stage code. |
CodeStage::AutoStageRestore csar(&fCodeStage, NULL); |
- SkASSERT(!fOutput.fUniformHandles.fRTHeightUni.isValid()); |
+ SkASSERT(!fUniformHandles.fRTHeightUni.isValid()); |
const char* rtHeightName; |
- fOutput.fUniformHandles.fRTHeightUni = |
+ fUniformHandles.fRTHeightUni = |
this->addUniform(kFragment_Visibility, kFloat_GrSLType, "RTHeight", &rtHeightName); |
// Using glFragCoord.zw for the last two components tickles an Adreno driver bug that |
@@ -496,7 +471,7 @@ const char* GrGLShaderBuilder::fragmentPosition() { |
"1.0);\n", kCoordName, rtHeightName); |
fSetupFragPosition = true; |
} |
- SkASSERT(fOutput.fUniformHandles.fRTHeightUni.isValid()); |
+ SkASSERT(fUniformHandles.fRTHeightUni.isValid()); |
return kCoordName; |
} |
} |
@@ -627,25 +602,22 @@ const char* GrGLShaderBuilder::enableSecondaryOutput() { |
} |
bool GrGLShaderBuilder::finish() { |
- SkASSERT(0 == fOutput.fProgramID); |
- GL_CALL_RET(fOutput.fProgramID, CreateProgram()); |
- if (!fOutput.fProgramID) { |
+ SkASSERT(0 == fProgramID); |
+ GL_CALL_RET(fProgramID, CreateProgram()); |
+ if (!fProgramID) { |
return false; |
} |
SkTDArray<GrGLuint> shadersToDelete; |
- if (!this->compileAndAttachShaders(fOutput.fProgramID, &shadersToDelete)) { |
- GL_CALL(DeleteProgram(fOutput.fProgramID)); |
+ if (!this->compileAndAttachShaders(fProgramID, &shadersToDelete)) { |
+ GL_CALL(DeleteProgram(fProgramID)); |
return false; |
} |
- this->bindProgramLocations(fOutput.fProgramID); |
- if (fProgramDataManager->isUsingBindUniform()) { |
- fProgramDataManager->getUniformLocations(fOutput.fProgramID, fUniforms); |
- } |
+ this->bindProgramLocations(fProgramID); |
- GL_CALL(LinkProgram(fOutput.fProgramID)); |
+ GL_CALL(LinkProgram(fProgramID)); |
// Calling GetProgramiv is expensive in Chromium. Assume success in release builds. |
bool checkLinked = !fGpu->ctxInfo().isChromium(); |
@@ -654,31 +626,29 @@ bool GrGLShaderBuilder::finish() { |
#endif |
if (checkLinked) { |
GrGLint linked = GR_GL_INIT_ZERO; |
- GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_LINK_STATUS, &linked)); |
+ GL_CALL(GetProgramiv(fProgramID, GR_GL_LINK_STATUS, &linked)); |
if (!linked) { |
GrGLint infoLen = GR_GL_INIT_ZERO; |
- GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
+ GL_CALL(GetProgramiv(fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen)); |
SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger |
if (infoLen > 0) { |
// retrieve length even though we don't need it to workaround |
// bug in chrome cmd buffer param validation. |
GrGLsizei length = GR_GL_INIT_ZERO; |
- GL_CALL(GetProgramInfoLog(fOutput.fProgramID, |
+ GL_CALL(GetProgramInfoLog(fProgramID, |
infoLen+1, |
&length, |
(char*)log.get())); |
GrPrintf((char*)log.get()); |
} |
SkDEBUGFAIL("Error linking program"); |
- GL_CALL(DeleteProgram(fOutput.fProgramID)); |
- fOutput.fProgramID = 0; |
+ GL_CALL(DeleteProgram(fProgramID)); |
+ fProgramID = 0; |
return false; |
} |
} |
- if (!fProgramDataManager->isUsingBindUniform()) { |
- fProgramDataManager->getUniformLocations(fOutput.fProgramID, fUniforms); |
- } |
+ this->resolveProgramLocations(fProgramID); |
for (int i = 0; i < shadersToDelete.count(); ++i) { |
GL_CALL(DeleteShader(shadersToDelete[i])); |
@@ -776,13 +746,35 @@ bool GrGLShaderBuilder::compileAndAttachShaders(GrGLuint programId, SkTDArray<Gr |
return true; |
} |
-void GrGLShaderBuilder::bindProgramLocations(GrGLuint programId) const { |
+void GrGLShaderBuilder::bindProgramLocations(GrGLuint programId) { |
if (fHasCustomColorOutput) { |
GL_CALL(BindFragDataLocation(programId, 0, declared_color_output_name())); |
} |
if (fHasSecondaryOutput) { |
GL_CALL(BindFragDataLocationIndexed(programId, 0, 1, dual_source_output_name())); |
} |
+ // skbug.com/2056 |
+ bool usingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL; |
+ if (usingBindUniform) { |
+ int count = fUniforms.count(); |
+ for (int i = 0; i < count; ++i) { |
+ GL_CALL(BindUniformLocation(programId, i, fUniforms[i].fVariable.c_str())); |
+ fUniforms[i].fLocation = i; |
+ } |
+ } |
+} |
+ |
+void GrGLShaderBuilder::resolveProgramLocations(GrGLuint programId) { |
+ bool usingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL; |
+ if (!usingBindUniform) { |
+ int count = fUniforms.count(); |
+ for (int i = 0; i < count; ++i) { |
+ GrGLint location; |
+ GL_CALL_RET(location, |
+ GetUniformLocation(programId, fUniforms[i].fVariable.c_str())); |
+ fUniforms[i].fLocation = location; |
+ } |
+ } |
} |
const GrGLContextInfo& GrGLShaderBuilder::ctxInfo() const { |
@@ -792,9 +784,8 @@ const GrGLContextInfo& GrGLShaderBuilder::ctxInfo() const { |
//////////////////////////////////////////////////////////////////////////////// |
GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu, |
- GrGLProgramDataManager* programResourceManager, |
const GrGLProgramDesc& desc) |
- : INHERITED(gpu, programResourceManager, desc) |
+ : INHERITED(gpu, desc) |
, fVSAttrs(kVarsPerBlock) |
, fVSOutputs(kVarsPerBlock) |
, fGSInputs(kVarsPerBlock) |
@@ -804,7 +795,7 @@ GrGLFullShaderBuilder::GrGLFullShaderBuilder(GrGpuGL* gpu, |
void GrGLFullShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr4* coverage) { |
const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); |
- fOutput.fHasVertexShader = true; |
+ fHasVertexShader = true; |
fPositionVar = &fVSAttrs.push_back(); |
fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition"); |
@@ -818,7 +809,7 @@ void GrGLFullShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr |
} |
const char* viewMName; |
- fOutput.fUniformHandles.fViewMatrixUni = |
+ fUniformHandles.fViewMatrixUni = |
this->addUniform(GrGLShaderBuilder::kVertex_Visibility, kMat33f_GrSLType, "ViewM", |
&viewMName); |
@@ -854,7 +845,7 @@ void GrGLFullShaderBuilder::emitCodeBeforeEffects(GrGLSLExpr4* color, GrGLSLExpr |
void GrGLFullShaderBuilder::emitCodeAfterEffects() { |
const char* rtAdjustName; |
- fOutput.fUniformHandles.fRTAdjustmentUni = |
+ fUniformHandles.fRTAdjustmentUni = |
this->addUniform(GrGLShaderBuilder::kVertex_Visibility, kVec4f_GrSLType, "rtAdjustment", |
&rtAdjustName); |
@@ -1006,7 +997,7 @@ bool GrGLFullShaderBuilder::compileAndAttachShaders(GrGLuint programId, |
return this->INHERITED::compileAndAttachShaders(programId, shaderIds); |
} |
-void GrGLFullShaderBuilder::bindProgramLocations(GrGLuint programId) const { |
+void GrGLFullShaderBuilder::bindProgramLocations(GrGLuint programId) { |
this->INHERITED::bindProgramLocations(programId); |
const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); |
@@ -1041,9 +1032,8 @@ void GrGLFullShaderBuilder::bindProgramLocations(GrGLuint programId) const { |
//////////////////////////////////////////////////////////////////////////////// |
GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu, |
- GrGLProgramDataManager* programResourceManager, |
const GrGLProgramDesc& desc) |
- : INHERITED(gpu, programResourceManager, desc) { |
+ : INHERITED(gpu, desc) { |
SkASSERT(!desc.getHeader().fHasVertexCode); |
SkASSERT(gpu->glCaps().pathRenderingSupport()); |
SkASSERT(GrGLProgramDesc::kAttribute_ColorInput != desc.getHeader().fColorInput); |
@@ -1051,9 +1041,9 @@ GrGLFragmentOnlyShaderBuilder::GrGLFragmentOnlyShaderBuilder(GrGpuGL* gpu, |
} |
int GrGLFragmentOnlyShaderBuilder::addTexCoordSets(int count) { |
- int firstFreeCoordSet = fOutput.fTexCoordSetCnt; |
- fOutput.fTexCoordSetCnt += count; |
- SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fOutput.fTexCoordSetCnt); |
+ int firstFreeCoordSet = fTexCoordSetCnt; |
+ fTexCoordSetCnt += count; |
+ SkASSERT(gpu()->glCaps().maxFixedFunctionTextureCoords() >= fTexCoordSetCnt); |
return firstFreeCoordSet; |
} |