blob: 3c6fd400334ca854be22107f9de7d4940f5180d1 [file] [log] [blame]
Geoff Langf9a6f082015-01-22 13:32:49 -05001//
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
Sami Väisänen46eaa942016-06-29 10:26:37 +030011#include "common/angleutils.h"
Jamie Madillc564c072017-06-01 12:45:42 -040012#include "common/bitset_utils.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050013#include "common/debug.h"
Sami Väisänen46eaa942016-06-29 10:26:37 +030014#include "common/string_utils.h"
Geoff Lang5ed74cf2015-04-14 13:57:07 -040015#include "common/utilities.h"
Jamie Madillc564c072017-06-01 12:45:42 -040016#include "libANGLE/Context.h"
Jamie Madill6db1c2e2017-11-08 09:17:40 -050017#include "libANGLE/ProgramLinkedResources.h"
Jamie Madillc564c072017-06-01 12:45:42 -040018#include "libANGLE/Uniform.h"
Geoff Lang92019432017-11-20 13:09:34 -050019#include "libANGLE/queryconversions.h"
Jamie Madilla7d12dc2016-12-13 15:08:19 -050020#include "libANGLE/renderer/gl/ContextGL.h"
Geoff Langb1f435e2015-02-20 10:01:01 -050021#include "libANGLE/renderer/gl/FunctionsGL.h"
22#include "libANGLE/renderer/gl/ShaderGL.h"
23#include "libANGLE/renderer/gl/StateManagerGL.h"
Philippe Hamel40911192016-04-07 16:45:50 -040024#include "libANGLE/renderer/gl/WorkaroundsGL.h"
unknownb4a3af22015-11-25 15:02:51 -050025#include "platform/Platform.h"
Geoff Langf9a6f082015-01-22 13:32:49 -050026
27namespace rx
28{
29
Jamie Madill48ef11b2016-04-27 15:21:52 -040030ProgramGL::ProgramGL(const gl::ProgramState &data,
Jamie Madill5c6b7bf2015-08-17 12:53:35 -040031 const FunctionsGL *functions,
Philippe Hamel40911192016-04-07 16:45:50 -040032 const WorkaroundsGL &workarounds,
Sami Väisänen46eaa942016-06-29 10:26:37 +030033 StateManagerGL *stateManager,
34 bool enablePathRendering)
Philippe Hamel40911192016-04-07 16:45:50 -040035 : ProgramImpl(data),
36 mFunctions(functions),
37 mWorkarounds(workarounds),
38 mStateManager(stateManager),
Sami Väisänen46eaa942016-06-29 10:26:37 +030039 mEnablePathRendering(enablePathRendering),
Martin Radev4e619f52017-08-09 11:50:06 +030040 mMultiviewBaseViewLayerIndexUniformLocation(-1),
Philippe Hamel40911192016-04-07 16:45:50 -040041 mProgramID(0)
Geoff Langb1f435e2015-02-20 10:01:01 -050042{
43 ASSERT(mFunctions);
44 ASSERT(mStateManager);
Geoff Lang0ca53782015-05-07 13:49:39 -040045
46 mProgramID = mFunctions->createProgram();
Geoff Langb1f435e2015-02-20 10:01:01 -050047}
Geoff Langf9a6f082015-01-22 13:32:49 -050048
49ProgramGL::~ProgramGL()
Geoff Langb1f435e2015-02-20 10:01:01 -050050{
Geoff Lang0ca53782015-05-07 13:49:39 -040051 mFunctions->deleteProgram(mProgramID);
52 mProgramID = 0;
Geoff Langb1f435e2015-02-20 10:01:01 -050053}
Geoff Langf9a6f082015-01-22 13:32:49 -050054
Jamie Madill9cf9e872017-06-05 12:59:25 -040055gl::LinkResult ProgramGL::load(const gl::Context *context,
56 gl::InfoLog &infoLog,
57 gl::BinaryInputStream *stream)
Geoff Langf9a6f082015-01-22 13:32:49 -050058{
Geoff Lang65a0be92015-10-02 09:57:30 -040059 preLink();
60
61 // Read the binary format, size and blob
62 GLenum binaryFormat = stream->readInt<GLenum>();
63 GLint binaryLength = stream->readInt<GLint>();
64 const uint8_t *binary = stream->data() + stream->offset();
65 stream->skip(binaryLength);
66
67 // Load the binary
68 mFunctions->programBinary(mProgramID, binaryFormat, binary, binaryLength);
69
70 // Verify that the program linked
71 if (!checkLinkStatus(infoLog))
72 {
Jamie Madillb0a838b2016-11-13 20:02:12 -050073 return false;
Geoff Lang65a0be92015-10-02 09:57:30 -040074 }
75
76 postLink();
Jamie Madill27a60632017-06-30 15:12:01 -040077 reapplyUBOBindingsIfNeeded(context);
Jamie Madilla7d12dc2016-12-13 15:08:19 -050078
Jamie Madillb0a838b2016-11-13 20:02:12 -050079 return true;
Geoff Langf9a6f082015-01-22 13:32:49 -050080}
81
Jamie Madill27a60632017-06-30 15:12:01 -040082void ProgramGL::save(const gl::Context *context, gl::BinaryOutputStream *stream)
Geoff Langf9a6f082015-01-22 13:32:49 -050083{
Geoff Lang65a0be92015-10-02 09:57:30 -040084 GLint binaryLength = 0;
85 mFunctions->getProgramiv(mProgramID, GL_PROGRAM_BINARY_LENGTH, &binaryLength);
86
Geoff Lang416a23e2017-11-20 12:34:20 -050087 std::vector<uint8_t> binary(std::max(binaryLength, 1));
Geoff Lang65a0be92015-10-02 09:57:30 -040088 GLenum binaryFormat = GL_NONE;
89 mFunctions->getProgramBinary(mProgramID, binaryLength, &binaryLength, &binaryFormat,
Geoff Lang416a23e2017-11-20 12:34:20 -050090 binary.data());
Geoff Lang65a0be92015-10-02 09:57:30 -040091
92 stream->writeInt(binaryFormat);
93 stream->writeInt(binaryLength);
Geoff Lang416a23e2017-11-20 12:34:20 -050094 stream->writeBytes(binary.data(), binaryLength);
Jamie Madill27a60632017-06-30 15:12:01 -040095
96 reapplyUBOBindingsIfNeeded(context);
97}
98
99void ProgramGL::reapplyUBOBindingsIfNeeded(const gl::Context *context)
100{
101 // Re-apply UBO bindings to work around driver bugs.
102 const WorkaroundsGL &workaroundsGL = GetImplAs<ContextGL>(context)->getWorkaroundsGL();
103 if (workaroundsGL.reapplyUBOBindingsAfterUsingBinaryProgram)
104 {
105 const auto &blocks = mState.getUniformBlocks();
106 for (size_t blockIndex : mState.getActiveUniformBlockBindingsMask())
107 {
108 setUniformBlockBinding(static_cast<GLuint>(blockIndex), blocks[blockIndex].binding);
109 }
110 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500111}
112
Geoff Langc5629752015-12-07 16:29:04 -0500113void ProgramGL::setBinaryRetrievableHint(bool retrievable)
114{
Geoff Lang65a0be92015-10-02 09:57:30 -0400115 // glProgramParameteri isn't always available on ES backends.
116 if (mFunctions->programParameteri)
117 {
118 mFunctions->programParameteri(mProgramID, GL_PROGRAM_BINARY_RETRIEVABLE_HINT,
119 retrievable ? GL_TRUE : GL_FALSE);
120 }
Geoff Langc5629752015-12-07 16:29:04 -0500121}
122
Yunchao He61afff12017-03-14 15:34:03 +0800123void ProgramGL::setSeparable(bool separable)
124{
125 mFunctions->programParameteri(mProgramID, GL_PROGRAM_SEPARABLE, separable ? GL_TRUE : GL_FALSE);
126}
127
jchen107ae70d82018-07-06 13:47:01 +0800128std::unique_ptr<LinkEvent> ProgramGL::link(const gl::Context *context,
129 const gl::ProgramLinkedResources &resources,
130 gl::InfoLog &infoLog)
131{
132 // TODO(jie.a.chen@intel.com): Parallelize linking.
133 return std::make_unique<LinkEventDone>(linkImpl(context, resources, infoLog));
134}
135
136gl::LinkResult ProgramGL::linkImpl(const gl::Context *context,
137 const gl::ProgramLinkedResources &resources,
138 gl::InfoLog &infoLog)
Geoff Langf9a6f082015-01-22 13:32:49 -0500139{
Geoff Lang65a0be92015-10-02 09:57:30 -0400140 preLink();
Geoff Langb1f435e2015-02-20 10:01:01 -0500141
Jiawei Shao385b3e02018-03-21 09:43:28 +0800142 if (mState.getAttachedShader(gl::ShaderType::Compute))
Geoff Lang1a683462015-09-29 15:09:59 -0400143 {
Jiawei Shao385b3e02018-03-21 09:43:28 +0800144 const ShaderGL *computeShaderGL =
145 GetImplAs<ShaderGL>(mState.getAttachedShader(gl::ShaderType::Compute));
Geoff Lang1a683462015-09-29 15:09:59 -0400146
Martin Radev4c4c8e72016-08-04 12:25:34 +0300147 mFunctions->attachShader(mProgramID, computeShaderGL->getShaderID());
148
149 // Link and verify
150 mFunctions->linkProgram(mProgramID);
151
152 // Detach the shaders
153 mFunctions->detachShader(mProgramID, computeShaderGL->getShaderID());
Geoff Lang1a683462015-09-29 15:09:59 -0400154 }
155 else
156 {
Martin Radev4c4c8e72016-08-04 12:25:34 +0300157 // Set the transform feedback state
Olli Etuaho855d9642017-05-17 14:05:06 +0300158 std::vector<std::string> transformFeedbackVaryingMappedNames;
Martin Radev4c4c8e72016-08-04 12:25:34 +0300159 for (const auto &tfVarying : mState.getTransformFeedbackVaryingNames())
Geoff Lang1528e562015-08-24 15:10:58 -0400160 {
Olli Etuaho855d9642017-05-17 14:05:06 +0300161 std::string tfVaryingMappedName =
Jiawei Shao385b3e02018-03-21 09:43:28 +0800162 mState.getAttachedShader(gl::ShaderType::Vertex)
163 ->getTransformFeedbackVaryingMappedName(tfVarying, context);
Olli Etuaho855d9642017-05-17 14:05:06 +0300164 transformFeedbackVaryingMappedNames.push_back(tfVaryingMappedName);
Geoff Lang1528e562015-08-24 15:10:58 -0400165 }
166
Olli Etuaho855d9642017-05-17 14:05:06 +0300167 if (transformFeedbackVaryingMappedNames.empty())
Martin Radev4c4c8e72016-08-04 12:25:34 +0300168 {
169 if (mFunctions->transformFeedbackVaryings)
170 {
171 mFunctions->transformFeedbackVaryings(mProgramID, 0, nullptr,
172 mState.getTransformFeedbackBufferMode());
173 }
174 }
175 else
176 {
177 ASSERT(mFunctions->transformFeedbackVaryings);
Olli Etuaho855d9642017-05-17 14:05:06 +0300178 std::vector<const GLchar *> transformFeedbackVaryings;
179 for (const auto &varying : transformFeedbackVaryingMappedNames)
180 {
181 transformFeedbackVaryings.push_back(varying.c_str());
182 }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300183 mFunctions->transformFeedbackVaryings(
Olli Etuaho855d9642017-05-17 14:05:06 +0300184 mProgramID, static_cast<GLsizei>(transformFeedbackVaryingMappedNames.size()),
Martin Radev4c4c8e72016-08-04 12:25:34 +0300185 &transformFeedbackVaryings[0], mState.getTransformFeedbackBufferMode());
186 }
187
Jiawei Shao385b3e02018-03-21 09:43:28 +0800188 const ShaderGL *vertexShaderGL =
189 GetImplAs<ShaderGL>(mState.getAttachedShader(gl::ShaderType::Vertex));
190 const ShaderGL *fragmentShaderGL =
191 GetImplAs<ShaderGL>(mState.getAttachedShader(gl::ShaderType::Fragment));
192 const ShaderGL *geometryShaderGL = rx::SafeGetImplAs<ShaderGL, gl::Shader>(
193 mState.getAttachedShader(gl::ShaderType::Geometry));
Martin Radev4c4c8e72016-08-04 12:25:34 +0300194
195 // Attach the shaders
196 mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID());
197 mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID());
Jiawei Shao4ed05da2018-02-02 14:26:15 +0800198 if (geometryShaderGL)
199 {
200 mFunctions->attachShader(mProgramID, geometryShaderGL->getShaderID());
201 }
Martin Radev4c4c8e72016-08-04 12:25:34 +0300202
203 // Bind attribute locations to match the GL layer.
204 for (const sh::Attribute &attribute : mState.getAttributes())
205 {
Olli Etuaho107c7242018-03-20 15:45:35 +0200206 if (!attribute.active || attribute.isBuiltIn())
Martin Radev4c4c8e72016-08-04 12:25:34 +0300207 {
208 continue;
209 }
210
Olli Etuaho855d9642017-05-17 14:05:06 +0300211 mFunctions->bindAttribLocation(mProgramID, attribute.location,
212 attribute.mappedName.c_str());
Martin Radev4c4c8e72016-08-04 12:25:34 +0300213 }
214
215 // Link and verify
216 mFunctions->linkProgram(mProgramID);
217
218 // Detach the shaders
219 mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID());
220 mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID());
Jiawei Shao4ed05da2018-02-02 14:26:15 +0800221 if (geometryShaderGL)
222 {
223 mFunctions->detachShader(mProgramID, geometryShaderGL->getShaderID());
224 }
Geoff Lang1528e562015-08-24 15:10:58 -0400225 }
226
Geoff Lang0ca53782015-05-07 13:49:39 -0400227 // Verify the link
Geoff Lang65a0be92015-10-02 09:57:30 -0400228 if (!checkLinkStatus(infoLog))
Geoff Langb1f435e2015-02-20 10:01:01 -0500229 {
Jamie Madillb0a838b2016-11-13 20:02:12 -0500230 return false;
Geoff Langb1f435e2015-02-20 10:01:01 -0500231 }
232
Philippe Hamel40911192016-04-07 16:45:50 -0400233 if (mWorkarounds.alwaysCallUseProgramAfterLink)
234 {
235 mStateManager->forceUseProgram(mProgramID);
236 }
237
Jamie Madill6db1c2e2017-11-08 09:17:40 -0500238 linkResources(resources);
Geoff Lang65a0be92015-10-02 09:57:30 -0400239 postLink();
Geoff Langb1f435e2015-02-20 10:01:01 -0500240
Jamie Madillb0a838b2016-11-13 20:02:12 -0500241 return true;
Geoff Langf9a6f082015-01-22 13:32:49 -0500242}
243
Jamie Madill36cfd6a2015-08-18 10:46:20 -0400244GLboolean ProgramGL::validate(const gl::Caps & /*caps*/, gl::InfoLog * /*infoLog*/)
245{
246 // TODO(jmadill): implement validate
247 return true;
248}
249
Geoff Langf9a6f082015-01-22 13:32:49 -0500250void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
251{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800252 if (mFunctions->programUniform1fv != nullptr)
253 {
254 mFunctions->programUniform1fv(mProgramID, uniLoc(location), count, v);
255 }
256 else
257 {
258 mStateManager->useProgram(mProgramID);
259 mFunctions->uniform1fv(uniLoc(location), count, v);
260 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500261}
262
263void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
264{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800265 if (mFunctions->programUniform2fv != nullptr)
266 {
267 mFunctions->programUniform2fv(mProgramID, uniLoc(location), count, v);
268 }
269 else
270 {
271 mStateManager->useProgram(mProgramID);
272 mFunctions->uniform2fv(uniLoc(location), count, v);
273 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500274}
275
276void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
277{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800278 if (mFunctions->programUniform3fv != nullptr)
279 {
280 mFunctions->programUniform3fv(mProgramID, uniLoc(location), count, v);
281 }
282 else
283 {
284 mStateManager->useProgram(mProgramID);
285 mFunctions->uniform3fv(uniLoc(location), count, v);
286 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500287}
288
289void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
290{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800291 if (mFunctions->programUniform4fv != nullptr)
292 {
293 mFunctions->programUniform4fv(mProgramID, uniLoc(location), count, v);
294 }
295 else
296 {
297 mStateManager->useProgram(mProgramID);
298 mFunctions->uniform4fv(uniLoc(location), count, v);
299 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500300}
301
302void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v)
303{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800304 if (mFunctions->programUniform1iv != nullptr)
305 {
306 mFunctions->programUniform1iv(mProgramID, uniLoc(location), count, v);
307 }
308 else
309 {
310 mStateManager->useProgram(mProgramID);
311 mFunctions->uniform1iv(uniLoc(location), count, v);
312 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500313}
314
315void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v)
316{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800317 if (mFunctions->programUniform2iv != nullptr)
318 {
319 mFunctions->programUniform2iv(mProgramID, uniLoc(location), count, v);
320 }
321 else
322 {
323 mStateManager->useProgram(mProgramID);
324 mFunctions->uniform2iv(uniLoc(location), count, v);
325 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500326}
327
328void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v)
329{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800330 if (mFunctions->programUniform3iv != nullptr)
331 {
332 mFunctions->programUniform3iv(mProgramID, uniLoc(location), count, v);
333 }
334 else
335 {
336 mStateManager->useProgram(mProgramID);
337 mFunctions->uniform3iv(uniLoc(location), count, v);
338 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500339}
340
341void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v)
342{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800343 if (mFunctions->programUniform4iv != nullptr)
344 {
345 mFunctions->programUniform4iv(mProgramID, uniLoc(location), count, v);
346 }
347 else
348 {
349 mStateManager->useProgram(mProgramID);
350 mFunctions->uniform4iv(uniLoc(location), count, v);
351 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500352}
353
354void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
355{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800356 if (mFunctions->programUniform1uiv != nullptr)
357 {
358 mFunctions->programUniform1uiv(mProgramID, uniLoc(location), count, v);
359 }
360 else
361 {
362 mStateManager->useProgram(mProgramID);
363 mFunctions->uniform1uiv(uniLoc(location), count, v);
364 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500365}
366
367void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
368{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800369 if (mFunctions->programUniform2uiv != nullptr)
370 {
371 mFunctions->programUniform2uiv(mProgramID, uniLoc(location), count, v);
372 }
373 else
374 {
375 mStateManager->useProgram(mProgramID);
376 mFunctions->uniform2uiv(uniLoc(location), count, v);
377 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500378}
379
380void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
381{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800382 if (mFunctions->programUniform3uiv != nullptr)
383 {
384 mFunctions->programUniform3uiv(mProgramID, uniLoc(location), count, v);
385 }
386 else
387 {
388 mStateManager->useProgram(mProgramID);
389 mFunctions->uniform3uiv(uniLoc(location), count, v);
390 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500391}
392
393void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
394{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800395 if (mFunctions->programUniform4uiv != nullptr)
396 {
397 mFunctions->programUniform4uiv(mProgramID, uniLoc(location), count, v);
398 }
399 else
400 {
401 mStateManager->useProgram(mProgramID);
402 mFunctions->uniform4uiv(uniLoc(location), count, v);
403 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500404}
405
406void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
407{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800408 if (mFunctions->programUniformMatrix2fv != nullptr)
409 {
410 mFunctions->programUniformMatrix2fv(mProgramID, uniLoc(location), count, transpose, value);
411 }
412 else
413 {
414 mStateManager->useProgram(mProgramID);
415 mFunctions->uniformMatrix2fv(uniLoc(location), count, transpose, value);
416 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500417}
418
419void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
420{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800421 if (mFunctions->programUniformMatrix3fv != nullptr)
422 {
423 mFunctions->programUniformMatrix3fv(mProgramID, uniLoc(location), count, transpose, value);
424 }
425 else
426 {
427 mStateManager->useProgram(mProgramID);
428 mFunctions->uniformMatrix3fv(uniLoc(location), count, transpose, value);
429 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500430}
431
432void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
433{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800434 if (mFunctions->programUniformMatrix4fv != nullptr)
435 {
436 mFunctions->programUniformMatrix4fv(mProgramID, uniLoc(location), count, transpose, value);
437 }
438 else
439 {
440 mStateManager->useProgram(mProgramID);
441 mFunctions->uniformMatrix4fv(uniLoc(location), count, transpose, value);
442 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500443}
444
445void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
446{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800447 if (mFunctions->programUniformMatrix2x3fv != nullptr)
448 {
449 mFunctions->programUniformMatrix2x3fv(mProgramID, uniLoc(location), count, transpose,
450 value);
451 }
452 else
453 {
454 mStateManager->useProgram(mProgramID);
455 mFunctions->uniformMatrix2x3fv(uniLoc(location), count, transpose, value);
456 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500457}
458
459void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
460{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800461 if (mFunctions->programUniformMatrix3x2fv != nullptr)
462 {
463 mFunctions->programUniformMatrix3x2fv(mProgramID, uniLoc(location), count, transpose,
464 value);
465 }
466 else
467 {
468 mStateManager->useProgram(mProgramID);
469 mFunctions->uniformMatrix3x2fv(uniLoc(location), count, transpose, value);
470 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500471}
472
473void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
474{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800475 if (mFunctions->programUniformMatrix2x4fv != nullptr)
476 {
477 mFunctions->programUniformMatrix2x4fv(mProgramID, uniLoc(location), count, transpose,
478 value);
479 }
480 else
481 {
482 mStateManager->useProgram(mProgramID);
483 mFunctions->uniformMatrix2x4fv(uniLoc(location), count, transpose, value);
484 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500485}
486
487void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
488{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800489 if (mFunctions->programUniformMatrix4x2fv != nullptr)
490 {
491 mFunctions->programUniformMatrix4x2fv(mProgramID, uniLoc(location), count, transpose,
492 value);
493 }
494 else
495 {
496 mStateManager->useProgram(mProgramID);
497 mFunctions->uniformMatrix4x2fv(uniLoc(location), count, transpose, value);
498 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500499}
500
501void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
502{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800503 if (mFunctions->programUniformMatrix3x4fv != nullptr)
504 {
505 mFunctions->programUniformMatrix3x4fv(mProgramID, uniLoc(location), count, transpose,
506 value);
507 }
508 else
509 {
510 mStateManager->useProgram(mProgramID);
511 mFunctions->uniformMatrix3x4fv(uniLoc(location), count, transpose, value);
512 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500513}
514
515void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
516{
Jiajia Qinee9f08c2016-11-16 10:06:10 +0800517 if (mFunctions->programUniformMatrix4x3fv != nullptr)
518 {
519 mFunctions->programUniformMatrix4x3fv(mProgramID, uniLoc(location), count, transpose,
520 value);
521 }
522 else
523 {
524 mStateManager->useProgram(mProgramID);
525 mFunctions->uniformMatrix4x3fv(uniLoc(location), count, transpose, value);
526 }
Geoff Langf9a6f082015-01-22 13:32:49 -0500527}
528
Geoff Lang5d124a62015-09-15 13:03:27 -0400529void ProgramGL::setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding)
530{
Jamie Madill4a3c2342015-10-08 12:58:45 -0400531 // Lazy init
532 if (mUniformBlockRealLocationMap.empty())
533 {
Jamie Madill48ef11b2016-04-27 15:21:52 -0400534 mUniformBlockRealLocationMap.reserve(mState.getUniformBlocks().size());
Jiajia Qin729b2c62017-08-14 09:36:11 +0800535 for (const gl::InterfaceBlock &uniformBlock : mState.getUniformBlocks())
Jamie Madill4a3c2342015-10-08 12:58:45 -0400536 {
Olli Etuaho855d9642017-05-17 14:05:06 +0300537 const std::string &mappedNameWithIndex = uniformBlock.mappedNameWithArrayIndex();
538 GLuint blockIndex =
539 mFunctions->getUniformBlockIndex(mProgramID, mappedNameWithIndex.c_str());
Jamie Madill4a3c2342015-10-08 12:58:45 -0400540 mUniformBlockRealLocationMap.push_back(blockIndex);
541 }
542 }
543
544 GLuint realBlockIndex = mUniformBlockRealLocationMap[uniformBlockIndex];
545 if (realBlockIndex != GL_INVALID_INDEX)
546 {
547 mFunctions->uniformBlockBinding(mProgramID, realBlockIndex, uniformBlockBinding);
548 }
Geoff Lang5d124a62015-09-15 13:03:27 -0400549}
550
Geoff Langb1f435e2015-02-20 10:01:01 -0500551GLuint ProgramGL::getProgramID() const
552{
553 return mProgramID;
554}
555
Olli Etuaho855d9642017-05-17 14:05:06 +0300556bool ProgramGL::getUniformBlockSize(const std::string & /* blockName */,
557 const std::string &blockMappedName,
558 size_t *sizeOut) const
Jamie Madill62d31cb2015-09-11 13:25:51 -0400559{
Jamie Madill4a3c2342015-10-08 12:58:45 -0400560 ASSERT(mProgramID != 0u);
Geoff Lang5d124a62015-09-15 13:03:27 -0400561
Olli Etuaho855d9642017-05-17 14:05:06 +0300562 GLuint blockIndex = mFunctions->getUniformBlockIndex(mProgramID, blockMappedName.c_str());
Jamie Madill4a3c2342015-10-08 12:58:45 -0400563 if (blockIndex == GL_INVALID_INDEX)
Geoff Lang5d124a62015-09-15 13:03:27 -0400564 {
Jamie Madill4a3c2342015-10-08 12:58:45 -0400565 *sizeOut = 0;
566 return false;
Geoff Lang5d124a62015-09-15 13:03:27 -0400567 }
568
Jamie Madill4a3c2342015-10-08 12:58:45 -0400569 GLint dataSize = 0;
570 mFunctions->getActiveUniformBlockiv(mProgramID, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
571 &dataSize);
572 *sizeOut = static_cast<size_t>(dataSize);
573 return true;
574}
575
Olli Etuaho855d9642017-05-17 14:05:06 +0300576bool ProgramGL::getUniformBlockMemberInfo(const std::string & /* memberUniformName */,
577 const std::string &memberUniformMappedName,
Jamie Madill4a3c2342015-10-08 12:58:45 -0400578 sh::BlockMemberInfo *memberInfoOut) const
579{
580 GLuint uniformIndex;
Olli Etuaho855d9642017-05-17 14:05:06 +0300581 const GLchar *memberNameGLStr = memberUniformMappedName.c_str();
Jamie Madill4a3c2342015-10-08 12:58:45 -0400582 mFunctions->getUniformIndices(mProgramID, 1, &memberNameGLStr, &uniformIndex);
583
584 if (uniformIndex == GL_INVALID_INDEX)
Geoff Lang5d124a62015-09-15 13:03:27 -0400585 {
Jamie Madill4a3c2342015-10-08 12:58:45 -0400586 *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo();
587 return false;
Geoff Lang5d124a62015-09-15 13:03:27 -0400588 }
Jamie Madill4a3c2342015-10-08 12:58:45 -0400589
590 mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_OFFSET,
591 &memberInfoOut->offset);
592 mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_ARRAY_STRIDE,
593 &memberInfoOut->arrayStride);
594 mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_MATRIX_STRIDE,
595 &memberInfoOut->matrixStride);
596
597 // TODO(jmadill): possibly determine this at the gl::Program level.
598 GLint isRowMajorMatrix = 0;
599 mFunctions->getActiveUniformsiv(mProgramID, 1, &uniformIndex, GL_UNIFORM_IS_ROW_MAJOR,
600 &isRowMajorMatrix);
Geoff Lang92019432017-11-20 13:09:34 -0500601 memberInfoOut->isRowMajorMatrix = gl::ConvertToBool(isRowMajorMatrix);
Jamie Madill4a3c2342015-10-08 12:58:45 -0400602 return true;
Jamie Madill62d31cb2015-09-11 13:25:51 -0400603}
Jamie Madill4a3c2342015-10-08 12:58:45 -0400604
Jiajia Qin3a9090f2017-09-27 14:37:04 +0800605bool ProgramGL::getShaderStorageBlockMemberInfo(const std::string & /* memberName */,
606 const std::string &memberUniformMappedName,
607 sh::BlockMemberInfo *memberInfoOut) const
608{
609 const GLchar *memberNameGLStr = memberUniformMappedName.c_str();
610 GLuint index =
611 mFunctions->getProgramResourceIndex(mProgramID, GL_BUFFER_VARIABLE, memberNameGLStr);
612
613 if (index == GL_INVALID_INDEX)
614 {
615 *memberInfoOut = sh::BlockMemberInfo::getDefaultBlockInfo();
616 return false;
617 }
618
619 constexpr int kPropCount = 5;
620 std::array<GLenum, kPropCount> props = {
621 {GL_ARRAY_STRIDE, GL_IS_ROW_MAJOR, GL_MATRIX_STRIDE, GL_OFFSET, GL_TOP_LEVEL_ARRAY_STRIDE}};
622 std::array<GLint, kPropCount> params;
623 GLsizei length;
624 mFunctions->getProgramResourceiv(mProgramID, GL_BUFFER_VARIABLE, index, kPropCount,
625 props.data(), kPropCount, &length, params.data());
626 ASSERT(kPropCount == length);
627 memberInfoOut->arrayStride = params[0];
Olli Etuahoc4eca922017-11-13 12:27:23 +0200628 memberInfoOut->isRowMajorMatrix = params[1] != 0;
Jiajia Qin3a9090f2017-09-27 14:37:04 +0800629 memberInfoOut->matrixStride = params[2];
630 memberInfoOut->offset = params[3];
631 memberInfoOut->topLevelArrayStride = params[4];
632
633 return true;
634}
635
636bool ProgramGL::getShaderStorageBlockSize(const std::string &name,
637 const std::string &mappedName,
638 size_t *sizeOut) const
639{
640 const GLchar *nameGLStr = mappedName.c_str();
641 GLuint index =
642 mFunctions->getProgramResourceIndex(mProgramID, GL_SHADER_STORAGE_BLOCK, nameGLStr);
643
644 if (index == GL_INVALID_INDEX)
645 {
646 *sizeOut = 0;
647 return false;
648 }
649
650 GLenum prop = GL_BUFFER_DATA_SIZE;
651 GLsizei length = 0;
652 GLint dataSize = 0;
653 mFunctions->getProgramResourceiv(mProgramID, GL_SHADER_STORAGE_BLOCK, index, 1, &prop, 1,
654 &length, &dataSize);
655 *sizeOut = static_cast<size_t>(dataSize);
656 return true;
657}
658
Jiajia Qin94f1e892017-11-20 12:14:32 +0800659void ProgramGL::getAtomicCounterBufferSizeMap(std::map<int, unsigned int> *sizeMapOut) const
660{
661 if (mFunctions->getProgramInterfaceiv == nullptr)
662 {
663 return;
664 }
665
666 int resourceCount = 0;
667 mFunctions->getProgramInterfaceiv(mProgramID, GL_ATOMIC_COUNTER_BUFFER, GL_ACTIVE_RESOURCES,
668 &resourceCount);
669
670 for (int index = 0; index < resourceCount; index++)
671 {
672 constexpr int kPropCount = 2;
673 std::array<GLenum, kPropCount> props = {{GL_BUFFER_BINDING, GL_BUFFER_DATA_SIZE}};
674 std::array<GLint, kPropCount> params;
675 GLsizei length;
676 mFunctions->getProgramResourceiv(mProgramID, GL_ATOMIC_COUNTER_BUFFER, index, kPropCount,
677 props.data(), kPropCount, &length, params.data());
678 ASSERT(kPropCount == length);
679 int bufferBinding = params[0];
680 unsigned int bufferDataSize = params[1];
681 sizeMapOut->insert(std::pair<int, unsigned int>(bufferBinding, bufferDataSize));
682 }
683}
684
Sami Väisänen46eaa942016-06-29 10:26:37 +0300685void ProgramGL::setPathFragmentInputGen(const std::string &inputName,
686 GLenum genMode,
687 GLint components,
688 const GLfloat *coeffs)
689{
690 ASSERT(mEnablePathRendering);
691
692 for (const auto &input : mPathRenderingFragmentInputs)
693 {
Olli Etuaho855d9642017-05-17 14:05:06 +0300694 if (input.mappedName == inputName)
Sami Väisänen46eaa942016-06-29 10:26:37 +0300695 {
696 mFunctions->programPathFragmentInputGenNV(mProgramID, input.location, genMode,
697 components, coeffs);
698 ASSERT(mFunctions->getError() == GL_NO_ERROR);
699 return;
700 }
701 }
702
703}
704
Geoff Lang65a0be92015-10-02 09:57:30 -0400705void ProgramGL::preLink()
706{
707 // Reset the program state
708 mUniformRealLocationMap.clear();
709 mUniformBlockRealLocationMap.clear();
Sami Väisänen46eaa942016-06-29 10:26:37 +0300710 mPathRenderingFragmentInputs.clear();
Martin Radev4e619f52017-08-09 11:50:06 +0300711
712 mMultiviewBaseViewLayerIndexUniformLocation = -1;
Geoff Lang65a0be92015-10-02 09:57:30 -0400713}
714
715bool ProgramGL::checkLinkStatus(gl::InfoLog &infoLog)
716{
717 GLint linkStatus = GL_FALSE;
718 mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
719 if (linkStatus == GL_FALSE)
720 {
Olli Etuaho81f891d2018-08-02 15:54:55 +0300721 // Linking or program binary loading failed, put the error into the info log.
Geoff Lang65a0be92015-10-02 09:57:30 -0400722 GLint infoLogLength = 0;
723 mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength);
724
Geoff Lang65a0be92015-10-02 09:57:30 -0400725 // Info log length includes the null terminator, so 1 means that the info log is an empty
726 // string.
727 if (infoLogLength > 1)
728 {
729 std::vector<char> buf(infoLogLength);
730 mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]);
731
Geoff Lang65a0be92015-10-02 09:57:30 -0400732 infoLog << buf.data();
733
Olli Etuaho81f891d2018-08-02 15:54:55 +0300734 WARN() << "Program link or binary loading failed: " << buf.data();
Geoff Lang65a0be92015-10-02 09:57:30 -0400735 }
736 else
737 {
Olli Etuaho81f891d2018-08-02 15:54:55 +0300738 WARN() << "Program link or binary loading failed with no info log.";
Geoff Lang65a0be92015-10-02 09:57:30 -0400739 }
Geoff Lang65a0be92015-10-02 09:57:30 -0400740
Olli Etuaho81f891d2018-08-02 15:54:55 +0300741 // This may happen under normal circumstances if we're loading program binaries and the
742 // driver or hardware has changed.
743 ASSERT(mProgramID != 0);
Geoff Lang65a0be92015-10-02 09:57:30 -0400744 return false;
745 }
746
747 return true;
748}
749
750void ProgramGL::postLink()
751{
752 // Query the uniform information
753 ASSERT(mUniformRealLocationMap.empty());
Jamie Madill48ef11b2016-04-27 15:21:52 -0400754 const auto &uniformLocations = mState.getUniformLocations();
755 const auto &uniforms = mState.getUniforms();
Geoff Lang65a0be92015-10-02 09:57:30 -0400756 mUniformRealLocationMap.resize(uniformLocations.size(), GL_INVALID_INDEX);
757 for (size_t uniformLocation = 0; uniformLocation < uniformLocations.size(); uniformLocation++)
758 {
759 const auto &entry = uniformLocations[uniformLocation];
Jamie Madillfb997ec2017-09-20 15:44:27 -0400760 if (!entry.used())
Geoff Lang65a0be92015-10-02 09:57:30 -0400761 {
762 continue;
763 }
764
Olli Etuahoc8538042017-09-27 11:20:15 +0300765 // From the GLES 3.0.5 spec:
Geoff Lang65a0be92015-10-02 09:57:30 -0400766 // "Locations for sequential array indices are not required to be sequential."
767 const gl::LinkedUniform &uniform = uniforms[entry.index];
768 std::stringstream fullNameStr;
Geoff Lang65a0be92015-10-02 09:57:30 -0400769 if (uniform.isArray())
770 {
Olli Etuahod2551232017-10-26 20:03:33 +0300771 ASSERT(angle::EndsWith(uniform.mappedName, "[0]"));
772 fullNameStr << uniform.mappedName.substr(0, uniform.mappedName.length() - 3);
Olli Etuaho1734e172017-10-27 15:30:27 +0300773 fullNameStr << "[" << entry.arrayIndex << "]";
Olli Etuahod2551232017-10-26 20:03:33 +0300774 }
775 else
776 {
777 fullNameStr << uniform.mappedName;
Geoff Lang65a0be92015-10-02 09:57:30 -0400778 }
779 const std::string &fullName = fullNameStr.str();
780
781 GLint realLocation = mFunctions->getUniformLocation(mProgramID, fullName.c_str());
782 mUniformRealLocationMap[uniformLocation] = realLocation;
783 }
784
Martin Radev4e619f52017-08-09 11:50:06 +0300785 if (mState.usesMultiview())
786 {
787 mMultiviewBaseViewLayerIndexUniformLocation =
Olli Etuaho855d9642017-05-17 14:05:06 +0300788 mFunctions->getUniformLocation(mProgramID, "multiviewBaseViewLayerIndex");
Martin Radev4e619f52017-08-09 11:50:06 +0300789 ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
790 }
791
Sami Väisänen46eaa942016-06-29 10:26:37 +0300792 // Discover CHROMIUM_path_rendering fragment inputs if enabled.
793 if (!mEnablePathRendering)
794 return;
795
796 GLint numFragmentInputs = 0;
797 mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_ACTIVE_RESOURCES,
798 &numFragmentInputs);
799 if (numFragmentInputs <= 0)
800 return;
801
802 GLint maxNameLength = 0;
803 mFunctions->getProgramInterfaceiv(mProgramID, GL_FRAGMENT_INPUT_NV, GL_MAX_NAME_LENGTH,
804 &maxNameLength);
805 ASSERT(maxNameLength);
806
807 for (GLint i = 0; i < numFragmentInputs; ++i)
808 {
Olli Etuaho855d9642017-05-17 14:05:06 +0300809 std::string mappedName;
810 mappedName.resize(maxNameLength);
Sami Väisänen46eaa942016-06-29 10:26:37 +0300811
812 GLsizei nameLen = 0;
813 mFunctions->getProgramResourceName(mProgramID, GL_FRAGMENT_INPUT_NV, i, maxNameLength,
Olli Etuaho855d9642017-05-17 14:05:06 +0300814 &nameLen, &mappedName[0]);
815 mappedName.resize(nameLen);
Sami Väisänen46eaa942016-06-29 10:26:37 +0300816
817 // Ignore built-ins
Olli Etuaho855d9642017-05-17 14:05:06 +0300818 if (angle::BeginsWith(mappedName, "gl_"))
Sami Väisänen46eaa942016-06-29 10:26:37 +0300819 continue;
820
821 const GLenum kQueryProperties[] = {GL_LOCATION, GL_ARRAY_SIZE};
822 GLint queryResults[ArraySize(kQueryProperties)];
823 GLsizei queryLength = 0;
824
Geoff Lang3f6a3982016-07-15 15:20:45 -0400825 mFunctions->getProgramResourceiv(
826 mProgramID, GL_FRAGMENT_INPUT_NV, i, static_cast<GLsizei>(ArraySize(kQueryProperties)),
827 kQueryProperties, static_cast<GLsizei>(ArraySize(queryResults)), &queryLength,
828 queryResults);
Sami Väisänen46eaa942016-06-29 10:26:37 +0300829
Olli Etuahoe3191712016-07-18 16:01:10 +0300830 ASSERT(queryLength == static_cast<GLsizei>(ArraySize(kQueryProperties)));
Sami Väisänen46eaa942016-06-29 10:26:37 +0300831
Geoff Lang3f6a3982016-07-15 15:20:45 -0400832 PathRenderingFragmentInput baseElementInput;
Olli Etuaho855d9642017-05-17 14:05:06 +0300833 baseElementInput.mappedName = mappedName;
Geoff Lang3f6a3982016-07-15 15:20:45 -0400834 baseElementInput.location = queryResults[0];
835 mPathRenderingFragmentInputs.push_back(std::move(baseElementInput));
Sami Väisänen46eaa942016-06-29 10:26:37 +0300836
837 // If the input is an array it's denoted by [0] suffix on the variable
838 // name. We'll then create an entry per each array index where index > 0
Olli Etuaho855d9642017-05-17 14:05:06 +0300839 if (angle::EndsWith(mappedName, "[0]"))
Sami Väisänen46eaa942016-06-29 10:26:37 +0300840 {
841 // drop the suffix
Olli Etuaho855d9642017-05-17 14:05:06 +0300842 mappedName.resize(mappedName.size() - 3);
Sami Väisänen46eaa942016-06-29 10:26:37 +0300843
844 const auto arraySize = queryResults[1];
845 const auto baseLocation = queryResults[0];
846
Geoff Lang3f6a3982016-07-15 15:20:45 -0400847 for (GLint arrayIndex = 1; arrayIndex < arraySize; ++arrayIndex)
Sami Väisänen46eaa942016-06-29 10:26:37 +0300848 {
Geoff Lang3f6a3982016-07-15 15:20:45 -0400849 PathRenderingFragmentInput arrayElementInput;
Olli Etuaho855d9642017-05-17 14:05:06 +0300850 arrayElementInput.mappedName = mappedName + "[" + ToString(arrayIndex) + "]";
Geoff Lang3f6a3982016-07-15 15:20:45 -0400851 arrayElementInput.location = baseLocation + arrayIndex;
852 mPathRenderingFragmentInputs.push_back(std::move(arrayElementInput));
Sami Väisänen46eaa942016-06-29 10:26:37 +0300853 }
854 }
855 }
Geoff Lang65a0be92015-10-02 09:57:30 -0400856}
857
Martin Radev4e619f52017-08-09 11:50:06 +0300858void ProgramGL::enableSideBySideRenderingPath() const
859{
860 ASSERT(mState.usesMultiview());
861 ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
862
863 ASSERT(mFunctions->programUniform1i != nullptr);
864 mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation, -1);
865}
866
867void ProgramGL::enableLayeredRenderingPath(int baseViewIndex) const
868{
869 ASSERT(mState.usesMultiview());
870 ASSERT(mMultiviewBaseViewLayerIndexUniformLocation != -1);
871
872 ASSERT(mFunctions->programUniform1i != nullptr);
873 mFunctions->programUniform1i(mProgramID, mMultiviewBaseViewLayerIndexUniformLocation,
874 baseViewIndex);
875}
876
Jamie Madill54164b02017-08-28 15:17:37 -0400877void ProgramGL::getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const
878{
879 mFunctions->getUniformfv(mProgramID, uniLoc(location), params);
880}
881
882void ProgramGL::getUniformiv(const gl::Context *context, GLint location, GLint *params) const
883{
884 mFunctions->getUniformiv(mProgramID, uniLoc(location), params);
885}
886
887void ProgramGL::getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const
888{
889 mFunctions->getUniformuiv(mProgramID, uniLoc(location), params);
890}
891
Jamie Madillfb997ec2017-09-20 15:44:27 -0400892void ProgramGL::markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
893 std::vector<gl::SamplerBinding> *samplerBindings)
Jamie Madill54164b02017-08-28 15:17:37 -0400894{
895 GLint maxLocation = static_cast<GLint>(uniformLocations->size());
896 for (GLint location = 0; location < maxLocation; ++location)
897 {
898 if (uniLoc(location) == -1)
899 {
Jamie Madillfb997ec2017-09-20 15:44:27 -0400900 auto &locationRef = (*uniformLocations)[location];
901 if (mState.isSamplerUniformIndex(locationRef.index))
902 {
903 GLuint samplerIndex = mState.getSamplerIndexFromUniformIndex(locationRef.index);
904 (*samplerBindings)[samplerIndex].unreferenced = true;
905 }
906 locationRef.markUnused();
Jamie Madill54164b02017-08-28 15:17:37 -0400907 }
908 }
909}
910
Jamie Madill6db1c2e2017-11-08 09:17:40 -0500911void ProgramGL::linkResources(const gl::ProgramLinkedResources &resources)
912{
913 // Gather interface block info.
914 auto getUniformBlockSize = [this](const std::string &name, const std::string &mappedName,
915 size_t *sizeOut) {
916 return this->getUniformBlockSize(name, mappedName, sizeOut);
917 };
918
919 auto getUniformBlockMemberInfo = [this](const std::string &name, const std::string &mappedName,
920 sh::BlockMemberInfo *infoOut) {
921 return this->getUniformBlockMemberInfo(name, mappedName, infoOut);
922 };
923
924 resources.uniformBlockLinker.linkBlocks(getUniformBlockSize, getUniformBlockMemberInfo);
925
Jiajia Qin3a9090f2017-09-27 14:37:04 +0800926 auto getShaderStorageBlockSize = [this](const std::string &name, const std::string &mappedName,
927 size_t *sizeOut) {
928 return this->getShaderStorageBlockSize(name, mappedName, sizeOut);
Jamie Madill6db1c2e2017-11-08 09:17:40 -0500929 };
930
Jiajia Qin3a9090f2017-09-27 14:37:04 +0800931 auto getShaderStorageBlockMemberInfo = [this](const std::string &name,
932 const std::string &mappedName,
933 sh::BlockMemberInfo *infoOut) {
934 return this->getShaderStorageBlockMemberInfo(name, mappedName, infoOut);
935 };
Jamie Madill6db1c2e2017-11-08 09:17:40 -0500936 resources.shaderStorageBlockLinker.linkBlocks(getShaderStorageBlockSize,
937 getShaderStorageBlockMemberInfo);
Jiajia Qin94f1e892017-11-20 12:14:32 +0800938
939 // Gather atomic counter buffer info.
940 std::map<int, unsigned int> sizeMap;
941 getAtomicCounterBufferSizeMap(&sizeMap);
942 resources.atomicCounterBufferLinker.link(sizeMap);
Jamie Madill6db1c2e2017-11-08 09:17:40 -0500943}
944
Jamie Madill4a3c2342015-10-08 12:58:45 -0400945} // namespace rx