我尝试将"Metal By Example“App -TextRendering- for IOS转换为OSX。不幸的是,Xcode告诉我MTLTextureDescriptor的storageMode需要设置为MTLStorageModePrivate,当我这样做的时候:MTLTextureDescriptor抛出"failed assertion ` `CPU access for textures with MTLResourceStorageModePrivate storage mode is disallowed“。
MTLTextureDescriptor *textureDesc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:AAPLDepthPixelFormat
width:MBEFontAtlasSize
height:MBEFontAtlasSize
mipmapped:NO];
textureDesc.storageMode = MTLStorageModePrivate;
textureDesc.usage = MTLTextureUsageRenderTarget | MTLTextureUsageShaderRead | MTLTextureUsageShaderWrite;
textureDesc.usage = MTLTextureUsageShaderRead;//MTLTextureUsageRenderTarget;
MTLRegion region = MTLRegionMake2D(0, 0, MBEFontAtlasSize, MBEFontAtlasSize);
_fontTexture = [_device newTextureWithDescriptor:textureDesc];
[_fontTexture setLabel:@"Font Atlas"];
[_fontTexture replaceRegion:region mipmapLevel:0 withBytes:_fontAtlas.textureData.bytes bytesPerRow:MBEFontAtlasSize];任何帮助都将不胜感激!
发布于 2021-03-12 03:02:41
在macOS上,您实际上必须显式地在CPU/RAM和GPU之间同步资源(因为Mac可能有一个拥有自己内存的专用GPU,而不是iOS上的共享内存模型)。
为此,您需要将存储模式设置为managed,并使用MTLBlitCommandEncoder在设备之间复制内存(请参阅documentation of managed)。
https://stackoverflow.com/questions/66588313
复制相似问题