Directcompute, rendertextures and mipmap generation

Hi everyone,

I’m using unity pro for windows in DX11 mode. I manage to have a texture generated by a directcompute shader, but I don’t see how I can benefit from the automatic mipmap generation. I’ve set useMipMap and generateMips to true on my rendertexture, but mipmaps stays black. I update the texture only by using Dispatch on my compute shader and only the highest level of mipmaps is modified.
Is the automatic mipmap generation available only when using a render to texture with camera and everything, or did I miss something?

Thanks in advance …

I am currently having the same problem. Maybe mipmap generation only works with Graphics.blit?

Have you tried calling Texture2D.Apply() after finishing your updates to the top mip level?

Thank you very much for the hint. Indeed this seems to do the trick and it solves also the problem of refreshing the texture in the viewport of Unity, which is great!

The downside is that I have to create a second texture (Texture2D) and copy the original RenderTexture in it with a readpixels and I have two issues with that :

  • This doubles the memory usage as I have a RenderTexture and a Texture2D. I know I can get rid of the RenderTexture once its content is transferred in the Texture2D, but there are allocations that can be avoided IMHO.
  • This seems quite slow. Well this is relative, as it takes 3 to 5 seconds for a 8192x4096 texture, but mipmaps generation on GPU should be much faster than that, even with large textures.

So, this helps me as it’s working now, and thank you for that ! But I think that something is missing here, because when you’re using a rendertexture in a more classical way, things are working fine without the need of using a Texture2D AFAIK …