1

I'm using ARB_sparse_texture extension to render volumetric effects in realtime, using very big virtual 3D textures.

And I can find no information on how it interacts with automatic mipmap generation (glGenerateMipmap()).

I correctly fill the level 0 of my texture with data and properly commit used blocks. Everything works well but I also need mipmap chain of this texture and I do not understand how to make it automatically (I found nothing about it either in the spec for ARB_sparse_texture or in the spec for ARB_sparse_texture2).

What happens if I just use glGenerateMipmap() after filling the level 0? (I tried it, and it started to stall drastically)

Should I manually compute and commit all the used blocks in coarser levels and also manually downsample the data using compute shader? (the worst variant. It's too much extra work)

Is there any simple way to do that (like glGenerateMipmap() with normal textures)?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
simpetar
  • 39
  • 2
  • 1
    @genpfault: A [comment by the asker](https://stackoverflow.com/questions/45107006#comment77197450_45107902) shows how beneficial it is to use descriptive words in links (e.g., "spec for `ARB_sparse_texture`) rather than "hide" those links in running text (e.g., behind the words "in" and "specs"). – Peter O. Jul 15 '17 at 07:38
  • @PeterO.: Fair enough, works for me! – genpfault Jul 15 '17 at 08:33

1 Answers1

1

The interaction between sparse memory and mipmap generation is rather obvious. glGenerateMipmaps reads data from the base mipmap level and writes it to all levels up to and including the max level. When using sparse memory, reads from uncommitted pages yield undefined data, and writes to uncommitted pages have no effect.

So if there are uncommitted pages in the base level, downsampling from it will yield undefined results. If there are uncommitted pages in the mipmap chain, writes to them will accomplish nothing. And since the sparse texture extensions do not alter the specified behavior of glGenerateMipmaps, then the generation process will execute its reads and writes without any idea as to which pages are committed.

Basically, if you're going to call glGenerateMipmaps, there is little point in having that texture be sparse. Unless you're fine with writing undefined values to lower mipmap levels.

I tried it, and it started to stall drastically

Well, yeah. What did you expect? glGenerateMipmaps internally either uses the rendering pipeline or a compute shader. Either way, it is effectively a rendering command, so it's not exactly a lightweight operation.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • thank you for your answer. you are not completely right about undefined data in uncommited regions. according to the updated specs (https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sparse_texture2.txt) reading from uncommited region in shaders returns zeroes, which is OK for me. But again there is not a word about glGenerateMipmap, does it behave analougous to shader-based rendering or not. For me it is not obvious. – simpetar Jul 14 '17 at 22:01
  • in short, do you mean that I should anyway manually compute and commit all the used blocks in coarser levels and then (after commitment all the blocks) can automatically downsample with glGenerateMipmap() and it will be at least correct after that (but will be slow, because it tries to downsample everything, even uncommited regions)? – simpetar Jul 14 '17 at 22:04
  • What did I expect? I had a very very very tiny hope that it behaves logically and does all dirty work for me (compute and commit only necessary blocks and downsample only existing data). It would be absolutely normal behaviour for high-level automatic mipmap generation function in case of sparsely allocated textures. But alas... – simpetar Jul 14 '17 at 22:13
  • @simpetar: "*according to the updated specs*" As far as ARB_sparse_texture is concerned, it's undefined behavior. ARB_sparse_texture2 may require the original, but the original does not require ARB_sparse_texture2. "*But again there is not a word about glGenerateMipmap*" You're really over-thinking this. Does the specification+extension say that `glGenerateMipmap` will commit pages of memory? If it doesn't say that it will happen, then it won't happen. – Nicol Bolas Jul 14 '17 at 22:55
  • in my original post i gave links to both ARB_sparse_texture and ARB_sparse_texture2 specs. (in my project i use the latter behaviour explicitly) but someone edited my question (why?) and now the link is hidden under the word specs. I find it very strange to edit someone's posts but i'm completely new to this site and do not know the rules. You are right: "if it doesn't say that it will happen, then it won't happen" but I'm a little disappointed that it doesn't say anything at all about interaction with this function. If it did, i probably wouldn't ask this question. Anyway, thanks. – simpetar Jul 14 '17 at 23:38