bevy/crates/bevy_render/src
Daniel Chia 40bbbbb34e Introduce detailed_trace macro, use in TrackedRenderPass (#7639)
Profiles show that in extremely hot loops, like the draw loops in the renderer, invoking the trace! macro has noticeable overhead, even if the trace log level is not enabled.

Solve this by introduce a 'wrapper' detailed_trace macro around trace, that wraps the trace! log statement in a trivially false if statement unless a cargo feature is enabled

# Objective

- Eliminate significant overhead observed with trace-level logging in render hot loops, even when trace log level is not enabled.
- This is an alternative solution to the one proposed in #7223 

## Solution

- Introduce a wrapper around the `trace!` macro called `detailed_trace!`. This macro wraps the `trace!` macro with an if statement that is conditional on a new cargo feature, `detailed_trace`. When the feature is not enabled (the default), then the if statement is trivially false and should be optimized away at compile time.
- Convert the observed hot occurrences of trace logging in `TrackedRenderPass` with this new macro.

Testing the results of 

```
cargo run --profile stress-test --features bevy/trace_tracy --example many_cubes -- spheres
```

![image](https://user-images.githubusercontent.com/1222141/218298552-38551717-b062-4c64-afdc-a60267ac984d.png)

shows significant improvement of the `main_opaque_pass_3d`  of the renderer, a median time decrease from 6.0ms to 3.5ms. 

---

## Changelog

- For performance reasons, some detailed renderer trace logs now require the use of cargo feature `detailed_trace` in addition to setting the log level to `TRACE` in order to be shown.

## Migration Guide

- Some detailed bevy trace events now require the use of the cargo feature `detailed_trace` in addition to enabling `TRACE` level logging to view. Should you wish to see these logs, please compile your code with the bevy feature `detailed_trace`. Currently, the only logs that are affected are the renderer logs pertaining to `TrackedRenderPass` functions
2023-02-13 18:20:27 +00:00
..
camera Improve OrthographicCamera consistency and usability (#6201) 2023-02-08 21:34:33 +00:00
color Add LCH(ab) color space to bevy_render::color::Color (#7483) 2023-02-06 17:51:40 +00:00
mesh added subdivisions to shape::Plane (#7546) 2023-02-13 18:20:20 +00:00
primitives Derive Copy for Aabb (#7401) 2023-01-30 18:27:58 +00:00
render_graph Use position in code when possible (#7621) 2023-02-11 08:28:14 +00:00
render_phase Introduce detailed_trace macro, use in TrackedRenderPass (#7639) 2023-02-13 18:20:27 +00:00
render_resource Changed &mut PipelineCache to &PipelineCache (#7598) 2023-02-10 11:17:18 +00:00
renderer Wgpu 0.15 (#7356) 2023-01-29 20:27:30 +00:00
texture EnvironmentMapLight, BRDF Improvements (#7051) 2023-02-09 16:46:32 +00:00
view Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
extract_component.rs Migrate engine to Schedule v3 (#7267) 2023-02-06 02:04:50 +00:00
extract_param.rs Migrate engine to Schedule v3 (#7267) 2023-02-06 02:04:50 +00:00
extract_resource.rs Migrate engine to Schedule v3 (#7267) 2023-02-06 02:04:50 +00:00
globals.rs Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
globals.wgsl Refactor Globals and View structs into separate shaders (#7512) 2023-02-11 17:55:18 +00:00
lib.rs Cleanup render schedule (#7589) 2023-02-10 03:32:54 +00:00
pipelined_rendering.rs Rename schedule v3 to schedule (#7519) 2023-02-06 18:44:40 +00:00
render_asset.rs use better set inheritance in render systems (#7524) 2023-02-06 21:57:59 +00:00
settings.rs add OpenGL and DX11 backends (#7481) 2023-02-04 23:20:20 +00:00
spatial_bundle.rs enum Visibility component (#6320) 2022-12-25 00:39:29 +00:00