How to toggle between DX10, DX11, DX12 and via Blueprint?

Hey guys, any idea how to toggle between Dx11, DX12 and DX10, and maybe ? via Blueprint

1 Like

To understand how to do it you need to understand how renderer is structured. UE4 for sake of code compatibility has common rendering interface Rendering Hardware Interface (RHI) for graphical libraries, similar concept to OnlineSubsystems if you seen that. Each library has itā€™s own RHI implmentation, in Windows you have D3D11 D3D12, OpenGL and Vulcan.

Now switch between them on runtime is kind of imposssible as if you look in this code:

https://github.com/EpicGames/UnrealEngine/blob/f794321ffcad597c6232bc706304c0c9b4e154b2/Engine/Source/Runtime/RHI/Private/Windows/WindowsDynamicRHI.cpp

RHI is decided on start up and thats it. But as you can see in there you can override RHI used by adding command line options on start up of your game

-d3d12, -d3d11, -d3d10, -, -opengl, -opengl3, -opengl4

So easiest way is to just create BAT files to run specific option and make user run proper one. You could technically make game run another instance of it self and then exit, so new instance of the game runs in selected RHI, but problem here is how to save this option, you would need to make some external aplication that would manage that.

Either way your options are quite limited in blueprints because by defaut (or else you get some plugin that can do so) you can exec external applications via blueprints to even do this engine restart trick. So your best bet is BATs or maybe make a game launcher which will run game with proper option, you can use anything here. Maybe submit feature request in feedback forum to have even ability to include preferable RHI options in config, then you would just need to do console command, as it really seems like a missing option to have.

Also impotent thing whatever you do, in order for RHI code modules to be included in your package game and even have a option to run game on specific one you need to mark them as targeted RHIs. To do so go to Project Settings-> Platfrom->Windows and there you will have a list of avable RHI which you want to be packaged with the game.

Also note that command line options work in editor too, you can start up editor in any RHI avable for Windows

2 Likes

Just need a confirmation. Is this still the only options also in nearly 2021 or has something changed to be able to switch the RHI more easily ingame? If restart required would be ok, thatā€™s not a problem. But the hack with the Batch file and/or needed 2nd app for configuration is not ā€œidealā€. :slight_smile:

Iā€™d like to know this too! 4 years later and almost every AAA game has this option. why isnā€™t this easier to control?

As of 4.26 you can do this with.

    FString DefaultGraphicsRHI;
    	if (GConfig->GetString(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("DefaultGraphicsRHI"), DefaultGraphicsRHI, GEngineIni))
    	{
    		FString NAME_DX11(TEXT("DefaultGraphicsRHI_DX11"));
    		FString NAME_DX12(TEXT("DefaultGraphicsRHI_DX12"));
    		GConfig->SetString(TEXT("/Script/WindowsTargetPlatform.WindowsTargetSettings"), TEXT("DefaultGraphicsRHI"), (useDx11? *NAME_DX11 : *NAME_DX12),GEngineIni);
    		GConfig->Flush(true, GEngineIni);

    	}

Exchange the ā€œNAME_DX11ā€ for the RHI your wanting if not dx11 or 12.
This obviously requires a restart to change

4 Likes

I made a plugin based what you said. You can toggle between dx11, dx12 and . Also you can get current RHI.

2 Likes

Nice, Did notice in my post i had ā€˜trueā€™ in ā€˜GConfig->Flush(true, GEngineIni);ā€™
This is a bit redundant in this situation as it just makes it read back the config after the write, can be false.

1 Like

Hello, thanks for answeringā€¦ what is the DefaultGraphicsRHI FString actually used for? What value should that FString have?

It does not change the DefaultEngine.Ini in the project, but changes the per user config in Saved\Config\Windows\Engine.ini under the same config section. You will need to restart your game for the change to happen.

DefaultGraphicsRHI specifies the rendering system to use, either RHI_DX11 ,12 or vulcan

Ahhhhhh okkkk!!!..Thank you very much

Finallyā€¦ I was able to do it, and it worksā€¦ thank you very much to all who answered!.. you were very helpful :heartbeat: :heartbeat: :heartbeat:

Kinda sorry for that, because I were reading more about it inside documentation and forget this args. Maybe more later I can update to optimize it

When I change using the okugin, after restart UE4 itā€™s affect the engine too

Ready!.. @Nathanmiguel thank you very much

Right, you can see more in my channel.

Thank you!

Set DefaultGraphicsRHI work only in Editor. In shipping Game it just not create Engine.ini when I set it.
Or I did something wrong?

1 Like