Commit dfbfb21b authored by Ashly Hale's avatar Ashly Hale Committed by Richard Pospesel
Browse files

Bug 1789729 - Implement webgl.max-size-per-texture-mib r=jgilbert a=RyanVM

parent 4c3730ee
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -752,9 +752,27 @@ static bool ValidateCompressedTexImageRestrictions(
  return true;
}

static bool ValidateTargetForFormat(const WebGLContext* webgl,
static bool ValidateFormatAndSize(const WebGLContext* webgl,
                                  TexImageTarget target,
                                    const webgl::FormatInfo* format) {
                                  const webgl::FormatInfo* format,
                                  const uvec3& size) {
  // Check if texture size will likely be rejected by the driver and give a more
  // meaningful error message.
  auto baseImageSize = CheckedInt<uint64_t>(format->estimatedBytesPerPixel) *
                       (uint32_t)size.x * (uint32_t)size.y * (uint32_t)size.z;
  if (target == LOCAL_GL_TEXTURE_CUBE_MAP) {
    baseImageSize *= 6;
  }
  if (!baseImageSize.isValid() ||
      baseImageSize.value() >
          (uint64_t)StaticPrefs::webgl_max_size_per_texture_mib() *
              (1024 * 1024)) {
    webgl->ErrorOutOfMemory(
        "Texture size too large; base image mebibytes > "
        "webgl.max-size-per-texture-mib");
    return false;
  }

  // GLES 3.0.4 p127:
  // "Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL
  // are supported by texture image specification commands only if `target` is
@@ -822,7 +840,7 @@ void WebGLTexture::TexStorage(TexTarget target, uint32_t levels,
  }
  auto dstFormat = dstUsage->format;

  if (!ValidateTargetForFormat(mContext, testTarget, dstFormat)) return;
  if (!ValidateFormatAndSize(mContext, testTarget, dstFormat, size)) return;

  if (dstFormat->compression) {
    if (!ValidateCompressedTexImageRestrictions(mContext, testTarget, 0,
@@ -987,7 +1005,7 @@ void WebGLTexture::TexImage(uint32_t level, GLenum respecFormat,
    }

    const auto& dstFormat = dstUsage->format;
    if (!ValidateTargetForFormat(mContext, imageTarget, dstFormat)) return;
    if (!ValidateFormatAndSize(mContext, imageTarget, dstFormat, size)) return;

    if (!mContext->IsWebGL2() && dstFormat->d) {
      if (imageTarget != LOCAL_GL_TEXTURE_2D || blob->HasData() || level != 0) {
@@ -1179,7 +1197,8 @@ void WebGLTexture::CompressedTexImage(bool sub, GLenum imageTarget,
    }
    MOZ_ASSERT(imageInfo);

    if (!ValidateTargetForFormat(mContext, imageTarget, usage->format)) return;
    if (!ValidateFormatAndSize(mContext, imageTarget, usage->format, size))
      return;
    if (!ValidateCompressedTexImageRestrictions(mContext, imageTarget, level,
                                                usage->format, size)) {
      return;
@@ -1815,7 +1834,7 @@ void WebGLTexture::CopyTexImage(GLenum imageTarget, uint32_t level,
    dstUsage = ValidateCopyDestUsage(mContext, srcFormat, respecFormat);
    if (!dstUsage) return;

    if (!ValidateTargetForFormat(mContext, imageTarget, dstUsage->format))
    if (!ValidateFormatAndSize(mContext, imageTarget, dstUsage->format, size))
      return;
  } else {
    if (!ValidateTexImageSelection(imageTarget, level, dstOffset, size,
+5 −0
Original line number Diff line number Diff line
@@ -11419,6 +11419,11 @@
  value: 300
  mirror: always

- name: webgl.max-size-per-texture-mib
  type: RelaxedAtomicUint32
  value: 1024
  mirror: always

- name: webgl.max-warnings-per-context
  type: RelaxedAtomicUint32
  value: 32