diff --git a/runtime/nvn_api_core.c b/runtime/nvn_api_core.c index e18f57e0..9e9b6a91 100644 --- a/runtime/nvn_api_core.c +++ b/runtime/nvn_api_core.c @@ -708,7 +708,9 @@ NVN_API(nvnQueueSubmitCommands) { finish_mask = e && *e ? strtoll(e, NULL, 0) : 1; if (e && *e && finish_mask == 1 && !(e[0] == '0' && (e[1] == 'x' || e[1] == 'X'))) finish_mask = -1; // "1": all } - int idx = nvn_submits_in_frame++; + // several guest threads submit at once (the pause menu's first frame on): a plain ++ lost counts, and with one the + // frame's first submission went without its wait, or a later one waited + int idx = __atomic_fetch_add(&nvn_submits_in_frame, 1, __ATOMIC_RELAXED); if (finish_mask && f && (finish_mask == -1 || (idx < 63 && (finish_mask >> idx & 1)))) gfx_backend()->exec_wait(f, UINT64_MAX); nvn_call_note(0, (uintptr_t)q, 0); } diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index d396c6b6..1a8ba7e8 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -866,7 +866,7 @@ NVN_API(nvnQueuePresentTexture) { rt_fatal("nvn: QueuePresentTexture of image %d on window %p", idx, (void *)o); nvn_call_note(1, (uintptr_t)arg_p(c, 0), 1); o->presents++; - nvn_submits_in_frame = 0; + __atomic_store_n(&nvn_submits_in_frame, 0, __ATOMIC_RELAXED); const tex_t *t = (const tex_t *)o->tex[idx]; uint64_t period = present_period(o), now = kern_now_ns(); uint64_t slot = now + pace(&o->pace, now, period); diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index 19ee467b..f7b90e84 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -616,7 +616,7 @@ static void vk_be_program_release(const prog_t *p) { replay_drain(DR_PROG_RELEAS // the value returned is the one the replay will signal. static uint64_t vk_be_submit(const uint64_t *handles, int n) { if (!gfx_replay_async()) { - vk_sub_in_frame = nvn_submits_in_frame; // the front end counts it up after the submit returns + vk_sub_in_frame = __atomic_load_n(&nvn_submits_in_frame, __ATOMIC_RELAXED); // the front end counts it up after the submit returns return submit_sync(handles, n); } vk_sync_start();