Bug 1286768 - Fix num used attrib locations for matrix types. - r=mtseng
MozReview-Commit-ID: 71v2R1cj0aC
--- a/dom/canvas/WebGLActiveInfo.cpp
+++ b/dom/canvas/WebGLActiveInfo.cpp
@@ -4,17 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "WebGLActiveInfo.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
namespace mozilla {
-uint8_t
+static uint8_t
ElemSizeFromType(GLenum elemType)
{
switch (elemType) {
case LOCAL_GL_BOOL:
case LOCAL_GL_FLOAT:
case LOCAL_GL_INT:
case LOCAL_GL_UNSIGNED_INT:
case LOCAL_GL_SAMPLER_2D:
--- a/dom/canvas/WebGLActiveInfo.h
+++ b/dom/canvas/WebGLActiveInfo.h
@@ -86,14 +86,13 @@ private:
{ }
// Private destructor, to discourage deletion outside of Release():
~WebGLActiveInfo() { }
};
//////////
-uint8_t ElemSizeFromType(GLenum elemType);
bool IsElemTypeSampler(GLenum elemType);
} // namespace mozilla
#endif // WEBGL_ACTIVE_INFO_H_
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -1041,16 +1041,42 @@ WebGLProgram::LinkProgram()
if (!mLinkLog.IsEmpty()) {
mContext->GenerateWarning("linkProgram: Failed to link, leaving the following"
" log:\n%s\n",
mLinkLog.BeginReading());
}
}
}
+static uint8_t
+NumUsedLocationsByElemType(GLenum elemType)
+{
+ // GLES 3.0.4 p55
+
+ switch (elemType) {
+ case LOCAL_GL_FLOAT_MAT2:
+ case LOCAL_GL_FLOAT_MAT2x3:
+ case LOCAL_GL_FLOAT_MAT2x4:
+ return 2;
+
+ case LOCAL_GL_FLOAT_MAT3x2:
+ case LOCAL_GL_FLOAT_MAT3:
+ case LOCAL_GL_FLOAT_MAT3x4:
+ return 3;
+
+ case LOCAL_GL_FLOAT_MAT4x2:
+ case LOCAL_GL_FLOAT_MAT4x3:
+ case LOCAL_GL_FLOAT_MAT4:
+ return 4;
+
+ default:
+ return 1;
+ }
+}
+
bool
WebGLProgram::ValidateAfterTentativeLink(nsCString* const out_linkLog) const
{
const auto& linkInfo = mMostRecentLinkInfo;
// Check if the attrib name conflicting to uniform name
for (const auto& attrib : linkInfo->attribs) {
const auto& attribName = attrib.mActiveInfo->mBaseUserName;
@@ -1063,19 +1089,19 @@ WebGLProgram::ValidateAfterTentativeLink
attribName.BeginReading());
return false;
}
}
}
std::map<uint32_t, const webgl::AttribInfo*> attribsByLoc;
for (const auto& attrib : linkInfo->attribs) {
- const uint32_t elemSize = ElemSizeFromType(attrib.mActiveInfo->mElemType);
- const uint32_t numUsedLocation = (elemSize + 3) / 4;
- for (uint32_t i = 0; i < numUsedLocation; i++) {
+ const auto& elemType = attrib.mActiveInfo->mElemType;
+ const auto numUsedLocs = NumUsedLocationsByElemType(elemType);
+ for (uint32_t i = 0; i < numUsedLocs; i++) {
const uint32_t usedLoc = attrib.mLoc + i;
const auto res = attribsByLoc.insert({usedLoc, &attrib});
const bool& didInsert = res.second;
if (!didInsert) {
const auto& aliasingName = attrib.mActiveInfo->mBaseUserName;
const auto& itrExisting = res.first;
const auto& existingInfo = itrExisting->second;