Conversation
b8c4202 to
52abb9f
Compare
| @@ -1,24 +1,24 @@ | |||
| test_editors: | |||
| - version: 2021.3 | |||
There was a problem hiding this comment.
shouldn't we also remove this and upgrade the minimum unity version to 6000.0?
Same with romotion_test_editors
There was a problem hiding this comment.
It's the minimum version of the package, so we have to keep the job for promotion.
There was a problem hiding this comment.
I believe its allow to bump the minimum version of the package if said version is not supported anymore without being considered a new major release. But if that would increase the scope of this PR, we can do it separately
There was a problem hiding this comment.
I would say it's indeed out of scope, so let's log a task to update this separately.
LeoUnity
left a comment
There was a problem hiding this comment.
Changes looks good to me, we do have a test failure on win trunk unfortunately.
626a370 to
12f0896
Compare
| } | ||
| #if UNITY_2023_1_OR_NEWER | ||
| #if UNITY_6000_4_OR_NEWER | ||
| return Object.FindObjectsByType<T>(); |
There was a problem hiding this comment.
The FindObjectsSortMode.InstanceID used in UNITY_2023_1_OR_NEWER code path is not needed as the result of GetTargets is only used with Any(), so I just removed the sorting mode here.
I was tempted to remove it in UNITY_2023_1_OR_NEWER code path too but on a very legacy package in basic support, the less we touch, the better.
Feel free to push back.
com.unity.formats.alembic/Runtime/Scripts/Exporter/AlembicExporter_impl.cs
Outdated
Show resolved
Hide resolved
| { | ||
| m_time = 0.0f; | ||
| #if UNITY_6000_4_OR_NEWER | ||
| m_context = new SafeContext(aiContext.Create(AllocateNativeContextUid())); |
There was a problem hiding this comment.
The native function called at the end of the line is aiContextCreate(int uid). So if we keep using a ulong here, we ultimately have to cast it, which can lead to some narrowing and rare but potential collisions.
But in the code where the id is used, there is no need for a correlation between the id and the abcTreeRoot object, we just need an id to destroy on dispose (cf aiContextDestroy(aiContext* ctx)).
Thus the introduction of an alternative surrogate id.
A question for reviewers: what is the bigger risk ?
1- Changing this code
2- Narrowing and collision
😅
There was a problem hiding this comment.
I think this approach you took is great!
|
|
||
| #endif | ||
|
|
||
| #if UNITY_6000_4_OR_NEWER |
There was a problem hiding this comment.
Explaination about why we need this:
There was a problem hiding this comment.
A concern that jumped out to me is performance.
When and how often is this sorting taking place? We are doing a lot more computations including string operations to get this determinism.
Also out of curiosity why is determinism important here? What would it mean not having determinism?
There was a problem hiding this comment.
Good questions :D
Put on your seat belt 😄
Some context
GetTargets (where this func is used) is the scene discovery mechanism. Its results feed ConstructTree, which inserts nodes into m_nodes aka builds the in-memory capture tree and ultimately determines the order in which Alembic nodes (NewXform, NewPolyMesh, etc.) are created inside the archive.
GetTargets is called at every capture frame during recording.
Why we want determinism
The tree topology is naturaly done and deterministic for parents/children because of the recursiveness used (aka we always resolves parents before children).
But what is not naturally stable is the sibling ordering, aka the order in which NewXform/NewPolyMesh is called on the children of a given parent, which determines the order those children appear in the Alembic file. If no sorting is done, sibling order will not be stable and produce .abc files that bit-wise/ascii-wise looks different when they technically are not (noise during versioning, unnessary cache invalidation...).
BTW the sorting by InstanceID was actually not great either, because from a Unity session to another, the instanceID could change and so the ordering of the sibblings.
The new sorting is based on the GO scene path and root-to-leaf sibling indices (that order is serialized into the scene file and restored identically every time the scene loads), this is now a structural and session-independent sorting.
Perf concern
At every captured frame, we unconditionally calls UpdateCaptureNodes, which calls GetTargets once per enabled capturer type (up to 4: Transform, Camera, MeshRenderer, SkinnedMeshRenderer) = SortComponentsByStableSceneHierarchy runs up to 4× per frame for the entire duration of recording 😅
So, ya, not great, the new sorting is probably worse than native InstanceID sorting.
That said there is room for improv, let me try.
There was a problem hiding this comment.
Well, I tried for few hours but the improvements I could get (without breaking everything) are almost anecdoctical and there is still this idea of minimalizing impact / halo in the changes we do in this package.
To mitigate, this is only run when we record. So I would stop there.
Feel free to push back if you feel I should persevere in trying to improve the perf.
How about that @LeoUnity ?
| // Theoretical int overflow after ~2 billion AbcLoad calls is impossible in practice. | ||
| static int s_nextNativeContextUid; | ||
|
|
||
| static int AllocateNativeContextUid() => Interlocked.Increment(ref s_nextNativeContextUid); |
There was a problem hiding this comment.
Should/could this be uint? we are leaving half of its range on the table
There was a problem hiding this comment.
I'm using the type of the native function that this id is for (aka aiContextCreate(int uid))
Purpose of this PR
Ticket/Jira #: UUM-137643
This PR address 3 issues:
1 - Compilation errors in the console
error CS0619: 'Object.GetInstanceID()' is obsolete: 'GetInstanceID is deprecated. Use GetEntityId instead.2 - Warnings (that will become errors in a foreseeable futur):
warning CS0618: 'FindObjectsSortMode' is obsolete: 'FindObjectsSortMode has been deprecated. Use the FindObjectsByType overloads that do not take a FindObjectsSortMode parameter.'SortComponentsByStableSceneHierarchy).3- replace renderPipelineAsset by defaultRenderPipeline
defautRenderPipeline was introduced in 2019 stream so that was due.
A general mindset for this PR is the less we touch, the better.
The reason is that this code is very legacy and in basic support. We want to mitigate the risk of breaking the past versions and increase our support load.
That's why every changes needed were encapsulated in
#if UNITY_6000_4_OR_NEWER...#endifeven when the changes would be considered a better practice for precedent versions too (like not sorting with instanceIds).Testing
Functional Testing status:
Performance Testing status:
Overall Product Risks
Complexity:
Halo Effect:
Documentation & UX Writing
Additional information
Note to reviewers:
Reminder: