Skip to content

Core SRP CPU Performance Improvements #7657

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void OnEnable()
{
var prefab = list.serializedProperty.GetArrayElementAtIndex(list.index).FindPropertyRelative("prefab").objectReferenceValue as GameObject;
if (prefab)
EditorGUIUtility.PingObject(prefab.gameObject);
EditorGUIUtility.PingObject(prefab);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void DrawHull(bool filled)
if (filled)
{
material.SetPass(0);
Matrix4x4 drawMatrix = Matrix4x4.TRS((Vector3)Handles.matrix.GetColumn(3), Quaternion.identity, Vector3.one * radius * 2f);
Matrix4x4 drawMatrix = Matrix4x4.TRS((Vector3)Handles.matrix.GetColumn(3), Quaternion.identity, 2f * radius * Vector3.one);
Graphics.DrawMeshNow(k_MeshSphere, drawMatrix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ static void DrawHandleLabel(Vector3 handlePosition, string labelText, float offs
var style = new GUIStyle { normal = { background = Texture2D.whiteTexture } };
GUI.color = new Color(0.82f, 0.82f, 0.82f, 1);

labelPosition = handlePosition + Handles.inverseMatrix.MultiplyVector(Vector3.up) * HandleUtility.GetHandleSize(handlePosition) * offsetFromHandle;
labelPosition = handlePosition + HandleUtility.GetHandleSize(handlePosition) * offsetFromHandle * Handles.inverseMatrix.MultiplyVector(Vector3.up);
Handles.Label(labelPosition, labelText, style);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int ReadProbeIndex(int x, int y, int z, int dataWidth, int dataHeight)
static bool NeighbourhoodIsEmptySpace(Vector3 pos, float searchDistance, Bounds boundsToCheckAgainst)
{

Vector3 halfExtents = Vector3.one * searchDistance * 0.5f;
Vector3 halfExtents = 0.5f * searchDistance * Vector3.one;
Vector3 brickCenter = pos + halfExtents;

Collider[] colliders = Physics.OverlapBox(brickCenter, halfExtents);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ public static Brick[] SubdivideCell(Bounds cellBounds, ProbeSubdivisionContext s

bool IsParentBrickInProbeVolume(Vector3Int parentSubCellPos, float minBrickSize, int brickSize)
{
Vector3 center = (Vector3)parentSubCellPos * minBrickSize + Vector3.one * brickSize * minBrickSize / 2.0f;
Bounds parentAABB = new Bounds(center, Vector3.one * brickSize * minBrickSize);
Vector3 center = (Vector3)parentSubCellPos * minBrickSize + brickSize * minBrickSize * Vector3.one / 2.0f;
Bounds parentAABB = new Bounds(center, brickSize * minBrickSize * Vector3.one);

bool generateParentBrick = false;
foreach (var probeVolume in probeVolumes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Vector3 GetMotionDirection()
m_FlySpeedAccelerated = 9;
else
m_FlySpeedAccelerated *= Mathf.Pow(k_FlyAcceleration, deltaTime);
result = m_MotionDirection.normalized * m_FlySpeedAccelerated * speed * deltaTime;
result = deltaTime * m_FlySpeedAccelerated * speed * m_MotionDirection.normalized;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ internal Vector3 QuickReprojectionWithFixedFOVOnPivotPlane(Rect screen, Vector2
screenPoint.x * 2f / screen.width - 1f,
screenPoint.y * 2f / screen.height - 1f);
return pivot
- up * verticalDistance * normalizedScreenPoint.y
- right * verticalDistance * aspect * normalizedScreenPoint.x;
- normalizedScreenPoint.y * verticalDistance * up
- aspect * normalizedScreenPoint.x * verticalDistance * right;
}

//Pivot is always on center axis by construction
Expand All @@ -92,8 +92,7 @@ internal Vector3 QuickProjectPivotInScreen(Rect screen)
/// <param name="camera">The camera to update</param>
public void UpdateCamera(Camera camera)
{
camera.transform.rotation = rotation;
camera.transform.position = position;
camera.transform.SetPositionAndRotation(position, rotation);
camera.nearClipPlane = nearClip;
camera.farClipPlane = farClip;
camera.fieldOfView = fieldOfView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void SelectGizmoZone(Vector2 normalizedMousePosition)
if (absDistanceToPlane < ComparisonGizmoState.thicknessSelected)
selected = Selected.PlaneSeparator;

Vector2 circleCenter = m_State.center + side * orthoPlaneNormal * m_State.length;
Vector2 circleCenter = m_State.center + m_State.length * side * orthoPlaneNormal;
float d = Vector2.Distance(normalizedMousePosition, circleCenter);
if (d <= ComparisonGizmoState.circleRadiusSelected)
selected = side > 0.0f ? Selected.NodeFirstView : Selected.NodeSecondView;
Expand Down
12 changes: 4 additions & 8 deletions Packages/com.unity.render-pipelines.core/Editor/LookDev/Stage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public void MoveIntoStage(GameObject gameObject, Vector3 position, Quaternion ro
return;

SceneManager.MoveGameObjectToScene(gameObject, m_PreviewScene);
gameObject.transform.position = position;
gameObject.transform.rotation = rotation;
gameObject.transform.SetPositionAndRotation(position, rotation);
if (persistent)
m_PersistentGameObjects.Add(gameObject);
else
Expand Down Expand Up @@ -195,16 +194,13 @@ static void InitAddedObjectsRecursively(GameObject go)
go.hideFlags = HideFlags.HideAndDontSave;
go.layer = k_PreviewCullingLayerIndex;

var meshRenderer = go.GetComponent<MeshRenderer>();
if (meshRenderer != null)
if (go.TryGetComponent<MeshRenderer>(out var meshRenderer))
meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;

var skinnedMeshRenderer = go.GetComponent<SkinnedMeshRenderer>();
if (skinnedMeshRenderer != null)
if (go.TryGetComponent<SkinnedMeshRenderer>(out var skinnedMeshRenderer))
skinnedMeshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;

var lineRenderer = go.GetComponent<LineRenderer>();
if (lineRenderer != null)
if (go.TryGetComponent<LineRenderer>(out var lineRenderer))
lineRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off;

var volumes = go.GetComponents<UnityEngine.Rendering.Volume>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal bool visible
if (RenderPipelineManager.currentPipeline == null)
return false;

if (!pipelineTypes.Any())
if (pipelineTypes.Length == 0)
return true;

return pipelineTypes.Contains(RenderPipelineManager.currentPipeline.GetType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void CreateComponentTree(List<Element> tree)
var volumeComponentTypesFiltered =
VolumeManager.GetSupportedVolumeComponents(currentPipeline.GetType());

if (volumeComponentTypesFiltered.Any())
if (volumeComponentTypesFiltered.Count > 0)
{
var rootNode = new PathNode();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ void SetCameraIndex(int index)
// If we witch back to the original camera, put back the transform in it.
if (m_CurrentCamera == m_OriginalCamera)
{
m_OriginalCamera.transform.position = m_OriginalCameraPosition;
m_OriginalCamera.transform.rotation = m_OriginalCameraRotation;
m_OriginalCamera.transform.SetPositionAndRotation(m_OriginalCameraPosition, m_OriginalCameraRotation);
}

transform.position = m_CurrentCamera.transform.position;
transform.rotation = m_CurrentCamera.transform.rotation;
transform.SetPositionAndRotation(m_CurrentCamera.transform.position, m_CurrentCamera.transform.rotation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ void Update()
float moveSpeed = Time.deltaTime * m_MoveSpeed;
if (fire1 || leftShiftBoost && leftShift)
moveSpeed *= m_Turbo;
transform.position += transform.forward * moveSpeed * inputVertical;
transform.position += transform.right * moveSpeed * inputHorizontal;
transform.position += Vector3.up * moveSpeed * inputYAxis;
transform.position += inputVertical * moveSpeed * transform.forward;
transform.position += inputHorizontal * moveSpeed * transform.right;
transform.position += inputYAxis * moveSpeed * Vector3.up;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ List<DebugUIHandlerWidget> GetActiveChildren()
if (!t.gameObject.activeInHierarchy)
continue;

var c = t.GetComponent<DebugUIHandlerWidget>();
if (c != null)
if (t.TryGetComponent<DebugUIHandlerWidget>(out var c))
list.Add(c);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void ChangeSelectedObject()
return;

var elementsArray = elements.ToArray();
var count = elementsArray.Count();
var count = elementsArray.Length;

if (m_Index >= count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,7 @@ public virtual void OnDecrement(bool fast) { }
/// <returns>Previous widget UI handler, parent if there is none.</returns>
public virtual DebugUIHandlerWidget Previous()
{
if (previousUIHandler != null)
return previousUIHandler;

if (parentUIHandler != null)
return parentUIHandler;

return null;
return previousUIHandler != null ? previousUIHandler : parentUIHandler;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ public void OnBeforeSerialize()
serializedProfiles.Add(item);
}

foreach (var set in bakingSets)
serializedBakingSets.Add(set);
serializedBakingSets.AddRange(bakingSets);
}

internal BakingSet CreateNewBakingSet(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,10 @@ float Fwt(float d, float l)
return l * l / (d * (d * d + l * l));
}

Vector3 p1Global = lightPositionWS + lightSide * lightWidth * 0.5f;
Vector3 p2Global = lightPositionWS - lightSide * lightWidth * 0.5f;
Vector3 p1Front = lightPositionWS + cam.transform.right * lightWidth * 0.5f;
Vector3 p2Front = lightPositionWS - cam.transform.right * lightWidth * 0.5f;
Vector3 p1Global = lightPositionWS + 0.5f * lightWidth * lightSide;
Vector3 p2Global = lightPositionWS - 0.5f * lightWidth * lightSide;
Vector3 p1Front = lightPositionWS + 0.5f * lightWidth * cam.transform.right;
Vector3 p2Front = lightPositionWS - 0.5f * lightWidth * cam.transform.right;

Vector3 p1World = cam.transform.InverseTransformPoint(p1Global);
Vector3 p2World = cam.transform.InverseTransformPoint(p2Global);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ static string GetTextureAutoName(int width, int height, string format, TextureDi
temp = string.Format("{0}x{1}{2}_{3}", width, height, mips ? "_Mips" : "", format);
else
temp = string.Format("{0}x{1}x{2}{3}_{4}", width, height, depth, mips ? "_Mips" : "", format);
temp = String.Format("{0}_{1}_{2}", name == "" ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp);
temp = String.Format("{0}_{1}_{2}", name?.Length == 0 ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, to add the null check, it is even better to rely on String.IsNullOrEmpty

Suggested change
temp = String.Format("{0}_{1}_{2}", name?.Length == 0 ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp);
temp = String.Format("{0}_{1}_{2}", String.IsNullOrEmpty(name) ? "Texture" : name, (dim == TextureDimension.None) ? "" : dim.ToString(), temp);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I benchmarked it and isNullOrEmpty actually does a string comparison instead of a null check, so is slower than this!
It is more readable however, so just say what you prefer. I can share the benchmark numbers tomorrow, but it was more than I expected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do, I am curious about the difference.


return temp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ bool ItemInRangeAreRemovedAfterRemoveRange<TList>(TList list, int startIndex, in
{
using (ListPool<int>.Get(out var copy))
{
foreach (int integer in list)
copy.Add(integer);
copy.AddRange(list);

if (list.TryRemoveElementsInRange(startIndex, count, out var exception))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public string[] AdditionalProperties(Type volumeComponentType)
.ToArray();

var notAdditionalParameters = editor.GetField("m_VolumeNotAdditionalParameters") as List<VolumeParameter>;
Assert.True(fields.Count() + notAdditionalParameters.Count == component.parameters.Count);
Assert.True(fields.Length + notAdditionalParameters.Count == component.parameters.Count);

ScriptableObject.DestroyImmediate(component);

Expand Down Expand Up @@ -153,9 +153,9 @@ public void TestHandleParameterDecorators()
editor.GetField("m_Parameters") as List<(GUIContent displayName, int displayOrder,
SerializedDataParameter param)>;

Assert.True(parameters != null && parameters.Count() == k_ExpectedResults.Count());
Assert.True(parameters != null && parameters.Count == k_ExpectedResults.Length);

for (int i = 0; i < k_ExpectedResults.Count(); ++i)
for (int i = 0; i < k_ExpectedResults.Length; ++i)
{
var property = parameters[i].param;
var title = new GUIContent(parameters[i].displayName);
Expand Down