Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3ffa7af

Browse files
csmartdalton86Skia Commit-Bot
authored andcommitted
Split uniform and texture uptades to different methods in GrGLProgram
Change-Id: Iaa167642a0593836773c256737e1828b38beeef7 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272504 Commit-Queue: Chris Dalton <[email protected]> Reviewed-by: Brian Salomon <[email protected]>
1 parent df283d0 commit 3ffa7af

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

src/gpu/gl/GrGLGpu.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,12 @@ bool GrGLGpu::flushGLState(GrRenderTarget* renderTarget, const GrProgramInfo& pr
18271827
this->flushBlendAndColorWrite(programInfo.pipeline().getXferProcessor().getBlendInfo(),
18281828
programInfo.pipeline().outputSwizzle());
18291829

1830-
fHWProgram->updateUniformsAndTextureBindings(renderTarget, programInfo);
1830+
fHWProgram->updateUniforms(renderTarget, programInfo);
1831+
if (!programInfo.hasDynamicPrimProcTextures()) {
1832+
auto* primProcTextures = (programInfo.hasFixedPrimProcTextures())
1833+
? programInfo.fixedPrimProcTextures() : nullptr;
1834+
fHWProgram->bindTextures(programInfo.primProc(), programInfo.pipeline(), primProcTextures);
1835+
}
18311836

18321837
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
18331838
GrStencilSettings stencil;
@@ -2374,9 +2379,8 @@ void GrGLGpu::drawMeshes(GrRenderTarget* renderTarget, const GrProgramInfo& prog
23742379
glRT->width(), glRT->height(), programInfo.origin());
23752380
}
23762381
if (hasDynamicPrimProcTextures) {
2377-
auto texProxyArray = programInfo.dynamicPrimProcTextures(m);
2378-
fHWProgram->updatePrimitiveProcessorTextureBindings(programInfo.primProc(),
2379-
texProxyArray);
2382+
fHWProgram->bindTextures(programInfo.primProc(), programInfo.pipeline(),
2383+
programInfo.dynamicPrimProcTextures(m));
23802384
}
23812385
if (this->glCaps().requiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines() &&
23822386
GrIsPrimTypeLines(programInfo.primitiveType()) &&

src/gpu/gl/GrGLProgram.cpp

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,63 +73,60 @@ void GrGLProgram::abandon() {
7373

7474
///////////////////////////////////////////////////////////////////////////////
7575

76-
void GrGLProgram::updateUniformsAndTextureBindings(const GrRenderTarget* renderTarget,
77-
const GrProgramInfo& programInfo) {
78-
76+
void GrGLProgram::updateUniforms(const GrRenderTarget* renderTarget,
77+
const GrProgramInfo& programInfo) {
7978
this->setRenderTargetState(renderTarget, programInfo.origin(), programInfo.primProc());
8079

81-
// we set the textures, and uniforms for installed processors in a generic way, but subclasses
82-
// of GLProgram determine how to set coord transforms
80+
// we set the uniforms for installed processors in a generic way, but subclasses of GLProgram
81+
// determine how to set coord transforms
8382

8483
// We must bind to texture units in the same order in which we set the uniforms in
8584
// GrGLProgramDataManager. That is, we bind textures for processors in this order:
8685
// primProc, fragProcs, XP.
8786
GrFragmentProcessor::PipelineCoordTransformRange range(programInfo.pipeline());
8887
fPrimitiveProcessor->setData(fProgramDataManager, programInfo.primProc(), range);
89-
if (programInfo.hasFixedPrimProcTextures()) {
90-
this->updatePrimitiveProcessorTextureBindings(programInfo.primProc(),
91-
programInfo.fixedPrimProcTextures());
92-
}
93-
int nextTexSamplerIdx = programInfo.primProc().numTextureSamplers();
9488

95-
this->setFragmentData(programInfo.pipeline(), &nextTexSamplerIdx);
89+
GrFragmentProcessor::CIter fpIter(programInfo.pipeline());
90+
GrGLSLFragmentProcessor::Iter glslIter(fFragmentProcessors.get(), fFragmentProcessorCnt);
91+
for (; fpIter && glslIter; ++fpIter, ++glslIter) {
92+
glslIter->setData(fProgramDataManager, *fpIter);
93+
}
94+
SkASSERT(!fpIter && !glslIter);
9695

9796
const GrXferProcessor& xp = programInfo.pipeline().getXferProcessor();
9897
SkIPoint offset;
9998
GrTexture* dstTexture = programInfo.pipeline().peekDstTexture(&offset);
10099

101100
fXferProcessor->setData(fProgramDataManager, xp, dstTexture, offset);
102-
if (dstTexture) {
103-
fGpu->bindTexture(nextTexSamplerIdx++, GrSamplerState::Filter::kNearest,
104-
programInfo.pipeline().dstProxyView().swizzle(),
105-
static_cast<GrGLTexture*>(dstTexture));
106-
}
107-
SkASSERT(nextTexSamplerIdx == fNumTextureSamplers);
108101
}
109102

110-
void GrGLProgram::updatePrimitiveProcessorTextureBindings(const GrPrimitiveProcessor& primProc,
111-
const GrSurfaceProxy* const proxies[]) {
103+
void GrGLProgram::bindTextures(const GrPrimitiveProcessor& primProc, const GrPipeline& pipeline,
104+
const GrSurfaceProxy* const primProcTextureOverrides[]) {
112105
for (int i = 0; i < primProc.numTextureSamplers(); ++i) {
113-
SkASSERT(proxies[i]->asTextureProxy());
114-
auto* tex = static_cast<GrGLTexture*>(proxies[i]->peekTexture());
106+
SkASSERT(primProcTextureOverrides[i]->asTextureProxy());
107+
auto* overrideTexture = static_cast<GrGLTexture*>(
108+
primProcTextureOverrides[i]->peekTexture());
115109
fGpu->bindTexture(i, primProc.textureSampler(i).samplerState(),
116-
primProc.textureSampler(i).swizzle(), tex);
110+
primProc.textureSampler(i).swizzle(), overrideTexture);
117111
}
118-
}
112+
int nextTexSamplerIdx = primProc.numTextureSamplers();
119113

120-
void GrGLProgram::setFragmentData(const GrPipeline& pipeline, int* nextTexSamplerIdx) {
121114
GrFragmentProcessor::CIter fpIter(pipeline);
122-
GrGLSLFragmentProcessor::Iter glslIter(fFragmentProcessors.get(), fFragmentProcessorCnt);
123-
for (; fpIter && glslIter; ++fpIter, ++glslIter) {
124-
glslIter->setData(fProgramDataManager, *fpIter);
115+
for (; fpIter; ++fpIter) {
125116
for (int i = 0; i < fpIter->numTextureSamplers(); ++i) {
126117
const GrFragmentProcessor::TextureSampler& sampler = fpIter->textureSampler(i);
127-
fGpu->bindTexture((*nextTexSamplerIdx)++, sampler.samplerState(),
128-
sampler.view().swizzle(),
118+
fGpu->bindTexture(nextTexSamplerIdx++, sampler.samplerState(), sampler.view().swizzle(),
129119
static_cast<GrGLTexture*>(sampler.peekTexture()));
130120
}
131121
}
132-
SkASSERT(!fpIter && !glslIter);
122+
123+
SkIPoint offset;
124+
GrTexture* dstTexture = pipeline.peekDstTexture(&offset);
125+
if (dstTexture) {
126+
fGpu->bindTexture(nextTexSamplerIdx++, GrSamplerState::Filter::kNearest,
127+
pipeline.dstProxyView().swizzle(), static_cast<GrGLTexture*>(dstTexture));
128+
}
129+
SkASSERT(nextTexSamplerIdx == fNumTextureSamplers);
133130
}
134131

135132
void GrGLProgram::setRenderTargetState(const GrRenderTarget* rt, GrSurfaceOrigin origin,

src/gpu/gl/GrGLProgram.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,19 @@ class GrGLProgram : public SkRefCnt {
113113
};
114114

115115
/**
116-
* This function uploads uniforms, calls each GrGLSL*Processor's setData. It binds all fragment
117-
* processor textures. Primitive process textures can be bound using this function or by
118-
* calling updatePrimitiveProcessorTextureBindings.
116+
* This function uploads uniforms and calls each GrGLSL*Processor's setData.
119117
*
120118
* It is the caller's responsibility to ensure the program is bound before calling.
121119
*/
122-
void updateUniformsAndTextureBindings(const GrRenderTarget*, const GrProgramInfo&);
120+
void updateUniforms(const GrRenderTarget*, const GrProgramInfo&);
123121

124-
void updatePrimitiveProcessorTextureBindings(const GrPrimitiveProcessor&,
125-
const GrSurfaceProxy* const[]);
122+
/**
123+
* Binds all primitive processor and fragment processor textures. We configure primitive
124+
* processor samplers based on the proxies on the processor itself, but the actual textures we
125+
* bind come from primProcTextureOverrides.
126+
*/
127+
void bindTextures(const GrPrimitiveProcessor&, const GrPipeline&,
128+
const GrSurfaceProxy* const primProcTextureOverrides[]);
126129

127130
int vertexStride() const { return fVertexStride; }
128131
int instanceStride() const { return fInstanceStride; }
@@ -140,9 +143,6 @@ class GrGLProgram : public SkRefCnt {
140143
}
141144

142145
private:
143-
// A helper to loop over effects, set the transforms (via subclass) and bind textures
144-
void setFragmentData(const GrPipeline&, int* nextTexSamplerIdx);
145-
146146
// Helper for setData() that sets the view matrix and loads the render target height uniform
147147
void setRenderTargetState(const GrRenderTarget*, GrSurfaceOrigin, const GrPrimitiveProcessor&);
148148

0 commit comments

Comments
 (0)