Gpu derivatives. How it's done across 2x2 boundary?
In Vulkan the shader only looks at each 2x2 and won't attempt to look beyond the neighbourhood: http://vulkan-spec-chunked.ahcox.com/ch15s05.html

$$dPdx_{0,0}=dPdx_{1, 0} = P_{1,0}−P_{0,0}\\
dPdx_{2,0}=dPdx_{3, 0} = P_{3,0}−P_{2,0}$$

For times when a pixel would fall off the geometry the shader is invoked for the values it would have if the triangle extended a pixel further.