3D mipmap generation notoriously slow because it's done on CPU

I want to share an observation, that is:
OpenGL mipmap generation for 3D textures seems to be done on the CPU and is thus very slow. Take this code as an example.

constexpr uint32_t levels = 8;
constexpr uint32_t size = 1 << levels;
uint32_t texture;
glCreateTextures(GL_TEXTURE_3D, 1, &texture);
glTextureStorage3D(texture, levels, GL_RGBA16F, size, size, size);

uint32_t timerQuery;
int32_t cpuTimeStart, cpuTimeEnd;
glGenQueries(1, &timerQuery);
glGetIntegerv(GL_TIMESTAMP, &cpuTimeStart);
glBeginQuery(GL_TIME_ELAPSED, timerQuery);

glGenerateTextureMipmap(texture);

glEndQuery(GL_TIME_ELAPSED);
glGetIntegerv(GL_TIMESTAMP, &cpuTimeEnd);

uint32_t gpuTimeElapsed;
glGetQueryObjectuiv(timerQuery, GL_QUERY_RESULT, &gpuTimeElapsed);
printf("GPU: %fms\n", gpuTimeElapsed / 1000000.0f);
printf("CPU: %fms\n", (cpuTimeEnd - cpuTimeStart) / 1000000.0f);

It prints:

GPU: 0.002048ms
CPU: 129.536446ms

This was tested on a RTX 3050 Ti Laptop + i7-11800H, driver 546.17. I’ve been told it behaves the same on a RTX 2060 Laptop. For comparison my simple compute shader mipmaping only takes around 0.43ms.

Obviously this might or might not be considered an issue.
Personally I am doing “VXGI” where you need to generate a 3D mipmap every frame and I don’t have this problem on other vendors.

Hello,
mipmaps for 3D textures are indeed created on the CPU.

1 Like

Alright then, so this is intended behaviour for now. Thanks for confirmation.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.