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
impl GpuContext
Sourcepub fn span(
&self,
span_location: &'static SpanLocation,
) -> Result<GpuSpan, GpuSpanCreationError>
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.
Sourcepub fn span_alloc(
&self,
name: &str,
function: &str,
file: &str,
line: u32,
) -> Result<GpuSpan, GpuSpanCreationError>
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.
Sourcepub fn begin_span(&self, span_location: &'static SpanLocation, query_id: u16)
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.
Sourcepub fn begin_span_alloc(
&self,
name: &str,
function: &str,
file: &str,
line: u32,
query_id: u16,
)
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.
Sourcepub fn end_span(&self, query_id: u16)
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.
Sourcepub fn upload_gpu_timestamp(&self, query_id: u16, gpu_timestamp: i64)
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.
Sourcepub fn sync_gpu_time(&self, gpu_timestamp: i64)
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
impl Clone for GpuContext
Source§fn clone(&self) -> GpuContext
fn clone(&self) -> GpuContext
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more