Dolphin, the GameCube and Wii emulator - Forums

Full Version: Stuttering in some games caused by shaders ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have noticed that a lot of games when first run and when entering some area for first time will stutter a little.
Then when same area is loaded again,there is no stuttering.
So,its quite clear that some kind of cashe is created which prevents further stuttering when replaying same areas.
I quickly discovered that if I delete context of "shadercache" folder stuttering will appear again,so its quite clear that this is somehow connected to gpu and shaders.
What I am wondering is this just normal dolphin behaviour which cant be avoided,or is there something which can be done to get rid of this stuttering ?
I have tried a lot of games,and a lot of dolphin revisions. Some games dont have this problem,but ones who do,have it on all dolphin revisions. I tried revisions from r7719 to latest dolphin 3.0-7xx.
Example of games which have this problem are Super Mario Galaxy 2,Last story,Xenoblade,Pandora Tower etc...
It seems only wii games have this problem...didnt encounter it in any gc games.
I tried a lot of different settings,nothing seems to fix it.
Tried async build didnt help.
This is my hardware
i5 2400,geforce 460 1gb gtx,8 gb ddr3,newest wd blue 500 gb 7200 rpm hdd,I tested it with hdd tune it has read speed of about 100mb/s.
Windows 7 x64.

Whats most curious about this is that this kinda of problem should be related to hdd speed,but its not,since "shadercache" folder is also on the same disc where game is.
So if this was hdd problem,then shadercache shouldn't help,but it does.
And no,context of it is not in my ram,I tried restarting computer and games still wouldn't stuttter untill I deleted context of cache folder.
So I guess this is some problem related to gpu/shaders...
Nobody knows anything about this ?
Can anybody atleast explain me what exactly is "shadercache" so I can figure out whats going on Smile
Easiest example of this is very start of last story,before even main menu appears,it will stutter after game tells you "press a" and you press it.
Also SMG 2 will stutter at the very begining,before game tells you "press a and b".
OFC games stutter during gameplay too,or I wouldnt even bother to mention it Smile
Yo. Shaders can be regarded as programs which are being executed on the GPU. Just like with "normal" C++ source code, we need to compile the shader source to a bytecode which can be run by the GPU. This shader compilation takes some time, but it's not much of a problem for normal applications because those know in advance what shaders they're going to use for rendering and thus can precompile them on startup.

Dolphin uses shaders to emulate the GC/Wii's GPU render output. There are lots of different possible pipeline configurations though and we need a separate shader for each of them. Thus, whenever the emulated application changes the render pipeline configuration, we'd need to compile a new shader. That takes time and thus causes the stuttering you're seeing.

It's not quite that bad because we have that shadercache, though. Whenever the emulated application changes to a render pipeline configuration that has been used before, we can just re-use the compiled shader from before. That reduces stuttering a lot Wink

About the remaining stuttering: We can't do much about that. Telling shader compilers to waste less time on optimizing shaders might be an option but it would slow down general emulation speed on the other hand.
Just to be sure: the shaders present on the ShaderCache are all loaded when booting the game or only when the game request it? I'm asking because when I play any game on Dolphin, some effects will cause an "one-time stuttering" when they are displayed first time, and later the game run fine (example: when I boot Zelda Skyward Sword, the first sword strike I do after booting the game will always stutter, and after the first strike, all stuttering go away)... So what I'm asking is if there is some way of loading all Shaders that have been cached when you boot the game to prevent future "one-time" stutters caused by the loading delay of that shaders
I guess I'll answer this indirectly. The shader cache is actually two-fold: Generally, compiled shaders are cached in RAM so that they can easily be re-used later. However, you'd still get a one-time lag on the first usage of a specific pipeline configuration whenever you restart the game. Thus, the D3D backends additionally save compiled shaders to disk (this is what you see in the ShaderCache folder) and reload them from that folder whenever you start the game again.

So yes, shaders are loaded on game startup unless you're using the OpenGL backend. Fwiw, note that "first time stutterings" might also be caused by things like HDD accesses, etc, which the game itself is lateron caching in the emulated RAM.
(08-30-2012, 09:11 AM)neobrain Wrote: [ -> ]So yes, shaders are loaded on game startup unless you're using the OpenGL backend. Fwiw, note that "first time stutterings" might also be caused by things like HDD accesses, etc, which the game itself is lateron caching in the emulated RAM.

Or the host PC OS is caching in RAM.
Ok,thanks for clarifying what I suspected,it's just how it is and nothing can be done atleast atm.
But,I do wonder why these shaders cant be compiled before game is started ? Even if it would take time and/or disc space,I am sure some people would find the option useful.
Or is it just not posible ?
Because there are like billions of billions of possibilities. Precompiling would be completely useless here.
(08-30-2012, 12:33 PM)delroth Wrote: [ -> ]Because there are like billions of billions of possibilities. Precompiling would be completely useless here.

Ok,I might be asking stupid questions,but that how we learn right ?
What I meant is compiling shaders for each game.
Can't dolphin go through game code and compile only shaders that specific game will use,and put it in shadercache folder ?
Basically same thing beeing done now,but instead compiling shaders exact moment game use it,compile it before ?
IF each shader is a file in shadercache folder,there are not billion of them...only a few files per game as far as I can see.
This would take time,maybe even couple of hours I dont know,but dolphin could be put in background while user is not playing and doing something alse to compile shaders for each game user has.

OR,do game NEED to be emulated and played in realtime to "discover" what shaders game needs ?

Again,sorry for stupid questions Smile
Yeah, we need to "discover" in realtime what shaders a game needs. We could create some kind of list of shaders which are used by each game and make dolphin precompile those shaders before running the game, but we aren't really interested in that. Also, it would introduce other kinds of problems, like noobs wondering why their game needs like 3 minutes to start.
Pages: 1 2