As I understand it:
the commands that I will send to the GPU regarding physics will be associated with the current backbuffer
in the same way that calling Clear() will clear the current backbuffer
and the only guarantee available is that by the time that backbuffer is resolved and swapped to the frontbuffer
those commands *will* have been executed
although the driver/gpu might see there is no actual dependency between the endresult of the backbuffer and my physics commands
it cannot defer execution of those commands till after the associated backbuffer has been swapped - because that would be crazy
also there is never anyway to guarantee the commands are executed *before* the associated backbuffer has been swapped to the front
that is why (I believe) the execution of the DirectX Present() function is relevant to my physics processing
If I was using DirectX maybe I could setup a separate swapchain purely for physics - with a swaprate much higher than for rendering
But in XNA my only choice is to use every frame for physics and 1 in N frames for rendering
Which leads me back round (like a swapchain) to the two critical pieces of information I need:
- how many backbuffers in the xna xbox360 swapchain
- will reading back a (fully resolved on the gpu) texture result in stalling or slowdowns
here is a picture
-- frame 1 draw() method --------------------
swapchain = {1, 2, 3} current back buffer = 1, 3 is visible
render to physics texture
render to texture
render texture to backbuffer
-- frame 2 draw() method --------------------
swapchain = {3, 1, 2} current back buffer = 3, 2 is visible (gpu *may* have started processing my physics commands)
render texture to backbuffer
-- frame 3 draw() method --------------------
swapchain = {2, 3, 1} current back buffer = 2, 1 is visible *** (my physics texture has been resolved!)
render texture to backbuffer
-- frame 4 draw() method --------------------
swapchain = {1, 2, 3} current back buffer = 1, 3 is visible
read from physics texture
process physics
render to physics texture
render to texture
render texture to backbuffer
-- etc. --------------------
[EDIT] maybe this explains it better:
| Using two backbuffer textures F1 F2 |
| and two physics textures P1 P2 |
| |
| BackBuffer |2|1|1|1|1|2|2|2|2|1|1|1|1|2|2|2| which backbuffer texture is rendered |
Render |1| | | |2| | | |1| | | |2| | | | when we render to backbuffer texture#
|
| PWrite | |1| | | |2| | | |1| | | |2| | | which physics texture we write |
| PRead | | |2| | | |1| | | |2| | | |1| | which physics texture we read |
| Update | | | |x| | | |x| | | |x| | | |x| when we update game state |
| |
| this should spread the workload as evenly as possible |
| and ensures plenty of swapchain presents before reading physics data to cpu |
| |
| |