[VE] Usability and performance enhancement #123
Merged
+827
−450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves VE in 3 ways:
2.1. Refactor the IScreenshotPlugin so that VE can receive the Texture2D instead of already encoded bytes (where possible).
2.2. Use a ThreadPool to encode Texture2D and write to disk. This helps because ThreadPool is multi-processor.
2.3. Activated by a toggle marked as BETA because of the nature of this change. I haven't had issues so far, but Unity objects like Texture2D are not thread-safe and I think it needs some testing on the field.
The biggest costs were the excessive GC calls and image encoding on the main thread.
This video shows the difference when recording using Builtin PNG (0:19 -> 0:13). This is much faster than the other test below because recording from this angle is less costly.
PR_VE.mp4
Other crude tests (all in 1440p):
KK, 180 frames (scene in demo video from camera object angle):
Builtin (BMP): 0:29 -> 0:11 *
Builtin (PNG): 0:49 -> 0:27 *
Manager (PNG): 1:04 -> 0:38
KK, 720 frames (timeline scene with 2 characters):
Builtin (BMP): 1:54 -> 0:41 *
Builtin (PNG): 4:04 -> 2:33 *
Manager (PNG): 5:25 -> 3:42
KK, 600 frames (ridiculous scene with 32 characters):
Builtin (BMP): 5:39 -> 4:09
Builtin (PNG): 6:43 -> 4:43
Manager (PNG): 7:41 -> 6:55
HS2, 1593 frames (timeline scene with 2 characters):
Builtin (BMP): 2:09 -> 1:46
Builtin (PNG): 7:14 -> 6:07
Manager (PNG): 9:12 -> 7:40
* Scenes with fast rendering times had the biggest gains because their main bottleneck was the encoding. Heavy scenes have to wait for their frame to render before offloading encoding and IO to the ThreadPool.
It's a small improvement for #89.