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

Fix MSAA writeback when 3 or more cameras have the same target. #11968

Merged
merged 2 commits into from
Feb 20, 2024

Conversation

komadori
Copy link
Contributor

@komadori komadori commented Feb 19, 2024

Objective

If multiple cameras render to the same target with MSAA enabled, only the first and the last camera output will appear in the final output*. This is because each camera maintains a separate flag to track the active main texture. The first camera renders to texture A and all subsequent cameras first write-back from A and then render into texture B. Hence, camera 3 onwards will overwrite the work of the previous camera.

* This would manifest slightly differently if there were other calls to post_process_write() in a more complex setup.

The is a functional regression from Bevy 0.12.

Solution

The flag which tracks the active main texture should be shared between cameras with the same NormalizedRenderTarget. Add the Arc<AtomicUsize> to the existing per-target cache.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen labels Feb 19, 2024
@djeedai
Copy link
Contributor

djeedai commented Feb 20, 2024

Fixes #12006

@djeedai djeedai added the P-Regression Functionality that used to work but no longer does. Add a test for this! label Feb 20, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 20, 2024
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Feb 20, 2024
github-merge-queue bot pushed a commit that referenced this pull request Feb 20, 2024
# Objective

Improve `split_screen` example to use 4 cameras.

This serves as a visual regression test for #12006.

## Solution

With the fix of #11968:


![image](https://github.com/bevyengine/bevy/assets/6532395/57e9e013-7d23-429f-98ac-c6542d6b4bea)

Without (current `main`):


![image](https://github.com/bevyengine/bevy/assets/6532395/0b2a88a4-97f8-408d-8a0e-ce917efc668d)
Merged via the queue into bevyengine:main with commit dc25edd Feb 20, 2024
25 checks passed
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

Improve `split_screen` example to use 4 cameras.

This serves as a visual regression test for bevyengine#12006.

## Solution

With the fix of bevyengine#11968:


![image](https://github.com/bevyengine/bevy/assets/6532395/57e9e013-7d23-429f-98ac-c6542d6b4bea)

Without (current `main`):


![image](https://github.com/bevyengine/bevy/assets/6532395/0b2a88a4-97f8-408d-8a0e-ce917efc668d)
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
…engine#11968)

# Objective

If multiple cameras render to the same target with MSAA enabled, only
the first and the last camera output will appear in the final output*.
This is because each camera maintains a separate flag to track the
active main texture. The first camera renders to texture A and all
subsequent cameras first write-back from A and then render into texture
B. Hence, camera 3 onwards will overwrite the work of the previous
camera.

\* This would manifest slightly differently if there were other calls to
post_process_write() in a more complex setup.

The is a functional regression from Bevy 0.12.

## Solution

The flag which tracks the active main texture should be shared between
cameras with the same `NormalizedRenderTarget`. Add the
`Arc<AtomicUsize>` to the existing per-target cache.
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
# Objective

Improve `split_screen` example to use 4 cameras.

This serves as a visual regression test for bevyengine#12006.

## Solution

With the fix of bevyengine#11968:


![image](https://github.com/bevyengine/bevy/assets/6532395/57e9e013-7d23-429f-98ac-c6542d6b4bea)

Without (current `main`):


![image](https://github.com/bevyengine/bevy/assets/6532395/0b2a88a4-97f8-408d-8a0e-ce917efc668d)
msvbg pushed a commit to msvbg/bevy that referenced this pull request Feb 26, 2024
…engine#11968)

# Objective

If multiple cameras render to the same target with MSAA enabled, only
the first and the last camera output will appear in the final output*.
This is because each camera maintains a separate flag to track the
active main texture. The first camera renders to texture A and all
subsequent cameras first write-back from A and then render into texture
B. Hence, camera 3 onwards will overwrite the work of the previous
camera.

\* This would manifest slightly differently if there were other calls to
post_process_write() in a more complex setup.

The is a functional regression from Bevy 0.12.

## Solution

The flag which tracks the active main texture should be shared between
cameras with the same `NormalizedRenderTarget`. Add the
`Arc<AtomicUsize>` to the existing per-target cache.
mockersf pushed a commit that referenced this pull request Feb 27, 2024
# Objective

If multiple cameras render to the same target with MSAA enabled, only
the first and the last camera output will appear in the final output*.
This is because each camera maintains a separate flag to track the
active main texture. The first camera renders to texture A and all
subsequent cameras first write-back from A and then render into texture
B. Hence, camera 3 onwards will overwrite the work of the previous
camera.

\* This would manifest slightly differently if there were other calls to
post_process_write() in a more complex setup.

The is a functional regression from Bevy 0.12.

## Solution

The flag which tracks the active main texture should be shared between
cameras with the same `NormalizedRenderTarget`. Add the
`Arc<AtomicUsize>` to the existing per-target cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Regression Functionality that used to work but no longer does. Add a test for this! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants