Cycles Light Tree: Add case for when an emitter is not selected #111292

Merged
Weizhen Huang merged 1 commits from Alaska/blender:gracefully-handle-111277-issue into main 2023-08-23 11:54:28 +02:00
Member

Discovered during an investigation into #111277
in rare situations (E.G. When normals are NaN), an emitter
won't be selected as part of light_tree_cluster_select_emitter()
and as a result of that, an emitter_index of -1 is passed to
kernel_data_fetch(light_tree_emitters, emitter_index) resulting in
an "illegal address" error on some devices.

Discovered during an investigation into #111277 in rare situations (E.G. When normals are NaN), an emitter won't be selected as part of `light_tree_cluster_select_emitter()` and as a result of that, an `emitter_index` of `-1` is passed to `kernel_data_fetch(light_tree_emitters, emitter_index)` resulting in an "illegal address" error on some devices.
Alaska added the
Module
Render & Cycles
label 2023-08-19 11:17:06 +02:00
Alaska added 1 commit 2023-08-19 11:17:18 +02:00
8b7d210301 Cycles Light Tree: Gracefully handle when an emitter is not selected
Discovered during an investigation into #111277 in rare situations,
an emitter won't be selected as part of
`light_tree_cluster_select_emitter()` and as a result of that,
an `emitter_index` of `-1` is passed to
`kernel_data_fetch(light_tree_emitters, emitter_index)` resulting in
an "illegal address" error on some devices.
Alaska requested review from Brecht Van Lommel 2023-08-19 11:17:30 +02:00
Alaska requested review from Weizhen Huang 2023-08-19 11:17:40 +02:00
Author
Member

This commit should also be backported to Blender 3.6 if it is accepted.

This commit should also be backported to Blender 3.6 if it is accepted.
Member

Is this still needed after #111294 is merged?
I am expecting light_tree_cluster_select_emitter() to pick an emitter if there is one, unless all emitters in the cluster have zero importance[0]. If any input is invalid it suggests that something else is wrong.

Is this still needed after #111294 is merged? I am expecting `light_tree_cluster_select_emitter()` to pick an emitter if there is one, unless all emitters in the cluster have zero `importance[0]`. If any input is invalid it suggests that something else is wrong.
Author
Member

I am expecting light_tree_cluster_select_emitter() to pick an emitter if there is one, unless all emitters in the cluster have zero importance[0]. If any input is invalid it suggests that something else is wrong.

