Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created October 19, 2012 01:03
Show Gist options
  • Select an option

  • Save rygorous/3915675 to your computer and use it in GitHub Desktop.

Select an option

Save rygorous/3915675 to your computer and use it in GitHub Desktop.
static RADINLINE bool is_fence_pending(GDrawFence fence)
{
U32 retired = get_gpu_fence();
// everything between "retired" (exclusive) and "next_fence_counter"
// (inclusive) is pending. everything else is definitely done.
//
// we need to be careful about this test since the "fence" value
// coming in is, for all practical purposes, an arbitrary U32. our
// fence counter might have wrapped around multiple times since we last
// used a resource that gets freed, for instance! so if we report a
// fence ID as pending that's not actually in flight, we might end up
// with an infinite wait.
//
// this is a bit subtle since it depends on unsigned wraparound for us
// to do the right thing.
// number of pending fences (next_fence_counter has, by definition, not been written yet)
U32 num_pending = gdraw->next_fence_counter - retired;
// position of the current fence in the "list of pending fences", counting
// from end (i.e. the "youngest" fence that we haven't even issued yet)
U32 pos_in_pending_list = gdraw->next_fence_counter - fence.uinteger;
return pos_in_pending_list < num_pending;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment