So the order between them is important？Or the order just depends on hardware？I have no idea which one needs to come first.
The OpenGL specification defines these as happening in the following order:
- Alpha test
- Stencil test
- Depth test
However, this order may not be strictly applied by all hardware or APIs. One example is if using an API that does not have alpha test, you would need to emulate it with discard instructions in your pixel shader. In that case it would still come first, but it would happen at a different (and earlier) pipeline stage - potentially before other operations that come between.
Another, more common, example is early depth testing. Depending on the combination of other states, modern hardware can often do a depth test before the pixel shader stage rather than after it, which can be a significant performance win. In that case the depth test comes much earlier - before the others you're interested in - but if the result would be the same as if it had run later, this is OK.