done_mode=spin (experimental): the rescue path's flag write can be lost while the spin polls

Offen
#39 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
48/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
cpp
Bereich
backend

Rechercherichtung

Start with the rescue-flag path in clean/runtime/interop/backend.cpp and the existing flag pass; compare its write with WriteBufferImmediate. Read the spin polling path in clean/runtime/interop/convert.cpp to understand how the flag is consumed. Replace the rescue write with a compute dispatch on the rescue queue, then test that a rescued frame avoids a spin timeout and measure the HIP writer case on hardware.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

area: runtime bug needs-hardware-test

With the experimental options ready_wait=memory and done_mode=spin, the game's queue runs a one-thread pass that
polls the done flag with an atomic (InterlockedAdd(flag, 0), PASS_SPIN in clean/runtime/interop/convert.cpp)
until the network writes it. When the network of a frame cannot be enqueued, rescue_flag
(clean/runtime/interop/backend.cpp) is meant to release that spin: a separate list on the backend's own compute queue
waits for the previous network frame, then writes the flag with WriteBufferImmediate. The spin was recorded into the
game's list before that, so the write can arrive while the spin is polling.

Measured on Windows with a test harness (no HIP): a flag written by a shader store on another queue while the spin
polls is seen in 5 of 5 runs; the same flag written with WriteBufferImmediate on another queue is not seen in any of
5 runs, the spin times out, and the flag still reads its old value afterwards: the write is lost, not late. Written
after the spin has finished, the same WriteBufferImmediate lands.

Why: while the spin polls, the flag buffer is in a write state on the game's queue (its atomic is a read-modify-write,
UNORDERED_ACCESS), and the rescue list writes the same 32 bits from a second queue (COPY_DEST, by implicit
promotion from COMMON, which is valid for buffers). Buffers have simultaneous-access semantics, which allow "multiple
readers and one writer, as long as the writer doesn't concurrently modify the texels that other readers are accessing"
(D3D12_RESOURCE_FLAGS, D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS). Two queues writing the same 32 bits at once
breaks the first half of that rule. The second half means that no cross-queue write to the flag while the spin reads
it is covered by the API, whoever writes it: the spin design as a whole relies on how the hardware behaves, which is
why it is experimental. On this hardware a shader write is seen and a command-processor write is lost.

The cost today: one spin timeout (bounded by spin_polls) and a stale flag for that frame. The normal writer
(hipStreamWriteValue32 on the HIP stream) also writes while the spin polls; whether it is seen could not be measured
here.

To do: write the rescue flag with the existing flag pass (a compute dispatch on the rescue queue: the shader-write case
that worked) instead of WriteBufferImmediate, and test that a rescued frame no longer costs a timeout. Measure the
HIP writer's case on hardware. Until this is fixed, the option's documentation states that spin mode relies on
behaviour the API does not guarantee.

Related: #7

Vorherrschende Sprache
C++
Sterne
12
Forks
2
Ø Merge
3 Std. 10 Min.
Gemergte PRs (30 T.)
171

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus phantoslayer21/wronggpu

Alle Issues in phantoslayer21/wronggpu

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.