Repository navigation
perf: skip frustum-culled GPU-driven draws; levels of detail in the static arena and in shadows #260
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
perf: skip frustum-culled GPU-driven draws; levels of detail in the static arena and in shadows #260
Changes from all commits
1269bbd
54d0a8c
e88a68c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -508,6 +508,7 @@ impl GpuDrivenRenderer { | |
| frustum_visible_oracle, | ||
| frustum_culled_oracle, | ||
| }; | ||
| draw_stats_log(&self.stats); | ||
| if !self.enabled || self.draw_scratch.is_empty() { | ||
| return; | ||
| } | ||
|
|
@@ -996,6 +997,23 @@ impl Renderer { | |
| } | ||
| } | ||
|
|
||
| /// `BLOOM_DRAW_STATS=1`: one line every 120 frames with how many retained draws went GPU-driven and how many | ||
| /// took the compatibility path, to see where a scene's draw-call cost comes from. | ||
| fn draw_stats_log(stats: &SubmissionStats) { | ||
| static ON: OnceLock<bool> = OnceLock::new(); | ||
| static FRAME: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); | ||
| if !*ON.get_or_init(|| std::env::var("BLOOM_DRAW_STATS").is_ok_and(|v| v != "0")) { | ||
| return; | ||
| } | ||
| let f = FRAME.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| if f % 120 == 0 { | ||
| println!( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not panic when diagnostic output fails. If stdout is closed or nonblocking,
|
||
| "bloom draws: gpu-driven records {} (indirect calls {}), compatibility {}, frustum visible {} culled {}", | ||
| stats.submitted, stats.indirect_calls, stats.compatibility, stats.frustum_visible_oracle, stats.frustum_culled_oracle | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| fn gpu_driven_forced_off() -> bool { | ||
| static OFF: OnceLock<bool> = OnceLock::new(); | ||
| *OFF.get_or_init(|| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -305,8 +305,17 @@ impl Renderer { | |
| { | ||
| continue; | ||
| } | ||
| let Some(vb) = &node.gpu_vb else { continue }; | ||
| let Some(ib) = &node.gpu_ib else { continue }; | ||
| // A node drawn at a simpler level of detail casts with that level too: the full | ||
| // mesh of a distant tree went into every cascade at its close-up triangle count. | ||
| let lod = node.active_lod_geometry(); | ||
| let (vb, ib, index_count) = match lod { | ||
| Some((vb, ib, count)) => (vb, ib, count), | ||
| None => { | ||
| let Some(vb) = &node.gpu_vb else { continue }; | ||
| let Some(ib) = &node.gpu_ib else { continue }; | ||
| (vb, ib, node.gpu_index_count) | ||
| } | ||
| }; | ||
| let vb_idx = shadow_vbs.len(); | ||
| shadow_vbs.push(vb); | ||
| shadow_ibs.push(ib); | ||
|
|
@@ -320,29 +329,31 @@ impl Renderer { | |
| } | ||
| None => -1, | ||
| }; | ||
| // The arena slice of the same geometry (active level or base) batches the caster. | ||
| let gpu_shared_draw = node | ||
| .gpu_geometry | ||
| .map(|slice| (slice.first_index, slice.base_vertex)); | ||
| .active_gpu_slice() | ||
| .filter(|(_, count)| *count == index_count) | ||
| .map(|(slice, _)| (slice.first_index, slice.base_vertex)); | ||
| let world_transform = node.world_transform(); | ||
| shadow_nodes.push(ShadowDrawEntry { | ||
| vb_idx, | ||
| ib_idx: vb_idx, | ||
| index_start: 0, | ||
| index_count: node.gpu_index_count, | ||
| index_count, | ||
| base_vertex: 0, | ||
| transform: world_transform, | ||
| wmin: node.world_bounds_min, | ||
| wmax: node.world_bounds_max, | ||
| cutout_idx, | ||
| skinned: false, | ||
| sig: entry_sig(0, i as u64, node.gpu_index_count as u64, &world_transform), | ||
| sig: entry_sig(0, i as u64, index_count as u64, &world_transform), | ||
| dynamic: false, | ||
| joint_offset: 0.0, | ||
| foliage: 0.0, | ||
| gpu_opaque_shared: gpu_shared_draw.is_some() && cutout_idx < 0, | ||
| gpu_index_start: gpu_shared_draw.map_or(0, |draw| draw.0), | ||
| gpu_base_vertex: gpu_shared_draw.map_or(0, |draw| draw.1), | ||
| key: caster_id(0, i as u64, node.gpu_index_count as u64, &world_transform), | ||
| key: caster_id(0, i as u64, index_count as u64, &world_transform), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep LOD changes out of the movement key. If 65 stationary casters select LODs with different index counts in one frame, all 65 keys change. Lines 755-757 promote them to dynamic casters. The static redraw excludes them, and Lines 1109-1120 limit their dynamic draws to 64. At least one shadow disappears for that frame. Keep the movement key independent of LOD, and update the receiver lookup to match. Keep geometry changes in
|
||
| }); | ||
| } | ||
|
|
||
|
|
@@ -643,12 +654,15 @@ impl Renderer { | |
| { | ||
| continue; | ||
| } | ||
| let cast_count = node | ||
| .active_lod_geometry() | ||
| .map_or(node.gpu_index_count, |g| g.2); | ||
| if node.cast_shadow | ||
| && !prev_caster_ids.is_empty() | ||
| && !prev_caster_ids.contains(&caster_id( | ||
| 0, | ||
| i as u64, | ||
| node.gpu_index_count as u64, | ||
| cast_count as u64, | ||
| &node.world_transform(), | ||
| )) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve the frustum counts for the log.
When
draw_scratch.len()is belowGPU_DRIVEN_MIN_DRAWS, the caller resets both frustum counts to zero before this call. The log then reportsvisible 0 culled 0, even whenappend_gpu_driven_drawsreturned nonzero counts. Pass the original counts to the logger so the diagnostic reports the CPU classification.