Skip to content

Commit

Permalink
fix: GetTargetGroups is called on each pipeline rebuild (#321)
Browse files Browse the repository at this point in the history
Closes: #306
  • Loading branch information
bdunderscore authored Aug 14, 2024
1 parent 7bf328f commit af1647d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- [#320] Render nodes are not correctly reused across frames
- [#321] Fix GetTargetGroup being called on every pipeline invalidation

### Changed

Expand Down
33 changes: 30 additions & 3 deletions Editor/PreviewSystem/Rendering/ProxyPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ class StageDescriptor

public readonly IRenderFilter Filter;
public readonly ImmutableList<RenderGroup> Originals;
public readonly ComputeContext Context;

public StageDescriptor(IRenderFilter filter, ComputeContext context)
public StageDescriptor(IRenderFilter filter, ComputeContext parentContext)
{
Filter = filter;

Context = new ComputeContext();
Context.Invalidates(parentContext);

var unsorted = filter.GetTargetGroups(context);
var unsorted = filter.GetTargetGroups(Context);

if (unsorted == null) unsorted = ImmutableList<RenderGroup>.Empty;
Originals = unsorted;
Expand All @@ -43,6 +47,15 @@ public StageDescriptor(IRenderFilter filter, ComputeContext context)
.OrderBy(group => group.Renderers.First().GetInstanceID())
.ToImmutableList();
}

public StageDescriptor(StageDescriptor prior, ComputeContext parentContext)
{
Filter = prior.Filter;
Context = new ComputeContext();
Context.Invalidates(parentContext);

Originals = prior.Originals;
}

#endregion

Expand Down Expand Up @@ -121,7 +134,21 @@ private async Task Build(ProxyObjectCache proxyCache, IEnumerable<IRenderFilter>
// TODO: Reuse logic

var filter = filterList[i];
var stage = new StageDescriptor(filter, context);

Profiler.BeginSample("new StageDescriptor");
var priorStageDescriptor = priorPipeline?._stages.ElementAtOrDefault(i);
StageDescriptor stage;
if (priorStageDescriptor?.Filter == filter && (priorStageDescriptor?.Context.IsInvalidated == false))
{
stage = new StageDescriptor(priorStageDescriptor, context);
}
else
{
stage = new StageDescriptor(filter, context);
}

Profiler.EndSample();

_stages.Add(stage);

var prior = priorPipeline?._stages.ElementAtOrDefault(i);
Expand Down

0 comments on commit af1647d

Please sign in to comment.