方向更改期间MTLRenderCommandEncoder的大小不一致

时间:2019-10-15 15:56:06

标签: ios metal

在iOS金属应用中,我在背景线程上的mtkView上进行渲染。我使用mtkView.currentRenderPassDescriptor从视图中获取了当前的renderDescriptor。我使用那个renderDescriptor创建一个MTLRenderCommandEncoder。 MTLRenderCommandEncoder有时在方向更改期间大小不一致:_width和_height与currentRenderPassDescriptor中存储的大小不同。使用setScissor方法时,这会导致问题:

失败的断言`(rect.x(0)+ rect.width(1792))(1792)必须为<= render pass width(828)”。

所以我的问题是:

  • 为什么这两个大小不同?第二个尺寸来自哪里?

  • 我如何访问第二个尺寸(MTLRenderCommandEncoder-> _ width),因为它似乎是用于验证setScissor方法的“实际尺寸”?

这是代码的摘要:

MTLRenderPassDescriptor* renderPassDescriptor = view.currentRenderPassDescriptor;
renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0, 0, 0, 1);
id<MTLRenderCommandEncoder> renderEncoder =
[commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];

CGFloat colorAttachementWidth = _passDescriptor.colorAttachments[0].texture.width;
CGFloat colorAttachementHeight = _passDescriptor.colorAttachments[0].texture.height;
MTLScissorRect rect;
rect.x = 0;
rect.y = 0;
rect.width = colorAttachementWidth;
rect.height = colorAttachementHeight;

[renderEncoder setScissorRect:self.scissorRect]; // -> that will trigger the assertion

这是我得到断言时对MTLRenderCommandEncoder的描述:

<MTLDebugRenderCommandEncoder: 0x105e98000> -> <AGXA12FamilyRenderContext: 0x281dc27c0>
    label = MyRenderEncoder 
    device = <AGXA12Device: 0x10aee4000>
        name = Apple A12 GPU
    descriptor = <MTLRenderPassDescriptorInternal: 0x283d909c0>
        Color Attachment 0 
            texture = <AGXA12FamilyTexture: 0x105f128d0>
                label = Drawable 
                textureType = MTLTextureType2D 
                pixelFormat = MTLPixelFormatBGRA8Unorm 
                width = 1792  // <——————————————————— this size is not consistent with the size below
                height = 828 
                depth = 1 
                arrayLength = 1 
                mipmapLevelCount = 1 
                sampleCount = 1 
                cpuCacheMode = MTLCPUCacheModeDefaultCache 
                storageMode = MTLStorageModeShared 
                resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModeShared  
        …
            level = 0 
            slice = 0 
            depthPlane = 0 
            resolveTexture = <null> 
            resolveLevel = 0 
            resolveSlice = 0 
            resolveDepthPlane = 0 
            loadAction = MTLLoadActionClear 
            storeAction = MTLStoreActionStore 
            storeActionOptions = none 
            clearColor = (0 0 0 1) 
            yInvert = NO 


        ...

        Depth Attachment: 
            texture = <AGXA12FamilyTexture: 0x105cb2fc0>
    label = Render Depth 
    textureType = MTLTextureType2D 
    pixelFormat = MTLPixelFormatDepth32Float 
    width = 828  // <——————————————————— this size is not consistent
    height = 1792 
    depth = 1 
    arrayLength = 1 
    mipmapLevelCount = 1 
    sampleCount = 1 
    cpuCacheMode = MTLCPUCacheModeDefaultCache 
    storageMode = MTLStorageModePrivate 
    resourceOptions = MTLResourceCPUCacheModeDefaultCache MTLResourceStorageModePrivate  
    usage = MTLTextureUsageRenderTarget  

    ...

0 个答案:

没有答案