Texture corruption when using mipmaps on OpenGL 4.2

Started by
7 comments, last by LorenzoGatti 1 year, 7 months ago

Hey, so I have this weird bug that only happens on my artist computer, and only when he's not attached to RenderDoc... One of the texture in the scene seem to be corrupted and this happens when we set the mipmap level to 2 or 3 (i.e. using the original texture + 1 or 2 mipmaps). If we set the mipmap level to 1 (just using the original texture) or 4 it's fine.

I've tried a few things so far and I'm running out of ideas:

  • I captured the frame with RenderDoc even though the bug is not present and analyzed it, no problem found
  • OpenGL logging and debugging is enabled but there's nothing relevant
  • The texture is 512x512px and the 2 mipmaps are at the right size (256x256 and 128x128)
  • I set the unpackAlignement to 1 when creating the texture so match what my data looks like and reset it to 4 after the texture creation
  • If I manually save the texture on disk at runtime with glGetTexImage, the 3 maps look ok

Any idea?

Corrupted texture, most if it is ok though
Advertisement

Is this a fixed texture or is it generated in live ?

Do you use ARB_debug_output ?

dancingmad said:
this happens when we set the mipmap level to 2 or 3

Explain. Also, if you let GL deduce the mipmap, does this happen ?

dancingmad said:
If we set the mipmap level to 1 (just using the original texture)

0 is the highest texture resolution, not 1. Do you use glGenerateMipmaps or do you provide your own texels for each levels ?

I would say most probably the texture data are OK since you get the correct values when reading the pixels.

I only used the default debug output system so I switch to using the ARB extension, this is what I get when I load the scene:

[OpenGL] Buffer detailed info: Buffer object 15 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 16 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 17 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 18 (bound to GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (0), GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB (1), and GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 2 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) stored in DMA CACHED memory has been updated.
[OpenGL] Buffer detailed info: Buffer object 2 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) will use DMA CACHED memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 2 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) will use DMA CACHED memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 3 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) stored in DMA CACHED memory has been updated.
[OpenGL] Buffer detailed info: Buffer object 3 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) will use DMA CACHED memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 3 (bound to GL_TEXTURE_BUFFER, usage hint is GL_DYNAMIC_READ) will use DMA CACHED memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 1 (bound to GL_UNIFORM_BUFFER (0), usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 1 (bound to GL_UNIFORM_BUFFER (0), usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 7 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 7 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 7 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 8 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 8 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 8 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 9 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 9 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 9 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 10 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 10 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 10 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 11 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 11 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 11 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 4 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 4 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 4 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 5 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 5 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 5 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Based on the usage hint and actual usage, buffer object 6 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will be configured as STREAM.
[OpenGL] Buffer detailed info: Buffer object 6 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[OpenGL] Buffer detailed info: Buffer object 6 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_DYNAMIC_DRAW) will use VIDEO memory as the source for buffer object operations.

(Since the issue only happens on someone else's computer, I'll ask him to send me his logs again to see if the ARB extension catches anything more).

I don't use glGenerateMipMaps, I do everything myself when compiling the assets of the game. If the mipmap level is 1 I just use the original texture, if it's 2 or more I generate additional mips. Those mips seem to be ok, I tried to save them on disk during the compilation.

When the texture is loaded:

  • I set the unpack alignement to 1 (my generated mips do not have padding)
  • I create, set and bind the active texture
  • I set the base level to 0
  • I set the max level to the number of mips (0 to 3)
  • I call glTexStorage2D and set the count and format
  • for each mip plus the map level 0 I call glTexSubImage2D with the right size

There's obviously something wrong with what I'm doing so I'll try to call glGenerateMipMaps and see if it changes anything. What's frustrating is that I don't have any error anywhere.

I can send the code that creates the texture but you should know that it's C# code and I have my own wrappers over C.

traditional opengl has extensions for mipmap generation, i dont know if it still exists in new profiles, but if yes, it might serve you well

https://developer.download.nvidia.com/opengl/specs/GL_SGIS_generate_mipmap.txt

I'll take a look, thank you.

Mipmapping might be a red herring. Maybe some improper write overlaps the memory occupied by level 2 and level 3 textures but spares the level 0,1 and 4 ones.

  • Does it happen without RenderDoc?
  • Are the affected textures initially correct, with some identifiable event causing the corruption? Likely, since you say that if you read them back they are OK.
  • What are the “buffer object operations” in the log? If you prevent them, does the corruption take place?

Omae Wa Mou Shindeiru

You may be right that mipmapping could be a red herring. The problem is that it's a heisenbug, it only occur sometimes where I'm not looking; right now the artist says it doesn't occur anymore on his computer but I'm sure the bug will be back in a while…

It used to happen only when RenderDoc was not attached and only with mipmapping enabled, that's all I know… If I read them back the result is ok but the texture is still corrupted visually. Maybe that's an issue in my shader, who knows.

I'll do some more research and try to prevent the buffer operation logs as you suggested, thank you for your answer.

If I read them back the result is ok but the texture is still corrupted visually. Maybe that's an issue in my shader, who knows.Maybe that's an issue in my shader, who knows.

If you read back correct textures after the defective rendering is displayed, it probably means that there is no actual corruption and you are just drawing with incorrect texture objects, coordinates, LOD levels etc. in your shader (or in its input buffers). Can you identify where the little red and blue rectangles come from? They are likely to be portions of an actual texture.

Omae Wa Mou Shindeiru

This topic is closed to new replies.

Advertisement