Commit 2fc9051e by Nicolas Capens Committed by Nicolas Capens

Fix pixel size calculation from upload format.

We were using the internal format to compute the size of the pixels provided for texture image upload. They can differ in size from the format/type combination. Change-Id: I7f3cd535cdefefc3c7ec4695d35d181b43ae20a4 Reviewed-on: https://swiftshader-review.googlesource.com/16629Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 8f215a4b
...@@ -906,192 +906,107 @@ namespace egl ...@@ -906,192 +906,107 @@ namespace egl
return sw::FORMAT_NULL; return sw::FORMAT_NULL;
} }
// Returns the size, in bytes, of a single texel in an Image // Returns the size, in bytes, of a single client-side pixel.
// OpenGL ES 3.0.5 table 3.2.
static int ComputePixelSize(GLenum format, GLenum type) static int ComputePixelSize(GLenum format, GLenum type)
{ {
switch(type) switch(format)
{ {
case GL_BYTE: case GL_RED:
switch(format) case GL_RED_INTEGER:
{ case GL_ALPHA:
case GL_R8: case GL_LUMINANCE:
case GL_R8I: switch(type)
case GL_R8_SNORM:
case GL_RED: return sizeof(char);
case GL_RED_INTEGER: return sizeof(char);
case GL_RG8:
case GL_RG8I:
case GL_RG8_SNORM:
case GL_RG: return sizeof(char) * 2;
case GL_RG_INTEGER: return sizeof(char) * 2;
case GL_RGB8:
case GL_RGB8I:
case GL_RGB8_SNORM:
case GL_RGB: return sizeof(char) * 3;
case GL_RGB_INTEGER: return sizeof(char) * 3;
case GL_RGBA8:
case GL_RGBA8I:
case GL_RGBA8_SNORM:
case GL_RGBA: return sizeof(char) * 4;
case GL_RGBA_INTEGER: return sizeof(char) * 4;
default: UNREACHABLE(format);
}
break;
case GL_UNSIGNED_BYTE:
switch(format)
{
case GL_R8:
case GL_R8UI:
case GL_RED: return sizeof(unsigned char);
case GL_RED_INTEGER: return sizeof(unsigned char);
case GL_ALPHA8_EXT:
case GL_ALPHA: return sizeof(unsigned char);
case GL_LUMINANCE8_EXT:
case GL_LUMINANCE: return sizeof(unsigned char);
case GL_LUMINANCE8_ALPHA8_EXT:
case GL_LUMINANCE_ALPHA: return sizeof(unsigned char) * 2;
case GL_RG8:
case GL_RG8UI:
case GL_RG: return sizeof(unsigned char) * 2;
case GL_RG_INTEGER: return sizeof(unsigned char) * 2;
case GL_RGB8:
case GL_RGB8UI:
case GL_SRGB8:
case GL_RGB: return sizeof(unsigned char) * 3;
case GL_RGB_INTEGER: return sizeof(unsigned char) * 3;
case GL_RGBA8:
case GL_RGBA8UI:
case GL_SRGB8_ALPHA8:
case GL_RGBA: return sizeof(unsigned char) * 4;
case GL_RGBA_INTEGER: return sizeof(unsigned char) * 4;
case GL_BGRA_EXT:
case GL_BGRA8_EXT: return sizeof(unsigned char)* 4;
default: UNREACHABLE(format);
}
break;
case GL_SHORT:
switch(format)
{ {
case GL_R16I: case GL_BYTE: return 1;
case GL_RED_INTEGER: return sizeof(short); case GL_UNSIGNED_BYTE: return 1;
case GL_RG16I: case GL_FLOAT: return 4;
case GL_RG_INTEGER: return sizeof(short) * 2; case GL_HALF_FLOAT: return 2;
case GL_RGB16I: case GL_HALF_FLOAT_OES: return 2;
case GL_RGB_INTEGER: return sizeof(short) * 3; case GL_SHORT: return 2;
case GL_RGBA16I: case GL_UNSIGNED_SHORT: return 2;
case GL_RGBA_INTEGER: return sizeof(short) * 4; case GL_INT: return 4;
default: UNREACHABLE(format); case GL_UNSIGNED_INT: return 4;
default: UNREACHABLE(type);
} }
break; break;
case GL_UNSIGNED_SHORT: case GL_RG:
switch(format) case GL_RG_INTEGER:
case GL_LUMINANCE_ALPHA:
switch(type)
{ {
case GL_DEPTH_COMPONENT16: case GL_BYTE: return 2;
case GL_DEPTH_COMPONENT: return sizeof(unsigned short); case GL_UNSIGNED_BYTE: return 2;
case GL_R16UI: case GL_FLOAT: return 8;
case GL_RED_INTEGER: return sizeof(unsigned short); case GL_HALF_FLOAT: return 4;
case GL_RG16UI: case GL_HALF_FLOAT_OES: return 4;
case GL_RG_INTEGER: return sizeof(unsigned short) * 2; case GL_SHORT: return 4;
case GL_RGB16UI: case GL_UNSIGNED_SHORT: return 4;
case GL_RGB_INTEGER: return sizeof(unsigned short) * 3; case GL_INT: return 8;
case GL_RGBA16UI: case GL_UNSIGNED_INT: return 8;
case GL_RGBA_INTEGER: return sizeof(unsigned short) * 4; default: UNREACHABLE(type);
default: UNREACHABLE(format);
} }
break; break;
case GL_INT: case GL_RGB:
switch(format) case GL_RGB_INTEGER:
switch(type)
{ {
case GL_R32I: case GL_BYTE: return 3;
case GL_RED_INTEGER: return sizeof(int); case GL_UNSIGNED_BYTE: return 3;
case GL_RG32I: case GL_UNSIGNED_SHORT_5_6_5: return 2;
case GL_RG_INTEGER: return sizeof(int) * 2; case GL_UNSIGNED_INT_10F_11F_11F_REV: return 4;
case GL_RGB32I: case GL_UNSIGNED_INT_5_9_9_9_REV: return 4;
case GL_RGB_INTEGER: return sizeof(int) * 3; case GL_FLOAT: return 12;
case GL_RGBA32I: case GL_HALF_FLOAT: return 6;
case GL_RGBA_INTEGER: return sizeof(int) * 4; case GL_HALF_FLOAT_OES: return 6;
default: UNREACHABLE(format); case GL_SHORT: return 6;
case GL_UNSIGNED_SHORT: return 6;
case GL_INT: return 12;
case GL_UNSIGNED_INT: return 12;
default: UNREACHABLE(type);
} }
break; break;
case GL_UNSIGNED_INT: case GL_RGBA:
switch(format) case GL_RGBA_INTEGER:
case GL_BGRA_EXT:
switch(type)
{ {
case GL_DEPTH_COMPONENT16: case GL_BYTE: return 4;
case GL_DEPTH_COMPONENT24: case GL_UNSIGNED_BYTE: return 4;
case GL_DEPTH_COMPONENT32_OES: case GL_UNSIGNED_SHORT_4_4_4_4: return 2;
case GL_DEPTH_COMPONENT: return sizeof(unsigned int); case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: return 2;
case GL_R32UI: case GL_UNSIGNED_SHORT_5_5_5_1: return 2;
case GL_RED_INTEGER: return sizeof(unsigned int); case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: return 2;
case GL_RG32UI: case GL_UNSIGNED_INT_2_10_10_10_REV: return 4;
case GL_RG_INTEGER: return sizeof(unsigned int) * 2; case GL_FLOAT: return 16;
case GL_RGB32UI: case GL_HALF_FLOAT: return 8;
case GL_RGB_INTEGER: return sizeof(unsigned int) * 3; case GL_HALF_FLOAT_OES: return 8;
case GL_RGBA32UI: case GL_SHORT: return 8;
case GL_RGBA_INTEGER: return sizeof(unsigned int) * 4; case GL_UNSIGNED_SHORT: return 8;
default: UNREACHABLE(format); case GL_INT: return 16;
case GL_UNSIGNED_INT: return 16;
default: UNREACHABLE(type);
} }
break; break;
case GL_UNSIGNED_SHORT_4_4_4_4: case GL_DEPTH_COMPONENT:
case GL_UNSIGNED_SHORT_5_5_5_1: switch(type)
case GL_UNSIGNED_SHORT_5_6_5:
case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
return sizeof(unsigned short);
case GL_UNSIGNED_INT_10F_11F_11F_REV:
case GL_UNSIGNED_INT_5_9_9_9_REV:
case GL_UNSIGNED_INT_2_10_10_10_REV:
case GL_UNSIGNED_INT_24_8_OES:
return sizeof(unsigned int);
case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
return sizeof(float) + sizeof(unsigned int);
case GL_FLOAT:
switch(format)
{ {
case GL_DEPTH_COMPONENT32F: case GL_FLOAT: return 4;
case GL_DEPTH_COMPONENT: return sizeof(float); case GL_UNSIGNED_SHORT: return 2;
case GL_ALPHA32F_EXT: case GL_UNSIGNED_INT: return 4;
case GL_ALPHA: return sizeof(float); default: UNREACHABLE(type);
case GL_LUMINANCE32F_EXT:
case GL_LUMINANCE: return sizeof(float);
case GL_LUMINANCE_ALPHA32F_EXT:
case GL_LUMINANCE_ALPHA: return sizeof(float) * 2;
case GL_RED: return sizeof(float);
case GL_R32F: return sizeof(float);
case GL_RG: return sizeof(float) * 2;
case GL_RG32F: return sizeof(float) * 2;
case GL_RGB: return sizeof(float) * 3;
case GL_RGB32F: return sizeof(float) * 3;
case GL_RGBA: return sizeof(float) * 4;
case GL_RGBA32F: return sizeof(float) * 4;
case GL_R11F_G11F_B10F: return sizeof(int);
case GL_RGB9_E5: return sizeof(int);
default: UNREACHABLE(format);
} }
break; break;
case GL_HALF_FLOAT: case GL_DEPTH_STENCIL:
case GL_HALF_FLOAT_OES: switch(type)
switch(format)
{ {
case GL_ALPHA16F_EXT: case GL_UNSIGNED_INT_24_8: return 4;
case GL_ALPHA: return sizeof(unsigned short); case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: return 8;
case GL_LUMINANCE16F_EXT: default: UNREACHABLE(type);
case GL_LUMINANCE: return sizeof(unsigned short);
case GL_LUMINANCE_ALPHA16F_EXT:
case GL_LUMINANCE_ALPHA: return sizeof(unsigned short) * 2;
case GL_RED: return sizeof(unsigned short);
case GL_R16F: return sizeof(unsigned short);
case GL_RG: return sizeof(unsigned short) * 2;
case GL_RG16F: return sizeof(unsigned short) * 2;
case GL_RGB: return sizeof(unsigned short) * 3;
case GL_RGB16F: return sizeof(unsigned short) * 3;
case GL_RGBA: return sizeof(unsigned short) * 4;
case GL_RGBA16F: return sizeof(unsigned short) * 4;
case GL_R11F_G11F_B10F: return sizeof(int);
case GL_RGB9_E5: return sizeof(int);
default: UNREACHABLE(format);
} }
break; break;
default: UNREACHABLE(type); default:
UNREACHABLE(format);
} }
return 0; return 0;
......
...@@ -1588,9 +1588,8 @@ Buffer *Context::getGenericUniformBuffer() const ...@@ -1588,9 +1588,8 @@ Buffer *Context::getGenericUniformBuffer() const
return mState.genericUniformBuffer; return mState.genericUniformBuffer;
} }
GLsizei Context::getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLint internalformat, GLenum type) const GLsizei Context::getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type) const
{ {
GLenum format = GetSizedInternalFormat(internalformat, type);
GLsizei inputWidth = (mState.unpackInfo.rowLength == 0) ? width : mState.unpackInfo.rowLength; GLsizei inputWidth = (mState.unpackInfo.rowLength == 0) ? width : mState.unpackInfo.rowLength;
GLsizei inputPitch = egl::ComputePitch(inputWidth, format, type, mState.unpackInfo.alignment); GLsizei inputPitch = egl::ComputePitch(inputWidth, format, type, mState.unpackInfo.alignment);
GLsizei inputHeight = (mState.unpackInfo.imageHeight == 0) ? height : mState.unpackInfo.imageHeight; GLsizei inputHeight = (mState.unpackInfo.imageHeight == 0) ? height : mState.unpackInfo.imageHeight;
......
...@@ -646,7 +646,7 @@ public: ...@@ -646,7 +646,7 @@ public:
Buffer *getPixelPackBuffer() const; Buffer *getPixelPackBuffer() const;
Buffer *getPixelUnpackBuffer() const; Buffer *getPixelUnpackBuffer() const;
Buffer *getGenericUniformBuffer() const; Buffer *getGenericUniformBuffer() const;
GLsizei getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLint internalformat, GLenum type) const; GLsizei getRequiredBufferSize(GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type) const;
GLenum getPixels(const GLvoid **data, GLenum type, GLsizei imageSize) const; GLenum getPixels(const GLvoid **data, GLenum type, GLsizei imageSize) const;
bool getBuffer(GLenum target, es2::Buffer **buffer) const; bool getBuffer(GLenum target, es2::Buffer **buffer) const;
Program *getCurrentProgram() const; Program *getCurrentProgram() const;
......
...@@ -6245,13 +6245,13 @@ void TexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei wi ...@@ -6245,13 +6245,13 @@ void TexImage3DOES(GLenum target, GLint level, GLenum internalformat, GLsizei wi
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
GLenum sizedInternalFormat = GetSizedInternalFormat(internalformat, type); GLenum validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, format, type));
GLenum validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, sizedInternalFormat, type));
if(validationError != GL_NONE) if(validationError != GL_NONE)
{ {
return error(validationError); return error(validationError);
} }
GLenum sizedInternalFormat = GetSizedInternalFormat(internalformat, type);
texture->setImage(context, level, width, height, depth, sizedInternalFormat, format, type, context->getUnpackInfo(), data); texture->setImage(context, level, width, height, depth, sizedInternalFormat, format, type, context->getUnpackInfo(), data);
} }
} }
......
...@@ -626,14 +626,13 @@ GL_APICALL void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint inter ...@@ -626,14 +626,13 @@ GL_APICALL void GL_APIENTRY glTexImage3D(GLenum target, GLint level, GLint inter
return error(GL_INVALID_OPERATION); return error(GL_INVALID_OPERATION);
} }
GLenum sizedInternalFormat = GetSizedInternalFormat(internalformat, type); GLenum validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, format, type));
GLenum validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, sizedInternalFormat, type));
if(validationError != GL_NONE) if(validationError != GL_NONE)
{ {
return error(validationError); return error(validationError);
} }
GLenum sizedInternalFormat = GetSizedInternalFormat(internalformat, type);
texture->setImage(context, level, width, height, depth, sizedInternalFormat, format, type, context->getUnpackInfo(), data); texture->setImage(context, level, width, height, depth, sizedInternalFormat, format, type, context->getUnpackInfo(), data);
} }
} }
...@@ -675,21 +674,19 @@ GL_APICALL void GL_APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xo ...@@ -675,21 +674,19 @@ GL_APICALL void GL_APIENTRY glTexSubImage3D(GLenum target, GLint level, GLint xo
{ {
es2::Texture3D *texture = (target == GL_TEXTURE_3D) ? context->getTexture3D() : context->getTexture2DArray(); es2::Texture3D *texture = (target == GL_TEXTURE_3D) ? context->getTexture3D() : context->getTexture2DArray();
GLenum sizedInternalFormat = GetSizedInternalFormat(format, type);
GLenum validationError = ValidateSubImageParams(false, false, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, texture, context->getClientVersion()); GLenum validationError = ValidateSubImageParams(false, false, target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, texture, context->getClientVersion());
if(validationError != GL_NONE) if(validationError != GL_NONE)
{ {
return error(validationError); return error(validationError);
} }
validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, sizedInternalFormat, type)); validationError = context->getPixels(&data, type, context->getRequiredBufferSize(width, height, depth, format, type));
if(validationError != GL_NONE) if(validationError != GL_NONE)
{ {
return error(validationError); return error(validationError);
} }
texture->subImage(context, level, xoffset, yoffset, zoffset, width, height, depth, sizedInternalFormat, type, context->getUnpackInfo(), data); texture->subImage(context, level, xoffset, yoffset, zoffset, width, height, depth, format, type, context->getUnpackInfo(), data);
} }
} }
......
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