Skip to content

Enable refit=True argument for render - #1559

Open
hartikainen wants to merge 2 commits into
google-deepmind:mainfrom
hartikainen:fix-rendering-race-condition
Open

Enable refit=True argument for render#1559
hartikainen wants to merge 2 commits into
google-deepmind:mainfrom
hartikainen:fix-rendering-race-condition

Conversation

@hartikainen

Copy link
Copy Markdown
Contributor

`refit_bvh` mutates the scene BVH owned by the `RenderContext` and `render` reads it back, but the two exchange nothing that a graph executor can see, so nothing keeps a frame's refit paired with its own ray cast.

In imperative Warp that is fine, since program order is the schedule, which is why `refit` defaults to `False` and no call site here changes. MJX's JAX/XLA bindings, however, lower the two to independent custom calls, and once several frames land in one executable XLA is free to hoist every refit ahead of every ray cast, so each frame ends up rendered against some other frame's BVH.

`render(refit=True)` refits for itself, which makes a ray cast self-sufficient regardless of how the caller's executor orders things. MJX opts in, and nothing else has to.
`create_render_context` fits the BVH to the pose it is handed, and every existing render test renders that same pose, so none of them would notice `refit=True` quietly doing nothing.

This adds a test that slides a box out from under the bounds fit at context creation, and then checks that `render(refit=True)` matches an explicit `refit_bvh` followed by `render`. It also guards itself by asserting that the stale BVH really does render a different image, since otherwise the test would pass whether or not the refit happens.
@erikfrey

Copy link
Copy Markdown
Collaborator

Hi @hartikainen - ouch, I can see this having resulted in a nasty bug. Hope it didn't bite you guys for very long.

I have heard that AbstractToken is used to ensure proper chaining of FFI calls:

https://github.com/jax-ml/jax/blob/75295224bb2d1ff4c48e476f8077622e6b7eac66/jax/_src/core.py#L3095-L3099

Example here:

jax-ml/jax#16303

Maybe there's a simple, generic way in the JAX wrapper code so that users can supply abstract tokens to indicate serial dependencies? cc @btaba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants