Repository navigation
Gather per-object data in parallel with chunked loops - #124
Open
JohnGreenFC wants to merge 1 commit into
Open
JohnGreenFC wants to merge 1 commit into
JohnGreenFC wants to merge 1 commit into
Conversation
…unked loops Walk shadow casters in parallel when marking outdated RT animations. Gather per-object data in parallel with a thread-safe pool allocator. Chunk the per-object parallel loops in EveSpaceScene.
| flags[i] = PER_OBJECT_DEFERRED; | ||
| continue; | ||
| } | ||
| perObjectData[i] = r->GetPerObjectData( opaqueBatches ); |
| } | ||
|
|
||
| for( const auto& shadowFrustum : spotLightFrustums ) | ||
| for( const auto& shadowFrustum : spotShadowFrustums ) |
Comment on lines
+75
to
+79
| uint8_t* p = chunk->current.fetch_add( size, std::memory_order_relaxed ); | ||
| if( p + size <= chunk->end ) | ||
| { | ||
| return p; | ||
| } |
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.

Summary
Goal: take the per-object loops in
EveSpaceScenethat still run serially on the main thread, and whose cost grows linearly with the number of objects in the scene, and spread them across worker threads. The supporting pieces make that pay off: the pool allocator used during the gather becomes safe to call from workers without a lock on the hot path, and the existing parallel loops hand out objects in blocks rather than one task per object, so task overhead no longer dominates the small amount of work done per object. The effect is less main-thread time per frame in object-heavy scenes, in both shadow modes.Three changes are included:
1. Per-object data gathered in parallel (
GetBatchesFromRenderables,TriPoolAllocator).The main-pass batch gather walked every renderable on the main thread, calling
GetPerObjectDataandHasTransparentBatchesfor each before the per-thread batch collection ran. Both calls only touch the object's own state for the common object types, so the walk now runs as aTr2ParallelForover blocks of 64 renderables.ITr2RenderablegainsSupportsParallelPerObjectData(), false by default;EveChildMeshandEveSpaceObject2override it to true. Renderables that do not opt in are flagged during the parallel pass and handled serially afterwards, and the list of objects with transparencies is rebuilt from the per-renderable flags in the original order, so batch ordering is unchanged. The per-object data is carved from aTriPoolAllocator, which was a single bump pointer with a list of spilled pools and could not be called from two threads. It is now a chain of chunks with an atomic bump pointer: an allocation does a compare-and-swap on the current chunk and only takes a mutex when the chunk is exhausted and a new one has to be added.Clearremains main-thread only. Toggle:gatherPerObjectDataParallel.2. Outdated RT animation marking in parallel (
MarkOutdatedRtAnimations).Every frame, each shadow caster is tested against the camera frustum, the sun shadow frustum, the local-light volumes and the spot-light frustums to decide whether its raytraced animation state is stale. This walk was a serial
ProcessComponentsover allIEveShadowCastercomponents. The frustums it tests against were also being constructed inside the loop; they are now built once before it, and the per-caster test runs as aTr2ParallelDoover the component list, with the serial walk kept behind the toggle. Toggle:rtOutdatedAnimationsParallel.3. Chunked parallel loops (
UpdateAsyncronous,UpdateVisibility,PushRtGeometry).These three loops were already parallel, but as
Tr2ParallelDowith one task per object. In scenes with thousands of objects the per-task scheduling cost was comparable to the work done per object. They now useTr2ParallelForover aTr2BlockedRangewith a grain of 32 objects, so each task handles a block and the task count drops by that factor.PushRtGeometryalso gets its own stats zone.Linked issue (optional)
Testing
Windows, DX12, release build. Measured in the EVE Frontier client on the QA Megastructure route (1080p, low preset) against origin/main: about -0.7 ms frame mean with raytraced shadows and -0.5 ms with cascaded shadows (single flights, ~0.5 ms noise band). Smoke test of this branch alone: full route flown with raytraced shadows, no frames over 100 ms, no crash dumps. Not built on Mac.
AI assistance
AI testing, investigation and CL explanation
Checklist