Skip to content

Commit

Permalink
[FIX] Fixed benchmark using overlaps for the regular actor set transf…
Browse files Browse the repository at this point in the history
…orm example (It's still faster 25% or so?)

[UPD] Changed transform bench actors to have a hierarchy of scene components and for the benchmark to tally up an average
[FIX] SetWorldTransformFastPath now accounts for multiple children correctly instead of overwriting the transform
  • Loading branch information
Megafunk committed Dec 5, 2022
1 parent 1161425 commit 0ab3438
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Config/DefaultEngine.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/MassSample/Maps/MassSampleHall.MassSampleHall
EditorStartupMap=/MassCommunitySample/MassSample/Maps/MassSampleHall.MassSampleHall
LocalMapOptions=
TransitionMap=None
bUseSplitscreen=False
Expand Down
3 changes: 0 additions & 3 deletions Content/MassSample/ISMPerInstanceData/EntityMaterial.uasset

This file was deleted.

This file was deleted.

This file was deleted.

Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UMSTransformToSceneCompTranslatorFastPath::UMSTransformToSceneCompTranslatorFast
ExecutionFlags = (int32)EProcessorExecutionFlags::All;
ExecutionOrder.ExecuteInGroup = UE::Mass::ProcessorGroupNames::UpdateWorldFromMass;
ExecutionOrder.ExecuteAfter.Add(UE::Mass::ProcessorGroupNames::Movement);

RequiredTags.Add<FMSMassTransformToSceneCompFastPathTag>();

bRequiresGameThreadExecution = true;
Expand All @@ -27,13 +27,12 @@ void UMSTransformToSceneCompTranslatorFastPath::ConfigureQueries()
}

void UMSTransformToSceneCompTranslatorFastPath::Execute(FMassEntityManager& EntityManager,
FMassExecutionContext& Context)
FMassExecutionContext& Context)
{
EntityQuery.ForEachEntityChunk(EntityManager, Context, [this](FMassExecutionContext& Context)
{
const TConstArrayView<FMassSceneComponentWrapperFragment> ComponentList = Context.GetFragmentView<
FMassSceneComponentWrapperFragment>();
const TArrayView<FTransformFragment> LocationList = Context.GetMutableFragmentView<FTransformFragment>();
const auto ComponentList = Context.GetFragmentView<FMassSceneComponentWrapperFragment>();
const auto LocationList = Context.GetMutableFragmentView<FTransformFragment>();

const int32 NumEntities = Context.GetNumEntities();

Expand Down Expand Up @@ -66,8 +65,8 @@ void UMSSceneCompTransformToMassTranslator::Execute(FMassEntityManager& EntityMa
{
EntityQuery.ForEachEntityChunk(EntityManager, Context, [this](FMassExecutionContext& Context)
{
const TConstArrayView<FMassSceneComponentWrapperFragment> ComponentList = Context.GetFragmentView<FMassSceneComponentWrapperFragment>();
const TArrayView<FTransformFragment> LocationList = Context.GetMutableFragmentView<FTransformFragment>();
const auto ComponentList = Context.GetFragmentView<FMassSceneComponentWrapperFragment>();
const auto LocationList = Context.GetMutableFragmentView<FTransformFragment>();

const int32 NumEntities = Context.GetNumEntities();
for (int32 i = 0; i < NumEntities; ++i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,44 @@ class MASSCOMMUNITYSAMPLE_API UMSTransformToSceneCompTranslatorFastPath : public


// Thanks to vblanco for this fast transform setting trick
// According to him the first two steps (to world and updatebounds) can be threaded but not the render dirty
FORCEINLINE static void SetWorldTransformFastPath(USceneComponent* InComp, FTransform InTransform)
// According to him the first two steps (comp to world and updatebounds) can be threaded but not the render dirty
FORCEINLINE static void SetWorldTransformFastPath(USceneComponent* InComp, const FTransform& InTransform)
{
// directly set transform and update bounds
InComp->SetComponentToWorld(InTransform);
InComp->UpdateBounds();

// Evil temp physics set with static cast
auto bodyinstance = static_cast<UPrimitiveComponent*>(InComp)->BodyInstance;
FChaosEngineInterface::SetGlobalPose_AssumesLocked(bodyinstance.ActorHandle, InTransform);

// dirty the render transform
InComp->MarkRenderTransformDirty();

for (auto Component : InComp->GetAttachChildren())
{
// This * transforms from local space to world space!
InTransform = Component->GetRelativeTransform() * InTransform;
FTransform CompWorldTransform = Component->GetRelativeTransform() * InTransform;

//These are to support non-relative transforms (could probably omit as this is rare?)
if(InComp->IsUsingAbsoluteLocation())

if(UNLIKELY(InComp->IsUsingAbsoluteLocation()))
{
InTransform.CopyTranslation(InTransform);
CompWorldTransform.CopyTranslation(InTransform);
}

if(InComp->IsUsingAbsoluteRotation())
if(UNLIKELY(InComp->IsUsingAbsoluteRotation()))
{
InTransform.CopyRotation(InTransform);
CompWorldTransform.CopyRotation(InTransform);
}

if(InComp->IsUsingAbsoluteScale())
if(UNLIKELY(InComp->IsUsingAbsoluteScale()))
{
InTransform.CopyScale3D(InTransform);
CompWorldTransform.CopyScale3D(InTransform);
}

// Recursive!
SetWorldTransformFastPath(Component,InTransform);
SetWorldTransformFastPath(Component,CompWorldTransform);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public MassCommunitySample(ReadOnlyTargetRules Target) : base(Target)
"Core",
"CoreUObject",
"Engine",
"InputCore"
"InputCore" ,
"Chaos"

}
);

Expand Down Expand Up @@ -59,11 +61,16 @@ public MassCommunitySample(ReadOnlyTargetRules Target) : base(Target)
"StateTreeModule",
"MassLOD",
"NavigationSystem",
//todo: maybe do thee editor only stuff on another module?
"Chaos",
"PhysicsCore",
"ChaosCore",
"ChaosSolverEngine"


}
);

//todo: maybe do thee editor only stuff on another module?

if (Target.bBuildEditor)
{
PrivateDependencyModuleNames.Add("CodeView");
Expand Down
2 changes: 2 additions & 0 deletions Source/MassSampleProject.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ public MassSampleProjectTarget(TargetInfo Target) : base(Target)
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.AddRange(new string[] { "MassSampleProject" });

IncludeOrderVersion = EngineIncludeOrderVersion.Latest;

}
}
3 changes: 3 additions & 0 deletions Source/MassSampleProjectEditor.Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ public MassSampleProjectEditorTarget(TargetInfo Target) : base(Target)
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V2;
ExtraModuleNames.Add("MassSampleProject");

IncludeOrderVersion = EngineIncludeOrderVersion.Latest;

}
}

0 comments on commit 0ab3438

Please sign in to comment.