Note: I think this should be distro-agnostic, but if it is relevant, I am using Arch Linux with KDE Plasma 5 and SDDM.
I'll try to keep this brief and keep only the absolutely relevant details.
I did a clean install of Arch Linux, and I wanted to set up Bumblebee for Optimus/Prime functionality (I have an optimus laptop - Asus X550V). I encountered some issues with bumblebee, and during the following experimentation to sort it out, I realized I still don't understand how xorg and graphics drivers work (please note that I think I have a muxless solution with the hybrid graphics - at least I cannot change the active card in BIOS).
What I thought how it works:
1) If the proprietary drivers are not installed, the system will load both the intel and the nouveau drivers, use intel by default, and use nouveau when DRI_PRIME=1 is passed to a command.
2) If the proprietary drivers ARE installed, the system will not load them unless the xorg configuration is set up the way it is detailed here (https://wiki.archlinux.org/index.php/NVIDIA_Optimus - the "using nvidia" part).
3) If the proprietary drivers are installed, and the proper xorg config is set up, then the system will try to use the nvidia drivers and the nvidia GPU but will give a black screen, as the nvidia GPU is not connected to the display - two xrandr lines are necessary in either ~/.xinitrc (if using startx) or in the display managers config files to tell xorg to use offloading.
What actually happened:
To investigate my bumblebee issues I uninstalled everything related to nvidia or bumblebee, and I installed the nvidia drivers only.
To my surprise, upon boot, SDDM failed to appear. I switched to a free tty, killed sddm (sudo systemctl stop sddm), and used startx (.xinitrc was set up with exec startkde but not with the two xrandr lines). To my (once again) suprise, KDE started. My fonts appeared small/low resolution, but otherwise it was fine, and a glxinfo | grep NVIDIA confirmed that I am using nvidia.
Afterwards, I appended the two xrandr lines to /usr/share/sddm/scripts/Xsetup, and then SDDM started without problem, and I could log in to Plasma. Fonts were still screwed, but it worked and with nvidia.
Questions:
Why on Earth did my system use the Nvidia drivers, if I didn't even have a xorg.conf file at all? (xorg.conf.d was also empty, save for a keyboard file) If it uses the Nvidia drivers by default then why tell everywhere (Arch Wiki, Nvidia docs) to create a xorg.conf file for the nvidia drivers if I want to use them? More importantly, how is it that when bumblebee is installed, the system will use Intel by default? The /etc/X11 folder has the same content in both cases with no xorg.conf file. Alternatively, the same thing happens on Ubuntu when the in-built PRIME applet is used - there is a xorg.conf file used when you switch to NVIDIA, but that xorg.conf is disabled when using Intel. How come it doesn't use NVIDIA then, if it uses NVIDIA in my case, even though there is no xorg.conf file telling xorg to use NVIDIA?
Why did I managed to run Plasma on NVIDIA, without having the xrandr lines in my startx? Only SDDM had problems. Running with startx was possible. I thought the offloading should only happen if those lines are there?