• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // ProgramGL.cpp: Implements the class methods for ProgramGL.
8 
9 #include "libANGLE/renderer/gl/ProgramGL.h"
10 
11 #include "common/angleutils.h"
12 #include "common/bitset_utils.h"
13 #include "common/debug.h"
14 #include "common/string_utils.h"
15 #include "common/utilities.h"
16 #include "libANGLE/Context.h"
17 #include "libANGLE/ProgramLinkedResources.h"
18 #include "libANGLE/Uniform.h"
19 #include "libANGLE/WorkerThread.h"
20 #include "libANGLE/queryconversions.h"
21 #include "libANGLE/renderer/gl/ContextGL.h"
22 #include "libANGLE/renderer/gl/FunctionsGL.h"
23 #include "libANGLE/renderer/gl/RendererGL.h"
24 #include "libANGLE/renderer/gl/ShaderGL.h"
25 #include "libANGLE/renderer/gl/StateManagerGL.h"
26 #include "libANGLE/trace.h"
27 #include "platform/FeaturesGL.h"
28 #include "platform/PlatformMethods.h"
29 
30 namespace rx
31 {
32 
ProgramGL(const gl::ProgramState & data,const FunctionsGL * functions,const angle::FeaturesGL & features,StateManagerGL * stateManager,const std::shared_ptr<RendererGL> & renderer)33 ProgramGL::ProgramGL(const gl::ProgramState &data,
34                      const FunctionsGL *functions,
35                      const angle::FeaturesGL &features,
36                      StateManagerGL *stateManager,
37                      const std::shared_ptr<RendererGL> &renderer)
38     : ProgramImpl(data),
39       mFunctions(functions),
40       mFeatures(features),
41       mStateManager(stateManager),
42       mMultiviewBaseViewLayerIndexUniformLocation(-1),
43       mProgramID(0),
44       mRenderer(renderer),
45       mLinkedInParallel(false)
46 {
47     ASSERT(mFunctions);
48     ASSERT(mStateManager);
49 
50     mProgramID = mFunctions->createProgram();
51 }
52 
~ProgramGL()53 ProgramGL::~ProgramGL()
54 {
55     mFunctions->deleteProgram(mProgramID);
56     mProgramID = 0;
57 }
58 
load(const gl::Context * context,gl::BinaryInputStream * stream,gl::InfoLog & infoLog)59 std::unique_ptr<LinkEvent> ProgramGL::load(const gl::Context *context,
60                                            gl::BinaryInputStream *stream,
61                                            gl::InfoLog &infoLog)
62 {
63     ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::load");
64     preLink();
65 
66     // Read the binary format, size and blob
67     GLenum binaryFormat   = stream->readInt<GLenum>();
68     GLint binaryLength    = stream->readInt<GLint>();
69     const uint8_t *binary = stream->data() + stream->offset();
70     stream->skip(binaryLength);
71 
72     // Load the binary
73     mFunctions->programBinary(mProgramID, binaryFormat, binary, binaryLength);
74 
75     // Verify that the program linked
76     if (!checkLinkStatus(infoLog))
77     {
78         return std::make_unique<LinkEventDone>(angle::Result::Incomplete);
79     }
80 
81     postLink();
82     reapplyUBOBindingsIfNeeded(context);
83 
84     return std::make_unique<LinkEventDone>(angle::Result::Continue);
85 }
86 
save(const gl::Context * context,gl::BinaryOutputStream * stream)87 void ProgramGL::save(const gl::Context *context, gl::BinaryOutputStream *stream)
88 {
89     GLint binaryLength = 0;
90     mFunctions->getProgramiv(mProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
91 
92     std::vector<uint8_t> binary(std::max(binaryLength, 1));
93     GLenum binaryFormat = GL_NONE;
94     mFunctions->getProgramBinary(mProgramID, binaryLength, &binaryLength, &binaryFormat,
95                                  binary.data());
96 
97     stream->writeInt(binaryFormat);
98     stream->writeInt(binaryLength);
99     stream->writeBytes(binary.data(), binaryLength);
100 
101     reapplyUBOBindingsIfNeeded(context);
102 }
103 
reapplyUBOBindingsIfNeeded(const gl::Context * context)104 void ProgramGL::reapplyUBOBindingsIfNeeded(const gl::Context *context)
105 {
106     // Re-apply UBO bindings to work around driver bugs.
107     const angle::FeaturesGL &features = GetImplAs<ContextGL>(context)->getFeaturesGL();
108     if (features.reapplyUBOBindingsAfterUsingBinaryProgram.enabled)
109     {
110         const auto &blocks = mState.getUniformBlocks();
111         for (size_t blockIndex : mState.getActiveUniformBlockBindingsMask())
112         {
113             setUniformBlockBinding(static_cast<GLuint>(blockIndex), blocks[blockIndex].binding);
114         }
115     }
116 }
117 
setBinaryRetrievableHint(bool retrievable)118 void ProgramGL::setBinaryRetrievableHint(bool retrievable)
119 {
120     // glProgramParameteri isn't always available on ES backends.
121     if (mFunctions->programParameteri)
122     {
123         mFunctions->programParameteri(mProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT,
124                                       retrievable ? GL_TRUE : GL_FALSE);
125     }
126 }
127 
setSeparable(bool separable)128 void ProgramGL::setSeparable(bool separable)
129 {
130     mFunctions->programParameteri(mProgramID, GL_PROGRAM_SEPARABLE, separable ? GL_TRUE : GL_FALSE);
131 }
132 
133 using LinkImplFunctor = std::function<bool(std::string &)>;
134 class ProgramGL::LinkTask final : public angle::Closure
135 {
136   public:
LinkTask(LinkImplFunctor && functor)137     LinkTask(LinkImplFunctor &&functor) : mLinkImplFunctor(functor), mFallbackToMainContext(false)
138     {}
139 
operator ()()140     void operator()() override
141     {
142         ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkTask::run");
143         mFallbackToMainContext = mLinkImplFunctor(mInfoLog);
144     }
145 
fallbackToMainContext()146     bool fallbackToMainContext() { return mFallbackToMainContext; }
getInfoLog()147     const std::string &getInfoLog() { return mInfoLog; }
148 
149   private:
150     LinkImplFunctor mLinkImplFunctor;
151     bool mFallbackToMainContext;
152     std::string mInfoLog;
153 };
154 
155 using PostLinkImplFunctor = std::function<angle::Result(bool, const std::string &)>;
156 
157 // The event for a parallelized linking using the native driver extension.
158 class ProgramGL::LinkEventNativeParallel final : public LinkEvent
159 {
160   public:
LinkEventNativeParallel(PostLinkImplFunctor && functor,const FunctionsGL * functions,GLuint programID)161     LinkEventNativeParallel(PostLinkImplFunctor &&functor,
162                             const FunctionsGL *functions,
163                             GLuint programID)
164         : mPostLinkImplFunctor(functor), mFunctions(functions), mProgramID(programID)
165     {}
166 
wait(const gl::Context * context)167     angle::Result wait(const gl::Context *context) override
168     {
169         ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkEventNativeParallel::wait");
170 
171         GLint linkStatus = GL_FALSE;
172         mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
173         if (linkStatus == GL_TRUE)
174         {
175             return mPostLinkImplFunctor(false, std::string());
176         }
177         return angle::Result::Incomplete;
178     }
179 
isLinking()180     bool isLinking() override
181     {
182         GLint completionStatus = GL_FALSE;
183         mFunctions->getProgramiv(mProgramID, GL_COMPLETION_STATUS, &completionStatus);
184         return completionStatus == GL_FALSE;
185     }
186 
187   private:
188     PostLinkImplFunctor mPostLinkImplFunctor;
189     const FunctionsGL *mFunctions;
190     GLuint mProgramID;
191 };
192 
193 // The event for a parallelized linking using the worker thread pool.
194 class ProgramGL::LinkEventGL final : public LinkEvent
195 {
196   public:
LinkEventGL(std::shared_ptr<angle::WorkerThreadPool> workerPool,std::shared_ptr<ProgramGL::LinkTask> linkTask,PostLinkImplFunctor && functor)197     LinkEventGL(std::shared_ptr<angle::WorkerThreadPool> workerPool,
198                 std::shared_ptr<ProgramGL::LinkTask> linkTask,
199                 PostLinkImplFunctor &&functor)
200         : mLinkTask(linkTask),
201           mWaitableEvent(std::shared_ptr<angle::WaitableEvent>(
202               angle::WorkerThreadPool::PostWorkerTask(workerPool, mLinkTask))),
203           mPostLinkImplFunctor(functor)
204     {}
205 
wait(const gl::Context * context)206     angle::Result wait(const gl::Context *context) override
207     {
208         ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkEventGL::wait");
209 
210         mWaitableEvent->wait();
211         return mPostLinkImplFunctor(mLinkTask->fallbackToMainContext(), mLinkTask->getInfoLog());
212     }
213 
isLinking()214     bool isLinking() override { return !mWaitableEvent->isReady(); }
215 
216   private:
217     std::shared_ptr<ProgramGL::LinkTask> mLinkTask;
218     std::shared_ptr<angle::WaitableEvent> mWaitableEvent;
219     PostLinkImplFunctor mPostLinkImplFunctor;
220 };
221 
link(const gl::Context * context,const gl::ProgramLinkedResources & resources,gl::InfoLog & infoLog,const gl::ProgramMergedVaryings &)222 std::unique_ptr<LinkEvent> ProgramGL::link(const gl::Context *context,
223                                            const gl::ProgramLinkedResources &resources,
224                                            gl::InfoLog &infoLog,
225                                            const gl::ProgramMergedVaryings & /*mergedVaryings*/)
226 {
227     ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::link");
228 
229     preLink();
230 
231     if (mState.getAttachedShader(gl::ShaderType::Compute))
232     {
233         const ShaderGL *computeShaderGL =
234             GetImplAs<ShaderGL>(mState.getAttachedShader(gl::ShaderType::Compute));
235 
236         mFunctions->attachShader(mProgramID, computeShaderGL->getShaderID());
237     }
238     else
239     {
240         // Set the transform feedback state
241         std::vector<std::string> transformFeedbackVaryingMappedNames;
242         for (const auto &tfVarying : mState.getTransformFeedbackVaryingNames())
243         {
244             gl::ShaderType tfShaderType =
245                 mState.getExecutable().hasLinkedShaderStage(gl::ShaderType::Geometry)
246                     ? gl::ShaderType::Geometry
247                     : gl::ShaderType::Vertex;
248             std::string tfVaryingMappedName =
249                 mState.getAttachedShader(tfShaderType)
250                     ->getTransformFeedbackVaryingMappedName(tfVarying);
251             transformFeedbackVaryingMappedNames.push_back(tfVaryingMappedName);
252         }
253 
254         if (transformFeedbackVaryingMappedNames.empty())
255         {
256             if (mFunctions->transformFeedbackVaryings)
257             {
258                 mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr,
259                                                       mState.getTransformFeedbackBufferMode());
260             }
261         }
262         else
263         {
264             ASSERT(mFunctions->transformFeedbackVaryings);
265             std::vector<const GLchar *> transformFeedbackVaryings;
266             for (const auto &varying : transformFeedbackVaryingMappedNames)
267             {
268                 transformFeedbackVaryings.push_back(varying.c_str());
269             }
270             mFunctions->transformFeedbackVaryings(
271                 mProgramID, static_cast<GLsizei>(transformFeedbackVaryingMappedNames.size()),
272                 &transformFeedbackVaryings[0], mState.getTransformFeedbackBufferMode());
273         }
274 
275         for (const gl::ShaderType shaderType : gl::kAllGraphicsShaderTypes)
276         {
277             const ShaderGL *shaderGL =
278                 rx::SafeGetImplAs<ShaderGL, gl::Shader>(mState.getAttachedShader(shaderType));
279             if (shaderGL)
280             {
281                 mFunctions->attachShader(mProgramID, shaderGL->getShaderID());
282             }
283         }
284 
285         // Bind attribute locations to match the GL layer.
286         for (const sh::ShaderVariable &attribute : mState.getProgramInputs())
287         {
288             if (!attribute.active || attribute.isBuiltIn())
289             {
290                 continue;
291             }
292 
293             mFunctions->bindAttribLocation(mProgramID, attribute.location,
294                                            attribute.mappedName.c_str());
295         }
296 
297         // Bind the secondary fragment color outputs defined in EXT_blend_func_extended. We only use
298         // the API to bind fragment output locations in case EXT_blend_func_extended is enabled.
299         // Otherwise shader-assigned locations will work.
300         if (context->getExtensions().blendFuncExtended)
301         {
302             gl::Shader *fragmentShader = mState.getAttachedShader(gl::ShaderType::Fragment);
303             if (fragmentShader && fragmentShader->getShaderVersion() == 100)
304             {
305                 // TODO(http://anglebug.com/2833): The bind done below is only valid in case the
306                 // compiler transforms the shader outputs to the angle/webgl prefixed ones. If we
307                 // added support for running EXT_blend_func_extended on top of GLES, some changes
308                 // would be required:
309                 //  - If we're backed by GLES 2.0, we shouldn't do the bind because it's not needed.
310                 //  - If we're backed by GLES 3.0+, it's a bit unclear what should happen. Currently
311                 //    the compiler doesn't support transforming GLSL ES 1.00 shaders to GLSL ES 3.00
312                 //    shaders in general, but support for that might be required. Or we might be
313                 //    able to skip the bind in case the compiler outputs GLSL ES 1.00.
314                 const auto &shaderOutputs =
315                     mState.getAttachedShader(gl::ShaderType::Fragment)->getActiveOutputVariables();
316                 for (const auto &output : shaderOutputs)
317                 {
318                     // TODO(http://anglebug.com/1085) This could be cleaner if the transformed names
319                     // would be set correctly in ShaderVariable::mappedName. This would require some
320                     // refactoring in the translator. Adding a mapped name dictionary for builtins
321                     // into the symbol table would be one fairly clean way to do it.
322                     if (output.name == "gl_SecondaryFragColorEXT")
323                     {
324                         mFunctions->bindFragDataLocationIndexed(mProgramID, 0, 0,
325                                                                 "webgl_FragColor");
326                         mFunctions->bindFragDataLocationIndexed(mProgramID, 0, 1,
327                                                                 "webgl_SecondaryFragColor");
328                     }
329                     else if (output.name == "gl_SecondaryFragDataEXT")
330                     {
331                         // Basically we should have a loop here going over the output
332                         // array binding "webgl_FragData[i]" and "webgl_SecondaryFragData[i]" array
333                         // indices to the correct color buffers and color indices.
334                         // However I'm not sure if this construct is legal or not, neither ARB or
335                         // EXT version of the spec mention this. They only mention that
336                         // automatically assigned array locations for ESSL 3.00 output arrays need
337                         // to have contiguous locations.
338                         //
339                         // In practice it seems that binding array members works on some drivers and
340                         // fails on others. One option could be to modify the shader translator to
341                         // expand the arrays into individual output variables instead of using an
342                         // array.
343                         //
344                         // For now we're going to have a limitation of assuming that
345                         // GL_MAX_DUAL_SOURCE_DRAW_BUFFERS is *always* 1 and then only bind the
346                         // basename of the variable ignoring any indices. This appears to work
347                         // uniformly.
348                         ASSERT(output.isArray() && output.getOutermostArraySize() == 1);
349 
350                         mFunctions->bindFragDataLocationIndexed(mProgramID, 0, 0, "webgl_FragData");
351                         mFunctions->bindFragDataLocationIndexed(mProgramID, 0, 1,
352                                                                 "webgl_SecondaryFragData");
353                     }
354                 }
355             }
356             else
357             {
358                 // ESSL 3.00 and up.
359                 const auto &outputLocations          = mState.getOutputLocations();
360                 const auto &secondaryOutputLocations = mState.getSecondaryOutputLocations();
361                 for (size_t outputLocationIndex = 0u; outputLocationIndex < outputLocations.size();
362                      ++outputLocationIndex)
363                 {
364                     const gl::VariableLocation &outputLocation =
365                         outputLocations[outputLocationIndex];
366                     if (outputLocation.arrayIndex == 0 && outputLocation.used() &&
367                         !outputLocation.ignored)
368                     {
369                         const sh::ShaderVariable &outputVar =
370                             mState.getOutputVariables()[outputLocation.index];
371                         if (outputVar.location == -1 || outputVar.index == -1)
372                         {
373                             // We only need to assign the location and index via the API in case the
374                             // variable doesn't have a shader-assigned location and index. If a
375                             // variable doesn't have its location set in the shader it doesn't have
376                             // the index set either.
377                             ASSERT(outputVar.index == -1);
378                             mFunctions->bindFragDataLocationIndexed(
379                                 mProgramID, static_cast<int>(outputLocationIndex), 0,
380                                 outputVar.mappedName.c_str());
381                         }
382                     }
383                 }
384                 for (size_t outputLocationIndex = 0u;
385                      outputLocationIndex < secondaryOutputLocations.size(); ++outputLocationIndex)
386                 {
387                     const gl::VariableLocation &outputLocation =
388                         secondaryOutputLocations[outputLocationIndex];
389                     if (outputLocation.arrayIndex == 0 && outputLocation.used() &&
390                         !outputLocation.ignored)
391                     {
392                         const sh::ShaderVariable &outputVar =
393                             mState.getOutputVariables()[outputLocation.index];
394                         if (outputVar.location == -1 || outputVar.index == -1)
395                         {
396                             // We only need to assign the location and index via the API in case the
397                             // variable doesn't have a shader-assigned location and index.  If a
398                             // variable doesn't have its location set in the shader it doesn't have
399                             // the index set either.
400                             ASSERT(outputVar.index == -1);
401                             mFunctions->bindFragDataLocationIndexed(
402                                 mProgramID, static_cast<int>(outputLocationIndex), 1,
403                                 outputVar.mappedName.c_str());
404                         }
405                     }
406                 }
407             }
408         }
409     }
410     auto workerPool = context->getWorkerThreadPool();
411     auto linkTask   = std::make_shared<LinkTask>([this](std::string &infoLog) {
412         std::string workerInfoLog;
413         ScopedWorkerContextGL worker(mRenderer.get(), &workerInfoLog);
414         if (!worker())
415         {
416 #if !defined(NDEBUG)
417             infoLog += "bindWorkerContext failed.\n" + workerInfoLog;
418 #endif
419             // Fallback to the main context.
420             return true;
421         }
422 
423         mFunctions->linkProgram(mProgramID);
424 
425         // Make sure the driver actually does the link job.
426         GLint linkStatus = GL_FALSE;
427         mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
428 
429         return false;
430     });
431 
432     auto postLinkImplTask = [this, &infoLog, &resources](bool fallbackToMainContext,
433                                                          const std::string &workerInfoLog) {
434         infoLog << workerInfoLog;
435         if (fallbackToMainContext)
436         {
437             mFunctions->linkProgram(mProgramID);
438         }
439 
440         if (mState.getAttachedShader(gl::ShaderType::Compute))
441         {
442             const ShaderGL *computeShaderGL =
443                 GetImplAs<ShaderGL>(mState.getAttachedShader(gl::ShaderType::Compute));
444 
445             mFunctions->detachShader(mProgramID, computeShaderGL->getShaderID());
446         }
447         else
448         {
449             for (const gl::ShaderType shaderType : gl::kAllGraphicsShaderTypes)
450             {
451                 const ShaderGL *shaderGL =
452                     rx::SafeGetImplAs<ShaderGL>(mState.getAttachedShader(shaderType));
453                 if (shaderGL)
454                 {
455                     mFunctions->detachShader(mProgramID, shaderGL->getShaderID());
456                 }
457             }
458         }
459         // Verify the link
460         if (!checkLinkStatus(infoLog))
461         {
462             return angle::Result::Incomplete;
463         }
464 
465         if (mFeatures.alwaysCallUseProgramAfterLink.enabled)
466         {
467             mStateManager->forceUseProgram(mProgramID);
468         }
469 
470         linkResources(resources);
471         postLink();
472 
473         return angle::Result::Continue;
474     };
475 
476     if (mRenderer->hasNativeParallelCompile())
477     {
478         mFunctions->linkProgram(mProgramID);
479 
480         return std::make_unique<LinkEventNativeParallel>(postLinkImplTask, mFunctions, mProgramID);
481     }
482     else if (workerPool->isAsync() &&
483              (!mFeatures.dontRelinkProgramsInParallel.enabled || !mLinkedInParallel))
484     {
485         mLinkedInParallel = true;
486         return std::make_unique<LinkEventGL>(workerPool, linkTask, postLinkImplTask);
487     }
488     else
489     {
490         return std::make_unique<LinkEventDone>(postLinkImplTask(true, std::string()));
491     }
492 }
493 
validate(const gl::Caps &,gl::InfoLog *)494 GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)
495 {
496     // TODO(jmadill): implement validate
497     return true;
498 }
499 
setUniform1fv(GLint location,GLsizei count,const GLfloat * v)500 void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
501 {
502     if (mFunctions->programUniform1fv != nullptr)
503     {
504         mFunctions->programUniform1fv(mProgramID, uniLoc(location), count, v);
505     }
506     else
507     {
508         mStateManager->useProgram(mProgramID);
509         mFunctions->uniform1fv(uniLoc(location), count, v);
510     }
511 }
512 
setUniform2fv(GLint location,GLsizei count,const GLfloat * v)513 void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
514 {
515     if (mFunctions->programUniform2fv != nullptr)
516     {
517         mFunctions->programUniform2fv(mProgramID, uniLoc(location), count, v);
518     }
519     else
520     {
521         mStateManager->useProgram(mProgramID);
522         mFunctions->uniform2fv(uniLoc(location), count, v);
523     }
524 }
525 
setUniform3fv(GLint location,GLsizei count,const GLfloat * v)526 void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
527 {
528     if (mFunctions->programUniform3fv != nullptr)
529     {
530         mFunctions->programUniform3fv(mProgramID, uniLoc(location), count, v);
531     }
532     else
533     {
534         mStateManager->useProgram(mProgramID);
535         mFunctions->uniform3fv(uniLoc(location), count, v);
536     }
537 }
538 
setUniform4fv(GLint location,GLsizei count,const GLfloat * v)539 void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
540 {
541     if (mFunctions->programUniform4fv != nullptr)
542     {
543         mFunctions->programUniform4fv(mProgramID, uniLoc(location), count, v);
544     }
545     else
546     {
547         mStateManager->useProgram(mProgramID);
548         mFunctions->uniform4fv(uniLoc(location), count, v);
549     }
550 }
551 
setUniform1iv(GLint location,GLsizei count,const GLint * v)552 void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v)
553 {
554     if (mFunctions->programUniform1iv != nullptr)
555     {
556         mFunctions->programUniform1iv(mProgramID, uniLoc(location), count, v);
557     }
558     else
559     {
560         mStateManager->useProgram(mProgramID);
561         mFunctions->uniform1iv(uniLoc(location), count, v);
562     }
563 }
564 
setUniform2iv(GLint location,GLsizei count,const GLint * v)565 void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v)
566 {
567     if (mFunctions->programUniform2iv != nullptr)
568     {
569         mFunctions->programUniform2iv(mProgramID, uniLoc(location), count, v);
570     }
571     else
572     {
573         mStateManager->useProgram(mProgramID);
574         mFunctions->uniform2iv(uniLoc(location), count, v);
575     }
576 }
577 
setUniform3iv(GLint location,GLsizei count,const GLint * v)578 void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v)
579 {
580     if (mFunctions->programUniform3iv != nullptr)
581     {
582         mFunctions->programUniform3iv(mProgramID, uniLoc(location), count, v);
583     }
584     else
585     {
586         mStateManager->useProgram(mProgramID);
587         mFunctions->uniform3iv(uniLoc(location), count, v);
588     }
589 }
590 
setUniform4iv(GLint location,GLsizei count,const GLint * v)591 void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v)
592 {
593     if (mFunctions->programUniform4iv != nullptr)
594     {
595         mFunctions->programUniform4iv(mProgramID, uniLoc(location), count, v);
596     }
597     else
598     {
599         mStateManager->useProgram(mProgramID);
600         mFunctions->uniform4iv(uniLoc(location), count, v);
601     }
602 }
603 
setUniform1uiv(GLint location,GLsizei count,const GLuint * v)604 void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
605 {
606     if (mFunctions->programUniform1uiv != nullptr)
607     {
608         mFunctions->programUniform1uiv(mProgramID, uniLoc(location), count, v);
609     }
610     else
611     {
612         mStateManager->useProgram(mProgramID);
613         mFunctions->uniform1uiv(uniLoc(location), count, v);
614     }
615 }
616 
setUniform2uiv(GLint location,GLsizei count,const GLuint * v)617 void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
618 {
619     if (mFunctions->programUniform2uiv != nullptr)
620     {
621         mFunctions->programUniform2uiv(mProgramID, uniLoc(location), count, v);
622     }
623     else
624     {
625         mStateManager->useProgram(mProgramID);
626         mFunctions->uniform2uiv(uniLoc(location), count, v);
627     }
628 }
629 
setUniform3uiv(GLint location,GLsizei count,const GLuint * v)630 void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
631 {
632     if (mFunctions->programUniform3uiv != nullptr)
633     {
634         mFunctions->programUniform3uiv(mProgramID, uniLoc(location), count, v);
635     }
636     else
637     {
638         mStateManager->useProgram(mProgramID);
639         mFunctions->uniform3uiv(uniLoc(location), count, v);
640     }
641 }
642 
setUniform4uiv(GLint location,GLsizei count,const GLuint * v)643 void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
644 {
645     if (mFunctions->programUniform4uiv != nullptr)
646     {
647         mFunctions->programUniform4uiv(mProgramID, uniLoc(location), count, v);
648     }
649     else
650     {
651         mStateManager->useProgram(mProgramID);
652         mFunctions->uniform4uiv(uniLoc(location), count, v);
653     }
654 }
655 
setUniformMatrix2fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)656 void ProgramGL::setUniformMatrix2fv(GLint location,
657                                     GLsizei count,
658                                     GLboolean transpose,
659                                     const GLfloat *value)
660 {
661     if (mFunctions->programUniformMatrix2fv != nullptr)
662     {
663         mFunctions->programUniformMatrix2fv(mProgramID, uniLoc(location), count, transpose, value);
664     }
665     else
666     {
667         mStateManager->useProgram(mProgramID);
668         mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value);
669     }
670 }
671 
setUniformMatrix3fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)672 void ProgramGL::setUniformMatrix3fv(GLint location,
673                                     GLsizei count,
674                                     GLboolean transpose,
675                                     const GLfloat *value)
676 {
677     if (mFunctions->programUniformMatrix3fv != nullptr)
678     {
679         mFunctions->programUniformMatrix3fv(mProgramID, uniLoc(location), count, transpose, value);
680     }
681     else
682     {
683         mStateManager->useProgram(mProgramID);
684         mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value);
685     }
686 }
687 
setUniformMatrix4fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)688 void ProgramGL::setUniformMatrix4fv(GLint location,
689                                     GLsizei count,
690                                     GLboolean transpose,
691                                     const GLfloat *value)
692 {
693     if (mFunctions->programUniformMatrix4fv != nullptr)
694     {
695         mFunctions->programUniformMatrix4fv(mProgramID, uniLoc(location), count, transpose, value);
696     }
697     else
698     {
699         mStateManager->useProgram(mProgramID);
700         mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value);
701     }
702 }
703 
setUniformMatrix2x3fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)704 void ProgramGL::setUniformMatrix2x3fv(GLint location,
705                                       GLsizei count,
706                                       GLboolean transpose,
707                                       const GLfloat *value)
708 {
709     if (mFunctions->programUniformMatrix2x3fv != nullptr)
710     {
711         mFunctions->programUniformMatrix2x3fv(mProgramID, uniLoc(location), count, transpose,
712                                               value);
713     }
714     else
715     {
716         mStateManager->useProgram(mProgramID);
717         mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value);
718     }
719 }
720 
setUniformMatrix3x2fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)721 void ProgramGL::setUniformMatrix3x2fv(GLint location,
722                                       GLsizei count,
723                                       GLboolean transpose,
724                                       const GLfloat *value)
725 {
726     if (mFunctions->programUniformMatrix3x2fv != nullptr)
727     {
728         mFunctions->programUniformMatrix3x2fv(mProgramID, uniLoc(location), count, transpose,
729                                               value);
730     }
731     else
732     {
733         mStateManager->useProgram(mProgramID);
734         mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value);
735     }
736 }
737 
setUniformMatrix2x4fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)738 void ProgramGL::setUniformMatrix2x4fv(GLint location,
739                                       GLsizei count,
740                                       GLboolean transpose,
741                                       const GLfloat *value)
742 {
743     if (mFunctions->programUniformMatrix2x4fv != nullptr)
744     {
745         mFunctions->programUniformMatrix2x4fv(mProgramID, uniLoc(location), count, transpose,
746                                               value);
747     }
748     else
749     {
750         mStateManager->useProgram(mProgramID);
751         mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value);
752     }
753 }
754 
setUniformMatrix4x2fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)755 void ProgramGL::setUniformMatrix4x2fv(GLint location,
756                                       GLsizei count,
757                                       GLboolean transpose,
758                                       const GLfloat *value)
759 {
760     if (mFunctions->programUniformMatrix4x2fv != nullptr)
761     {
762         mFunctions->programUniformMatrix4x2fv(mProgramID, uniLoc(location), count, transpose,
763                                               value);
764     }
765     else
766     {
767         mStateManager->useProgram(mProgramID);
768         mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value);
769     }
770 }
771 
setUniformMatrix3x4fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)772 void ProgramGL::setUniformMatrix3x4fv(GLint location,
773                                       GLsizei count,
774                                       GLboolean transpose,
775                                       const GLfloat *value)
776 {
777     if (mFunctions->programUniformMatrix3x4fv != nullptr)
778     {
779         mFunctions->programUniformMatrix3x4fv(mProgramID, uniLoc(location), count, transpose,
780                                               value);
781     }
782     else
783     {
784         mStateManager->useProgram(mProgramID);
785         mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value);
786     }
787 }
788 
setUniformMatrix4x3fv(GLint location,GLsizei count,GLboolean transpose,const GLfloat * value)789 void ProgramGL::setUniformMatrix4x3fv(GLint location,
790                                       GLsizei count,
791                                       GLboolean transpose,
792                                       const GLfloat *value)
793 {
794     if (mFunctions->programUniformMatrix4x3fv != nullptr)
795     {
796         mFunctions->programUniformMatrix4x3fv(mProgramID, uniLoc(location), count, transpose,
797                                               value);
798     }
799     else
800     {
801         mStateManager->useProgram(mProgramID);
802         mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value);
803     }
804 }
805 
setUniformBlockBinding(GLuint uniformBlockIndex,GLuint uniformBlockBinding)806 void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding)
807 {
808     // Lazy init
809     if (mUniformBlockRealLocationMap.empty())
810     {
811         mUniformBlockRealLocationMap.reserve(mState.getUniformBlocks().size());
812         for (const gl::InterfaceBlock &uniformBlock : mState.getUniformBlocks())
813         {
814             const std::string &mappedNameWithIndex = uniformBlock.mappedNameWithArrayIndex();
815             GLuint blockIndex =
816                 mFunctions->getUniformBlockIndex(mProgramID, mappedNameWithIndex.c_str());
817             mUniformBlockRealLocationMap.push_back(blockIndex);
818         }
819     }
820 
821     GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex];
822     if (realBlockIndex != GL_INVALID_INDEX)
823     {
824         mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding);
825     }
826 }
827 
getUniformBlockSize(const std::string &,const std::string & blockMappedName,size_t * sizeOut) const828 bool ProgramGL::getUniformBlockSize(const std::string & /* blockName */,
829                                     const std::string &blockMappedName,
830                                     size_t *sizeOut) const
831 {
832     ASSERT(mProgramID != 0u);
833 
834     GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockMappedName.c_str());
835     if (blockIndex == GL_INVALID_INDEX)
836     {
837         *sizeOut = 0;
838         return false;
839     }
840 
841     GLint dataSize = 0;
842     mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
843                                         &dataSize);
844     *sizeOut = static_cast<size_t>(dataSize);
845     return true;
846 }
847 
getUniformBlockMemberInfo(const std::string &,const std::string & memberUniformMappedName,sh::BlockMemberInfo * memberInfoOut) const848 bool ProgramGL::getUniformBlockMemberInfo(const std::string & /* memberUniformName */,
849                                           const std::string &memberUniformMappedName,
850                                           sh::BlockMemberInfo *memberInfoOut) const
851 {
852     GLuint uniformIndex;
853     const GLchar *memberNameGLStr = memberUniformMappedName.c_str();
854     mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex);
855 
856     if (uniformIndex == GL_INVALID_INDEX)
857     {
858         *memberInfoOut = sh::kDefaultBlockMemberInfo;
859         return false;
860     }
861 
862     mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET,
863                                     &memberInfoOut->offset);
864     mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE,
865                                     &memberInfoOut->arrayStride);
866     mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE,
867                                     &memberInfoOut->matrixStride);
868 
869     // TODO(jmadill): possibly determine this at the gl::Program level.
870     GLint isRowMajorMatrix = 0;
871     mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR,
872                                     &isRowMajorMatrix);
873     memberInfoOut->isRowMajorMatrix = gl::ConvertToBool(isRowMajorMatrix);
874     return true;
875 }
876 
getShaderStorageBlockMemberInfo(const std::string &,const std::string & memberUniformMappedName,sh::BlockMemberInfo * memberInfoOut) const877 bool ProgramGL::getShaderStorageBlockMemberInfo(const std::string & /* memberName */,
878                                                 const std::string &memberUniformMappedName,
879                                                 sh::BlockMemberInfo *memberInfoOut) const
880 {
881     const GLchar *memberNameGLStr = memberUniformMappedName.c_str();
882     GLuint index =
883         mFunctions->getProgramResourceIndex(mProgramID, GL_BUFFER_VARIABLE, memberNameGLStr);
884 
885     if (index == GL_INVALID_INDEX)
886     {
887         *memberInfoOut = sh::kDefaultBlockMemberInfo;
888         return false;
889     }
890 
891     constexpr int kPropCount             = 5;
892     std::array<GLenum, kPropCount> props = {
893         {GL_ARRAY_STRIDE, GL_IS_ROW_MAJOR, GL_MATRIX_STRIDE, GL_OFFSET, GL_TOP_LEVEL_ARRAY_STRIDE}};
894     std::array<GLint, kPropCount> params;
895     GLsizei length;
896     mFunctions->getProgramResourceiv(mProgramID, GL_BUFFER_VARIABLE, index, kPropCount,
897                                      props.data(), kPropCount, &length, params.data());
898     ASSERT(kPropCount == length);
899     memberInfoOut->arrayStride         = params[0];
900     memberInfoOut->isRowMajorMatrix    = params[1] != 0;
901     memberInfoOut->matrixStride        = params[2];
902     memberInfoOut->offset              = params[3];
903     memberInfoOut->topLevelArrayStride = params[4];
904 
905     return true;
906 }
907 
getShaderStorageBlockSize(const std::string & name,const std::string & mappedName,size_t * sizeOut) const908 bool ProgramGL::getShaderStorageBlockSize(const std::string &name,
909                                           const std::string &mappedName,
910                                           size_t *sizeOut) const
911 {
912     const GLchar *nameGLStr = mappedName.c_str();
913     GLuint index =
914         mFunctions->getProgramResourceIndex(mProgramID, GL_SHADER_STORAGE_BLOCK, nameGLStr);
915 
916     if (index == GL_INVALID_INDEX)
917     {
918         *sizeOut = 0;
919         return false;
920     }
921 
922     GLenum prop    = GL_BUFFER_DATA_SIZE;
923     GLsizei length = 0;
924     GLint dataSize = 0;
925     mFunctions->getProgramResourceiv(mProgramID, GL_SHADER_STORAGE_BLOCK, index, 1, &prop, 1,
926                                      &length, &dataSize);
927     *sizeOut = static_cast<size_t>(dataSize);
928     return true;
929 }
930 
getAtomicCounterBufferSizeMap(std::map<int,unsigned int> * sizeMapOut) const931 void ProgramGL::getAtomicCounterBufferSizeMap(std::map<int, unsigned int> *sizeMapOut) const
932 {
933     if (mFunctions->getProgramInterfaceiv == nullptr)
934     {
935         return;
936     }
937 
938     int resourceCount = 0;
939     mFunctions->getProgramInterfaceiv(mProgramID, GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES,
940                                       &resourceCount);
941 
942     for (int index = 0; index < resourceCount; index++)
943     {
944         constexpr int kPropCount             = 2;
945         std::array<GLenum, kPropCount> props = {{GL_BUFFER_BINDING, GL_BUFFER_DATA_SIZE}};
946         std::array<GLint, kPropCount> params;
947         GLsizei length;
948         mFunctions->getProgramResourceiv(mProgramID, GL_ATOMIC_COUNTER_BUFFER, index, kPropCount,
949                                          props.data(), kPropCount, &length, params.data());
950         ASSERT(kPropCount == length);
951         int bufferBinding           = params[0];
952         unsigned int bufferDataSize = params[1];
953         sizeMapOut->insert(std::pair<int, unsigned int>(bufferBinding, bufferDataSize));
954     }
955 }
956 
preLink()957 void ProgramGL::preLink()
958 {
959     // Reset the program state
960     mUniformRealLocationMap.clear();
961     mUniformBlockRealLocationMap.clear();
962 
963     mMultiviewBaseViewLayerIndexUniformLocation = -1;
964 }
965 
checkLinkStatus(gl::InfoLog & infoLog)966 bool ProgramGL::checkLinkStatus(gl::InfoLog &infoLog)
967 {
968     GLint linkStatus = GL_FALSE;
969     mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
970     if (linkStatus == GL_FALSE)
971     {
972         // Linking or program binary loading failed, put the error into the info log.
973         GLint infoLogLength = 0;
974         mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength);
975 
976         // Info log length includes the null terminator, so 1 means that the info log is an empty
977         // string.
978         if (infoLogLength > 1)
979         {
980             std::vector<char> buf(infoLogLength);
981             mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]);
982 
983             infoLog << buf.data();
984 
985             WARN() << "Program link or binary loading failed: " << buf.data();
986         }
987         else
988         {
989             WARN() << "Program link or binary loading failed with no info log.";
990         }
991 
992         // This may happen under normal circumstances if we're loading program binaries and the
993         // driver or hardware has changed.
994         ASSERT(mProgramID != 0);
995         return false;
996     }
997 
998     return true;
999 }
1000 
postLink()1001 void ProgramGL::postLink()
1002 {
1003     // Query the uniform information
1004     ASSERT(mUniformRealLocationMap.empty());
1005     const auto &uniformLocations = mState.getUniformLocations();
1006     const auto &uniforms         = mState.getUniforms();
1007     mUniformRealLocationMap.resize(uniformLocations.size(), GL_INVALID_INDEX);
1008     for (size_t uniformLocation = 0; uniformLocation < uniformLocations.size(); uniformLocation++)
1009     {
1010         const auto &entry = uniformLocations[uniformLocation];
1011         if (!entry.used())
1012         {
1013             continue;
1014         }
1015 
1016         // From the GLES 3.0.5 spec:
1017         // "Locations for sequential array indices are not required to be sequential."
1018         const gl::LinkedUniform &uniform = uniforms[entry.index];
1019         std::stringstream fullNameStr;
1020         if (uniform.isArray())
1021         {
1022             ASSERT(angle::EndsWith(uniform.mappedName, "[0]"));
1023             fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3);
1024             fullNameStr << "[" << entry.arrayIndex << "]";
1025         }
1026         else
1027         {
1028             fullNameStr << uniform.mappedName;
1029         }
1030         const std::string &fullName = fullNameStr.str();
1031 
1032         GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str());
1033         mUniformRealLocationMap[uniformLocation] = realLocation;
1034     }
1035 
1036     if (mState.usesMultiview())
1037     {
1038         mMultiviewBaseViewLayerIndexUniformLocation =
1039             mFunctions->getUniformLocation(mProgramID, "multiviewBaseViewLayerIndex");
1040         ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
1041     }
1042 }
1043 
enableSideBySideRenderingPath() const1044 void ProgramGL::enableSideBySideRenderingPath() const
1045 {
1046     ASSERT(mState.usesMultiview());
1047     ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
1048 
1049     ASSERT(mFunctions->programUniform1i != nullptr);
1050     mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, -1);
1051 }
1052 
enableLayeredRenderingPath(int baseViewIndex) const1053 void ProgramGL::enableLayeredRenderingPath(int baseViewIndex) const
1054 {
1055     ASSERT(mState.usesMultiview());
1056     ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
1057 
1058     ASSERT(mFunctions->programUniform1i != nullptr);
1059     mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation,
1060                                  baseViewIndex);
1061 }
1062 
getUniformfv(const gl::Context * context,GLint location,GLfloat * params) const1063 void ProgramGL::getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const
1064 {
1065     mFunctions->getUniformfv(mProgramID, uniLoc(location), params);
1066 }
1067 
getUniformiv(const gl::Context * context,GLint location,GLint * params) const1068 void ProgramGL::getUniformiv(const gl::Context *context, GLint location, GLint *params) const
1069 {
1070     mFunctions->getUniformiv(mProgramID, uniLoc(location), params);
1071 }
1072 
getUniformuiv(const gl::Context * context,GLint location,GLuint * params) const1073 void ProgramGL::getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const
1074 {
1075     mFunctions->getUniformuiv(mProgramID, uniLoc(location), params);
1076 }
1077 
markUnusedUniformLocations(std::vector<gl::VariableLocation> * uniformLocations,std::vector<gl::SamplerBinding> * samplerBindings,std::vector<gl::ImageBinding> * imageBindings)1078 void ProgramGL::markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
1079                                            std::vector<gl::SamplerBinding> *samplerBindings,
1080                                            std::vector<gl::ImageBinding> *imageBindings)
1081 {
1082     GLint maxLocation = static_cast<GLint>(uniformLocations->size());
1083     for (GLint location = 0; location < maxLocation; ++location)
1084     {
1085         if (uniLoc(location) == -1)
1086         {
1087             auto &locationRef = (*uniformLocations)[location];
1088             if (mState.isSamplerUniformIndex(locationRef.index))
1089             {
1090                 GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(locationRef.index);
1091                 gl::SamplerBinding &samplerBinding = (*samplerBindings)[samplerIndex];
1092                 if (locationRef.arrayIndex < samplerBinding.boundTextureUnits.size())
1093                 {
1094                     // Crop unused sampler bindings in the sampler array.
1095                     samplerBinding.boundTextureUnits.resize(locationRef.arrayIndex);
1096                 }
1097             }
1098             else if (mState.isImageUniformIndex(locationRef.index))
1099             {
1100                 GLuint imageIndex = mState.getImageIndexFromUniformIndex(locationRef.index);
1101                 gl::ImageBinding &imageBinding = (*imageBindings)[imageIndex];
1102                 if (locationRef.arrayIndex < imageBinding.boundImageUnits.size())
1103                 {
1104                     // Crop unused image bindings in the image array.
1105                     imageBinding.boundImageUnits.resize(locationRef.arrayIndex);
1106                 }
1107             }
1108             // If the location has been previously bound by a glBindUniformLocation call, it should
1109             // be marked as ignored. Otherwise it's unused.
1110             if (mState.getUniformLocationBindings().getBindingByLocation(location) != -1)
1111             {
1112                 locationRef.markIgnored();
1113             }
1114             else
1115             {
1116                 locationRef.markUnused();
1117             }
1118         }
1119     }
1120 }
1121 
linkResources(const gl::ProgramLinkedResources & resources)1122 void ProgramGL::linkResources(const gl::ProgramLinkedResources &resources)
1123 {
1124     // Gather interface block info.
1125     auto getUniformBlockSize = [this](const std::string &name, const std::string &mappedName,
1126                                       size_t *sizeOut) {
1127         return this->getUniformBlockSize(name, mappedName, sizeOut);
1128     };
1129 
1130     auto getUniformBlockMemberInfo = [this](const std::string &name, const std::string &mappedName,
1131                                             sh::BlockMemberInfo *infoOut) {
1132         return this->getUniformBlockMemberInfo(name, mappedName, infoOut);
1133     };
1134 
1135     resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo);
1136 
1137     auto getShaderStorageBlockSize = [this](const std::string &name, const std::string &mappedName,
1138                                             size_t *sizeOut) {
1139         return this->getShaderStorageBlockSize(name, mappedName, sizeOut);
1140     };
1141 
1142     auto getShaderStorageBlockMemberInfo = [this](const std::string &name,
1143                                                   const std::string &mappedName,
1144                                                   sh::BlockMemberInfo *infoOut) {
1145         return this->getShaderStorageBlockMemberInfo(name, mappedName, infoOut);
1146     };
1147     resources.shaderStorageBlockLinker.linkBlocks(getShaderStorageBlockSize,
1148                                                   getShaderStorageBlockMemberInfo);
1149 
1150     // Gather atomic counter buffer info.
1151     std::map<int, unsigned int> sizeMap;
1152     getAtomicCounterBufferSizeMap(&sizeMap);
1153     resources.atomicCounterBufferLinker.link(sizeMap);
1154 }
1155 
syncState(const gl::Context * context,const gl::Program::DirtyBits & dirtyBits)1156 angle::Result ProgramGL::syncState(const gl::Context *context,
1157                                    const gl::Program::DirtyBits &dirtyBits)
1158 {
1159     for (size_t dirtyBit : dirtyBits)
1160     {
1161         ASSERT(dirtyBit <= gl::Program::DIRTY_BIT_UNIFORM_BLOCK_BINDING_MAX);
1162         GLuint binding = static_cast<GLuint>(dirtyBit);
1163         setUniformBlockBinding(binding, mState.getUniformBlockBinding(binding));
1164     }
1165     return angle::Result::Continue;
1166 }
1167 }  // namespace rx
1168