Shader might kill instancing #106770

Closed
opened 2023-04-10 18:54:57 +02:00 by Rincewind · 13 comments

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 4090/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.18

Blender Version
Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: 1be25cfff18b
Worked: propably never

Short description of error
Under some cirumstance the shader of instanced object might kill the instancing which leads to increase of memory usage, which increases exponentially with the number of instances and mesh density.

Exact steps for others to reproduce the error
This issue was discovered with the addon PSA (https://www.physicaladdons.com/psa/).
To add object atmospheric fog/haze, this addon is not a using a volume, intead it is using a smart shader group, added to all materials, to create a fog effect.

However, this shader group from PSA is destorying instancing. As soon the shader node group is added, those meshes are no longer instanced when scattered via geo nodes or particles.

This leads to an exponetial memory increased based of on the number of isntances and mesh density.

Example:

No object fog applied: 1.5 GB

no fog.png

Object fog applied: 7.8 GB

object fog.png

If the amount of instanced in the geonode is increased or the subdivision of Suzanne the memory will increase dramatically.

I analzed this issue and broke it down to this node, added to the material of Suzanne:

bad boy.png

I talked to the developers of PSA and they are fine to share the PSA node setup here, so that issue can be analyzed, after they where not able themself to find a solution.

Here is version with no object fog applied:
no object fog.blend

And here with object fog:
object fog.blend

Attention
Thanks to a file upload limit, more files are in the second comment.

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 4090/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.18 **Blender Version** Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: `1be25cfff18b` Worked: propably never **Short description of error** Under some cirumstance the shader of instanced object might kill the instancing which leads to increase of memory usage, which increases exponentially with the number of instances and mesh density. **Exact steps for others to reproduce the error** This issue was discovered with the addon PSA (https://www.physicaladdons.com/psa/). To add object atmospheric fog/haze, this addon is not a using a volume, intead it is using a smart shader group, added to all materials, to create a fog effect. However, this shader group from PSA is destorying instancing. As soon the shader node group is added, those meshes are no longer instanced when scattered via geo nodes or particles. This leads to an exponetial memory increased based of on the number of isntances and mesh density. Example: No object fog applied: 1.5 GB ![no fog.png](/attachments/d2380df5-ddd0-4a38-b687-dbd59ba7a304) Object fog applied: 7.8 GB ![object fog.png](/attachments/9e2dde56-5683-4425-90d8-69740be041d4) If the amount of instanced in the geonode is increased or the subdivision of Suzanne the memory will increase dramatically. I analzed this issue and broke it down to this node, added to the material of Suzanne: ![bad boy.png](/attachments/a0247f28-763b-4260-951d-265130a78c5e) I talked to the developers of PSA and they are fine to share the PSA node setup here, so that issue can be analyzed, after they where not able themself to find a solution. Here is version with no object fog applied: [no object fog.blend](/attachments/5730f66f-522c-4c5a-91d8-bb6d53c6a942) And here with object fog: [object fog.blend](/attachments/2fb7d9ad-4955-4b83-975a-96831f3a1a4c) **Attention** Thanks to a file upload limit, more files are in the second comment.
Rincewind added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-04-10 18:54:57 +02:00
Author

Continuation. I was not able to upload more files to the first post.

I analyzed the issue myself and I was able to break down the root cause of this "memory leek" to this two node groups inside the PSA node group:

simplified.png

Here is also a blend file of the simplied version where everything is removed which is causing not the memory leak.

simplified.blend

Continuation. I was not able to upload more files to the first post. I analyzed the issue myself and I was able to break down the root cause of this "memory leek" to this two node groups inside the PSA node group: ![simplified.png](/attachments/ef355c90-1574-4223-a4f5-fc0fb101e8af) Here is also a blend file of the simplied version where everything is removed which is causing not the memory leak. [simplified.blend](/attachments/103cbb42-8fa8-4273-bf41-4c6c0df9ef55)

Can you clarify how this issue should be tested?

Can you clarify how this issue should be tested?
Richard Antalik added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2023-04-14 05:04:09 +02:00
Author

@iss

Sorry, I thought this was obvious.

It's pretty easy to test.

You can either:

Download the no object fog.blend and object fog.blend and press F12. You will see a significan difference in memory usage.

Or you can download the simplified.blend and toggle there the PSA shader node group in Suzanne to test the issue.

If you are running out of memory in the version with object fog, you can also reduce the subdivsion of Suzanne or the amount of instances in the instance emitter.
I optimized the settings of a GPU around 11GB memory.

@iss Sorry, I thought this was obvious. It's pretty easy to test. You can either: Download the `no object fog.blend` and `object fog.blend` and press F12. You will see a significan difference in memory usage. Or you can download the `simplified.blend` and toggle there the PSA shader node group in Suzanne to test the issue. If you are running out of memory in the version with object fog, you can also reduce the subdivsion of Suzanne or the amount of instances in the instance emitter. I optimized the settings of a GPU around 11GB memory.
Author

@iss

Just did a demo video based on the object fog.blend

@iss Just did a demo video based on the `object fog.blend`

Thanks for clarification, Simplified seems best for me, since I can enable/disable something to localize the issue. Unfortunately I am not able to reproduce any excessive memory usage in any of provided files.

Thanks for clarification, Simplified seems best for me, since I can enable/disable something to localize the issue. Unfortunately I am not able to reproduce any excessive memory usage in any of provided files.
Author

@iss

Indeed, I tested it in a Vanilla Blender without any addon activated and the files where totally broken.

In the past PSA was working without the addon active. It seems they changed the addon and you need now the addon to make the sky system work. However, I figured out what they changed. The settings requires no driver. I removed each single driver manually and now my demo files are working without the PSA addon.

I reuploaded the files. Please check again, should work now.

@iss Indeed, I tested it in a Vanilla Blender without any addon activated and the files where totally broken. In the past PSA was working without the addon active. It seems they changed the addon and you need now the addon to make the sky system work. However, I figured out what they changed. The settings requires no driver. I removed each single driver manually and now my demo files are working without the PSA addon. I reuploaded the files. Please check again, should work now.

I can reproduce memory usage increase now, but this is RAM, not GPU memory.

The shader is quite branched and I am not sure how cycles manages this internally, so it could be normal, will have to ask developers about this. The memory is released, so this is not really a leak.

I can reproduce memory usage increase now, but this is RAM, not GPU memory. The shader is quite branched and I am not sure how cycles manages this internally, so it could be normal, will have to ask developers about this. The memory is released, so this is not really a leak.
Author

Are you sure about this?

As far as I know, Cycles can move shaders/textures to the RAM, but geometry is always staying in the VRAM of the GPU.

I thought it's increasing the VRAM usage, because, if you increase the subdivision of Suzanne, the memory usage is also increasing which each instance.

It looks like, that the shader causes that the geometry of the instances are no longer instanced and handeled as separate objects, which are filling the VRAM.

Are you sure about this? As far as I know, Cycles can move shaders/textures to the RAM, but geometry is always staying in the VRAM of the GPU. I thought it's increasing the VRAM usage, because, if you increase the subdivision of Suzanne, the memory usage is also increasing which each instance. It looks like, that the shader causes that the geometry of the instances are no longer instanced and handeled as separate objects, which are filling the VRAM.
Member

I can replicate the increase in RAM on my CPU (my GPU is too old to run Cycles).
About 450mb without the shader, and 6.7Gb with it.

I reduced it down to just a single emission shader in the material.

I am guessing that perhaps Cycles calculates each triangle as its own light. Each Suzanne with 6 levels of subdivisions is a million triangles.

The scene without the PSA shader has one light: the sun.

The scene with the shader has 107,000,000 lights whose emissive vectors and pdfs need to be calculated.

I can replicate the increase in RAM on my CPU (my GPU is too old to run Cycles). About 450mb without the shader, and 6.7Gb with it. I reduced it down to just a single emission shader in the material. I am guessing that perhaps Cycles calculates each triangle as its own light. Each Suzanne with 6 levels of subdivisions is a million triangles. The scene without the PSA shader has one light: the sun. The scene with the shader has 107,000,000 lights whose emissive vectors and pdfs need to be calculated.
Author

Btw, the basic concept is working.

I simplieifed what PSA is doing and built a shadersystem which is changing the color of the shader by distance without any crazy memory usage:

grafik

PSA seems to usage a strange shader setup which drives Cycles crazy.

IMHO, regardless of whether this is a bug or a limitation. This should not happen. No shader should be able to drive up the memory usage that much, when it's instanced.

Btw, the basic concept is working. I simplieifed what PSA is doing and built a shadersystem which is changing the color of the shader by distance without any crazy memory usage: ![grafik](/attachments/83db3d6d-a232-4589-9d14-42d2f477b02d) PSA seems to usage a strange shader setup which drives Cycles crazy. IMHO, regardless of whether this is a bug or a limitation. This should not happen. No shader should be able to drive up the memory usage that much, when it's instanced.
Author

btw... this issue is confirmed now, right? Because status is still Needs Information from User ?

btw... this issue is confirmed now, right? Because status is still `Needs Information from User` ?
Member

Actually I just found an earlier report of this issue with a workaround.

The workaround here is to disable multiple importance sampling on the emissive material.

#90968 (comment)

The Multiple Importance checkbox was replaced with an Emission Sampling drop-down menu in 3.5

396b407c7d

Go into material settings and set Emission Sampling to None as seen in the picture below.

I will merge this report into the older one.

Please subscribe in #90968 if you want to see further updates.

If this doesn't fix your issue @Rincewind3D, let us know and we can reopen this report.

Actually I just found an earlier report of this issue with a workaround. >[The workaround here is to disable multiple importance sampling on the emissive material.](https://projects.blender.org/blender/blender/issues/90968#issuecomment-195315) https://projects.blender.org/blender/blender/issues/90968#issuecomment-195315 The Multiple Importance checkbox was replaced with an Emission Sampling drop-down menu in 3.5 https://projects.blender.org/blender/blender/commit/396b407c7d14d2ad4fb43da196b7ea0cc5891fe6 Go into material settings and set Emission Sampling to None as seen in the picture below. I will merge this report into the older one. Please subscribe in #90968 if you want to see further updates. If this doesn't fix your issue @Rincewind3D, let us know and we can reopen this report.
Blender Bot added
Status
Archived
and removed
Status
Needs Information from User
labels 2023-04-14 19:30:09 +02:00
Evan Wilson added
Status
Duplicate
and removed
Status
Archived
labels 2023-04-14 19:34:39 +02:00
Author

Nice, that fixed that issue. I will forward this solution to the PSA developers.

Thank you!

Nice, that fixed that issue. I will forward this solution to the PSA developers. Thank you!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106770
No description provided.