Group Group Group Group Group Group Group Group Group

The upperbound of the textures in Metal

#1

Anyone know the upperbound of the textures in Metal
Refer to : setFragmentTextures:withRange:
Recently, I want to render lots of subtitles use the kernel function, steps as below:

  1. turn the each subtitle to texture? so it’s may be a lots of texture need to send the GPU
  2. in the kernel function, update the position for each texture
  3. if some texture was out of the screen, then reuse the texture or update the list of textures

So, use the - (void)setFragmentTextures:(id _Nullable const *)textures withRange:(NSRange)range is the correct way?
Thanks~

#2

You can find out the limits here:

Maximum number of entries in the texture argument table, per graphics or compute function is 31 for mobile devices and Apple TV and 128 for Macs.

I’m afraid I don’t really understand exactly what you want to do. Have you tried putting subtitles in a normal NSView or UIView and is it too slow?

1 Like
#3

I do put subtitle in a normal MTKView, for example, I turn one text to one texture and send it to shader function and then update the position x, so it will move from the right to left in mobile phone screen. But, we know that there could be 100 or 1000 subtitles display in the screen and update it’s position at the same time, so what should I do is to create 100 or 1000 textures? Or other better way to solve this?

Another way I can think of is alloc MTLBuffer and put 100 or 1000 subtitles vertices to it. Is this a good way?
Thank you for your help.

#4

I haven’t done much with text in Metal, I tend to use other frameworks for it, such as CATextLayer.

Warren Moore has written this on rendering text with signed distance fields:

But if you have your text successfully rendering into a texture, then can you create three textures each the width of the screen, and scroll them across the screen. As one texture goes off the edge of the screen, move it back to the original position and fill it with the next text. And cycle round the three textures like this?

#5

Yes, as you said, three texture can handle this situation, but generally speaking,there are more than three subtitles, may be I misunderstand your opinion, one texture contains lots of subtitles or one texture contain one subtitle, is it?
What I have done is turn one text to one texture and change the position, as you see, it’s easy…
I will read about the article to figure out the detail about render text use Metal.
It’s more like the barrage system in the live app, everyone can write words and display in the screen

#6

I just meant reuse the texture that’s off the screen for the next subtitle and keep cycling, rather than creating all the textures up front. I don’t know that this is better - I haven’t tried it.

#7

I get it ! , I will try this and other method to see which one is feasible.
Thanks for help so much.

1 Like