NVIDIA-Omniverse / PhysX

NVIDIA PhysX SDK
BSD 3-Clause "New" or "Revised" License
2.34k stars 313 forks source link

Bad task scheduling due to lack of priority #279

Open Zeblote opened 2 weeks ago

Zeblote commented 2 weeks ago

Here's an example. CM and ABP tasks are scheduled at roughly the same time. CM task is usually quite fine grained, while ABP has few very long ones. But the engine has no way to know this! So it often schedules them terribly.

image

We can fix this by letting the engine know the ABP task has higher priority. Here's the result of passing ETaskPriority::High to new UE::Tasks API in Unreal for ABP tasks only.

image

I only implemented the API necessary to get the info to Unreal, not in the default task scheduler, so it's probably not worthy of a PR as is. https://github.com/brickadia/PhysX/commit/cde092e8a1f0a297ea9b6b74686d589033d8004e

Zeblote commented 2 weeks ago

On that note, I'm wondering if it is possible to further split the PABP tasks. It seems like the dynamics (full) one is constantly taking much longer than the others, but I don't really understand the internal code that well.

PierreTerdiman commented 2 weeks ago

Thank you for the report. This is interesting, and I think we could try that in our own benchmarks. AFAIK the scheduler does not support task priorities so we would need to implement that first.

There is currently no way to further split the PABP tasks. This is possible in theory though, and there is / was some experimental code doing just that a while ago. But it has never been productized (IIRC it introduced more task-related overhead, to the point that only really large scenes showed benefits). It would be interesting to revisit this, but this is probably not a high-priority task.