Skip to content
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
10 changes: 4 additions & 6 deletions src/python/isaaccapture/ovxr_session_manager/frame_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,13 @@ def render(self, ordinal: int) -> bool:
raise RuntimeError(
f"OVXR submit_frame failed: {ovxr.result_name(result)}: {self._context.last_error}"
)
if (
result == ovxr.Result.SUCCESS
and _frame.submitted
and self._frame_consumers
):
# Submit consumed the plan; consumer callbacks must not
if result == ovxr.Result.SUCCESS and _frame.submitted:
# Submit consumed the plan; callbacks must not
# cancel it even if a callback fails.
active_plan = None
self._pending_plan = None
if self._binding.on_frame_submitted is not None:
self._binding.on_frame_submitted()
for consumer in self._frame_consumers:
consumer.on_frame_submitted()
active_plan = None
Expand Down
7 changes: 6 additions & 1 deletion src/python/isaaccapture/ovxr_session_manager/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,18 @@ def abandon(self, ordinal: int) -> None:

@dataclass(frozen=True)
class OvxrSessionBinding:
"""Exact application-owned objects borrowed by one OVXR context."""
"""Exact application-owned objects borrowed by one OVXR context.

The optional submission callback runs on the OVXR owner thread after
a successful rendered frame submission.
"""

renderer: object
stage: object
ordinal_ledger: StageOrdinalLedger
frame_consumers: tuple[OvxrFrameConsumer, ...] = ()
prepare_frame_scene: Callable[[], None] | None = None
on_frame_submitted: Callable[[], None] | None = None

def __post_init__(self) -> None:
if self.renderer is None or self.stage is None or self.ordinal_ledger is None:
Expand Down
49 changes: 49 additions & 0 deletions tests/python/core/ovxr_session_manager/test_ovxr_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,55 @@ def close(self):
assert not any(name == "cancel" for name, _ in _FakeContext.operations)


def test_submission_callback_runs_without_frame_consumers(monkeypatch):
submissions = []
output_reads = []

class Host(_FakeHost):
def attach_on_render_thread(self, capability):
return replace(
super().attach_on_render_thread(capability),
on_frame_submitted=lambda: submissions.append(
threading.get_native_id()
),
)

class Context(_FakeContext):
results = iter(((0, True), (0, False), (1, False), (0, True)))

def begin_frame(self):
return 0, _bound_plan()

def submit_frame(self, _plan, *, additional_layers=()):
result, submitted = next(self.results)
return result, SimpleNamespace(submitted=submitted)

api = _fake_ovxr()
api.Context = Context
monkeypatch.setattr(frame_pump, "_import_ovxr", lambda: api)
monkeypatch.setattr(frame_pump, "native_renderer_handle", lambda _renderer: 7)
monkeypatch.setattr(
frame_pump, "completed_outputs", lambda *_: output_reads.append(True)
)

host = Host()
pump = ovxr_session.OvxrSession(host, _config())._pump
# The pump takes the owner lane when creating and destroying the context.
pump.attach(host.offer_render_owner_transfer())
try:
pump.create_context()
pump.render(host.publish_complete_scene("step-1"))
assert len(submissions) == 1
for expected in (1, 1, 2):
pump.render_reused()
assert len(submissions) == expected
finally:
pump.close()

assert not output_reads
assert submissions == [threading.get_native_id()] * 2


def test_consumer_start_failure_retires_borrowed_owners():
host = _FakeHost()
failure = RuntimeError("consumer start failed")
Expand Down
Loading