From 0abd8c4da5fe89fefe3ace24cd3192aeb67a799f Mon Sep 17 00:00:00 2001 From: Zach Lee Date: Wed, 9 Aug 2023 10:35:13 +0800 Subject: [PATCH] fix metal pvrtc upload issue (#15894) --- native/cocos/renderer/gfx-metal/MTLTexture.mm | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/native/cocos/renderer/gfx-metal/MTLTexture.mm b/native/cocos/renderer/gfx-metal/MTLTexture.mm index edab24a636..96d7b9a1bc 100644 --- a/native/cocos/renderer/gfx-metal/MTLTexture.mm +++ b/native/cocos/renderer/gfx-metal/MTLTexture.mm @@ -225,17 +225,21 @@ bool CCMTLTexture::createMTLTexture() { descriptor.mipmapLevelCount = _info.levelCount; descriptor.arrayLength = _info.type == TextureType::CUBE ? 1 : _info.layerCount; - descriptor.storageMode = MTLStorageModePrivate; + bool memoryless = false; if (@available(macos 11.0, ios 10.0, *)) { - bool memoryless = hasFlag(_info.flags, TextureFlagBit::LAZILY_ALLOCATED) && - hasFlag(_info.usage, TextureUsageBit::COLOR_ATTACHMENT) && - hasFlag(_info.usage, TextureUsageBit::DEPTH_STENCIL_ATTACHMENT); + memoryless = hasFlag(_info.flags, TextureFlagBit::LAZILY_ALLOCATED) && + hasAllFlags(TextureUsageBit::COLOR_ATTACHMENT | TextureUsageBit::DEPTH_STENCIL_ATTACHMENT | TextureUsageBit::INPUT_ATTACHMENT, _info.usage); if (memoryless) { descriptor.storageMode = MTLStorageModeMemoryless; _allocateMemory = false; } } + if (!memoryless && !_isPVRTC) { + // pvrtc can not use blit encoder to upload data. + descriptor.storageMode = MTLStorageModePrivate; + } + id mtlDevice = id(CCMTLDevice::getInstance()->getMTLDevice()); _mtlTexture = [mtlDevice newTextureWithDescriptor:descriptor];