GpuContext

Struct GpuContext 

Source
pub struct GpuContext { /* private fields */ }
Expand description

Context for creating gpu spans.

Generally corresponds to a single hardware queue.

The flow of creating and using gpu context generally looks like this:

// The period of the gpu clock in nanoseconds, as provided by your GPU api.
// This value corresponds to 1GHz.
let period: f32 = 1_000_000_000.0;

// GPU API: Record writing a timestamp and resolve that to a mappable buffer.
// GPU API: Submit the command buffer writing the timestamp.
// GPU API: Immediately block until the submission is finished.
// GPU API: Map buffer, get timestamp value.
let starting_timestamp: i64 = /* whatever you get from this timestamp */ 0;

// Create the gpu context
let gpu_context = client.new_gpu_context(
    Some("MyContext"),
    tracy_client::GpuContextType::Vulkan,
    starting_timestamp,
    period
).unwrap();

// Now you have some work that you want to time on the gpu.

// GPU API: Record writing a timestamp before the work.
let mut span = gpu_context.span_alloc("MyGpuSpan1", "My::Work", "myfile.rs", 12).unwrap();

// GPU API: Record work.

// GPU API: Record writing a timestamp after the work.
span.end_zone();

// Some time later, once the written timestamp values are available on the cpu.

span.upload_timestamp_start(starting_timestamp);
span.upload_timestamp_end(ending_timestamp);

Implementations§

Source§

impl GpuContext

Source

pub fn span( &self, span_location: &'static SpanLocation, ) -> Result<GpuSpan, GpuSpanCreationError>

Creates a new gpu span with the given source location.

This should be called right next to where you record the corresponding gpu timestamp. This allows tracy to correctly associate the cpu time with the gpu timestamp.

§Errors
  • If there are more than 32767 spans waiting for gpu data at once.
Source

pub fn span_alloc( &self, name: &str, function: &str, file: &str, line: u32, ) -> Result<GpuSpan, GpuSpanCreationError>

Creates a new gpu span with the given name, function, file, and line.

This should be called right next to where you record the corresponding gpu timestamp. This allows tracy to correctly associate the cpu time with the gpu timestamp.

§Errors
  • If there are more than 32767 spans waiting for gpu data at once.
Source

pub fn begin_span(&self, span_location: &'static SpanLocation, query_id: u16)

Begins a new manually tracked GPU span.

You can use this instead of GpuContext::span() if you’d like to track the GPU span manually. query_id is the id of the GPU timestamp query that you had created; when the GPU timestamp is ready, call GpuContext::upload_gpu_timestamp() to upload it to Tracy.

This should be called right next to where you record the corresponding GPU timestamp. This allows tracy to correctly associate the cpu time with the gpu timestamp.

Source

pub fn begin_span_alloc( &self, name: &str, function: &str, file: &str, line: u32, query_id: u16, )

Begins a new manually tracked GPU span with the given name, function, file, and line.

You can use this instead of GpuContext::span() if you’d like to track the GPU span manually.

query_id is the id of the GPU timestamp query that you had created; when the GPU timestamp is ready, call GpuContext::upload_gpu_timestamp() to upload it to Tracy.

This should be called right next to where you record the corresponding GPU timestamp. This allows tracy to correctly associate the cpu time with the gpu timestamp.

Source

pub fn end_span(&self, query_id: u16)

Ends a manually tracked GPU span.

Call this to end a span started with GpuContext::begin_span() or GpuContext::begin_span_alloc().

query_id is the id of the GPU timestamp query that you had created; when the GPU timestamp is ready, call GpuContext::upload_gpu_timestamp() to upload it to Tracy.

This should be called right next to where you record the corresponding GPU timestamp. This allows tracy to correctly associate the cpu time with the gpu timestamp.

Source

pub fn upload_gpu_timestamp(&self, query_id: u16, gpu_timestamp: i64)

Uploads a GPU timestamp for a manually tracked span.

Call this to upload the ready GPU timestamp for a query corresponding to query_id.

Source

pub fn sync_gpu_time(&self, gpu_timestamp: i64)

Communicates the current GPU timestamp to Tracy.

Some GPUs (like AMD) will aggressively reset their timing when going into lower power states. If your application does not continuously utilize the GPU, this will cause Tracy’s synchronization of CPU and GPU timestamps to immediately go out of sync, resulting in broken GPU span display.

You can use this method to resynchronize CPU and GPU timestamps. Fetch the current GPU timestamp, then immediately call this method. It will synchronize the given gpu_timestamp to the CPU timestamp at the time of this call.

Trait Implementations§

Source§

impl Clone for GpuContext

Source§

fn clone(&self) -> GpuContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.