Performance Issue - PolySpatial Test ShaderGraphs are loaded on startup

The test shader graphs in the PolySpatial package are automatically loaded on startup. This adds 42(ish) extra materials that are never used. Each material adds a small overhead for every global shader property that is being set, so it would be nice to get rid of them.

Here’s a list of the material names, instance ids, and shaders I’m seeing in our project.

Adjustment 8796 Tests/Artistic/Adjustment
Blend 8798 Tests/Artistic/Blend
Colorspace 8800 Tests/Artistic/Colorspace
Filter 8802 Tests/Artistic/Filter
hsv 8804 Tests/Artistic/hsv
Mask 8806 Tests/Artistic/Mask
Normal 8808 Tests/Artistic/Normal
ReconstructZ 8810 Tests/Artistic/ReconstructZ
Channel 8812 Tests/Channel/Channel
AllIO 8814 Tests/GraphIO/AllIO
CustomInterpolator 8816 Tests/Input/CustomInterpolator
GeomBitangent 8818 Tests/Input/GeomBitangent
Geometry 8820 Tests/Input/Geometry
GeomNormal 8822 Tests/Input/GeomNormal
GeomPosition 8824 Tests/Input/GeomPosition
GeomTangent 8826 Tests/Input/GeomTangent
Gradient 8828 Tests/Input/Gradient
Inline 8830 Tests/Input/Inline
Keywords 8832 Tests/Input/Keywords
Lighting 8834 Tests/Input/Lighting
Matrix 8836 Tests/Input/Matrix
PBR 8838 Tests/Input/PBR
ProblematicNodes 8840 Tests/Input/ProblematicNodes
Scene 8842 Tests/Input/Scene
Texture 8844 Tests/Input/Texture
Advanced 8846 Tests/Math/Advanced
BasicAdvanced 8848 Tests/Math/BasicAdvanced
Interpolation 8850 Tests/Math/Interpolation
LerpRange 8852 Tests/Math/LerpRange
Linear 8854 Tests/Math/Linear
Matrix 8856 Tests/Math/Matrix
RoundTrig 8858 Tests/Math/RoundTrig
Trigonometry 8860 Tests/Math/Trigonometry
Vector 8862 Tests/Math/Vector
Wave 8864 Shader Graphs/Wave
Procedural 8866 Tests/Procedural
Noise 8868 Tests/Procedural/Noise
Shapes 8870 Tests/Procedural/Shapes
Textures 8872 Tests/Textures/Textures
Utility 8874 Tests/Utility
Logic 8876 Tests/Utility/Logic
TexCoord 8878 Tests/UV/TexCoord
UV 8880 Tests/UV/UV

I suspect this is a result of a call to Resources.LoadAll that will be fixed in the next version (although those shaders also shouldn’t be Resources, so we can change that to make sure this doesn’t happen again).

Do you mean on the Swift/visionOS side? In that case, there shouldn’t be any overhead for shaders that aren’t actually used (apart from the memory they occupy).

It looks like setting global shader properties has a performance impact, per material, but perhaps only if they are active in the scene?

Yes, this is unfortunately the case. Because RealityKit doesn’t itself support global shader properties, we emulate them by applying the globals separately to all materials that use them (and then updating their ModelComponents, which is necessary because materials are value types). This has a decided performance cost. We’ve requested support for shader globals from Apple, and if you can submit feedback requesting it as well, that may help convince them.

For global time, at least, we’re adding a proxy for the MaterialX time node (PolySpatial Time), so that that doesn’t need to be a global (at the expense of not being in sync with Time.time).

I understand the limitations of the system :slight_smile: Anything you can do to boost performance, like using a different time node, is much appreciated!

As a workaround we are deleting the materials after the first scene has loaded. It looks like it does give a slight performance improvement.

1 Like