Skip to content

Commit

Permalink
fix metal pvrtc upload issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bluesky013 committed Aug 8, 2023
1 parent b7ad5b1 commit dae1344
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions native/cocos/renderer/gfx-metal/MTLTexture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,21 @@ of this software and associated engine source code (the "Software"), a limited,
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> mtlDevice = id<MTLDevice>(CCMTLDevice::getInstance()->getMTLDevice());
_mtlTexture = [mtlDevice newTextureWithDescriptor:descriptor];

Expand Down

0 comments on commit dae1344

Please sign in to comment.