Texture Storage + Texture Views AND mipmapping

Started by
12 comments, last by Chris_F 9 years, 6 months ago

hi there,

how do you do mipmapping with texture storage?
I tried the following on AMD Catalyst 14.7 rc3, but it didn't really seem to work.


//create immutable texture storage
glGenTextures( 1, &orig_tex );
float num_mips = std::log2( float( std::max( orig_tex_width, orig_tex_height ) ) ) + 1;
glBindTexture( GL_TEXTURE_2D, orig_tex );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);

//mipmapping doesn't work
glTexStorage2D( GL_TEXTURE_2D, num_mips, GL_RGBA8, orig_tex_width, orig_tex_height );
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, im.getSize().x, im.getSize().y, GL_RGBA, GL_UNSIGNED_BYTE, im.getPixelsPtr() );

//mipmapping works, but this is not immutable storage
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, orig_tex_width, orig_tex_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel_data );

glGenerateMipmap( GL_TEXTURE_2D );

/**
.
.
.
/**/

//create texture views for the immutable storage
glGenTextures( 1, &tex );
glTextureView( tex, GL_TEXTURE_2D, orig_tex, GL_RGBA8, 0, num_mips, 0, 1 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 4);

//"texture view" workaround, as texstorage doesn't work
tex = orig_tex; //...

Best regards,

Yours3!f

Advertisement

Could you describe what you mean by


I tried the following on AMD Catalyst 14.7 rc3, but it didn't really seem to work.


Do you get a GL error ? Are mipmap not getting used ?.....saying something doesn't work gives no indication of what you are seeing/hear/ not seeing etc...

How did you verify that mipmapping is not working ?

Could you describe what you mean by


I tried the following on AMD Catalyst 14.7 rc3, but it didn't really seem to work.


Do you get a GL error ? Are mipmap not getting used ?.....saying something doesn't work gives no indication of what you are seeing/hear/ not seeing etc...

How did you verify that mipmapping is not working ?

no GL errors, I would've mentioned that.

I created two screenshots, it's quite obvious.

texstorage:
http://minus.com/i/AVUONR7EuQ0d

teximage:
http://minus.com/i/bm1HwuQt5y9rC

I've also verified this with CodeXL: with teximage the mipmaps are generated, I get all the 11 levels of mipmaps. With texstorage I get only one leve, so no mipmaps are generated.

(also I forgot to copy here one glTexSubImage, now the code above should be the same)

bump :)

I don't see any apparent issues. A while back I had an issue with glGenerateTextureMipmapEXT on AMD. In fact I had so many issues with random bugs in AMD's OpenGL drivers that I just gave up and ordered an Nvidia graphics card.

I don't see any apparent issues. A while back I had an issue with glGenerateTextureMipmapEXT on AMD. In fact I had so many issues with random bugs in AMD's OpenGL drivers that I just gave up and ordered an Nvidia graphics card.

If you zoom in on the texstorage pic, you can see that it is pixelated where the lower mip levels should come. I get the same on nvidia (344.11 driver), so I suppose I'm doing it wrong.

They both look mipmapped to me... except that in the 'texstorage' screenshot, it looks like the mipmaps have been generated using a worse algorithm than in the other screenshots.

Do you generate the mipmaps yourself, or do you just ask the GL driver to create them for you?

[edit]To answer my own question -- you're using glGenerateMipmap in your code snippet, so the driver is creating them for you biggrin.png

In that case, it just looks like that your drivers suck at creating mipmaps in some cases?

There's no special mipmap generation hardware in modern GPUs -- when you ask the driver to create them for you, you're actually just asking it to load up a built in shader program and dispatch a bunch of compute tasks, or draw a bunch of quads, filling in your mips with appropriate data.

IMHO, this is a really bad idea because every driver might use a different algorithm, landing you in situations like this... I'd prefer to just ship your own compute/fragment shaders for generating mips, or even better, to precompute them ahead of time using a very high quality algorithm and load them from disk.

I could not fathom a reason for why immutable texture vs. mutable texture would have an effect on how the mipmaps are being generated. In the case of RTT you would have no choice but to use glGenerateMipmaps. Well, maybe you could do it yourself with a compute shader if that is available to you. I wonder what the performance difference would be if any.

Also, maybe try using glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST).

They both look mipmapped to me... except that in the 'texstorage' screenshot, it looks like the mipmaps have been generated using a worse algorithm than in the other screenshots.

Do you generate the mipmaps yourself, or do you just ask the GL driver to create them for you?

[edit]To answer my own question -- you're using glGenerateMipmap in your code snippet, so the driver is creating them for you biggrin.png

In that case, it just looks like that your drivers suck at creating mipmaps in some cases?

There's no special mipmap generation hardware in modern GPUs -- when you ask the driver to create them for you, you're actually just asking it to load up a built in shader program and dispatch a bunch of compute tasks, or draw a bunch of quads, filling in your mips with appropriate data.

IMHO, this is a really bad idea because every driver might use a different algorithm, landing you in situations like this... I'd prefer to just ship your own compute/fragment shaders for generating mips, or even better, to precompute them ahead of time using a very high quality algorithm and load them from disk.

Thank you, I didn't know that, I always thought there's a fixed function unit that does this. I think I'll switch to custom mip generation :)

I could not fathom a reason for why immutable texture vs. mutable texture would have an effect on how the mipmaps are being generated. In the case of RTT you would have no choice but to use glGenerateMipmaps. Well, maybe you could do it yourself with a compute shader if that is available to you. I wonder what the performance difference would be if any.

Also, maybe try using glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST).

Compute shaders are definitely available :)

glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST) didn't work, I'll try custom mip generation now.

This topic is closed to new replies.

Advertisement