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

GLTF Shaders are using too much space in ram #586

Open
Hexer611 opened this issue Mar 13, 2023 · 7 comments
Open

GLTF Shaders are using too much space in ram #586

Hexer611 opened this issue Mar 13, 2023 · 7 comments
Labels
material material/shader features performance

Comments

@Hexer611
Copy link
Contributor

Hello, i have a project where i need to import glb files in runtime. I need all shader variants (at least that is what i think) so i included those in the build. I took a memory snapshot using Unity Memory Profiler, this snapshot belongs to a standalone build. I am not sure if this is a bug, is there anything i can do to decrease this ram usage?

image

@Phantomxm2021
Copy link

string[] tmp_ShaderNames =
            {
                "glTF-pbrMetallicRoughness",
                "glTF-pbrMetallicRoughness-Opaque",
                "glTF-pbrSpecularGlossiness", 
                "glTF-pbrSpecularGlossiness-Opaque", 
                "glTF-pbrSpecularGlossiness-Blend", 
                "glTF-unlit",
                "glTF-pbrMetallicRoughness-Blend", 
            };
            foreach (string tmp_ShaderName in tmp_ShaderNames)
            {
                var tmp_Shader = Shader.Find($"Shader Graphs/{tmp_ShaderName}");
                if (tmp_Shader)
                    Resources.UnloadAsset(tmp_Shader);
            }

Try this code this release the shaders.

@VrabelJannn
Copy link

We have the same problem on our project, and I'm afraid that releasing it is not the solution. Is there any statement from the developers? If native memory is allocated by 1.02GB, and two shaders need 0.8GB, it is more than suspicious :\

image

@azipf
Copy link

azipf commented Sep 26, 2024

Still prevalent on our iOS built with Unity6 and glTFast 6.8. If you only have 2GB available, having nearly half of it just for those shaders is too much!

@atteneder
Copy link
Owner

Thanks for providing those insights.

Without doing further investigation I suspect the problem is the sheer mass of shader variants as a result of including all of them.

Unfortunately there's no generic quick fix, but I can think of solutions:

  1. Tools that allow developers to reduce the number of included shader variants.
  2. Alternative shader that uses dynamic branching instead of keywords and thus has fewer variants (see Dynamic branch shaders/shader graphs with less variants. #703).
  3. Workflow that outsources shader variants in asset bundles/addressables and loads them on-demand.

Question regarding point 2: Would you be willing to accept a regression in render performance if this memory issue would be resolved by it?

@azipf
Copy link

azipf commented Oct 3, 2024

In our case, we would be perfectly fine with the approach in point 2. Since we're using it as a more generic GLTF viewer and don’t always know in advance what assets we’ll be working with, it’s not feasible for us to manually reduce shader variants. A solution like dynamic branching would be a great fit for our needs.

@atteneder
Copy link
Owner

Thanks for the feedback, duly noted. I'll consider it in the planning process.

In case someone jumps ahead and crafts that solution, feel free to share and make a contribution.

@atteneder
Copy link
Owner

#703 might be a solution for this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
material material/shader features performance
Projects
Status: To do
Development

No branches or pull requests

5 participants