Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PBRGraph shader size in memory is too much - 433.2 MBs #792

Open
umeraamir-arthur opened this issue Oct 25, 2024 · 11 comments
Open

PBRGraph shader size in memory is too much - 433.2 MBs #792

umeraamir-arthur opened this issue Oct 25, 2024 · 11 comments

Comments

@umeraamir-arthur
Copy link

Hi!

I was wondering why this PBRGraph shader has this much size in memory even though if I've no GLBs in the scene. I can surely place any GLB at runtime but currently at the time of this memory capture there was no GLB present in the scene.

image

I've included both UnityGLTF shaders in my project Graphics settings because we don't have any GLB in the scene but we can place any type of GLB at runtime.

image

We don't support draco, GPU instancing or these things so I was wondering if there is any way that I could remove some parts from this shader referring to these things and my apps memory will be saved in some way?

Any suggestion would be appreciated, Thankyou
cc. @pfcDorn @hybridherbst

@hybridherbst
Copy link
Collaborator

hybridherbst commented Oct 25, 2024

Hey @umeraamir-arthur, instead of adding the shaders directly to the "Always Included" list, use the Shader Variant Collections that ship with UnityGLTF.

By adding them to "Always Included" you are including ALL potential variants, for any combination of Unity rendering features, including ones that Unity would otherwise strip.
By using the Shader Variant Collections, you still get full runtime support, but only the variants that you need (e.g. the same ones that Unity also creates for their own shaders).

So: please use the Shader Variant Collections instead :)

@umeraamir-arthur
Copy link
Author

Yes and by adding directly to "Always Included" shaders we usually have to wait for 3 hours for first build to create them in Library folder and people hates me for that :D
Can you point me to the location where Shader Variant Collections are placed in UnityGLTF. I'm not able to see them. Maybe giving an example will be amazing e.g. this is the shader variant which is used when you've GPU instancing in your GLBs. This is the shader variant when you've KTX2 in your GLBs, and this one is for Draco...... Maybe a little like that...

@hybridherbst
Copy link
Collaborator

They’re here: https://github.com/KhronosGroup/UnityGLTF/tree/main/Runtime/Shaders/VariantCollections

There included in the latest release already. There’s no extra variant sets for different features, these should „just work“ and absolutely not be as big as what you saw with „Always Include“.

@umeraamir-arthur
Copy link
Author

That's Great!

We're using URP with forward render pass. Is this the right settings that I selected?
image

@robLE83
Copy link

robLE83 commented Oct 28, 2024

Hey, yes...that's correct 👍

@umeraamir-arthur
Copy link
Author

umeraamir-arthur commented Oct 28, 2024

Thanks @robLE83 !!!
And the last question before creating a build.... the steps are

  1. Remove PBRGraph and UnlitGraph from Always Include Shaders
  2. Just create a build after updating UnityGLTFSettings

I think I don't need to change anything for Shader Variant Collections to initialize. Rest of the things are handled by UnityGLTF... right? For both shaders i.e. PBRGraph and UnlitGraph?

@umeraamir-arthur
Copy link
Author

Hey Guys that is a great update. We now have 218.6 MBs of PBRGraph shader occupied and the first build time has been reduced from 3 hours to 1 hour.
image
.
.
.
.
.
.

  • THERE IS ONE THING REMAINING AND THAT WOULD BE GREAT IF SOLVED.... IF WE'VE NO GLB IN A SCENE THEN STILL IT IS OCCUPYING 218.8MB ALTHOUGH WE DON'T WANT THIS TO BE ALWAYS THERE ON ALL THE SCENES

@umeraamir-arthur
Copy link
Author

umeraamir-arthur commented Oct 28, 2024

Any suggestions on how to remove this shader completely if there is no GLB in the scene. And as soon as we place any GLB in the scene then it can load the shader, maybe?

@pfcDorn
Copy link
Contributor

pfcDorn commented Oct 29, 2024

Yeah, that's "by design". This is to avoid loading/compiling a shader when you instantiate a model which is using such a shader. Otherwise you would first see a pink material until the shader is ready for rendering (or you would have frame drops in this moment). Not perfect for low-end platforms, but i'm not aware of any solutions :/

@umeraamir-arthur
Copy link
Author

Yes that would be an issue. I remember once I was profiling GLTFast and there shader was adaptive from scene to scene. On one scene it was ~100MB and on the other scene it was ~200MB.... Idk what were they using never explored it after then.

@hybridherbst
Copy link
Collaborator

hybridherbst commented Oct 29, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants