Skip to content

Commit f058612

Browse files
committed
Fix profiler maker scope.
1 parent 7d4f3e5 commit f058612

File tree

2 files changed

+100
-91
lines changed

2 files changed

+100
-91
lines changed

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ public bool wantsInitialStateCheck
686686
/// ProfilerMarker for measuring the enabling/disabling of InputActions.
687687
/// </summary>
688688
static readonly ProfilerMarker k_InputActionEnableProfilerMarker = new ProfilerMarker("InputAction.Enable");
689+
static readonly ProfilerMarker k_InputActionDisableProfilerMarker = new ProfilerMarker("InputAction.Disable");
689690

690691
/// <summary>
691692
/// Construct an unnamed, free-standing action that is not part of any map or asset
@@ -905,19 +906,21 @@ public override string ToString()
905906
/// <seealso cref="enabled"/>
906907
public void Enable()
907908
{
908-
if (enabled)
909-
return;
909+
using (k_InputActionEnableProfilerMarker.Auto())
910+
{
911+
if (enabled)
912+
return;
910913

911-
k_InputActionEnableProfilerMarker.Auto();
912-
// For singleton actions, we create an internal-only InputActionMap
913-
// private to the action.
914-
var map = GetOrCreateActionMap();
914+
// For singleton actions, we create an internal-only InputActionMap
915+
// private to the action.
916+
var map = GetOrCreateActionMap();
915917

916-
// First time we're enabled, find all controls.
917-
map.ResolveBindingsIfNecessary();
918+
// First time we're enabled, find all controls.
919+
map.ResolveBindingsIfNecessary();
918920

919-
// Go live.
920-
map.m_State.EnableSingleAction(this);
921+
// Go live.
922+
map.m_State.EnableSingleAction(this);
923+
}
921924
}
922925

923926
/// <summary>
@@ -935,10 +938,13 @@ public void Enable()
935938
/// <seealso cref="Enable"/>
936939
public void Disable()
937940
{
938-
if (!enabled)
939-
return;
941+
using (k_InputActionDisableProfilerMarker.Auto())
942+
{
943+
if (!enabled)
944+
return;
940945

941-
m_ActionMap.m_State.DisableSingleAction(this);
946+
m_ActionMap.m_State.DisableSingleAction(this);
947+
}
942948
}
943949

944950
////REVIEW: is *not* cloning IDs here really the right thing to do?

Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs

