首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MTLTextureDescriptor难题

MTLTextureDescriptor难题
EN

Stack Overflow用户
提问于 2021-03-12 02:22:55
回答 1查看 39关注 0票数 0

我尝试将"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“。

代码语言:javascript
复制
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];

任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

发布于 2021-03-12 03:02:41

在macOS上,您实际上必须显式地在CPU/RAM和GPU之间同步资源(因为Mac可能有一个拥有自己内存的专用GPU,而不是iOS上的共享内存模型)。

为此,您需要将存储模式设置为managed,并使用MTLBlitCommandEncoder在设备之间复制内存(请参阅documentation of managed)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66588313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档