Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c9fd4a1a1e6a337b6f4b75c1e660e2cab54e1470
      
https://github.com/WebKit/WebKit/commit/c9fd4a1a1e6a337b6f4b75c1e660e2cab54e1470
  Author: Kimmo Kinnunen <[email protected]>
  Date:   2026-06-15 (Mon, 15 Jun 2026)

  Changed paths:
    M Source/ThirdParty/ANGLE/src/common/angleutils.h
    M Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.h
    M Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.mm
    M Source/ThirdParty/ANGLE/src/tests/gl_tests/CopyTexImageTest.cpp
    M Source/ThirdParty/ANGLE/src/tests/gl_tests/MipmapTest.cpp
    M Source/ThirdParty/ANGLE/src/tests/gl_tests/TextureTest.cpp

  Log Message:
  -----------
  WebGL: GenerateMipmap after out of base level -max level texupload uses the 
wrong type
https://bugs.webkit.org/show_bug.cgi?id=309414
rdar://171630355

Reviewed by Dan Glastonbury.

TextureMtl::mFormat was updated on each TexImage2D. However, this
variable represents the format of mNativeTextureStorage, the base-max
mipmap range of a mipmap complete texture. Updating out-of-range
mipmaps does not invalidate the mipmap chain, and thus not
mNativeTextureStorage. Many functions further used mFormat then to
configure the use or update of mNativeTextureStorage, with incorrect
mFormat.

Fix by not updating mFormat when an image is defined. This happens
in glTexImage*(), glCopyImage*(), glCopyTexture*(), eglBindTexImage(),
eglReleaseTexImage().

Fix updating mFormat only when mNativeTextureStorage is updated,
based on the mipmap chain format, i.e base mipmap format. This happens
in glGenerateMipmap() and state synchronization for rendering to texture
and draw sampling from the texture.

Fix by using the existing image definition for functions that already
expect the image to exist. If the image does not exist, fail with
a internal runtime error. This happens for glTexSubImage*,
glCopySubTexture*() glCopySubImage*().

* Source/ThirdParty/ANGLE/src/common/angleutils.h:
* Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.h:
* Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.mm:
(rx::TextureMtl::deallocateNativeStorage):
Remove keepSamplerStateAndFormat
Only used when the base or max mipmap level changes. This might
change the texture format, so the sampler and format will change.
Also, mFormat is only defined when mNativeTextureStorage exists, and
this function discards it.
Sampler is always discarded, because base-max change might change
the format, and sample depends on the format.

(rx::TextureMtl::ensureNativeStorageCreated):
(rx::TextureMtl::onBaseMaxLevelsChanged):
(rx::TextureMtl::getRenderTarget):

Framebuffer attachment update on render-to-texture via FBO
- Expect image to be defined, as otherwise frontend should not let
  the call through.
- Use the format of the defined image, not the format of the mipmap
  chain. The RT image might not be within the mipmap chain.

(rx::TextureMtl::generateMipmapCPU):
(rx::TextureMtl::setStorageImpl):
(rx::TextureMtl::setSubImageImpl):
(rx::TextureMtl::convertAndSetPerSliceSubImage):
(rx::TextureMtl::initializeContents):
(rx::TextureMtl::copySubImageImpl):
(rx::TextureMtl::copySubImageCPU):
(rx::TextureMtl::copySubTextureImpl):
(rx::TextureMtl::copySubTextureWithDraw):
(rx::TextureMtl::copySubTextureCPU):
(rx::TextureMtl::ensureImageCreated): Deleted.
Remove the function. It was always called from functions that
should already have image on that level. If we didn't have image on
the particular level, we would not be able to create one since we
would not know which format to create.

* Source/ThirdParty/ANGLE/src/tests/gl_tests/CopyTexImageTest.cpp:
(angle::TEST_P):
* Source/ThirdParty/ANGLE/src/tests/gl_tests/MipmapTest.cpp:
* Source/ThirdParty/ANGLE/src/tests/gl_tests/TextureTest.cpp:

Originally-landed-as: 305413.455@rapid/safari-7624.2.5.110-branch 
(92ab1d63ba59). rdar://176061493
Canonical link: https://commits.webkit.org/315237@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to