Commit 513558d3 by Jamie Madill Committed by Commit Bot

Pass depth to computeBlockSize.

This was very wrong for 3D textures. BUG=angleproject:1384 Change-Id: I7f042449e30e1e909778c0524d1ce99d20ddfd65 Reviewed-on: https://chromium-review.googlesource.com/348063Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent e2e406c3
......@@ -696,7 +696,7 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
}
else
{
ANGLE_TRY_RESULT(computeBlockSize(formatType, width, 1), rowBytes);
ANGLE_TRY_RESULT(computeBlockSize(formatType, gl::Extents(width, 1, 1)), rowBytes);
}
auto checkedResult = rx::CheckedRoundUp(rowBytes, static_cast<GLuint>(alignment));
ANGLE_TRY_CHECKED_MATH(checkedResult);
......@@ -729,17 +729,17 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
}
gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType,
GLsizei width,
GLsizei height) const
const gl::Extents &size) const
{
CheckedNumeric<GLuint> checkedWidth(width);
CheckedNumeric<GLuint> checkedHeight(height);
CheckedNumeric<GLuint> checkedWidth(size.width);
CheckedNumeric<GLuint> checkedHeight(size.height);
CheckedNumeric<GLuint> checkedDepth(size.depth);
if (compressed)
{
auto numBlocksWide = (checkedWidth + compressedBlockWidth - 1u) / compressedBlockWidth;
auto numBlocksHigh = (checkedHeight + compressedBlockHeight - 1u) / compressedBlockHeight;
auto bytes = numBlocksWide * numBlocksHigh * pixelBytes;
auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
ANGLE_TRY_CHECKED_MATH(bytes);
return bytes.ValueOrDie();
}
......@@ -747,7 +747,7 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType,
const Type &typeInfo = GetTypeInfo(formatType);
GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
auto result = checkedWidth * checkedHeight * components * typeInfo.bytes;
auto result = checkedWidth * checkedHeight * checkedDepth * components * typeInfo.bytes;
ANGLE_TRY_CHECKED_MATH(result);
return result.ValueOrDie();
}
......
......@@ -44,9 +44,7 @@ struct InternalFormat
GLint alignment,
GLint rowLength,
GLint imageHeight) const;
gl::ErrorOrResult<GLuint> computeBlockSize(GLenum formatType,
GLsizei width,
GLsizei height) const;
gl::ErrorOrResult<GLuint> computeBlockSize(GLenum formatType, const gl::Extents &size) const;
GLuint computeSkipPixels(GLint rowPitch,
GLint depthPitch,
GLint skipImages,
......
......@@ -389,9 +389,9 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
{
if (internalFormatInfo.compressed)
{
size_t dataSize = 0;
ANGLE_TRY_RESULT(internalFormatInfo.computeBlockSize(
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height),
GLuint dataSize = 0;
ANGLE_TRY_RESULT(
internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize),
dataSize);
mFunctions->compressedTexImage2D(target, static_cast<GLint>(level),
texStorageFormat.internalFormat,
......@@ -412,10 +412,9 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
{
if (internalFormatInfo.compressed)
{
size_t dataSize = 0;
GLuint dataSize = 0;
ANGLE_TRY_RESULT(
internalFormatInfo.computeBlockSize(
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height),
internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize),
dataSize);
mFunctions->compressedTexImage2D(
face, static_cast<GLint>(level), texStorageFormat.internalFormat,
......@@ -464,14 +463,13 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
if (internalFormatInfo.compressed)
{
GLuint blockSize = 0;
ANGLE_TRY_RESULT(internalFormatInfo.computeBlockSize(
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height),
blockSize);
GLsizei dataSize = static_cast<GLsizei>(blockSize) * levelSize.depth;
GLuint dataSize = 0;
ANGLE_TRY_RESULT(
internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize), dataSize);
mFunctions->compressedTexImage3D(target, i, texStorageFormat.internalFormat,
levelSize.width, levelSize.height,
levelSize.depth, 0, dataSize, nullptr);
levelSize.depth, 0,
static_cast<GLsizei>(dataSize), nullptr);
}
else
{
......
......@@ -1830,7 +1830,8 @@ bool ValidateCompressedTexImage2D(Context *context,
}
const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat);
auto blockSizeOrErr = formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height);
auto blockSizeOrErr =
formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1));
if (blockSizeOrErr.isError())
{
context->handleError(blockSizeOrErr.getError());
......@@ -1877,7 +1878,8 @@ bool ValidateCompressedTexSubImage2D(Context *context,
}
const InternalFormat &formatInfo = GetInternalFormatInfo(format);
auto blockSizeOrErr = formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height);
auto blockSizeOrErr =
formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, 1));
if (blockSizeOrErr.isError())
{
context->handleError(blockSizeOrErr.getError());
......
......@@ -490,7 +490,7 @@ bool ValidateES3TexImageParametersBase(Context *context,
}
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat);
auto copyBytesOrErr = formatInfo.computeBlockSize(type, width, height);
auto copyBytesOrErr = formatInfo.computeBlockSize(type, gl::Extents(width, height, depth));
if (copyBytesOrErr.isError())
{
context->handleError(copyBytesOrErr.getError());
......@@ -1557,10 +1557,11 @@ bool ValidateCompressedTexImage3D(Context *context,
}
const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat);
auto blockSizeOrErr = formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height);
auto blockSizeOrErr =
formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth));
if (blockSizeOrErr.isError())
{
context->handleError(blockSizeOrErr.getError());
context->handleError(Error(GL_INVALID_VALUE));
return false;
}
if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult())
......@@ -1905,7 +1906,8 @@ bool ValidateCompressedTexSubImage3D(Context *context,
}
const InternalFormat &formatInfo = GetInternalFormatInfo(format);
auto blockSizeOrErr = formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height);
auto blockSizeOrErr =
formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth));
if (blockSizeOrErr.isError())
{
context->handleError(blockSizeOrErr.getError());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment