Dolphin, the GameCube and Wii emulator - Forums

Full Version: OpenGL Shader Cache support?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello there, I have been playing with Dolphin for some weeks now, it works great on my system, but I have always some random lag during gameplay, at least at first i thought it was random, but looking for it in the forum, I found it was actually the Shader loading/compiling the culprit.

My post is not to ask to fix it or something like that, I already researched a lot about it and know why this is like that, what I want to ask, is actually about the ShaderCache folder that the emulator uses to store the game compiled shaders so the stutter doens't happen again on the same place.

The problem is that I only have this folder (also .cache files being created e populated) when using Directx9 and Directx11 backends on windows, when I try OpenGL on linux or even on windows, I dont have this folder and files and so, the cache is not created, resulting in the same lag next time I open the game..

So, my question is, why there is no (or if there is, how to activate) support for ShaderCache on OpenGL? It can be done?

If it is needed, my system is an Asus g74sx, i7 2.9ghz, 8gb ram and a 560GTX.

For the emulator I have used the vannila one on windows and compiled a ICC-based binary myself for linux.

Thanks!
So.. no one know about the opengl backend?

I have been looking in the code and found the part in the directx11 where it loads (or save) the cached shaders from the HD.. and couldnt find it in the OpenGL one.. So I'm guessing it really doesn't have one.. No one knows the reason why it doesn't have? It's not possible?

Ah, I have search about the nvidia shaders disk cache http://www.phoronix.com/scan.php?page=news_item&px=MTAwNDk , I tried it and it really stores the compiled shaders when running Mario Kart on dolphin.. the problem is that it doesn't look like it loads it the next run, as the compile lag is still present.

So.. again, can someone explan to me what are the reasons to the OpenGL backend doesn't have it? I don't know too much about openGL, but would happily help code it to the backend, I just need to know the directions to research it.
The answer is simply that we (the developers) don't think there would be much benefit in having one.
Oh, ok, but this means that the OpenGL manages the shaders better than directX? I mean, it really does a big difference (at least for me) in the directX version, as it will never lag again on the same place never again after the first run, on OpenGL for the other side, it does lag every time I open the game again..
(07-28-2012, 01:45 PM)sezaru Wrote: [ -> ]Oh, ok, but this means that the OpenGL manages the shaders better than directX?

Yes, that's right.

One thing you can try is to preload all of the shaders before the game starts, so it does not lag mid game.
Nice idea, but I don't have any idea how to do it eheh, do you have any idea?

Thanks for the help so far.

PS: In this bug, they say the emulator already do it http://code.google.com/p/dolphin-emu/issues/detail?id=4350#c3 that's mean it is an option?
The report refers to OpenGL is not caching the shader to disk and therefore does not load the shader mid game.
(07-28-2012, 01:36 PM)skid Wrote: [ -> ]The answer is simply that we (the developers) don't think there would be much benefit in having one.

Uh, maybe you don't think there would be, but I definitely think it would be a useful addition - I just don't have the time to implement something like this, and Mesa drivers don't support the required GL extension anyway.

Patches welcomed Smile
Ok, I'm trying to write something that would work like the the DirectX backend.

So, in the DirectX side, the code uses a function called PD3DXCompileShader to compile the pixel shader, one of the parameters is an LPD3DXBUFFER type that will hold the compiled byte code and then it will me saved in the .cache file to future use.

For OpenGL, I found the function cgGetProgramString wish will return the compiled program, but I'm not sure this is exactly the same as the DirectX one, this is the output from the function for one shader when I loaded Mario Kart with it:
Code:
!!NVfp4.0
# cgc version 2.1.0017, build date Feb 17 2009
# command line args: -q -profile gp4fp -entry main -profileopts MaxLocalParams=224,NumInstructionSlots=16384 -O2 -q
#vendor NVIDIA Corporation
#version 2.1.0.17
#profile gp4fp
#program main
#semantic samp0 : TEXUNIT0
#var float4 ocol0 : $vout.COLOR0 : COL : 0 : 1
#var float2 uv0 : $vin.TEXCOORD0 : TEX0 : 1 : 1
#var samplerRECT samp0 : TEXUNIT0 : texunit 0 : -1 : 1
ATTRIB fragment_texcoord[] = { fragment.texcoord[0..0] };
TEMP R0, R1;
TEMP RC, HC;
OUTPUT oCol = result.color;
FRC.F R0.x, fragment.texcoord[0];
SGE.F R1.x, R0, {0.5};
TEX.F R0, fragment.texcoord[0], texture[0], RECT;
ADD.F R1.y, R0.x, -R0.z;
TRUNC.U R1.x, R1;
I2F   R0.x, R1;
MAD.F R0.x, R0, R1.y, R0.z;
ADD.F R0.x, R0, {-0.0625};
MUL.F R0.x, R0, {1.164};
ADD.F R0.z, R0.w, {-0.5}.x;
ADD.F R0.y, R0, {-0.5}.x;
MAD.F oCol.x, R0.z, {1.596}, R0;
MAD.F R0.z, -R0, {0.81300002}.x, R0.x;
MAD.F oCol.y, -R0, {0.391}.x, R0.z;
MAD.F oCol.z, R0.y, {2.0179999}.x, R0.x;
MOV.F oCol.w, {1}.x;
END
# 16 instructions, 2 R-regs

So, can someone confirm I can use this output code to store the cached shader? If not, is there an OpenGL equivalent to PD3DXCompileShader?

Thanks!

PS: i don't know if the topic still makes sense to remain in the Support area, some administrator, feel free to change it to another place.
The actual equivalent to D3DXCompileShader (note that there's not really a P in that function name btw) would be glGetProgramBinary. However, we might not be able to use that function, as someone on IRC suggested (don't really know, though).
Caching the ARB output would be better than not caching anything at all, though. But there's still room for further optimization Wink
Pages: 1 2