How much of the UI rendering could be moved to shaders?

The current Unity UI is running on the CPU, but how much of the UI could be moved into shaders?

For Example: Shadertoy has a “word” processor https://www.shadertoy.com/view/Xst3zX

Could we have a text renderer shader, a 9 slice sprite shader.

Could the entire UI be running in a set of shaders on the GPU?

Or is there a sweat spot where CPU and GPU work best together on UI.

Apologies in advance I’m not an advanced shader guru, but isn’t the UI just a sprite sheet with rules on where to and how to draw the sprites?

The value of shaders is parallelization, which doesn’t really apply to text and GUIs.
It’s like using a 400-ton mining haul-truck to deliver groceries. :slight_smile:

1 Like

Wrong analogy!

A GPU has lots of power because it has lots of small lower power processors, thousands of them in some cases. It’s like giving a job to a swarm of ants, as long as the job can be divided up into small enough pieces it will be processed very fast.

And aren’t text and UI elements lots of small pieces, with simple processing to offset their relative positions and scales.

At the moment I think Unity runs the UI mainly on the CPU (@UT correct me if this is wrong) and CPU’s are good at running complex logic and calculations at speed but they are linear or bandwidth limited. So if your UI has lots of small and simple to process elements, like text and 9 slice sprites there comes a point where through sheer number of elements a UI will slow down your game/app.

But if you transfer the smaller simpler but higher quantity jobs to the GPU then your UI will be more performant under load.

A lot of modern OS’s use hardware acceleration to speed up their UI’s, so why shouldn’t Unity?

It is actually the right analogy, the only reason GPU GUI acceleration still provides OS speed benefits is that PC-class GPUs are so blazingly fast. For example, Google hasn’t added hardware acceleration of font rasterization on most (or maybe all, I don’t really pay much attention to mobile) Android platforms yet because mobile GPUs can’t handle the workload.

Also it’s still fairly recent that the GPUs could handle vector font data. Early GPU GUI acceleration naively packed bitmapped fonts into a texture atlas and blasted those out – so scaling without artifacts was limited at best.

But I would guess the real answer is probably… do enough games use so much UI that it would be a worthwhile effort?

Well I think with the higher frame rates needed for VR even simple menu systems may benefit from this boost.