Shader caching ?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Froyok
Prole
Posts: 27
Joined: Tue Nov 16, 2021 4:53 pm
Contact:

Shader caching ?

Post by Froyok »

Heya,

I have been evaluating Löve these last few days to see if it could fit my needs (and so far it's really promising). Looking around the API and the Github repository I didn't find an explicit answer to a question I have. I did a little search on the forum as well but I didn't find anything relevant.

What kind of shader caching does Löve actually do ?

Given the rendering backend is OpenGL, I was wondering if it could be possible to save the compiled programs to disk to reload them when launching the game the next time instead of having to recompile it again. Looking at the API, the only thing I see to create shaders is feeding strings (or text files I presume). The closest answer I found is this: https://github.com/love2d/love/issues/1240, however this seems to be focused on current launch caching, not across instances/sessions.

I plan to heavily use shaders for my projects, hence the slight concern on the loading times. It's also a curiosity question to understand better Löve itself. ;)
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Shader caching ?

Post by grump »

Froyok wrote: Sat Nov 20, 2021 8:25 am What kind of shader caching does Löve actually do ?
None. You can request it - but even if someone acknowledges your request (lol), it would take years for it to make its way into a release.

It's more of a low-tech environment that's like 8 years behind current developments, has a weird-ass release policy that nobody understands, and the project suffers from less-than-ideal communication skills of the two poor devs who are still trying to make things work. I'm waiting for basic bug fixes in a proper release for over two years now.

Part of love2d's charm is that you have to work around the limitations and make things work despite all its shortcomings and outdated tech. Like a PICO-8 for grownups.
User avatar
slime
Solid Snayke
Posts: 3131
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Shader caching ?

Post by slime »

grump wrote: Sat Nov 20, 2021 2:33 pm None.
That's not really true. LÖVE caches the parse results of vertex and pixel shader code in memory while it's running (so there is a form of caching there) - it avoids a bit of work if you have a lot of different pixel shaders which all use the same vertex shader, for example. It does not save anything to disk on its own across runs - OpenGL graphics drivers tend to do that themselves.

OpenGL itself does not really have robust explicit shader caching APIs - so drivers do it on their own. Graphics drivers also tend to compile OpenGL shaders at runtime very quickly compared to something like HLSL's offline compiler or game engines like UE4 and Unity, even without the internal driver caching.

Recent OpenGL versions do have an optional API that some but not all drivers support, to explicitly save and reuse cached shader binaries. But even if it was supported everywhere, it's not as useful as pipeline state caches in newer graphics APIs like Vulkan, because OpenGL shaders don't have all the information modern GPUs actually need to save and restore compiled pipeline state.

If you do end up having a ton of long shaders, if many of them are slight variations of each other it can be useful (in LÖVE and in other engines) to have runtime branches based on uniforms in the shader code instead. Whether shader variants or branches are better for a certain thing is very context-dependent, though.
grump wrote: Sat Nov 20, 2021 2:33 pm You can request it - but even if someone acknowledges your request (lol), it would take years for it to make its way into a release.

It's more of a low-tech environment that's like 8 years behind current developments, has a weird-ass release policy that nobody understands, and the project suffers from less-than-ideal communication skills of the two poor devs who are still trying to make things work. I'm waiting for basic bug fixes in a proper release for over two years now.
There's no need to be so antagonistic and hostile, especially when you're wrong about the topic being discussed in the original post.

LÖVE is open source and community-run, so if you have something to contribute that would help its development, that's how it moves forward as a project. There are a few reasons for the long delay between 11.x releases, some of them are related to core dependencies (e.g. problems with LuaJIT on desktop arm64, which is a platform we'd like to support in a new release) rather than just the activity of project contributors. We're also splitting time between making 11.4 a solid release and working on features for 12.0. :)
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Shader caching ?

Post by grump »

slime wrote: Sat Nov 20, 2021 5:01 pm That's not really true. LÖVE caches the parse results of vertex and pixel shader code in memory while it's running
That doesn't seem like it's an answer in the spirit of the question, but okay - I was wrong.
slime wrote: Sat Nov 20, 2021 5:01 pmThere's no need to be so antagonistic and hostile, especially when you're wrong about the topic being discussed in the original post.
I didn't really mean to be hostile, honestly. I just suck at communication just as well. I appreciate LÖVE very much, it's my favorite programming toy, even though I don't agree with the development culture surrounding it. It's just the way things seem to be to me.

I would love to contribute, but I don't feel like contributions, questions, proposals, really anything at all seem to be welcome, especially outside of Discord (and the handling of that is another issue on its own). Every attempt to get involved with improvements got shut down or fizzled out quickly. The prospect of having to wait for several years(!) to get your contributions out there is super discouraging. I'm not gonna fix bugs under these conditions.

I feel blessed if I even get an answer to basic questions. Community involvement is not good and we're all just waiting for someone from the ivory tower to speak to the dirty masses.

I still appreciate your work very much. More so in the past than what's happening today, but still. Thanks.
User avatar
Froyok
Prole
Posts: 27
Joined: Tue Nov 16, 2021 4:53 pm
Contact:

Re: Shader caching ?

Post by Froyok »

slime wrote: Sat Nov 20, 2021 5:01 pm LÖVE caches the parse results of vertex and pixel shader code in memory while it's running (so there is a form of caching there) - it avoids a bit of work if you have a lot of different pixel shaders which all use the same vertex shader, for example. It does not save anything to disk on its own across runs - OpenGL graphics drivers tend to do that themselves.
That's pretty much what I guessed from the github link. I was expecting to have the GPU drivers cache shaders for me as well.
slime wrote: Sat Nov 20, 2021 5:01 pm OpenGL itself does not really have robust explicit shader caching APIs - so drivers do it on their own. Graphics drivers also tend to compile OpenGL shaders at runtime very quickly compared to something like HLSL's offline compiler or game engines like UE4 and Unity, even without the internal driver caching.
Ha that's interesting, I didn't know about this particularity regarding OpenGL on that matter. :D
slime wrote: Sat Nov 20, 2021 5:01 pmIf you do end up having a ton of long shaders, if many of them are slight variations of each other it can be useful (in LÖVE and in other engines) to have runtime branches based on uniforms in the shader code instead. Whether shader variants or branches are better for a certain thing is very context-dependent, though.
What about a very long shader to compile (just because of the high amount of instructions). I'm wondering if an alternative would be to request a shader compilation via another thread/context (or would it be necessarily blocking) ?
I didn't see any mention of anything close to OpenGL context in the API (which i presume is fully abstracted).

Once again, it's more curiosity questions rather than real issues for now.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Shader caching ?

Post by grump »

For what it's worth - I've done some shader-heavy things and shader compilation times were never a bottleneck, or even a noticable blip. If you're really that shader dependent and it takes that much time, LÖVE might not be the best choice for you.

There is no way to do anything GL-releated in a second thread, and a second context is not possible at all.
User avatar
Froyok
Prole
Posts: 27
Joined: Tue Nov 16, 2021 4:53 pm
Contact:

Re: Shader caching ?

Post by Froyok »

Yeah, it's likely very premature in my case anyway. :)
Thank you for the additional details !
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 41 guests