This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Mali Offline Compiler - arithmetics cycles vs texture cycles

So as its written in documentation and explained in some sources, whenever you work with mali offline compiler - you need to focus on stage which has the highest score in output from Mali first (I.e. arithmetics/load storage or texture stage)

One thing I noticed is that in pretty much any shader texture unit is never a bottleneck.
Example:

Hardware: Mali-T720 r1p1
Architecture: Midgard
Driver: r23p0-00rel0
Shader type: OpenGL ES Fragment

Main shader
===========

Work registers: 4
Uniform registers: 1
Stack spilling: false

                                A      LS       T    Bound
Total instruction cycles:   22.00    1.00    5.00        A
Shortest path cycles:       10.75    1.00    5.00        A
Longest path cycles:        10.75    1.00    5.00        A

A = Arithmetic, LS = Load/Store, T = Texture


Every texture instruction usually takes one cycle (on Midgard at least). 

So if you add another texture - you need to do something with it - blend it with other computation at least - it means arithmetics cycles will go up as well.. So as I said - texture cycles are like never higher than other columns.
So when I work on optimizing shaders - my current intuition is to still be quite agressive and try to reduce texture fetches as much as possible. And usually I don't tradeoff arithmetics and texture fetches - i.e. I don't move computation from arithmetcs to baked texture unless it's something very expensive.

Another thing: Mali offline compiler makes assumption that texture fetch is bilinear and texture has mipmaps.
We currently mostly use bilinear filtering without mipmaps on mobile. 
Rationale: when you start using mipmaps - you also need trilinear filtering, otherwise transition between mipmaps levels become visible.
Trilinear filtering means - double the cycles and also more memory throughput is needed (fetching 8 texels instead of 4 for bilinear).
On the other hand not using mipmaps means poor cache utilization which also means - more memory throughput is needed. No idea what's better in practice. I guess depends on the project/hardware. Or is there a universal answer?

And also fetching texture means latency, this latency is hidden to some degree if shader use relatively small amount but I assume it's still there.

Once I switch to another project in the company, I'll have time to do extensive tests related to the cost of textures and hopefully build some intuition.
As I am impatient and curious, I do hope other more experienced devs will share their intuition here.

So my questions:
1. Is it good strategy to aggressively optimize out texture fetches and treat them as very expensive thing (even if it's not a bottleneck by Mali offline compiler). Should I adjust score by Mali offline compiler, i.e. multiply it by 2  (so it's trilinear) or maybe I should use GPU profiler and look at some GPU metrics like memory throughput to make final decision? How do you do it in practice? 

