Hash :
b61e173a
Author :
Date :
2015-06-05T11:49:55
Only sync attributes used by the current program in RendererGL. Improves draw call overhead of RendererGL. DrawCallPerf_gl: Before: 136973 score After: 153317 score Improvement: 11.932% BUG=angleproject:959 Change-Id: Ib75f6fdd756648e4a07f6e970cda03abbdbcf009 Reviewed-on: https://chromium-review.googlesource.com/275409 Reviewed-by: Kenneth Russell <kbr@chromium.org> Tested-by: Geoff Lang <geofflang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ProgramGL.cpp: Implements the class methods for ProgramGL.
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "common/debug.h"
#include "common/utilities.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
namespace rx
{
ProgramGL::ProgramGL(const FunctionsGL *functions, StateManagerGL *stateManager)
: ProgramImpl(),
mFunctions(functions),
mStateManager(stateManager),
mProgramID(0)
{
ASSERT(mFunctions);
ASSERT(mStateManager);
mProgramID = mFunctions->createProgram();
}
ProgramGL::~ProgramGL()
{
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
}
bool ProgramGL::usesPointSize() const
{
UNIMPLEMENTED();
return bool();
}
int ProgramGL::getShaderVersion() const
{
UNIMPLEMENTED();
return int();
}
GLenum ProgramGL::getTransformFeedbackBufferMode() const
{
UNIMPLEMENTED();
return GLenum();
}
GLenum ProgramGL::getBinaryFormat()
{
UNIMPLEMENTED();
return GLenum();
}
LinkResult ProgramGL::load(gl::InfoLog &infoLog, gl::BinaryInputStream *stream)
{
UNIMPLEMENTED();
return LinkResult(false, gl::Error(GL_INVALID_OPERATION));
}
gl::Error ProgramGL::save(gl::BinaryOutputStream *stream)
{
UNIMPLEMENTED();
return gl::Error(GL_INVALID_OPERATION);
}
LinkResult ProgramGL::link(const gl::Data &data, gl::InfoLog &infoLog,
gl::Shader *fragmentShader, gl::Shader *vertexShader,
const std::vector<std::string> &transformFeedbackVaryings,
GLenum transformFeedbackBufferMode,
int *registers, std::vector<gl::LinkedVarying> *linkedVaryings,
std::map<int, gl::VariableLocation> *outputVariables)
{
// Reset the program state, delete the current program if one exists
reset();
ShaderGL *vertexShaderGL = GetImplAs<ShaderGL>(vertexShader);
ShaderGL *fragmentShaderGL = GetImplAs<ShaderGL>(fragmentShader);
// Attach the shaders
mFunctions->attachShader(mProgramID, vertexShaderGL->getShaderID());
mFunctions->attachShader(mProgramID, fragmentShaderGL->getShaderID());
// Link and verify
mFunctions->linkProgram(mProgramID);
// Detach the shaders
mFunctions->detachShader(mProgramID, vertexShaderGL->getShaderID());
mFunctions->detachShader(mProgramID, fragmentShaderGL->getShaderID());
// Verify the link
GLint linkStatus = GL_FALSE;
mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
ASSERT(linkStatus == GL_TRUE);
if (linkStatus == GL_FALSE)
{
// Linking failed, put the error into the info log
GLint infoLogLength = 0;
mFunctions->getProgramiv(mProgramID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<char> buf(infoLogLength);
mFunctions->getProgramInfoLog(mProgramID, infoLogLength, nullptr, &buf[0]);
mFunctions->deleteProgram(mProgramID);
mProgramID = 0;
infoLog << &buf[0];
TRACE("\n%s", &buf[0]);
// TODO, return GL_OUT_OF_MEMORY or just fail the link? This is an unexpected case
return LinkResult(false, gl::Error(GL_NO_ERROR));
}
// Query the uniform information
// TODO: A lot of this logic should be done at the gl::Program level
GLint activeUniformMaxLength = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_UNIFORM_MAX_LENGTH, &activeUniformMaxLength);
std::vector<GLchar> uniformNameBuffer(activeUniformMaxLength);
GLint uniformCount = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_UNIFORMS, &uniformCount);
for (GLint i = 0; i < uniformCount; i++)
{
GLsizei uniformNameLength = 0;
GLint uniformSize = 0;
GLenum uniformType = GL_NONE;
mFunctions->getActiveUniform(mProgramID, i, uniformNameBuffer.size(), &uniformNameLength, &uniformSize, &uniformType, &uniformNameBuffer[0]);
std::string uniformName = gl::ParseUniformName(std::string(&uniformNameBuffer[0], uniformNameLength), nullptr);
for (size_t arrayIndex = 0; arrayIndex < static_cast<size_t>(uniformSize); arrayIndex++)
{
std::string locationName = uniformName;
if (uniformSize > 1)
{
locationName += "[" + Str(arrayIndex) + "]";
}
GLint location = mFunctions->getUniformLocation(mProgramID, locationName.c_str());
if (location >= 0)
{
mUniformIndex[location] = gl::VariableLocation(uniformName, arrayIndex, static_cast<unsigned int>(mUniforms.size()));
// If the uniform is a sampler, track it in the sampler bindings array
if (gl::IsSamplerType(uniformType))
{
SamplerLocation samplerLoc;
samplerLoc.samplerIndex = mSamplerBindings.size();
samplerLoc.arrayIndex = arrayIndex;
mSamplerUniformMap[location] = samplerLoc;
}
}
}
// ANGLE uses 0 to identify an non-array uniform.
unsigned int arraySize = (uniformSize > 1) ? static_cast<unsigned int>(uniformSize) : 0;
// TODO: determine uniform precision
mUniforms.push_back(new gl::LinkedUniform(uniformType, GL_NONE, uniformName, arraySize, -1, sh::BlockMemberInfo::getDefaultBlockInfo()));
// If uniform is a sampler type, insert it into the mSamplerBindings array
if (gl::IsSamplerType(uniformType))
{
SamplerBindingGL samplerBinding;
samplerBinding.textureType = gl::SamplerTypeToTextureType(uniformType);
samplerBinding.boundTextureUnits.resize(uniformSize, 0);
mSamplerBindings.push_back(samplerBinding);
}
}
// Query the attribute information
GLint activeAttributeMaxLength = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &activeAttributeMaxLength);
std::vector<GLchar> attributeNameBuffer(activeAttributeMaxLength);
GLint attributeCount = 0;
mFunctions->getProgramiv(mProgramID, GL_ACTIVE_ATTRIBUTES, &attributeCount);
for (GLint i = 0; i < attributeCount; i++)
{
GLsizei attributeNameLength = 0;
GLint attributeSize = 0;
GLenum attributeType = GL_NONE;
mFunctions->getActiveAttrib(mProgramID, i, attributeNameBuffer.size(), &attributeNameLength, &attributeSize, &attributeType, &attributeNameBuffer[0]);
std::string attributeName(&attributeNameBuffer[0], attributeNameLength);
GLint location = mFunctions->getAttribLocation(mProgramID, attributeName.c_str());
// TODO: determine attribute precision
setShaderAttribute(static_cast<size_t>(i), attributeType, GL_NONE, attributeName, attributeSize, location);
mActiveAttributeLocations.push_back(location);
}
return LinkResult(true, gl::Error(GL_NO_ERROR));
}
void ProgramGL::bindAttributeLocation(GLuint index, const std::string &name)
{
mFunctions->bindAttribLocation(mProgramID, index, name.c_str());
}
void ProgramGL::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform1fv(location, count, v);
}
void ProgramGL::setUniform2fv(GLint location, GLsizei count, const GLfloat *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform2fv(location, count, v);
}
void ProgramGL::setUniform3fv(GLint location, GLsizei count, const GLfloat *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform3fv(location, count, v);
}
void ProgramGL::setUniform4fv(GLint location, GLsizei count, const GLfloat *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform4fv(location, count, v);
}
void ProgramGL::setUniform1iv(GLint location, GLsizei count, const GLint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform1iv(location, count, v);
auto iter = mSamplerUniformMap.find(location);
if (iter != mSamplerUniformMap.end())
{
const SamplerLocation &samplerLoc = iter->second;
std::vector<GLuint> &boundTextureUnits = mSamplerBindings[samplerLoc.samplerIndex].boundTextureUnits;
size_t copyCount = std::max<size_t>(count, boundTextureUnits.size() - samplerLoc.arrayIndex);
std::copy(v, v + copyCount, boundTextureUnits.begin() + samplerLoc.arrayIndex);
}
}
void ProgramGL::setUniform2iv(GLint location, GLsizei count, const GLint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform2iv(location, count, v);
}
void ProgramGL::setUniform3iv(GLint location, GLsizei count, const GLint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform3iv(location, count, v);
}
void ProgramGL::setUniform4iv(GLint location, GLsizei count, const GLint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform4iv(location, count, v);
}
void ProgramGL::setUniform1uiv(GLint location, GLsizei count, const GLuint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform1uiv(location, count, v);
}
void ProgramGL::setUniform2uiv(GLint location, GLsizei count, const GLuint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform2uiv(location, count, v);
}
void ProgramGL::setUniform3uiv(GLint location, GLsizei count, const GLuint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform3uiv(location, count, v);
}
void ProgramGL::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniform4uiv(location, count, v);
}
void ProgramGL::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix3fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix2x3fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix3x2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix2x4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix4x2fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix3x4fv(location, count, transpose, value);
}
void ProgramGL::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *value)
{
mStateManager->useProgram(mProgramID);
mFunctions->uniformMatrix4x3fv(location, count, transpose, value);
}
void ProgramGL::getUniformfv(GLint location, GLfloat *params)
{
mFunctions->getUniformfv(mProgramID, location, params);
}
void ProgramGL::getUniformiv(GLint location, GLint *params)
{
mFunctions->getUniformiv(mProgramID, location, params);
}
void ProgramGL::getUniformuiv(GLint location, GLuint *params)
{
mFunctions->getUniformuiv(mProgramID, location, params);
}
GLint ProgramGL::getSamplerMapping(gl::SamplerType type, unsigned int samplerIndex, const gl::Caps &caps) const
{
UNIMPLEMENTED();
return GLint();
}
GLenum ProgramGL::getSamplerTextureType(gl::SamplerType type, unsigned int samplerIndex) const
{
UNIMPLEMENTED();
return GLenum();
}
GLint ProgramGL::getUsedSamplerRange(gl::SamplerType type) const
{
UNIMPLEMENTED();
return GLint();
}
void ProgramGL::updateSamplerMapping()
{
UNIMPLEMENTED();
}
bool ProgramGL::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
{
//UNIMPLEMENTED();
return true;
}
LinkResult ProgramGL::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shader *fragmentShader, gl::Shader *vertexShader,
int registers)
{
//UNIMPLEMENTED();
return LinkResult(true, gl::Error(GL_NO_ERROR));
}
bool ProgramGL::linkUniforms(gl::InfoLog &infoLog, const gl::Shader &vertexShader, const gl::Shader &fragmentShader,
const gl::Caps &caps)
{
//UNIMPLEMENTED();
return true;
}
bool ProgramGL::defineUniformBlock(gl::InfoLog &infoLog, const gl::Shader &shader, const sh::InterfaceBlock &interfaceBlock,
const gl::Caps &caps)
{
UNIMPLEMENTED();
return bool();
}
gl::Error ProgramGL::applyUniforms()
{
//UNIMPLEMENTED();
// TODO(geofflang)
return gl::Error(GL_NO_ERROR);
}
gl::Error ProgramGL::applyUniformBuffers(const gl::Data &data, GLuint uniformBlockBindings[])
{
UNIMPLEMENTED();
return gl::Error(GL_INVALID_OPERATION);
}
bool ProgramGL::assignUniformBlockRegister(gl::InfoLog &infoLog, gl::UniformBlock *uniformBlock, GLenum shader,
unsigned int registerIndex, const gl::Caps &caps)
{
UNIMPLEMENTED();
return bool();
}
void ProgramGL::reset()
{
ProgramImpl::reset();
mSamplerUniformMap.clear();
mSamplerBindings.clear();
mActiveAttributeLocations.clear();
}
GLuint ProgramGL::getProgramID() const
{
return mProgramID;
}
const std::vector<SamplerBindingGL> &ProgramGL::getAppliedSamplerUniforms() const
{
return mSamplerBindings;
}
const std::vector<GLuint> &ProgramGL::getActiveAttributeLocations() const
{
return mActiveAttributeLocations;
}
}