Issue is related to the definition of the GL_MAX_TEXTURE_SIZE.
OpenGL does not clearly defined GL_MAX_TEXTURE_SIZE exactly means. Both on AMD and NVIDIA we
have issues with huge textures that they don't get created even if they are smaller. (See D9530: Added test case to research support of texture sizes for research).
This patch will try to create the texture in a smaller size when the texture creation failed.
Future
In my opinion we should create a solution that doesn't need downscaling. For this specific case ARB_sparse_texture might help to create cleaner code, but you still have to commit the whole image. Other option is to optimize the scaling current implementation isn't optimized for performance.