Chapter 21 - retina bug

Hi there!:grin:

When add

    // blit encoder
    finalTexture = outputTexture
    guard let blitEncoder = commandBuffer.makeBlitCommandEncoder()
    else { return }
    let origin = MTLOriginMake(0, 0, 0)
    let size = MTLSizeMake(drawable.texture.width, drawable.texture.height,
    blitEncoder.copy(from: finalTexture,
                     sourceSlice: 0,
                     sourceLevel: 0,
                     sourceOrigin: origin,
                     sourceSize: size,
                     to: drawable.texture,
                     destinationSlice: 0,
                     destinationLevel: 0,
                     destinationOrigin: origin)


-[MTLDebugBlitCommandEncoder internalValidateCopyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toTexture:destinationSlice:destinationLevel:destinationOrigin:options:]:473: failed assertion `(sourceOrigin.x + sourceSize.width)(960) must be <= width(480).’


I suppose is necessary check if the display is retina, check the scale factor and set the sizes of output and finalTexture appropriately… I’m right?

Unfortunately, if you have an Intel GPU and not a discrete GPU, the blit doesn’t work. Are you able to check it out on an iOS device because it should work there?

I am in chapter 14 trying to use the blit and I am getting a similar error… same error except it reads `(sourceOrigin.x + sourceSize.width)(1125) must be <= width(375).’

I am using an iPhone X…

When I plug in 375 and 812 for the width and height, respectively, though, it seems to almost work. The albedo texture is being drawn but it fills only one ninth of the screen… so it is only a third as wide and a third as tall as it should be.

@escobea0 - I’m not quite sure what’s going on there. A quick fix might be to replace the size with:

 let size = MTLSizeMake(albedoTexture.width, albedoTexture.height, albedoTexture.depth)

My bad!!! When creating the albedo texture, I was using a texture descriptor that used a size of “Int(self.metalview.bounds.width)” but when I changed the texture descriptor to use a size of “Int(self.metalview.drawableSize.width)” it worked full screen as it should. However, I had to change all of the textures (albedo, normal, position, and depth) descriptors sizes to the drawableSize before I saw the full screen correction.

@escobea0 - that’s interesting, because I got the same error as you did, and I was scratching my head :smiley:

I’ve both (Intel UHD Graphics 630 & AMD Radeon Pro 5300M) so its supposed blit should work, isn’t?

@quaternionboy - my apologies. This is weird - ch 21 Bloom project is working for me now on both GPUs.

You do mean the Bloom project? What happens if you run the supplied final project?

@escobea0 - for ch 14, I think it’s our bug on initialization, and I hope this fixes it.

In init(metalView:), change:

mtkView(metalView, drawableSizeWillChange: metalView.bounds.size)


mtkView(metalView, drawableSizeWillChange: metalView.drawableSize)

The app was failing for me sometimes and not others, so I went into Edit Scheme for the macOS scheme, chose Run → Options and checked Persistent State - Launch app without state restoration to make sure that the app didn’t remember my screen size. And then the app failed every time.

I don’t know if is related but I updated OS and Xcode and now works…


1 Like