这是indexloc提供的服务,不要输入任何密码
Skip to content

Texture views cause unnecessary memory bandwidth use #744

@litherum

Description

@litherum

Creating a texture view in Metal requires the use of the MTLTextureUsagePixelFormatView usage on the original texture. Specifying this usage disables hardware lossless compression in modern iPhones. The reason is that the texture view can have a different pixel format than the original, and the lossless compression is specific to a particular pixel format. The result of specifying this flag when it isn’t really needed is that memory bandwidth use is unnecessarily increased.

The user-visible symptom of increased memory bandwidth use is:

  1. Worse performance, if the content is already memory bandwidth limited
  2. Worse battery life, as memory bandwidth use is a good indicator of power use by the GPU on iPhones
  3. A hotter device, which users don't like

In order to characterize this, you can run the “traditional deferred lighting” mode of this sample code with and without the MTLTextureUsagePixelFormatView flag. If you run it unmodified, an iPhone XS Max reads 40.32 MiB and writes 56.8 MiB per frame. If you then add the flag to the texture creation functions, this increases to 55.55 MiB read and 71.81 MiB written of memory per frame. Therefore, removing the flag causes a 23.7% reduction of bandwidth use on this content.

Screen Shot 2020-05-01 at 5 14 54 PM

This is a simple case. In our experience, it's not uncommon to see memory bandwidth use shrink by 50% in real content.

This is a problem in WebGPU because texture views are used in bind groups. In WebGPU, it is impossible to sample from a texture without a view.

One way to solve this would be to let GPUBindingResource be a GPUTexture. However, that alone probably wouldn’t be sufficient because there are some types of GPUTextureViews which can’t be represented by just GPUTextures, like cubemaps. Therefore, we should unify GPUTextureViewDimension and GPUTextureDimension, and add an arrayLayerCount into GPUTextureDescriptor (and possibly more).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions