diff options
Diffstat (limited to 'gfx/angle/src/libANGLE/Program.cpp')
-rwxr-xr-x | gfx/angle/src/libANGLE/Program.cpp | 236 |
1 files changed, 136 insertions, 100 deletions
diff --git a/gfx/angle/src/libANGLE/Program.cpp b/gfx/angle/src/libANGLE/Program.cpp index 06d8d15343..7f4226da17 100755 --- a/gfx/angle/src/libANGLE/Program.cpp +++ b/gfx/angle/src/libANGLE/Program.cpp @@ -377,27 +377,39 @@ const std::string &Program::getLabel() const return mState.mLabel; } -void Program::attachShader(Shader *shader) +bool Program::attachShader(Shader *shader) { switch (shader->getType()) { case GL_VERTEX_SHADER: { - ASSERT(!mState.mAttachedVertexShader); + if (mState.mAttachedVertexShader) + { + return false; + } + mState.mAttachedVertexShader = shader; mState.mAttachedVertexShader->addRef(); break; } case GL_FRAGMENT_SHADER: { - ASSERT(!mState.mAttachedFragmentShader); + if (mState.mAttachedFragmentShader) + { + return false; + } + mState.mAttachedFragmentShader = shader; mState.mAttachedFragmentShader->addRef(); break; } case GL_COMPUTE_SHADER: { - ASSERT(!mState.mAttachedComputeShader); + if (mState.mAttachedComputeShader) + { + return false; + } + mState.mAttachedComputeShader = shader; mState.mAttachedComputeShader->addRef(); break; @@ -405,6 +417,8 @@ void Program::attachShader(Shader *shader) default: UNREACHABLE(); } + + return true; } bool Program::detachShader(Shader *shader) @@ -509,7 +523,7 @@ BindingInfo Program::getFragmentInputBindingInfo(GLint index) const if (arrayIndex == GL_INVALID_INDEX) arrayIndex = 0; - ret.name = in.mappedName + "[" + ToString(arrayIndex) + "]"; + ret.name = in.mappedName + "[" + std::to_string(arrayIndex) + "]"; } else { @@ -597,10 +611,11 @@ Error Program::link(const ContextState &data) return NoError(); } - ANGLE_TRY_RESULT(mProgram->link(data, mInfoLog), mLinked); - if (!mLinked) + rx::LinkResult result = mProgram->link(data, mInfoLog); + + if (result.error.isError() || !result.linkSuccess) { - return NoError(); + return result.error; } } else @@ -653,10 +668,10 @@ Error Program::link(const ContextState &data) linkOutputVariables(); - ANGLE_TRY_RESULT(mProgram->link(data, mInfoLog), mLinked); - if (!mLinked) + rx::LinkResult result = mProgram->link(data, mInfoLog); + if (result.error.isError() || !result.linkSuccess) { - return NoError(); + return result.error; } gatherTransformFeedbackVaryings(mergedVaryings); @@ -664,6 +679,7 @@ Error Program::link(const ContextState &data) gatherInterfaceBlockInfo(); + mLinked = true; return NoError(); } @@ -843,9 +859,14 @@ Error Program::loadBinary(GLenum binaryFormat, const void *binary, GLsizei lengt stream.readInt(&mSamplerUniformRange.start); stream.readInt(&mSamplerUniformRange.end); - ANGLE_TRY_RESULT(mProgram->load(mInfoLog, &stream), mLinked); + rx::LinkResult result = mProgram->load(mInfoLog, &stream); + if (result.error.isError() || !result.linkSuccess) + { + return result.error; + } - return NoError(); + mLinked = true; + return Error(GL_NO_ERROR); #endif // #if ANGLE_PROGRAM_BINARY_LOAD == ANGLE_ENABLED } @@ -1336,128 +1357,128 @@ GLuint Program::getUniformIndex(const std::string &name) const void Program::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) { - GLsizei clampedCount = setUniformInternal(location, count, 1, v); - mProgram->setUniform1fv(location, clampedCount, v); + setUniformInternal(location, count * 1, v); + mProgram->setUniform1fv(location, count, v); } void Program::setUniform2fv(GLint location, GLsizei count, const GLfloat *v) { - GLsizei clampedCount = setUniformInternal(location, count, 2, v); - mProgram->setUniform2fv(location, clampedCount, v); + setUniformInternal(location, count * 2, v); + mProgram->setUniform2fv(location, count, v); } void Program::setUniform3fv(GLint location, GLsizei count, const GLfloat *v) { - GLsizei clampedCount = setUniformInternal(location, count, 3, v); - mProgram->setUniform3fv(location, clampedCount, v); + setUniformInternal(location, count * 3, v); + mProgram->setUniform3fv(location, count, v); } void Program::setUniform4fv(GLint location, GLsizei count, const GLfloat *v) { - GLsizei clampedCount = setUniformInternal(location, count, 4, v); - mProgram->setUniform4fv(location, clampedCount, v); + setUniformInternal(location, count * 4, v); + mProgram->setUniform4fv(location, count, v); } void Program::setUniform1iv(GLint location, GLsizei count, const GLint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 1, v); - mProgram->setUniform1iv(location, clampedCount, v); + setUniformInternal(location, count * 1, v); + mProgram->setUniform1iv(location, count, v); } void Program::setUniform2iv(GLint location, GLsizei count, const GLint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 2, v); - mProgram->setUniform2iv(location, clampedCount, v); + setUniformInternal(location, count * 2, v); + mProgram->setUniform2iv(location, count, v); } void Program::setUniform3iv(GLint location, GLsizei count, const GLint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 3, v); - mProgram->setUniform3iv(location, clampedCount, v); + setUniformInternal(location, count * 3, v); + mProgram->setUniform3iv(location, count, v); } void Program::setUniform4iv(GLint location, GLsizei count, const GLint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 4, v); - mProgram->setUniform4iv(location, clampedCount, v); + setUniformInternal(location, count * 4, v); + mProgram->setUniform4iv(location, count, v); } void Program::setUniform1uiv(GLint location, GLsizei count, const GLuint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 1, v); - mProgram->setUniform1uiv(location, clampedCount, v); + setUniformInternal(location, count * 1, v); + mProgram->setUniform1uiv(location, count, v); } void Program::setUniform2uiv(GLint location, GLsizei count, const GLuint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 2, v); - mProgram->setUniform2uiv(location, clampedCount, v); + setUniformInternal(location, count * 2, v); + mProgram->setUniform2uiv(location, count, v); } void Program::setUniform3uiv(GLint location, GLsizei count, const GLuint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 3, v); - mProgram->setUniform3uiv(location, clampedCount, v); + setUniformInternal(location, count * 3, v); + mProgram->setUniform3uiv(location, count, v); } void Program::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) { - GLsizei clampedCount = setUniformInternal(location, count, 4, v); - mProgram->setUniform4uiv(location, clampedCount, v); + setUniformInternal(location, count * 4, v); + mProgram->setUniform4uiv(location, count, v); } void Program::setUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<2, 2>(location, count, transpose, v); - mProgram->setUniformMatrix2fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<2, 2>(location, count, transpose, v); + mProgram->setUniformMatrix2fv(location, count, transpose, v); } void Program::setUniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<3, 3>(location, count, transpose, v); - mProgram->setUniformMatrix3fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<3, 3>(location, count, transpose, v); + mProgram->setUniformMatrix3fv(location, count, transpose, v); } void Program::setUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<4, 4>(location, count, transpose, v); - mProgram->setUniformMatrix4fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<4, 4>(location, count, transpose, v); + mProgram->setUniformMatrix4fv(location, count, transpose, v); } void Program::setUniformMatrix2x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<2, 3>(location, count, transpose, v); - mProgram->setUniformMatrix2x3fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<2, 3>(location, count, transpose, v); + mProgram->setUniformMatrix2x3fv(location, count, transpose, v); } void Program::setUniformMatrix2x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<2, 4>(location, count, transpose, v); - mProgram->setUniformMatrix2x4fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<2, 4>(location, count, transpose, v); + mProgram->setUniformMatrix2x4fv(location, count, transpose, v); } void Program::setUniformMatrix3x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<3, 2>(location, count, transpose, v); - mProgram->setUniformMatrix3x2fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<3, 2>(location, count, transpose, v); + mProgram->setUniformMatrix3x2fv(location, count, transpose, v); } void Program::setUniformMatrix3x4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<3, 4>(location, count, transpose, v); - mProgram->setUniformMatrix3x4fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<3, 4>(location, count, transpose, v); + mProgram->setUniformMatrix3x4fv(location, count, transpose, v); } void Program::setUniformMatrix4x2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<4, 2>(location, count, transpose, v); - mProgram->setUniformMatrix4x2fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<4, 2>(location, count, transpose, v); + mProgram->setUniformMatrix4x2fv(location, count, transpose, v); } void Program::setUniformMatrix4x3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat *v) { - GLsizei clampedCount = setMatrixUniformInternal<4, 3>(location, count, transpose, v); - mProgram->setUniformMatrix4x3fv(location, clampedCount, transpose, v); + setMatrixUniformInternal<4, 3>(location, count, transpose, v); + mProgram->setUniformMatrix4x3fv(location, count, transpose, v); } void Program::getUniformfv(GLint location, GLfloat *v) const @@ -1612,6 +1633,44 @@ void Program::getActiveUniformBlockName(GLuint uniformBlockIndex, GLsizei bufSiz } } +void Program::getActiveUniformBlockiv(GLuint uniformBlockIndex, GLenum pname, GLint *params) const +{ + ASSERT( + uniformBlockIndex < + mState.mUniformBlocks.size()); // index must be smaller than getActiveUniformBlockCount() + + const UniformBlock &uniformBlock = mState.mUniformBlocks[uniformBlockIndex]; + + switch (pname) + { + case GL_UNIFORM_BLOCK_DATA_SIZE: + *params = static_cast<GLint>(uniformBlock.dataSize); + break; + case GL_UNIFORM_BLOCK_NAME_LENGTH: + *params = + static_cast<GLint>(uniformBlock.name.size() + 1 + (uniformBlock.isArray ? 3 : 0)); + break; + case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: + *params = static_cast<GLint>(uniformBlock.memberUniformIndexes.size()); + break; + case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: + { + for (unsigned int blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberUniformIndexes.size(); blockMemberIndex++) + { + params[blockMemberIndex] = static_cast<GLint>(uniformBlock.memberUniformIndexes[blockMemberIndex]); + } + } + break; + case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: + *params = static_cast<GLint>(uniformBlock.vertexStaticUse); + break; + case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: + *params = static_cast<GLint>(uniformBlock.fragmentStaticUse); + break; + default: UNREACHABLE(); + } +} + GLint Program::getActiveUniformBlockMaxLength() const { int maxLength = 0; @@ -2401,6 +2460,7 @@ bool Program::linkValidateTransformFeedback(InfoLog &infoLog, // All transform feedback varyings are expected to exist since packVaryings checks for them. ASSERT(found); + UNUSED_ASSERTION_VARIABLE(found); } if (mState.mTransformFeedbackBufferMode == GL_INTERLEAVED_ATTRIBS && @@ -2751,13 +2811,7 @@ void Program::defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenu size_t blockSize = 0; // Don't define this block at all if it's not active in the implementation. - std::stringstream blockNameStr; - blockNameStr << interfaceBlock.name; - if (interfaceBlock.arraySize > 0) - { - blockNameStr << "[0]"; - } - if (!mProgram->getUniformBlockSize(blockNameStr.str(), &blockSize)) + if (!mProgram->getUniformBlockSize(interfaceBlock.name, &blockSize)) { return; } @@ -2803,10 +2857,15 @@ void Program::defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenu UNREACHABLE(); } - // Since all block elements in an array share the same active uniforms, they will all be - // active once any uniform member is used. So, since interfaceBlock.name[0] was active, - // here we will add every block element in the array. - block.dataSize = static_cast<unsigned int>(blockSize); + // TODO(jmadill): Determine if we can ever have an inactive array element block. + size_t blockElementSize = 0; + if (!mProgram->getUniformBlockSize(block.nameWithArrayIndex(), &blockElementSize)) + { + continue; + } + + ASSERT(blockElementSize == blockSize); + block.dataSize = static_cast<unsigned int>(blockElementSize); mState.mUniformBlocks.push_back(block); } } @@ -2842,32 +2901,18 @@ void Program::defineUniformBlock(const sh::InterfaceBlock &interfaceBlock, GLenu } template <typename T> -GLsizei Program::setUniformInternal(GLint location, GLsizei countIn, int vectorSize, const T *v) +void Program::setUniformInternal(GLint location, GLsizei count, const T *v) { const VariableLocation &locationInfo = mState.mUniformLocations[location]; LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index]; uint8_t *destPointer = linkedUniform->getDataPtrToElement(locationInfo.element); - // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array - // element index used, as reported by GetActiveUniform, will be ignored by the GL." - unsigned int remainingElements = linkedUniform->elementCount() - locationInfo.element; - GLsizei maxElementCount = - static_cast<GLsizei>(remainingElements * linkedUniform->getElementComponents()); - - GLsizei count = countIn; - GLsizei clampedCount = count * vectorSize; - if (clampedCount > maxElementCount) - { - clampedCount = maxElementCount; - count = maxElementCount / vectorSize; - } - if (VariableComponentType(linkedUniform->type) == GL_BOOL) { // Do a cast conversion for boolean types. From the spec: // "The uniform is set to FALSE if the input value is 0 or 0.0f, and set to TRUE otherwise." GLint *destAsInt = reinterpret_cast<GLint *>(destPointer); - for (GLsizei component = 0; component < clampedCount; ++component) + for (GLsizei component = 0; component < count; ++component) { destAsInt[component] = (v[component] != static_cast<T>(0) ? GL_TRUE : GL_FALSE); } @@ -2875,39 +2920,32 @@ GLsizei Program::setUniformInternal(GLint location, GLsizei countIn, int vectorS else { // Invalide the validation cache if we modify the sampler data. - if (linkedUniform->isSampler() && memcmp(destPointer, v, sizeof(T) * clampedCount) != 0) + if (linkedUniform->isSampler() && memcmp(destPointer, v, sizeof(T) * count) != 0) { mCachedValidateSamplersResult.reset(); } - memcpy(destPointer, v, sizeof(T) * clampedCount); + memcpy(destPointer, v, sizeof(T) * count); } - - return count; } template <size_t cols, size_t rows, typename T> -GLsizei Program::setMatrixUniformInternal(GLint location, - GLsizei count, - GLboolean transpose, - const T *v) +void Program::setMatrixUniformInternal(GLint location, + GLsizei count, + GLboolean transpose, + const T *v) { if (!transpose) { - return setUniformInternal(location, count, cols * rows, v); + setUniformInternal(location, count * cols * rows, v); + return; } // Perform a transposing copy. const VariableLocation &locationInfo = mState.mUniformLocations[location]; LinkedUniform *linkedUniform = &mState.mUniforms[locationInfo.index]; T *destPtr = reinterpret_cast<T *>(linkedUniform->getDataPtrToElement(locationInfo.element)); - - // OpenGL ES 3.0.4 spec pg 67: "Values for any array element that exceeds the highest array - // element index used, as reported by GetActiveUniform, will be ignored by the GL." - unsigned int remainingElements = linkedUniform->elementCount() - locationInfo.element; - GLsizei clampedCount = std::min(count, static_cast<GLsizei>(remainingElements)); - - for (GLsizei element = 0; element < clampedCount; ++element) + for (GLsizei element = 0; element < count; ++element) { size_t elementOffset = element * rows * cols; @@ -2919,8 +2957,6 @@ GLsizei Program::setMatrixUniformInternal(GLint location, } } } - - return clampedCount; } template <typename DestT> |