Lines changed: 81 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,101 +1305,104 @@ internal bool ResolveBindingsIfNecessary()
13051305
/// </remarks>
13061306
internal void ResolveBindings()
13071307
{
1308-
k_ResolveBindingsProfilerMarker.Auto();
1309-
// Make sure that if we trigger callbacks as part of disabling and re-enabling actions,
1310-
// we don't trigger a re-resolve while we're already resolving bindings.
1311-
using (InputActionRebindingExtensions.DeferBindingResolution())
1308+
using (k_ResolveBindingsProfilerMarker.Auto())
13121309
{
1313-
// In case we have actions that are currently enabled, we temporarily retain the
1314-
// UnmanagedMemory of our InputActionState so that we can sync action states after
1315-
// we have re-resolved bindings.
1316-
var oldMemory = new InputActionState.UnmanagedMemory();
1317-
try
1310+
// Make sure that if we trigger callbacks as part of disabling and re-enabling actions,
1311+
// we don't trigger a re-resolve while we're already resolving bindings.
1312+
using (InputActionRebindingExtensions.DeferBindingResolution())
13181313
{
1319-
OneOrMore<InputActionMap, ReadOnlyArray<InputActionMap>> actionMaps;
1314+
// In case we have actions that are currently enabled, we temporarily retain the
1315+
// UnmanagedMemory of our InputActionState so that we can sync action states after
1316+
// we have re-resolved bindings.
1317+
var oldMemory = new InputActionState.UnmanagedMemory();
1318+
try
1319+
{
1320+
OneOrMore<InputActionMap, ReadOnlyArray<InputActionMap>> actionMaps;
13201321

1321-
// Start resolving.
1322-
var resolver = new InputBindingResolver();
1322+
// Start resolving.
1323+
var resolver = new InputBindingResolver();
13231324

1324-
// If we're part of an asset, we share state and thus binding resolution with
1325-
// all maps in the asset.
1326-
var needFullResolve = m_State == null;
1327-
if (m_Asset != null)
1328-
{
1329-
actionMaps = m_Asset.actionMaps;
1330-
Debug.Assert(actionMaps.Count > 0, "Asset referred to by action map does not have action maps");
1325+
// If we're part of an asset, we share state and thus binding resolution with
1326+
// all maps in the asset.
1327+
var needFullResolve = m_State == null;
1328+
if (m_Asset != null)
1329+
{
1330+
actionMaps = m_Asset.actionMaps;
1331+
Debug.Assert(actionMaps.Count > 0, "Asset referred to by action map does not have action maps");
13311332

1332-
// If there's a binding mask set on the asset, apply it.
1333-
resolver.bindingMask = m_Asset.m_BindingMask;
1333+
// If there's a binding mask set on the asset, apply it.
1334+
resolver.bindingMask = m_Asset.m_BindingMask;
13341335

1335-
foreach (var map in actionMaps)
1336+
foreach (var map in actionMaps)
1337+
{
1338+
needFullResolve |= map.bindingResolutionNeedsFullReResolve;
1339+
map.needToResolveBindings = false;
1340+
map.bindingResolutionNeedsFullReResolve = false;
1341+
map.controlsForEachActionInitialized = false;
1342+
}
1343+
}
1344+
else
13361345
{
1337-
needFullResolve |= map.bindingResolutionNeedsFullReResolve;
1338-
map.needToResolveBindings = false;
1339-
map.bindingResolutionNeedsFullReResolve = false;
1340-
map.controlsForEachActionInitialized = false;
1346+
// Standalone action map (possibly a hidden one created for a singleton action).
1347+
// Gets its own private state.
1348+
1349+
actionMaps = this;
1350+
needFullResolve |= bindingResolutionNeedsFullReResolve;
1351+
needToResolveBindings = false;
1352+
bindingResolutionNeedsFullReResolve = false;
1353+
controlsForEachActionInitialized = false;
13411354
}
1342-
}
1343-
else
1344-
{
1345-
// Standalone action map (possibly a hidden one created for a singleton action).
1346-
// Gets its own private state.
1347-
1348-
actionMaps = this;
1349-
needFullResolve |= bindingResolutionNeedsFullReResolve;
1350-
needToResolveBindings = false;
1351-
bindingResolutionNeedsFullReResolve = false;
1352-
controlsForEachActionInitialized = false;
1353-
}
13541355

1355-
// If we already have a state, re-use the arrays we have already allocated.
1356-
// NOTE: We will install the arrays on the very same InputActionState instance below. In the
1357-
// case where we didn't have to grow the arrays, we should end up with zero GC allocations
1358-
// here.
1359-
var hasEnabledActions = false;
1360-
InputControlList<InputControl> activeControls = default;
1361-
if (m_State != null)
1362-
{
1363-
// Grab a clone of the current memory. We clone because disabling all the actions
1364-
// in the map will alter the memory state and we want the state before we start
1365-
// touching it.
1366-
oldMemory = m_State.memory.Clone();
1356+
// If we already have a state, re-use the arrays we have already allocated.
1357+
// NOTE: We will install the arrays on the very same InputActionState instance below. In the
1358+
// case where we didn't have to grow the arrays, we should end up with zero GC allocations
1359+
// here.
1360+
var hasEnabledActions = false;
1361+
InputControlList<InputControl> activeControls = default;
1362+
if (m_State != null)
1363+
{
1364+
// Grab a clone of the current memory. We clone because disabling all the actions
1365+
// in the map will alter the memory state and we want the state before we start
1366+
// touching it.
1367+
oldMemory = m_State.memory.Clone();
13671368

1368-
m_State.PrepareForBindingReResolution(needFullResolve, ref activeControls, ref hasEnabledActions);
1369+
m_State.PrepareForBindingReResolution(needFullResolve, ref activeControls, ref hasEnabledActions);
13691370

1370-
// Reuse the arrays we have so that we can avoid managed memory allocations, if possible.
1371-
resolver.StartWithPreviousResolve(m_State, isFullResolve: needFullResolve);
1371+
// Reuse the arrays we have so that we can avoid managed memory allocations, if possible.
1372+
resolver.StartWithPreviousResolve(m_State, isFullResolve: needFullResolve);
13721373

1373-
// Throw away old memory.
1374-
m_State.memory.Dispose();
1375-
}
1374+
// Throw away old memory.
1375+
m_State.memory.Dispose();
1376+
}
1377+
1378+
// Resolve all maps in the asset.
1379+
foreach (var map in actionMaps)
1380+
resolver.AddActionMap(map);
13761381

1377-
// Resolve all maps in the asset.
1378-
foreach (var map in actionMaps)
1379-
resolver.AddActionMap(map);
1382+
// Install state.
1383+
if (m_State == null)
1384+
{
1385+
m_State = new InputActionState();
1386+
m_State.Initialize(resolver);
1387+
}
1388+
else
1389+
{
1390+
m_State.ClaimDataFrom(resolver);
1391+
}
13801392

1381-
// Install state.
1382-
if (m_State == null)
1383-
{
1384-
m_State = new InputActionState();
1385-
m_State.Initialize(resolver);
1386-
}
1387-
else
1388-
{
1389-
m_State.ClaimDataFrom(resolver);
1393+
if (m_Asset != null)
1394+
{
1395+
foreach (var map in actionMaps)
1396+
map.m_State = m_State;
1397+
m_Asset.m_SharedStateForAllMaps = m_State;
1398+
}
1399+
1400+
m_State.FinishBindingResolution(hasEnabledActions, oldMemory, activeControls, isFullResolve: needFullResolve);
13901401
}
1391-
if (m_Asset != null)
1402+
finally
13921403
{
1393-
foreach (var map in actionMaps)
1394-
map.m_State = m_State;
1395-
m_Asset.m_SharedStateForAllMaps = m_State;
1404+
oldMemory.Dispose();
13961405
}
1397-
1398-
m_State.FinishBindingResolution(hasEnabledActions, oldMemory, activeControls, isFullResolve: needFullResolve);
1399-
}
1400-
finally
1401-
{
1402-
oldMemory.Dispose();
14031406
}
14041407
}
14051408
}

0 commit comments

Comments
 (0)