If you've played a game using Unreal Engine, or for that matter any modern game engine, you've likely encountered various forms of stuttering. One major issue is shader stuttering, as games build up that cache and it seems Epic Games have a solution for Unreal Engine.
We might finally see games eventually perform a lot better on PC.
Their blog post is highly technical but it's good to see Epic developers are working on solutions, and giving advice to developers on some best practices. In super-simple basic terms: when developers make games, the shaders used to render 3D images are written in a language that needs to be changed so your GPU can actually run it.
"Shader compilation stuttering happens when a render engine discovers that it needs to compile a new shader right before it uses it for drawing something, so everything stops while waiting for the driver to finish compilation." - Epic Games
The issue, as Epic say, is that going way back games didn't have as many shaders, and so this code translation wasn't much of an issue when running a game. But, games have grown a lot bigger and more complex resulting in all the stuttering.
"Rendering an object usually involves several shaders (e.g. a vertex shader and a pixel shader working together), as well as a number of other settings for the GPU: culling mode, blend mode, depth and stencil comparison modes etc. Together, these items describe the configuration, or state, of the GPU pipeline.
Older graphics APIs like Direct3D 11 and OpenGL allow for changing parts of the state individually and at arbitrary times, which means that the driver only sees the complete configuration when the game issues a draw request. Some settings influence the executable shader code, so there are cases when the driver can only start compiling shaders when the draw command is processed. This can take tens of milliseconds or more for a single draw command, resulting in very long frames when a shader is used for the first time—a phenomenon known to most gamers as hitching or stuttering.
Modern APIs require developers to package all the shaders and settings they will use for a draw request into a Pipeline State Object and set it as a single unit. Crucially, PSOs can be constructed at any time, so in theory engines can create everything they need sufficiently early (for example during loading), so that compilation has time to finish before rendering." - Epic Games
Making use of modern graphics APIs like Direct3D 12 and Vulkan with Pipeline State Objects (PSOs) is part of the solution. They even talk up Vulkan's Graphics Pipeline Library as a "good initiative". However, prior to Unreal Engine 5.2, they were suggesting developers run "automated level fly-throughs, and other such discovery methods" (like playing the game through) to build up a cache of the PSOs to bundle with the game (in a way, similar to Valve's shader precache system on Steam). The problem is, as they say, it has many limitations like being "resource-intensive and it must be kept up to date when content changes".
With Unreal Engine 5.2 they introduced a PSO precaching system, to enable developers to do a fair amount of this at game loading time. With GPU drivers saving these PSOs, they can be re-loaded and reduce loading time on subsequent game sessions and result in a smoother gameplay experience. This precache system is not finished though and still seeing lots of improvements:
"The precaching system has evolved a lot since its experimental introduction in 5.2 and it prevents most kinds of shader compilation stutters. However, it still has some coverage gaps and other limitations, so there are ongoing efforts to improve it further. We’re also working with hardware and software vendors to adapt drivers and graphics APIs to the way games use these systems in practice." - Epic Games
Epic ends the post with a few bits of useful advice for game developers on ensuring a smoother experience.
And thank you Alex from digital foundry LOL
Thank the PC gods that epic are taking this seriously
But are they really? This is not exactly a new problem. In fact, I'd say the problem is as old as GPUs themselves. They just ignored it until it got so bad that it was actively affecting the perception of Epic.
Personally I think the problem is that shaders are not manually written anymore. And the ones generated by these engines are so complicated and allow so many combinations of conditional compilation that compilation effort got out of hand.
Also I suppose have to ask, who's responsibility is it? Epic or the game developers, maybe abit of both? There's definitely some UE4 games that don't have shader stutter if the developers make it a priority, or at least minimise it
And even if shader stutter wasn't a thing, there's still things like traversal stutter and the constant streaming of assets that has been a hindrance too, bring back loading screens!
Pre-GPL Apex Legends on Linux? Anyone?
But are they really? This is not exactly a new problem. In fact, I'd say the problem is as old as GPUs themselves. They just ignored it until it got so bad that it was actively affecting the perception of Epic.
Personally I think the problem is that shaders are not manually written anymore. And the ones generated by these engines are so complicated and allow so many combinations of conditional compilation that compilation effort got out of hand.
Generated shaders are not as old as GPUs, but rather a new thing (last 10 years). Each those combinations (static switches) become a separate shader, so like the article says, it has become an issue because there are so many of those shaders to compile.
It isn't realistic anymore that all those shaders would be written manually, it would be waste of time.
See more from me