You're right. An emitter should be selected under normal conditions. But under bad conditions (E.G. When the normals are NaN), an emitter won't be selected and this catch is useful as it stops an illegal address error on the GPU. (E.G. If #111294 wasn't applied, then having this catch would still allow people to render the scene shared in #111277 on a GPU, even though it has NaN normals).

Since #111294 has been merged into main (and is being back ported to 3.6), this pull request is no longer needed to fix any of the issues reported in #111277. But having this pull request merged could still be useful for situations in the future when the normals or some other value is NaN (due to something else being broken in Blender/Cycles) and a user is trying to render on the GPU, because this pull request will stop the Light Tree Sampling code from reaching a kernel_assert and reporting an "illegal address" error on GPUs in those scenes.

It comes down to how you want to handle things.

  • Decline this pull request because under normal conditions everything works. If someone tries rendering a broken mesh/shader in the future, an emitter may not be selected, GPUs will spit out errors and refuse to render, a user makes a report, and a Blender/Cycles developer fixes the underlying geometry/shader issue.

Or

  • Accept this pull request so GPUs will still render even when rendering with a broken mesh/shader, and when a user reports rendering artifacts caused by the geometry/shader, then a Blender/Cycles developers goes in and fixes the issue. (Although as a side effect of avoiding the illegal address error, users are less likely to report these sorts of bugs for scenes that look alright, but do have issues)

From the perspective of a Blender user with no knowledge of programming, I would personally like this pull request to be accepted. It means I can keep rendering with the GPU even when something else is broken (especially if the broken thing only takes up a small part of the scene, such as a single face on a chair leg having NaN normals in a render of the exterior of a building).

As a casual developer, I can see both accepting and declining as valid options based on different criteria and preferences. I'll leave the decision up to you.

> I am expecting `light_tree_cluster_select_emitter()` to pick an emitter if there is one, unless all emitters in the cluster have zero `importance[0]`. If any input is invalid it suggests that something else is wrong. You're right. An emitter should be selected under normal conditions. But under bad conditions (E.G. When the normals are NaN), an emitter won't be selected and this catch is useful as it stops an illegal address error on the GPU. (E.G. If #111294 wasn't applied, then having this catch would still allow people to render the scene shared in #111277 on a GPU, even though it has NaN normals). Since #111294 has been merged into main (and is being back ported to 3.6), this pull request is no longer needed to fix any of the issues reported in #111277. But having this pull request merged could still be useful for situations in the future when the normals or some other value is NaN (due to something else being broken in Blender/Cycles) and a user is trying to render on the GPU, because this pull request will stop the Light Tree Sampling code from reaching a kernel_assert and reporting an "illegal address" error on GPUs in those scenes. It comes down to how you want to handle things. - Decline this pull request because under normal conditions everything works. If someone tries rendering a broken mesh/shader in the future, an emitter may not be selected, GPUs will spit out errors and refuse to render, a user makes a report, and a Blender/Cycles developer fixes the underlying geometry/shader issue. Or - Accept this pull request so GPUs will still render even when rendering with a broken mesh/shader, and when a user reports rendering artifacts caused by the geometry/shader, then a Blender/Cycles developers goes in and fixes the issue. (Although as a side effect of avoiding the illegal address error, users are less likely to report these sorts of bugs for scenes that look alright, but do have issues) --- From the perspective of a Blender user with no knowledge of programming, I would personally like this pull request to be accepted. It means I can keep rendering with the GPU even when something else is broken (especially if the broken thing only takes up a small part of the scene, such as a single face on a chair leg having NaN normals in a render of the exterior of a building). As a casual developer, I can see both accepting and declining as valid options based on different criteria and preferences. I'll leave the decision up to you.
Author
Member

Extra note because I just remembered it.

It's possible a user could still create a NaN normal with something like a custom OSL script.

Extra note because I just remembered it. It's possible a user could still create a NaN normal with something like a custom OSL script.
Weizhen Huang approved these changes 2023-08-23 11:52:10 +02:00
Weizhen Huang left a comment
Member

You are right, if the normal is wrong it's still visible as an artefact, this patch is just to cover illegal address error, so I think it's fine. Thanks!

You are right, if the normal is wrong it's still visible as an artefact, this patch is just to cover illegal address error, so I think it's fine. Thanks!
Weizhen Huang merged commit 206ab6437b into main 2023-08-23 11:54:28 +02:00
Member

Hi, turns out that the selected emitter can be -1 because all the importance[1](min_importance) are zero, which is allowed at the line you changed, so the tests failed.
The problem is that total_importance[0] == 0 failed to detect the case where all the entries are NaN, a proper fix would be to use !has_importance instead (c076202e23). I also moved the selected_emitter < 0 detection a bit earlier. min_importance seems fine because there is a fmaxf(..., 0.0f) when computing it which is NaN-aware.
Again, many thanks for spotting and investigating the issue!

Hi, turns out that the selected emitter can be -1 because all the `importance[1]`(`min_importance`) are zero, which is allowed at the line you changed, so the tests failed. The problem is that `total_importance[0] == 0` failed to detect the case where all the entries are NaN, a proper fix would be to use `!has_importance` instead (c076202e23767e7c1a26b60c402118f808c3f499). I also moved the `selected_emitter < 0` detection a bit earlier. `min_importance` seems fine because there is a `fmaxf(..., 0.0f)` when computing it which is NaN-aware. Again, many thanks for spotting and investigating the issue!
Author
Member

Thanks for implementing a better fix.

Thanks for implementing a better fix.
Alaska deleted branch gracefully-handle-111277-issue 2023-08-23 22:16:21 +02:00
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
2 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#111292
No description provided.