Fix the stall model for a bloom render pass

Review the AI's codeEasy12 minNvidia style

Your task

Your renderer's bloom pass maps a parameter buffer the GPU may still be reading, and reads back a luminance value the GPU may not have written yet. Either one makes the CPU wait for the GPU, and the profiler shows a stall every frame. You model which frames stall for a given buffer setup.

An assistant wrote simulate_frame_sync(frame_count, ring_size, frames_in_flight, readback_delay). It is in the editor. It has a bug. Find it and fix it.

Input and output:

  • frame_count: how many frames to simulate, numbered from 0.
  • ring_size: how many copies of the parameter buffer exist. Frame f writes copy f % ring_size.
  • frames_in_flight: how far the GPU runs behind. Work from frame g is finished once the CPU starts frame g + frames_in_flight.
  • readback_delay: frame f reads the luminance written by frame f - readback_delay.
  • Return one boolean per frame: whether the CPU stalls on that frame.

Rules the tests check:

  • If frame_count is 0 or less, return []. A ring_size or frames_in_flight below 1 counts as 1, and a negative readback_delay counts as 0.
  • Map stall: the first ring_size frames write copies nobody has used yet, so they never wait. From frame ring_size on, frame f stalls when ring_size is less than frames_in_flight.
  • Readback stall: frame f stalls when f - readback_delay is 0 or more and readback_delay is less than frames_in_flight. Before that, no result exists yet, so there is nothing to wait for.
  • A frame stalls when either rule says so.

Examples

simulate_frame_sync(frame_count: int, ring_size: int, frames_in_flight: int, readback_delay: int) -> list[bool]
Example 1
Inputsimulate_frame_sync(4, 1, 2, 0)
Output[True, True, True, True]
Example 2
Inputsimulate_frame_sync(4, 2, 2, 2)
Output[False, False, False, False]