Bug 1329988 - Always use ANGLE's less-slow transpose:true path. - r=kvark

MozReview-Commit-ID: ugVzpBlwCP
This commit is contained in:
Jeff Gilbert 2017-02-14 15:21:37 -08:00
Родитель 1c6c3bfb07
Коммит 7bd233bc87
1 изменённых файлов: 51 добавлений и 4 удалений

Просмотреть файл

@ -2035,9 +2035,21 @@ WebGLContext::UniformNfv(const char* funcName, uint8_t N, WebGLUniformLocation*
(gl->*func)(loc->mLoc, numElementsToUpload, elemBytes); (gl->*func)(loc->mLoc, numElementsToUpload, elemBytes);
} }
static inline void
MatrixAxBToRowMajor(const uint8_t width, const uint8_t height,
const float* __restrict srcColMajor,
float* __restrict dstRowMajor)
{
for (uint8_t x = 0; x < width; ++x) {
for (uint8_t y = 0; y < height; ++y) {
dstRowMajor[y * width + x] = srcColMajor[x * height + y];
}
}
}
void void
WebGLContext::UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B, WebGLContext::UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
WebGLUniformLocation* loc, bool transpose, WebGLUniformLocation* loc, const bool transpose,
const Float32Arr& arr, GLuint elemOffset, const Float32Arr& arr, GLuint elemOffset,
GLuint elemCountOverride) GLuint elemCountOverride)
{ {
@ -2049,14 +2061,49 @@ WebGLContext::UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
} }
const auto elemBytes = arr.elemBytes + elemOffset; const auto elemBytes = arr.elemBytes + elemOffset;
uint32_t numElementsToUpload; uint32_t numMatsToUpload;
if (!ValidateUniformMatrixArraySetter(loc, A, B, LOCAL_GL_FLOAT, elemCount, if (!ValidateUniformMatrixArraySetter(loc, A, B, LOCAL_GL_FLOAT, elemCount,
transpose, funcName, &numElementsToUpload)) transpose, funcName, &numMatsToUpload))
{ {
return; return;
} }
MOZ_ASSERT(!loc->mInfo->mSamplerTexList, "Should not be a sampler."); MOZ_ASSERT(!loc->mInfo->mSamplerTexList, "Should not be a sampler.");
////
bool uploadTranspose = transpose;
const float* uploadBytes = elemBytes;
UniqueBuffer temp;
if (!transpose && gl->WorkAroundDriverBugs() && gl->IsANGLE() &&
gl->IsAtLeast(gl::ContextProfile::OpenGLES, 300))
{
// ANGLE is really slow at non-GL-transposed matrices.
const size_t kElemsPerMat = A * B;
temp = malloc(numMatsToUpload * kElemsPerMat * sizeof(float));
if (!temp) {
ErrorOutOfMemory("%s: Failed to alloc temporary buffer for transposition.",
funcName);
return;
}
auto srcItr = (const float*)elemBytes;
auto dstItr = (float*)temp.get();
const auto srcEnd = srcItr + numMatsToUpload * kElemsPerMat;
while (srcItr != srcEnd) {
MatrixAxBToRowMajor(A, B, srcItr, dstItr);
srcItr += kElemsPerMat;
dstItr += kElemsPerMat;
}
uploadBytes = (const float*)temp.get();
uploadTranspose = true;
}
////
static const decltype(&gl::GLContext::fUniformMatrix2fv) kFuncList[] = { static const decltype(&gl::GLContext::fUniformMatrix2fv) kFuncList[] = {
&gl::GLContext::fUniformMatrix2fv, &gl::GLContext::fUniformMatrix2fv,
&gl::GLContext::fUniformMatrix2x3fv, &gl::GLContext::fUniformMatrix2x3fv,
@ -2073,7 +2120,7 @@ WebGLContext::UniformMatrixAxBfv(const char* funcName, uint8_t A, uint8_t B,
const auto func = kFuncList[3*(A-2) + (B-2)]; const auto func = kFuncList[3*(A-2) + (B-2)];
MakeContextCurrent(); MakeContextCurrent();
(gl->*func)(loc->mLoc, numElementsToUpload, transpose, elemBytes); (gl->*func)(loc->mLoc, numMatsToUpload, uploadTranspose, uploadBytes);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////