0 Replies
      Latest reply on Oct 16, 2019 12:51 PM by apleton
      apleton Level 1 Level 1 (0 points)

        In a iOS metal app, I render on a mtkView on a backround thread. I get the current renderDescriptor from the view using mtkView.currentRenderPassDescriptor. I use that renderDescriptor to create a MTLRenderCommandEncoder. That MTLRenderCommandEncoder sometimes have inconsistent size (width, height) during orientation change : _width and _height are different than the size of stored in the currentRenderPassDescriptor. This causes problem when using setScissor method :

        failed assertion `(rect.x(0) + rect.width(1792))(1792) must be <= render pass width(828)’.

        So my questions are :

        • why those 2 sizes are different ? Where does the second size come from ?
        • How can I access this second size (MTLRenderCommandEncoder->_width) as it seems the “real size” used to validate the setScissor method?

        This is a summary of the code :

        MTLRenderPassDescriptor* renderPassDescriptor = view.currentRenderPassDescriptor;
        renderPassDescriptor.colorAttachments[0].loadAction = MTLLoadActionClear;
        renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColorMake(0, 0, 0, 1);
        id 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

         

        This is the description of the MTLRenderCommandEncoder when I get the assertion :

         

         -> 
            label = MyRenderEncoder
            device = 
                name = Apple A12 GPU
            descriptor = 
                Color Attachment 0
                    texture = 
                        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 = 
                    resolveLevel = 0
                    resolveSlice = 0
                    resolveDepthPlane = 0
                    loadAction = MTLLoadActionClear
                    storeAction = MTLStoreActionStore
                    storeActionOptions = none
                    clearColor = (0 0 0 1)
                    yInvert = NO
        
              
                ...
        
                Depth Attachment:
                    texture = 
            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