⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 276190 in webkit


Ignore:
Timestamp:
Apr 16, 2021, 7:06:15 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

Metal-ANGLE: Shared memory texture tests failing in iOS Simulator
https://bugs.webkit.org/show_bug.cgi?id=222685

Patch by Kyle Piddington <Kyle Piddington> on 2021-04-16
Reviewed by Dean Jackson.

Simulator-only path drives filling textures via Blit encoders instead of mapped memory.
This workaround fixes dropped texture writes when using replaceRegion

  • src/libANGLE/renderer/metal/TextureMtl.mm:
  • src/libANGLE/renderer/metal/mtl_utils.mm:

(rx::mtl::InitializeTextureContents):

Location:
trunk/Source/ThirdParty/ANGLE
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/ThirdParty/ANGLE/ChangeLog

    r276104 r276190  
     12021-04-16  Kyle Piddington  <kpiddington@apple.com>
     2
     3        Metal-ANGLE: Shared memory texture tests failing in iOS Simulator
     4        https://bugs.webkit.org/show_bug.cgi?id=222685
     5
     6        Reviewed by Dean Jackson.
     7
     8        Simulator-only path drives filling textures via Blit encoders instead of mapped memory.
     9        This workaround fixes dropped texture writes when using replaceRegion
     10
     11        * src/libANGLE/renderer/metal/TextureMtl.mm:
     12        * src/libANGLE/renderer/metal/mtl_utils.mm:
     13        (rx::mtl::InitializeTextureContents):
     14
    1152021-04-15  Alex Christensen  <achristensen@webkit.org>
    216
  • trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/TextureMtl.mm

    r275649 r276190  
    175175}
    176176
     177
     178#if TARGET_OS_SIMULATOR
     179void CopyTextureData(const MTLSize &regionSize,
     180                             size_t srcRowPitch,
     181                             size_t src2DImageSize,
     182                             const uint8_t *psrc,
     183                             size_t destRowPitch,
     184                             size_t dest2DImageSize,
     185                             uint8_t *pdst)
     186{
     187    {
     188        size_t rowCopySize = std::min(srcRowPitch, destRowPitch);
     189        for (NSUInteger d = 0; d < regionSize.depth; ++d)
     190        {
     191            for (NSUInteger r = 0; r < regionSize.height; ++r)
     192            {
     193                const uint8_t *pCopySrc = psrc + d * src2DImageSize + r * srcRowPitch;
     194                uint8_t *pCopyDst       = pdst + d * dest2DImageSize + r * destRowPitch;
     195                memcpy(pCopyDst, pCopySrc, rowCopySize);
     196            }
     197        }
     198    }
     199}
     200#endif
     201
    177202void ConvertDepthStencilData(const MTLSize &regionSize,
    178203                             const angle::Format &srcAngleFormat,
     
    266291    return angle::Result::Continue;
    267292}
     293
     294#if TARGET_OS_SIMULATOR
     295angle::Result CopyTextureContentsToStagingBuffer(
     296    ContextMtl *contextMtl,
     297    const angle::Format &textureAngleFormat,
     298    const MTLSize &regionSize,
     299    const uint8_t *data,
     300    size_t bytesPerRow,
     301    size_t bytesPer2DImage,
     302    size_t *bufferRowPitchOut,
     303    size_t *buffer2DImageSizeOut,
     304    mtl::BufferRef *bufferOut)
     305{
     306    size_t stagingBufferRowPitch    = regionSize.width * textureAngleFormat.pixelBytes;
     307    size_t stagingBuffer2DImageSize = stagingBufferRowPitch * regionSize.height;
     308    size_t stagingBufferSize        = stagingBuffer2DImageSize * regionSize.depth;
     309    mtl::BufferRef stagingBuffer;
     310    ANGLE_TRY(mtl::Buffer::MakeBuffer(contextMtl, stagingBufferSize, nullptr, &stagingBuffer));
     311
     312    uint8_t *pdst = stagingBuffer->map(contextMtl);
     313
     314    CopyTextureData(regionSize, bytesPerRow, bytesPer2DImage,
     315                    data, stagingBufferRowPitch, stagingBuffer2DImageSize, pdst);
     316
     317    stagingBuffer->unmap(contextMtl);
     318
     319    *bufferOut            = stagingBuffer;
     320    *bufferRowPitchOut    = stagingBufferRowPitch;
     321    *buffer2DImageSizeOut = stagingBuffer2DImageSize;
     322
     323    return angle::Result::Continue;
     324}
     325#endif
    268326
    269327angle::Result UploadDepthStencilTextureContentsWithStagingBuffer(
     
    379437}
    380438
     439#if TARGET_OS_SIMULATOR
     440angle::Result UploadTextureContentsWithStagingBuffer(
     441    ContextMtl *contextMtl,
     442    const angle::Format &textureAngleFormat,
     443    MTLRegion region,
     444    const mtl::MipmapNativeLevel &mipmapLevel,
     445    uint32_t slice,
     446    const uint8_t *data,
     447    size_t bytesPerRow,
     448    size_t bytesPer2DImage,
     449    const mtl::TextureRef &texture)
     450{
     451    ASSERT(texture && texture->valid());
     452   
     453    angle::FormatID stagingBufferFormatID = textureAngleFormat.id;
     454    const angle::Format &angleStagingFormat = angle::Format::Get(stagingBufferFormatID);
     455   
     456
     457    size_t stagingBufferRowPitch;
     458    size_t stagingBuffer2DImageSize;
     459    mtl::BufferRef stagingBuffer;
     460
     461    // Copy depth data to staging depth buffer
     462    ANGLE_TRY(CopyTextureContentsToStagingBuffer(contextMtl, angleStagingFormat, region.size, data, bytesPerRow, bytesPer2DImage, &stagingBufferRowPitch, &stagingBuffer2DImageSize, &stagingBuffer));
     463    mtl::BlitCommandEncoder *encoder = contextMtl->getBlitCommandEncoder();
     464
     465    encoder->copyBufferToTexture(stagingBuffer, 0, stagingBufferRowPitch,
     466                                 stagingBuffer2DImageSize, region.size, texture, slice,
     467                                 mipmapLevel, region.origin, 0);
     468   
     469
     470    return angle::Result::Continue;
     471}
     472#endif
     473
    381474angle::Result UploadTextureContents(const gl::Context *context,
    382475                                    const angle::Format &textureAngleFormat,
     
    391484    ASSERT(texture && texture->valid());
    392485    ContextMtl *contextMtl = mtl::GetImpl(context);
    393 
     486#if TARGET_OS_SIMULATOR
     487    if (!textureAngleFormat.depthBits && !textureAngleFormat.stencilBits)
     488    {
     489        ANGLE_TRY(UploadTextureContentsWithStagingBuffer(contextMtl,textureAngleFormat,region,mipmapLevel,slice,data,bytesPerRow,bytesPer2DImage,texture));
     490        return angle::Result::Continue;
     491    }
     492#else
    394493    if (texture->isCPUAccessible())
    395494    {
     
    400499        return angle::Result::Continue;
    401500    }
    402 
     501#endif
    403502    ASSERT(textureAngleFormat.depthBits || textureAngleFormat.stencilBits);
    404503
     
    418517
    419518    return angle::Result::Continue;
     519   
    420520}
    421521
  • trunk/Source/ThirdParty/ANGLE/src/libANGLE/renderer/metal/mtl_utils.mm

    r275476 r276190  
    114114    const angle::Format &actualAngleFormat           = textureObjFormat.actualAngleFormat();
    115115    const gl::InternalFormat &intendedInternalFormat = textureObjFormat.intendedInternalFormat();
    116 
     116    bool forceGPUInitialization = false;
     117#if TARGET_OS_SIMULATOR
     118    forceGPUInitialization = true;
     119#endif
    117120    // This function is called in many places to initialize the content of a texture.
    118121    // So it's better we do the sanity check here instead of let the callers do it themselves:
     
    149152
    150153    if (texture->isCPUAccessible() && index.getType() != gl::TextureType::_2DMultisample &&
    151         index.getType() != gl::TextureType::_2DMultisampleArray)
     154        index.getType() != gl::TextureType::_2DMultisampleArray && forceGPUInitialization == false)
    152155    {
    153156        const angle::Format &dstFormat = angle::Format::Get(textureObjFormat.actualFormatId);
     
    199202        }
    200203    }  // if (texture->isCPUAccessible())
     204
    201205    else
    202206    {
Note: See TracChangeset for help on using the changeset viewer.