Make indirect drawing opt-out instead of opt-in, enabling multidraw by default.#16757
Merged
alice-i-cecile merged 8 commits intobevyengine:mainfrom Dec 13, 2024
Merged
Conversation
default. This patch replaces the undocumented `NoGpuCulling` component with a new component, `NoIndirectDrawing`, effectively turning indirect drawing on by default. Indirect mode is needed for the recently-landed multidraw feature (bevyengine#16427). Since multidraw is such a win for performance, when that feature is supported the small performance tax that indirect mode incurs is virtually always worth paying. To ensure that custom drawing code such as that in the `custom_shader_instancing` example continues to function, this commit additionally makes GPU culling take the `NoFrustumCulling` component into account. This PR is an alternative to bevyengine#16670 that doesn't break the `custom_shader_instancing` example. **PR bevyengine#16755 should land first in order to avoid breaking deferred rendering, as multidraw currently breaks it**.
Contributor
|
Did you mean to add the new component to custom_shader_instancing? |
Contributor
Author
|
@JMS55 Good catch, fixed. |
bushrat011899
approved these changes
Dec 12, 2024
Contributor
bushrat011899
left a comment
There was a problem hiding this comment.
Code looks good, and it works on my i5-1240P iGPU with Windows 10 and DX12.
Contributor
Author
|
Looks like the tests all passed except for some timeouts on Android that look like test flakiness rather than actual failures. |
alice-i-cecile
approved these changes
Dec 13, 2024
ecoskey
pushed a commit
to ecoskey/bevy
that referenced
this pull request
Jan 6, 2025
…y default. (bevyengine#16757) This patch replaces the undocumented `NoGpuCulling` component with a new component, `NoIndirectDrawing`, effectively turning indirect drawing on by default. Indirect mode is needed for the recently-landed multidraw feature (bevyengine#16427). Since multidraw is such a win for performance, when that feature is supported the small performance tax that indirect mode incurs is virtually always worth paying. To ensure that custom drawing code such as that in the `custom_shader_instancing` example continues to function, this commit additionally makes GPU culling take the `NoFrustumCulling` component into account. This PR is an alternative to bevyengine#16670 that doesn't break the `custom_shader_instancing` example. **PR bevyengine#16755 should land first in order to avoid breaking deferred rendering, as multidraw currently breaks it**. ## Migration Guide * Indirect drawing (GPU culling) is now enabled by default, so the `GpuCulling` component is no longer available. To disable indirect mode, which may be useful with custom render nodes, add the new `NoIndirectDrawing` component to your camera.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 20, 2025
# Objective Fix incorrect mesh culling where objects (particularly directional shadows) were being incorrectly culled during the early preprocessing phase. The issue manifested specifically on Apple M1 GPUs but not on newer devices like the M4. The bug was in the `view_frustum_intersects_obb` function, where including the w component (plane distance) in the dot product calculations led to false positive culling results. This caused objects to be incorrectly culled before shadow casting could begin. ## Issue Details The problem of missing shadows is reproducible on Apple M1 GPUs as of this commit (bisected): ``` 00722b8 Make indirect drawing opt-out instead of opt-in, enabling multidraw by default. (#16757) ``` and as recent as this commit: ``` c818c92 Add option to animate materials in many_cubes (#17927) ``` - The frustum culling calculation incorrectly included the w component (plane distance) when transforming basis vectors - The relative radius calculation should only consider directional transformation (xyz), not positional information (w) - This caused false positive culling specifically on M1 devices likely due to different device-specific floating-point behavior - When objects were incorrectly culled, `early_instance_count` never incremented, leading to missing geometry in the shadow pass ## Testing - Tested on M1 and M4 devices to verify the fix - Verified shadows and geometry render correctly on both platforms - Confirmed the solution matches the existing Rust implementation's behavior for calculating the relative radius: https://github.com/bevyengine/bevy/blob/c818c92143e56ef3b51836af423319a5a61b15ad/crates/bevy_render/src/primitives/mod.rs#L77-L87 - The fix resolves a mathematical error in the frustum culling calculation while maintaining correct culling behavior across all platforms. --- ## Showcase `c818c9214` <img width="1284" alt="c818c9214" src="https://github.com/user-attachments/assets/fe1c7ea9-b13d-422e-b12d-f1cd74475213" /> `mate-h/frustum-cull-fix` <img width="1283" alt="frustum-cull-fix" src="https://github.com/user-attachments/assets/8a9ccb2a-64b6-4d5e-a17d-ac4798da5b51" />
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This patch replaces the undocumented
NoGpuCullingcomponent with a new component,NoIndirectDrawing, effectively turning indirect drawing on by default. Indirect mode is needed for the recently-landed multidraw feature (#16427). Since multidraw is such a win for performance, when that feature is supported the small performance tax that indirect mode incurs is virtually always worth paying.To ensure that custom drawing code such as that in the
custom_shader_instancingexample continues to function, this commit additionally makes GPU culling take theNoFrustumCullingcomponent into account.This PR is an alternative to #16670 that doesn't break the
custom_shader_instancingexample. PR #16755 should land first in order to avoid breaking deferred rendering, as multidraw currently breaks it.Migration Guide
GpuCullingcomponent is no longer available. To disable indirect mode, which may be useful with custom render nodes, add the newNoIndirectDrawingcomponent to your camera.