Kode / Kha

Ultra-portable, high performance, open source multimedia framework.
http://kha.tech
zlib License
1.49k stars 173 forks source link

G2 multitexturing #1471

Closed RblSb closed 1 year ago

RblSb commented 1 year ago

Don't know how to fix sampler warnings

RobDangerous commented 1 year ago

Sorry but I don't intend to change the G2 implementation like this. There are a thousand options to make 2D rendering faster for different situations and for different hardware. This for example will help in a lot of situations but it will also make the GPU side of things about ten times slower which is really bad for some mobile hardware. Something like this is better kept as a sample-project than as a replacement for the standard G2 implementation.

RblSb commented 1 year ago

Do you tested it on some project and gpu? It shows big difference for my mobile gpus. Since changes are minor, can we make selection between two shaders, with singletextured by default?

RobDangerous commented 1 year ago

What's faster will depend entirely on what exactly your project is doing so just testing it on some project is pretty much pointless. We already have functionality for G2 selection - just copy it into your project and use that.

AndreiRudenko commented 1 year ago

I agree that simpler G2 is better. You can use sprite sheets to have less texture switching.

RblSb commented 1 year ago

You can provide your results from different gpus if you want to be helpful with one to ten texture switches, as realistic scenarios, or in real projects. I'm still don't know how this can be 10 times slower in practice, since i only see no difference or 2-4x fps improvements in my low to high end mobile gpus.

RobDangerous commented 1 year ago

GPUs don't really do if/else for diverging work across the same wave (aka what's running in one shader unit), they just mark lanes as inactive. And that means you will always do eight texture-samples instead of one aka eight times the work for the slowest part of the GPU. When your bottleneck is texture-switches you are CPU bound so that doesn't matter. But when you are GPU bound (which very easily happens when your project has some overdraw and you run on today's mobile devices with their super high res screens), this is super bad. You could use actual TextureArrays to avoid that (see https://github.com/Kinc-Samples/TextureArray-Kinc - it's not yet exposed in Kha) but then you need at least WebGL 2 and all textures have to have the same size so that's not an option for G2 in Kha - but it absolutely is an option for a project-specific variation of G2. Or you could use bindless textures but that's not even supported in WebGPU.