I know that texture caching on GPU works to optimize locality in 2D (or 3D if using 3D textures). I believe this is done using space-filling curves like Morton or Hilbert curves.
When passing an array of texture data to the GPU, though, for example using glTextureSubImage2D, the data is specified in scan-line order.
So how and when does the conversion take place? I can think of a couple of possibilites:
- The texture is laid out linearly in VRAM, and the texture unit merges transactions on different areas when loading to cache.
- The texture gets swizzled when passed to the GPU, and is stored in VRAM in Morton-coded order (or another space-filling curve).
So which is it, or is there another possibility I've missed? If it's option 2, is there an option to pass textures 'verbatim' if you already have a Morton-coded version on CPU-side? Or would you have to de-swizzle it before loading to GPU?