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, ...@@ -696,7 +696,7 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
} }
else 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)); auto checkedResult = rx::CheckedRoundUp(rowBytes, static_cast<GLuint>(alignment));
ANGLE_TRY_CHECKED_MATH(checkedResult); ANGLE_TRY_CHECKED_MATH(checkedResult);
...@@ -729,17 +729,17 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType, ...@@ -729,17 +729,17 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
} }
gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType, gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType,
GLsizei width, const gl::Extents &size) const
GLsizei height) const
{ {
CheckedNumeric<GLuint> checkedWidth(width); CheckedNumeric<GLuint> checkedWidth(size.width);
CheckedNumeric<GLuint> checkedHeight(height); CheckedNumeric<GLuint> checkedHeight(size.height);
CheckedNumeric<GLuint> checkedDepth(size.depth);
if (compressed) if (compressed)
{ {
auto numBlocksWide = (checkedWidth + compressedBlockWidth - 1u) / compressedBlockWidth; auto numBlocksWide = (checkedWidth + compressedBlockWidth - 1u) / compressedBlockWidth;
auto numBlocksHigh = (checkedHeight + compressedBlockHeight - 1u) / compressedBlockHeight; auto numBlocksHigh = (checkedHeight + compressedBlockHeight - 1u) / compressedBlockHeight;
auto bytes = numBlocksWide * numBlocksHigh * pixelBytes; auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
ANGLE_TRY_CHECKED_MATH(bytes); ANGLE_TRY_CHECKED_MATH(bytes);
return bytes.ValueOrDie(); return bytes.ValueOrDie();
} }
...@@ -747,7 +747,7 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType, ...@@ -747,7 +747,7 @@ gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType,
const Type &typeInfo = GetTypeInfo(formatType); const Type &typeInfo = GetTypeInfo(formatType);
GLuint components = typeInfo.specialInterpretation ? 1u : componentCount; 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); ANGLE_TRY_CHECKED_MATH(result);
return result.ValueOrDie(); return result.ValueOrDie();
} }
......
...@@ -44,9 +44,7 @@ struct InternalFormat ...@@ -44,9 +44,7 @@ struct InternalFormat
GLint alignment, GLint alignment,
GLint rowLength, GLint rowLength,
GLint imageHeight) const; GLint imageHeight) const;
gl::ErrorOrResult<GLuint> computeBlockSize(GLenum formatType, gl::ErrorOrResult<GLuint> computeBlockSize(GLenum formatType, const gl::Extents &size) const;
GLsizei width,
GLsizei height) const;
GLuint computeSkipPixels(GLint rowPitch, GLuint computeSkipPixels(GLint rowPitch,
GLint depthPitch, GLint depthPitch,
GLint skipImages, GLint skipImages,
......
...@@ -389,10 +389,10 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor ...@@ -389,10 +389,10 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
{ {
if (internalFormatInfo.compressed) if (internalFormatInfo.compressed)
{ {
size_t dataSize = 0; GLuint dataSize = 0;
ANGLE_TRY_RESULT(internalFormatInfo.computeBlockSize( ANGLE_TRY_RESULT(
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height), internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize),
dataSize); dataSize);
mFunctions->compressedTexImage2D(target, static_cast<GLint>(level), mFunctions->compressedTexImage2D(target, static_cast<GLint>(level),
texStorageFormat.internalFormat, texStorageFormat.internalFormat,
levelSize.width, levelSize.height, 0, levelSize.width, levelSize.height, 0,
...@@ -412,10 +412,9 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor ...@@ -412,10 +412,9 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
{ {
if (internalFormatInfo.compressed) if (internalFormatInfo.compressed)
{ {
size_t dataSize = 0; GLuint dataSize = 0;
ANGLE_TRY_RESULT( ANGLE_TRY_RESULT(
internalFormatInfo.computeBlockSize( internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize),
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height),
dataSize); dataSize);
mFunctions->compressedTexImage2D( mFunctions->compressedTexImage2D(
face, static_cast<GLint>(level), texStorageFormat.internalFormat, face, static_cast<GLint>(level), texStorageFormat.internalFormat,
...@@ -464,14 +463,13 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor ...@@ -464,14 +463,13 @@ gl::Error TextureGL::setStorage(GLenum target, size_t levels, GLenum internalFor
if (internalFormatInfo.compressed) if (internalFormatInfo.compressed)
{ {
GLuint blockSize = 0; GLuint dataSize = 0;
ANGLE_TRY_RESULT(internalFormatInfo.computeBlockSize( ANGLE_TRY_RESULT(
GL_UNSIGNED_BYTE, levelSize.width, levelSize.height), internalFormatInfo.computeBlockSize(GL_UNSIGNED_BYTE, levelSize), dataSize);
blockSize);
GLsizei dataSize = static_cast<GLsizei>(blockSize) * levelSize.depth;
mFunctions->compressedTexImage3D(target, i, texStorageFormat.internalFormat, mFunctions->compressedTexImage3D(target, i, texStorageFormat.internalFormat,
levelSize.width, levelSize.height, levelSize.width, levelSize.height,
levelSize.depth, 0, dataSize, nullptr); levelSize.depth, 0,
static_cast<GLsizei>(dataSize), nullptr);
} }
else else
{ {
......
...@@ -1830,7 +1830,8 @@ bool ValidateCompressedTexImage2D(Context *context, ...@@ -1830,7 +1830,8 @@ bool ValidateCompressedTexImage2D(Context *context,
} }
const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); 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()) if (blockSizeOrErr.isError())
{ {
context->handleError(blockSizeOrErr.getError()); context->handleError(blockSizeOrErr.getError());
...@@ -1877,7 +1878,8 @@ bool ValidateCompressedTexSubImage2D(Context *context, ...@@ -1877,7 +1878,8 @@ bool ValidateCompressedTexSubImage2D(Context *context,
} }
const InternalFormat &formatInfo = GetInternalFormatInfo(format); 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()) if (blockSizeOrErr.isError())
{ {
context->handleError(blockSizeOrErr.getError()); context->handleError(blockSizeOrErr.getError());
......
...@@ -490,7 +490,7 @@ bool ValidateES3TexImageParametersBase(Context *context, ...@@ -490,7 +490,7 @@ bool ValidateES3TexImageParametersBase(Context *context,
} }
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); 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()) if (copyBytesOrErr.isError())
{ {
context->handleError(copyBytesOrErr.getError()); context->handleError(copyBytesOrErr.getError());
...@@ -1557,10 +1557,11 @@ bool ValidateCompressedTexImage3D(Context *context, ...@@ -1557,10 +1557,11 @@ bool ValidateCompressedTexImage3D(Context *context,
} }
const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); 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()) if (blockSizeOrErr.isError())
{ {
context->handleError(blockSizeOrErr.getError()); context->handleError(Error(GL_INVALID_VALUE));
return false; return false;
} }
if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult())
...@@ -1905,7 +1906,8 @@ bool ValidateCompressedTexSubImage3D(Context *context, ...@@ -1905,7 +1906,8 @@ bool ValidateCompressedTexSubImage3D(Context *context,
} }
const InternalFormat &formatInfo = GetInternalFormatInfo(format); 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()) if (blockSizeOrErr.isError())
{ {
context->handleError(blockSizeOrErr.getError()); 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