diff --git a/src/python/isaaccapture/ovxr_session_manager/frame_pump.py b/src/python/isaaccapture/ovxr_session_manager/frame_pump.py index 356701020e..f0b5b4e283 100644 --- a/src/python/isaaccapture/ovxr_session_manager/frame_pump.py +++ b/src/python/isaaccapture/ovxr_session_manager/frame_pump.py @@ -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 diff --git a/src/python/isaaccapture/ovxr_session_manager/interfaces.py b/src/python/isaaccapture/ovxr_session_manager/interfaces.py index c23de8e73e..7c1bc1cd71 100644 --- a/src/python/isaaccapture/ovxr_session_manager/interfaces.py +++ b/src/python/isaaccapture/ovxr_session_manager/interfaces.py @@ -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: diff --git a/tests/python/core/ovxr_session_manager/test_ovxr_session.py b/tests/python/core/ovxr_session_manager/test_ovxr_session.py index b4464be127..8e6a56da4a 100644 --- a/tests/python/core/ovxr_session_manager/test_ovxr_session.py +++ b/tests/python/core/ovxr_session_manager/test_ovxr_session.py @@ -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")