2. Bilinear no mipmaps vs Trilinear mipmaps - what do you think is better in practice? How do you choose what to use? Does it depend on hardware maybe? We do need to support Midgard devices (we support very old devices, we're mobile development company) 
 
3. If you can share with me any links/books/resources explaining anything above which might help me - please do share them as well. I already read official mali documentation and optimization guides.

Parents
  • Hi Mikhail, 

    One thing I noticed is that in pretty much any shader texture unit is never a bottleneck.

    Mali-T720 is an older GPU, with the lowest ALU:TEX ratio of any Midgard GPU, so it's going to be more arithmetic limited than any other Midgard GPUs and any of the more modern GPU architecture families. It's really tuned for user interface rendering and casual gaming - complex 3D shaders are not going to perform as well as they would on higher-end products.

    Midgard GPUs are increasingly rare in devices - Mali-T720 was launched 10 years ago, and the last new Midgard GPU was released in 2016. 

    Is Mali-T720 really a GPU you need to target? A lot of the later devices with Midgard GPUs are Mali-T880-based which has a lot more arithmetic performance than a Mali-T720. I also suspect you'd get a substantially different result on a newer Bifrost or Valhall GPU. If you want to try out more modern entry-level devices configuration I'd suggest Mali-G51 (Bifrost architecture) or Mali-G57 (Valhall architecture).

    Is it good strategy to aggressively optimize out texture fetches and treat them as very expensive thing (even if it's not a bottleneck by Mali offline compiler). 

    GPUs are designed to be efficient at texturing, so I wouldn't optimize it out for the sake of it if it's not the bottleneck. However ...

    We currently mostly use bilinear filtering without mipmaps on mobile. Rationale: when you start using mipmaps - you also need trilinear filtering, otherwise transition between mipmaps levels become visible.

    In general I'd always recommend using mipmaps for 3D content, even with bilinear filtering. The visible filtering line on the mipmap boundary tends to be less objectionable than under-sampling shimmer. In addition, the under-sampling gives you poor locality in the texture cache. If the 4 samples for a fragment quad hit different cache lines because of missing mips causing sparse sample locations then you'll take a 4x hit on filtering performance (which is more expensive than the 2x cost of trilinear filtering), so that's definitely one to watch out for.

    For the Valhall hardware we doubled the effective texturing performance, so trilinear is definitely feasible there. For Valhall I would also test the performance of trilinear samples with 2x MAX_ANISOTROPY - this can significantly improve texture image quality at glancing viewing angles - and the performance hit is usually manageable (for a 2x MAX with trilinear sub-samples, the cost of a sample is between 1 - 4x the cost of a bilinear sample, depending on orientation)

    3. If you can share with me any links/books/resources explaining anything above which might help me - please do share them as well.

    Not aware of much beyond our optimization guides that goes in to more detail. Perhaps I need to write one =)

    Cheers, 
    Pete

Reply
  • Hi Mikhail, 

    One thing I noticed is that in pretty much any shader texture unit is never a bottleneck.

    Mali-T720 is an older GPU, with the lowest ALU:TEX ratio of any Midgard GPU, so it's going to be more arithmetic limited than any other Midgard GPUs and any of the more modern GPU architecture families. It's really tuned for user interface rendering and casual gaming - complex 3D shaders are not going to perform as well as they would on higher-end products.

    Midgard GPUs are increasingly rare in devices - Mali-T720 was launched 10 years ago, and the last new Midgard GPU was released in 2016. 

    Is Mali-T720 really a GPU you need to target? A lot of the later devices with Midgard GPUs are Mali-T880-based which has a lot more arithmetic performance than a Mali-T720. I also suspect you'd get a substantially different result on a newer Bifrost or Valhall GPU. If you want to try out more modern entry-level devices configuration I'd suggest Mali-G51 (Bifrost architecture) or Mali-G57 (Valhall architecture).

    Is it good strategy to aggressively optimize out texture fetches and treat them as very expensive thing (even if it's not a bottleneck by Mali offline compiler). 

    GPUs are designed to be efficient at texturing, so I wouldn't optimize it out for the sake of it if it's not the bottleneck. However ...

    We currently mostly use bilinear filtering without mipmaps on mobile. Rationale: when you start using mipmaps - you also need trilinear filtering, otherwise transition between mipmaps levels become visible.

    In general I'd always recommend using mipmaps for 3D content, even with bilinear filtering. The visible filtering line on the mipmap boundary tends to be less objectionable than under-sampling shimmer. In addition, the under-sampling gives you poor locality in the texture cache. If the 4 samples for a fragment quad hit different cache lines because of missing mips causing sparse sample locations then you'll take a 4x hit on filtering performance (which is more expensive than the 2x cost of trilinear filtering), so that's definitely one to watch out for.

    For the Valhall hardware we doubled the effective texturing performance, so trilinear is definitely feasible there. For Valhall I would also test the performance of trilinear samples with 2x MAX_ANISOTROPY - this can significantly improve texture image quality at glancing viewing angles - and the performance hit is usually manageable (for a 2x MAX with trilinear sub-samples, the cost of a sample is between 1 - 4x the cost of a bilinear sample, depending on orientation)

    3. If you can share with me any links/books/resources explaining anything above which might help me - please do share them as well.

    Not aware of much beyond our optimization guides that goes in to more detail. Perhaps I need to write one =)

    Cheers, 
    Pete

Children