How does the GPU know whether to magnify/minify?
Minification vs magnification is an extension of mipmap selection. When you calculate the desired mip level, it can come out to be less than 0 (or in general, less than the sampler's configured minimum LOD). In that case you're doing magnification of the lowest mip level. If the desired level comes out to a value greater than 0 then you're doing minification.
Mipmap selection works by calculating differences of the UV coordinates between adjacent pixels on screen (see shader derivative functions). Since the GPU is always shading pixels in 2×2 quads, it can look at the set of UVs input to the sampling operation across all those pixels. Those derivative vectors establish what the pixel footprint in texel space is, and their lengths are used to calculate which mip level to sample.
The details of how these calculations work exactly can be found in the OpenGL spec, section 8.14 &quot;Texture Minification&quot;