How to change storage mode of MTKView's depth texture

In the Metal's profiler I get this suggestion:

"Texture:0x12880c010 "MTKView Depth"" has storage mode 'Private' but was a transient render target accessed exclusively by the GPU

Consider changing the storage mode to 'Memoryless'.

This texture is created by MTKView automatically if depthStencilPixelFormat property is set to a meaningful value. It is even possible to control the texture usage by setting depthStencilAttachmentTextureUsage property.

But I can't see how can I change the storage mode of this texture. It seems that the MTKView should somehow set the right storage mode automatically as this excerpt from the documentation suggests:

...the view automatically creates those textures for you 
and configures them as part of any render passes that the view creates.

But in my case it certainly fails to take into account that in my pipeline I don't read from this texture.

So the question is how can I change the storage mode of the depth texture of MTKView to .memoryless?

Answered by in 752403022

Hi Gadirom,

You can use property depthStencilStorageMode to .memoryless to configure your MTKView instance.

https://developer.apple.com/documentation/metalkit/mtkview/3951238-depthstencilstoragemode

This API is available since macOS Ventura and iOS 16.

Accepted Answer

Hi Gadirom,

You can use property depthStencilStorageMode to .memoryless to configure your MTKView instance.

https://developer.apple.com/documentation/metalkit/mtkview/3951238-depthstencilstoragemode

This API is available since macOS Ventura and iOS 16.

You can also just create your own depth texture, you don't have to have the MTKView create one. But then setup your own renderpass to the framebuffer + depth you create, and you then have to keep that depth in sync.

How to change storage mode of MTKView's depth texture
 
 
Q