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

[Merged by Bors] - use const Vec2 in lights cluster and bounding box when possible #4602

Closed

Conversation

mockersf
Copy link
Member

Objective

  • noticed a few Vec3 and Vec2 that could be const

Solution

  • Declared them as const
  • It seems to make a tiny improvement in example many_light, but given that the change is not complex at all it could still be worth it

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Apr 26, 2022
@mockersf mockersf added A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Apr 26, 2022
@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times C-Code-Quality A section of code that is hard to understand or change labels Apr 26, 2022
@@ -485,8 +487,7 @@ fn ndc_position_to_cluster(
view_z: f32,
) -> UVec3 {
let cluster_dimensions_f32 = cluster_dimensions.as_vec3();
let frag_coord =
(ndc_p.xy() * Vec2::new(0.5, -0.5) + Vec2::splat(0.5)).clamp(Vec2::ZERO, Vec2::ONE);
let frag_coord = (ndc_p.xy() * VEC2_HALF_NEGATIVE_Y + VEC2_HALF).clamp(Vec2::ZERO, Vec2::ONE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay named constants 🎉

@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 Apr 26, 2022
)
}

const NDC_MIN: Vec3 = const_vec3!([-1.0, -1.0, f32::MIN]);
const NDC_MAX: Vec3 = const_vec3!([1.0, 1.0, f32::MAX]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a misnomer. ndc min/max depth values are 0.0 and 1.0 as anything outside will be clipped. I’ll have a closer look what this bit of code is doing to see whether the values should be changed or whether there’s a more accurate name that can be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reordered the code to not need to clamp on a Vec3, but do it on the Vec2. The clamp on z was meaningless anyway as it was between f32::MIN and f32::MAX. This seem to be even a tad bit faster to execute 🎉

@alice-i-cecile alice-i-cecile removed 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 Apr 26, 2022
@mockersf mockersf requested a review from superdump April 27, 2022 11:10
@alice-i-cecile
Copy link
Member

Removing the clamping is nice, good eye.

@mockersf mockersf changed the title use const Vec2 and Vec3 in lights cluster and bounding box when possible use const Vec2 in lights cluster and bounding box when possible Apr 27, 2022
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can merge this when you've dealt with the conflicts.

@mockersf mockersf force-pushed the lights-use-const-vec3-clamping-bounds branch from 3bfdfbb to bb4e130 Compare May 5, 2022 07:10
@mockersf
Copy link
Member Author

mockersf commented May 6, 2022

bors r+

bors bot pushed a commit that referenced this pull request May 6, 2022
# Objective

- noticed a few Vec3 and Vec2 that could be const

## Solution

- Declared them as const
- It seems to make a tiny improvement in example `many_light`, but given that the change is not complex at all it could still be worth it
@bors bors bot changed the title use const Vec2 in lights cluster and bounding box when possible [Merged by Bors] - use const Vec2 in lights cluster and bounding box when possible May 6, 2022
@bors bors bot closed this May 6, 2022
robtfm pushed a commit to robtfm/bevy that referenced this pull request May 10, 2022
…engine#4602)

- noticed a few Vec3 and Vec2 that could be const

- Declared them as const
- It seems to make a tiny improvement in example `many_light`, but given that the change is not complex at all it could still be worth it
robtfm pushed a commit to robtfm/bevy that referenced this pull request May 10, 2022
…engine#4602)

- noticed a few Vec3 and Vec2 that could be const

- Declared them as const
- It seems to make a tiny improvement in example `many_light`, but given that the change is not complex at all it could still be worth it
exjam pushed a commit to exjam/bevy that referenced this pull request May 22, 2022
…engine#4602)

# Objective

- noticed a few Vec3 and Vec2 that could be const

## Solution

- Declared them as const
- It seems to make a tiny improvement in example `many_light`, but given that the change is not complex at all it could still be worth it
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
…engine#4602)

# Objective

- noticed a few Vec3 and Vec2 that could be const

## Solution

- Declared them as const
- It seems to make a tiny improvement in example `many_light`, but given that the change is not complex at all it could still be worth it
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-Code-Quality A section of code that is hard to understand or change C-Performance A change motivated by improving speed, memory usage or compile times
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants