1
\$\begingroup\$

I have a very low res mobile game I'm working on that takes multiple rendering passes followed by a pass the composes them. Currently, I have a tex for each pass- each of which gets given to the shader for final composition.

I want to keep # of textures used low, and I'm only able to sample from so many textures per-shader anyways (esp. for mobile). So I'm thinking each render pass would instead render to a portion of a single, bigger texture. Then the composition pass would sample the same texture from multiple places. Are there any red flags that pop out regarding this strategy?

My biggest worry is it would totally thrash the texel cache (since every frame, every pixel samples the exact same texels for all the textures (each texture is a 1 to 1 mapping of the screen) = incredibly predictable/efficient caching. However, I really only have a very basic understanding of how that works so I could be totally wrong.

Also, note that my game is incredibly low resolution (128x256), so a single "giant" texture that could hold maybe 6 screens would still be pretty small at the end of the day.

Any insight is helpful! Thanks!

\$\endgroup\$
5
  • \$\begingroup\$ Have you actually tried to do it? I can assure you that the smaller your assets are and the bigger the tileset is, there will be rounding errors because texture coordinates are 0-1. On a 512x512 a 16x16 would be 0.00xxx. \$\endgroup\$
    – Krythic
    Commented Nov 20, 2016 at 11:44
  • \$\begingroup\$ @Krythic texture coordinates are usually treated as single precision floats, with 23 bits of mantissa. That means your textures could be 8 million pixels across (thousands of times larger than the max supported on most mobile GPUs) and you'd still have enough precision to address any individual pixel. So, texture coordinate accuracy is unlikely to be the limiting factor here. \$\endgroup\$
    – DMGregory
    Commented Dec 20, 2016 at 17:56
  • \$\begingroup\$ @DMGregory Ah, you again. I'm going to take pleasure in it this time. Do me a favor, write a float to a file and read it in, parsing it to a float, look at the loss of precision, and then come back and apologize to me, and delete your comment. \$\endgroup\$
    – Krythic
    Commented Dec 20, 2016 at 18:09
  • 1
    \$\begingroup\$ @Krythic Done. Please see some sample code demonstrating this here. When correctly serializing a float to a game asset file there is no loss of precision necessary, as you can easily verify for yourself by running the code at the provided link, using either text or binary serialization as you so choose. If you're experiencing a loss of precision, then you may be inadvertently truncating or rounding your values when saving them. Please also try to keep the discussion here constructive - we're all learning together, so we don't need to take corrections personally. \$\endgroup\$
    – DMGregory
    Commented Dec 20, 2016 at 19:06
  • \$\begingroup\$ @DMGregory I will look at your code shortly. \$\endgroup\$
    – Krythic
    Commented Dec 20, 2016 at 21:41

2 Answers 2

0
\$\begingroup\$

Ok- so I've tried it out. So far, so good. No noticeable performance losses yet. The one hangup I hadn't considered was that I have to manually implement what was previously taken care of by GL_CLAMP regarding texture bleeding. So I think the answer so far is "yep, this is a good thing". (Unless this is just a ticking time bomb waiting to bite me in the butt...)

\$\endgroup\$
0
0
\$\begingroup\$

The fewer buffers you use, the better the performance will be but obviously it is more work to use fewer, larger buffers instead of smaller ones (as you are finding).

\$\endgroup\$
2
  • \$\begingroup\$ by "more work", do you mean for me (the programmer)? like, it requires more complex wrangling of figuring out which data goes where? or do you men more work for the GPU? would you have any insight on my texel-cache theory? will using a single buffer sampled from multiple places ruin any GPU caching? Thanks! \$\endgroup\$
    – Phildo
    Commented Sep 14, 2016 at 14:55
  • \$\begingroup\$ I mean more work for you as a programmer. Look at the difference between drawing a GUI or text in an atlas as opposed to having it all in one texture. It has better performance but is kind of a pain. \$\endgroup\$
    – Yudrist
    Commented Sep 14, 2016 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .