Bug 966630 - Clamp level to TexImage operations to [0..31]. r=jgilbert
authorDan Glastonbury <dglastonbury@mozilla.com>
Wed, 16 Apr 2014 11:23:41 +1000
changeset 178738 b300ff71f9b0a57ea2fad3eba139085760806b63
parent 178737 ed916d97eb27f7c7481614d176f0661ef0853dd0
child 178739 b45fb59280c6eb46b8ed4bdd3a909f62ff4d58b1
push id26595
push usercbook@mozilla.com
push dateWed, 16 Apr 2014 12:48:58 +0000
treeherdermozilla-central@f7c4e7719778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjgilbert
bugs966630
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 966630 - Clamp level to TexImage operations to [0..31]. r=jgilbert
content/canvas/src/WebGLContextValidate.cpp
--- a/content/canvas/src/WebGLContextValidate.cpp
+++ b/content/canvas/src/WebGLContextValidate.cpp
@@ -924,16 +924,29 @@ WebGLContext::ValidateCompTexImageDataSi
  */
 bool
 WebGLContext::ValidateTexImageSize(GLenum target, GLint level,
                                    GLint width, GLint height, GLint depth,
                                    WebGLTexImageFunc func)
 {
     MOZ_ASSERT(level >= 0, "level should already be validated");
 
+    /* Bug 966630: maxTextureSize >> level runs into "undefined"
+     * behaviour depending on ISA. For example, on Intel shifts
+     * amounts are mod 64 (in 64-bit mode on 64-bit dest) and mod 32
+     * otherwise. This means 16384 >> 0x10000001 == 8192 which isn't
+     * what would be expected. Make the required behaviour explicit by
+     * clamping to a shift of 31 bits if level is greater than that
+     * ammount. This will give 0 that if (!maxAllowedSize) is
+     * expecting.
+     */
+
+    if (level > 31)
+        level = 31;
+
     const GLuint maxTexImageSize = MaxTextureSizeForTarget(target) >> level;
     const bool isCubemapTarget = IsTexImageCubemapTarget(target);
 
     if (isCubemapTarget && width != height) {
         /* GL ES Version 2.0.25 - 3.7.1 Texture Image Specification
          *   "When the target parameter to TexImage2D is one of the
          *   six cube map two-dimensional image targets, the error
          *   INVALID_VALUE is generated if the width and height