wgpu_core

Module timestamp_normalization

Source
Expand description

Utility for normalizing GPU timestamp queries to have a consistent 1GHz period. This uses a compute shader to do the normalization, so the timestamps exist in their correct format on the GPU, as is required by the WebGPU specification.

§Algorithm

The fundamental operation is multiplying a u64 timestamp by an f32 value. We have neither f64s nor u64s in shaders, so we need to do something more complicated.

We first decompose the f32 into a u32 fraction where the denominator is a power of two. We do the computation with f64 for ease of computation, as those can store u32s losslessly.

Because the denominator is a power of two, this means the shader can evaluate this divide by using a shift. Additionally, we always choose the largest denominator we can, so that the fraction is as precise as possible.

To evaluate this function, we have two helper operations (both in common.wgsl).

  1. u64_mul_u32 multiplies a u64 by a u32 and returns a u96.
  2. shift_right_u96 shifts a u96 right by a given amount, returning a u96.

See their implementations for more details.

We then multiply the timestamp by the numerator, and shift it right by the denominator. This gives us the normalized timestamp.

Structs§

Enums§

Constants§

Functions§