The theoretical knowledge i learned already is the following:
when selecting the mipmap level first the footprint of a fragment onto a texture is calculated.
Based on that the mipmap level can be calculated using the log2.
For raytraced renderers one simple implementation
that i'am aware of would be to cast a ray through every pixel
corner an intersect it with the texture plane.
Afterwards the footprint
can be calculated as the difference
of the uv coordinates times texture dimensions.
Now in rasterized renderers it seems unlikely that is is how it is implemented because when sampling from a texture we only supply the uv coordinate, which is clearly not enough. I believe the pipeline probably uses other data which is implicity stored, but i don't know what that data might be and i also don't know how it uses that data to calculate the mipmap level.
Now to the actual question:
What data does a rasterized pipeline like OpenGL store and how does it use that data to calculate the footprint or the mipmap level directly.
The "rasterized renderers" do exactly what your suggestion for ray tracing does. Only it's much faster and more robust than your suggestion because it already had to compute them.
GPUs gain their performance by doing lots of computations in parallel. So you never rasterize a single fragment. You rasterize several fragments from a single triangle at the same time. So for any fragment, you are already computing its neighbor's texture coordinates.
It's just a simple matter of peeking at the neighboring fragment shader's data and doing a bit of math.
Note that this works even at the edges of triangles. Even if a triangle only covers a single pixel/sample, GPUs will compute at least 4 fragments for it. These other 3 are called "helper invocations", and they don't get to write results to the framebuffer (or even image load/store/SSBOs). So the GPU can interpolate past the borders of a triangle to compute the neighboring texture coordinates.